// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets 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.Linq; using Ringtoets.Piping.Data.Properties; namespace Ringtoets.Piping.Data { /// /// This class represents a soil profile, which was imported for use in a piping calculation. /// public class PipingSoilProfile { private IEnumerable layers; /// /// Creates a new instance ofL , with the given , and . /// A new collection is created for and used in the . /// /// The name of the profile. /// The bottom level of the profile. /// The collection of layers that should be part of the profile. /// Thrown when contains no layers. /// Thrown when is null. public PipingSoilProfile(string name, double bottom, IEnumerable layers) { Name = name; Bottom = bottom; Layers = layers; } /// /// Gets the bottom level of the . /// public double Bottom { get; private set; } /// /// Gets the name of . /// public string Name { get; private set; } /// /// Gets an ordered (by , descending) of /// for the . /// /// Thrown when the value is null. /// Thrown when the value contains no layers. public IEnumerable Layers { get { return layers; } private set { ValidateLayersCollection(value); layers = value.OrderByDescending(l => l.Top).ToArray(); } } /// /// Validates the given . A valid has layers which /// all have values for which are greater than or equal to . /// /// The collection of to validate. /// Thrown when is null. /// Thrown when /// /// contains no layers /// contains a layer with the less than /// /// private void ValidateLayersCollection(IEnumerable collection) { if (collection == null) { throw new ArgumentNullException(@"collection", string.Format(Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers)); } if (!collection.Any()) { throw new ArgumentException(Resources.Error_Cannot_Construct_PipingSoilProfile_Without_Layers); } if (collection.Any(l => l.Top < Bottom)) { throw new ArgumentException(Resources.PipingSoilProfile_Layers_Layer_top_below_profile_bottom); } } /// /// Gets the thickness of the given layer in the . /// Thickness of a layer is determined by its top and the top of the layer below it. /// /// The to determine the thickness of. /// The thickness of the . /// does not contain . public double GetLayerThickness(PipingSoilLayer layer) { var orderedLayers = layers.OrderBy(l => l.Top); var previousLevel = Bottom; foreach (var oLayer in orderedLayers) { if (ReferenceEquals(layer, oLayer)) { return layer.Top - previousLevel; } previousLevel = oLayer.Top; } throw new ArgumentException("Layer not found in profile."); } public override string ToString() { return Name; } } }