// 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
{
private FailureMechanismSystemType failureMechanismSystemType;
private PipingModelType pipingModelType = PipingModelType.Wti2017;
private Enum calculationModel;
private Boolean firstTime = true;
public DamFailureMechanismeCalculationSpecification()
{
//Todo interface
failureMechanismSystemType = FailureMechanismSystemType.StabilityInside;
StabilityParameters = new StabilityParameters();
CalculationModel = StabilityParameters.MStabParameters.Model;
ReadUserSettingsSlipCircleDefinition();
}
[Browsable(false)] [Validate] public StabilityParameters StabilityParameters { get; set; }
[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");
}
}
}
[Browsable(false)]
public PipingModelType PipingModelType
{
get
{
return pipingModelType;
}
set
{
pipingModelType = value;
if (failureMechanismSystemType == FailureMechanismSystemType.Piping)
{
CalculationModel = pipingModelType;
}
}
}
[Browsable(false)] public static DamProjectType DamProjectType { get; set; }
///
/// 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
{
StabilityParameters.MStabParameters.Model = (StabilityModelType) value;
if (StabilityParameters.MStabParameters.Model != StabilityModelType.Bishop)
{
StabilityParameters.MStabParameters.SearchMethod = StabilitySearchMethod.BeeSwarm;
}
}
DataEventPublisher.AfterChange(this, "CalculationModel");
}
}
[Browsable(false)]
public StabilityModelType StabilityModelType
{
get
{
return StabilityParameters.MStabParameters.Model;
}
set
{
StabilityParameters.MStabParameters.Model = value;
if (failureMechanismSystemType != FailureMechanismSystemType.Piping)
{
CalculationModel = value;
}
}
}
private void Assign(DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculation)
{
failureMechanismSystemType = damFailureMechanismeCalculation.FailureMechanismSystemType;
calculationModel = damFailureMechanismeCalculation.CalculationModel;
pipingModelType = damFailureMechanismeCalculation.pipingModelType;
StabilityParameters.Assign(damFailureMechanismeCalculation.StabilityParameters);
StabilityModelType = damFailureMechanismeCalculation.StabilityModelType;
//assign interface
}
public DamFailureMechanismeCalculationSpecification Clone()
{
var damFailureMechanismeCalculation = new DamFailureMechanismeCalculationSpecification();
damFailureMechanismeCalculation.Assign(this);
return damFailureMechanismeCalculation;
}
///
/// Reads the user settings.
///
private void ReadUserSettingsSlipCircleDefinition()
{
if (StabilityParameters.MStabParameters.SlipCircleDefinition == null)
{
StabilityParameters.MStabParameters.SlipCircleDefinition = new SlipCircleDefinition();
}
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanTangentLinesDefinition = Settings.Default.SlipCircleUpliftVanTangentLinesDefinition;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanTangentLinesDistance = Settings.Default.SlipCircleUpliftVanTangentLinesDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopSearchAreaDetermination = Settings.Default.SlipCircleBishopSearchAreaDetermination;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopTangentLinesDistance = Settings.Default.SlipCircleBishopTangentLinesDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanGridSizeDetermination = Settings.Default.SlipCircleUpliftVanGridSizeDetermination;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridVerticalPointCount = Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridVerticalPointDistance = Settings.Default.SlipCircleUpliftVanLeftGridVerticalPointDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridHorizontalPointCount = Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance = Settings.Default.SlipCircleUpliftVanLeftGridHorizontalPointDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanRightGridVerticalPointCount = Settings.Default.SlipCircleUpliftVanRightGridVerticalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanRightGridVerticalPointDistance = Settings.Default.SlipCircleUpliftVanRightGridVerticalPointDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanRightGridHorizontalPointCount = Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.UpliftVanRightGridHorizontalPointDistance = Settings.Default.SlipCircleUpliftVanRightGridHorizontalPointDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopGridVerticalPointCount = Settings.Default.SlipCircleBishopGridVerticalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopGridVerticalPointDistance = Settings.Default.SlipCircleBishopGridVerticalPointDistance;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopGridHorizontalPointCount = Settings.Default.SlipCircleBishopGridHorizontalPointCount;
StabilityParameters.MStabParameters.SlipCircleDefinition.BishopGridHorizontalPointDistance = Settings.Default.SlipCircleBishopGridHorizontalPointDistance;
}
public override string ToString()
{
var description = "";
description += $"{FailureMechanismSystemType}";
if ((FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside) ||
(FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside))
{
//interface?
description += $" ({StabilityParameters.MStabParameters.Model})";
}
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 "StabilityKernelType":
return ConfigurationManager.Instance.GetAvailableFailureMechanisms(DamProjectType);
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.
}
return true;
}
public bool IsVisible(string property)
{
if (Equals(property, nameof(StabilityParameters)))
{
switch (FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityInside: return true;
case FailureMechanismSystemType.StabilityOutside: return false;
case FailureMechanismSystemType.Piping: return false;
default: return true;
}
}
return true;
}
}