Пример #1
0
        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);
            }
        }
Пример #2
0
        private void PlaceThumbs(PathGeometry pathGeometry)
        {
            double scale = Map.Scale;

            foreach (PathFigure figure in pathGeometry.Figures)
            {
                PointCollection  points = (figure.Segments[0] as PolyLineSegment).Points;
                List <MoveThumb> thumbs = new List <MoveThumb>();
                allMoveThumbs.Add(thumbs);
                List <InsertThumb> insertThumbs = new List <InsertThumb>();


                for (int i = 0; i < points.Count; i++)
                {
                    MoveThumb thumb = new MoveThumb(this, figure, i, scale, thumbs);
                    thumbs.Add(thumb);
                }

                for (int i = 1; i < thumbs.Count - 1; i++)
                {
                    MoveThumb thumb = thumbs[i];
                    thumb.PrevThumb = thumbs[i - 1];
                    thumb.NextThumb = thumbs[i + 1];

                    InsertThumb prevInsertThumb = new InsertThumb(this, figure, i - 1, i, scale, thumbs);
                    prevInsertThumb.PrevThumb = thumb.PrevThumb;
                    prevInsertThumb.NextThumb = thumb;
                    insertThumbs.Add(prevInsertThumb);

                    thumb.PrevInsertThumb           = prevInsertThumb;
                    thumb.PrevThumb.NextInsertThumb = prevInsertThumb;
                }

                MoveThumb startThumb = thumbs[0];
                MoveThumb lastThumb  = thumbs[thumbs.Count - 1];
                startThumb.NextThumb       = thumbs[1];
                startThumb.NextInsertThumb = startThumb.NextThumb.PrevInsertThumb;
                lastThumb.PrevThumb        = thumbs[thumbs.Count - 2];
                lastThumb.PrevInsertThumb  = lastThumb.PrevThumb.NextInsertThumb;

                InsertThumb lastPrevInsertThumb = new InsertThumb(this, figure, thumbs.Count - 2, thumbs.Count - 1, scale, thumbs);
                lastPrevInsertThumb.PrevThumb = lastThumb.PrevThumb;
                lastPrevInsertThumb.NextThumb = lastThumb;
                insertThumbs.Add(lastPrevInsertThumb);

                lastThumb.PrevInsertThumb           = lastPrevInsertThumb;
                lastThumb.PrevThumb.NextInsertThumb = lastPrevInsertThumb;

                if (figure.IsClosed)
                {
                    startThumb.PrevThumb = lastThumb;
                    lastThumb.NextThumb  = startThumb;

                    InsertThumb insertThumb = new InsertThumb(this, figure, thumbs.Count - 1, 0, scale, thumbs);
                    insertThumb.PrevThumb = lastThumb;
                    insertThumb.NextThumb = startThumb;
                    insertThumbs.Add(insertThumb);

                    startThumb.PrevInsertThumb = insertThumb;
                    lastThumb.NextInsertThumb  = insertThumb;
                }

                foreach (MoveThumb thumb in thumbs)
                {
                    Children.Add(thumb);
                }
                foreach (InsertThumb thumb in insertThumbs)
                {
                    Children.Add(thumb);
                }
            }
        }