// 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.Generic;
using System.Drawing;
using System.Globalization;
using Deltares.Geotechnics.Soils;
namespace Deltares.Dam.Data
{
///
/// SoilUtils contains some general utility functions that were moved here from the Soil class (also used by DAM) as they are considered obsolete.
/// Afterwards this was moved here from DSL-GeoIo, to make DSL-GeoIo redundant.
///
public static class SoilUtils
{
///
/// Get a list of all soil parameters
///
/// list of name/value pair strings with soil parameters
public static Dictionary GetParametersAsNameValuePairs(Soil soil)
{
var numberFormatInfo = new NumberFormatInfo
{
NumberDecimalSeparator = "."
};
// General
var nameValuePairs = new Dictionary
{
{
SoilParameterNames.Color, soil.Color.ToArgb().ToString(numberFormatInfo)
},
{
SoilParameterNames.SoilType, soil.SoilType.ToString()
}
};
if (soil.GetPropertyIsAssigned("AbovePhreaticLevel"))
{
nameValuePairs.Add(SoilParameterNames.AbovePhreaticLevel, soil.AbovePhreaticLevel.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("BelowPhreaticLevel"))
{
nameValuePairs.Add(SoilParameterNames.BelowPhreaticLevel, soil.BelowPhreaticLevel.ToString(numberFormatInfo));
}
// Piping
if (soil.GetPropertyIsAssigned("DiameterD70"))
{
nameValuePairs.Add(SoilParameterNames.DiameterD70, soil.DiameterD70.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("PermeabKx"))
{
nameValuePairs.Add(SoilParameterNames.PermeabKx, soil.PermeabKx.ToString(numberFormatInfo));
}
// Stability
if (soil.GetPropertyIsAssigned("Cohesion"))
{
nameValuePairs.Add(SoilParameterNames.Cohesion, soil.Cohesion.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("FrictionAngle"))
{
nameValuePairs.Add(SoilParameterNames.Phi, soil.FrictionAngle.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("RatioCuPc"))
{
nameValuePairs.Add(SoilParameterNames.RatioCuPc, soil.RatioCuPc.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("ShearStrengthModel"))
{
nameValuePairs.Add(SoilParameterNames.ShearStrengthModel, soil.ShearStrengthModel.ToString());
}
if (soil.GetPropertyIsAssigned("POP"))
{
nameValuePairs.Add(SoilParameterNames.POP, soil.POP.ToString(numberFormatInfo));
}
if (soil.GetPropertyIsAssigned("StrengthIncreaseExponent"))
{
nameValuePairs.Add(SoilParameterNames.StrengthIncreaseExponent, soil.StrengthIncreaseExponent.ToString(numberFormatInfo));
}
return nameValuePairs;
}
///
/// Set a soil property according to name/value string pair.
///
/// The soil property.
/// Name of property
/// (String) value of property
public static void SetParameterFromNameValuePair(Soil soil, string parameterName, string parameterValue)
{
var numberFormatInfo = new NumberFormatInfo
{
NumberDecimalSeparator = "."
};
switch (parameterName)
{
case SoilParameterNames.Color:
soil.Color = Color.FromArgb(Convert.ToInt32(parameterValue));
break;
case SoilParameterNames.SoilType:
soil.SoilType = (SoilType) Enum.Parse(typeof(SoilType), parameterValue);
break;
case SoilParameterNames.DiameterD70:
soil.DiameterD70 = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.PermeabKx:
soil.PermeabKx = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.AbovePhreaticLevel:
soil.AbovePhreaticLevel = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.BelowPhreaticLevel:
soil.BelowPhreaticLevel = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.Cohesion:
soil.Cohesion = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.Phi:
soil.FrictionAngle = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.RatioCuPc:
soil.RatioCuPc = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.ShearStrengthModel:
soil.ShearStrengthModel = (ShearStrengthModel) Enum.Parse(typeof(ShearStrengthModel), parameterValue);
break;
case SoilParameterNames.POP:
soil.POP = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
case SoilParameterNames.StrengthIncreaseExponent:
soil.StrengthIncreaseExponent = Convert.ToDouble(parameterValue, numberFormatInfo);
break;
}
}
}
}