public void UpdatePosition() { PointCollection points = (Figure.Segments[0] as PolyLineSegment).Points; Point prevPosition = points[PrevThumb.GetIndex()]; Point nextPosition = points[NextThumb.GetIndex()]; Canvas.SetLeft(this, (prevPosition.X + nextPosition.X) * 0.5 * scale); Canvas.SetTop(this, (prevPosition.Y + nextPosition.Y) * 0.5 * scale); }
public void InsertVertex(/*bool forceDrag = false*/) { if (PrevThumb != null && NextThumb != null) { int prevIndex = PrevThumb.GetIndex(); int nextIndex = NextThumb.GetIndex(); int newIndex = nextIndex > prevIndex ? nextIndex : prevIndex + 1; //Correct handling of closed curves (Figure.Segments[0] as PolyLineSegment).Points.Insert(newIndex, new Point(Canvas.GetLeft(this) / Scale, Canvas.GetTop(this) / Scale)); MoveThumb moveThumb = new MoveThumb(ParentCanvas, Figure, newIndex, Scale, ThumbList /*, IsDragging || forceDrag*/); ThumbList.Insert(newIndex, moveThumb); moveThumb.PrevThumb = PrevThumb; moveThumb.NextThumb = NextThumb; PrevThumb.NextThumb = moveThumb; NextThumb.PrevThumb = moveThumb; prevIndex = PrevThumb.GetIndex(); nextIndex = NextThumb.GetIndex(); //DependencyObject p = LogicalTreeHelper.GetParent(this); //MapCanvas parent = (MapCanvas)VisualTreeHelper.GetParent(this); //MapCanvas parent = ((MapCanvas)Parent); InsertThumb prevInsertThumb = new InsertThumb(ParentCanvas, Figure, prevIndex, newIndex, Scale, ThumbList); prevInsertThumb.PrevThumb = PrevThumb; prevInsertThumb.NextThumb = moveThumb; moveThumb.PrevInsertThumb = prevInsertThumb; PrevThumb.NextInsertThumb = prevInsertThumb; ParentCanvas.Children.Add(prevInsertThumb); InsertThumb nextInsertThumb = new InsertThumb(ParentCanvas, Figure, newIndex, nextIndex, Scale, ThumbList); nextInsertThumb.PrevThumb = moveThumb; nextInsertThumb.NextThumb = NextThumb; moveThumb.NextInsertThumb = nextInsertThumb; NextThumb.PrevInsertThumb = nextInsertThumb; ParentCanvas.Children.Add(nextInsertThumb); ParentCanvas.Children.Remove(this); ParentCanvas.Children.Add(moveThumb); } }
public void DeleteVertex() { PointCollection points = (Figure.Segments[0] as PolyLineSegment).Points; if (points.Count > 2) { int index = GetIndex(); points.RemoveAt(index); ThumbList.RemoveAt(index); if (index == 0) { Figure.StartPoint = points[0]; } //MapCanvas parent = ((MapCanvas)Parent); if (PrevThumb == null) { NextThumb.PrevThumb = null; NextThumb.PrevInsertThumb = null; } else if (NextThumb == null) { PrevThumb.NextThumb = null; PrevThumb.NextInsertThumb = null; } else { PrevThumb.NextThumb = NextThumb; NextThumb.PrevThumb = PrevThumb; InsertThumb newInsertThumb = new InsertThumb(ParentCanvas, Figure, PrevThumb.GetIndex(), NextThumb.GetIndex(), Scale, ThumbList); newInsertThumb.PrevThumb = PrevThumb; newInsertThumb.NextThumb = NextThumb; PrevThumb.NextInsertThumb = newInsertThumb; NextThumb.PrevInsertThumb = newInsertThumb; ParentCanvas.Children.Add(newInsertThumb); } ParentCanvas.Children.Remove(this); ParentCanvas.Children.Remove(PrevInsertThumb); ParentCanvas.Children.Remove(NextInsertThumb); } }