// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Controls.TreeView;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Forms.ProgressDialog;
using Core.Common.Gui.Plugin;
using Core.Common.Utils;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Probability;
using Ringtoets.Common.Forms.ChangeHandlers;
using Ringtoets.Common.Forms.ExportInfos;
using Ringtoets.Common.Forms.Helpers;
using Ringtoets.Common.Forms.ImportInfos;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.TreeNodeInfos;
using Ringtoets.Common.IO.FileImporters;
using Ringtoets.Common.IO.FileImporters.MessageProviders;
using Ringtoets.Common.Service;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionInwards.Forms.PropertyClasses;
using Ringtoets.GrassCoverErosionInwards.Forms.Views;
using Ringtoets.GrassCoverErosionInwards.IO.Configurations;
using Ringtoets.GrassCoverErosionInwards.Plugin.FileImporters;
using Ringtoets.GrassCoverErosionInwards.Plugin.Properties;
using Ringtoets.GrassCoverErosionInwards.Service;
using Ringtoets.GrassCoverErosionInwards.Utils;
using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using GrassCoverErosionInwardsFormsResources = Ringtoets.GrassCoverErosionInwards.Forms.Properties.Resources;
namespace Ringtoets.GrassCoverErosionInwards.Plugin
{
///
/// The plug-in for the .
///
public class GrassCoverErosionInwardsPlugin : PluginBase
{
public override IEnumerable GetPropertyInfos()
{
yield return new PropertyInfo
{
CreateInstance = context => new GrassCoverErosionInwardsFailureMechanismContextProperties(
context,
new FailureMechanismPropertyChangeHandler())
};
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new GrassCoverErosionInwardsInputContextProperties(
context,
new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData))
};
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new DikeProfileCollectionProperties(context.WrappedData)
};
yield return new PropertyInfo();
yield return new PropertyInfo();
yield return new PropertyInfo();
}
public override IEnumerable GetImportInfos()
{
yield return RingtoetsImportInfoFactory.CreateCalculationConfigurationImportInfo(
(context, filePath) => new GrassCoverErosionInwardsCalculationConfigurationImporter(
filePath,
context.WrappedData,
context.AvailableHydraulicBoundaryLocations,
context.AvailableDikeProfiles,
context.FailureMechanism));
yield return new ImportInfo
{
CreateFileImporter = (context, filePath) => new DikeProfilesImporter(context.WrappedData,
context.ParentAssessmentSection.ReferenceLine,
filePath,
new GrassCoverErosionInwardsDikeProfileReplaceDataStrategy(context.ParentFailureMechanism),
new ImportMessageProvider()),
Name = RingtoetsCommonIOResources.DikeProfilesImporter_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsCommonFormsResources.DikeProfile,
FileFilterGenerator = DikeProfileImporterFileFilterGenerator(),
IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null,
VerifyUpdates = context => VerifyDikeProfilesShouldUpdate(context,
Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileImport_When_importing_DikeProfiles_Calculation_output_will_be_cleared_confirm)
};
}
public override IEnumerable GetUpdateInfos()
{
yield return new UpdateInfo
{
CreateFileImporter = (context, filePath) => new DikeProfilesImporter(context.WrappedData,
context.ParentAssessmentSection.ReferenceLine,
filePath,
new GrassCoverErosionInwardsDikeProfileUpdateDataStrategy(context.ParentFailureMechanism),
new UpdateMessageProvider()),
Name = RingtoetsCommonIOResources.DikeProfilesImporter_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsCommonFormsResources.DikeProfile,
FileFilterGenerator = DikeProfileImporterFileFilterGenerator(),
CurrentPath = context => context.WrappedData.SourcePath,
IsEnabled = context => context.WrappedData.SourcePath != null,
VerifyUpdates = context => VerifyDikeProfilesShouldUpdate(context,
Resources.GrassCoverErosionInwardsPlugin_VerifyDikeProfileUpdate_When_updating_Calculation_with_DikeProfile_data_output_will_be_cleared_confirm)
};
}
public override IEnumerable GetExportInfos()
{
yield return RingtoetsExportInfoFactory.CreateCalculationGroupConfigurationExportInfo(
(context, filePath) => new GrassCoverErosionInwardsCalculationConfigurationExporter(context.WrappedData.Children, filePath),
context => context.WrappedData.Children.Any());
yield return RingtoetsExportInfoFactory.CreateCalculationConfigurationExportInfo(
(context, filePath) => new GrassCoverErosionInwardsCalculationConfigurationExporter(new[]
{
context.WrappedData
}, filePath));
}
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo
{
GetViewName = (view, mechanism) => mechanism.WrappedData.Name,
Image = RingtoetsCommonFormsResources.CalculationIcon,
CloseForData = CloseGrassCoverErosionInwardsFailureMechanismViewForData,
AdditionalDataCheck = context => context.WrappedData.IsRelevant
};
yield return new ViewInfo<
GrassCoverErosionInwardsScenariosContext,
CalculationGroup,
GrassCoverErosionInwardsScenariosView>
{
GetViewData = context => context.WrappedData,
GetViewName = (view, calculationGroup) => RingtoetsCommonFormsResources.Scenarios_DisplayName,
AfterCreate = (view, context) => view.FailureMechanism = context.ParentFailureMechanism,
CloseForData = CloseScenariosViewForData,
Image = RingtoetsCommonFormsResources.ScenariosIcon
};
yield return new ViewInfo<
FailureMechanismSectionResultContext,
IEnumerable,
GrassCoverErosionInwardsFailureMechanismResultView>
{
GetViewName = (view, results) => RingtoetsCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName,
Image = RingtoetsCommonFormsResources.FailureMechanismSectionResultIcon,
CloseForData = CloseFailureMechanismResultViewForData,
GetViewData = context => context.WrappedData,
AfterCreate = (view, context) => view.FailureMechanism = context.FailureMechanism
};
yield return new ViewInfo
{
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
GetViewName = (view, input) => RingtoetsCommonFormsResources.Calculation_Input,
GetViewData = context => context.Calculation,
CloseForData = CloseInputViewForData
};
}
public override IEnumerable GetTreeNodeInfos()
{
yield return RingtoetsTreeNodeInfoFactory.CreateFailureMechanismContextTreeNodeInfo(
FailureMechanismEnabledChildNodeObjects,
FailureMechanismDisabledChildNodeObjects,
FailureMechanismEnabledContextMenuStrip,
FailureMechanismDisabledContextMenuStrip);
yield return new TreeNodeInfo
{
Text = context => RingtoetsCommonFormsResources.DikeProfiles_DisplayName,
Image = context => RingtoetsCommonFormsResources.GeneralFolderIcon,
ForeColor = context => context.WrappedData.Any() ?
Color.FromKnownColor(KnownColor.ControlText) :
Color.FromKnownColor(KnownColor.GrayText),
ChildNodeObjects = context => context.WrappedData
.Cast