// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the application DAM - UI. // // 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; using System.Collections; using System.ComponentModel; using System.Xml.Serialization; using Deltares.Dam.Data.Properties; using Deltares.Dam.Data.UISupport; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using Deltares.Standard.Validation; namespace Deltares.Dam.Data; /// /// /// public class DamFailureMechanismeCalculationSpecification : IDomain, IVisibleEnabled, ICloneable { private FailureMechanismSystemType failureMechanismSystemType; private PipingModelType pipingModelType = PipingModelType.Wti2017; private StabilityModelType stabilityModelType = StabilityModelType.UpliftVan; private Enum calculationModel = StabilityModelType.UpliftVan; private Boolean firstTime = true; public DamFailureMechanismeCalculationSpecification() { //Todo interface failureMechanismSystemType = FailureMechanismSystemType.StabilityInside; SearchMethod = StabilitySearchMethod.BeeSwarm; IsUpliftVanRunOnlyWhenUpliftOccurs = true; SlipCircleDefinition = new SlipCircleDefinition(); ReadUserSettingsSlipCircleDefinition(); } /// /// The search method to use for stability calculations. /// [Validate] public StabilitySearchMethod SearchMethod { get; set; } /// /// When true, the uplift van calculation is only run when an uplift occurs. /// [Validate] public bool IsUpliftVanRunOnlyWhenUpliftOccurs { get; set; } /// /// The slip circle definition. /// [Validate] public SlipCircleDefinition SlipCircleDefinition { get; set; } /// /// The failure mechanism system type. /// [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. PipingModelType oldPipingModelType = pipingModelType; foreach (Enum possibleModel in GetDomain("CalculationModel")) { CalculationModel = possibleModel; break; } if (failureMechanismSystemType == FailureMechanismSystemType.Piping) { PipingModelType = oldPipingModelType; } DataEventPublisher.AfterChange(this, "FailureMechanismSystemType"); } } } /// /// The dam project type. /// [Browsable(false)] public static DamProjectType DamProjectType { get; set; } /// /// The piping model type. /// [Browsable(false)] public PipingModelType PipingModelType { get { return pipingModelType; } set { pipingModelType = value; if (failureMechanismSystemType == FailureMechanismSystemType.Piping) { CalculationModel = pipingModelType; } } } /// /// The stability model type. /// [Browsable(false)] public StabilityModelType StabilityModelType { get { return stabilityModelType; } set { stabilityModelType = value; if (failureMechanismSystemType != FailureMechanismSystemType.Piping) { CalculationModel = 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 /// mechanism instead of the fixed types per mechanism. /// [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 { stabilityModelType = (StabilityModelType) value; if (stabilityModelType != StabilityModelType.Bishop) { SearchMethod = StabilitySearchMethod.BeeSwarm; } } DataEventPublisher.AfterChange(this, "CalculationModel"); } } private void Assign(DamFailureMechanismeCalculationSpecification damFailureMechanismCalculation) { failureMechanismSystemType = damFailureMechanismCalculation.FailureMechanismSystemType; calculationModel = damFailureMechanismCalculation.CalculationModel; pipingModelType = damFailureMechanismCalculation.PipingModelType; stabilityModelType = damFailureMechanismCalculation.StabilityModelType; SearchMethod = damFailureMechanismCalculation.SearchMethod; IsUpliftVanRunOnlyWhenUpliftOccurs = damFailureMechanismCalculation.IsUpliftVanRunOnlyWhenUpliftOccurs; if (SlipCircleDefinition != null) { SlipCircleDefinition.Assign(damFailureMechanismCalculation.SlipCircleDefinition); } else { SlipCircleDefinition = null; } //assign interface } public DamFailureMechanismeCalculationSpecification Clone() { var damFailureMechanismeCalculation = new DamFailureMechanismeCalculationSpecification(); if (SlipCircleDefinition != null) { SlipCircleDefinition = SlipCircleDefinition.Clone(); } damFailureMechanismeCalculation.Assign(this); return damFailureMechanismeCalculation; } /// /// Reads the user settings. /// private void ReadUserSettingsSlipCircleDefinition() { if (SlipCircleDefinition == null) { SlipCircleDefinition = new SlipCircleDefinition(); } SlipCircleDefinition.UpliftVanTangentLinesDefinition = Settings.Default.SlipCircleUpliftVanTangentLinesDefinition; SlipCircleDefinition.UpliftVanTangentLinesDistance = Settings.Default.SlipCircleUpliftVanTangentLinesDistance; SlipCircleDefinition.BishopSearchAreaDetermination = Settings.Default.SlipCircleBishopSearchAreaDetermination; SlipCircleDefinition.BishopTangentLinesDistance = Settings.Default.SlipCircleBishopTangentLinesDistance; SlipCircleDefinition.UpliftVanGridSizeDetermination = Settings.Default.SlipCircleUpliftVanGridSizeDetermination; SlipCircleDefinition.UpliftVanLeftGridVerticalPointCount = Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointCount; SlipCircleDefinition.UpliftVanLeftGridVerticalPointDistance = Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointDistance; SlipCircleDefinition.UpliftVanLeftGridHorizontalPointCount = Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointCount; SlipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance = Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointDistance; SlipCircleDefinition.UpliftVanRightGridVerticalPointCount = Settings.Default.SlipCircleUpliftVanRightGridVerticalPointCount; SlipCircleDefinition.UpliftVanRightGridVerticalPointDistance = Settings.Default.SlipCircleUpliftVanRightGridVerticalPointDistance; SlipCircleDefinition.UpliftVanRightGridHorizontalPointCount = Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointCount; SlipCircleDefinition.UpliftVanRightGridHorizontalPointDistance = Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointDistance; SlipCircleDefinition.BishopGridVerticalPointCount = Settings.Default.SlipCircleBishopGridVerticalPointCount; SlipCircleDefinition.BishopGridVerticalPointDistance = Settings.Default.SlipCircleBishopGridVerticalPointDistance; SlipCircleDefinition.BishopGridHorizontalPointCount = Settings.Default.SlipCircleBishopGridHorizontalPointCount; SlipCircleDefinition.BishopGridHorizontalPointDistance = Settings.Default.SlipCircleBishopGridHorizontalPointDistance; } public override string ToString() { var description = ""; description += $"{FailureMechanismSystemType}"; if ((FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside) || (FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside)) { //interface? description += $" ({StabilityModelType})"; } return description; } public ICollection GetDomain(string property) { switch (property) { case "CalculationModel": return ConfigurationManager.Instance.GetAvailableMechanismModels(DamProjectType, failureMechanismSystemType); case "PipingModelType": return ConfigurationManager.Instance.GetAvailableMechanismModels(DamProjectType, FailureMechanismSystemType.Piping); case "FailureMechanismSystemType": return ConfigurationManager.Instance.GetAvailableFailureMechanisms(DamProjectType); case "SearchMethod": if (SlipCircleDefinition.Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside && (StabilityModelType == StabilityModelType.UpliftVan || StabilityModelType == StabilityModelType.BishopUpliftVan)) { return new[] { StabilitySearchMethod.BeeSwarm, StabilitySearchMethod.Grid }; } // Make sure that grid is reset and updated too when needed. if (SearchMethod != StabilitySearchMethod.Grid) { DataEventPublisher.BeforeChange(this, "SearchMethod"); SearchMethod = StabilitySearchMethod.Grid; DataEventPublisher.AfterChange(this, "SearchMethod"); } return new[] { StabilitySearchMethod.Grid }; default: return null; } } public bool IsEnabled(string property) { if (Equals(nameof(CalculationModel), property) && FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) { return false; // Disable model selection when stability outside is active, as only Bishop is currently supported. } switch (property) { case "SearchMethod": case "IsUpliftVanRunOnlyWhenUpliftOccurs": return Location.DamProjectType == DamProjectType.Design; default: return true; } } public bool IsVisible(string property) { if (Equals(property, nameof(StabilityModelType))) { switch (FailureMechanismSystemType) { case FailureMechanismSystemType.StabilityInside: return true; case FailureMechanismSystemType.StabilityOutside: return false; case FailureMechanismSystemType.Piping: return false; default: return true; } } switch (property) { case "SearchMethod": case "IsUpliftVanRunOnlyWhenUpliftOccurs": return (SlipCircleDefinition.Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside || SlipCircleDefinition.Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) && (stabilityModelType == StabilityModelType.BishopUpliftVan || stabilityModelType == StabilityModelType.UpliftVan); default: return true; } } }