// Copyright (C) Stichting Deltares 2016. 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.Generic; using System.ComponentModel; using System.Drawing.Design; using System.Linq; using Core.Common.Base; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Core.Common.Gui.Attributes; using Core.Common.Gui.Converters; using Core.Common.Gui.PropertyBag; using Core.Common.Utils; using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.DikeProfiles; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PresentationObjects; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Common.Forms.UITypeEditors; using Ringtoets.Revetment.Data; using Ringtoets.Revetment.Forms.PresentationObjects; using Ringtoets.Revetment.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Revetment.Forms.PropertyClasses { /// /// ViewModel of for properties panel. /// public abstract class WaveConditionsInputContextProperties : ObjectProperties, IHasHydraulicBoundaryLocationProperty, IHasForeshoreProfileProperty where T : WaveConditionsInputContext { private const int hydraulicBoundaryLocationPropertyIndex = 0; private const int assessmentLevelPropertyIndex = 1; private const int upperBoundaryDesignWaterLevelPropertyIndex = 2; private const int upperBoundaryRevetmentPropertyIndex = 3; private const int lowerBoundaryRevetmentPropertyIndex = 4; private const int upperBoundaryWaterLevelsPropertyIndex = 5; private const int lowerBoundaryWaterLevelsPropertyIndex = 6; private const int stepSizePropertyIndex = 7; private const int waterLevelsPropertyIndex = 8; private const int foreshoreProfilePropertyIndex = 9; private const int worldReferencePointPropertyIndex = 10; private const int orientationPropertyIndex = 11; private const int breakWaterPropertyIndex = 12; private const int foreshoreGeometryPropertyIndex = 13; private const int revetmentTypePropertyIndex = 14; private readonly IObservablePropertyChangeHandler propertyChangeHandler; /// /// Creates a new instance of . /// /// The for which the properties are shown. /// The handler responsible for handling effects of a property change. /// Thrown when any parameter is null. protected WaveConditionsInputContextProperties(T context, IObservablePropertyChangeHandler handler) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } propertyChangeHandler = handler; Data = context; } [PropertyOrder(assessmentLevelPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.AssessmentLevel_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.AssessmentLevel_Description))] public virtual RoundedDouble AssessmentLevel { get { return data.WrappedData.AssessmentLevel; } } [PropertyOrder(upperBoundaryDesignWaterLevelPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryDesignWaterLevel_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryDesignWaterLevel_Description))] public virtual RoundedDouble UpperBoundaryDesignWaterLevel { get { return data.WrappedData.UpperBoundaryDesignWaterLevel; } } [PropertyOrder(upperBoundaryRevetmentPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryRevetment_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryRevetment_Description))] public RoundedDouble UpperBoundaryRevetment { get { return data.WrappedData.UpperBoundaryRevetment; } set { ChangePropertyAndNotify(() => data.WrappedData.UpperBoundaryRevetment = value); } } [PropertyOrder(lowerBoundaryRevetmentPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_LowerBoundaryRevetment_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_LowerBoundaryRevetment_Description))] public RoundedDouble LowerBoundaryRevetment { get { return data.WrappedData.LowerBoundaryRevetment; } set { ChangePropertyAndNotify(() => data.WrappedData.LowerBoundaryRevetment = value); } } [PropertyOrder(upperBoundaryWaterLevelsPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryWaterLevels_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_UpperBoundaryWaterLevels_Description))] public RoundedDouble UpperBoundaryWaterLevels { get { return data.WrappedData.UpperBoundaryWaterLevels; } set { ChangePropertyAndNotify(() => data.WrappedData.UpperBoundaryWaterLevels = value); } } [PropertyOrder(lowerBoundaryWaterLevelsPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_LowerBoundaryWaterLevels_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_LowerBoundaryWaterLevels_Description))] public RoundedDouble LowerBoundaryWaterLevels { get { return data.WrappedData.LowerBoundaryWaterLevels; } set { ChangePropertyAndNotify(() => data.WrappedData.LowerBoundaryWaterLevels = value); } } [PropertyOrder(stepSizePropertyIndex)] [TypeConverter(typeof(EnumTypeConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_StepSize_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_StepSize_Description))] public WaveConditionsInputStepSize StepSize { get { return data.WrappedData.StepSize; } set { ChangePropertyAndNotify(() => data.WrappedData.StepSize = value); } } [PropertyOrder(waterLevelsPropertyIndex)] [TypeConverter(typeof(ExpandableReadOnlyArrayConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_WaterLevels_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_WaterLevels_Description))] public RoundedDouble[] WaterLevels { get { return data.WrappedData.WaterLevels.ToArray(); } } [PropertyOrder(worldReferencePointPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.WorldReferencePoint_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.WorldReferencePoint_ForeshoreProfile_Description))] public Point2D WorldReferencePoint { get { return data.WrappedData.ForeshoreProfile == null ? null : new Point2D( new RoundedDouble(0, data.WrappedData.ForeshoreProfile.WorldReferencePoint.X), new RoundedDouble(0, data.WrappedData.ForeshoreProfile.WorldReferencePoint.Y)); } } [PropertyOrder(orientationPropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Orientation_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Orientation_ForeshoreProfile_Description))] public RoundedDouble Orientation { get { return data.WrappedData.Orientation; } set { ChangePropertyAndNotify(() => data.WrappedData.Orientation = value); } } [PropertyOrder(breakWaterPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.BreakWaterProperties_Description))] public UseBreakWaterProperties BreakWater { get { return data.WrappedData.ForeshoreProfile == null ? new UseBreakWaterProperties() : new UseBreakWaterProperties(data.WrappedData, propertyChangeHandler); } } [PropertyOrder(foreshoreGeometryPropertyIndex)] [TypeConverter(typeof(ExpandableObjectConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.ForeshoreProperties_Description))] public UseForeshoreProperties ForeshoreGeometry { get { return new UseForeshoreProperties(data.WrappedData, propertyChangeHandler); } } [PropertyOrder(revetmentTypePropertyIndex)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.WaveConditionsInput_RevetmentType_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.WaveConditionsInput_RevetmentType_Description))] public abstract string RevetmentType { get; } [PropertyOrder(foreshoreProfilePropertyIndex)] [Editor(typeof(ForeshoreProfileEditor), typeof(UITypeEditor))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_Schematization))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.ForeshoreProfile_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.ForeshoreProfile_Description))] public ForeshoreProfile ForeshoreProfile { get { return data.WrappedData.ForeshoreProfile; } set { ChangePropertyAndNotify(() => data.WrappedData.ForeshoreProfile = value); } } [PropertyOrder(hydraulicBoundaryLocationPropertyIndex)] [Editor(typeof(HydraulicBoundaryLocationEditor), typeof(UITypeEditor))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_HydraulicData))] [ResourcesDisplayName(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.HydraulicBoundaryLocation_DisplayName))] [ResourcesDescription(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.HydraulicBoundaryLocation_Description))] public virtual SelectableHydraulicBoundaryLocation SelectedHydraulicBoundaryLocation { get { Point2D referenceLocation = data.WrappedData.ForeshoreProfile?.WorldReferencePoint; return data.WrappedData.HydraulicBoundaryLocation != null ? new SelectableHydraulicBoundaryLocation(data.WrappedData.HydraulicBoundaryLocation, referenceLocation) : null; } set { ChangePropertyAndNotify(() => data.WrappedData.HydraulicBoundaryLocation = value.HydraulicBoundaryLocation); } } public virtual IEnumerable GetAvailableForeshoreProfiles() { return data.ForeshoreProfiles; } public IEnumerable GetSelectableHydraulicBoundaryLocations() { Point2D referenceLocation = data.WrappedData.ForeshoreProfile?.WorldReferencePoint; return SelectableHydraulicBoundaryLocationHelper.GetSortedSelectableHydraulicBoundaryLocations( data.HydraulicBoundaryLocations, referenceLocation); } private void ChangePropertyAndNotify(SetObservablePropertyValueDelegate setPropertyValue) { IEnumerable affectedObjects = propertyChangeHandler.SetPropertyValueAfterConfirmation(setPropertyValue); NotifyAffectedObjects(affectedObjects); } private static void NotifyAffectedObjects(IEnumerable affectedObjects) { foreach (var affectedObject in affectedObjects) { affectedObject.NotifyObservers(); } } } }