public static void Draw(Canvas canvas, List<LinePoint> points, Brush stroke, bool clear = true)
        {
            if (clear)
            {
                canvas.Children.Clear();
            }

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            PathGeometry myPathGeometry = new PathGeometry();

            foreach (LinePoint p in points)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = p.StartPoint;

                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = p.EndPoint;

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;

                myPathFigureCollection.Add(myPathFigure);
            }

            myPathGeometry.Figures = myPathFigureCollection;
            Path myPath = new Path();
            myPath.Stroke = stroke == null ? Brushes.Black : stroke;
            myPath.StrokeThickness = 1;
            myPath.Data = myPathGeometry;

            canvas.Children.Add(myPath);
        }
Beispiel #2
0
        private void RenderPolygon(DrawingContext drawingContext)
        {
            var fillBrush = Brushes.LawnGreen;
            var borderPen = new Pen(Brushes.Black,1.0);

            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = maxPoints[0];

            //PolyLineSegment seg = new PolyLineSegment(

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            for (int i = 1; i < maxPoints.Count; i++)
            {
                myPathSegmentCollection.Add(new LineSegment(maxPoints[i], true));
            }
            for (int i = minPoints.Count - 1; i >= 0; i--)
            {
                myPathSegmentCollection.Add(new LineSegment(minPoints[i], true));
            }

            myPathFigure.Segments = myPathSegmentCollection;
            PathGeometry myPathGeometry = new PathGeometry();
            
            myPathGeometry.Figures.Add(myPathFigure);

            drawingContext.DrawGeometry(fillBrush, borderPen, myPathGeometry);
        }
Beispiel #3
0
            private Geometry GetDefaultGlyph()
            {
                var x1 = this._columnHeader.ActualWidth - 13;
                var x2 = x1 + 10;
                var x3 = x1 + 5;
                var y1 = this._columnHeader.ActualHeight / 2 - 3;
                var y2 = y1 + 5;

                if (this._direction == ListSortDirection.Ascending)
                {
                    var tmp = y1;
                    y1 = y2;
                    y2 = tmp;
                }

                var pathSegmentCollection = new PathSegmentCollection();

                pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
                pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

                var pathFigure = new PathFigure(new Point(x1, y1), pathSegmentCollection, true);

                var pathFigureCollection = new PathFigureCollection();

                pathFigureCollection.Add(pathFigure);

                var pathGeometry = new PathGeometry(pathFigureCollection);

                return(pathGeometry);
            }
Beispiel #4
0
            private Geometry GetDefaultGlyph()
            {
                double x1 = _columnHeader.ActualWidth - 13;
                double x2 = x1 + 10;
                double x3 = x1 + 5;
                double y1 = _columnHeader.ActualHeight / 2 - 3;
                double y2 = y1 + 5;

                if (_direction == ListSortDirection.Ascending)
                {
                    double tmp = y1;
                    y1 = y2;
                    y2 = tmp;
                }

                PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

                pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
                pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

                PathFigure pathFigure = new PathFigure(
                    new Point(x1, y1),
                    pathSegmentCollection,
                    true);

                PathFigureCollection pathFigureCollection = new PathFigureCollection();

                pathFigureCollection.Add(pathFigure);

                PathGeometry pathGeometry = new PathGeometry(pathFigureCollection);

                return(pathGeometry);
            }
Beispiel #5
0
        private void RenderPolygon(DrawingContext drawingContext)
        {
            var fillBrush = Brushes.Bisque;
            var borderPen = new Pen(Brushes.Black, 1.0);

            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = CreatePoint(maxValues, 0);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            for (int i = 1; i < maxValues.Count; i++)
            {
                myPathSegmentCollection.Add(new LineSegment(CreatePoint(maxValues, i), true));
            }
            for (int i = minValues.Count - 1; i >= 0; i--)
            {
                myPathSegmentCollection.Add(new LineSegment(CreatePoint(minValues, i), true));
            }

            myPathFigure.Segments = myPathSegmentCollection;
            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures.Add(myPathFigure);

            drawingContext.DrawGeometry(fillBrush, borderPen, myPathGeometry);
        }
Beispiel #6
0
        public void TestReadTopologicallyInvalid()
        {
            // Create a collection of points for a polygon
            var pathSegments = new PathSegmentCollection();

            pathSegments.Add(new LineSegment(new WpfPoint(50, 100), true));
            pathSegments.Add(new LineSegment(new WpfPoint(85, 0), true));
            pathSegments.Add(new LineSegment(new WpfPoint(0, 65), true));
            pathSegments.Add(new LineSegment(new WpfPoint(100, 65), true));
            pathSegments.Add(new LineSegment(new WpfPoint(15, 0), true));

            var pathGeometry = new PathGeometry(new [] { new PathFigure(new WpfPoint(15, 0), pathSegments, true) },
                                                FillRule.EvenOdd, Transform.Identity);

            var geomEvenOdd = WpfGeometryReader.Read(pathGeometry, 0, Geometries.GeometryFactory.Default);

            Assert.IsTrue(geomEvenOdd.IsValid);
            Console.WriteLine("EvenOdd:\n{0}", geomEvenOdd.AsText());

            pathGeometry = new PathGeometry(new[] { new PathFigure(new WpfPoint(15, 0), pathSegments, true) },
                                            FillRule.Nonzero, Transform.Identity);
            var geomNonzero = WpfGeometryReader.Read(pathGeometry, 0, Geometries.GeometryFactory.Default);

            Console.WriteLine("NotNull:\n{0}", geomNonzero.AsText());
            Assert.IsTrue(geomNonzero.IsValid);

            Assert.IsFalse(geomEvenOdd.EqualsTopologically(geomNonzero));
        }
        /// <summary>
        /// Returns the Glyph to display
        /// </summary>
        /// <returns>Glyph object</returns>
        private Geometry GetDefaultGlyph()
        {
            double x1 = this.columnHeader.ActualWidth - 13;
            double x2 = x1 + 10;
            double x3 = x1 + 5;
            double y1 = (this.columnHeader.ActualHeight / 2) - 3;
            double y2 = y1 + 5;

            if (this.direction == ListSortDirection.Ascending)
            {
                double tmp = y1;
                y1 = y2;
                y2 = tmp;
            }

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(new LineSegment(new Point(x2, y1), true));
            pathSegmentCollection.Add(new LineSegment(new Point(x3, y2), true));

            PathFigure pathFigure = new PathFigure(new Point(x1, y1), pathSegmentCollection, true);

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry(pathFigureCollection);
            return pathGeometry;
        }
Beispiel #8
0
        private void RenderPolygon(DrawingContext drawingContext)
        {
            var fillBrush = Brushes.LawnGreen;
            var borderPen = new Pen(Brushes.Black, 1.0);

            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = maxPoints[0];

            //PolyLineSegment seg = new PolyLineSegment(

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            for (int i = 1; i < maxPoints.Count; i++)
            {
                myPathSegmentCollection.Add(new LineSegment(maxPoints[i], true));
            }
            for (int i = minPoints.Count - 1; i >= 0; i--)
            {
                myPathSegmentCollection.Add(new LineSegment(minPoints[i], true));
            }

            myPathFigure.Segments = myPathSegmentCollection;
            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures.Add(myPathFigure);

            drawingContext.DrawGeometry(fillBrush, borderPen, myPathGeometry);
        }
Beispiel #9
0
        private void DrawIndicatorSegment(Point out1Point, Point out2Point, Point in2Point, Point in1Point, bool isLargeArc, Brush fill)
        {
            if (_layoutRoot == null)
            {
                return;
            }

            var outRadius = IndicatorRadius + IndicatorThickness;
            var inRadius  = IndicatorRadius;

            var segmentCollection = new PathSegmentCollection();

            var pathFigure = new PathFigure()
            {
                //确定起点(外弧线左侧点)
                StartPoint = out1Point,
                Segments   = segmentCollection,
                IsClosed   = true
            };

            //连到外弧线右侧点
            segmentCollection.Add(new ArcSegment()
            {
                Size           = new Size(outRadius, outRadius),
                Point          = out2Point,
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc     = isLargeArc
            });

            //连到内弧线右侧点
            segmentCollection.Add(new LineSegment()
            {
                Point = in2Point
            });

            //连到内弧线左侧点
            segmentCollection.Add(new ArcSegment()
            {
                Size           = new Size(inRadius, inRadius),
                Point          = in1Point,
                SweepDirection = SweepDirection.Counterclockwise,
                IsLargeArc     = isLargeArc
            });

            var indicatorPath = new Path()
            {
                RenderTransformOrigin = new Point(0.5, 0.5),
                Fill = fill,
                Data = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        pathFigure
                    }
                }
            };

            _indicatorRoot.Children.Insert(0, indicatorPath);
        }
        public static PathSegmentCollection GetSegments(IReadOnlyList <Point> controlPoints)
        {
            if (controlPoints.Count == 0)
            {
                return((PathSegmentCollection)null);
            }
            PathSegmentCollection segmentCollection = new PathSegmentCollection();
            Point  point1 = controlPoints[0];
            double x1     = point1.X;

            point1 = controlPoints[0];
            double y1 = point1.Y;

            if (controlPoints.Count <= 3)
            {
                LineSegment lineSegment = new LineSegment()
                {
                    Point = new Point(x1 + 1.0, y1)
                };
                segmentCollection.Add((PathSegment)lineSegment);
            }
            else
            {
                for (int index = 1; index < controlPoints.Count; ++index)
                {
                    point1 = controlPoints[index - 1];
                    double x2 = point1.X;
                    point1 = controlPoints[index - 1];
                    double y2 = point1.Y;
                    point1 = controlPoints[index];
                    double x3 = point1.X;
                    point1 = controlPoints[index];
                    double y3 = point1.Y;
                    if (Math.Sqrt(Math.Pow(x3 - x2, 2.0) + Math.Pow(y3 - y2, 2.0)) < 2.0)
                    {
                        LineSegment lineSegment = new LineSegment()
                        {
                            Point = new Point(x3, y3)
                        };
                        segmentCollection.Add((PathSegment)lineSegment);
                    }
                    else
                    {
                        PolyQuadraticBezierSegment quadraticBezierSegment1 = new PolyQuadraticBezierSegment();
                        PointCollection            pointCollection         = new PointCollection();
                        Point point2 = new Point(x2, y2);
                        pointCollection.Add(point2);
                        Point point3 = new Point((x2 + x3) / 2.0, (y2 + y3) / 2.0);
                        pointCollection.Add(point3);
                        quadraticBezierSegment1.Points = pointCollection;
                        PolyQuadraticBezierSegment quadraticBezierSegment2 = quadraticBezierSegment1;
                        segmentCollection.Add((PathSegment)quadraticBezierSegment2);
                    }
                }
            }
            return(segmentCollection);
        }
        private void DrawCursor(DrawingContext g)
        {
            int adjustedY = CalculateFaderIndex(); //t_mousePoint.Y - 5;

            PathGeometry leftcur = new PathGeometry();
            PathFigure   lpf     = new PathFigure();

            lpf.StartPoint = new System.Windows.Point(0, adjustedY + 0);
            LineSegment lls1 = new LineSegment(new System.Windows.Point(5, adjustedY + 0), true);
            LineSegment lls2 = new LineSegment(new System.Windows.Point(8, adjustedY + 5), true);
            LineSegment lls3 = new LineSegment(new System.Windows.Point(5, adjustedY + 10), true);
            LineSegment lls4 = new LineSegment(new System.Windows.Point(0, adjustedY + 10), true);
            LineSegment lls5 = new LineSegment(new System.Windows.Point(0, adjustedY + 0), true);

            PathSegmentCollection lpsc = new PathSegmentCollection(5);

            lpsc.Add(lls1);
            lpsc.Add(lls2);
            lpsc.Add(lls3);
            lpsc.Add(lls4);
            lpsc.Add(lls5);

            lpf.Segments = lpsc;

            leftcur.Figures = new PathFigureCollection(1);
            leftcur.Figures.Add(lpf);

            PathGeometry rightcur = new PathGeometry();
            PathFigure   rpf      = new PathFigure();

            rpf.StartPoint = new System.Windows.Point(23, adjustedY + 0);
            LineSegment rls1 = new LineSegment(new System.Windows.Point(23, adjustedY + 10), true);
            LineSegment rls2 = new LineSegment(new System.Windows.Point(23, adjustedY + 10), true);
            LineSegment rls3 = new LineSegment(new System.Windows.Point(18, adjustedY + 10), true);
            LineSegment rls4 = new LineSegment(new System.Windows.Point(15, adjustedY + 5), true);
            LineSegment rls5 = new LineSegment(new System.Windows.Point(18, adjustedY + 0), true);

            PathSegmentCollection rpsc = new PathSegmentCollection(5);

            rpsc.Add(rls1);
            rpsc.Add(rls2);
            rpsc.Add(rls3);
            rpsc.Add(rls4);
            rpsc.Add(rls5);

            rpf.Segments = rpsc;

            rightcur.Figures = new PathFigureCollection(1);
            rightcur.Figures.Add(rpf);

            SolidColorBrush b = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 210, 210, 210));

            System.Windows.Media.Pen p = new System.Windows.Media.Pen(new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 100, 100, 100)), 1d);

            g.DrawGeometry(b, p, leftcur);
            g.DrawGeometry(b, p, rightcur);
        }
        private Path TwoPathFigures()
        {
            // <Snippet38>
            PathFigure myPathFigure1 = new PathFigure();

            myPathFigure1.StartPoint = new Point(10, 100);
            myPathFigure1.IsClosed   = true;

            LineSegment myLineSegment1 = new LineSegment();

            myLineSegment1.Point = new Point(100, 100);
            LineSegment myLineSegment2 = new LineSegment();

            myLineSegment2.Point = new Point(100, 50);

            PathFigure myPathFigure2 = new PathFigure();

            myPathFigure2.StartPoint = new Point(10, 10);
            myPathFigure2.IsClosed   = true;

            LineSegment myLineSegment3 = new LineSegment();

            myLineSegment3.Point = new Point(100, 10);
            LineSegment myLineSegment4 = new LineSegment();

            myLineSegment4.Point = new Point(100, 40);

            PathSegmentCollection myPathSegmentCollection1 = new PathSegmentCollection();

            myPathSegmentCollection1.Add(myLineSegment1);
            myPathSegmentCollection1.Add(myLineSegment2);
            myPathFigure1.Segments = myPathSegmentCollection1;

            PathSegmentCollection myPathSegmentCollection2 = new PathSegmentCollection();

            myPathSegmentCollection2.Add(myLineSegment3);
            myPathSegmentCollection2.Add(myLineSegment4);
            myPathFigure2.Segments = myPathSegmentCollection2;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure1);
            myPathFigureCollection.Add(myPathFigure2);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
            // </Snippet38>
            return(myPath);
        }
Beispiel #13
0
        private static void TerminateLastActivity(double x, ref int activity, PathSegmentCollection segments)
        {
            if (activity == 1)
            {
                return;
            }

            activity = 1;
            segments.Add(new LineSegment(new Point(x, 0), false));
            segments.Add(new LineSegment(new Point(x, 1), false));
        }
Beispiel #14
0
        private void DrawCurvedPath(Point p1, Point p2, Point p3, Point p4, ref web_color color, double thickness)
        {
            var geometry = new PathGeometry();
            PathSegmentCollection path = new PathSegmentCollection();

            path.Add(new LineSegment(p2, true));
            path.Add(new QuadraticBezierSegment(p3, p4, true));
            geometry.Figures.Add(new PathFigure(p1, path, false));

            DrawingContext.DrawGeometry(null, color.GetPen(thickness), geometry);
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     var ps = new PathSegmentCollection(4);
     ContentPresenter cp = (ContentPresenter)value;
     double h = cp.ActualHeight > 10 ? 1.4 * cp.ActualHeight : 10;
     double w = cp.ActualWidth > 10 ? 1.25 * cp.ActualWidth : 10;
     ps.Add(new LineSegment(new Point(1, 0.7 * h), true));
     ps.Add(new BezierSegment(new Point(1, 0.9 * h), new Point(0.1 * h, h), new Point(0.3 * h, h), true));
     ps.Add(new LineSegment(new Point(w, h), true));
     ps.Add(new BezierSegment(new Point(w + 0.6 * h, h), new Point(w + h, 0), new Point(w + h * 1.3, 0), true));
     return ps;
 }
        public override void HandleMove(object arg)
        {
            if (arg.GetType() == typeof(Point))
            {
                if (PocketPaintApplication.GetInstance().cursorControl.isDrawingActivated())
                {
                    setHeightWidth();

                    var coordinate = new Point(width + _transforms.Value.OffsetX, height + _transforms.Value.OffsetY);
                    System.Diagnostics.Debug.WriteLine("BrushTool Coord: " + coordinate.X + " " + coordinate.Y);

                    if (!_lastPointSet)
                    {
                        _lastPoint    = coordinate;
                        _lastPointSet = true;
                        return;
                    }

                    if (_lastPointSet && !_lastPoint.Equals(coordinate))
                    {
                        var qbs = new QuadraticBezierSegment
                        {
                            Point1 = _lastPoint,
                            Point2 = coordinate
                        };

                        _pathSegmentCollection.Add(qbs);


                        PocketPaintApplication.GetInstance().PaintingAreaLayoutRoot.InvalidateMeasure();
                        _lastPointSet = false;
                    }
                }
            }
            else if (arg.GetType() == typeof(TranslateTransform))
            {
                var move = (TranslateTransform)arg;
                _transforms.Children.Add(move);
            }

            if (PocketPaintApplication.GetInstance() != null)
            {
                AppBarButton appBarButtonReset = PocketPaintApplication.GetInstance().PaintingAreaView.getAppBarResetButton();
                if (appBarButtonReset != null)
                {
                    if (!appBarButtonReset.IsEnabled)
                    {
                        appBarButtonReset.IsEnabled = true;
                    }
                }
            }
        }
        public static bool EnsureOnlySingleSegmentsInFigure(PathFigure original)
        {
            bool flag = false;
            PathSegmentCollection segmentCollection = new PathSegmentCollection();

            foreach (PathSegment pathSegment in original.Segments)
            {
                PolyLineSegment            polyLineSegment         = pathSegment as PolyLineSegment;
                PolyQuadraticBezierSegment quadraticBezierSegment1 = pathSegment as PolyQuadraticBezierSegment;
                PolyBezierSegment          polyBezierSegment       = pathSegment as PolyBezierSegment;
                if (polyLineSegment != null)
                {
                    foreach (Point point in polyLineSegment.Points)
                    {
                        LineSegment lineSegment = PathSegmentUtilities.CreateLineSegment(point, polyLineSegment.IsStroked, new bool?(polyLineSegment.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)lineSegment);
                    }
                    flag = true;
                }
                else if (quadraticBezierSegment1 != null)
                {
                    int index = 0;
                    while (index < quadraticBezierSegment1.Points.Count - 1)
                    {
                        QuadraticBezierSegment quadraticBezierSegment2 = PathSegmentUtilities.CreateQuadraticBezierSegment(quadraticBezierSegment1.Points[index], quadraticBezierSegment1.Points[index + 1], quadraticBezierSegment1.IsStroked, new bool?(quadraticBezierSegment1.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)quadraticBezierSegment2);
                        index += 2;
                    }
                    flag = true;
                }
                else if (polyBezierSegment != null)
                {
                    int index = 0;
                    while (index < polyBezierSegment.Points.Count - 2)
                    {
                        BezierSegment bezierSegment = PathSegmentUtilities.CreateBezierSegment(polyBezierSegment.Points[index], polyBezierSegment.Points[index + 1], polyBezierSegment.Points[index + 2], polyBezierSegment.IsStroked, new bool?(polyBezierSegment.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)bezierSegment);
                        index += 3;
                    }
                    flag = true;
                }
                else
                {
                    segmentCollection.Add(pathSegment);
                }
            }
            if (flag)
            {
                original.Segments = segmentCollection;
            }
            return(flag);
        }
Beispiel #18
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var ps = new PathSegmentCollection(4);
            ContentPresenter cp = (ContentPresenter)value;
            double           h  = cp.ActualHeight > 10 ? 1.4 * cp.ActualHeight : 10;
            double           w  = cp.ActualWidth > 10 ? 1.25 * cp.ActualWidth : 10;

            ps.Add(new LineSegment(new Point(1, 0.7 * h), true));
            ps.Add(new BezierSegment(new Point(1, 0.9 * h), new Point(0.1 * h, h), new Point(0.3 * h, h), true));
            ps.Add(new LineSegment(new Point(w, h), true));
            ps.Add(new BezierSegment(new Point(w + 0.6 * h, h), new Point(w + h, 0), new Point(w + h * 1.3, 0), true));
            return(ps);
        }
        private Geometry CreateFieldOfViewGeometry()
        {
            // Positioing of the start and end of the rays from
            // the sensor that bound the FOV shape.
            const double StartEdgeMeterOffset = 0.4;
            const double EndEdgeMeterLength   = 3.0;

            // The depth sensor is documented to have a field of view
            // of 57 degrees.
            const double FovRadians = 57.0 * Math.PI / 180.0;

            // The angles of the left and right boundaries of the field of
            // view indicator.
            const double FovLeft  = Math.PI + ((Math.PI - FovRadians) / 2.0);
            const double FovRight = FovLeft + FovRadians;

            // Radius of the circle for drawing the arc segment at the bottom
            // of the field of view indicator.
            const double ArcRadius = 120;

            var figure   = new PathFigure();
            var segments = new PathSegmentCollection();

            var center = new Vector(MeterWidth / 2.0, 0.0);

            if (this.Settings != null)
            {
                center += new Vector(this.Settings.SensorOffsetX, this.Settings.SensorOffsetZ);
            }

            var rightEdgeVector     = new Vector(Math.Cos(FovRight), -Math.Sin(FovRight));
            var leftEdgeVector      = new Vector(Math.Cos(FovLeft), -Math.Sin(FovLeft));
            var rightEdgeStartPoint = this.MeterToPixel((Point)(center + (rightEdgeVector * StartEdgeMeterOffset)));
            var rightEdgeEndPoint   = this.MeterToPixel((Point)(center + (rightEdgeVector * EndEdgeMeterLength)));
            var leftEdgeStartPoint  = this.MeterToPixel((Point)(center + (leftEdgeVector * StartEdgeMeterOffset)));
            var leftEdgeEndPoint    = this.MeterToPixel((Point)(center + (leftEdgeVector * EndEdgeMeterLength)));

            figure.IsFilled   = true;
            figure.StartPoint = rightEdgeStartPoint;
            segments.Add(new LineSegment(rightEdgeEndPoint, true));
            segments.Add(new ArcSegment(leftEdgeEndPoint, new Size(ArcRadius, ArcRadius), 0.0, false, SweepDirection.Clockwise, true));
            segments.Add(new LineSegment(leftEdgeStartPoint, true));
            segments.Add(new LineSegment(rightEdgeStartPoint, true));
            figure.Segments = segments;

            var figures = new PathFigureCollection {
                figure
            };

            return(new PathGeometry(figures));
        }
Beispiel #20
0
        private void GenerateMap(Point startPoint, PointCollection points)
        {
            map_DirtTexture = new BitmapImage(new Uri(@"Resources/Dirt texture.png", UriKind.Relative));
            map_DirtBrush   = new ImageBrush(map_DirtTexture);

            map_LinePointCollection = new PointCollection()
            {
                points.Last(),
                new Point(points.Last().X, 500),
                new Point(startPoint.X, 500),
                startPoint
            };

            map_PolyLineSegment = new PolyLineSegment()
            {
                Points = map_LinePointCollection
            };

            map_BezierPointCollection = points;

            map_PolyBezierSegment = new PolyBezierSegment()
            {
                Points = map_BezierPointCollection
            };

            map_PathSegmentCollection = new PathSegmentCollection();
            map_PathSegmentCollection.Add(map_PolyBezierSegment);
            map_PathSegmentCollection.Add(map_PolyLineSegment);

            map_PathFigure = new PathFigure()
            {
                StartPoint = startPoint,
                Segments   = map_PathSegmentCollection
            };

            map_PathFigureCollection = new PathFigureCollection();
            map_PathFigureCollection.Add(map_PathFigure);

            map_PathGeometry = new PathGeometry()
            {
                Figures = map_PathFigureCollection
            };

            map_Path = new Path()
            {
                Stroke          = map_DirtBrush,
                Fill            = map_DirtBrush,
                StrokeThickness = 2,
                Data            = map_PathGeometry
            };
        }
Beispiel #21
0
        public static Geometry Get(double angle, Point centrePt, int innerRadius, int outerRadius)
        {
            PathSegmentCollection segs = new PathSegmentCollection();

            segs.Add(CreateLine1(angle, centrePt, outerRadius));
            segs.Add(CreateArc1(angle, centrePt, outerRadius));
            segs.Add(CreateLine2(angle, centrePt, innerRadius));
            segs.Add(CreateArc2(angle, centrePt, innerRadius));

            Point      start = GetStartPoint(angle, centrePt, innerRadius);
            PathFigure pf    = new PathFigure(start, segs, true);

            return(new PathGeometry(new[] { pf }, FillRule.EvenOdd, null));
        }
        /// <summary>
        /// Creates a circle path for the specified location, angle in degrees, circle radius and inner radius.
        /// </summary>
        /// <param name="location">
        /// The start location.
        /// </param>
        /// <param name="angle">
        /// The angle in degrees.
        /// </param>
        /// <param name="radius">
        /// The radius.
        /// </param>
        /// <param name="innerRadius">
        /// Inner radius.
        /// </param>
        /// <returns>
        /// The circle path for the specified location, angle in degrees, circle radius and inner radius.
        /// </returns>
        public static PathGeometry CreatePath(this Point location, double angle, double radius, double innerRadius)
        {
            if (DoubleUtil.LessThan(radius, 0))
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("Radius '{0}' must be greater than zero.", radius));
            }
            if (DoubleUtil.LessThan(innerRadius, 0))
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("Inner radius '{0}' must be greater than zero.", innerRadius));
            }

            bool isLargeArc = angle > FullCircleInDegrees / 2;

            PathGeometry          pathGeometry = new PathGeometry();
            PathSegmentCollection segments     = new PathSegmentCollection();

            Point arcPoint      = ConvertRadianToCartesian(angle, radius);
            Point innerArcPoint = ConvertRadianToCartesian(angle, innerRadius);

            segments.Add(new LineSegment(
                             new Point(location.X, location.Y - radius), false));
            segments.Add(new ArcSegment(
                             new Point(location.X + arcPoint.X, location.Y + arcPoint.Y),
                             new Size(radius, radius),
                             0,
                             isLargeArc,
                             SweepDirection.Clockwise,
                             false));

            segments.Add(new LineSegment(
                             new Point(location.X + innerArcPoint.X, location.Y + innerArcPoint.Y), false));
            segments.Add(new ArcSegment(
                             new Point(location.X, location.Y - innerRadius),
                             new Size(innerRadius, innerRadius),
                             0,
                             isLargeArc,
                             SweepDirection.Counterclockwise,
                             false));

            PathFigure figure = new PathFigure(location, segments, true);

            pathGeometry.Figures = new PathFigureCollection
            {
                figure
            };

            return(pathGeometry);
        }
Beispiel #23
0
        private void DrawPieSection(double startAngle, double endAngle, Color color, bool showLines)
        {
            // Calculate start and end circumference points for the section
            Point A = CalculateCircumferencePoint(startAngle, Radius);
            Point B = CalculateCircumferencePoint(endAngle, Radius);

            PathSegmentCollection segments = new PathSegmentCollection();

            segments.Add(new LineSegment {
                Point = this.Center
            });

            segments.Add(new LineSegment {
                Point = B
            });
            segments.Add(new ArcSegment
            {
                Size           = new Size(Radius, Radius),
                Point          = A,
                SweepDirection = SweepDirection.Counterclockwise,
            });

            Path segmentPath = new Path
            {
                StrokeLineJoin  = PenLineJoin.Round,
                StrokeThickness = StrokeThickness,
                Fill            = new SolidColorBrush(color),
                Data            = new PathGeometry
                {
                    Figures = new PathFigureCollection
                    {
                        new PathFigure
                        {
                            IsClosed   = true,
                            StartPoint = A,
                            Segments   = segments
                        }
                    }
                }
            };

            if (showLines)
            {
                segmentPath.Stroke = PieStroke;
            }

            this.Children.Add(segmentPath);
        }
		private void AddCircularArcGraph(Point startPoint, Point endPoint, Size size)
		{
			PathFigure pf = new PathFigure();
			pf.StartPoint = new Point(startPoint.X, startPoint.Y);

			ArcSegment arcSegment = new ArcSegment();
			arcSegment.Point = new Point(endPoint.X, endPoint.Y);
			arcSegment.Size = size;
			arcSegment.SweepDirection = SweepDirection.Counterclockwise;

			PathSegmentCollection psc = new PathSegmentCollection();
			psc.Add(arcSegment);

			pf.Segments = psc;

			PathFigureCollection pfc = new PathFigureCollection();
			pfc.Add(pf);

			PathGeometry pg = new PathGeometry();
			pg.Figures = pfc;

			var path = new Path();
			path.Stroke = Brushes.Black;
			path.StrokeThickness = 1;
			path.Data = pg;
			path.Fill = Brushes.Orange;
			path.Stretch = Stretch.Fill;

			var viewportPanel = new ViewportHostPanel();
			ViewportPanel.SetViewportBounds(path, new DataRect(0, 0, 50, 50));
			viewportPanel.Children.Add(path);
			plotter.Children.Add(viewportPanel);
		}
Beispiel #25
0
        public Superposition()
        {
            InitializeComponent();
                        
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure();
            
            pathFigure.StartPoint = new Point(0,0);

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            int maxHeight = (int)this.Height;
            int maxWidth = (int)this.Width;
            Random rand = new Random();
            for (int i = 0; i < 500; i++)
            {
                LineSegment newSegment = new LineSegment();
                newSegment.Point = new Point(rand.Next(0, maxWidth), rand.Next(0, maxHeight));
                pathSegmentCollection.Add(newSegment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);

            pathBackground.Data = pathGeometry;


        }
Beispiel #26
0
        public PathFigure AddArc(int start, int end)
        {
            int horizontalPostion = 100;

            var startPoint = new Point(horizontalPostion, start);
            var endPoint = new Point(horizontalPostion, end);

            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;

            ArcSegment arcSeg = new ArcSegment();
            arcSeg.Point = endPoint;
            arcSeg.Size = new Size(25, 25);
            arcSeg.IsLargeArc = true;
            arcSeg.SweepDirection = SweepDirection.Clockwise;
            arcSeg.RotationAngle = 90;

            var arrowhead = new Polygon();
            arrowhead.Stroke = Brushes.Black;
            arrowhead.StrokeThickness = 2;
            arrowhead.Points.Add(new Point(endPoint.X - 4, endPoint.Y));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y + 3));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y - 3));
            arrowhead.Fill = Brushes.Black;

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(arcSeg);
            pathFigure.Segments = myPathSegmentCollection;

            _pathFigureCollection.Add(pathFigure);

            _root.Children.Add(arrowhead);

            return pathFigure;
        }
Beispiel #27
0
        /*  将相邻两点连线
        protected override void OnRender(DrawingContext dc)
        {
            if (InternalChildren.Count < 2)
            {
                base.OnRender(dc);
                return;
            }

            Point? StartPoint = null;
            Point? EndPoint = null;

            for (int index = 0; index < InternalChildren.Count; index++)
            {
                UIElement CurChhild = this.Children[index];
                Vector CurV = VisualTreeHelper.GetOffset(CurChhild);

                if (index == 0)
                    StartPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);
                else
                    EndPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);

                if (StartPoint != null && EndPoint != null)
                {
                    dc.DrawLine(new Pen(LineBrush, 1.0), StartPoint.Value, EndPoint.Value);
                    StartPoint = EndPoint;
                }
            } 
        }
        */

        // 由LineSegment连接相邻两点并最终构成Path
        protected override void OnRender(DrawingContext dc)
        {
            if (InternalChildren.Count < 2)
            {
                base.OnRender(dc);
                return;
            }

            PathSegmentCollection segmentCollection = new PathSegmentCollection();
            PathFigure pathFigure = new PathFigure() { Segments = segmentCollection }; 

            for (int index = 0; index < InternalChildren.Count; index++)
            {
                UIElement CurChhild = this.Children[index];
                Vector CurV = VisualTreeHelper.GetOffset(CurChhild);

                if (index == 0)
                    pathFigure.StartPoint = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2);
                else
                    segmentCollection.Add(new LineSegment() { Point = new Point(CurV.X + CurChhild.RenderSize.Width / 2, CurV.Y + CurChhild.RenderSize.Height / 2) });
            }
 
            PathGeometry pathGeometry = new PathGeometry() { Figures = new PathFigureCollection() { pathFigure } };
            dc.DrawGeometry(Brushes.Transparent, new Pen(LineBrush, 1.0), pathGeometry);
        }
        private Path SimpleQuadraticBezierLine()
        {
            // <Snippet34>
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(10, 100);

            QuadraticBezierSegment myQuadraticBezierSegment = new QuadraticBezierSegment();

            myQuadraticBezierSegment.Point1 = new Point(200, 200);
            myQuadraticBezierSegment.Point2 = new Point(300, 100);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myQuadraticBezierSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
            // </Snippet34>
            return(myPath);
        }
Beispiel #29
0
        public static PathFigure GetPathFigureFromPoints(Point startPoint, params Point[] otherPoints)
        {
            var oPathFigure = new PathFigure()
            {
                StartPoint = startPoint
            };
            var oPathSegmentCollection = new PathSegmentCollection();

            foreach (var item in otherPoints)
            {
                oPathSegmentCollection.Add(new LineSegment
                {
                    Point = item,
#if WPF
                    IsStroked = true
#endif
                });
            }


            oPathFigure.Segments = oPathSegmentCollection;
            oPathFigure.IsClosed = true;
#if WPF
            TryFreeze(oPathFigure);
#endif
            return(oPathFigure);
        }
Beispiel #30
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (path.Data == null)
            {
                var myPathFigure = new PathFigure();

                myPathFigure.StartPoint = new Point(10, 50);;
                var myLineSegment = new LineSegment();
                CurrentPosition     = new Point(200, 70);
                myLineSegment.Point = CurrentPosition;

                var myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;
                MyPathFigure          = myPathFigure;

                var myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);

                var myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                path.Data = myPathGeometry;
            }
            else
            {
                CurrentPosition = CurrentPosition.Change(50, 30);
                var myLineSegment = new LineSegment()
                {
                    Point = CurrentPosition
                };
                MyPathFigure.Segments.Add(myLineSegment);
            }
        }
        internal void DrawBezier(double thickness, Color color, Point startPoint, Point controlPoint, Point endPoint)
        {
            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = startPoint;

            BezierSegment myBezierSegment = new BezierSegment(startPoint, endPoint, controlPoint, true);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(myBezierSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();
            myPathGeometry.Figures = myPathFigureCollection;

            DrawingContext drawingContext = drawingVisual.RenderOpen();

            mySolidColorBrush.Color = color;
            //ApplyColortool(color.A);
            pen.Brush = mySolidColorBrush;
            pen.Thickness = thickness;

            drawingContext.DrawGeometry(null, pen, myPathGeometry);

            drawingContext.Close();
            image.Render(drawingVisual);
        }
Beispiel #32
0
        public override Path getPath()
        {
            if (path.Data == null)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = new Point(start.x, start.y);

                LineSegment myLineSegment = new LineSegment();
                myLineSegment.Point = new Point(finish.x, finish.y);

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                myPathSegmentCollection.Add(myLineSegment);

                myPathFigure.Segments = myPathSegmentCollection;

                PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);

                PathGeometry myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                path.Stroke          = Brushes.Black;
                path.StrokeThickness = 1;
                path.Data            = myPathGeometry;
            }
            return(path);
        }
Beispiel #33
0
        /// <summary>
        /// This function allows to draw the right arc of the object.
        /// </summary>
        protected void drawRightArc()
        {
            // The radius of the circumcercle.
            double radius = Math.Sqrt(height * height + width * width) / 2;

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            PathFigure            segmentPathFigure     = new PathFigure();

            Point arcStartPoint = PointOnCircle(radius, arcRight_angleLow, new Point(x, y));
            Point arcStopPoint  = PointOnCircle(radius, arcRight_angleHigh, new Point(x, y));

            segmentPathFigure.StartPoint = arcStartPoint;

            ArcSegment arcSegment = new ArcSegment(arcStopPoint, new Size(radius, radius), 0, false, SweepDirection.Counterclockwise, true);

            pathSegmentCollection.Add(arcSegment);
            segmentPathFigure.Segments = pathSegmentCollection;
            PathFigureCollection segmentPathFigureCollection = new PathFigureCollection();

            segmentPathFigureCollection.Add(segmentPathFigure);
            PathGeometry segmentPathGeometry = new PathGeometry();

            segmentPathGeometry.Figures = segmentPathFigureCollection;

            // Set up the segment's drawing (and hit-testing) path.
            arcRight                 = new Path();
            arcRight.Stroke          = Brushes.Black;
            arcRight.StrokeThickness = 1;
            arcRight.Fill            = Brushes.Transparent;
            arcRight.Data            = segmentPathGeometry;
            Canvas.SetLeft(arcRight, 0);
            Canvas.SetTop(arcRight, 0);
            Canvas.SetZIndex(arcRight, 1);
            Canvas.Children.Add(arcRight);
        }
Beispiel #34
0
        public PathGeometry Plotter()
        {
            PathFigure            pathFigure            = new PathFigure();
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            if (points.Count > 0)
            {
                pathFigure.StartPoint = points[0];
                for (int i = 0; i < points.Count; i++)
                {
                    LineSegment lineSegment = new LineSegment
                    {
                        Point = points[i]
                    };
                    pathSegmentCollection.Add(lineSegment);
                }
            }
            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection
            {
                pathFigure
            };

            PathGeometry myPathGeometry = new PathGeometry
            {
                Figures = myPathFigureCollection
            };

            return(myPathGeometry);
        }
Beispiel #35
0
        public void Sample()
        {
            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(10, 50);

            LineSegment myLineSegment = new LineSegment();

            myLineSegment.Point = new Point(200, 70);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myLineSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            Path myPath = new Path();

            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            myPath.Data            = myPathGeometry;
        }
Beispiel #36
0
        public static void DrawPolygon(this DrawingContext drawingContext, Point[] points, double width, Color color, bool fill)
        {
            if (points.Length > 0)
            {
                var figure = new PathFigure {
                    StartPoint = points[0]
                };

                var myPathSegmentCollection = new PathSegmentCollection();
                for (var i = 1; i < points.Length; i++)
                {
                    myPathSegmentCollection.Add(new LineSegment(points[i], true));
                }

                figure.Segments = myPathSegmentCollection;
                var pathGeometry = new PathGeometry();
                pathGeometry.Figures.Add(figure);

                var brush = new SolidColorBrush(color);
                var pen   = new Pen(brush, width);
                if (fill)
                {
                    drawingContext.DrawGeometry(brush, null, pathGeometry);
                }
                else
                {
                    drawingContext.DrawGeometry(null, pen, pathGeometry);
                }
            }
        }
        public void Draw(EasingFunctionBase easingFunction)
        {
            canvas1.Children.Clear();


            PathSegmentCollection pathSegments = new PathSegmentCollection();

            for (double i = 0; i < 1; i += _samplingInterval)
            {
                double x = i * canvas1.Width;
                double y = easingFunction.Ease(i) * canvas1.Height;

                var segment = new LineSegment();
                segment.Point = new Point(x, y);

                pathSegments.Add(segment);

            }
            var p = new Path();
            p.Stroke = new SolidColorBrush(Colors.Black);
            p.StrokeThickness = 3;
            PathFigureCollection figures = new PathFigureCollection();
            figures.Add(new PathFigure() { Segments = pathSegments });
            p.Data = new PathGeometry() { Figures = figures };
            canvas1.Children.Add(p);
        }
Beispiel #38
0
        /// <summary>
        /// Creates figure by joining the given points.
        /// </summary>
        protected PathGeometry CreatePathFigure(IEnumerable <Point2Dmm[]> geometryPointClusters)
        {
            var figures = new List <PathFigure>();

            foreach (var geometryPoints in geometryPointClusters)
            {
                var pathSegments = new PathSegmentCollection();
                var firstPoint   = new Point(0, 0);
                var isFirst      = true;
                foreach (var point in geometryPoints)
                {
                    var visualPoint = ConvertToVisual(point);

                    pathSegments.Add(new LineSegment(visualPoint, !isFirst));
                    if (isFirst)
                    {
                        firstPoint = visualPoint;
                    }
                    isFirst = false;
                }
                var figure = new PathFigure(firstPoint, pathSegments, false);
                figures.Add(figure);
            }
            var geometry = new PathGeometry(figures, FillRule.EvenOdd, Transform.Identity);

            return(geometry);
        }
Beispiel #39
0
        /// <summary>
        /// Given a list of points, return a WPF PathGeometry.  This is a helper method
        /// that can be used to create a simple Geometry composed of straight lines.
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static PathGeometry GeometryFromPoints(Point[] points)
        {
            PolyLineSegment pls = new PolyLineSegment();

            foreach (Point p in points)
            {
                pls.Points.Add(p);
            }

            PathSegmentCollection segs = new PathSegmentCollection();

            segs.Add(pls);
            PathFigure fig = new PathFigure()
            {
                Segments = segs, StartPoint = points[points.Length - 1]
            };

            PathFigureCollection figs = new PathFigureCollection();

            figs.Add(fig);

            return(new PathGeometry()
            {
                Figures = figs
            });
        }
        public CachingTest()
        {
            InitializeComponent();

            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure();

            pathFigure.StartPoint = new Point(0, 0);
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            int    maxHeight = (int)this.Height;
            int    maxWidth  = (int)this.Width;
            Random rand      = new Random();

            for (int i = 0; i < 500; i++)
            {
                LineSegment newSegment = new LineSegment();
                newSegment.Point = new Point(rand.Next(0, maxWidth), rand.Next(0, maxHeight));
                pathSegmentCollection.Add(newSegment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);

            pathBackground.Data = pathGeometry;
        }
        public PointOfViewIndicator()
        {
            _activePositionBrush = Brushes.Red;
            _lineBrush = Brushes.DarkGray;
            _linePen = new Pen(_lineBrush, 1d);

            PathSegmentCollection segments = new PathSegmentCollection(4);
            segments.Add(new LineSegment(new Point(0, 10), false));
            segments.Add(new LineSegment(new Point(5, 0), false));
            segments.Add(new LineSegment(new Point(10, 10), false));
            segments.Add(new LineSegment(new Point(5, 5), false));

            PathFigureCollection figures = new PathFigureCollection();
            figures.Add(new PathFigure(new Point(5, 5), segments, true));

            _arrowPath = new PathGeometry(figures);
        }
Beispiel #42
0
 public static PathSegmentCollection Clone(this PathSegmentCollection source)
 {
     var result = new PathSegmentCollection();
     foreach (var pathSegment in source)
     {
         var line = pathSegment as LineSegment;
         result.Add(new LineSegment { Point = line.Point });
     }
     return result;
 }
Beispiel #43
0
        public Path CreatePath(Point location, double angle, double radius, double innerRadius, Brush brush)
        {
            var isLargeArc = angle > FULL_ARC / 2;

            var path = new Path();
            var segments = new PathSegmentCollection();
            var arcPoint = ConvertRadianToCartesian(angle, radius);
            var innerArcPoint = ConvertRadianToCartesian(angle, innerRadius);

            segments.Add(new LineSegment(new Point(location.X, location.Y - radius), false));
            segments.Add(new ArcSegment(new Point(location.X + arcPoint.X, location.Y + arcPoint.Y), new Size(radius, radius), 0, isLargeArc, SweepDirection.Clockwise, false));
            segments.Add(new LineSegment(new Point(location.X + innerArcPoint.X, location.Y + innerArcPoint.Y), false));
            segments.Add(new ArcSegment(new Point(location.X, location.Y - innerRadius), new Size(innerRadius, innerRadius), 0, isLargeArc, SweepDirection.Counterclockwise, false));

            var figure = new PathFigure(location, segments, true);
            path.Data = new PathGeometry { Figures = new PathFigureCollection { figure } };

            path.Fill = brush;
            return path;
        }
        private static PathSegmentCollection PointsAroundWidget(List<System.Windows.Point> pointlist)
        {
            PathSegmentCollection collection = new PathSegmentCollection();

            int index = 0;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));


            index = (index + 1) % pointlist.Count;
            collection.Add(new ArcSegment(pointlist[index], new System.Windows.Size(0, 0), 0, true, SweepDirection.Clockwise, false));

            return collection;
        }
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
     PathSegmentCollection retVal = new PathSegmentCollection();
     PointCollection pointCollection = value as PointCollection;
     if (RoundRadius > 0)
     {
         if (pointCollection != null && pointCollection.Count > 0)
         {
             retVal.Add(new LineSegment(pointCollection[0], true));
             double curSegmentArcUsed = 0;
             for (int i = 1; i < pointCollection.Count - 1; i++)
             {
                 double dist1 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i - 1], pointCollection[i]);
                 double dist2 = DesignerGeometryHelper.DistanceBetweenPoints(pointCollection[i], pointCollection[i + 1]);
                 if (dist1 - curSegmentArcUsed > RoundRadius &&
                     dist2 > RoundRadius)
                 {
                     //build rounded arc at line join.
                     curSegmentArcUsed = RoundRadius;
                     Vector firstSegmentPointingVector = new Vector(pointCollection[i].X - pointCollection[i - 1].X, pointCollection[i].Y - pointCollection[i - 1].Y);
                     Vector secondSegmentPointingVector = new Vector(pointCollection[i + 1].X - pointCollection[i].X, pointCollection[i + 1].Y - pointCollection[i].Y);
                     firstSegmentPointingVector.Normalize();
                     secondSegmentPointingVector.Normalize();
                     Point turningPoint1 = Point.Add(pointCollection[i - 1], Vector.Multiply(dist1 - RoundRadius, firstSegmentPointingVector));
                     Point turningPoint2 = Point.Add(pointCollection[i], Vector.Multiply(RoundRadius, secondSegmentPointingVector));
                     double crossProductZ = firstSegmentPointingVector.X * secondSegmentPointingVector.Y - firstSegmentPointingVector.Y * secondSegmentPointingVector.X;
                     retVal.Add(new LineSegment(turningPoint1, true));
                     retVal.Add(new ArcSegment(turningPoint2, new Size(RoundRadius, RoundRadius), 0, false, crossProductZ > 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, true));
                 }
                 else
                 {
                     curSegmentArcUsed = 0;
                     retVal.Add(new LineSegment(pointCollection[i], true));
                 }
             }
             retVal.Add(new LineSegment(pointCollection[pointCollection.Count - 1], true));
         }
     }
     return retVal;
 }
Beispiel #46
0
        public static PathGeometry GenerateBezierCurve(Point[] points)
        {
            PathFigure pathFigure = new PathFigure();
            PointCollection pointCollection = new PointCollection(points.Length);
            pathFigure.StartPoint = new Point(points[0].X, points[0].Y);

            PathGeometry myPathGeometry = new PathGeometry();
            PathSegment pathSegment;

            if (points.Length == 2)
            {
                pathSegment = new LineSegment();
                ((LineSegment)pathSegment).Point = new Point(points[1].X, points[1].Y);
            }
            else if (points.Length == 3)
            {
                pathSegment = new QuadraticBezierSegment();
                ((QuadraticBezierSegment)pathSegment).Point1 = new Point(points[1].X, points[1].Y);
                ((QuadraticBezierSegment)pathSegment).Point2 = new Point(points[2].X, points[2].Y);
            }
            else if (points.Length == 4)
            {
                for (int i = 1; i < points.Length; i++)
                {
                    pointCollection.Add(points[i]);
                }

                pathSegment = new PolyBezierSegment();
                ((PolyBezierSegment)pathSegment).Points = pointCollection;
            }
            else
            {
                return null;
            }

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(pathSegment);

            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            myPathGeometry.Figures = pathFigureCollection;

            return myPathGeometry;
        }
        public static Geometry BorderFromPoints(double haw, double hah, double taw,double tah,double arcvalue)
        {
            //double Margin = 10;
            //double before = Margin + arcvalue;
            double startheaderxmargin = 20;
            double yupmargin = hah / 2;
            double ymargin = 5;
            double xmargin = 2;

            PathFigure myPathFigure = new PathFigure();
            myPathFigure.StartPoint = new Point(haw + startheaderxmargin, yupmargin);

            Size ArcSize = new Size(arcvalue, arcvalue);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(new LineSegment(new Point(taw - arcvalue, yupmargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(taw - xmargin, yupmargin + arcvalue), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(taw - xmargin, tah - arcvalue - ymargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(taw - arcvalue - xmargin, tah - ymargin), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(arcvalue, tah - ymargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(0, tah - ymargin - arcvalue), ArcSize, 90, false, SweepDirection.Clockwise, true));

            myPathSegmentCollection.Add(new LineSegment(new Point(0, arcvalue + yupmargin), true));
            myPathSegmentCollection.Add(new ArcSegment(new Point(arcvalue / 2, yupmargin + arcvalue / 2), ArcSize, 45, false, SweepDirection.Clockwise, true));
    
            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            myPathFigureCollection.Add(myPathFigure);

            PathGeometry pg = new PathGeometry();
            pg.Figures = myPathFigureCollection;
            return pg;
        }
Beispiel #48
0
        /// <summary>
        /// transform a list of coordinate in a scatterviewitem
        /// </summary>
        /// <param name="coord"></param>
        public ScatterViewItem createScatterViewItem(List<int> coord)
        {
            ScatterViewItem myShape = new ScatterViewItem();
            //create the pathGeometry
            if (coord != null)
            {
                PathFigure myPathFigure = new PathFigure();
                myPathFigure.StartPoint = new Point(coord[0], coord[1]);

                PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
                for (int i = 2; i < coord.Count(); i = i + 2)
                {
                    LineSegment myLineSegment = new LineSegment();
                    myLineSegment.Point = new Point(coord[i], coord[i + 1]);
                    myPathSegmentCollection.Add(myLineSegment);
                }

                myPathFigure.Segments = myPathSegmentCollection;
                PathFigureCollection myPathFigureCollection = new PathFigureCollection();
                myPathFigureCollection.Add(myPathFigure);
                PathGeometry myPathGeometry = new PathGeometry();
                myPathGeometry.Figures = myPathFigureCollection;

                //create the path
                System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path();
                myPath.Stroke = Brushes.Black;
                myPath.StrokeThickness = 1;
                myPath.Data = myPathGeometry;
                myPath.Fill = new SolidColorBrush(Colors.Blue);

                //create the scatterViewItem
                myShape.Content = myPath;
                myShape.Width = this.max(coord);
                myShape.Height = this.max(coord);
            }

            return myShape;
        }
    GetPathGeometryFromPoints
    (
        System.Windows.Point startPoint,
        params Point [] otherPoints
    )
    {
        Debug.Assert(otherPoints != null);

        Int32 iOtherPoints = otherPoints.Length;

        Debug.Assert(iOtherPoints > 0);

        PathFigure oPathFigure = new PathFigure();

        oPathFigure.StartPoint = startPoint;

        PathSegmentCollection oPathSegmentCollection =
            new PathSegmentCollection(iOtherPoints);

        for (Int32 i = 0; i < iOtherPoints; i++)
        {
            oPathSegmentCollection.Add(
                new LineSegment(otherPoints[i], true) );
        }

        oPathFigure.Segments = oPathSegmentCollection;
        oPathFigure.IsClosed = true;
        WpfGraphicsUtil.FreezeIfFreezable(oPathFigure);

        PathGeometry oPathGeometry = new PathGeometry();

        oPathGeometry.Figures.Add(oPathFigure);
        WpfGraphicsUtil.FreezeIfFreezable(oPathGeometry);

        return (oPathGeometry);
    }
Beispiel #50
0
        /// <summary>
        /// Draw segments and connect them together.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void DrawPathSegments_Clicked(object sender, RoutedEventArgs e)
        {
            // Create a path
            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Black);
            path.StrokeThickness = 2;

            var pathGeometry = new PathGeometry();

            //create segments
            PathSegmentCollection segmentCollection = new PathSegmentCollection();
            segmentCollection.Add(new LineSegment() { Point = new Point(300, 400) });
            segmentCollection.Add(new LineSegment() { Point = new Point(400, 300) });
            segmentCollection.Add(new LineSegment() { Point = new Point(500, 300) });

            //create path feature
            var pathFigure = new PathFigure() { Segments = segmentCollection };
            pathFigure.StartPoint = new Point(150, 10);
            pathGeometry.Figures = new PathFigureCollection() { pathFigure };

            path.Data = pathGeometry;

            //Add drag drop behavior.
            path.SetValue(DragDropBehavior.PlacementTarget, this.DrawCanvas);

            Canvas.SetLeft(path, 0);
            Canvas.SetTop(path, 0);
            this.DrawCanvas.Children.Add(path);
        }
Beispiel #51
0
        private static Shape Worm(double dSize)
        {
            Path path = new Path();
            path.StrokeThickness = iStrokeThickness;
            path.StrokeLineJoin = PenLineJoin.Round;

            /*
            string[] arrStrPoints = new string[10];
            double dBringToStartX = -(dSize / 8);
            double dBringToStartY = -(dSize / 5);
            arrStrPoints[0] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[1] = (dBringToStartX + 3 * (dSize / 5)).ToString() + "," + (dBringToStartY + (dSize / 4) - (dSize / 10)).ToString() + " ";
            arrStrPoints[2] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[3] = dBringToStartX.ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[4] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[5] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[6] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[7] = (dBringToStartX + 3 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[8] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[9] = dBringToStartX.ToString() + "," + (dBringToStartY + dSize + (dSize / 10)).ToString() + " ";

            string sGeometry = "M " + arrStrPoints[0];
            sGeometry += "C " + arrStrPoints[0] + arrStrPoints[1] + arrStrPoints[2];
            sGeometry += "C " + arrStrPoints[3] + arrStrPoints[4] + arrStrPoints[5];
            sGeometry += "M " + arrStrPoints[0];
            sGeometry += "C " + arrStrPoints[6] + arrStrPoints[7] + arrStrPoints[8];
            sGeometry += "C " + arrStrPoints[8] + arrStrPoints[9] + arrStrPoints[5];
            path.Data = Geometry.Parse(sGeometry);
            */

            QuadraticBezierSegment pBezierSegment = new QuadraticBezierSegment();
            PointCollection pointsCollection = new PointCollection();
            pointsCollection.Add(new Point(0, 20));
            pointsCollection.Add(new Point(-10, 10));
            pointsCollection.Add(new Point(0, 0));
            pointsCollection.Add(new Point(10, 0));
            pointsCollection.Add(new Point(20, 40));
            pointsCollection.Add(new Point(30, 50));
            pointsCollection.Add(new Point(20, 60));
            pointsCollection.Add(new Point(10, 60));

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[0], pointsCollection[1], pointsCollection[2]), pointsCollection[2], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[2], pointsCollection[3], pointsCollection[4]), pointsCollection[4], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[4], pointsCollection[5], pointsCollection[6]), pointsCollection[6], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[6], pointsCollection[7], pointsCollection[0]), pointsCollection[0], true));

            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = pointsCollection[0];
            pathFigure.IsClosed = true;
            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures = pathFigureCollection;

            path.Data = pathGeometry;

            /*
            GraphicsPath p = new GraphicsPath();
            System.Drawing.Point[] wormArray = new System.Drawing.Point[6];
            wormArray[0] = new System.Drawing.Point(0, 0);
            wormArray[1] = new System.Drawing.Point(iSize / 10, 2 * (iSize / 5));
            wormArray[2] = new System.Drawing.Point(iSize / 10, 9 * (iSize / 10));
            wormArray[3] = new System.Drawing.Point(3 * (iSize / 5), iSize);
            wormArray[4] = new System.Drawing.Point((iSize / 2), 3 * (iSize / 5));
            wormArray[5] = new System.Drawing.Point((iSize / 2), (iSize / 10));

            for (int i = 0; i < 6; i++)
            {
                wormArray[i].X += x;
                wormArray[i].Y += y;
            }
            p.AddClosedCurve(wormArray);
            */
            return path;
        }
Beispiel #52
0
        internal void LayoutSegment(double startAngle, double endAngle, double radius, double gapScale, Point center, bool isDoughnut)
        {
            try
            {                
                if (startAngle > 360)
                {
                    return;
                }
                if (endAngle > 360)
                {
                    return;
                }
                if ((startAngle == 0.0) && (endAngle == 0.0))
                {
                    return;
                }
                if (endAngle > 359.5)
                {
                    endAngle = 359.5;    //pie disappears if endAngle is 360                 
                }

                // Segment Geometry
                double pieRadius = radius;
                double gapRadius = pieRadius * ((gapScale == 0.0) ? 0.25 : gapScale);

                Point A = GetCircumferencePoint(startAngle, pieRadius, center.X, center.Y);
                Point B = isDoughnut ? GetCircumferencePoint(startAngle, gapRadius, center.X, center.Y) : center;
                Point C = GetCircumferencePoint(endAngle, gapRadius, center.X, center.Y);
                Point D = GetCircumferencePoint(endAngle, pieRadius, center.X, center.Y);

                bool isReflexAngle = Math.Abs(endAngle - startAngle) > 180.0;
                
                PathSegmentCollection segments = new PathSegmentCollection();
                segments.Add(new LineSegment() { Point = B });

                if (isDoughnut)
                {
                    segments.Add(new ArcSegment()
                    {
                        Size = new Size(gapRadius, gapRadius),
                        Point = C,
                        SweepDirection = SweepDirection.Clockwise,
                        IsLargeArc = isReflexAngle
                    });
                }

                segments.Add(new LineSegment() { Point = D });
                segments.Add(new ArcSegment()
                {
                    Size = new Size(pieRadius, pieRadius),
                    Point = A,
                    SweepDirection = SweepDirection.Counterclockwise,
                    IsLargeArc = isReflexAngle
                });
                
                Path segmentPath = new Path()
                {
                    StrokeLineJoin = PenLineJoin.Round,
                    Stroke = new SolidColorBrush() { Color = Colors.Black },
                    StrokeThickness = 0.0d,
                    Data = new PathGeometry()
                    {
                        Figures = new PathFigureCollection()
                        {
                            new PathFigure()
                            {
                                IsClosed = true,
                                StartPoint = A,
                                Segments = segments
                            }
                        }
                    }
                };
                SetValue(PiePiece.GeometryProperty, CloneDeep(segmentPath.Data as PathGeometry));
                SetValue(PiePiece.SelectionGeometryProperty, CloneDeep(segmentPath.Data as PathGeometry));


                double inRadius = radius * 0.65;
                double outRadius = radius * 1.25;

                double midAngle = startAngle + ((endAngle - startAngle) / 2.0);
                Point pointOnCircle = GetCircumferencePoint(midAngle, pieRadius, center.X, center.Y);

                //recalculate midangle if point is to close to top or lower border
                double distanceToCenter = Math.Abs(pointOnCircle.Y - center.Y);
                double factor = distanceToCenter / center.Y;

                double midAngleBefore = midAngle;
                if ((GetQuadrant(pointOnCircle, center) == 1) || (GetQuadrant(pointOnCircle, center) == 3))
                {   //point is in quadrant 1 center, we go further the end angle
                    midAngle = startAngle + ((endAngle - startAngle) / 2.0) + (((endAngle - startAngle) / 2.0) * factor);
                }
                else
                {
                    //point 
                    midAngle = startAngle + ((endAngle - startAngle) / 2.0) - (((endAngle - startAngle) / 2.0) * factor);
                }
                
                pointOnCircle = GetCircumferencePoint(midAngle, pieRadius, center.X, center.Y);

                Point pointOuterCircle = GetCircumferencePoint(midAngle, pieRadius + 10, center.X, center.Y);
                Point pointerMoreOuter = new Point(pointOuterCircle.X - 10, pointOuterCircle.Y);
                if (pointOnCircle.X > center.X)
                {
                    pointerMoreOuter = new Point(pointOuterCircle.X + 10, pointOuterCircle.Y);
                }

                PathSegmentCollection linesegments = new PathSegmentCollection();
                linesegments.Add(new LineSegment() { Point = pointOuterCircle });
                linesegments.Add(new LineSegment() { Point = pointerMoreOuter });

                Path linesegmentPath = new Path()
                {
                    StrokeLineJoin = PenLineJoin.Round,
                    Stroke = new SolidColorBrush() { Color = Colors.Black },
                    StrokeThickness = 2.0d,
                    Data = new PathGeometry()
                    {
                        Figures = new PathFigureCollection()
                        {
                            new PathFigure()
                            {
                                IsClosed = false,
                                StartPoint = pointOnCircle,
                                Segments = linesegments
                            }
                        }
                    }
                };
                SetValue(PiePiece.LineGeometryProperty, CloneDeep(linesegmentPath.Data as PathGeometry));
                /*
                label.Measure(new Size(420, 420));
                double labelwidth = label.DesiredSize.Width;
                double labelwidth = label.DesiredSize.Width;
                
                Size s = label.DesiredSize;
                double x = this.Value;
                */
                label.SetValue(Canvas.TopProperty, pointerMoreOuter.Y - (label.ActualHeight / 2.0));
                if (pointerMoreOuter.X > center.X)
                {
                    label.SetValue(Canvas.LeftProperty, pointerMoreOuter.X);
                }
                else
                {
                    label.SetValue(Canvas.LeftProperty, pointerMoreOuter.X - (label.ActualWidth));
                }                
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #53
0
        public static System.Windows.Shapes.Path CreatePath(List<System.Windows.Point> rawData)
        {
            System.Windows.Shapes.Path finalPath = new System.Windows.Shapes.Path();
            PathGeometry finalPathGeometry = new PathGeometry();
            PathFigure primaryFigure = new PathFigure();

            //if you want the path to be a shape, you want to close the PathFigure
            //   that makes up the Path. If you want it to simply by a line, set
            //   primaryFigure.IsClosed = false;
            primaryFigure.IsClosed = true;
            primaryFigure.StartPoint = rawData[0];

            PathSegmentCollection lineSegmentCollection = new PathSegmentCollection();
            for (int i = 1; i < rawData.Count; i++)
            {
                LineSegment newSegment = new LineSegment();
                newSegment.Point = rawData[i];
                lineSegmentCollection.Add(newSegment);
            }

            primaryFigure.Segments = lineSegmentCollection;
            finalPathGeometry.Figures.Add(primaryFigure);
            finalPath.Data = finalPathGeometry;

            return finalPath;
        }
Beispiel #54
0
        public override void Plot(bool animate = true)
        {
            if (Visibility != Visibility.Visible) return;
            var chart = Chart as RadarChart;
            if (chart == null) return;
            var alpha = 360 / chart.Max.X;

            var pf = new PathFigure();
            var segments = new PathSegmentCollection();
            var l = 0d;

            Point? p2 = null;

            if (!Values.Points.Any()) return;
            var lastPoint = Values.Points.Last();
            var fisrtPoint = Values.Points.First();
            foreach (var point in Values.Points)
            {
                var r1 = point != lastPoint
                    ? chart.ToChartRadius(point.Y)
                    : chart.ToChartRadius(fisrtPoint.Y);
                if (point == fisrtPoint)
                    pf.StartPoint = new Point(
                        chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                        chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                else
                    segments.Add(new LineSegment
                    {
                        Point = new Point
                        {
                            X = chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                            Y = chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1
                        }
                    });

                var p1 = new Point(chart.ActualWidth/2 + Math.Sin(alpha*point.X*(Math.PI/180))*r1,
                    chart.ActualHeight/2 - Math.Cos(alpha*point.X*(Math.PI/180))*r1);
                if (p2 != null)
                {
                    l += Math.Sqrt(
                        Math.Pow(Math.Abs(p1.X - p2.Value.X), 2) +
                        Math.Pow(Math.Abs(p1.Y - p2.Value.Y), 2)
                        );
                }
                p2 = p1;

                if (point == lastPoint) continue;

                var r = new Rectangle
                {
                    Fill = Brushes.Transparent,
                    Width = 40,
                    Height = 40
                };
                var e = new Ellipse
                {
                    Width = PointRadius*2,
                    Height = PointRadius*2,
                    Fill = Stroke,
                    Stroke = new SolidColorBrush {Color = Chart.PointHoverColor},
                    StrokeThickness = 2
                };

                r.MouseEnter += chart.DataMouseEnter;
                r.MouseLeave += chart.DataMouseLeave;
                r.MouseDown += chart.DataMouseDown;
                chart.Canvas.Children.Add(r);
                Shapes.Add(r);
                chart.HoverableShapes.Add(new HoverableShape
                {
                    Series = this,
                    Shape = r,
                    Value = point,
                    Target = e
                });

                Shapes.Add(e);
                chart.Canvas.Children.Add(e);
                Panel.SetZIndex(r, int.MaxValue);

                Canvas.SetLeft(e, p1.X - e.Width/2);
                Canvas.SetTop(e, p1.Y - e.Height/2);
                Panel.SetZIndex(e, 2);

                Canvas.SetLeft(r, p1.X - r.Width/2);
                Canvas.SetTop(r, p1.Y - r.Height/2);
                Panel.SetZIndex(r, int.MaxValue);

                if (!chart.DisableAnimation && animate)
                {
                    var topAnim = new DoubleAnimation
                    {
                        From = chart.ActualHeight/2,
                        To = p1.Y - e.Height/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.TopProperty, topAnim);
                    var leftAnim = new DoubleAnimation
                    {
                        From = chart.ActualWidth/2,
                        To = p1.X - e.Width/2,
                        Duration = TimeSpan.FromMilliseconds(300)
                    };
                    e.BeginAnimation(Canvas.LeftProperty, leftAnim);
                }

            }

            pf.Segments = segments;
            var g = new PathGeometry
            {
                Figures = new PathFigureCollection(new List<PathFigure>
                {
                    pf
                })
            };

            var path = new Path
            {
                Stroke = Stroke,
                StrokeThickness = StrokeThickness,
                Data = g,
                StrokeEndLineCap = PenLineCap.Round,
                StrokeStartLineCap = PenLineCap.Round,
                Fill = Fill,
                StrokeDashOffset = l,
                StrokeDashArray = new DoubleCollection { l, l }
            };

            var draw = new DoubleAnimationUsingKeyFrames
            {
                BeginTime = TimeSpan.FromSeconds(0),
                KeyFrames = new DoubleKeyFrameCollection
                {
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(1),
                        Value = l
                    },
                    new SplineDoubleKeyFrame
                    {
                        KeyTime = TimeSpan.FromMilliseconds(750),
                        Value = 0
                    }
                }
            };
            Storyboard.SetTarget(draw, path);
            Storyboard.SetTargetProperty(draw, new PropertyPath(Shape.StrokeDashOffsetProperty));
            var sbDraw = new Storyboard();
            sbDraw.Children.Add(draw);
            var animated = false;
            if (!chart.DisableAnimation)
            {
                if (animate)
                {
                    sbDraw.Begin();
                    animated = true;
                }
            }
            if (!animated) path.StrokeDashOffset = 0;

            chart.Canvas.Children.Add(path);
            Shapes.Add(path);
        }
        private void DrawSegment(Point p1, Point p2, Point p3, Point p4, bool reflexangle, Color clr)
        {

            // Segment Geometry
            PathSegmentCollection segments = new PathSegmentCollection();

            // First line segment from pt p1 - pt p2
            segments.Add(new LineSegment() { Point = p2 });

            //Arc drawn from pt p2 - pt p3 with the RangeIndicatorRadius 
            segments.Add(new ArcSegment()
            {
                Size = new Size(arcradius2, arcradius2),
                Point = p3,
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc = reflexangle

            });

            // Second line segment from pt p3 - pt p4
            segments.Add(new LineSegment() { Point = p4 });

            //Arc drawn from pt p4 - pt p1 with the Radius of arcradius1 
            segments.Add(new ArcSegment()
            {
                Size = new Size(arcradius1, arcradius1),
                Point = p1,
                SweepDirection = SweepDirection.Counterclockwise,
                IsLargeArc = reflexangle

            });

            // Defining the segment path properties
            Color rangestrokecolor;
            if (clr == Colors.Transparent)
            {
                rangestrokecolor = clr;
            }
            else
                rangestrokecolor = Colors.White;



            rangeIndicator = new Path()
            {
                StrokeLineJoin = PenLineJoin.Round,
                Stroke = new SolidColorBrush(rangestrokecolor),
                //Color.FromArgb(0xFF, 0xF5, 0x9A, 0x86)
                Fill = new SolidColorBrush(clr),
                Opacity = 0.65,
                StrokeThickness = 0.25,
                Data = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                     {
                        new PathFigure()
                        {
                            IsClosed = true,
                            StartPoint = p1,
                            Segments = segments
                        }
                    }
                }
            };

            //Set Z index of range indicator
            rangeIndicator.SetValue(Canvas.ZIndexProperty, 150);
            // Adding the segment to the root grid 
            LayoutRoot.Children.Add(rangeIndicator);

        }
        /// <summary>
        /// Draw the hatches and the transparent area where isn't covering the elements.
        /// </summary>
        /// <param name="drawingContext"></param>
        private void DrawBackgound(DrawingContext drawingContext)
        {
            PathGeometry hatchGeometry = null;
            Geometry rectGeometry = null;

            int count = _elementsBounds.Count;
            if ( count != 0 )
            {
                // Create a union collection of the element regions.
                for ( int i = 0; i < count; i++ )
                {
                    Rect hatchRect = _elementsBounds[i];

                    if ( hatchRect.IsEmpty )
                    {
                        continue;
                    }

                    hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2);

                    if ( hatchGeometry == null )
                    {
                        PathFigure path = new PathFigure();
                        path.StartPoint = new Point(hatchRect.Left, hatchRect.Top);

                        PathSegmentCollection segments = new PathSegmentCollection();
                        
                        PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); 
                        line.Freeze();
                        segments.Add(line);
                        
                        line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); 
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true);
                        line.Freeze();
                        segments.Add(line);

                        line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true);
                        line.Freeze();
                        segments.Add(line);

                        segments.Freeze();
                        path.Segments = segments;

                        path.IsClosed = true;
                        path.Freeze();

                        hatchGeometry = new PathGeometry();
                        hatchGeometry.Figures.Add(path);
                    }
                    else
                    {
                        rectGeometry = new RectangleGeometry(hatchRect);
                        rectGeometry.Freeze();

                        hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null);
                    }
                }
            }

            // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..."
            GeometryGroup backgroundGeometry = new GeometryGroup( );
            GeometryCollection geometryCollection = new GeometryCollection();

            // Add the entile rectanlge to the group.
            rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height));
            rectGeometry.Freeze();
            geometryCollection.Add(rectGeometry);

            // Add the union of the element rectangles. Then the group will do oddeven operation.
            Geometry outlineGeometry = null;

            if ( hatchGeometry != null )
            {
                hatchGeometry.Freeze();

                outlineGeometry = hatchGeometry.GetOutlinedPathGeometry();
                outlineGeometry.Freeze();
                if ( count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0 )
                {
                    geometryCollection.Add(outlineGeometry);
                }
            }

            geometryCollection.Freeze();
            backgroundGeometry.Children = geometryCollection;
            backgroundGeometry.Freeze();

            // Then, draw the region which may contain holes so that the elements cannot be covered.
            // After that, the underneath elements can receive the messages.
#if DEBUG_OUTPUT
            // Draw the debug feedback
            drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry);
#else
            drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry);
#endif

            // At last, draw the hatch borders
            if ( outlineGeometry != null )
            {
                drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry);
            }
        }
Beispiel #57
0
        // Plots a graph of the passed easing function using the given sampling interval on the "Graph" Canvas control 
        private void PlotEasingFunctionGraph(EasingFunctionBase easingFunction, double samplingInterval)
        {
            UISettings UserSettings = new UISettings();
            Graph.Children.Clear();

            Path path = new Path();
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure pathFigure = new PathFigure() { StartPoint = new Point(0, 0) };
            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();

            // Note that an easing function is just like a regular function that operates on doubles.
            // Here we plot the range of the easing function's output on the y-axis of a graph.
            for (double i = 0; i < 1; i += samplingInterval)
            {
                double x = i * GraphContainer.Width;
                double y = easingFunction.Ease(i) * GraphContainer.Height;

                LineSegment segment = new LineSegment();
                segment.Point = new Point(x, y);
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            pathGeometry.Figures.Add(pathFigure);
            path.Data = pathGeometry;
            path.Stroke = new SolidColorBrush(UserSettings.UIElementColor(UIElementType.ButtonText));
            path.StrokeThickness = 1;

            // Add the path to the Canvas
            Graph.Children.Add(path);
        }
Beispiel #58
0
 public void plotPoints(List<Point> pointslist)
 {
     setAxes();
     setXaxisTitle(Xtitle);
     setYaxisTitle(Ytitle);
     setPlotTitle(Plottitle);
     GeometryGroup s = new GeometryGroup();
     PathGeometry pg = new PathGeometry();
     PathFigureCollection pfc = new PathFigureCollection();
     PathFigure pf = new PathFigure();
     PathSegmentCollection psc = new PathSegmentCollection();
     Point stpoint = pointslist[0];
     stpoint.X = origin.X + spanX * stpoint.X;
     stpoint.Y = origin.Y - spanY * stpoint.Y;
     pf.StartPoint = stpoint;
     EllipseGeometry elg = new EllipseGeometry(stpoint, 2, 2);
     s.Children.Add(elg);
     string pointText = pointToText(stpoint);
     setText(pointText, stpoint);
     for (int i = 1; i < pointslist.Count; i++)
     {
         Point point = pointslist[i];
         point.X = origin.X + spanX * point.X;
         point.Y = origin.Y - spanY * point.Y;
         LineSegment ls = new LineSegment(point, true);
         elg = new EllipseGeometry(point, 2, 2);
         setText(pointToText(point), point);
         s.Children.Add(elg);
         psc.Add(ls);
     }
     pf.Segments = psc;
     pfc.Add(pf);
     pg.Figures = pfc;
     Path p = new Path();
     Path p1 = new Path();
     p.Data = pg;
     p.Stroke = Brushes.Green;
     p1.Data = s;
     p1.Fill = Brushes.Blue;
     activeCanvas.Children.Add(p);
     activeCanvas.Children.Add(p1);
     activeCanvas.ClipToBounds = true;
 }
        private Path StrokeToPath(Stroke oStroke)
        {
            PathFigure myPathFigure = null;
            LineSegment myLineSegment = null;
            PathFigureCollection myPathFigureCollection = new PathFigureCollection();
            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            if (oStroke == null) return null;

            // Number of points.
            int n = oStroke.StylusPoints.Count;
            if (n == 0) return null;

            // Start point is first point from sytluspoints collection (M, item 0).
            myPathFigure = new PathFigure();
            myPathFigure.StartPoint =
                new Point(oStroke.StylusPoints[0].X, oStroke.StylusPoints[0].Y);
            myPathFigureCollection.Add(myPathFigure);

            // Make small line segment L if there is only one point in the Stroke (workaround).
            // Data with only M is not shown.
            if (n == 1)
            {
                myLineSegment = new LineSegment();
                myLineSegment.Point =
                    new Point(oStroke.StylusPoints[0].X + 1, oStroke.StylusPoints[0].Y + 1);
                myPathSegmentCollection.Add(myLineSegment);
            }

            // The other points are line segments (L, items 1..n-1).
            for (int i = 1; i < n; i++)
            {
                myLineSegment = new LineSegment();
                myLineSegment.Point = new Point(oStroke.StylusPoints[i].X, oStroke.StylusPoints[i].Y);
                myPathSegmentCollection.Add(myLineSegment);
            }

            myPathFigure.Segments = myPathSegmentCollection;

            PathGeometry myPathGeometry = new PathGeometry();
            myPathGeometry.Figures = myPathFigureCollection;

            Path oPath = new Path();

            // Add the data to the Path.
            oPath.Data = myPathGeometry;                    // <-|

            // Copy Stroke properties to Path.
            // ----------------------------------------
            // Stroke color.
            Color oC = oStroke.DrawingAttributes.Color;     // Stroke color.
            SolidColorBrush oBr = new SolidColorBrush();
            oBr.Color = oC;
            oPath.Stroke = oBr;

            // Stroke thickness.
            double dW = oStroke.DrawingAttributes.Width;    // Width of stylus.
            double dH = oStroke.DrawingAttributes.Height;   // Height of stylus.
            oPath.StrokeThickness = dW;

            // Attribute FitToCurve.
            // FitToCurve has no effect on the points, oStroke.StylusPoints is used.
            // See also oStroke.GetBezierStylusPoints().
            // See also test with GetAllPoints().

            // Stroke has no Fill property in attributes.
            // oPath.Fill = mySolidColorBrush;
            // ----------------------------------------

            return oPath;
        }
Beispiel #60
0
        private void plotLogPoints()
        {
            double spanX = Math.Log(2);
            double spanY = Math.Log(2);
            setLogAxes();
            GeometryGroup s = new GeometryGroup();
            PathGeometry pg = new PathGeometry();
            PathFigureCollection pfc = new PathFigureCollection();
            PathFigure pf = new PathFigure();
            PathSegmentCollection psc = new PathSegmentCollection();
            Point stpoint = pointslist[0];
            stpoint.X = Math.Round(origin.X + spanX * stpoint.X, 2);
            stpoint.Y = Math.Round(origin.Y - spanY * stpoint.Y, 2);
            pf.StartPoint = stpoint;
            EllipseGeometry elg = new EllipseGeometry(stpoint, 2, 2);
            s.Children.Add(elg);
            setText(pointToText(stpoint), stpoint);
            for (int i = 1; i < pointslist.Count; i++)
            {
                Point point = pointslist[i];
                point.X = Math.Round(origin.X + spanX * point.X, 2);
                point.Y = Math.Round(origin.Y - spanY * point.Y, 2);
                LineSegment ls = new LineSegment(point, true);
                elg = new EllipseGeometry(point, 2, 2);
                setText(pointToText(point), point);
                s.Children.Add(elg);
                psc.Add(ls);
                spanX = Math.Log(i + 1) * 10;
                spanY = Math.Log(i + 1) * 10;
            }
            pf.Segments = psc;
            pfc.Add(pf);
            pg.Figures = pfc;
            Path p = new Path();
            Path p1 = new Path();
            p.Data = pg;
            p.Stroke = Brushes.Green;
            p1.Data = s;
            p1.Fill = Brushes.Blue;
            activeCanvas.Children.Add(p);
            activeCanvas.Children.Add(p1);
            activeCanvas.ClipToBounds = true;

        }