// Copyright (C) Stichting Deltares 2024. 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.Collections;
using Deltares.Standard;
using Deltares.Standard.Attributes;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.Units;
using Deltares.Standard.Validation;
namespace Deltares.Dam.Data;
public enum TangentLinesDefinition
{
OnBoundaryLines = 0,
Specified = 1,
Automatic = 2
}
public enum GridSizeDetermination
{
Automatic = 0,
Specified = 1
}
public class SlipCircleDefinition : IVisibleEnabled, IAssignable, ICloneable
{
private const string upliftVanTangentLinesDistanceObject = "upliftVanTangentLinesDistance";
private const string bishopTangentLinesDistanceObject = "bishopTangentLinesDistance";
private const string upliftVanLeftGridVerticalPointCountObject = "UpliftVanLeftGridVerticalPointCount";
private const string upliftVanLeftGridVerticalPointDistanceObject = "upliftVanLeftGridVerticalPointDistance";
private const string upliftVanLeftGridHorizontalPointCountObject = "UpliftVanLeftGridHorizontalPointCount";
private const string upliftVanLeftGridHorizontalPointDistanceObject = "UpliftVanLeftGridHorizontalPointDistance";
private const string upliftVanRightGridVerticalPointCountObject = "UpliftVanRightGridVerticalPointCount";
private const string upliftVanRightGridVerticalPointDistanceObject = "UpliftVanRightGridVerticalPointDistance";
private const string upliftVanRightGridHorizontalPointCountObject = "UpliftVanRightGridHorizontalPointCount";
private const string upliftVanRightGridHorizontalPointDistanceObject = "UpliftVanRightGridHorizontalPointDistance";
private const string bishopGridHorizontalPointCountObject = "BishopGridHorizontalPointCount";
private const string bishopGridHorizontalPointDistanceObject = "BishopGridHorizontalPointDistance";
private const string bishopGridVerticalPointCountObject = "bishopGridVerticalPointCount";
private const string bishopGridVerticalPointDistanceObject = "bishopGridVerticalPointDistance";
private double xCoordinateLastUpliftPoint;
private int upliftVanLeftGridVerticalPointCount;
private double upliftVanTangentLinesDistance;
private double bishopTangentLinesDistance;
private double upliftVanLeftGridVerticalPointDistance;
private int upliftVanLeftGridHorizontalPointCount;
private double upliftVanLeftGridHorizontalPointDistance;
private int upliftVanRightGridVerticalPointCount;
private double upliftVanRightGridVerticalPointDistance;
private int upliftVanRightGridHorizontalPointCount;
private double upliftVanRightGridHorizontalPointDistance;
private int bishopGridHorizontalPointCount;
private double bishopGridHorizontalPointDistance;
private int bishopGridVerticalPointCount;
private double bishopGridVerticalPointDistance;
[Format("F2")]
[Unit(UnitType.Length)]
public double XCoordinateLastUpliftPoint
{
get
{
return xCoordinateLastUpliftPoint;
}
set
{
DataEventPublisher.BeforeChange(this, "XCoordinateLastUpliftPoint");
xCoordinateLastUpliftPoint = value;
DataEventPublisher.AfterChange(this, "XCoordinateLastUpliftPoint");
}
}
public TangentLinesDefinition UpliftVanTangentLinesDefinition { get; set; }
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double UpliftVanTangentLinesDistance
{
get
{
return upliftVanTangentLinesDistance;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanTangentLinesDistanceObject);
upliftVanTangentLinesDistance = value;
DataEventPublisher.AfterChange(this, upliftVanTangentLinesDistanceObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double BishopTangentLinesDistance
{
get
{
return bishopTangentLinesDistance;
}
set
{
DataEventPublisher.BeforeChange(this, bishopTangentLinesDistanceObject);
bishopTangentLinesDistance = value;
DataEventPublisher.AfterChange(this, bishopTangentLinesDistanceObject);
}
}
public GridSizeDetermination UpliftVanGridSizeDetermination { get; set; }
public GridSizeDetermination BishopSearchAreaDetermination { get; set; }
[Unit(UnitType.None)]
[Minimum(1)]
[Maximum(100)]
public int UpliftVanLeftGridVerticalPointCount
{
get
{
return upliftVanLeftGridVerticalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanLeftGridVerticalPointCountObject);
upliftVanLeftGridVerticalPointCount = value;
DataEventPublisher.AfterChange(this, upliftVanLeftGridVerticalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double UpliftVanLeftGridVerticalPointDistance
{
get
{
return upliftVanLeftGridVerticalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanLeftGridVerticalPointDistanceObject);
upliftVanLeftGridVerticalPointDistance = value;
DataEventPublisher.AfterChange(this, upliftVanLeftGridVerticalPointDistanceObject);
}
}
[Unit(UnitType.None)]
[Minimum(1)]
[Maximum(100)]
public int UpliftVanLeftGridHorizontalPointCount
{
get
{
return upliftVanLeftGridHorizontalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanLeftGridHorizontalPointCountObject);
upliftVanLeftGridHorizontalPointCount = value;
DataEventPublisher.AfterChange(this, upliftVanLeftGridHorizontalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double UpliftVanLeftGridHorizontalPointDistance
{
get
{
return upliftVanLeftGridHorizontalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanLeftGridHorizontalPointDistanceObject);
upliftVanLeftGridHorizontalPointDistance = value;
DataEventPublisher.AfterChange(this, upliftVanLeftGridHorizontalPointDistanceObject);
}
}
[Unit(UnitType.None)]
[Minimum(1)]
[Maximum(100)]
public int UpliftVanRightGridVerticalPointCount
{
get
{
return upliftVanRightGridVerticalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanRightGridVerticalPointCountObject);
upliftVanRightGridVerticalPointCount = value;
DataEventPublisher.AfterChange(this, upliftVanRightGridVerticalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double UpliftVanRightGridVerticalPointDistance
{
get
{
return upliftVanRightGridVerticalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanRightGridVerticalPointDistanceObject);
upliftVanRightGridVerticalPointDistance = value;
DataEventPublisher.AfterChange(this, upliftVanRightGridVerticalPointDistanceObject);
}
}
[Unit(UnitType.None)]
[Minimum(1)]
[Maximum(100)]
public int UpliftVanRightGridHorizontalPointCount
{
get
{
return upliftVanRightGridHorizontalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanRightGridHorizontalPointCountObject);
upliftVanRightGridHorizontalPointCount = value;
DataEventPublisher.AfterChange(this, upliftVanRightGridHorizontalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double UpliftVanRightGridHorizontalPointDistance
{
get
{
return upliftVanRightGridHorizontalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, upliftVanRightGridHorizontalPointDistanceObject);
upliftVanRightGridHorizontalPointDistance = value;
DataEventPublisher.AfterChange(this, upliftVanRightGridHorizontalPointDistanceObject);
}
}
[Minimum(1)]
[Unit(UnitType.None)]
[Maximum(100)]
public int BishopGridVerticalPointCount
{
get
{
return bishopGridVerticalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, bishopGridVerticalPointCountObject);
bishopGridVerticalPointCount = value;
DataEventPublisher.AfterChange(this, bishopGridVerticalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double BishopGridVerticalPointDistance
{
get
{
return bishopGridVerticalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, bishopGridVerticalPointDistanceObject);
bishopGridVerticalPointDistance = value;
DataEventPublisher.AfterChange(this, bishopGridVerticalPointDistanceObject);
}
}
[Unit(UnitType.None)]
[Minimum(1)]
[Maximum(100)]
public int BishopGridHorizontalPointCount
{
get
{
return bishopGridHorizontalPointCount;
}
set
{
DataEventPublisher.BeforeChange(this, bishopGridHorizontalPointCountObject);
bishopGridHorizontalPointCount = value;
DataEventPublisher.AfterChange(this, bishopGridHorizontalPointCountObject);
}
}
[Format("F2")]
[Unit(UnitType.Length)]
[Minimum(0.01)]
[Maximum(1000.0)]
public double BishopGridHorizontalPointDistance
{
get
{
return bishopGridHorizontalPointDistance;
}
set
{
DataEventPublisher.BeforeChange(this, bishopGridHorizontalPointDistanceObject);
bishopGridHorizontalPointDistance = value;
DataEventPublisher.AfterChange(this, bishopGridHorizontalPointDistanceObject);
}
}
public DamFailureMechanismeCalculationSpecification Specification { get; set; }
public void Assign(SlipCircleDefinition slipCircleDefinition)
{
XCoordinateLastUpliftPoint = slipCircleDefinition.XCoordinateLastUpliftPoint;
UpliftVanTangentLinesDefinition = slipCircleDefinition.UpliftVanTangentLinesDefinition;
UpliftVanTangentLinesDistance = slipCircleDefinition.UpliftVanTangentLinesDistance;
UpliftVanGridSizeDetermination = slipCircleDefinition.UpliftVanGridSizeDetermination;
UpliftVanLeftGridVerticalPointCount = slipCircleDefinition.UpliftVanLeftGridVerticalPointCount;
UpliftVanLeftGridVerticalPointDistance = slipCircleDefinition.UpliftVanLeftGridVerticalPointDistance;
UpliftVanLeftGridHorizontalPointCount = slipCircleDefinition.UpliftVanLeftGridHorizontalPointCount;
UpliftVanLeftGridHorizontalPointDistance = slipCircleDefinition.UpliftVanLeftGridHorizontalPointDistance;
UpliftVanRightGridVerticalPointCount = slipCircleDefinition.UpliftVanRightGridVerticalPointCount;
UpliftVanRightGridVerticalPointDistance = slipCircleDefinition.UpliftVanRightGridVerticalPointDistance;
UpliftVanRightGridHorizontalPointCount = slipCircleDefinition.UpliftVanRightGridHorizontalPointCount;
UpliftVanRightGridHorizontalPointDistance = slipCircleDefinition.UpliftVanRightGridHorizontalPointDistance;
BishopSearchAreaDetermination = slipCircleDefinition.BishopSearchAreaDetermination;
BishopTangentLinesDistance = slipCircleDefinition.BishopTangentLinesDistance;
BishopGridVerticalPointCount = slipCircleDefinition.BishopGridVerticalPointCount;
BishopGridVerticalPointDistance = slipCircleDefinition.BishopGridVerticalPointDistance;
BishopGridHorizontalPointCount = slipCircleDefinition.BishopGridHorizontalPointCount;
BishopGridHorizontalPointDistance = slipCircleDefinition.BishopGridHorizontalPointDistance;
}
public SlipCircleDefinition Clone()
{
var slipCircleDefinition = new SlipCircleDefinition();
slipCircleDefinition.Assign(this);
return slipCircleDefinition;
}
public bool IsVisible(string property)
{
if (Specification == null)
{
return true;
}
switch (property)
{
// Uplift Van
case "UpliftVanGridSizeDetermination":
case "UpliftVanTangentLinesDefinition":
case "UpliftVanTangentLinesDistance":
case "UpliftVanLeftGridVerticalPointCount":
case "UpliftVanLeftGridVerticalPointDistance":
case "UpliftVanLeftGridHorizontalPointCount":
case "UpliftVanLeftGridHorizontalPointDistance":
case "UpliftVanRightGridVerticalPointCount":
case "UpliftVanRightGridVerticalPointDistance":
case "UpliftVanRightGridHorizontalPointCount":
case "UpliftVanRightGridHorizontalPointDistance":
return IsStabilityUpliftVan() || IsStabilityBishopUpliftVan();
// Bishop
case "BishopSearchAreaDetermination":
case "BishopTangentLinesDistance":
case "BishopGridVerticalPointCount":
case "BishopGridVerticalPointDistance":
case "BishopGridHorizontalPointCount":
case "BishopGridHorizontalPointDistance":
return IsStabilityBishop() || IsStabilityBishopUpliftVan();
default: return true;
}
}
public bool IsEnabled(string property)
{
if (Specification == null)
{
return true;
}
switch (property)
{
// Uplift Van
case "UpliftVanTangentLinesDefinition":
return true;
case "UpliftVanTangentLinesDistance":
return UpliftVanTangentLinesDefinition == TangentLinesDefinition.Specified;
case "UpliftVanLeftGridVerticalPointCount":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanLeftGridVerticalPointDistance":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanLeftGridHorizontalPointCount":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanLeftGridHorizontalPointDistance":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanRightGridVerticalPointCount":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanRightGridVerticalPointDistance":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanRightGridHorizontalPointCount":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
case "UpliftVanRightGridHorizontalPointDistance":
return UpliftVanGridSizeDetermination == GridSizeDetermination.Specified;
// Bishop
case "BishopTangentLinesDistance":
return BishopSearchAreaDetermination == GridSizeDetermination.Specified;
case "BishopGridVerticalPointCount":
return BishopSearchAreaDetermination == GridSizeDetermination.Specified;
case "BishopGridVerticalPointDistance":
return BishopSearchAreaDetermination == GridSizeDetermination.Specified;
case "BishopGridHorizontalPointCount":
return BishopSearchAreaDetermination == GridSizeDetermination.Specified;
case "BishopGridHorizontalPointDistance":
return BishopSearchAreaDetermination == GridSizeDetermination.Specified;
default: return true;
}
}
private bool IsStabilityBishop()
{
return ((Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside ||
Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) &&
(MStabModelType) Specification.CalculationModel == MStabModelType.Bishop);
}
private bool IsStabilityUpliftVan()
{
return ((Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside ||
Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) &&
(MStabModelType) Specification.CalculationModel == MStabModelType.UpliftVan);
}
private bool IsStabilityBishopUpliftVan()
{
return ((Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside ||
Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) &&
(MStabModelType) Specification.CalculationModel == MStabModelType.BishopUpliftVan);
}
}
public class MStabForbiddenZone : IAssignable, ICloneable
{
public bool IsXEntryMinUsed { get; set; }
public bool IsXEntryMaxUsed { get; set; }
public double XEntryMin { get; set; }
public double XEntryMax { get; set; }
public void Assign(MStabForbiddenZone mstabForbiddenZone)
{
IsXEntryMinUsed = mstabForbiddenZone.IsXEntryMinUsed;
IsXEntryMaxUsed = mstabForbiddenZone.IsXEntryMaxUsed;
XEntryMin = mstabForbiddenZone.XEntryMin;
XEntryMax = mstabForbiddenZone.XEntryMax;
}
public MStabForbiddenZone Clone()
{
var mstabForbiddenZone = new MStabForbiddenZone();
mstabForbiddenZone.Assign(this);
return mstabForbiddenZone;
}
}
public class MStabDesignEmbankment : IAssignable, ICloneable
{
public string EmbankmentMaterialname { get; set; }
public string PreviousGeometry2DFilename { get; set; }
public void Assign(MStabDesignEmbankment mstabDesignEmbankment)
{
EmbankmentMaterialname = mstabDesignEmbankment.EmbankmentMaterialname;
PreviousGeometry2DFilename = mstabDesignEmbankment.PreviousGeometry2DFilename;
}
public MStabDesignEmbankment Clone()
{
var mstabDesignEmbankment = new MStabDesignEmbankment();
mstabDesignEmbankment.Assign(this);
return mstabDesignEmbankment;
}
}
public class MStabParameters : ICloneable, IVisibleEnabled, IDomain
{
private MStabGridPosition gridPosition;
public MStabParameters()
{
Model = MStabModelType.UpliftVan;
SearchMethod = MStabSearchMethod.BeeSwarm;
gridPosition = MStabGridPosition.Right;
SlipCircleDefinition = new SlipCircleDefinition();
}
[Label("Model")] public MStabModelType Model { get; set; }
public MStabSearchMethod SearchMethod { get; set; }
public string ProjectFileName { get; set; }
[Validate] public SlipCircleDefinition SlipCircleDefinition { get; set; }
public MStabGridPosition GridPosition
{
get
{
return gridPosition;
}
set
{
DataEventPublisher.BeforeChange(this, "GridPosition");
gridPosition = value;
DataEventPublisher.AfterChange(this, "GridPosition");
}
}
public void Assign(MStabParameters mstabParameters)
{
Model = mstabParameters.Model;
SearchMethod = mstabParameters.SearchMethod;
GridPosition = mstabParameters.GridPosition;
ProjectFileName = mstabParameters.ProjectFileName;
if (SlipCircleDefinition != null)
{
SlipCircleDefinition.Assign(mstabParameters.SlipCircleDefinition);
}
else
{
SlipCircleDefinition = null;
}
}
public MStabParameters Clone()
{
var mstabParameters = new MStabParameters();
if (SlipCircleDefinition != null)
{
mstabParameters.SlipCircleDefinition = SlipCircleDefinition.Clone();
}
mstabParameters.Assign(this);
return mstabParameters;
}
#region IVisibleEnabled Members
public bool IsEnabled(string property)
{
switch (property)
{
case "SearchMethod": return Location.DamProjectType == DamProjectType.Design;
case "GridPosition": return false; // position depends on failuremechanisme type (inside or outside)
case "ZonesType": return false; // Is set per location!
default: return true;
}
}
public bool IsVisible(string property)
{
switch (property)
{
case "Model": return true;
case "SearchMethod":
return
(SlipCircleDefinition.Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside ||
SlipCircleDefinition.Specification.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside) &&
(Model == MStabModelType.BishopUpliftVan || Model == MStabModelType.UpliftVan);
case "ZonesType": return false; // Is set per location!
case "GridPosition": return false; // position depends on failuremechanisme type (inside or outside)
default: return true;
}
}
///
/// Gets the domain to ensure proper options for the search method depending on FailureMechanismSystemType and model.
///
/// The property.
///
public ICollection GetDomain(string property)
{
if (property == "SearchMethod")
{
if (SlipCircleDefinition.Specification.FailureMechanismSystemType ==
FailureMechanismSystemType.StabilityInside && (Model == MStabModelType.UpliftVan || Model == MStabModelType.BishopUpliftVan))
{
return new[]
{
MStabSearchMethod.BeeSwarm,
MStabSearchMethod.Grid
};
}
// Make sure that grid is reset and updated too when needed.
if (SearchMethod != MStabSearchMethod.Grid)
{
DataEventPublisher.BeforeChange(this, "SearchMethod");
SearchMethod = MStabSearchMethod.Grid;
DataEventPublisher.AfterChange(this, "SearchMethod");
}
return new[]
{
MStabSearchMethod.Grid
};
}
return null;
}
#endregion
}