using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using Deltares.Probabilistic; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.Language; namespace Deltares.Stability { public class ProbabilisticDefaults { private Stochast cohesionStochast = new Stochast("CohesionStochast", DistributionType.Deterministic); private Stochast compressionStochast = new Stochast("CompressionStochast", DistributionType.Normal); private Stochast consolidationStochast = new Stochast("ConsolidationStochast", DistributionType.Normal); private Stochast cuStochast = new Stochast("CuStochast", DistributionType.Normal); private Stochast frictionAngleStochast = new Stochast("FrictionAngleStochast", DistributionType.Deterministic); private Stochast hydraulicPressureStochast = new Stochast("HydraulicPressureStochast", DistributionType.Normal); private Stochast limitValueBishopStochast = new Stochast("LimitValueBishopStochast", DistributionType.Normal); private Stochast limitValueVanStochast = new Stochast("LimitValueVanStochast", DistributionType.Normal); private Stochast popStochast = new Stochast("POPStochast", DistributionType.Deterministic); private Stochast ratioCuPcStochast = new Stochast("RatioCuPcStochast", DistributionType.Normal); private Stochast stressTableStochast = new Stochast("StressTableStochast", DistributionType.Normal); public ProbabilisticDefaults() { foreach (var stochast in new[] { cohesionStochast, frictionAngleStochast, popStochast, compressionStochast, consolidationStochast, cuStochast, ratioCuPcStochast, stressTableStochast, hydraulicPressureStochast }) { stochast.Owner = this; } } [Translation("Cohesion")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast CohesionStochast { get { return cohesionStochast; } set { cohesionStochast = value; cohesionStochast.Owner = this; cohesionStochast.Name = "CohesionStochast"; } } [Translation("FrictionAngle")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast FrictionAngleStochast { get { return frictionAngleStochast; } set { frictionAngleStochast = value; frictionAngleStochast.Owner = this; frictionAngleStochast.Name = "FrictionAngleStochast"; } } [Translation("POP")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast POPStochast { get { return popStochast; } set { popStochast = value; popStochast.Owner = this; popStochast.Name = "POPStochast"; } } [Translation("Compression")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast CompressionStochast { get { return compressionStochast; } set { compressionStochast = value; compressionStochast.Owner = this; compressionStochast.Name = "CompressionStochast"; } } [Translation("Consolidation")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast ConsolidationStochast { get { return consolidationStochast; } set { consolidationStochast = value; consolidationStochast.Owner = this; consolidationStochast.Name = "ConsolidationStochast"; } } [Translation("Cu")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast CuStochast { get { return cuStochast; } set { cuStochast = value; cuStochast.Owner = this; cuStochast.Name = "CuStochast"; } } [Translation("RatioCuPc")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast RatioCuPcStochast { get { return ratioCuPcStochast; } set { ratioCuPcStochast = value; ratioCuPcStochast.Owner = this; ratioCuPcStochast.Name = "RatioCuPcStochast"; } } [Translation("StressTable")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast StressTableStochast { get { return stressTableStochast; } set { stressTableStochast = value; stressTableStochast.Owner = this; stressTableStochast.Name = "StressTableStochast"; } } [Translation("HydraulicPressure")] [Stochast(ErrorOnly = true, HasDesign = true)] [Format("G5")] public Stochast HydraulicPressureStochast { get { return hydraulicPressureStochast; } set { hydraulicPressureStochast = value; hydraulicPressureStochast.Owner = this; hydraulicPressureStochast.Name = "HydraulicPressureStochast"; } } [Translation("LimitValueBishop")] [Format("G5")] public Stochast LimitValueBishopStochast { get { return limitValueBishopStochast; } set { limitValueBishopStochast = value; limitValueBishopStochast.Owner = this; limitValueBishopStochast.Name = "LimitValueBishopStochast"; } } [Translation("LimitValueVan")] [Format("G5")] public Stochast LimitValueVanStochast { get { return limitValueVanStochast; } set { limitValueVanStochast = value; limitValueVanStochast.Owner = this; limitValueVanStochast.Name = "LimitValueVanStochast"; } } public override string ToString() { return "Probabilistic defaults"; } } #region Distribtuion converter types public class DistributionConverter : ExpandableObjectConverter { public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { var values = new DistributionValues(); return new StandardValuesCollection(values.GetNames()); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(int)) { return true; } return base.CanConvertTo(context, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value.GetType() == typeof(int)) { var values = new DistributionValues(); return values.GetStringValue((int) value); } return base.ConvertTo(context, culture, value, destinationType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { try { var values = new DistributionValues(); return values.GetIntValue((string) value); } catch { throw new ArgumentException("Can not convert '" + (string) value + "' to distibution value"); } } return base.ConvertFrom(context, culture, value); } } public class DistributionValues { private const string Val1 = "probabilisticDefaultDistributionVal1"; private const string Val2 = "probabilisticDefaultDistributionVal2"; private const string Val3 = "probabilisticDefaultDistributionVal3"; private const string DistributionStringValueNotSupported = "distributionStringValueNotSupported"; private static readonly string StringValueNotSupported = LocalizationManager.GetTranslatedText(typeof(DistributionValues), DistributionStringValueNotSupported); private readonly List items; private readonly string val1 = GetTranslatedDistributionValue(Val1); private readonly string val2 = GetTranslatedDistributionValue(Val2); private readonly string val3 = GetTranslatedDistributionValue(Val3); public DistributionValues() { items = new List { val1, val2, val3 }; } public ICollection GetNames() { return items; } public string GetStringValue(int val) { return items[val]; } public int GetIntValue(string val) { int i = items.IndexOf(val); if (i == -1) { throw new NotSupportedException(string.Format(StringValueNotSupported, val)); } return i; } private static string GetTranslatedDistributionValue(string id) { switch (id) { case Val1: var v1 = LocalizationManager.GetTranslatedText(typeof(DistributionValues), Val1); return string.IsNullOrEmpty(v1) ? "Normal" : v1; case Val2: var v2 = LocalizationManager.GetTranslatedText(typeof(DistributionValues), Val2); return string.IsNullOrEmpty(v2) ? "Log Normal" : v2; case Val3: var v3 = LocalizationManager.GetTranslatedText(typeof(DistributionValues), Val3); return string.IsNullOrEmpty(v3) ? "None" : v3; } throw new NotSupportedException(string.Format(StringValueNotSupported, id)); } } #endregion }