// Copyright (C) Stichting Deltares 2018. All rights reserved. // // This file is part of the application DAM - Clients Library. // // DAM - UI 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 Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Standard.Logging; namespace Deltares.Dam.Data { public class WaterBoardPostProcessRelativeProfilesException : Exception { public WaterBoardPostProcessRelativeProfilesException(string message) : base(message) { } } public static class WaterBoardPostProcessRelativeProfiles { /// /// Creates the absolute profiles based on the original profiles. /// The original profiles are considered to be relative to the specified characteristic point /// 1) Create a copy of the assigned segment for each location /// 2) In the copy the toplevel of the soilprofile will be moved to the z-coordinate of the specified characteristic point /// /// The water board. /// The characteristic point to which the soilprofile toplevel should be moved public static void CreateAbsoluteProfiles(WaterBoard waterBoard, CharacteristicPointType characteristicPointType) { foreach (Dike dike in waterBoard.Dikes) { foreach (Location location in dike.Locations) { var orgSegment = location.Segment; if (orgSegment != null) { var newSegment = new Segment(); newSegment.Name = String.Format("Segment {0}", location.Name); foreach (SoilGeometryProbability orgSoilGeometryProbability in orgSegment.SoilProfileProbabilities) { try { var characteristicGeometryPoint = location.SurfaceLine2.CharacteristicPoints.GetGeometryPoint(characteristicPointType); if (characteristicGeometryPoint == null) { throw new WaterBoardPostProcessRelativeProfilesException(String.Format("Characteristic point {0} is not defined", characteristicPointType)); } if (orgSoilGeometryProbability.SoilGeometryType.Equals(SoilGeometryType.SoilGeometry2D)) { throw new WaterBoardPostProcessRelativeProfilesException("Cannnot apply releative profiles for 2d soilprofiles"); } // Create a copy of the original SoilGeometryProbability SoilGeometryProbability newSoilGeometryProbability = new SoilGeometryProbability(); newSoilGeometryProbability.Assign(orgSoilGeometryProbability); // Move all layer boundaries so toplevel of the soilprofile1D will be at level of specified characteristic point // Dependent if deltaZ is positive or negative, the bottomLevel should be adjusted before or after adjusting the layers // This is necessary, because the bottomlevel is adjusted automatically during adjustment of layers var soilProfile1D = newSoilGeometryProbability.SoilProfile; double deltaZ = characteristicGeometryPoint.Z - soilProfile1D.TopLevel; if (deltaZ < 0) { soilProfile1D.BottomLevel += deltaZ; } foreach (SoilLayer1D soilLayer1D in soilProfile1D.Layers) { soilLayer1D.TopLevel += deltaZ; } if (deltaZ > 0) { soilProfile1D.BottomLevel += deltaZ; } // Add new SoilGeometryProbability to new segment and assign new segment to location newSegment.SoilProfileProbabilities.Add(newSoilGeometryProbability); location.Segment = newSegment; waterBoard.Segments.Add(newSegment); } catch (Exception e) { LogManager.Messages.Add(new LogMessage(LogMessageType.Error, location, String.Format("Error in location '{0}' applying relative height for soilprofile '{1}': {2} ", location.Name, orgSoilGeometryProbability.SoilGeometryName, e.Message))); } } } } } } } }