// 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.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Core.Common.Base;
using Core.Common.Base.Data;
using Core.Common.Base.IO;
using Core.Common.Controls.TreeView;
using Core.Common.Controls.Views;
using Core.Common.Gui;
using Core.Common.Gui.ContextMenu;
using Core.Common.Gui.Forms;
using Core.Common.Gui.Plugin;
using Core.Common.Utils;
using Core.Common.Utils.Extensions;
using Core.Components.Gis.Data;
using log4net;
using Ringtoets.ClosingStructures.Data;
using Ringtoets.ClosingStructures.Forms.PresentationObjects;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.Common.Data.Calculation;
using Ringtoets.Common.Data.Contribution;
using Ringtoets.Common.Data.DikeProfiles;
using Ringtoets.Common.Data.FailureMechanism;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Data.IllustrationPoints;
using Ringtoets.Common.Data.Structures;
using Ringtoets.Common.Forms.ChangeHandlers;
using Ringtoets.Common.Forms.GuiServices;
using Ringtoets.Common.Forms.PresentationObjects;
using Ringtoets.Common.Forms.PropertyClasses;
using Ringtoets.Common.Forms.TreeNodeInfos;
using Ringtoets.Common.Forms.Views;
using Ringtoets.Common.IO.FileImporters;
using Ringtoets.Common.IO.FileImporters.MessageProviders;
using Ringtoets.Common.IO.HydraRing;
using Ringtoets.Common.IO.Hydraulics;
using Ringtoets.Common.IO.ReferenceLines;
using Ringtoets.Common.Service;
using Ringtoets.Common.Utils.TypeConverters;
using Ringtoets.DuneErosion.Data;
using Ringtoets.DuneErosion.Forms.PresentationObjects;
using Ringtoets.DuneErosion.Plugin.Handlers;
using Ringtoets.GrassCoverErosionInwards.Data;
using Ringtoets.GrassCoverErosionInwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionOutwards.Data;
using Ringtoets.GrassCoverErosionOutwards.Forms.PresentationObjects;
using Ringtoets.GrassCoverErosionOutwards.Forms.Views;
using Ringtoets.HeightStructures.Data;
using Ringtoets.HeightStructures.Forms.PresentationObjects;
using Ringtoets.Integration.Data;
using Ringtoets.Integration.Data.StandAlone;
using Ringtoets.Integration.Data.StandAlone.SectionResults;
using Ringtoets.Integration.Forms;
using Ringtoets.Integration.Forms.Commands;
using Ringtoets.Integration.Forms.PresentationObjects;
using Ringtoets.Integration.Forms.PropertyClasses;
using Ringtoets.Integration.Forms.Views;
using Ringtoets.Integration.Forms.Views.SectionResultViews;
using Ringtoets.Integration.Plugin.FileImporters;
using Ringtoets.Integration.Plugin.Handlers;
using Ringtoets.Integration.Service;
using Ringtoets.Integration.Service.MessageProviders;
using Ringtoets.MacroStabilityInwards.Data;
using Ringtoets.MacroStabilityInwards.Forms.PresentationObjects;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms.PresentationObjects;
using Ringtoets.Revetment.Data;
using Ringtoets.Revetment.Forms.PresentationObjects;
using Ringtoets.Revetment.Forms.Views;
using Ringtoets.StabilityPointStructures.Data;
using Ringtoets.StabilityPointStructures.Forms.PresentationObjects;
using Ringtoets.StabilityStoneCover.Data;
using Ringtoets.StabilityStoneCover.Forms.PresentationObjects;
using Ringtoets.StabilityStoneCover.Forms.Views;
using Ringtoets.WaveImpactAsphaltCover.Data;
using Ringtoets.WaveImpactAsphaltCover.Forms.PresentationObjects;
using Ringtoets.WaveImpactAsphaltCover.Forms.Views;
using RingtoetsDataResources = Ringtoets.Integration.Data.Properties.Resources;
using RingtoetsFormsResources = Ringtoets.Integration.Forms.Properties.Resources;
using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources;
using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources;
using RingtoetsCommonServiceResources = Ringtoets.Common.Service.Properties.Resources;
using RingtoetsIntegrationPluginResources = Ringtoets.Integration.Plugin.Properties.Resources;
using BaseResources = Core.Common.Base.Properties.Resources;
using GuiResources = Core.Common.Gui.Properties.Resources;
namespace Ringtoets.Integration.Plugin
{
///
/// The plug-in for the Ringtoets application.
///
public class RingtoetsPlugin : PluginBase
{
private static readonly ILog log = LogManager.GetLogger(typeof(PluginBase));
#region failureMechanismAssociations
private static readonly IEnumerable failureMechanismAssociations = new[]
{
new FailureMechanismContextAssociation(
typeof(PipingFailureMechanism),
(mechanism, assessmentSection) => new PipingFailureMechanismContext(
(PipingFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(GrassCoverErosionInwardsFailureMechanism),
(mechanism, assessmentSection) => new GrassCoverErosionInwardsFailureMechanismContext(
(GrassCoverErosionInwardsFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(HeightStructuresFailureMechanism),
(mechanism, assessmentSection) => new HeightStructuresFailureMechanismContext(
(HeightStructuresFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(DuneErosionFailureMechanism),
(mechanism, assessmentSection) => new DuneErosionFailureMechanismContext(
(DuneErosionFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(GrassCoverErosionOutwardsFailureMechanism),
(mechanism, assessmentSection) => new GrassCoverErosionOutwardsFailureMechanismContext(
(GrassCoverErosionOutwardsFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(GrassCoverSlipOffInwardsFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(GrassCoverSlipOffOutwardsFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(MicrostabilityFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(PipingStructureFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(StabilityStoneCoverFailureMechanism),
(mechanism, assessmentSection) => new StabilityStoneCoverFailureMechanismContext(
(StabilityStoneCoverFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(TechnicalInnovationFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(StrengthStabilityLengthwiseConstructionFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(WaveImpactAsphaltCoverFailureMechanism),
(mechanism, assessmentSection) => new WaveImpactAsphaltCoverFailureMechanismContext(
(WaveImpactAsphaltCoverFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(WaterPressureAsphaltCoverFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(ClosingStructuresFailureMechanism),
(mechanism, assessmentSection) => new ClosingStructuresFailureMechanismContext(
(ClosingStructuresFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(MacroStabilityInwardsFailureMechanism),
(mechanism, assessmentSection) => new MacroStabilityInwardsFailureMechanismContext(
(MacroStabilityInwardsFailureMechanism) mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(MacrostabilityOutwardsFailureMechanism),
(mechanism, assessmentSection) => new FailureMechanismContext(
mechanism,
assessmentSection)
),
new FailureMechanismContextAssociation(
typeof(StabilityPointStructuresFailureMechanism),
(mechanism, assessmentSection) => new StabilityPointStructuresFailureMechanismContext(
(StabilityPointStructuresFailureMechanism) mechanism,
assessmentSection)
)
};
#endregion
private RingtoetsRibbon ribbonCommandHandler;
private IAssessmentSectionFromFileCommandHandler assessmentSectionFromFileCommandHandler;
private IHydraulicBoundaryLocationCalculationGuiService hydraulicBoundaryLocationCalculationGuiService;
public override IRibbonCommandHandler RibbonCommandHandler
{
get
{
return ribbonCommandHandler;
}
}
public override IGui Gui
{
get
{
return base.Gui;
}
set
{
RemoveOnOpenProjectListener(base.Gui);
base.Gui = value;
AddOnOpenProjectListener(value);
}
}
public override void Activate()
{
base.Activate();
if (Gui == null)
{
throw new InvalidOperationException("Gui cannot be null");
}
assessmentSectionFromFileCommandHandler = new AssessmentSectionFromFileCommandHandler(Gui.MainWindow, Gui, Gui.DocumentViewController);
hydraulicBoundaryLocationCalculationGuiService = new HydraulicBoundaryLocationCalculationGuiService(Gui.MainWindow);
ribbonCommandHandler = new RingtoetsRibbon
{
AddAssessmentSectionButtonCommand = new AddAssessmentSectionCommand(assessmentSectionFromFileCommandHandler)
};
}
///
/// Returns all instances provided for data of .
///
public override IEnumerable GetPropertyInfos()
{
yield return new PropertyInfo();
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = data => new BackgroundDataProperties(data)
};
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new FailureMechanismContributionProperties(
context.WrappedData,
context.Parent,
new FailureMechanismContributionNormChangeHandler(),
new AssessmentSectionCompositionChangeHandler(Gui.ViewCommands))
};
yield return new PropertyInfo, StandAloneFailureMechanismContextProperties>();
yield return new PropertyInfo, CalculationGroupContextProperties>();
yield return new PropertyInfo, CalculationContextProperties>();
yield return new PropertyInfo
{
CreateInstance = context => new StructuresOutputProperties(context.WrappedData.Output)
};
yield return new PropertyInfo
{
CreateInstance = context => new DesignWaterLevelLocationsContextProperties(
context.WrappedData.HydraulicBoundaryDatabase)
};
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new WaveHeightLocationsContextProperties(
context.WrappedData.HydraulicBoundaryDatabase)
};
yield return new PropertyInfo();
yield return new PropertyInfo();
yield return new PropertyInfo
{
CreateInstance = context => new ForeshoreProfileCollectionProperties(context.WrappedData)
};
yield return new PropertyInfo
{
CreateInstance = illustrationPoint =>
{
var topLevelIllustrationPoint = illustrationPoint.TopLevelIllustrationPoint as TopLevelSubMechanismIllustrationPoint;
if (topLevelIllustrationPoint != null)
{
return new TopLevelSubMechanismIllustrationPointProperties(topLevelIllustrationPoint,
illustrationPoint.ClosingSituations);
}
return null;
}
};
}
///
/// Returns all instances provided for data of .
///
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo
{
GetViewName = (view, context) => RingtoetsDataResources.FailureMechanismContribution_DisplayName,
GetViewData = context => context.WrappedData,
Image = RingtoetsCommonFormsResources.FailureMechanismContributionIcon,
CloseForData = CloseFailureMechanismContributionViewForData,
CreateInstance = context => new FailureMechanismContributionView(Gui.ViewCommands),
AfterCreate = (view, context) => view.AssessmentSection = context.Parent
};
yield return new ViewInfo, DesignWaterLevelLocationsView>
{
GetViewName = (view, context) => RingtoetsFormsResources.DesignWaterLevelLocationsContext_DisplayName,
GetViewData = context => context.WrappedData.HydraulicBoundaryDatabase?.Locations,
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
CloseForData = CloseHydraulicBoundaryLocationsViewForData,
CreateInstance = context => new DesignWaterLevelLocationsView(context.WrappedData),
AfterCreate = (view, context) => { view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; }
};
yield return new ViewInfo, WaveHeightLocationsView>
{
GetViewName = (view, context) => RingtoetsFormsResources.WaveHeightLocationsContext_DisplayName,
GetViewData = context => context.WrappedData.HydraulicBoundaryDatabase?.Locations,
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
CloseForData = CloseHydraulicBoundaryLocationsViewForData,
CreateInstance = context => new WaveHeightLocationsView(context.WrappedData),
AfterCreate = (view, context) => { view.CalculationGuiService = hydraulicBoundaryLocationCalculationGuiService; }
};
yield return new ViewInfo
{
GetViewName = (view, section) => RingtoetsFormsResources.AssessmentSectionMap_DisplayName,
Image = RingtoetsFormsResources.Map
};
yield return new ViewInfo, FailureMechanismView>
{
GetViewName = (view, context) => context.WrappedData.Name,
Image = RingtoetsCommonFormsResources.CalculationIcon,
CloseForData = CloseFailureMechanismViewForData,
AdditionalDataCheck = context => context.WrappedData.IsRelevant
};
yield return CreateFailureMechanismResultViewInfo<
GrassCoverSlipOffInwardsFailureMechanismSectionResult,
GrassCoverSlipOffInwardsResultView>();
yield return CreateFailureMechanismResultViewInfo<
GrassCoverSlipOffOutwardsFailureMechanismSectionResult,
GrassCoverSlipOffOutwardsResultView>();
yield return CreateFailureMechanismResultViewInfo<
MicrostabilityFailureMechanismSectionResult,
MicrostabilityResultView>();
yield return CreateFailureMechanismResultViewInfo<
PipingStructureFailureMechanismSectionResult,
PipingStructureResultView>();
yield return CreateFailureMechanismResultViewInfo<
TechnicalInnovationFailureMechanismSectionResult,
TechnicalInnovationResultView>();
yield return CreateFailureMechanismResultViewInfo<
StrengthStabilityLengthwiseConstructionFailureMechanismSectionResult,
StrengthStabilityLengthwiseConstructionResultView>();
yield return CreateFailureMechanismResultViewInfo<
WaterPressureAsphaltCoverFailureMechanismSectionResult,
WaterPressureAsphaltCoverResultView>();
yield return CreateFailureMechanismResultViewInfo<
MacrostabilityOutwardsFailureMechanismSectionResult,
MacrostabilityOutwardsResultView>();
yield return new ViewInfo
{
GetViewName = (view, context) => RingtoetsIntegrationPluginResources.Comment_DisplayName,
GetViewData = context => context,
Image = RingtoetsCommonFormsResources.EditDocumentIcon,
CloseForData = CloseCommentViewForData
};
yield return new ViewInfo, WaveConditionsInputView>
{
Image = RingtoetsCommonFormsResources.GenericInputOutputIcon,
GetViewName = (view, context) => RingtoetsCommonFormsResources.Calculation_Input,
GetViewData = context => context.Calculation,
CloseForData = CloseCalculationViewForData>,
CreateInstance = context => new WaveConditionsInputView(GetWaveConditionsInputViewStyle(context))
};
yield return new ViewInfo
{
Image = RingtoetsCommonFormsResources.GeneralOutputIcon,
GetViewName = (view, context) => RingtoetsCommonFormsResources.CalculationOutput_DisplayName,
GetViewData = context => context.WrappedData,
CloseForData = CloseCalculationViewForData,
CreateInstance = context => new GeneralResultFaultTreeIllustrationPointView(() => context.WrappedData.Output?.GeneralResult)
};
}
public override IEnumerable GetImportInfos()
{
yield return new ImportInfo
{
Name = RingtoetsCommonDataResources.ReferenceLine_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsCommonFormsResources.ReferenceLineIcon,
FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension,
RingtoetsCommonIOResources.Shape_file_filter_Description),
CreateFileImporter = (context, filePath) => new ReferenceLineImporter(context.WrappedData,
new ReferenceLineReplacementHandler(Gui.ViewCommands),
filePath)
};
yield return new ImportInfo
{
Name = RingtoetsCommonFormsResources.FailureMechanism_Sections_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsCommonFormsResources.SectionsIcon,
FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension,
RingtoetsCommonIOResources.Shape_file_filter_Description),
IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null,
CreateFileImporter = (context, filePath) => new FailureMechanismSectionsImporter(context.WrappedData,
context.ParentAssessmentSection.ReferenceLine,
filePath)
};
yield return new ImportInfo
{
CreateFileImporter = (context, filePath) =>
new ForeshoreProfilesImporter(context.WrappedData,
context.ParentAssessmentSection.ReferenceLine,
filePath,
new ForeshoreProfileReplaceDataStrategy(context.ParentFailureMechanism,
context.WrappedData),
new ImportMessageProvider()),
Name = RingtoetsIntegrationPluginResources.ForeshoreProfilesImporter_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsIntegrationPluginResources.Foreshore,
FileFilterGenerator = CreateForeshoreProfileFileFilterGenerator,
IsEnabled = context => context.ParentAssessmentSection.ReferenceLine != null,
VerifyUpdates = context => VerifyForeshoreProfileUpdates(context, RingtoetsIntegrationPluginResources.RingtoetsPlugin_VerifyForeshoreProfileUpdates_When_importing_ForeshoreProfile_definitions_assigned_to_calculations_output_will_be_cleared_confirm)
};
}
public override IEnumerable GetExportInfos()
{
yield return new ExportInfo
{
Name = RingtoetsCommonDataResources.ReferenceLine_DisplayName,
CreateFileExporter = (context, filePath) => new ReferenceLineExporter(context.WrappedData.ReferenceLine, context.WrappedData.Id, filePath),
IsEnabled = context => context.WrappedData.ReferenceLine != null,
FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension,
RingtoetsCommonIOResources.Shape_file_filter_Description)
};
yield return new ExportInfo
{
Name = RingtoetsCommonDataResources.HydraulicBoundaryConditions_DisplayName,
CreateFileExporter = (context, filePath) => new HydraulicBoundaryLocationsExporter(
context.WrappedData.HydraulicBoundaryDatabase.Locations, filePath,
RingtoetsIntegrationPluginResources.DesignWaterLevel_Description, RingtoetsIntegrationPluginResources.WaveHeight_Description),
IsEnabled = context => context.WrappedData.HydraulicBoundaryDatabase != null,
FileFilterGenerator = new FileFilterGenerator(RingtoetsCommonIOResources.Shape_file_filter_Extension,
RingtoetsCommonIOResources.Shape_file_filter_Description)
};
}
public override IEnumerable GetUpdateInfos()
{
yield return new UpdateInfo
{
CreateFileImporter = (context, filePath) =>
new ForeshoreProfilesImporter(context.WrappedData,
context.ParentAssessmentSection.ReferenceLine,
filePath,
new ForeshoreProfileUpdateDataStrategy(context.ParentFailureMechanism, context.WrappedData),
new UpdateMessageProvider()),
Name = RingtoetsIntegrationPluginResources.ForeshoreProfilesImporter_DisplayName,
Category = RingtoetsCommonFormsResources.Ringtoets_Category,
Image = RingtoetsIntegrationPluginResources.Foreshore,
FileFilterGenerator = CreateForeshoreProfileFileFilterGenerator,
CurrentPath = context => context.WrappedData.SourcePath,
IsEnabled = context => context.WrappedData.SourcePath != null,
VerifyUpdates = context => VerifyForeshoreProfileUpdates(context, RingtoetsIntegrationPluginResources.RingtoetsPlugin_VerifyForeshoreProfileUpdates_When_updating_ForeshoreProfile_definitions_assigned_to_calculations_output_will_be_cleared_confirm)
};
}
///
/// Gets the child data instances that have definitions of some parent data object.
///
/// The parent data object.
/// Sequence of child data.
public override IEnumerable