// Copyright (C) Stichting Deltares 2021. All rights reserved.
//
// This file is part of Riskeer.
//
// Riskeer 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.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Controls.TreeView;
using Core.Common.Util;
using Core.Gui.ContextMenu;
using Core.Gui.Forms.ProgressDialog;
using Core.Gui.Helpers;
using Core.Gui.Plugin;
using Riskeer.Common.Data.AssessmentSection;
using Riskeer.Common.Data.Calculation;
using Riskeer.Common.Data.Contribution;
using Riskeer.Common.Data.Hydraulics;
using Riskeer.Common.Forms;
using Riskeer.Common.Forms.ChangeHandlers;
using Riskeer.Common.Forms.ExportInfos;
using Riskeer.Common.Forms.Helpers;
using Riskeer.Common.Forms.ImportInfos;
using Riskeer.Common.Forms.PresentationObjects;
using Riskeer.Common.Forms.TreeNodeInfos;
using Riskeer.Common.Forms.UpdateInfos;
using Riskeer.Common.Plugin;
using Riskeer.Common.Service;
using Riskeer.Revetment.Data;
using Riskeer.Revetment.Forms.Views;
using Riskeer.Revetment.IO.Configurations;
using Riskeer.Revetment.Service;
using Riskeer.WaveImpactAsphaltCover.Data;
using Riskeer.WaveImpactAsphaltCover.Forms;
using Riskeer.WaveImpactAsphaltCover.Forms.PresentationObjects;
using Riskeer.WaveImpactAsphaltCover.Forms.PropertyClasses;
using Riskeer.WaveImpactAsphaltCover.Forms.Views;
using Riskeer.WaveImpactAsphaltCover.IO.Exporters;
using Riskeer.WaveImpactAsphaltCover.Plugin.FileImporters;
using Riskeer.WaveImpactAsphaltCover.Service;
using RiskeerCommonDataResources = Riskeer.Common.Data.Properties.Resources;
using RiskeerCommonFormsResources = Riskeer.Common.Forms.Properties.Resources;
namespace Riskeer.WaveImpactAsphaltCover.Plugin
{
///
/// The plug-in for the .
///
public class WaveImpactAsphaltCoverPlugin : PluginBase
{
public override IEnumerable GetPropertyInfos()
{
yield return new PropertyInfo
{
CreateInstance = context => new WaveImpactAsphaltCoverHydraulicLoadsProperties(context.WrappedData)
};
yield return new PropertyInfo
{
CreateInstance = context => new WaveImpactAsphaltCoverFailurePathProperties(context.WrappedData, context.Parent)
};
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new WaveImpactAsphaltCoverWaveConditionsInputContextProperties(
context,
() => context.AssessmentSection.GetAssessmentLevel(context.Calculation.InputParameters.HydraulicBoundaryLocation,
context.Calculation.InputParameters.CategoryType),
new ObservablePropertyChangeHandler(context.Calculation, context.WrappedData))
};
}
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo
{
GetViewName = (view, context) => context.WrappedData.Name,
Image = RiskeerCommonFormsResources.FailureMechanismIcon,
CreateInstance = context => new WaveImpactAsphaltCoverFailureMechanismView(context.WrappedData, context.Parent)
};
yield return new ViewInfo
{
GetViewName = (view, context) => context.WrappedData.Name,
Image = RiskeerCommonFormsResources.FailureMechanismIcon,
CreateInstance = context => new WaveImpactAsphaltCoverFailurePathView(context.WrappedData, context.Parent)
};
yield return new ViewInfo,
IObservableEnumerable,
WaveImpactAsphaltCoverFailureMechanismResultView>
{
GetViewName = (view, context) => RiskeerCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName,
Image = RiskeerCommonFormsResources.FailureMechanismSectionResultIcon,
CloseForData = CloseFailureMechanismResultViewForData,
GetViewData = context => context.WrappedData,
CreateInstance = context => new WaveImpactAsphaltCoverFailureMechanismResultView(
context.WrappedData,
(WaveImpactAsphaltCoverFailureMechanism) context.FailureMechanism)
};
yield return new ViewInfo,
WaveConditionsInputView>
{
Image = RiskeerCommonFormsResources.GenericInputOutputIcon,
GetViewName = (view, context) => RiskeerCommonFormsResources.Calculation_Input,
CloseForData = RiskeerPluginHelper.ShouldCloseViewWithCalculationData,
CreateInstance = context => new WaveConditionsInputView(
context.Calculation,
() => context.AssessmentSection.GetHydraulicBoundaryLocationCalculation(context.Calculation.InputParameters.HydraulicBoundaryLocation,
context.Calculation.InputParameters.CategoryType),
new WaveImpactAsphaltCoverWaveConditionsInputViewStyle())
};
}
public override IEnumerable GetImportInfos()
{
yield return RiskeerImportInfoFactory.CreateCalculationConfigurationImportInfo(
(context, filePath) =>
new AssessmentSectionCategoryWaveConditionsCalculationConfigurationImporter(
filePath,
context.WrappedData,
context.AssessmentSection.HydraulicBoundaryDatabase.Locations,
context.ForeshoreProfiles,
context.AssessmentSection.FailureMechanismContribution.NormativeNorm));
}
public override IEnumerable GetTreeNodeInfos()
{
yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo(
HydraulicLoadsChildNodeObjects,
HydraulicLoadsContextMenuStrip);
yield return RiskeerTreeNodeInfoFactory.CreateFailureMechanismStateContextTreeNodeInfo(
FailurePathChildNodeObjects,
FailurePathContextMenuStrip);
yield return new TreeNodeInfo>
{
Text = context => RiskeerCommonFormsResources.FailureMechanism_AssessmentResult_DisplayName,
Image = context => RiskeerCommonFormsResources.FailureMechanismSectionResultIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddOpenItem()
.Build()
};
yield return RiskeerTreeNodeInfoFactory.CreateCalculationGroupContextTreeNodeInfo(
WaveConditionsCalculationGroupContextChildNodeObjects,
WaveConditionsCalculationGroupContextContextMenuStrip,
WaveConditionsCalculationGroupContextOnNodeRemoved);
yield return RiskeerTreeNodeInfoFactory.CreateCalculationContextTreeNodeInfo(
WaveConditionsCalculationContextChildNodeObjects,
WaveConditionsCalculationContextContextMenuStrip,
WaveConditionsCalculationContextOnNodeRemoved,
CalculationType.Hydraulic);
yield return new TreeNodeInfo
{
Text = emptyOutput => RiskeerCommonFormsResources.CalculationOutput_DisplayName,
Image = emptyOutput => RiskeerCommonFormsResources.GeneralOutputIcon,
ForeColor = emptyOutput => Color.FromKnownColor(KnownColor.GrayText),
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddPropertiesItem()
.Build()
};
yield return new TreeNodeInfo
{
Text = emptyOutput => RiskeerCommonFormsResources.CalculationOutput_DisplayName,
Image = emptyOutput => RiskeerCommonFormsResources.GeneralOutputIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddPropertiesItem()
.Build()
};
yield return new TreeNodeInfo
{
Text = context => RiskeerCommonFormsResources.Calculation_Input,
Image = context => RiskeerCommonFormsResources.GenericInputOutputIcon,
ContextMenuStrip = (nodeData, parentData, treeViewControl) => Gui.Get(nodeData, treeViewControl)
.AddOpenItem()
.AddSeparator()
.AddPropertiesItem()
.Build()
};
}
public override IEnumerable GetExportInfos()
{
yield return new ExportInfo
{
Name = RiskeerCommonFormsResources.WaveConditionsExporter_DisplayName,
Extension = RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Extension,
CreateFileExporter = (context, filePath) =>
{
IEnumerable calculations = context.WrappedData.GetCalculations().Cast();
return new WaveImpactAsphaltCoverWaveConditionsExporter(calculations, filePath);
},
IsEnabled = context => context.WrappedData.GetCalculations().Cast().Any(c => c.HasOutput),
GetExportPath = () => ExportHelper.GetFilePath(GetInquiryHelper(), GetWaveConditionsFileFilterGenerator())
};
yield return new ExportInfo
{
Name = RiskeerCommonFormsResources.WaveConditionsExporter_DisplayName,
Extension = RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Extension,
CreateFileExporter = (context, filePath) => new WaveImpactAsphaltCoverWaveConditionsExporter(new[]
{
context.WrappedData
}, filePath),
IsEnabled = context => context.WrappedData.HasOutput,
GetExportPath = () => ExportHelper.GetFilePath(GetInquiryHelper(), GetWaveConditionsFileFilterGenerator())
};
yield return RiskeerExportInfoFactory.CreateCalculationGroupConfigurationExportInfo(
(context, filePath) => new AssessmentSectionCategoryWaveConditionsCalculationConfigurationExporter(context.WrappedData.Children, filePath),
context => context.WrappedData.Children.Any(),
GetInquiryHelper());
yield return RiskeerExportInfoFactory.CreateCalculationConfigurationExportInfo(
(context, filePath) => new AssessmentSectionCategoryWaveConditionsCalculationConfigurationExporter(new[]
{
context.WrappedData
}, filePath),
GetInquiryHelper());
}
public override IEnumerable GetUpdateInfos()
{
yield return RiskeerUpdateInfoFactory.CreateFailureMechanismSectionsUpdateInfo<
WaveImpactAsphaltCoverFailureMechanismSectionsContext, WaveImpactAsphaltCoverFailureMechanism, WaveImpactAsphaltCoverFailureMechanismSectionResult>(
new WaveImpactAsphaltCoverFailureMechanismSectionResultUpdateStrategy());
}
private static FileFilterGenerator GetWaveConditionsFileFilterGenerator()
{
return new FileFilterGenerator(RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Extension,
RiskeerCommonFormsResources.DataTypeDisplayName_csv_file_filter_Description);
}
#region ViewInfos
private static bool CloseFailureMechanismResultViewForData(WaveImpactAsphaltCoverFailureMechanismResultView view, object dataToCloseFor)
{
WaveImpactAsphaltCoverFailureMechanism failureMechanism = null;
if (dataToCloseFor is IAssessmentSection assessmentSection)
{
failureMechanism = assessmentSection.GetFailureMechanisms()
.OfType()
.FirstOrDefault();
}
if (dataToCloseFor is IFailureMechanismContext failureMechanismContext)
{
failureMechanism = failureMechanismContext.WrappedData;
}
return failureMechanism != null && ReferenceEquals(view.FailureMechanism.SectionResults, failureMechanism.SectionResults);
}
#endregion
#region TreeNodeInfos
#region WaveImpactAsphaltCoverHydraulicLoadsContext TreeNodeInfo
private static object[] HydraulicLoadsChildNodeObjects(WaveImpactAsphaltCoverHydraulicLoadsContext context)
{
WaveImpactAsphaltCoverFailureMechanism failureMechanism = context.WrappedData;
IAssessmentSection assessmentSection = context.Parent;
return new object[]
{
new CategoryTreeFolder(RiskeerCommonFormsResources.FailureMechanism_Inputs_DisplayName,
GetHydraulicLoadsInputs(failureMechanism, assessmentSection), TreeFolderCategory.Input),
new WaveImpactAsphaltCoverWaveConditionsCalculationGroupContext(failureMechanism.WaveConditionsCalculationGroup, null,
failureMechanism, assessmentSection)
};
}
private static IEnumerable