Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs
===================================================================
diff -u -r4899 -r5028
--- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 4899)
+++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryData.cs (.../GeometryData.cs) (revision 5028)
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Deltares.DamEngine.Data.Standard;
using Deltares.DamEngine.Data.Standard.Language;
using Deltares.DamEngine.Data.Standard.Validation;
@@ -750,8 +751,8 @@
/// The points on the Left boundary
public List GetLeftPoints()
{
- List geometryPoints = Points.Where(gp => Math.Abs(gp.X - Left) < GeometryConstants.Accuracy).ToList();
- return geometryPoints;
+ List leftPoints = Points.Where(gp => Math.Abs(gp.X - Left) < GeometryConstants.Accuracy).ToList();
+ return leftPoints;
}
///
@@ -760,8 +761,8 @@
/// The points on the Right boundary
public List GetRightPoints()
{
- List geometryPoints = Points.Where(point => Math.Abs(point.X - Right) < GeometryConstants.Accuracy).ToList();
- return geometryPoints;
+ List rightPoints = Points.Where(point => Math.Abs(point.X - Right) < GeometryConstants.Accuracy).ToList();
+ return rightPoints;
}
///
@@ -878,17 +879,17 @@
if (geometryObject.GetType() == typeof(Point2D))
{
- var geometryPoint = (Point2D) geometryObject;
+ var point = (Point2D) geometryObject;
- if (Points.Remove(geometryPoint))
+ if (Points.Remove(point))
{
// TODO: MWDAM-2132, check if code below is still needed
// if (aValidate)
// {
// HandleDelete(objectlist);
// }
//
- // DataEventPublisher.DataListModified(pointDataList, geometryPoint);
+ // DataEventPublisher.DataListModified(pointDataList, point);
removeFromList = true;
}
}
@@ -992,10 +993,10 @@
/// CheckIfIntersectStricktly
/// Determines if two lines intersect each other stricktly (so no extrapolated points).
///
- /// Line 1 GeometryPoint 1
- /// Line 1 GeometryPoint 2
- /// Line 2 GeometryPoint 1
- /// Line 2 GeometryPoint 2
+ /// Line 1 Point2D 1
+ /// Line 1 Point2D 2
+ /// Line 2 Point2D 1
+ /// Line 2 Point2D 2
/// Intersection coordinates
/// True if lines intersect each other
private bool CheckIfIntersectStricktly(Point2D beginPoint1, Point2D endPoint1,
@@ -1017,10 +1018,10 @@
/// CheckIfIntersect
/// Determines if two lines intersect each other stricktly (so no extrapolated points).
///
- /// Line 1 GeometryPoint 1
- /// Line 1 GeometryPoint 2
- /// Line 2 GeometryPoint 1
- /// Line 2 GeometryPoint 2
+ /// Line 1 Point2D 1
+ /// Line 1 Point2D 2
+ /// Line 2 Point2D 1
+ /// Line 2 Point2D 2
/// Intersection coordinates
/// True if lines intersect each other
public bool CheckIfIntersect(double[] aL1P1, double[] aL1P2, double[] aL2P1, double[] aL2P2,
@@ -1159,4 +1160,209 @@
#endregion
#endregion
+
+ public Point2D CreatePoint(Point2D requestedPoint, bool snapToExistingPoint)
+ {
+ long num = 0;
+ Point2D newPoint = null;
+ bool flag1 = false;
+ if (num < 1L)
+ {
+ bool flag2 = false;
+ if (snapToExistingPoint)
+ newPoint = GetPoint(requestedPoint, 0.001);
+ if (newPoint != null)
+ {
+ requestedPoint.X = newPoint.X;
+ requestedPoint.Z = newPoint.Z;
+ if (!Points.Contains(requestedPoint))
+ newPoint = null;
+ else
+ flag1 = true;
+ }
+ if (newPoint == null)
+ {
+ newPoint = new Point2D(requestedPoint.X, requestedPoint.Z);
+ Create((IGeometryObject) newPoint);
+ }
+ else
+ flag2 = true;
+ if (!flag2 & snapToExistingPoint)
+ {
+ int count = this.Curves.Count;
+ for (int index = 0; index < count; ++index)
+ {
+ GeometryCurve curve = this.Curves[index];
+ if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, newPoint, 0.25))
+ {
+ double aResultX;
+ double aResultZ;
+ Routines2D.GetPointOnLineClosestTo(newPoint.X, newPoint.Z, curve.HeadPoint.X, curve.HeadPoint.Z,
+ curve.EndPoint.X, curve.EndPoint.Z, out aResultX, out aResultZ);
+ newPoint.X = aResultX;
+ newPoint.Z = aResultZ;
+ break;
+ }
+ }
+ }
+ }
+ if (!NewlyEffectedPoints.Contains(newPoint) && !flag1)
+ NewlyEffectedPoints.Add(newPoint);
+ return newPoint;
+ }
+
+ public IGeometryObject Create(IGeometryObject aData)
+ {
+ if (aData == null)
+ return (IGeometryObject) null;
+ if (aData.GetType() == typeof (Point2D))
+ {
+ Point2D point = (Point2D) aData;
+ this.Points.Add(point);
+ //point.Name = (pointIndex++.ToString());
+ }
+ else if (aData.GetType() == typeof (GeometryCurve))
+ {
+ GeometryCurve geometryCurve = (GeometryCurve) aData;
+ Curves.Add(geometryCurve);
+ //geometryCurve.SetName(this.curveIndex++.ToString());
+ }
+ else if (aData.GetType() == typeof (GeometryLoop))
+ Loops.Add((GeometryLoop) aData);
+ else if (aData.GetType() == typeof (GeometrySurface))
+ Surfaces.Add((GeometrySurface) aData);
+ return aData;
+ }
+
+ public Point2D GetPoint(Point2D point2D, double snapDistance)
+ {
+ for (int index = 0; index < Points.Count; ++index)
+ {
+ if (Routines2D.DetermineIfPointsCoincide(point2D.X, point2D.Z, Points[index].X, Points[index].Z, snapDistance))
+ return new Point2D(Points[index].X, Points[index].Z);
+ }
+ return null;
+ }
+
+ public bool DeletePoint(Point2D aPoint)
+ {
+ int num = 0;
+ bool flag = false;
+ List source = new List();
+ if (Curves.Count > 0)
+ {
+ source.AddRange(Curves.Where((Func) (c => c.HeadPoint == aPoint || c.EndPoint == aPoint)));
+ if (num + source.Count == 2)
+ {
+ Point2D line1Point1 = new Point2D();
+ Point2D line2Point1 = new Point2D();
+ line1Point1.Init(source[0].HeadPoint != aPoint ? source[0].HeadPoint : source[0].EndPoint);
+ line2Point1.Init(source[1].HeadPoint != aPoint ? source[1].HeadPoint : source[1].EndPoint);
+ double angle = Routines2D.FindAngle(line1Point1, aPoint, line2Point1, aPoint);
+ if (angle.IsGreaterThanOrEqualTo(179.0) && angle.IsLessThanOrEqualTo(181.0))
+ {
+ for (int index = 0; index < Curves.Count - 1; ++index)
+ {
+ if (Curves[index] == source[0])
+ {
+ if (Curves[index].EndPoint != source[1].EndPoint && aPoint == source[0].HeadPoint && aPoint == source[1].HeadPoint)
+ Curves[index].HeadPoint = source[1].EndPoint;
+ else if (Curves[index].EndPoint != source[1].EndPoint && aPoint == source[1].HeadPoint)
+ Curves[index].EndPoint = source[1].EndPoint;
+ else if (Curves[index].HeadPoint != source[1].HeadPoint && aPoint == Curves[index].EndPoint)
+ Curves[index].EndPoint = source[1].HeadPoint;
+ else if (Curves[index].HeadPoint == source[1].EndPoint)
+ Curves[index].HeadPoint = source[1].HeadPoint;
+ Remove(aPoint, false);
+ Remove(source[1], false);
+ }
+ }
+ }
+ }
+ Remove(aPoint, false);
+ if (source.Any((Func) (curve => curve.SurfaceAtLeft != null || curve.SurfaceAtRight != null)))
+ flag = true;
+ foreach (GeometryCurve aCurve in source)
+ DeleteCurve(aCurve, true);
+ return flag;
+ }
+ Remove(aPoint, false);
+ return false;
+ }
+
+ public GeometryCurve CreateCurve(List points, Point2D aPoint1, Point2D aPoint2)
+ {
+ if (aPoint1 == null && aPoint2 == null)
+ {
+ if (points.Count < 1)
+ return null;
+ Point2D geometryPoint1 = null;
+ if (points.Count == 1)
+ {
+ Point2D point = points[0];
+ Point2D aPoint = new Point2D(point.X, point.Z);
+ List aCurveList = new List();
+ GetCurvesCoincidingInputPoint(aPoint, ref aCurveList);
+ if (aCurveList.Count <= 0)
+ return null;
+ geometryGenerator.SplitCurvesAtCoincidentPoint(CreatePoint(point, true), aCurveList);
+ }
+ else
+ {
+ for (int index = 0; index < points.Count - 1; ++index)
+ {
+ Point2D geometryPoint2 = index != 0 ? geometryPoint1 : CreatePoint(points[index], true);
+ geometryPoint1 = CreatePoint(points[index + 1], true);
+ bool flag = false;
+ foreach (GeometryCurve curve in Curves)
+ {
+ if (curve.HeadPoint == geometryPoint2 && curve.EndPoint == geometryPoint1 ||
+ curve.HeadPoint == geometryPoint1 && curve.EndPoint == geometryPoint2)
+ {
+ flag = true;
+ }
+ }
+ if (!flag)
+ {
+ GeometryCurve geometryCurve = new GeometryCurve();
+ geometryGenerator.SetIsUsed(geometryCurve, CurveDirection.Forward, false);
+ geometryGenerator.SetIsUsed(geometryCurve, CurveDirection.Reverse, false);
+ geometryCurve.HeadPoint = geometryPoint2;
+ geometryCurve.EndPoint = geometryPoint1;
+ Create((IGeometryObject) geometryCurve);
+ NewlyEffectedCurves.Add(geometryCurve);
+ }
+ }
+ }
+ RegenerateGeometry(); // #Bka: dit is een directe call, geen delayed invoke. Kan tot problemen leiden (eeuwig ronddraaien)
+ return Curves.Count > 0 ? Curves[0] : (GeometryCurve) null;
+ }
+ foreach (GeometryCurve curve in this.Curves)
+ {
+ if (curve.HeadPoint == aPoint1 && curve.EndPoint == aPoint2 || curve.HeadPoint == aPoint2 && curve.EndPoint == aPoint1)
+ {
+ return curve;
+ }
+ }
+ GeometryCurve curve1 = new GeometryCurve();
+ geometryGenerator.SetIsUsed(curve1, CurveDirection.Forward, false);
+ geometryGenerator.SetIsUsed(curve1, CurveDirection.Reverse, false);
+ curve1.HeadPoint = aPoint1;
+ curve1.EndPoint = aPoint2;
+ this.Create((IGeometryObject) curve1);
+ NewlyEffectedCurves.Add(curve1);
+ return curve1;
+ }
+
+ public void GetCurvesCoincidingInputPoint(Point2D aPoint, ref List aCurveList)
+ {
+ aCurveList.Clear();
+ int count = this.Curves.Count;
+ for (int index = 0; index < count; ++index)
+ {
+ GeometryCurve curve = this.Curves[index];
+ if (Routines2D.DoesPointExistInLine(curve.HeadPoint, curve.EndPoint, aPoint, 0.001))
+ aCurveList.Add(curve);
+ }
+ }
}
\ No newline at end of file