//----------------------------------------------------------------------- // // Copyright (c) 2010 Deltares. All rights reserved. // // Tom The // tom.the@deltares.nl // 07-06-2010 // // class for converting dike object coordinates from global to local system // //----------------------------------------------------------------------- using System.Linq; using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.SurfaceLines; namespace Deltares.Dam.Data { using System; using System.Collections.Generic; /// /// Exception class for DikeCoordinateSystemConverter /// public class DikeCoordinateSystemConverterException : Exception { public DikeCoordinateSystemConverterException(string message) : base(message) { } } /// /// class for converting dike object coordinates from global to local system /// public class DikeCoordinateSystemConverter { public void CreateLocalXZObjects(Dike dike) { ThrowIfInvalidDike(dike); foreach (Location location in dike.Locations.Where(x => null != x.SurfaceLine2)) { // This can obviously only be done when SurfaceLine is available // In unit test situations sometimes the surfaceline is not defined ThrowIfAlreadyConvertedToLocalCoordinates(location.AreLocalXZObjectsCreated, String.Format("Location {0}", location.Name)); var coordinateSystemConverter = new CoordinateSystemConverter(); coordinateSystemConverter.DefineGlobalXYZBasedOnLine(location.SurfaceLine2.Geometry); PL1Line localPL1Line = (location.PL1Line != null) ? location.PL1Line.Clone() : null; SurfaceLine2 localSurfaceLine = location.SurfaceLine2.FullDeepClone(); GeometryPoint localSheetPilePoint = (GeometryPoint)location.SheetPilePoint.Clone(); coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(localSurfaceLine.Geometry); if (localPL1Line != null) coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(localPL1Line); if (location.SheetPileLength > 0) { coordinateSystemConverter.ConvertGlobalXYZToLocalXZ(localSheetPilePoint); } location.LocalXZPL1Line = localPL1Line; if (location.LocalXZSurfaceLine2 != null) { location.LocalXZSurfaceLine2.Dispose(); } location.LocalXZSurfaceLine2 = localSurfaceLine; location.LocalXZSheetPilePoint = localSheetPilePoint; location.AreLocalXZObjectsCreated = true; } } /// /// Validate dike and throw exception if not valid /// /// private static void ThrowIfInvalidDike(Dike dike) { try { dike.Validate(); } catch (Exception exception) { throw new DikeCoordinateSystemConverterException(exception.Message); } } /// /// Throws exception if surfaceline already has been converted /// /// private static void ThrowIfAlreadyConvertedToLocalCoordinates(bool isConvertedToLocalCoordinates, string objectDescription) { if (isConvertedToLocalCoordinates) { throw new DikeCoordinateSystemConverterException(String.Format("{0} has already been converted from global to local coordinates", objectDescription)); } } } }