// Copyright (C) Stichting Deltares 2024. All rights reserved. // // This file is part of the D-Soil Model application. // // The D-Soil Model application 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.Xml.Serialization; using Deltares.Geographic; using Deltares.Geotechnics.Soils; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using Deltares.Standard.Language; using Deltares.Standard.Maps; using Deltares.Standard.Units; namespace Deltares.DSoilModel.Data { /// /// Class to hold the location of the proposed split of a segment. /// public class SoilSegmentSplitLocation : GeographicPoint, IName { private SoilProfile2D soilProfile2D; private SoilSegment soilSegment; private double xCoordinate; public string Name { get { return (SoilSegment != null) ? SoilSegment.Name : base.ToString(); } set { } } /// /// This method is called when the user moves a point on the map /// /// X /// Y public override void SetCoordinate(double newX, double newY) { if (newX != X || newY != Y) { if (SoilSegment != null && SoilSegment.Points != null && SoilSegment.Points.Count > 0) { // lock on to segment line var snapPoint = SoilSegment.NearestPointOnGeographicString(new GeographicPoint(newX, newY)); XCoordinate = GeographicHelper.Instance.GetOffsetOnGeographicLineString(snapPoint, SoilSegment); base.SetCoordinate(snapPoint.X, snapPoint.Y); } } } /// /// Gets or sets the relative x coordinate of the split location along the segment line. /// [Unit(UnitType.Length)] [Format("F3")] [XmlIgnore] public double XCoordinate { get { return xCoordinate; } set { if (value != xCoordinate ) { DataEventPublisher.BeforeChange(this, prop => prop.XCoordinate); xCoordinate = value; if (SoilSegment != null && SoilSegment.Points != null && SoilSegment.Points.Count > 0) { // update geographic coordinate xCoordinate = Math.Max(0, Math.Min(value, SoilSegment.GetSegmentLength())); var point = GeographicHelper.Instance.FindGeographicPointByOffsetOnLine(xCoordinate, SoilSegment); base.SetCoordinate(point.X, point.Y); } DataEventPublisher.AfterChange(this, prop => prop.XCoordinate); } } } /// /// Gets or sets the Soil Profile 2D (UI element used by DSoilModelGeometryEditor). /// [XmlIgnore] public SoilProfile2D SoilProfile2D { get { return soilProfile2D; } set { DataEventPublisher.BeforeChange(this, prop => prop.SoilProfile2D); soilProfile2D = value; } } /// /// Gets or sets the Soil Profile 2D (UI element used by DSoilModelGeometryEditor). /// [XmlIgnore] public SoilSegment SoilSegment { get { return soilSegment; } set { DataEventPublisher.BeforeChange(this, prop => prop.SoilSegment); soilSegment = value; DataEventPublisher.AfterChange(this, prop => prop.SoilSegment); } } public override string ToString() { return LocalizationManager.GetTranslatedText(this,"SplitLocation"); } } }