Index: DamEngine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs =================================================================== diff -u -r5476 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs (.../FillDamFromXmlInput.cs) (revision 5476) +++ DamEngine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlInput.cs (.../FillDamFromXmlInput.cs) (revision 5498) @@ -949,7 +949,7 @@ } isStartPoint = false; - var existingPoint = soilProfile2D.Geometry.GetPointAtLocation(point, GeometryConstants.Accuracy); + var existingPoint = soilProfile2D.Geometry.GetPointAtLocation(point); if (existingPoint == null) { soilProfile2D.Geometry.Points.Add(point); Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs =================================================================== diff -u -r5494 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5494) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5498) @@ -65,54 +65,6 @@ } /// - /// Checks geometry for loose curves and AutoRegeneration - /// - /// - [Validate] - public ValidationResult[] ValidateGeometry() - { - var validationList = new List(); - { - foreach (Point2D point in Points) - { - foreach (Point2D point1 in Points) - { - if (point != point1) - { - var isValidated = false; - foreach (ValidationResult validatedItem in validationList) - { - if (validatedItem.Subject == point) - { - isValidated = true; - } - } - - if (!isValidated) - { - if (Math.Abs(point.X - point1.X) < GeometryConstants.Accuracy && - Math.Abs(point.Z - point1.Z) < GeometryConstants.Accuracy) - { - validationList.Add(new ValidationResult(ValidationResultType.Error, - point + " and " + - point1 + " values are same.", - point1)); - } - } - } - } - } - } - if (Surfaces.Count < 1) - { - validationList.Add(new ValidationResult(ValidationResultType.Error, "No soil surface available.", - this)); - } - - return validationList.ToArray(); - } - - /// /// Deletes the point and the curves it belongs too. /// /// The point. @@ -144,7 +96,7 @@ { if (GetDependentCurveCount(geometryPoint) == 0) { - Remove(geometryPoint, true); + Remove(geometryPoint); } } } @@ -154,7 +106,7 @@ /// Returns true when the loose curve is inside publisherEventArgs surface. /// Calls Regeneration if the funtion returns true. /// - public bool DeleteLooseCurves() + public void DeleteLooseCurves() { SynchronizeLoops(); if (geometryGenerator == null) @@ -188,57 +140,47 @@ { RegenerateGeometry(); } - - return regenerateGeometry; } /// /// 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) + public void DeleteCurve(GeometryCurve geometryCurve, bool validate) { GeometryCurve curve = geometryCurve; if (validate) { if (GetDependentCurveCount(curve.HeadPoint) <= 1 && Points.Contains(curve.HeadPoint)) { - Remove(curve.HeadPoint, false); + Remove(curve.HeadPoint); } if (GetDependentCurveCount(curve.EndPoint) <= 1 && Points.Contains(curve.EndPoint)) { - Remove(curve.EndPoint, false); + Remove(curve.EndPoint); } - Remove(geometryCurve, false); - - if (geometryCurve.SurfaceAtLeft != null || geometryCurve.SurfaceAtRight != null) - { - return true; - } + Remove(geometryCurve); } else { - Remove(geometryCurve, false); + Remove(geometryCurve); } - - return false; } /// /// Synchronizes the loops. /// - public void SynchronizeLoops() + private void SynchronizeLoops() { DeleteAllLoops(); foreach (GeometrySurface surface in Surfaces) { - // #Bka: as real donuts (or holes in geom) are not allowed, there can be no innerloop that - // is NOT an outerloop for another surface. So no need to sync innerloops. + // As real donuts (or holes in geom) are not allowed, there can be no innerloop that + // is NOT an outerloop for another surface. So no need to sync innerloops. if (surface.OuterLoop != null && surface.OuterLoop.IsLoop()) { Loops.Add(surface.OuterLoop); @@ -250,13 +192,12 @@ /// Finds the point at location. /// /// Point location to be found. - /// The tolerance. /// The point at the location; if not found returns null. - public Point2D GetPointAtLocation(Point2D point2D, double tolerance) + public Point2D GetPointAtLocation(Point2D point2D) { for (var i = 0; i < Points.Count; i++) { - if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[i].X, Points[i].Z, tolerance)) + if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[i].X, Points[i].Z, GeometryConstants.Accuracy)) { return Points[i]; } @@ -315,38 +256,27 @@ surfaceLine.SyncPoints(); } - public Point2D CreatePoint(Point2D requestedPoint, bool snapToExistingPoint) + /// + /// Creates a point and adds it to the proper lists when needed. + /// + /// + /// + public Point2D CreatePointAndAddItToTheProperListsWhenNeeded(Point2D requestedPoint) { - Point2D newPoint = DetermineNewPointAndFlags(requestedPoint, out bool flag1, out bool flag2); - if (!flag2 && snapToExistingPoint) + Point2D newPoint = AddRequestedPointAsNewPointWhenNeeded(requestedPoint, out bool isExistingPoint); + if (!NewlyEffectedPoints.Contains(newPoint) && !isExistingPoint) { - int count = Curves.Count; - for (var index = 0; index < count; ++index) - { - GeometryCurve curve = Curves[index]; - if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, newPoint, GeometryConstants.Accuracy)) - { - Routines2D.GetPointOnLineClosestTo(newPoint.X, newPoint.Z, curve.HeadPoint.X, curve.HeadPoint.Z, - curve.EndPoint.X, curve.EndPoint.Z, out Point2D aResultPoint); - - newPoint.X = aResultPoint.X; - newPoint.Z = aResultPoint.Z; - break; - } - } - } - - if (!NewlyEffectedPoints.Contains(newPoint) && !flag1) - { NewlyEffectedPoints.Add(newPoint); } - return newPoint; } - public bool DeletePoint(Point2D aPoint) + /// + /// Deletes the point and the curves it belongs too. + /// + /// + public void DeletePoint(Point2D aPoint) { - var flag = false; var source = new List(); if (Curves.Count > 0) { @@ -356,24 +286,25 @@ CheckForCurvesWherePointIsOnBothConnectedCurvesInLineWithEachOther(aPoint, source); } - Remove(aPoint, false); - if (source.Exists(curve => curve.SurfaceAtLeft != null || curve.SurfaceAtRight != null)) - { - flag = true; - } - + Remove(aPoint); + foreach (GeometryCurve aCurve in source) { DeleteCurve(aCurve, true); } - return flag; + return; } - Remove(aPoint, false); - return false; + Remove(aPoint); } + /// + /// Creates a curve between the two points if no such curve already exists. + /// + /// + /// + /// public GeometryCurve CreateCurve(Point2D aPoint1, Point2D aPoint2) { foreach (GeometryCurve curve in Curves) @@ -389,7 +320,7 @@ geometryGenerator.SetIsUsed(curve1, CurveDirection.Reverse, false); curve1.HeadPoint = aPoint1; curve1.EndPoint = aPoint2; - Create(curve1); + AddDataItemToProperList(curve1); NewlyEffectedCurves.Add(curve1); return curve1; } @@ -406,26 +337,24 @@ Right = Right, Bottom = Bottom }; - foreach (Point2D point in Points) - { - clonedGeometryData.Points.Add(point.Clone()); - } + ClonePoints(clonedGeometryData); - foreach (Point2D point in NewlyEffectedPoints) - { - clonedGeometryData.NewlyEffectedPoints.Add(point.Clone()); - } + CloneNewlyEffectedPoints(clonedGeometryData); - foreach (GeometryCurve curve in Curves) - { - clonedGeometryData.Curves.Add(curve.Clone(clonedGeometryData.Points)); - } + CloneCurves(clonedGeometryData); - foreach (GeometryCurve curve in NewlyEffectedCurves) - { - clonedGeometryData.NewlyEffectedCurves.Add(curve.Clone(clonedGeometryData.NewlyEffectedPoints)); - } + CloneNewlyEffectedCurves(clonedGeometryData); + CloneSurfaces(clonedGeometryData); + + // For the clone, set use geometry generator to null. + // This will ensure that a new generator for this geometry using this geometry will be used. + clonedGeometryData.geometryGenerator = null; + return clonedGeometryData; + } + + private void CloneSurfaces(GeometryData clonedGeometryData) + { foreach (GeometrySurface surface in Surfaces) { GeometryLoop clonedLoop = surface.OuterLoop.Clone(); @@ -438,112 +367,37 @@ clonedSurface.InnerLoops.AddRange(innerLoops); clonedGeometryData.Surfaces.Add(clonedSurface); } - - // For the clone, set use geometry generator to null. - // This will ensure that a new generator for this geometry using this geometry will be used. - clonedGeometryData.geometryGenerator = null; - return clonedGeometryData; } - public bool HandleDelete(List aList) + private void CloneNewlyEffectedCurves(GeometryData clonedGeometryData) { - var regenerationResult = false; - - //SaveGeometryState(); - - foreach (IGeometryObject anObject in aList) + foreach (GeometryCurve curve in NewlyEffectedCurves) { - bool tobeRegenerated; - if (anObject.GetType() == typeof(GeometryPoint)) - { - var selectedPoint = (Point2D) anObject; - //if (Points.Contains(selectedPoint)) - { - tobeRegenerated = DeletePoint(selectedPoint); - if (!regenerationResult) - { - regenerationResult = tobeRegenerated; - } - //DataEventPublisher.DataListModified(Points); - } - } - else if (anObject.GetType() == typeof(GeometryCurve)) - { - var selectedCurve = (GeometryCurve) anObject; - - tobeRegenerated = DeleteCurve(selectedCurve, true); - if (!regenerationResult) - { - regenerationResult = tobeRegenerated; - } - - // if (curveDataList.Contains(selectedCurve)) - // { - // DataEventPublisher.DataListModified(curveDataList); - // } - } - else if (anObject.GetType() == typeof(GeometrySurface)) - { - var selectedSurface = (GeometrySurface) anObject; - DeleteSurface(selectedSurface, true); - //DataEventPublisher.DataListModified(surfaceDataList); - } + clonedGeometryData.NewlyEffectedCurves.Add(curve.Clone(clonedGeometryData.NewlyEffectedPoints)); } + } - if (regenerationResult) + private void CloneCurves(GeometryData clonedGeometryData) + { + foreach (GeometryCurve curve in Curves) { - RegenerateGeometry(); + clonedGeometryData.Curves.Add(curve.Clone(clonedGeometryData.Points)); } - - return regenerationResult; } - /// - /// Deletes the given IGeometrySurface if aValidate is true. - /// - /// - /// - public void DeleteSurface(GeometrySurface aSurface, bool aValidate) + private void CloneNewlyEffectedPoints(GeometryData clonedGeometryData) { - aValidate = aValidate && !geometryGenerator.IsRegenerationOn; - GeometrySurface surface = aSurface; - - GeometryLoop outerLoop = aSurface.OuterLoop; - - if (aValidate) + foreach (Point2D point in NewlyEffectedPoints) { - // Delete all curves which are part of the surface - //DataEventPublisher.BeforeChange(Curves); - //DataEventPublisher.BeforeChange(Points); - - var curvesToBeDeleted = new List(); - foreach (GeometryCurve curve in outerLoop.CurveList) - { - bool allowDelete = curve.SurfaceAtLeft == null || curve.SurfaceAtLeft == surface; - allowDelete &= curve.SurfaceAtRight == null || curve.SurfaceAtRight == surface; - - if (allowDelete) - { - curvesToBeDeleted.Add(curve); - } - else - { - NewlyEffectedCurves.Add(curve); - } - } - - foreach (GeometryCurve delCurve in curvesToBeDeleted) - { - DeleteCurve(delCurve, true); - } - - Remove(outerLoop, false); - Remove(aSurface, false); + clonedGeometryData.NewlyEffectedPoints.Add(point.Clone()); } - else + } + + private void ClonePoints(GeometryData clonedGeometryData) + { + foreach (Point2D point in Points) { - Remove(outerLoop, false); - Remove(surface, false); + clonedGeometryData.Points.Add(point.Clone()); } } @@ -769,41 +623,41 @@ curve1.EndPoint.X.IsLessThanOrEqualTo(curve2.EndPoint.X); } - private Point2D DetermineNewPointAndFlags(Point2D requestedPoint, out bool isExistingPoint, out bool flag2) + private Point2D AddRequestedPointAsNewPointWhenNeeded(Point2D requestedPoint, out bool isExistingPoint) { isExistingPoint = false; - flag2 = false; - // try to find the point in Points - Point2D newPoint = GetPoint(requestedPoint, GeometryConstants.Accuracy); + + // try to find the requested point in Points + Point2D newPoint = GetNewPointFromPointsByLocation(requestedPoint); if (newPoint != null) { + // When found make sure that requested point has the same coordinates the found point requestedPoint.X = newPoint.X; requestedPoint.Z = newPoint.Z; + // Check by reference if the point is already in the list of points if (!Points.Contains(requestedPoint)) { + // if not, make sure a new points is created and added to the list newPoint = null; } else { isExistingPoint = true; } } - + if (newPoint == null) { newPoint = new Point2D(requestedPoint.X, requestedPoint.Z); - Create(newPoint); + AddDataItemToProperList(newPoint); + return newPoint; } - else - { - flag2 = true; - } - + return newPoint; } - private void Create(IGeometryObject aData) + private void AddDataItemToProperList(IGeometryObject aData) { if (aData.GetType() == typeof(Point2D)) { @@ -826,16 +680,15 @@ } /// - /// Checks whether the given point already exists in Points within the requested snap distance. + /// Tries to find the given points in points and returns a new copy when it does /// /// - /// - /// the existing point if found else null - private Point2D GetPoint(Point2D point2D, double snapDistance) + /// the new copy of the given point if found else null + private Point2D GetNewPointFromPointsByLocation(Point2D point2D) { for (var index = 0; index < Points.Count; ++index) { - if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[index].X, Points[index].Z, snapDistance)) + if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[index].X, Points[index].Z, GeometryConstants.Accuracy)) { return new Point2D(Points[index].X, Points[index].Z); } @@ -880,8 +733,8 @@ Curves[index].HeadPoint = source[1].HeadPoint; } - Remove(aPoint, false); - Remove(source[1], false); + Remove(aPoint); + Remove(source[1]); } } } @@ -894,7 +747,6 @@ /// /// The points. /// - [Validate] public List Points { get; } = new List(); /// @@ -1242,81 +1094,40 @@ /// Removes the given data object /// /// The IGeometryObject to remove - /// If set to true [a validate]. /// - public bool Remove(IGeometryObject geometryObject, bool validate) + public void Remove(IGeometryObject geometryObject) { - var removeFromList = false; - var objectlist = new List - { - geometryObject - }; - if (geometryObject == null) { - return false; + return; } if (geometryObject.GetType() == typeof(Point2D)) { var point = (Point2D) geometryObject; - - if (Points.Remove(point)) - { - // TODO: MWDAM-2132, check if code below is still needed - if (validate) - { - HandleDelete(objectlist); - } - - removeFromList = true; - } + Points.Remove(point); } 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 (validate) - { - HandleDelete(objectlist); - } - if (Curves.Remove(geometryCurve)) { RemoveDeletedCurveFromIsUsedCurveLists(geometryCurve); - removeFromList = true; } } } else if (geometryObject.GetType() == typeof(GeometryLoop)) { var geometryLoop = (GeometryLoop) geometryObject; - - if (Loops.Remove(geometryLoop)) - { - // TODO: MWDAM-2132, check if code below is still needed - if (validate) - { - HandleDelete(objectlist); - } - - removeFromList = true; - } + Loops.Remove(geometryLoop); } else if (geometryObject.GetType() == typeof(GeometrySurface)) { var geometrySurface = (GeometrySurface) geometryObject; - - if (Surfaces.Remove(geometrySurface)) - { - removeFromList = true; - } + Surfaces.Remove(geometrySurface); } - - return removeFromList; } /// Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs =================================================================== diff -u -r5460 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 5460) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryHelper.cs (.../GeometryHelper.cs) (revision 5498) @@ -290,8 +290,8 @@ } foreach (GeometryCurve aCurve in geometryCurveList) geometry.DeleteCurve(aCurve, true); - geometry.Remove( outerLoop, false); - geometry.Remove( aSurface, false); + geometry.Remove( outerLoop); + geometry.Remove( aSurface); geometry.NewlyEffectedCurves.Clear(); } Index: DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryDataTests.cs =================================================================== diff -u -r5264 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryDataTests.cs (.../GeometryDataTests.cs) (revision 5264) +++ DamEngine/trunk/src/Deltares.DamEngine.Data.Tests/Geometry/GeometryDataTests.cs (.../GeometryDataTests.cs) (revision 5498) @@ -156,7 +156,7 @@ point4 }); - Point2D point = geometryModel.GetPointAtLocation(new Point2D(x, z), tolerance); + Point2D point = geometryModel.GetPointAtLocation(new Point2D(x, z)); if (isPresent) { Assert.Multiple(() => Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r5460 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5460) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 5498) @@ -1002,16 +1002,15 @@ if (!Routines2D.DetermineIfPointsCoincide(pointXz1.X, pointXz1.Z, intersectionPoint.X, intersectionPoint.Z, 0.001) && !Routines2D.DetermineIfPointsCoincide(pointXz2.X, pointXz2.Z, intersectionPoint.X, intersectionPoint.Z, 0.001)) { - Point2D point = geometryData.CreatePoint(new Point2D(intersectionPoint.X, intersectionPoint.Z), true); + Point2D point = geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); SplitCurve(geometryCurve1, point); flag = true; } if (!Routines2D.DetermineIfPointsCoincide(pointXz3.X, pointXz3.Z, intersectionPoint.X, intersectionPoint.Z, 0.001) && !Routines2D.DetermineIfPointsCoincide(pointXz4.X, pointXz4.Z, intersectionPoint.X, intersectionPoint.Z, 0.001)) { - Point2D point = this.geometryData.CreatePoint(new Point2D(intersectionPoint.X, intersectionPoint.Z), - true); + Point2D point = this.geometryData.CreatePointAndAddItToTheProperListsWhenNeeded(new Point2D(intersectionPoint.X, intersectionPoint.Z)); SplitCurve(geometryCurve2, point); flag = true; } @@ -1352,7 +1351,7 @@ } } foreach (GeometryCurve aCurve in list) - geometryData.DeleteCurve(aCurve, true); //#Bka was true, moet ook true zijn + geometryData.DeleteCurve(aCurve, true); } private void CheckAndAddToIntersectedCurveList(GeometryCurve aCurve) Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs =================================================================== diff -u -r5460 -r5498 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 5460) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geotechnics/SoilProfile2DSurfaceLineHelper.cs (.../SoilProfile2DSurfaceLineHelper.cs) (revision 5498) @@ -216,7 +216,7 @@ IList points = surfaceLine.CalcPoints; GeometryData geometry = result.Geometry; Point2D current1 = points[0].Clone(); - var existingPoint1 = geometry.GetPointAtLocation(current1, GeometryConstants.Accuracy); + var existingPoint1 = geometry.GetPointAtLocation(current1); if (existingPoint1 == null) { Point2D[] leftPoints = geometry.GetLeftPoints().OrderBy(x => x.Z).ToArray(); @@ -238,7 +238,7 @@ while (index < points.Count) { current2 = points[index].Clone(); - var existingPoint2 = geometry.GetPointAtLocation(current2, GeometryConstants.Accuracy); + var existingPoint2 = geometry.GetPointAtLocation(current2); if (existingPoint2 == null) { if (index == checked (points.Count - 1))