//probably this method can be better private void AddVertex(Point webMercatorPoint, Geometry geometry, RecursiveCollection <Locateable> primaryCollection) { if (geometry.Points != null) { var point = this.ToScreen(webMercatorPoint.AsWpfPoint()); var locateable = ToPrimaryLocateable(webMercatorPoint); //geometry.Points.Count > 0, is to see if it is not going to add first point of a new part if (geometry.Points.Count > 0 && geometry.Points.Last().AreExactlyTheSame(webMercatorPoint) == true) { return; } geometry.InsertLastPoint(webMercatorPoint); primaryCollection.Values.Add(locateable); //if (!MassEdit) //{ this._primaryVerticesLayer.Items.Add(locateable); //} if (geometry.Points.Count > 1 && Options.IsEdgeLabelVisible) { this._edgeLabelLayer.Items.Add(ToEdgeLengthLocatable(geometry.Points[geometry.Points.Count - 2], webMercatorPoint)); } } else { AddVertex(webMercatorPoint, geometry.Geometries.Last(), primaryCollection.Collections.Last()); } }
private void UpdateMidPoints(Point point, Point newPoint, int pointIndex, RecursiveCollection <Locateable> midCollection) { try { var displacement = new Point((newPoint.X - point.X) / 2.0, (newPoint.Y - point.Y) / 2.0); var length = midCollection.Values.Count; var leftIndex = GetLeftMidPointIndex(pointIndex, length); var rightIndex = GetRightMidPointIndex(pointIndex, length); Locateable left = leftIndex == int.MinValue ? null : midCollection.Values[leftIndex]; if (left != null) { left.X = left.X + displacement.X; left.Y = left.Y + displacement.Y; } Locateable right = rightIndex == int.MinValue ? null : midCollection.Values[rightIndex]; if (right != null) { right.X = right.X + displacement.X; right.Y = right.Y + displacement.Y; } } catch (Exception ex) { } }
private void ReconstructLocateables() { this._vertices = new RecursiveCollection <Locateable>(); this._midVertices = new RecursiveCollection <Locateable>(); MakeLocateables(this._webMercatorGeometry, _vertices, _midVertices); this._primaryVerticesLayer.Items.Clear(); this._midVerticesLayer.Items.Clear(); this._primaryVerticesLabelLayer.Items.Clear(); var primary = _vertices.GetFlattenCollection(); var mid = _midVertices.GetFlattenCollection(); foreach (var item in mid) { _midVerticesLayer.Items.Add(item); } foreach (var item in primary) { _primaryVerticesLayer.Items.Add(item); } UpdateEdgeLables(); }
public void AddChildrenTest() { var coll = new RecursiveCollection <string>("V0", "V0-0", "V0-1", "V0-2"); coll.Add("V0-3"); Assert.IsTrue(coll.Value == "V0"); Assert.IsTrue(coll[1].Value == "V0-1"); coll[1].Add("V0-1-0"); coll[1].Add("V0-1-1"); coll[1].Add("V0-1-2"); Assert.IsTrue(coll[1][2].Value == "V0-1-2"); coll[2].AddRange( new RecursiveCollection <string>("V0-2-0"), new RecursiveCollection <string>("V0-2-1")); coll[2].AddRange(new[] { new RecursiveCollection <string>("V0-2-2"), new RecursiveCollection <string>("V0-2-3") }); Assert.IsTrue(coll[2].Value == "V0-2"); Assert.IsTrue(coll[2][2].Value == "V0-2-2"); }
private bool UpdateLineSegment(Point point, Point newPoint, Geometry geometry, RecursiveCollection <Locateable> midCollection) { if (geometry.Points != null) { for (int i = 0; i < geometry.Points.Count; i++) { if (geometry.Points[i] == point) { UpdateMidPoints(point, newPoint, i, midCollection); return(true); } } } else { for (int g = 0; g < geometry.Geometries.Count; g++) { var matched = UpdateLineSegment(point, newPoint, geometry.Geometries[g], midCollection.Collections[g]); if (matched) { return(true); } } } return(false); }
private void MakeLocateables(Geometry geometry, RecursiveCollection <Locateable> primaryCollection, RecursiveCollection <Locateable> midCollection) { if (geometry.Points != null) { primaryCollection.Values = new List <Locateable>(); midCollection.Values = new List <Locateable>(); //if (MassEdit) //{ // return; //} for (int i = 0; i < geometry.Points.Count; i++) { var locateable = ToPrimaryLocateable(geometry.Points[i]); primaryCollection.Values.Add(locateable); //do not make mid points in drawing mode if (Options.IsNewDrawing) { continue; } if (geometry.Type == GeometryType.Point || geometry.Type == GeometryType.MultiPoint) { continue; } if (i == geometry.Points.Count - 1) { if (_webMercatorGeometry.IsRingBase()) { midCollection.Values.Add(ToSecondaryLocateable(geometry.Points[i], geometry.Points[0])); } } else { midCollection.Values.Add(ToSecondaryLocateable(geometry.Points[i], geometry.Points[i + 1])); } } } else { primaryCollection.Collections = new List <RecursiveCollection <Locateable> >(); midCollection.Collections = new List <RecursiveCollection <Locateable> >(); foreach (var item in geometry.Geometries) { RecursiveCollection <Locateable> subPrimaryCollection = new RecursiveCollection <Locateable>(); RecursiveCollection <Locateable> subMidCollection = new RecursiveCollection <Locateable>(); MakeLocateables(item, subPrimaryCollection, subMidCollection); primaryCollection.Collections.Add(subPrimaryCollection); midCollection.Collections.Add(subMidCollection); } } }