Index: DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProjectCalculationSpecification.cs =================================================================== diff -u -r6831 -r6964 --- DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProjectCalculationSpecification.cs (.../DamProjectCalculationSpecification.cs) (revision 6831) +++ DamClients/DamUI/trunk/src/DamClientsLibrary/Deltares.Dam.Data/DamProjectCalculationSpecification.cs (.../DamProjectCalculationSpecification.cs) (revision 6964) @@ -24,6 +24,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Xml.Serialization; +using Deltares.Dam.Data.UISupport; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; @@ -36,101 +37,211 @@ /// Represents the calculation specifications at project level for DAM. /// These are the main choices that specify the calculation /// -public class DamProjectCalculationSpecification : IVisibleEnabled, IDomain, IRepairer, IDisposable +public class DamProjectCalculationSpecification : IVisibleEnabled, IDomain, IDisposable, ICloneable { private static AnalysisType selectedAnalysisType = AnalysisType.NoAdaption; - private DamFailureMechanismeCalculationSpecification currentSpecification; + private FailureMechanismSystemType failureMechanismSystemType; + private PipingModelType pipingModelType = PipingModelType.Wti2017; + private StabilityModelType stabilityModelType = StabilityModelType.UpliftVan; + private Enum calculationModel = StabilityModelType.UpliftVan; + private DamStabilityParameters damStabilityParameters = new(); + private Boolean firstTime = true; public DamProjectCalculationSpecification() { - DamCalculationSpecifications = new List(); + failureMechanismSystemType = FailureMechanismSystemType.StabilityInside; + damStabilityParameters.SlipCircleDefinition.Specification = this; DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange; + } - [ReadOnly(true)] //For now make read only as only 1 spec is allowed at this moment - [Validate] - public List DamCalculationSpecifications { get; } + public DamProjectCalculationSpecification Clone() + { + var damFailureMechanismCalculation = new DamProjectCalculationSpecification(); + + if (damStabilityParameters != null) + { + damFailureMechanismCalculation.DamStabilityParameters = damStabilityParameters.Clone(); + } + damFailureMechanismCalculation.Assign(this); + + return damFailureMechanismCalculation; + } + + public override string ToString() + { + var description = ""; + description += $"{FailureMechanismSystemType}"; + if ((FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside) || + (FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside)) + { + //interface? + description += $" ({StabilityModelType})"; + } + + return description; + } + /// - /// Gets or sets the analysis type for serialization purpose only. - /// This "dummy" property is and must be only used for serialization/deserialization purposes as the real static property - /// SelectedAnalysisType is NOT serialized. + /// The stability parameters. /// - /// - /// The analysis type for serialization purpose only. - /// - public AnalysisType AnalysisType + public DamStabilityParameters DamStabilityParameters { get { - return selectedAnalysisType; + return damStabilityParameters; } set { - selectedAnalysisType = value; + damStabilityParameters = value; + DataEventPublisher.AfterChange(this); } } /// - /// Gets or sets the type of the selected analysis. + /// The failure mechanism system type. /// - /// - /// The type of the selected analysis. - /// - [Label("Analysis type")] - public static AnalysisType SelectedAnalysisType + [Label("Failure mechanism")] + [PropertyOrder(1, 0)] + public FailureMechanismSystemType FailureMechanismSystemType { get { - return selectedAnalysisType; + return failureMechanismSystemType; } set { - // Create local instance of DamProjectCalculationSpecification because event handlers need sender - var r = new DamProjectCalculationSpecification(); - DataEventPublisher.BeforeChange(r, "SelectedAnalysisType"); - selectedAnalysisType = value; - DataEventPublisher.AfterChange(r, "SelectedAnalysisType"); + // 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"); + } } } - - [XmlIgnore] - public DamFailureMechanismeCalculationSpecification CurrentSpecification + + /// + /// The dam project type. + /// + [Browsable(false)] public static DamProjectType DamProjectType { get; set; } + + /// + /// The piping model type. + /// + [Browsable(false)] + public PipingModelType PipingModelType { get { - if (currentSpecification == null && DamCalculationSpecifications.Count > 0) + return pipingModelType; + } + set + { + pipingModelType = value; + if (failureMechanismSystemType == FailureMechanismSystemType.Piping) { - currentSpecification = DamCalculationSpecifications[0]; + CalculationModel = pipingModelType; } - - return currentSpecification; } + } + + /// + /// The stability model type. + /// + [Browsable(false)] + public StabilityModelType StabilityModelType + { + get + { + return stabilityModelType; + } set { - DataEventPublisher.BeforeChange(this, "CurrentSpecification"); - currentSpecification = value; - DataEventPublisher.AfterChange(this, "CurrentSpecification"); + stabilityModelType = value; + if (failureMechanismSystemType != FailureMechanismSystemType.Piping) + { + CalculationModel = value; + } } } - - [XmlIgnore] [Browsable(false)] public IVisibleEnabledProvider VisibleEnabledProvider { get; set; } - - [Validate] - public ValidationResult[] Validate() + + /// + /// 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 { - if (DamCalculationSpecifications.Count > 1) + get { - return new[] + return calculationModel; + } + set + { + DataEventPublisher.BeforeChange(this, "CalculationModel"); + calculationModel = value; + if (value is PipingModelType) { - new ValidationResult(ValidationResultType.Error, LocalizationManager.GetTranslatedText(this, "MaxOneCalculationSpecification"), - this, "DamCalculationSpecifications", "DamCalculationSpecifications", this) - }; + pipingModelType = (PipingModelType) value; + } + else + { + stabilityModelType = (StabilityModelType) value; + if (stabilityModelType != StabilityModelType.Bishop) + { + damStabilityParameters.SearchMethod = StabilitySearchMethod.BeeSwarm; + } + } + + DataEventPublisher.AfterChange(this, "CalculationModel"); } + } - return new ValidationResult[0]; + /// + /// Gets or sets the type of the selected analysis. + /// + /// + /// The type of the selected analysis. + /// + [Label("Analysis type")] + public static AnalysisType SelectedAnalysisType + { + get + { + return selectedAnalysisType; + } + set + { + // Create local instance of DamProjectCalculationSpecification because event handlers need sender + var r = new DamProjectCalculationSpecification(); + DataEventPublisher.BeforeChange(r, "SelectedAnalysisType"); + selectedAnalysisType = value; + DataEventPublisher.AfterChange(r, "SelectedAnalysisType"); + } } + [XmlIgnore] [Browsable(false)] public IVisibleEnabledProvider VisibleEnabledProvider { get; set; } + public void Dispose() { DataEventPublisher.OnAfterChange -= DataEventPublisher_OnAfterChange; @@ -140,6 +251,12 @@ { 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 "SelectedAnalysisType": return new[] { @@ -150,51 +267,35 @@ } } - public void Repair(object subject, string property, string id) - { - switch (id) - { - case "DamCalculationSpecifications": - RepairTooManySpecifications(); - break; - } - } - - public string GetRepairDescription(object subject, string property, string id) - { - switch (id) - { - case "DamCalculationSpecifications": - return LocalizationManager.GetTranslatedText(this, "KeepFirstCalculationSpecification"); - default: return ""; - } - } - public bool IsVisible(string property) { - if (DamCalculationSpecifications.Count <= 0) + if (Equals(property, nameof(StabilityModelType))) { - return false; + switch (FailureMechanismSystemType) + { + case FailureMechanismSystemType.StabilityInside: return true; + case FailureMechanismSystemType.StabilityOutside: return false; + case FailureMechanismSystemType.Piping: return false; + default: return true; + } } switch (property) { case "SelectedAnalysisType": return Location.DamProjectType == DamProjectType.Design; - case "CurrentSpecification": - { - bool bol = (DamCalculationSpecifications.Count > 0) && - (CurrentSpecification.FailureMechanismSystemType == - FailureMechanismSystemType.StabilityInside || - CurrentSpecification.FailureMechanismSystemType == - FailureMechanismSystemType.StabilityOutside); - return bol; - } + case "DamStabilityParameters": return FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside || + FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside; default: return true; } } 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) { default: return true; @@ -203,17 +304,26 @@ private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e) { - if (sender == currentSpecification) + if (sender == damStabilityParameters) { DataEventPublisher.AfterChange(this); } } - - private void RepairTooManySpecifications() + + private void Assign(DamProjectCalculationSpecification damFailureMechanismCalculation) { - for (int i = DamCalculationSpecifications.Count - 1; i > 0; i--) + failureMechanismSystemType = damFailureMechanismCalculation.FailureMechanismSystemType; + calculationModel = damFailureMechanismCalculation.CalculationModel; + pipingModelType = damFailureMechanismCalculation.PipingModelType; + stabilityModelType = damFailureMechanismCalculation.StabilityModelType; + if (DamStabilityParameters != null) { - DamCalculationSpecifications.Remove(DamCalculationSpecifications[i]); + DamStabilityParameters.Assign(damFailureMechanismCalculation.DamStabilityParameters); } + else + { + DamStabilityParameters = null; + } } + } \ No newline at end of file