// Copyright (C) Stichting Deltares 2021. 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;
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
{
///
///
///
public class DamFailureMechanismeCalculationSpecification: IDomain, IVisibleEnabled
{
private FailureMechanismSystemType failureMechanismSystemType;
private PipingModelType pipingModelType = PipingModelType.Sellmeijer4Forces;
private Enum calculationModel;
private FailureMechanismeParamatersMStab failureMechanismeParamatersMStab;
private static DamProjectType damProjectType;
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; }
}
///
/// 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
{
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;
}
}
}
public void Assign(DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculation)
{
failureMechanismSystemType = damFailureMechanismeCalculation.FailureMechanismSystemType;
calculationModel = damFailureMechanismeCalculation.CalculationModel;
pipingModelType = damFailureMechanismeCalculation.pipingModelType;
failureMechanismeParamatersMStab.Assign(damFailureMechanismeCalculation.FailureMechanismeParamatersMStab);
StabilityModelType = damFailureMechanismeCalculation.StabilityModelType;
//assign interface
}
public DamFailureMechanismeCalculationSpecification Clone()
{
DamFailureMechanismeCalculationSpecification damFailureMechanismeCalculation = new DamFailureMechanismeCalculationSpecification();
damFailureMechanismeCalculation.Assign(this);
return damFailureMechanismeCalculation;
}
public override string ToString()
{
string description = "";
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(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
|| FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside))
{
return false; // Disable model selection when stability is active, as only UpliftVan is currently supported.
}
return true;
}
public bool IsVisible(string property)
{
if (Equals(property, nameof(FailureMechanismeParamatersMStab)))
{
switch (FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityInside: return true;
case FailureMechanismSystemType.StabilityOutside: return false;
case FailureMechanismSystemType.HorizontalBalance: return false;
case FailureMechanismSystemType.Piping: return false;
default: return true;
}
}
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;
}
}
}