// 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.Generic; using System.ComponentModel; using Core.Common.Base; using Core.Common.Gui.Attributes; using Core.Common.Gui.PropertyBag; using Core.Common.Utils; using Core.Common.Utils.Attributes; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Contribution; using Ringtoets.Common.Forms.ChangeHandlers; using Ringtoets.Common.Forms.Helpers; using Ringtoets.Common.Forms.PropertyClasses; using Ringtoets.Integration.Forms.Properties; using RingtoetsCommonFormsResources = Ringtoets.Common.Forms.Properties.Resources; namespace Ringtoets.Integration.Forms.PropertyClasses { /// /// ViewModel of for properties panel. /// public class FailureMechanismContributionProperties : ObjectProperties { private readonly IObservablePropertyChangeHandler normChangeHandler; private readonly IAssessmentSectionCompositionChangeHandler compositionChangeHandler; private readonly IAssessmentSection assessmentSection; /// /// Creates a new instance of . /// /// The for which the properties are shown. /// The assessment section for which the properties are shown. /// The for when the norm changes. /// The for when the composition changes. /// Thrown when any parameter is null. public FailureMechanismContributionProperties( FailureMechanismContribution failureMechanismContribution, IAssessmentSection assessmentSection, IObservablePropertyChangeHandler normChangeHandler, IAssessmentSectionCompositionChangeHandler compositionChangeHandler) { if (failureMechanismContribution == null) { throw new ArgumentNullException(nameof(failureMechanismContribution)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (normChangeHandler == null) { throw new ArgumentNullException(nameof(normChangeHandler)); } if (compositionChangeHandler == null) { throw new ArgumentNullException(nameof(compositionChangeHandler)); } Data = failureMechanismContribution; this.normChangeHandler = normChangeHandler; this.compositionChangeHandler = compositionChangeHandler; this.assessmentSection = assessmentSection; } [PropertyOrder(1)] [TypeConverter(typeof(EnumTypeConverter))] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.FailureMechanismContribution_Composition_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.FailureMechanismContribution_Composition_Description))] public AssessmentSectionComposition AssessmentSectionComposition { get { return assessmentSection.Composition; } set { if (compositionChangeHandler.ConfirmCompositionChange()) { IEnumerable changedObjects = compositionChangeHandler.ChangeComposition(assessmentSection, value); foreach (IObservable changedObject in changedObjects) { changedObject.NotifyObservers(); } data.NotifyObservers(); } } } [PropertyOrder(2)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.SignalingNorm_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.SignalingNorm_Description))] public string SignalingNorm { get { return ProbabilityFormattingHelper.Format(data.SignalingNorm); } set { PropertyChangeHelper.ChangePropertyAndNotify(() => data.SignalingNorm = GetProbabilityValue(value), normChangeHandler); } } [PropertyOrder(3)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.LowerLimitNorm_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.LowerLimitNorm_Description))] public string LowerLimitNorm { get { return ProbabilityFormattingHelper.Format(data.LowerLimitNorm); } set { PropertyChangeHelper.ChangePropertyAndNotify(() => data.LowerLimitNorm = GetProbabilityValue(value), normChangeHandler); } } [PropertyOrder(4)] [ResourcesCategory(typeof(RingtoetsCommonFormsResources), nameof(RingtoetsCommonFormsResources.Categories_General))] [ResourcesDisplayName(typeof(Resources), nameof(Resources.NormType_DisplayName))] [ResourcesDescription(typeof(Resources), nameof(Resources.NormType_Description))] [TypeConverter(typeof(EnumTypeConverter))] public NormType NormativeNorm { get { return data.NormativeNorm; } set { PropertyChangeHelper.ChangePropertyAndNotify(() => data.NormativeNorm = value, normChangeHandler); } } /// /// Gets a probability value based on the input string value. /// /// The probability value to convert. /// Thrown when equals null. /// Thrown when cannot be parsed into a double. private static double GetProbabilityValue(string value) { if (value == null) { throw new ArgumentNullException(nameof(value), RingtoetsCommonFormsResources.Probability_Value_cannot_be_null); } try { return ProbabilityFormattingHelper.Parse(value); } catch (OverflowException) { throw new ArgumentException(RingtoetsCommonFormsResources.Probability_Value_too_large); } catch (FormatException) { throw new ArgumentException(RingtoetsCommonFormsResources.Probability_Could_not_parse_string_to_double_value); } } } }