Index: Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs =================================================================== diff -u -rbf926725b3c2994fb1f2d7c8b4294ab66691b3d2 -r35c2e5f60d72d56ae51a816c1cb50396f76357a4 --- Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision bf926725b3c2994fb1f2d7c8b4294ab66691b3d2) +++ Ringtoets/HeightStructures/src/Ringtoets.HeightStructures.Plugin/HeightStructuresPlugin.cs (.../HeightStructuresPlugin.cs) (revision 35c2e5f60d72d56ae51a816c1cb50396f76357a4) @@ -25,8 +25,10 @@ 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.Gui; using Core.Common.Gui.ContextMenu; using Core.Common.Gui.Forms.ProgressDialog; using Core.Common.Gui.Plugin; @@ -35,6 +37,7 @@ using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Data.Probability; using Ringtoets.Common.Data.Structures; using Ringtoets.Common.Forms; @@ -780,9 +783,83 @@ private void UpdateStructureDependentDataOfCalculation(StructuresCalculation calculation) { - // TODO: Implement + string message = + RingtoetsCommonFormsResources.StructuresPlugin_VerifyStructureUpdate_Confirm_calculation_output_cleared_when_updating_Structure_dependent_data; + if (StructureDependentDataShouldUpdate(new[] + { + calculation + }, message)) + { + UpdateStructureDerivedCalculationInput(calculation); + } } + private bool StructureDependentDataShouldUpdate(IEnumerable> calculations, string query) + { + var changeHandler = new CalculationChangeHandler(calculations, + query, + new DialogBasedInquiryHelper(Gui.MainWindow)); + + return !changeHandler.RequireConfirmation() || changeHandler.InquireConfirmation(); + } + + private static void UpdateStructureDerivedCalculationInput(StructuresCalculation calculation) + { + HeightStructuresInput inputParameters = calculation.InputParameters; + + RoundedDouble currentStructureNormalOrientation = inputParameters.StructureNormalOrientation; + NormalDistribution currentLevelCrestStructure = inputParameters.LevelCrestStructure; + LogNormalDistribution currentFlowWidthAtBottomProtection = inputParameters.FlowWidthAtBottomProtection; + VariationCoefficientLogNormalDistribution currentCriticalOvertoppingDischarge = inputParameters.CriticalOvertoppingDischarge; + NormalDistribution currentWidthFlowApertures = inputParameters.WidthFlowApertures; + double currentFailureProbabilityStructureWithErosion = inputParameters.FailureProbabilityStructureWithErosion; + VariationCoefficientLogNormalDistribution currentStorageStructureArea = inputParameters.StorageStructureArea; + LogNormalDistribution currentAllowedLevelIncreaseStorage = inputParameters.AllowedLevelIncreaseStorage; + + // Reapply the structure will update the derived inputs + inputParameters.Structure = inputParameters.Structure; + + var affectedObjects = new List(); + if (IsDerivedInputUpdated(currentStructureNormalOrientation, + currentLevelCrestStructure, + currentFlowWidthAtBottomProtection, + currentCriticalOvertoppingDischarge, + currentWidthFlowApertures, + currentFailureProbabilityStructureWithErosion, + currentStorageStructureArea, + currentAllowedLevelIncreaseStorage, + inputParameters)) + { + affectedObjects.Add(inputParameters); + affectedObjects.AddRange(RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(calculation)); + } + + foreach (IObservable affectedObject in affectedObjects) + { + affectedObject.NotifyObservers(); + } + } + + private static bool IsDerivedInputUpdated(RoundedDouble currentStructureNormalOrientation, + NormalDistribution currentLevelCrestStructure, + LogNormalDistribution currentFlowWidthAtBottomProtection, + VariationCoefficientLogNormalDistribution currentCriticalOvertoppingDischarge, + NormalDistribution currentWidthFlowApertures, + double currentFailureProbabilityStructureWithErosion, + VariationCoefficientLogNormalDistribution currentStorageStructureArea, + LogNormalDistribution currentAllowedLevelIncreaseStorage, + HeightStructuresInput actualInput) + { + return !Equals(currentStructureNormalOrientation, actualInput.StructureNormalOrientation) + || !Equals(currentLevelCrestStructure, actualInput.LevelCrestStructure) + || !Equals(currentFlowWidthAtBottomProtection, actualInput.FlowWidthAtBottomProtection) + || !Equals(currentCriticalOvertoppingDischarge, actualInput.CriticalOvertoppingDischarge) + || !Equals(currentWidthFlowApertures, actualInput.WidthFlowApertures) + || !Equals(currentFailureProbabilityStructureWithErosion, actualInput.FailureProbabilityStructureWithErosion) + || !Equals(currentStorageStructureArea, actualInput.StorageStructureArea) + || !Equals(currentAllowedLevelIncreaseStorage, actualInput.AllowedLevelIncreaseStorage); + } + #endregion #endregion