Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs =================================================================== diff -u -r4540 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/Point2D.cs (.../Point2D.cs) (revision 4835) @@ -29,7 +29,7 @@ /// Class for pure X,Z coors, to be used in calculation /// [TypeConverter(typeof(ExpandableObjectConverter))] -public class Point2D : IComparable +public class Point2D : IComparable, IGeometryObject { /// /// Initializes a new instance of the class. @@ -107,4 +107,6 @@ return String.Compare(ToString(), obj.ToString(), StringComparison.Ordinal); } + + public string Name { get; set; } } \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (revision 4835) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2024. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero 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.Collections.Generic; +using System.Linq; + +namespace Deltares.DamEngine.Data.Geometry; + +public static class GeometryHelper +{ + /// + /// Extends the geometry left to the given value of x. + /// + /// The x position to move the boundary to. + public static void ExtendGeometryLeft(GeometryData geometry, double toX) + { + Point2D[] leftPoints = geometry.GetLeftPoints().OrderBy(x => x.Z).ToArray(); + List leftCurves = geometry.GetLeftCurves(); + Point2D prevPoint = null; + for (var i = 0; i < leftPoints.Count(); i++) + { + var newPoint = new Point2D(toX, leftPoints[i].Z); + geometry.Points.Add(newPoint); + var newhorizontalCurve = new GeometryCurve(newPoint, leftPoints[i]); + geometry.Curves.Add(newhorizontalCurve); + if (i > 0) + { + var newVerticalCurve = new GeometryCurve(newPoint, prevPoint); + geometry.Curves.Add(newVerticalCurve); + } + + prevPoint = newPoint; + } + + foreach (GeometryCurve geometryCurve in leftCurves) + { + // check if curve is vertical, only then it is on the "old" boundary and needs to be deleted + if (Math.Abs(geometryCurve.HeadPoint.X - geometryCurve.EndPoint.X) < GeometryConstants.Accuracy) + { + geometry.DeleteCurve(geometryCurve, false); + } + } + + geometry.Rebox(); + geometry.Left = toX; + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs =================================================================== diff -u -r4759 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs (.../FactoryForSoilProfiles.cs) (revision 4759) +++ DamEngine/trunk/src/Deltares.DamEngine.TestHelpers/Factories/FactoryForSoilProfiles.cs (.../FactoryForSoilProfiles.cs) (revision 4835) @@ -995,7 +995,7 @@ /// /// Create a soil profile 2D with one layer /// - /// + /// The 2D Soil Profile public static SoilProfile2D CreateSoilProfile2DWithOneLayer() { const string layerName = "Layer"; @@ -1030,6 +1030,47 @@ return soilProfile2D; } + /// + /// Creates 2D SoilProfile with two layers + /// + /// The 2D Soil Profile + public static SoilProfile2D CreateSoilProfile2DWithTwoLayers() + { + const string layer1Name = "Layer1"; + const string layer2Name = "Layer2"; + const string topLayerName = "TopLayer"; + + SoilLayer1D soilLayer1 = CreateSoilLayer(-8, layer1Name); + SoilLayer1D soilLayer2 = CreateSoilLayer(-5, layer2Name); + + var profile = new SoilProfile1D + { + BottomLevel = -10 + }; + profile.Layers.Add(soilLayer1); + profile.Layers.Add(soilLayer2); + + SurfaceLine2 surfaceLine = CreateSurfaceLine(new[] + { + new GeometryPoint(0, 0), + new GeometryPoint(5, 10), + new GeometryPoint(10, 10) + }); + + var soilSurfaceProfile = new SoilSurfaceProfile + { + SoilProfile = profile, + SurfaceLine2 = surfaceLine, + DikeEmbankmentMaterial = new Soil + { + Name = topLayerName + } + }; + + SoilProfile2D soilProfile2D = soilSurfaceProfile.ConvertToSoilProfile2D(); + return soilProfile2D; + } + private static string GetNewUniqueLayerId(SoilProfile1D soilProfile1D) { var num = 0; Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs =================================================================== diff -u -r4772 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs (.../MacroStabilityCommonHelper.cs) (revision 4772) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityCommonHelper.cs (.../MacroStabilityCommonHelper.cs) (revision 4835) @@ -53,6 +53,7 @@ { /// /// Ensures the soil profile2d is filled. + /// In case the soil profile2d is not filled, it will be filled by combining the surfaceline wit the SoilProfile1D. /// /// The sub soil scenario. /// The surface line2. Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r4540 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 4835) @@ -29,9 +29,6 @@ // The main geometry regeneration manager public class GeometryGenerator { - // aValue1 list that collects all surfaces that are at the right and left of effected curves (above) - // will be used to re-assign after regeneration - private readonly Dictionary geometryCurveForwardsIsUsed = new Dictionary(); private readonly Dictionary geometryCurveReversedIsUsed = new Dictionary(); private readonly GeometryData geometryData; @@ -102,6 +99,23 @@ } /// + /// Removes the curve from both the dictionaries geometryCurveForwardsIsUsed and geometryCurveReversedIsUsed. + /// + /// + public void RemoveIsUsedCurve(GeometryCurve aCurve) + { + if ((geometryCurveForwardsIsUsed.ContainsKey(aCurve))) + { + geometryCurveForwardsIsUsed.Remove(aCurve); + } + + if ((geometryCurveReversedIsUsed.ContainsKey(aCurve))) + { + geometryCurveReversedIsUsed.Remove(aCurve); + } + } + + /// /// Adds the curve to the list in given direction. /// /// Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/DebuggingTest.cs =================================================================== diff -u -r4705 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/DebuggingTest.cs (.../DebuggingTest.cs) (revision 4705) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/IntegrationTests/DebuggingTest.cs (.../DebuggingTest.cs) (revision 4835) @@ -39,7 +39,7 @@ /// 2) Copy the file to src\Deltares.DamEngine.IntegrationTests\TestFiles\InputForDebugging.xml /// 3) Run the test in Debugging mode /// - [Test, Ignore("This test is only used for debugging XML files generated by Dam UI")] + [Test] //, Ignore("This test is only used for debugging XML files generated by Dam UI")] public void DebugWithXmlInputFile() { const string inputFilename = "InputForDebugging.xml"; Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r4540 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 4835) @@ -136,6 +136,43 @@ } /// + /// Deletes the curve if the aValidate is true. + /// + /// The curve to delete + /// Indocates whether the validation was successful + /// True if delete successful + public bool DeleteCurve(GeometryCurve geometryCurve, bool validate) + { + GeometryCurve curve = geometryCurve; + + if (validate) + { + if (GetDependentCurveCount(curve.HeadPoint) <= 1 && Points.Contains(curve.HeadPoint)) + { + Remove(curve.HeadPoint, false); + } + + if (GetDependentCurveCount(curve.EndPoint) <= 1 && Points.Contains(curve.EndPoint)) + { + Remove(curve.EndPoint, false); + } + + Remove(geometryCurve, false); + + if (geometryCurve.SurfaceAtLeft != null || geometryCurve.SurfaceAtRight != null) + { + return true; + } + } + else + { + Remove(geometryCurve, false); + } + + return false; + } + + /// /// Synchronizes the loops. /// public void SynchronizeLoops() @@ -633,7 +670,7 @@ /// Gets all points on the Left boundary. /// /// - private List GetLeftPoints() + public List GetLeftPoints() { List geometryPoints = Points.Where(gp => Math.Abs(gp.X - Left) < GeometryConstants.Accuracy).ToList(); return geometryPoints; @@ -650,6 +687,28 @@ } /// + /// Gets the left curves, i.e. all curves that are on or connected to the Left boundary. + /// + /// The left curves + public List GetLeftCurves() + { + var leftCurves = new List(); + foreach (GeometryCurve geometryCurve in Curves) + { + if (geometryCurve.HeadPoint.X <= Left && geometryCurve.EndPoint.X >= Left) + { + leftCurves.Add(geometryCurve); + } + else if (geometryCurve.HeadPoint.X >= Left && geometryCurve.EndPoint.X <= Left) + { + leftCurves.Add(geometryCurve); + } + } + + return leftCurves; + } + + /// /// Gets the geometry bounds. /// /// @@ -705,6 +764,104 @@ } /// + /// Removes the given data object + /// + /// The IGeometryObject to remove + /// If set to true [a validate]. + /// + public bool Remove(IGeometryObject geometryObject, bool validate) + { + var removeFromList = false; + var objectlist = new List + { + geometryObject + }; + + if (geometryObject == null) + { + return false; + } + + if (geometryObject.GetType() == typeof(Point2D)) + { + var geometryPoint = (Point2D) geometryObject; + + if (Points.Remove(geometryPoint)) + { + // TODO: MWDAM-2132, check if code below is still needed + // if (aValidate) + // { + // HandleDelete(objectlist); + // } + // + // DataEventPublisher.DataListModified(pointDataList, geometryPoint); + removeFromList = true; + } + } + else if (geometryObject.GetType() == typeof(GeometryCurve)) + { + var geometryCurve = (GeometryCurve) geometryObject; + + if (Curves.IndexOf(geometryCurve) > -1) + { + // TODO: MWDAM-2132, check if code below is still needed + // if (aValidate) + // { + // HandleDelete(objectlist); + // } + if (Curves.Remove(geometryCurve)) + { + RemoveDeletedCurveFromIsUsedCurveLists(geometryCurve); + removeFromList = true; + // TODO: MWDAM-2132, check if code below is still needed + // DataEventPublisher.DataListModified(curveDataList, geometryCurve); + } + } + } + else if (geometryObject.GetType() == typeof(GeometryLoop)) + { + var geometryLoop = (GeometryLoop) geometryObject; + + if (Loops.Remove(geometryLoop)) + { + // TODO: MWDAM-2132, check if code below is still needed + // DataEventPublisher.DataListModified(loopDataList, geometryLoop); + // + // if (aValidate) + // { + // HandleDelete(objectlist); + // } + removeFromList = true; + } + } + else if (geometryObject.GetType() == typeof(GeometrySurface)) + { + var geometrySurface = (GeometrySurface) geometryObject; + + if (Surfaces.Remove(geometrySurface)) + { + removeFromList = true; + // TODO: MWDAM-2132, check if code below is still needed + // DataEventPublisher.DataListModified(surfaceDataList, geometrySurface); + } + } + + // TODO: MWDAM-2132, check if code below is still needed + // DataEventPublisher.AfterChange(this); + + return removeFromList; + } + + /// + /// Removes the deleted curve from IsUsedCurve lists. + /// + /// The curve to delete. + private void RemoveDeletedCurveFromIsUsedCurveLists(GeometryCurve geometryCurve) + { + geometryGenerator.RemoveIsUsedCurve(geometryCurve); + } + + /// /// deletes all the Loop from IGeometryLoop. /// private void DeleteAllLoops() @@ -718,6 +875,25 @@ #region calculation function + private int GetDependentCurveCount(Point2D aPoint) + { + int curveCount = Curves.Count; + var curvePointDependency = 0; + + if (curveCount > 0) + { + for (var index = 0; index < curveCount; index++) + { + if (Curves[index].HeadPoint == aPoint || Curves[index].EndPoint == aPoint) + { + curvePointDependency++; + } + } + } + + return curvePointDependency; + } + /// /// CheckIfIntersectStricktly /// Determines if two lines intersect each other stricktly (so no extrapolated points). Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs =================================================================== diff -u --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs (revision 0) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geotechnics/GeometryHelperTests.cs (revision 4835) @@ -0,0 +1,46 @@ +// Copyright (C) Stichting Deltares 2024. All rights reserved. +// +// This file is part of the Dam Engine. +// +// The Dam Engine is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero 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 Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero 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 Deltares.DamEngine.Data.Geometry; +using Deltares.DamEngine.Data.Geotechnics; +using Deltares.DamEngine.TestHelpers.Factories; +using NUnit.Framework; + +namespace Deltares.DamEngine.Data.Tests.Geotechnics; + +[TestFixture] +public class GeometryHelperTests +{ + const double cTolerance = 1e-6; + + [Test] + public void GivenTwoLayerGeometryWhenExtendingLeftThenLeftBoundaryIsChanged() + { + // Given + SoilProfile2D soilProfile2D = FactoryForSoilProfiles.CreateSoilProfile2DWithTwoLayers(); + + // When + GeometryHelper.ExtendGeometryLeft(soilProfile2D.Geometry, -2); + + // Then + Assert.That(soilProfile2D.Geometry.Left, Is.EqualTo(-2).Within(cTolerance)); + } +} \ No newline at end of file Index: DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/TestFiles/InputForDebugging.xml =================================================================== diff -u -r4273 -r4835 --- DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/TestFiles/InputForDebugging.xml (.../InputForDebugging.xml) (revision 4273) +++ DamEngine/trunk/src/Deltares.DamEngine.IntegrationTests/TestFiles/InputForDebugging.xml (.../InputForDebugging.xml) (revision 4835) @@ -1,1182 +1,493 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file