// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of the application DAM - Clients Library. // // DAM - UI 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.Collections; using System.ComponentModel; using System.Xml.Serialization; using Deltares.Dam.Data.UISupport; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using Deltares.Standard.Validation; namespace Deltares.Dam.Data { using System; /// /// /// public class DamFailureMechanismeCalculationSpecification: IDomain, IVisibleEnabled { private FailureMechanismSystemType failureMechanismSystemType; private PipingModelType pipingModelType = PipingModelType.Sellmeijer4Forces; private Enum calculationModel; private FailureMechanismeParamatersMStab failureMechanismeParamatersMStab; private static ProbabilisticType probabilisticType; private static DamProjectType damProjectType; private StabilityKernelType stabilityKernelType = StabilityKernelType.DamClassicStabilty; private Boolean firstTime = true; public DamFailureMechanismeCalculationSpecification() { //Todo interface failureMechanismSystemType = FailureMechanismSystemType.StabilityInside; failureMechanismeParamatersMStab = new FailureMechanismeParamatersMStab(); CalculationModel = failureMechanismeParamatersMStab.MStabParameters.Model; FailureMechanismeParamatersMStab.MStabParameters.GridPosition = MStabGridPosition.Right; ReadUserSettingsSlipCircleDefinition(); } [Browsable(false)] [Validate] public FailureMechanismeParamatersMStab FailureMechanismeParamatersMStab { get { return failureMechanismeParamatersMStab; } set { failureMechanismeParamatersMStab = value; } } [Label("Failure mechanism")] [PropertyOrder(1, 0)] public FailureMechanismSystemType FailureMechanismSystemType { get { return failureMechanismSystemType; } set { // Make sure the set is done for the very first time too even when the value has not changed (MWDAM-1199). if (failureMechanismSystemType != value || firstTime) { firstTime = false; DataEventPublisher.BeforeChange(this, "FailureMechanismSystemType"); failureMechanismSystemType = value; // To solve MWDAM-592, remember the current pipingmodeltype as this gets reset by setting the // calculationmodel. Only switch it back when needed. var oldPipingModelType = pipingModelType; foreach (Enum possibleModel in this.GetDomain("CalculationModel")) { this.CalculationModel = possibleModel; break; } switch (failureMechanismSystemType) { case FailureMechanismSystemType.StabilityInside: failureMechanismeParamatersMStab.MStabParameters.GridPosition = MStabGridPosition.Right; break; case FailureMechanismSystemType.StabilityOutside: failureMechanismeParamatersMStab.MStabParameters.GridPosition = MStabGridPosition.Left; break; case FailureMechanismSystemType.Piping: PipingModelType = oldPipingModelType; break; } DataEventPublisher.AfterChange(this, "FailureMechanismSystemType"); } } } [Browsable(false)] public PipingModelType PipingModelType { get { return pipingModelType; } set { pipingModelType = value; if (failureMechanismSystemType == FailureMechanismSystemType.Piping) { CalculationModel = pipingModelType; } } } [Browsable(false)] public static DamProjectType DamProjectType { get { return damProjectType; } set { damProjectType = value; } } [Browsable(false)] public static ProbabilisticType ProbabilisticType { get { return probabilisticType; } set { probabilisticType = value; } } /// /// The calculationmodel is only needed to support the selection of the modeltype in the UI. The dropdownlist /// in the UI depends on this. This set can be filled with any proper types (for piping, stabilty etc) for any /// mechanisme instead of the fixed types per mechanisme. /// [XmlIgnore] [Label("Model")] [PropertyOrder(1, 1)] public Enum CalculationModel { get { return calculationModel; } set { DataEventPublisher.BeforeChange(this, "CalculationModel"); calculationModel = value; if (value is PipingModelType) { pipingModelType = (PipingModelType) value; } else { failureMechanismeParamatersMStab.MStabParameters.Model = (MStabModelType)value; } DataEventPublisher.AfterChange(this, "CalculationModel"); } } [Browsable(false)] public MStabModelType StabilityModelType { get { return failureMechanismeParamatersMStab.MStabParameters.Model; } set { failureMechanismeParamatersMStab.MStabParameters.Model = value; if (failureMechanismSystemType != FailureMechanismSystemType.Piping) { CalculationModel = value; } } } [Browsable(false)] public StabilityKernelType StabilityKernelType { get { return stabilityKernelType; } set { stabilityKernelType = value; } } public void Assign(DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculation) { failureMechanismSystemType = damFailureMechanismeCalculation.FailureMechanismSystemType; calculationModel = damFailureMechanismeCalculation.CalculationModel; pipingModelType = damFailureMechanismeCalculation.pipingModelType; failureMechanismeParamatersMStab.Assign(damFailureMechanismeCalculation.FailureMechanismeParamatersMStab); StabilityModelType = damFailureMechanismeCalculation.StabilityModelType; stabilityKernelType = damFailureMechanismeCalculation.StabilityKernelType; //assign interface } public DamFailureMechanismeCalculationSpecification Clone() { DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculation = new DamFailureMechanismeCalculationSpecification(); damFailureMechanismeCalculation.Assign(this); return damFailureMechanismeCalculation; } public override string ToString() { string description = ""; description += String.Format("{0}", StabilityKernelType); description += String.Format("{0}", this.FailureMechanismSystemType); if ((this.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside) || (this.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside)) { //interface? description += String.Format(" ({0})", this.FailureMechanismeParamatersMStab.MStabParameters.Model); } return description; } public ICollection GetDomain(string property) { switch (property) { case "CalculationModel": return (ConfigurationManager.Instance.GetAvailableMechanismModels(StabilityKernelType, DamProjectType, ProbabilisticType, failureMechanismSystemType)); case "PipingModelType": return (ConfigurationManager.Instance.GetAvailableMechanismModels(StabilityKernelType, DamProjectType, ProbabilisticType, FailureMechanismSystemType.Piping)); case "FailureMechanismSystemType": return (ConfigurationManager.Instance.GetAvailableFailureMechanisms(StabilityKernelType, DamProjectType, ProbabilisticType)); case "StabilityKernelType": return (ConfigurationManager.Instance.GetAvailableFailureMechanisms(StabilityKernelType, DamProjectType, ProbabilisticType)); default: return null; } } public bool IsEnabled(string property) { return true; } public bool IsVisible(string property) { switch (property) { case "FailureMechanismeParamatersMStab": switch (this.FailureMechanismSystemType) { case Data.FailureMechanismSystemType.StabilityInside: return true; case Data.FailureMechanismSystemType.StabilityOutside: return true; case Data.FailureMechanismSystemType.HorizontalBalance: return false; case Data.FailureMechanismSystemType.Piping: return false; default: return true; } default: return true; } } /// /// Determines whether slip circle definition is undefined. /// /// /// true if [is slip circle definition undefined]; otherwise, false. /// public bool IsSlipCircleDefinitionUndefined() { bool isSlipCircleDefinitionUndefined = (failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition == null); if (!isSlipCircleDefinitionUndefined) { isSlipCircleDefinitionUndefined = (failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridHorizontalPointCount == 0); } return isSlipCircleDefinitionUndefined; } /// /// Reads the user settings. /// public void ReadUserSettingsSlipCircleDefinition() { if (failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition == null) { failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition = new SlipCircleDefinition(); } failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanTangentLinesDefinition = Properties.Settings.Default.SlipCircleUpliftVanTangentLinesDefinition; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanTangentLinesDistance = Properties.Settings.Default.SlipCircleUpliftVanTangentLinesDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopTangentLinesDefinition = Properties.Settings.Default.SlipCircleBishopTangentLinesDefinition; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopTangentLinesDistance = Properties.Settings.Default.SlipCircleBishopTangentLinesDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.GridSizeDetermination = Properties.Settings.Default.SlipCircleGridSizeDetermination; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridVerticalPointCount = Properties.Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridVerticalPointDistance = Properties.Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridHorizontalPointCount = Properties.Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance = Properties.Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanRightGridVerticalPointCount = Properties.Settings.Default.SlipCircleUpliftVanRightGridVerticalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanRightGridVerticalPointDistance = Properties.Settings.Default.SlipCircleUpliftVanRightGridVerticalPointDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanRightGridHorizontalPointCount = Properties.Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.UpliftVanRightGridHorizontalPointDistance = Properties.Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopGridVerticalPointCount = Properties.Settings.Default.SlipCircleBishopGridVerticalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopGridVerticalPointDistance = Properties.Settings.Default.SlipCircleBishopGridVerticalPointDistance; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopGridHorizontalPointCount = Properties.Settings.Default.SlipCircleBishopGridHorizontalPointCount; failureMechanismeParamatersMStab.MStabParameters.SlipCircleDefinition.BishopGridHorizontalPointDistance = Properties.Settings.Default.SlipCircleBishopGridHorizontalPointDistance; } } }