// 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 log4net; using Ringtoets.Common.IO.Exceptions; using Ringtoets.Common.IO.Properties; using Ringtoets.Common.IO.SurfaceLines; using Ringtoets.Piping.Primitives; namespace Ringtoets.Piping.IO.SurfaceLines { /// /// Extension methods for the class. /// public static class PipingSurfaceLineExtensions { private static readonly ILog log = LogManager.GetLogger(typeof(PipingSurfaceLineExtensions)); /// /// Tries to set the relevant characteristic points from the /// on the . /// /// The surface line to set the characteristic points for. /// The characteristic points to set, if the collection is valid. /// Thrown when is null. /// Thrown when defines /// a dike toe at polder side in front of the dike toe at river side. public static void SetCharacteristicPoints(this PipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (surfaceLine == null) { throw new ArgumentNullException(nameof(surfaceLine)); } if (characteristicPoints == null) { return; } surfaceLine.ValidateDikeToesInOrder(characteristicPoints); surfaceLine.TrySetDikeToeAtRiver(characteristicPoints.DikeToeAtRiver); surfaceLine.TrySetDitchDikeSide(characteristicPoints.DitchDikeSide); surfaceLine.TrySetBottomDitchDikeSide(characteristicPoints.BottomDitchDikeSide); surfaceLine.TrySetBottomDitchPolderSide(characteristicPoints.BottomDitchPolderSide); surfaceLine.TrySetDitchPolderSide(characteristicPoints.DitchPolderSide); surfaceLine.TrySetDikeToeAtPolder(characteristicPoints.DikeToeAtPolder); } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetDitchPolderSide(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetDitchPolderSideAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetBottomDitchPolderSide(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetBottomDitchPolderSideAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetBottomDitchDikeSide(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetBottomDitchDikeSideAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetDitchDikeSide(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetDitchDikeSideAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetDikeToeAtRiver(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetDikeToeAtRiverAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } /// /// Tries to set the at the location of /// . /// /// The to set the /// for. /// The point at which to set the . private static void TrySetDikeToeAtPolder(this PipingSurfaceLine surfaceLine, Point3D point) { if (point != null) { try { surfaceLine.SetDikeToeAtPolderAt(point); } catch (ArgumentException e) { LogError(surfaceLine, e); } } } private static void LogError(PipingSurfaceLine surfaceLine, ArgumentException e) { log.ErrorFormat(Resources.SurfaceLinesCsvImporter_CharacteristicPoint_of_SurfaceLine_0_skipped_cause_1_, surfaceLine.Name, e.Message); } /// /// Validates whether or not the dike toes are in the right order. /// /// The surface line. /// The characteristic points (possibly) containing the dike toes. /// Thrown when the dike toes are not in the right order. private static void ValidateDikeToesInOrder(this PipingSurfaceLine surfaceLine, CharacteristicPoints characteristicPoints) { if (characteristicPoints.DikeToeAtRiver != null && characteristicPoints.DikeToeAtPolder != null) { Point2D localDikeToeAtRiver = surfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtRiver); Point2D localDikeToeAtPolder = surfaceLine.GetLocalPointFromGeometry(characteristicPoints.DikeToeAtPolder); if (localDikeToeAtPolder.X <= localDikeToeAtRiver.X) { string message = string.Format(Resources.SurfaceLinesCsvImporter_CheckCharacteristicPoints_EntryPointL_greater_or_equal_to_ExitPointL_for_0_, characteristicPoints.Name); throw new ImportedDataTransformException(message); } } } } }