// Copyright (C) Stichting Deltares 2025. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero 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 Affero General Public License for more details. // // You should have received a copy of the GNU Affero 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.Linq; using System.Text; namespace Deltares.DamEngine.Data.General; /// /// Class holding all soilprofiles (1D/2D) and their probabilities as segment. /// public class Segment { private readonly List soilGeometryProbabilities = new List(); /// /// Gets or sets the name. /// /// /// The name. /// public virtual string Name { get; set; } /// /// Gets the soil probalilities for this segment /// public virtual List SoilProfileProbabilities { get { return soilGeometryProbabilities; } } /// /// Gets the most probable soil geometry probability. /// /// Type of the segment failure mechanism. /// public SoilGeometryProbability GetMostProbableSoilGeometryProbability(SegmentFailureMechanismType? segmentFailureMechanismType) { IEnumerable spps = from SoilGeometryProbability spp in soilGeometryProbabilities where !spp.SegmentFailureMechanismType.HasValue || !segmentFailureMechanismType.HasValue || spp.SegmentFailureMechanismType == segmentFailureMechanismType orderby spp.Probability descending select spp; if (spps.Any()) { return spps.First(); } return null; } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { var sb = new StringBuilder(); sb.Append(Name); sb.Append(": "); foreach (SegmentFailureMechanismType type in Enum.GetValues(typeof(SegmentFailureMechanismType))) { sb.Append(type.ToString()); sb.Append(": "); foreach (SoilGeometryProbability spp in SoilProfileProbabilities.Where(x => x.SegmentFailureMechanismType == null || x.SegmentFailureMechanismType == type)) { if (spp.SoilProfile1D != null) { sb.Append($"(1D) {spp.SoilProfile1D.Name} ({spp.Probability}%) "); } else { sb.Append($"(2D) {spp.SoilProfile2D} ({spp.Probability}%) "); } } } return sb.ToString(); } }