// 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 Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.GrassCoverErosionInwards.Data.Properties; namespace Ringtoets.GrassCoverErosionInwards.Data { /// /// Definition for a dike profile for the Grass Cover Erosion Inwards failure mechanism. /// public class DikeProfile { private readonly List foreshoreGeometry; private readonly List dikeGeometry; private RoundedDouble orientation; private RoundedDouble crestLevel; /// /// Initializes a new instance of the class. /// /// The value for . public DikeProfile(Point2D worldCoordinate) { if (worldCoordinate == null) { throw new ArgumentNullException("worldCoordinate"); } orientation = new RoundedDouble(2); crestLevel = new RoundedDouble(2); Name = Resources.DikeProfile_DefaultName; Memo = ""; dikeGeometry = new List(); foreshoreGeometry = new List(); WorldReferencePoint = worldCoordinate; } /// /// Gets or sets the orientation of the dike profile geometry with respect to North /// in degrees. A positive value equals a clockwise rotation. /// /// When is /// not in range [0, 360]. public RoundedDouble Orientation { get { return orientation; } set { var roundedValue = value.ToPrecision(orientation.NumberOfDecimalPlaces); if (roundedValue < 0.0 || roundedValue > 360.0) { string message = string.Format(Resources.DikeProfile_Orientation_Value_0_should_be_in_interval, roundedValue); throw new ArgumentOutOfRangeException("value", message); } orientation = roundedValue; } } /// /// Gets the reference point in world coordinates corresponding to the local coordinate . /// public Point2D WorldReferencePoint { get; private set; } /// /// Gets or sets the local x-coordinate corresponding to the world reference point . /// public double X0 { get; set; } /// /// Gets or sets the name of the dike profile. /// public string Name { get; set; } /// /// Gets or sets the break water object of the dike profile, if any. /// public BreakWater BreakWater { get; set; } /// /// Gets the geometry of the dike with roughness data. /// public IEnumerable DikeGeometry { get { return dikeGeometry; } } /// /// Gets the geometry of the foreshore. /// public IList ForeshoreGeometry { get { return foreshoreGeometry; } } /// /// Gets or sets the height of the dike [m+NAP]. /// public RoundedDouble CrestLevel { get { return crestLevel; } set { crestLevel = value.ToPrecision(crestLevel.NumberOfDecimalPlaces); } } /// /// Gets or sets the optional notes about this instance. /// public string Memo { get; set; } /// /// Indicates if there is a break water object available for this instance or not. /// public bool HasBreakWater { get { return BreakWater != null; } } /// /// Adds a geometry section to . /// /// The new section to add. /// Thrown when the /// is either not connected to or is connected but has /// an incorrect orientation. public void AddDikeGeometrySection(RoughnessProfileSection roughnessProfileSection) { AddProfileSection(dikeGeometry, roughnessProfileSection); } /// /// Adds a profile section to an existing collection profile section, but only if /// it can be connected properly. /// /// The type of profile section. /// Collection of already defined geometry sections. /// The section to add to . /// Thrown when the /// is either not connected to or is connected /// but has an incorrect orientation. private static void AddProfileSection(IList profileSections, T section) where T : ProfileSection { if (profileSections.Count == 0) { profileSections.Add(section); return; } ProfileSection startingSection = profileSections.First(); ProfileSection endingSection = profileSections.Last(); if (section.StartingPoint.Equals(startingSection.StartingPoint) || section.EndingPoint.Equals(endingSection.EndingPoint)) { throw new ArgumentException(Resources.DikeProfile_AddProfileSection_New_segment_connected_with_incorrect_orientation); } if (section.EndingPoint.Equals(startingSection.StartingPoint)) { profileSections.Insert(0, section); } else if (section.StartingPoint.Equals(endingSection.EndingPoint)) { profileSections.Add(section); } else { throw new ArgumentException(Resources.DikeProfile_AddProfileSection_New_segment_not_connected); } } } }