Index: Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs =================================================================== diff -u -r69eb8c7057601ce45297368b9281ea1e60980f28 -r60d95df18eb252bf99dff07a76d9660f331c92c2 --- Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 69eb8c7057601ce45297368b9281ea1e60980f28) +++ Ringtoets/Piping/src/Ringtoets.Piping.Forms/PropertyClasses/PipingInputContextProperties.cs (.../PipingInputContextProperties.cs) (revision 60d95df18eb252bf99dff07a76d9660f331c92c2) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; @@ -32,8 +33,8 @@ using Ringtoets.Common.Data.Probabilistics; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; +using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.UITypeEditors; -using Ringtoets.Common.Service; using Ringtoets.Piping.Data; using Ringtoets.Piping.Forms.PresentationObjects; using Ringtoets.Piping.Forms.Properties; @@ -70,7 +71,31 @@ private const int diameter70PropertyIndex = 17; private const int saturatedVolumicWeightOfCoverageLayerPropertyIndex = 18; + private readonly ICalculationInputPropertyChangeHandler propertyChangeHandler; + /// + /// Creates a new instance of . + /// + /// The instance to show the properties for. + /// The handler responsible for handling effects of a property change. + /// Thrown when any parameter is null. + public PipingInputContextProperties(PipingInputContext data, + ICalculationInputPropertyChangeHandler handler) + { + if (data == null) + { + throw new ArgumentNullException(nameof(data)); + } + if (handler == null) + { + throw new ArgumentNullException(nameof(handler)); + } + + Data = data; + propertyChangeHandler = handler; + } + + /// /// Gets the available surface lines on . /// public IEnumerable GetAvailableSurfaceLines() @@ -125,9 +150,7 @@ /// public IEnumerable GetSelectableHydraulicBoundaryLocations() { - Point2D referencePoint = SurfaceLine == null || SurfaceLine.ReferenceLineIntersectionWorldPoint == null - ? null - : SurfaceLine.ReferenceLineIntersectionWorldPoint; + Point2D referencePoint = SurfaceLine?.ReferenceLineIntersectionWorldPoint; return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( data.AvailableHydraulicBoundaryLocations, referencePoint); } @@ -144,7 +167,7 @@ { get { - Point2D referencePoint = SurfaceLine != null ? SurfaceLine.ReferenceLineIntersectionWorldPoint : null; + Point2D referencePoint = SurfaceLine?.ReferenceLineIntersectionWorldPoint; return data.WrappedData.HydraulicBoundaryLocation != null ? new SelectableHydraulicBoundaryLocation(data.WrappedData.HydraulicBoundaryLocation, @@ -153,8 +176,7 @@ } set { - data.WrappedData.HydraulicBoundaryLocation = value.HydraulicBoundaryLocation; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.HydraulicBoundaryLocation = v, value.HydraulicBoundaryLocation); } } @@ -171,8 +193,7 @@ } set { - data.WrappedData.AssessmentLevel = value; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.AssessmentLevel = v, value); } } @@ -188,8 +209,7 @@ } set { - data.WrappedData.UseAssessmentLevelManualInput = value; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.UseAssessmentLevelManualInput = v, value); } } @@ -206,8 +226,7 @@ } set { - data.WrappedData.DampingFactorExit = value.Distribution; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.DampingFactorExit = v, value.Distribution); } } @@ -224,8 +243,7 @@ } set { - data.WrappedData.PhreaticLevelExit = value.Distribution; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.PhreaticLevelExit = v, value.Distribution); } } @@ -260,9 +278,11 @@ { if (!ReferenceEquals(value, data.WrappedData.SurfaceLine)) { - data.WrappedData.SurfaceLine = value; - PipingInputService.SetMatchingStochasticSoilModel(data.WrappedData, GetAvailableStochasticSoilModels()); - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => + { + input.SurfaceLine = v; + PipingInputService.SetMatchingStochasticSoilModel(input, GetAvailableStochasticSoilModels()); + }, value); } } } @@ -282,9 +302,11 @@ { if (!ReferenceEquals(value, data.WrappedData.StochasticSoilModel)) { - data.WrappedData.StochasticSoilModel = value; - PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(data.WrappedData); - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => + { + input.StochasticSoilModel = v; + PipingInputService.SyncStochasticSoilProfileWithStochasticSoilModel(input); + }, value); } } } @@ -304,8 +326,7 @@ { if (!ReferenceEquals(value, data.WrappedData.StochasticSoilProfile)) { - data.WrappedData.StochasticSoilProfile = value; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.StochasticSoilProfile = v, value); } } } @@ -322,8 +343,7 @@ } set { - data.WrappedData.EntryPointL = value; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.EntryPointL = v, value); } } @@ -339,8 +359,7 @@ } set { - data.WrappedData.ExitPointL = value; - ClearOutputAndNotifyPropertyChanged(); + ChangePropertyValueAndNotifyAffectedObjects((input, v) => input.ExitPointL = v, value); } } @@ -437,14 +456,26 @@ #endregion - private void ClearOutputAndNotifyPropertyChanged() + + private void ChangePropertyValueAndNotifyAffectedObjects( + SetCalculationInputPropertyValueDelegate setPropertyValue, + TValue value) { - IEnumerable affectedCalculation = RingtoetsCommonDataSynchronizationService.ClearCalculationOutput(data.PipingCalculation); - foreach (var calculation in affectedCalculation) + IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation( + data.WrappedData, + data.PipingCalculation, + value, + setPropertyValue); + + NotifyAffectedObjects(affectedObjects); + } + + private static void NotifyAffectedObjects(IEnumerable affectedObjects) + { + foreach (var affectedObject in affectedObjects) { - calculation.NotifyObservers(); + affectedObject.NotifyObservers(); } - data.WrappedData.NotifyObservers(); } } } \ No newline at end of file