// Copyright (C) Stichting Deltares 2017. 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.ComponentModel; using System.Linq; using Core.Common.Base.Geometry; using Deltares.WTIStability.Data.Geo; using Ringtoets.MacroStabilityInwards.KernelWrapper.Kernels.UpliftVan; using Ringtoets.MacroStabilityInwards.Primitives; using LandwardDirection = Ringtoets.MacroStabilityInwards.KernelWrapper.Calculators.Input.LandwardDirection; using WTIStabilityLandwardDirection = Deltares.WTIStability.Data.Geo.LandwardDirection; namespace Ringtoets.MacroStabilityInwards.KernelWrapper.Creators.Input { /// /// Creates instances which are required by . /// internal static class SurfaceLineCreator { /// /// Creates a based on information of , /// which can be used by . /// /// The from /// which to take the information. /// The landward direction of the surface line. /// A new with information taken from the . /// Thrown when is null. /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value but unsupported. public static SurfaceLine2 Create(MacroStabilityInwardsSurfaceLine surfaceLine, LandwardDirection landwardDirection) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } var wtiSurfaceLine = new SurfaceLine2 { Name = surfaceLine.Name, LandwardDirection = ConvertLandwardDirection(landwardDirection) }; if (surfaceLine.Points.Any()) { GeometryPoint[] geometryPoints = surfaceLine.LocalGeometry.Select(projectedPoint => new GeometryPoint(projectedPoint.X, projectedPoint.Y)).ToArray(); var geometry = new GeometryPointString(); ((List) geometry.Points).AddRange(geometryPoints); wtiSurfaceLine.Geometry = geometry; foreach (CharacteristicPoint characteristicPoint in CreateCharacteristicPoints(surfaceLine, geometryPoints).ToArray()) { wtiSurfaceLine.CharacteristicPoints.Add(characteristicPoint); } } return wtiSurfaceLine; } /// /// Converts a into a . /// /// The to convert. /// A based on . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value but unsupported. private static WTIStabilityLandwardDirection ConvertLandwardDirection(LandwardDirection landwardDirection) { if (!Enum.IsDefined(typeof(LandwardDirection), landwardDirection)) { throw new InvalidEnumArgumentException(nameof(landwardDirection), (int) landwardDirection, typeof(LandwardDirection)); } switch (landwardDirection) { case LandwardDirection.PositiveX: return WTIStabilityLandwardDirection.PositiveX; case LandwardDirection.NegativeX: return WTIStabilityLandwardDirection.NegativeX; default: throw new NotSupportedException(); } } private static IEnumerable CreateCharacteristicPoints(MacroStabilityInwardsSurfaceLine surfaceLine, GeometryPoint[] geometryPoints) { var characteristicPoints = new List(); for (var i = 0; i < surfaceLine.Points.Length; i++) { characteristicPoints.AddRange(CreateCharacteristicPoint(surfaceLine, geometryPoints, i)); } return characteristicPoints; } private static IEnumerable CreateCharacteristicPoint(MacroStabilityInwardsSurfaceLine surfaceLine, GeometryPoint[] geometryPoints, int index) { Point3D surfaceLinePoint = surfaceLine.Points[index]; GeometryPoint geometryPoint = geometryPoints[index]; IList characteristicPoints = new List(); if (ReferenceEquals(surfaceLine.DitchPolderSide, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DitchPolderSide)); } if (ReferenceEquals(surfaceLine.BottomDitchPolderSide, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.BottomDitchPolderSide)); } if (ReferenceEquals(surfaceLine.BottomDitchDikeSide, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.BottomDitchDikeSide)); } if (ReferenceEquals(surfaceLine.DitchDikeSide, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DitchDikeSide)); } if (ReferenceEquals(surfaceLine.DikeToeAtPolder, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DikeToeAtPolder)); } if (ReferenceEquals(surfaceLine.DikeToeAtRiver, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DikeToeAtRiver)); } if (ReferenceEquals(surfaceLine.DikeTopAtPolder, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DikeTopAtPolder)); } if (ReferenceEquals(surfaceLine.TrafficLoadInside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.TrafficLoadInside)); } if (ReferenceEquals(surfaceLine.TrafficLoadOutside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.TrafficLoadOutside)); } if (ReferenceEquals(surfaceLine.ShoulderBaseInside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.ShoulderBaseInside)); } if (ReferenceEquals(surfaceLine.ShoulderTopInside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.ShoulderTopInside)); } if (ReferenceEquals(surfaceLine.SurfaceLevelInside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.SurfaceLevelInside)); } if (ReferenceEquals(surfaceLine.SurfaceLevelOutside, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.SurfaceLevelOutside)); } if (ReferenceEquals(surfaceLine.DikeTopAtRiver, surfaceLinePoint)) { characteristicPoints.Add(CreateCharacteristicPointOfType(geometryPoint, CharacteristicPointType.DikeTopAtRiver)); } return characteristicPoints; } private static CharacteristicPoint CreateCharacteristicPointOfType(GeometryPoint geometryPoints, CharacteristicPointType pointType) { return new CharacteristicPoint { CharacteristicPointType = pointType, GeometryPoint = geometryPoints }; } } }