Пример #1
0
        public void HookChange(Hook hook)
        {
            foreach (Hook hookToNotify in Hooks)
            {
                if (hookToNotify != hook)
                {
                    hookToNotify.IsVisible = false;
                }
            }
            PointCollection temPoints  = new PointCollection(Points);
            int             startIndex = temPoints.IndexOf(hook.OriginalStartPoint);
            int             endIndex   = temPoints.IndexOf(hook.OriginalEndPoint);

            if (startIndex != -1 && endIndex != -1)
            {
                for (int i = startIndex; i <= endIndex; i++)
                {
                    Point toChangePoint = temPoints[i];

                    switch (hook.Orientation)
                    {
                    case Orientation.Horizontal:
                        temPoints[i] = new Point(hook.HookPoint.X, toChangePoint.Y);
                        break;

                    case Orientation.Vertical:
                        temPoints[i] = new Point(toChangePoint.X, hook.HookPoint.Y);
                        break;
                    }
                }
                hook.SetNewPoints();
            }
            Points     = temPoints;
            ArrowPoint = Points[Points.Count - 1];
        }
Пример #2
0
        /// <summary>
        /// Handles the Double click event extension on Graphic and deletes the vertex.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param>
        private void vertex_doubleClick(object sender, MouseButtonEventArgs e)
        {
            Graphic g      = sender as Graphic;
            Graphic parent = g.Attributes["Feature"] as Graphic;

            if (parent.Geometry is Envelope)
            {
                return;                              //Cannot delete
            }
            PointCollection p = g.Attributes["PointCollection"] as PointCollection;

            if (parent.Geometry is Polygon && p.Count < 5)
            {
                return;                                                        //Cannot delete
            }
            if (parent.Geometry is Polyline && p.Count < 3)
            {
                return;                                                         //Cannot delete
            }
            int index = p.IndexOf(g.Geometry as MapPoint);

            if (parent.Geometry is Polygon && index == 0) //Maintain closing point
            {
                p.RemoveAt(p.Count - 1);                  //remove last point
                p.Add(new MapPoint(p[1].X, p[1].Y));      //close poly
            }
            MapPoint removeItem = p[index];

            p.RemoveAt(index);
            //Restart edit to rebuild vertices and hover lines
            StopEdit(true);
            StartEdit(parent, true);
            OnGeometryEdit(g, null, removeItem, Action.VertexRemoved);
        }
Пример #3
0
        public Point GetMousePositionCanvas()
        {
            Point point = Mouse.GetPosition(Canvas);

            Text(point.X, point.Y, "(" + (point.X - 125) + ":" + (point.Y - 125) + ")", Colors.Blue);
            bool added = false;

            if (point.X > 0 && point.Y > 0)
            {
                PointCollection.Add(point);
                added = true;
            }

            if (buttonsDisplay.Children.Count < 10 && added)
            {
                Button b = new Button();
                b.Click  += new RoutedEventHandler(this.ButtonClick);
                b.Content = "Mudar";
                b.Name    = "Button" + PointCollection.IndexOf(point).ToString();

                buttonsDisplay.Children.Add(b);

                TextBox tx = new TextBox();
                tx.Name      = "X" + PointCollection.IndexOf(point).ToString();
                tx.Text      = (point.X - 125).ToString();
                tx.MaxLength = 4;
                tx.MaxLines  = 1;
                xDisplay.Children.Add(tx);

                TextBox ty = new TextBox();
                ty.Name      = "Y" + PointCollection.IndexOf(point).ToString();
                ty.Text      = (point.Y - 125).ToString();
                ty.MaxLength = 4;
                ty.MaxLines  = 1;
                yDisplay.Children.Add(ty);
            }

            return(new Point(point.X, point.Y));
        }
Пример #4
0
        // 对输入的两点及其上点集执行递归算法,找到最远点,根据围成的三角形分类点,生成两条边,对每条边极其上方的点集再次执行本递归算法
        private int FindSubHull(PointCollection points, Point pointLeft, Point pointRight)
        {
            if (points.Count == 0)
            {
                return(1);
            }
            int   totalCommandCount = 0;
            Point pointFarthest     = FindFarthestPoint(points, pointLeft, pointRight, out int commandCount);

            totalCommandCount += commandCount;
            ChangeToVertex(pointFarthest, pointsVertex.IndexOf(pointLeft) + 1);
            totalCommandCount += 3;
            historyLines.Add(GetLines(pointsVertex, out commandCount));
            totalCommandCount += commandCount;
            points.Remove(pointFarthest);
            totalCommandCount++;

            PointCollection points1 = new PointCollection();
            PointCollection points2 = new PointCollection();

            foreach (Point point in points)
            {
                int deter1 = CalDeter(pointLeft, pointFarthest, point);
                int deter2 = CalDeter(pointFarthest, pointRight, point);
                totalCommandCount += 2;
                if (deter1 > 0)
                {
                    points1.Add(point);
                    totalCommandCount++;
                }
                else if (deter2 > 0)
                {
                    points2.Add(point);
                    totalCommandCount++;
                }
                else    // 三角形内
                {
                    ChangeToInternal(point);
                    totalCommandCount += 2;;
                }
            }
            totalCommandCount += FindSubHull(points1, pointLeft, pointFarthest);
            totalCommandCount += FindSubHull(points2, pointFarthest, pointRight);
            return(totalCommandCount);
        }
Пример #5
0
        /// <summary>
        /// Get the previous point to the selected point on the polygon.
        /// </summary>
        /// <remarks>This method is used to help draw a ghost point</remarks>
        /// <returns>Next polygon point</returns>
        public PolygonPointViewModel GetPreviousPoint()
        {
            // Get the index of the selected point
            int selectedPointIndex = PointCollection.IndexOf(SelectedVertex);

            // Attempt to move to the previous point
            int prevPoint = selectedPointIndex - 1;

            // If we passed the first point then...
            if (prevPoint < 0)
            {
                // Wrap around to the last point
                prevPoint = PointCollection.Count - 1;
            }

            // Return the previous point
            return(PointCollection[prevPoint]);
        }
Пример #6
0
        /// <summary>
        /// Get the next point on the polygon following the selected point.
        /// </summary>
        /// <remarks>This method is used to help draw a ghost point</remarks>
        /// <returns>Next polygon point</returns>
        public PolygonPointViewModel GetNextPoint()
        {
            // Get the index of the selected point
            int selectedPointIndex = PointCollection.IndexOf(SelectedVertex);

            // Attempt to advance to the next point
            int nextPoint = selectedPointIndex + 1;

            // If we have passed the last point then...
            if (nextPoint > PointCollection.Count - 1)
            {
                // Wrap around to the first point
                nextPoint = 0;
            }

            // Return the next point
            return(PointCollection[nextPoint]);
        }
Пример #7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            // Drawing the arrow
            StreamGeometry streamGeometry = new StreamGeometry();

            using (StreamGeometryContext geometryContext = streamGeometry.Open())
            {
                if (_points != null && _points.Any())
                {
                    geometryContext.BeginFigure(_points[0], true, true);
                    geometryContext.PolyLineTo(_points.Where(p => _points.IndexOf(p) > 0).ToList(), true, true);
                }
            }

            // Draw the polygon visual
            drawingContext.DrawGeometry(Brushes.DarkOrchid, new Pen(_btn.Background, 0.5), streamGeometry);

            base.OnRender(drawingContext);
        }
Пример #8
0
        private void vertexLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            Graphic graphic = args.Graphic;

            if (graphic.Geometry is MapPoint)             //Moving point
            {
                DraggingVertex = graphic;
                args.Handled   = true;               //Prevent map from reacting to mouse event
                DraggingVertex.Select();
                StartTracking();
                fromPoint = new MapPoint((graphic.Geometry as MapPoint).X, (graphic.Geometry as MapPoint).Y);
            }
            else if (graphic.Geometry is Polyline)             //Adding vertex
            {
                Polyline line    = graphic.Geometry as Polyline;
                Point    pScreen = args.GetPosition(MyMap);
                MapPoint pMap    = MyMap.ScreenToMap(pScreen);
                MapPoint snap    = FindPointOnLineClosestToPoint(line.Paths[0][0], line.Paths[0][1], pMap);
                args.Handled = true;
                PointCollection pnts   = graphic.Attributes["PointCollection"] as PointCollection;
                Graphic         parent = graphic.Attributes["Feature"] as Graphic;
                //Add new vertex and immediately start tracking it
                if (snapVertex != null)
                {
                    vertexLayer.Graphics.Remove(snapVertex);
                }
                DraggingVertex = AddVertexToEditLayer(parent, vertexLayer, snap);
                DraggingVertex.Select();
                args.Handled = true;                 //Prevent map from reacting to mouse event
                StartTracking();
                DraggingVertex.Attributes.Add("PointCollection", pnts);
                int index = pnts.IndexOf(line.Paths[0][0]);
                pnts.Insert(index + 1, snap);
                vertexLayer.Graphics.Remove(graphic);
                AddHoverLineSegment(pnts, line.Paths[0][0], snap, parent);
                AddHoverLineSegment(pnts, snap, line.Paths[0][1], parent);
                OnGeometryEdit(graphic, snap, null, Action.VertexAdded);
                fromPoint = new MapPoint(snap.X, snap.Y);
            }
        }
Пример #9
0
        private void canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Point newPoint = new Point()
            {
                X = (int)e.GetPosition(canvas).X, Y = (int)e.GetPosition(canvas).Y
            };
            bool alreadyInserted = false;

            foreach (Point p in _pointCollection)
            {
                if (p.X > newPoint.X)
                {
                    _pointCollection.Insert(_pointCollection.IndexOf(p), newPoint);
                    alreadyInserted = true;
                    break;
                }
            }
            if (!alreadyInserted)
            {
                _pointCollection.Add(newPoint);
            }
        }
Пример #10
0
        private void PointCollectionOperations(object sender, SelectionChangedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch
            case "rb1":
            {
                //<SnippetPointCollectionAdd>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating an array of Points to the points
                Point[] pointArray = new Point[3];

                // Adding points to array
                pointArray[0] = point1;
                pointArray[1] = point2;
                pointArray[2] = point3;

                // Instantiating a PointCollection and initializing with an array
                PointCollection pointCollection1 = new PointCollection(pointArray);

                //  Adding a point to the PointCollection
                pointCollection1.Add(point4);

                // pointCollection1 is equal to (10,10 20,20 30,30 40,40)

                //</SnippetPointCollectionAdd>



                break;
            }

            case "rb2":
            {
                //<SnippetPointCollectionClear>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // clearing the PointCollection
                pointCollection1.Clear();

                // pointCollection1 is now empty

                //</SnippetPointCollectionClear>

                break;
            }

            case "rb3":
            {
                //<SnippetPointCollectionContains>

                Boolean inCollection;

                // Instantiating and Initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                inCollection = pointCollection1.Contains(point4);

                // inCollection is equal to False

                //</SnippetPointCollectionContains>

                break;
            }

            case "rb4":
            {
                //<SnippetPointCollectionIndexOf>

                int pIndex;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);
                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting the index of a Point
                pIndex = pointCollection1.IndexOf(point2);

                // pointIndex is equal to 1

                //</SnippetPointCollectionIndexOf>

                break;
            }

            case "rb5":
            {
                //<SnippetPointCollectionInsert>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Inserting a Point into the PointCollection
                pointCollection1.Insert(1, point4);

                // pointCollection1 is now equal to (10,10 40,40 20,20 30,30

                //</SnippetPointCollectionInsert>

                break;
            }

            case "rb6":
            {
                //<SnippetPointCollectionRemove>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a Point from the PointCollection
                pointCollection1.Remove(point2);

                // pointCollection1 is equal to 10,10 30,30

                //</SnippetPointCollectionRemove>

                break;
            }

            case "rb7":
            {
                //<SnippetPointCollectionRemoveAt>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a range of Points
                pointCollection1.RemoveAt(1);

                // pointCollection1 is equal to (10,10 30,30)

                //</SnippetPointCollectionRemoveAt>

                break;
            }

            case "rb8":
            {
                //<SnippetPointCollectionToString>
                string pcString;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting a string representation of the PointCollection
                pcString = pointCollection1.ToString();


                // pcString is equal to "10,10 20,20 30,30"

                //</SnippetPointCollectionToString>


                break;
            }

            case "rb9":
            {
                break;
            }

            case "rb10":
            {
                break;
            }

            case "rb11":
            {
                break;
            }

            case "rb12":
            {
                break;
            }
            } //end switch
        }
Пример #11
0
        private void VisualiseData()
        {
            if (GraphData == null)
            {
                return;
            }
            //Data deets
            int xPartitions = GraphData.Count;

            if (xPartitions == 0)
            {
                return;
            }
            double valueMax = GraphData.Max(x => x.Value);

            //Y plot points
            int    yMax             = valueMax == 0 ? 10 : (int)(Math.Ceiling(valueMax / 10) * 10);
            double yValueInteravals = yMax / 10;

            //Label Y - Axis
            for (int i = 0; i <= 10; i++)
            {
                TextBlock yLabel = new TextBlock {
                    Text = $"{i * yValueInteravals}", Background = Brushes.Transparent, TextAlignment = TextAlignment.Justify, FontSize = GraphDataLabelFontSize
                };
                var aw = yLabel.ActualWidth;
                var ah = yLabel.ActualHeight;

                yLabel.Margin = new Thickness(GraphMargin - 25 - aw, (zero.Y - endY.Y) - (i * ((zero.Y - endY.Y) / 10)) + (2 * GraphMargin / 3), 0, 0);
                dataDependentLabels.Children.Add(yLabel);
            }

            //Label X-Axis
            GeometryGroup xaxis_geom = new GeometryGroup();
            var           xStep      = (endX.X - zero.X) / GraphData.Count;

            for (int j = 0; j < GraphData.Count; j++)
            {
                //Create Axis data mark
                xaxis_geom.Children.Add(new LineGeometry(new Point(GraphMargin + ((j + 1) * xStep), zero.Y), new Point(GraphMargin + ((j + 1) * xStep), zero.Y + 5)));

                //Create and position label
                TextBlock xLabel = new TextBlock {
                    Text = GraphData[j].Key.ToString(), Background = Brushes.Transparent, FontSize = GraphDataLabelFontSize
                };

                xLabel.Margin = new Thickness((j + 1) * xStep + (2 * GraphMargin / 3), zero.Y, 0, 0);
                dataDependentLabels.Children.Add(xLabel);
            }
            Path yaxis_path = new Path();

            yaxis_path.StrokeThickness = 1;
            yaxis_path.Stroke          = Brushes.Black;
            yaxis_path.Data            = xaxis_geom;
            dataDependentLabels.Children.Add(yaxis_path);


            //Get data Coordinates
            PointCollection points = new PointCollection();

            for (int p = 0; p < GraphData.Count; p++)
            {
                points.Add(new Point(GraphMargin + (xStep * (p + 1)), zero.Y - ((GraphData[p].Value / yMax) * (zero.Y - endY.Y))));
            }

            //Draw on points
            foreach (Point p in points)
            {
                Ellipse dot = new Ellipse()
                {
                    Fill = DataPointColour, Width = 6, Height = 6
                };
                Canvas.SetTop(dot, p.Y - (dot.Height / 2));
                Canvas.SetLeft(dot, p.X - (dot.Width / 2));
                ToolTip pointToolTip = new ToolTip();
                pointToolTip.Content = GraphData[points.IndexOf(p)].Value;
                dot.ToolTip          = pointToolTip;
                dataDependentLabels.Children.Add(dot);
            }

            //Draw line
            Polyline dataLine = new Polyline();

            dataLine.StrokeThickness = 1;
            dataLine.Stroke          = DataLineColour;
            dataLine.Points          = points;
            dataDependentLabels.Children.Add(dataLine);
        }