// 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 Core.Common.Base.Geometry; using Ringtoets.Common.Data; using RingtoetsCommonDataResources = Ringtoets.Common.Data.Properties.Resources; namespace Ringtoets.MacroStabilityInwards.Primitives { /// /// Definition of a surface line for macro stability inwards. /// public class MacroStabilityInwardsSurfaceLine : MechanismSurfaceLineBase { /// /// Creates a new instance of . /// /// The name of the surface line. /// Thrown when /// is null. public MacroStabilityInwardsSurfaceLine(string name) : base(name) {} /// /// Gets the location which generalizes the height of the surface /// on the outside of the polder. /// public Point3D SurfaceLevelOutside { get; private set; } /// /// Gets the location of dike toe when approaching from outside /// the polder. /// public Point3D DikeToeAtRiver { get; private set; } /// /// Gets the location of the start of traffic load when approaching /// from outside the polder. /// public Point3D TrafficLoadOutside { get; private set; } /// /// Gets the location of the start of traffic load when approaching /// from inside the polder. /// public Point3D TrafficLoadInside { get; private set; } /// /// Gets the location of the top of the dike when approaching from /// inside the polder. /// public Point3D DikeTopAtPolder { get; private set; } /// /// Gets the location of the top of the dike when approaching from /// outside the polder. /// public Point3D DikeTopAtRiver { get; private set; } /// /// Gets the location where the shoulder on the side of the polder /// connects with the dike. /// public Point3D ShoulderBaseInside { get; private set; } /// /// Gets the location where the shoulder on the side of the polder /// declines towards the location of the dike toe when approaching from inside /// the polder. /// public Point3D ShoulderTopInside { get; private set; } /// /// Gets the location of dike toe when approaching from inside /// the polder. /// public Point3D DikeToeAtPolder { get; private set; } /// /// Gets the location of the start of the ditch when approaching /// from the dike. /// public Point3D DitchDikeSide { get; private set; } /// /// Gets the location of the bottom of the ditch when approaching /// from the dike. /// public Point3D BottomDitchDikeSide { get; private set; } /// /// Gets the location of the bottom of the ditch when approaching /// from inside the polder. /// public Point3D BottomDitchPolderSide { get; private set; } /// /// Gets the location of the start of the ditch when approaching from /// inside the polder. /// public Point3D DitchPolderSide { get; private set; } /// /// Gets the location which generalizes the surface level on the /// inside of the polder. /// public Point3D SurfaceLevelInside { get; private set; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDitchPolderSideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DitchPolderSide); } DitchPolderSide = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetBottomDitchPolderSideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_BottomDitchPolderSide); } BottomDitchPolderSide = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetBottomDitchDikeSideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_BottomDitchDikeSide); } BottomDitchDikeSide = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDitchDikeSideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DitchDikeSide); } DitchDikeSide = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDikeTopAtPolderAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtPolder); } DikeTopAtPolder = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDikeTopAtRiverAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DikeTopAtRiver); } DikeTopAtRiver = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetShoulderBaseInsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_ShoulderBaseInside); } ShoulderBaseInside = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetShoulderTopInsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_ShoulderTopInside); } ShoulderTopInside = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetTrafficLoadInsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_TrafficLoadInside); } TrafficLoadInside = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetTrafficLoadOutsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_TrafficLoadOutside); } TrafficLoadOutside = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDikeToeAtRiverAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtRiver); } DikeToeAtRiver = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetDikeToeAtPolderAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_DikeToeAtPolder); } DikeToeAtPolder = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetSurfaceLevelInsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelInside); } SurfaceLevelInside = geometryPoint; } /// /// Sets the at the given point. /// /// The location as a which to set as the . /// Thrown when doesn't contain a at /// . /// Thrown when is null. public void SetSurfaceLevelOutsideAt(Point3D point) { Point3D geometryPoint = GetPointFromGeometry(point); if (geometryPoint == null) { throw CreatePointNotInGeometryException(point, RingtoetsCommonDataResources.CharacteristicPoint_SurfaceLevelOutside); } SurfaceLevelOutside = geometryPoint; } /// /// Copies the property values of the to /// the . /// /// The /// to get the property values from. /// Thrown when /// is null. public void CopyProperties(MacroStabilityInwardsSurfaceLine fromSurfaceLine) { if (fromSurfaceLine == null) { throw new ArgumentNullException(nameof(fromSurfaceLine)); } Name = fromSurfaceLine.Name; ReferenceLineIntersectionWorldPoint = fromSurfaceLine.ReferenceLineIntersectionWorldPoint != null ? new Point2D(fromSurfaceLine.ReferenceLineIntersectionWorldPoint) : null; SetGeometry(fromSurfaceLine.Points); SetCharacteristicPoints(fromSurfaceLine); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } var other = obj as MacroStabilityInwardsSurfaceLine; return other != null && Equals((MacroStabilityInwardsSurfaceLine) obj); } public override int GetHashCode() { unchecked { int hashCode = Name.GetHashCode(); foreach (Point3D point in Points) { hashCode = (hashCode * 397) ^ point.GetHashCode(); } hashCode = (hashCode * 397) ^ (SurfaceLevelInside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (SurfaceLevelOutside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (TrafficLoadInside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (TrafficLoadOutside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DikeTopAtPolder?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DikeTopAtRiver?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ShoulderBaseInside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ShoulderTopInside?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DikeToeAtPolder?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DikeToeAtRiver?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DitchDikeSide?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (DitchPolderSide?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (BottomDitchDikeSide?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (BottomDitchPolderSide?.GetHashCode() ?? 0); return hashCode; } } private void SetCharacteristicPoints(MacroStabilityInwardsSurfaceLine fromSurfaceLine) { SurfaceLevelOutside = PointFromGeometryOrNull(fromSurfaceLine.SurfaceLevelOutside); TrafficLoadOutside = PointFromGeometryOrNull(fromSurfaceLine.TrafficLoadOutside); TrafficLoadInside = PointFromGeometryOrNull(fromSurfaceLine.TrafficLoadInside); DikeTopAtPolder = PointFromGeometryOrNull(fromSurfaceLine.DikeTopAtPolder); DikeTopAtRiver = PointFromGeometryOrNull(fromSurfaceLine.DikeTopAtRiver); ShoulderBaseInside = PointFromGeometryOrNull(fromSurfaceLine.ShoulderBaseInside); ShoulderTopInside = PointFromGeometryOrNull(fromSurfaceLine.ShoulderTopInside); BottomDitchDikeSide = PointFromGeometryOrNull(fromSurfaceLine.BottomDitchDikeSide); BottomDitchPolderSide = PointFromGeometryOrNull(fromSurfaceLine.BottomDitchPolderSide); DikeToeAtPolder = PointFromGeometryOrNull(fromSurfaceLine.DikeToeAtPolder); DikeToeAtRiver = PointFromGeometryOrNull(fromSurfaceLine.DikeToeAtRiver); DitchDikeSide = PointFromGeometryOrNull(fromSurfaceLine.DitchDikeSide); DitchPolderSide = PointFromGeometryOrNull(fromSurfaceLine.DitchPolderSide); SurfaceLevelInside = PointFromGeometryOrNull(fromSurfaceLine.SurfaceLevelInside); } private Point3D PointFromGeometryOrNull(Point3D point3D) { return point3D != null ? GetPointFromGeometry(point3D) : null; } private bool Equals(MacroStabilityInwardsSurfaceLine other) { return string.Equals(Name, other.Name) && Equals(ReferenceLineIntersectionWorldPoint, other.ReferenceLineIntersectionWorldPoint) && EqualGeometricPoints(other.Points) && EqualCharacteristicPoints(other); } private bool EqualCharacteristicPoints(MacroStabilityInwardsSurfaceLine other) { return Equals(SurfaceLevelInside, other.SurfaceLevelInside) && Equals(SurfaceLevelOutside, other.SurfaceLevelOutside) && Equals(TrafficLoadInside, other.TrafficLoadInside) && Equals(TrafficLoadOutside, other.TrafficLoadOutside) && Equals(DikeTopAtPolder, other.DikeTopAtPolder) && Equals(DikeTopAtRiver, other.DikeTopAtRiver) && Equals(ShoulderBaseInside, other.ShoulderBaseInside) && Equals(ShoulderTopInside, other.ShoulderTopInside) && Equals(DikeToeAtPolder, other.DikeToeAtPolder) && Equals(DikeToeAtRiver, other.DikeToeAtRiver) && Equals(DitchDikeSide, other.DitchDikeSide) && Equals(DitchPolderSide, other.DitchPolderSide) && Equals(BottomDitchDikeSide, other.BottomDitchDikeSide) && Equals(BottomDitchPolderSide, other.BottomDitchPolderSide); } private bool EqualGeometricPoints(Point3D[] otherPoints) { int nrOfOtherPoints = otherPoints.Length; if (Points.Length != nrOfOtherPoints) { return false; } for (var index = 0; index < Points.Length; index++) { if (!Points[index].Equals(otherPoints[index])) { return false; } } return true; } } }