Inheritance: Geometry, IGeometryGroup
Exemplo n.º 1
0
 private Path getPiece()
 {
     if ((piece == cross))
     {
         Path lines = new Path();
         LineGeometry line1 = new LineGeometry();
         LineGeometry line2 = new LineGeometry();
         GeometryGroup linegroup = new GeometryGroup();
         line1.StartPoint = new Point(0, 0);
         line1.EndPoint = new Point(60, 60);
         line2.StartPoint = new Point(60, 0);
         line2.EndPoint = new Point(0, 60);
         linegroup.Children.Add(line1);
         linegroup.Children.Add(line2);
         lines.Data = linegroup;
         lines.Stroke = new SolidColorBrush(Colors.Red);
         lines.StrokeThickness = 5;
         lines.Margin = new Thickness(10);
         return lines;
     }
     else
     {
         EllipseGeometry ellipse = new EllipseGeometry();
         Path circle = new Path();
         ellipse.Center = new Point(30, 30);
         ellipse.RadiusX = 30;
         ellipse.RadiusY = 30;
         circle.Data = ellipse;
         circle.Stroke = new SolidColorBrush(Colors.Blue);
         circle.StrokeThickness = 5;
         circle.Margin = new Thickness(10);
         return circle;
     }
 }
Exemplo n.º 2
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (value == null) return null;
            var fontsize = int.Parse((string)parameter);
            CultureInfo info = CultureInfo.CurrentUICulture;
            var flowDirection = FlowDirection.LeftToRight;
            var fontFamily = new FontFamily((string)Application.Current.Resources["DefaultFontFamily"]);
            var path = new GeometryGroup();
            double scale = fontsize/(double)32;
            var point = new Point();

            return path;
        }
Exemplo n.º 3
0
        private Path MkPath(double indx, double increment)
        {
            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Braid{0}", indx);
            path.Tag = indx;

            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);

            //pg.Figures.Add(BuildStrand(indx * repeatAngle, 0, increment));
            for (int i = 0; i < bd.NumStrands; i++)
            {
                pg.Figures.Add(BuildStrand(indx * repeatAngle, i, increment));
            } 
            return path;
        }
Exemplo n.º 4
0
        public async Task<bool> DrawWaveform(Canvas canvas)
        {
            if (this.WaveFile == null)
            {
                this.WaveFile = await WaveFile.Create(AudioFile);
            }

            double W = canvas.ActualWidth;
            double H = canvas.ActualHeight;

            double y_c = H / 2.0;

            canvas.Children.Clear();
            double dseconds = (1.0 / 16000.0);
            double dpixels = PixelsPerSecond * dseconds;
            canvas.Width = this.WaveFile.SmoothedSamples.Count * dpixels;


            Path path = new Path();
            path.Stroke = new SolidColorBrush(Windows.UI.Colors.DeepSkyBlue);
            path.StrokeThickness = 2.0;
            GeometryGroup geomGroup = new GeometryGroup();

            for (int i = 0; i < Samples.Count; ++i)
            {
                double f = Samples[i];

                Point a = new Point((i * dpixels) + 0.5, y_c - f * y_c);
                Point b = new Point((i * dpixels) + 0.5, y_c + f * y_c);

                LineGeometry line = new LineGeometry();
                line.StartPoint = a;
                line.EndPoint = b;
                geomGroup.Children.Add(line);
            }

            path.Data = geomGroup;
            canvas.Children.Add(path);

            return true;
        }
Exemplo n.º 5
0
        private Geometry buildSingleItemPath(Point centerPoint)
        {
            GeometryGroup gg = new GeometryGroup();

            EllipseGeometry outerEllipse = new EllipseGeometry();
            outerEllipse.Center = centerPoint;
            outerEllipse.RadiusX = Radius;
            outerEllipse.RadiusY = Radius;

            gg.Children.Add(outerEllipse);

            if (InnerRadius != 0)
            {
                EllipseGeometry innerEllipse = new EllipseGeometry();
                innerEllipse.Center = centerPoint;
                innerEllipse.RadiusX = InnerRadius;
                innerEllipse.RadiusY = InnerRadius;

                gg.Children.Add(innerEllipse);
            }

            return gg;

        }
 private Path getPiece(int player)
 {
     if ((player == 1)) // Draw X
     {
         Path lines = new Path();
         LineGeometry line1 = new LineGeometry();
         LineGeometry line2 = new LineGeometry();
         GeometryGroup linegroup = new GeometryGroup();
         line1.StartPoint = new Point(0, 0);
         line1.EndPoint = new Point(30, 30);
         line2.StartPoint = new Point(30, 0);
         line2.EndPoint = new Point(0, 30);
         linegroup.Children.Add(line1);
         linegroup.Children.Add(line2);
         lines.Data = linegroup;
         lines.Stroke = new SolidColorBrush(Colors.Red);
         lines.StrokeThickness = 2;
         lines.Margin = new Thickness(4);
         return lines;
     }
     else // Draw O
     {
         EllipseGeometry ellipse = new EllipseGeometry();
         Path circle = new Path();
         ellipse.Center = new Point(15, 15);
         ellipse.RadiusX = 15;
         ellipse.RadiusY = 15;
         circle.Data = ellipse;
         circle.Stroke = new SolidColorBrush(Colors.Blue);
         circle.StrokeThickness = 2;
         circle.Margin = new Thickness(4);
         return circle;
     }
 }
Exemplo n.º 7
0
        private GeometryGroup GetBorderGeometry(IList<Point> points)
        {
            var group = new GeometryGroup();
            var geom = new PathGeometry();

            var path = new PathFigure { StartPoint = points[7] };
            path.Segments.Add(GetCornerSegment(points[7], points[0], CellRadius, CellSize));
            if ((ConnectionType & CellConnectionType.Top) != CellConnectionType.Top)
            {
                path.Segments.Add(new LineSegment() { Point = points[1] });
            }
            else
            {
                geom.Figures.Add(path);
                path = new PathFigure { StartPoint = points[1] };
            }

            path.Segments.Add(GetCornerSegment(points[1], points[2], CellRadius, CellSize));

            if ((ConnectionType & CellConnectionType.Right) != CellConnectionType.Right)
            {
                path.Segments.Add(new LineSegment() { Point = points[3] });
            }
            else
            {
                geom.Figures.Add(path);
                path = new PathFigure { StartPoint = points[3] };
            }
            path.Segments.Add(GetCornerSegment(points[3], points[4], CellRadius, CellSize));

            if ((ConnectionType & CellConnectionType.Bottom) != CellConnectionType.Bottom)
            {
                path.Segments.Add(new LineSegment() { Point = points[5] });
            }
            else
            {
                geom.Figures.Add(path);
                path = new PathFigure { StartPoint = points[5] };
            }
            path.Segments.Add(GetCornerSegment(points[5], points[6], CellRadius, CellSize));

            if ((ConnectionType & CellConnectionType.Left) != CellConnectionType.Left)
            {
                path.Segments.Add(new LineSegment() { Point = points[7] });
            }

            geom.Figures.Add(path);
            group.Children.Add(geom);
            return group;
        }
Exemplo n.º 8
0
        private Windows.UI.Xaml.Shapes.Shape MkPath(int indx, int indy, double inc)
        {
            double innerR = Math.Abs(ld.Layout.ClipRange.Start);
            double outerR = Math.Abs(ld.Layout.ClipRange.End);
            
            double startX = indx * ld.Layout.Width + ld.Layout.OffsetX * colWidth;
            double startY = indy * ld.Layout.Height + ld.Layout.OffsetY * rowHeight;

            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Lattice{0}_{1}", indx,indy);
            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);
            PathFigure pf;
            Point origin = new Point(0, 0);

            foreach (Line2D ll in ld.Lines)
            {
                double x1 = startX + ll.X1 * colWidth;
                double x2 = startX + ll.X2 * colWidth;
                double y1 = startY + ll.Y1 * rowHeight;
                double y2 = startY + ll.Y2 * rowHeight;

               
                Point p1 = new Point(x1, y1);
                Point p2 = new Point(x2, y2);
                if (ld.Layout.Hyper)
                {
                    Hypo(ref p1);
                    Hypo(ref p2);
                }

                Point intrsct;

                if (ld.Layout.Clip)
                {
                    double d1 = p1.Radius();
                    double d2 = p2.Radius();
                    Point pstart = (d1 < d2) ? p1 : p2;
                    Point pend = (d1 < d2) ? p2 : p1;
                    pf = null;
                    if (innerR > 0)
                    {
                        d1 = pstart.Radius();
                        d2 = pend.Radius();
                        // must clip against both inner and outer radii
                        // first clip against inner 
                        if ((d1 > outerR) && (d2 > outerR))
                        {
                            Tuple<int, Point, Point> intrscts = BasicLib.CircleLineIntersect(pstart, pend, outerR);
                            if (intrscts.Item1 == 1)
                            {
                               
                            }
                            else if (intrscts.Item1 == 2)
                            {
                                if (BasicLib.Between(pstart, intrscts.Item2, pend) &&
                                    BasicLib.Between(pstart, intrscts.Item3, pend))
                                {
                                    pf = GeneratePathFigure(intrscts.Item2, intrscts.Item3);
                                    pg.Figures.Add(pf);
                                }
                            }
                        }
                        else if ((d1 < innerR) && (d2 < innerR))
                        {
                           // do nothing
                        }
                       
                        else if ((d1 < innerR) && (d2 >= innerR) && (d2 <= outerR))
                        {
                            if (BasicLib.IsVertical(pstart, pend))
                            {
                                double y = BasicLib.Sgn(pstart.Y) * Math.Sqrt(innerR * innerR - pstart.X * pstart.X);
                                Point p = new Point(pstart.X, y);
                                pf = GeneratePathFigure(p, pend);
                            }
                            else if (BasicLib.IsHorizontal(pstart, pend))
                            {
                                double x = BasicLib.Sgn(pstart.X) * Math.Sqrt(innerR * innerR - pstart.Y * pstart.Y);
                                Point p =  new Point(x, pstart.Y);
                                pf = GeneratePathFigure(p,pend);
                            }
                            else
                            {
                                intrsct = CircleLineIntersect(pstart, pend, innerR);
                                pf = GeneratePathFigure(intrsct, pend);
                            }
                        }
                        else if ((d1 >= innerR) && (d1 <= outerR) && (d2 >= innerR))
                        {
                            if (d2 <= outerR)
                            {
                                if (BasicLib.IsDiagonal(pstart, pend))
                                { // need to check if there is an intersection
                                    Tuple<int, Point, Point> intrscts = BasicLib.CircleLineIntersect(pstart, pend, innerR);
                                    if ((intrscts.Item1 == 0) ||(intrscts.Item1 == 1))
                                    { // tangent so plot
                                         pf = GeneratePathFigure(pstart, pend);
                                    }
                                    else if (intrscts.Item1 == 2)
                                    {
                                        
                                        if (BasicLib.Between(pstart, intrscts.Item2, pend) &&
                                            BasicLib.Between(pstart, intrscts.Item3, pend))
                                        {
                                            Vector2 v1 = new Vector2(pstart, intrscts.Item2);
                                            Vector2 v2 = new Vector2(pstart, intrscts.Item3);
                                            if (v1.Length < v2.Length)
                                            {
                                                pf = GeneratePathFigure(pstart, intrscts.Item2);
                                                pg.Figures.Add(pf);
                                                pf = GeneratePathFigure(intrscts.Item3, pend);
                                            }
                                            else
                                            {
                                                pf = GeneratePathFigure(pstart, intrscts.Item3);
                                                pg.Figures.Add(pf);
                                                pf = GeneratePathFigure(intrscts.Item2, pend);
                                            }
                                        }
                                        else pf = GeneratePathFigure(pstart, pend);
                                    }
                                }
                                else
                                    pf = GeneratePathFigure(pstart, pend);
                            }
                            else  // here d2 lies outside outerR
                            {
                                if (BasicLib.IsVertical(pstart, pend))
                                {
                                    double y = BasicLib.Sgn(pstart.Y) * Math.Sqrt(outerR * outerR - pstart.X * pstart.X);
                                    pf = GeneratePathFigure(pstart, new Point(pstart.X, y));
                                }
                                else if (BasicLib.IsHorizontal(pstart, pend))
                                {
                                    double x = BasicLib.Sgn(pstart.X) * Math.Sqrt(outerR * outerR - pstart.Y * pstart.Y);
                                    pf = GeneratePathFigure(pstart, new Point(x, pstart.Y));
                                }
                                else
                                {
                                    intrsct = CircleLineIntersect(pstart, pend, outerR);
                                    pf = GeneratePathFigure(pstart, intrsct);
                                }
                            }
                        }
                        if (pf != null)
                            try
                            {
                                if (pg.Figures.Contains(pf))
                                {
                                    pg.Figures.Remove(pf);
                                }
                                pg.Figures.Add(pf);
                            }
                            catch
                            {

                            }
                    }
                    else  // ignore innerR
                    #region Ignore innerR
                    {
                        if ((d1 > outerR) && (d2 > outerR))
                        {
                            pf = null;
                        }
                        else if ((d1 <= outerR) && (d2 <= outerR))
                        {
                            pf = GeneratePathFigure(pstart, pend);
                        }
                        else // one point lies either side
                        { // outerR must lie between d2 - d1
                            // need to start from inner not nearest
                            pstart = (d1 < outerR) ? p1 : p2;
                            pend = (d1 < outerR) ? p2 : p1;

                            if (BasicLib.IsVertical(p1, p2))
                            {
                                double y = Math.Sign(pstart.Y) * Math.Sqrt(outerR * outerR - pstart.X * pstart.X);
                                pf = GeneratePathFigure(pstart, new Point(pstart.X, y));
                            }
                            else if (BasicLib.IsHorizontal(p1, p2))
                            {
                                double x = Math.Sign(pstart.X) * Math.Sqrt(outerR * outerR - pstart.Y * pstart.Y);
                                pf = GeneratePathFigure(pstart, new Point(x, pstart.Y));
                            }
                            else
                            {
                                intrsct = CircleLineIntersect(pstart, pend, outerR);
                                pf = GeneratePathFigure(pstart, intrsct);
                            }
                        }

                        if (pf != null)
                            pg.Figures.Add(pf);
                    } 
                    #endregion

                   
                }
                else
                {
                    pf = GeneratePathFigure(p1,p2);
                    pg.Figures.Add(pf);
                }
            }
            return path;
        }
        /// <summary>
        /// Draws a collection of rectangles, where all have the same stroke and fill.
        /// This performs better than calling DrawRectangle multiple times.
        /// </summary>
        /// <param name="rectangles">
        /// The rectangles.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        public void DrawRectangles(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup { FillRule = FillRule.Nonzero };
            foreach (OxyRect rect in rectangles)
            {
                gg.Children.Add(new RectangleGeometry { Rect = rect.ToRect(true) });
            }

            path.Data = gg;
            this.Add(path);
        }
Exemplo n.º 10
0
        public void Update(bool globalNormlize = true)
        {
            var toDelete = xCanvas.Children.Where(u => u != xHightlightRect).ToArray();
            foreach (var uiElement in toDelete)
            {
                xCanvas.Children.Remove(uiElement);
            }

            DrawBackground();

            var vm = (LineGraphViewModel) DataContext;
            //    vm.TimeSeries.CollectionChanged += OnTimeSeriesChanged;

            double overallMin, overallMax;

            overallMin = vm.TimeSeries.Min(t => t.MetaData.Min);
            overallMax = vm.TimeSeries.Max(t => t.MetaData.Max);

            if (_path != null && xCanvas.Children.Contains(_path))
                xCanvas.Children.Remove(_path);

            _geometryGroup = new GeometryGroup();

            foreach (var ts in vm.TimeSeries)
            {
                var t = ts.Clone();
                t.Normalize(globalNormlize ? overallMin : ts.MetaData.Min, globalNormlize ? overallMax : ts.MetaData.Max);
                DrawGraph(t);
            }

              //  _path = new Path { Data = _geometryGroup, StrokeThickness = 3, Stroke = new SolidColorBrush(Colors.White) };

              //  xCanvas.Children.Add(_path);

            // DrawLabels(ts);
        }
Exemplo n.º 11
0
        private Windows.UI.Xaml.Shapes.Shape MkPath(int indx, int indy, double inc)
        {
            double rad = BasicLib.ToRadians;
            double deg = BasicLib.ToDegrees;

            Path path = new Path();
            path.Stroke = new SolidColorBrush(Colors.Red);
            path.Name = string.Format("Lattice{0}_{1}", indx, indy);
            GeometryGroup g = new GeometryGroup();
            path.Data = g;
            PathGeometry pg = new PathGeometry();
            g.Children.Add(pg);
            double startAngle = indx * repeatAngle;

            foreach (Line2D ll in ld.Lines)
            { 
                PathFigure pf = new PathFigure();
                double angle1 = startAngle + ll.X1 * colAngle;
                double angl1 = angle1 * rad;
                double angle2 = startAngle + ll.X2 * colAngle;
                double angl2 = angle2 * rad;
                double rowstart = indy * ld.Layout.Height;
                double y1 = ld.Layout.ToolPosition - rowstart  - ll.Y1 * rowHeight;
                double y2 = ld.Layout.ToolPosition - rowstart - ll.Y2 * rowHeight;
                
                pf.StartPoint = new Point(y1 * Math.Cos(angl1),
                                          y1 * Math.Sin(angl1));
                if (ll.IsVertical)
                {      
                    LineSegment ls = new LineSegment();
                    ls.Point = new Point(y2 * Math.Cos(angl1),
                                          y2 * Math.Sin(angl1));
                    pf.Segments.Add(ls);
                   
                }
                else if (ll.IsHorizontal)
                {
                    PolyLineSegment pls = new PolyLineSegment();
                    double a = angl1;
                    Point pnt;
                    do
                    {
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                        a += (angl1 < angl2) ? inc : -inc;
                    }
                    while ((angl1 < angl2) ? (a < angl2) : ( a > angl2));
                    if ((angl1 < angl2) ? (a != angl2) : (a != angl1))
                    {
                        a = (angl1 < angl2) ? angl2 : angl1;
                        pnt = new Point(y2 * Math.Cos(a), y2 * Math.Sin(a));
                        pls.Points.Add(pnt);
                    }
                    pf.Segments.Add(pls);
                }
                else // is diagonal
                {
                    double i = 0;
                    PolyLineSegment pls = new PolyLineSegment();
                    for (i = 0; i <= 1.0; i += inc)
                    {                  
                        pls.Points.Add(Interp(ll.X1,y1,i,ll.X2,y2,startAngle));
                    }        
                    pls.Points.Add(Interp(ll.X1, y1, 1.0, ll.X2, y2,startAngle));
                  
                    pf.Segments.Add(pls);
                } 
                pg.Figures.Add(pf);
            }
            return path;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Redraws this meter
        /// </summary>
        protected override void Redraw()
        {
            var group = new GeometryGroup();
            if (TickLength == null)
            {
                TickLength = 5;
            }
            DrawScale((double)TickLength, group, StartAngle);

            Data = group;
            InvalidateArrange();
        }
Exemplo n.º 13
0
        public static Windows.UI.Xaml.Shapes.Path GetGeometry(double width, double widthPoint1, double widthPoint2, double widthPoint3, double heightPoint1, double heightPoint2, SolidColorBrush color)
        {
            Windows.UI.Xaml.Shapes.Path myPath = new Windows.UI.Xaml.Shapes.Path();
            myPath.Stroke = color;
            myPath.StrokeThickness = 15;
           

            LineGeometry myLineGeometry = new LineGeometry();
            myLineGeometry.StartPoint = new Point(widthPoint1, heightPoint2);
            myLineGeometry.EndPoint = new Point(widthPoint1, heightPoint1);


            ArcSegment arc2 = new ArcSegment();
            arc2.Point = new Point(widthPoint2, heightPoint1);
            arc2.RotationAngle = 180;
            arc2.SweepDirection = SweepDirection.Clockwise;
            arc2.Size = new Size((double)(width / 6), heightPoint1);



            LineGeometry line3 = new LineGeometry();
            line3.StartPoint = new Point(widthPoint2, heightPoint1);
            line3.EndPoint = new Point(widthPoint2, heightPoint2);



            ArcSegment arc4 = new ArcSegment();
            arc4.Point = new Point(widthPoint3, heightPoint2);
            arc4.RotationAngle = 180;
            

            arc4.SweepDirection = SweepDirection.Clockwise;
            arc4.Size = new Size(width / 12, heightPoint1 / 2);

            LineGeometry line5 = new LineGeometry();
            line5.StartPoint = new Point(widthPoint3, heightPoint2);
            line5.EndPoint = new Point(widthPoint3, heightPoint1);

            

            PathFigure pathfigureforarc2 = new PathFigure();

            pathfigureforarc2.StartPoint = new Point(widthPoint1, heightPoint1);
            pathfigureforarc2.Segments.Add(arc2);
            pathfigureforarc2.IsFilled = false;

            PathFigure pathfigureforarc4 = new PathFigure();
            pathfigureforarc4.StartPoint = new Point(widthPoint2, heightPoint2);
            pathfigureforarc4.Segments.Add(arc4);
            pathfigureforarc4.IsFilled = false;

            PathGeometry pathgeoforarc2 = new PathGeometry();

            pathgeoforarc2.Figures.Add(pathfigureforarc2);


            PathGeometry pathgeoforarc4 = new PathGeometry();
            pathgeoforarc4.Figures.Add(pathfigureforarc4);


            GeometryGroup myGeometryGroup = new GeometryGroup();
            myGeometryGroup.Children.Add(myLineGeometry);
            myGeometryGroup.Children.Add(pathgeoforarc2);
            myGeometryGroup.Children.Add(line3);
            myGeometryGroup.Children.Add(pathgeoforarc4);
            myGeometryGroup.Children.Add(line5);            

            myPath.Data = myGeometryGroup;
            return myPath;
        }
Exemplo n.º 14
0
        private static PointCollection GetPoints(GeometryGroup geo)
        {
            PointCollection points = new PointCollection();
            foreach (Geometry geom in geo.Children)
            {

                if (geom.GetType() == typeof(LineGeometry))
                {
                    LineGeometry line = geom as LineGeometry;
                    Point start = line.StartPoint;
                    Point end = line.EndPoint;

                    double length = Math.Abs(end.Y - start.Y);

                    double fraction = length / 30;

                    for (int x = 0; x < 30; x++)
                    {
                        if (geom == geo.Children[0])
                        {
                            points.Add(new Point(start.X - 5,  start.Y - (x) * fraction));
                        }
                        else if( geom == geo.Children[4])
                        {
                            points.Add(new Point(start.X - 5, -5 + start.Y - (x) * fraction));
                        }
                        else //number 2 here
                        {
                        points.Add(new Point(start.X - 5, -10 + start.Y + (x) * fraction));
                        }

                    }

                }

                if (geom.GetType() == typeof(PathGeometry))
                {
                    PathGeometry pathgeo = geom as PathGeometry;

                    PathFigure figure = pathgeo.Figures[0];

                    ArcSegment path = (ArcSegment)figure.Segments[0];

                    Point start = figure.StartPoint;
                    Point end = path.Point;


                    double x6 = Math.Abs(end.X + start.X) / 2;
                    double radius = Math.Abs(x6 - start.X);
                    for (int c = 16; c > 1; c--)
                    {

                        if (geom == geo.Children[1])
                        {
                            points.Add(new Point(x6 + (-5) + radius * Math.Cos((11 * c * Math.PI) / 180), 5 + start.Y - radius * Math.Sin((11 * c * Math.PI) / 180)));
                        }
                        else // number 3 here
                        {
                            points.Add(new Point(x6 + (-5) - radius * Math.Cos((11 * (c) * Math.PI) / 180), -10 + start.Y + radius * Math.Sin((11 * (c) * Math.PI) / 180)));

                        }

                    }
                }

            }
            
            return points;
        }
Exemplo n.º 15
0
 public void CreateWorkOutline()
 {
     WorkOutline = new Windows.UI.Xaml.Shapes.Path();
     GeometryGroup gg = new GeometryGroup();
     Point origin = new Point(0, 0);
     EllipseGeometry eg = new EllipseGeometry();
     eg.Center = origin;
     eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.End;
     gg.Children.Add(eg);
     if ((_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start > 0)
     {
         eg = new EllipseGeometry();
         eg.Center = origin;
         eg.RadiusX = eg.RadiusY = (_viewmodel.CurrentPathData as LatticeData).Layout.ClipRange.Start;
         gg.Children.Add(eg);
     }
     WorkOutline.Data = gg;
     WorkOutline.StrokeThickness = 1 / ScaleFactor;
     WorkOutline.Stroke = new SolidColorBrush(Colors.Wheat);
     WorkOutline.StrokeDashArray = new DoubleCollection() { 5, 5 };
     WorkOutline.Name = "WorkOutline";
 }
Exemplo n.º 16
0
        public override Path CreateGrid()
        {
            Path _outline = base.CreateGrid();
            _outline.Name = "RADIAL_GRID";
            if (Dim1 == null || Dim2 == null) return _outline;
            GeometryGroup gg = new GeometryGroup();
            Point origin = new Point(0, 0);
            double inc = (_dim1.Inc <= 0) ? 5 : _dim1.Inc;
            for (double r = _dim1.Start; r <= _dim1.End; r += inc)
            {
                EllipseGeometry eg = new EllipseGeometry();
                eg.Center = origin;
                eg.RadiusX = eg.RadiusY = r;
                gg.Children.Add(eg);
            }

            inc = (_dim2.Inc <= 0) ? 5 : _dim2.Inc;

            for (double a = _dim2.Start; a <= _dim2.End; a += _dim2.Inc)
            {
                double aa = a * Math.PI / 180;
                double xs = _dim1.Start * Math.Cos(aa);
                double ys = _dim1.Start * Math.Sin(aa);
                Point start = new Point(xs, ys);
                double xe = _dim1.End * Math.Cos(aa);
                double ye = _dim1.End * Math.Sin(aa);
                Point end = new Point(xe, ye);
                LineGeometry lg = new LineGeometry();
                lg.StartPoint = start;
                lg.EndPoint = end;
                gg.Children.Add(lg);
            }
            _outline.Data = gg;
            return _outline;
        }
Exemplo n.º 17
0
        public static WMedia.Geometry ToWindows(this Geometry geometry)
        {
            WMedia.Geometry wGeometry = null;

            if (geometry is LineGeometry)
            {
                LineGeometry lineGeometry = geometry as LineGeometry;
                wGeometry = new WMedia.LineGeometry
                {
                    StartPoint = lineGeometry.StartPoint.ToWindows(),
                    EndPoint   = lineGeometry.EndPoint.ToWindows()
                };
            }
            else if (geometry is RectangleGeometry)
            {
                var rect = (geometry as RectangleGeometry).Rect;
                wGeometry = new WMedia.RectangleGeometry
                {
                    Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height)
                };
            }
            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry ellipseGeometry = geometry as EllipseGeometry;
                wGeometry = new WMedia.EllipseGeometry
                {
                    Center  = ellipseGeometry.Center.ToWindows(),
                    RadiusX = ellipseGeometry.RadiusX,
                    RadiusY = ellipseGeometry.RadiusY
                };
            }
            else if (geometry is GeometryGroup)
            {
                GeometryGroup geometryGroup = geometry as GeometryGroup;
                wGeometry = new WMedia.GeometryGroup
                {
                    FillRule = ConvertFillRule(geometryGroup.FillRule)
                };

                foreach (Geometry children in geometryGroup.Children)
                {
                    WMedia.Geometry winChild = children.ToWindows();
                    (wGeometry as WMedia.GeometryGroup).Children.Add(winChild);
                }
            }
            else if (geometry is PathGeometry)
            {
                PathGeometry pathGeometry = geometry as PathGeometry;

                WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry
                {
                    FillRule = ConvertFillRule(pathGeometry.FillRule)
                };

                foreach (PathFigure xamPathFigure in pathGeometry.Figures)
                {
                    WMedia.PathFigure wPathFigure = new WMedia.PathFigure
                    {
                        StartPoint = xamPathFigure.StartPoint.ToWindows(),
                        IsFilled   = xamPathFigure.IsFilled,
                        IsClosed   = xamPathFigure.IsClosed
                    };
                    wPathGeometry.Figures.Add(wPathFigure);

                    foreach (PathSegment pathSegment in xamPathFigure.Segments)
                    {
                        // LineSegment
                        if (pathSegment is LineSegment)
                        {
                            LineSegment lineSegment = pathSegment as LineSegment;

                            WMedia.LineSegment winSegment = new WMedia.LineSegment
                            {
                                Point = lineSegment.Point.ToWindows()
                            };

                            wPathFigure.Segments.Add(winSegment);
                        }

                        // PolylineSegment
                        if (pathSegment is PolyLineSegment)
                        {
                            PolyLineSegment        polyLineSegment = pathSegment as PolyLineSegment;
                            WMedia.PolyLineSegment wSegment        = new WMedia.PolyLineSegment();

                            foreach (var point in polyLineSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // BezierSegment
                        if (pathSegment is BezierSegment)
                        {
                            BezierSegment bezierSegment = pathSegment as BezierSegment;

                            WMedia.BezierSegment wSegment = new WMedia.BezierSegment
                            {
                                Point1 = bezierSegment.Point1.ToWindows(),
                                Point2 = bezierSegment.Point2.ToWindows(),
                                Point3 = bezierSegment.Point3.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyBezierSegment
                        else if (pathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment        polyBezierSegment = pathSegment as PolyBezierSegment;
                            WMedia.PolyBezierSegment wSegment          = new WMedia.PolyBezierSegment();

                            foreach (var point in polyBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }

                        // QuadraticBezierSegment
                        if (pathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment;

                            WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment
                            {
                                Point1 = quadraticBezierSegment.Point1.ToWindows(),
                                Point2 = quadraticBezierSegment.Point2.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // PolyQuadraticBezierSegment
                        else if (pathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment        polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment;
                            WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment();

                            foreach (var point in polyQuadraticBezierSegment.Points)
                            {
                                wSegment.Points.Add(point.ToWindows());
                            }

                            wPathFigure.Segments.Add(wSegment);
                        }
                        // ArcSegment
                        else if (pathSegment is ArcSegment)
                        {
                            ArcSegment arcSegment = pathSegment as ArcSegment;

                            WMedia.ArcSegment wSegment = new WMedia.ArcSegment
                            {
                                Size           = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                RotationAngle  = arcSegment.RotationAngle,
                                IsLargeArc     = arcSegment.IsLargeArc,
                                SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise,
                                Point          = arcSegment.Point.ToWindows()
                            };

                            wPathFigure.Segments.Add(wSegment);
                        }
                    }
                }

                wGeometry = wPathGeometry;
            }

            return(wGeometry);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Draws an interval for the meter
        /// </summary>
        /// <param name="interval">The MeterRangeInteraval which represents this range of the meter</param>
        /// <param name="tickLength">The length of the ticks for this range</param>
        /// <param name="group">The geometry group to add this to add this to</param>
        /// <param name="startAngle"></param>
        private void DrawInterval(MeterRangeInterval interval, double tickLength, GeometryGroup group, double startAngle = 0.0)
        {
            double startRad = interval.StartDegree*(Math.PI/180), endRad = interval.EndDegree*(Math.PI/180);
            double radianInterval = (endRad - startRad) * (interval.TickInterval / (interval.EndValue - interval.StartValue));
            var tickCount = (uint)((endRad - startRad)/ radianInterval);

            for (var i = 0; i <= tickCount; i++)
            {
                var pathGeometry = new PathGeometry();
                var figure = new PathFigure();

                // draw tick line
                double x1 = MeterRadius * Math.Sin(startAngle),
                       y1 = MeterRadius * Math.Cos(startAngle),
                       x2 = (MeterRadius + tickLength) * Math.Sin(startAngle),
                       y2 = (MeterRadius + tickLength) * Math.Cos(startAngle),
                       labelX = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Sin(startAngle),
                       labelY = (MeterRadius + LabelOffset + (tickLength / 2)) * Math.Cos(startAngle);

                figure.StartPoint = new Point(Radius + x1, Radius - y1);

                var line = new LineSegment
                {
                    Point = new Point(Radius + x2, Radius - y2)
                };

                MeterTickPoints?.Add(new TickPoint() {
                    // midway point in the tick - the point the tick crosses the meter circle
                    Point = new Point(Radius + (MeterRadius * Math.Sin(startAngle)), Radius - (MeterRadius * Math.Cos(startAngle))),
                    LabelPoint = new Point(Radius + labelX, Radius - labelY),
                    Value = i * interval.TickInterval + interval.StartValue
                });

                figure.Segments.Add(line);
                pathGeometry.Figures.Add(figure);
                group.Children.Add(pathGeometry);
                startAngle += radianInterval;
            }
        }
Exemplo n.º 19
0
 public static void Write(this StreamGeometryContext ctx, GeometryGroup geometryGroup)
 {
     geometryGroup.Children?.ForEach(ctx.Write);
 }
Exemplo n.º 20
0
        public object ConvertToNative(Geometry geometry)
        {
            winMedia.Geometry winGeometry = null;

            // Determine what type of geometry we're dealing with.
            if (geometry is LineGeometry)
            {
                LineGeometry xamGeometry = geometry as LineGeometry;
                winGeometry = new winMedia.LineGeometry
                {
                    StartPoint = ConvertPoint(xamGeometry.StartPoint),
                    EndPoint   = ConvertPoint(xamGeometry.EndPoint)
                };
            }

            else if (geometry is RectangleGeometry)
            {
                Rect rect = (geometry as RectangleGeometry).Rect;
                winGeometry = new winMedia.RectangleGeometry
                {
                    Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height)
                };
            }

            else if (geometry is EllipseGeometry)
            {
                EllipseGeometry xamGeometry = geometry as EllipseGeometry;
                winGeometry = new winMedia.EllipseGeometry
                {
                    Center  = ConvertPoint(xamGeometry.Center),
                    RadiusX = xamGeometry.RadiusX,
                    RadiusY = xamGeometry.RadiusY
                };
            }

            else if (geometry is GeometryGroup)
            {
                GeometryGroup xamGeometry = geometry as GeometryGroup;
                winGeometry = new winMedia.GeometryGroup
                {
                    FillRule = ConvertFillRule(xamGeometry.FillRule)
                };

                foreach (Geometry xamChild in xamGeometry.Children)
                {
                    winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry;
                    (winGeometry as winMedia.GeometryGroup).Children.Add(winChild);
                }
            }

            else if (geometry is PathGeometry)
            {
                PathGeometry xamPathGeometry = geometry as PathGeometry;

                winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry
                {
                    FillRule = ConvertFillRule(xamPathGeometry.FillRule)
                };

                foreach (PathFigure xamPathFigure in xamPathGeometry.Figures)
                {
                    winMedia.PathFigure winPathFigure = new winMedia.PathFigure
                    {
                        StartPoint = ConvertPoint(xamPathFigure.StartPoint),
                        IsFilled   = xamPathFigure.IsFilled,
                        IsClosed   = xamPathFigure.IsClosed
                    };
                    winPathGeometry.Figures.Add(winPathFigure);

                    foreach (PathSegment xamPathSegment in xamPathFigure.Segments)
                    {
                        // LineSegment
                        if (xamPathSegment is LineSegment)
                        {
                            LineSegment xamSegment = xamPathSegment as LineSegment;

                            winMedia.LineSegment winSegment = new winMedia.LineSegment
                            {
                                Point = ConvertPoint(xamSegment.Point)
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolylineSegment
                        if (xamPathSegment is PolyLineSegment)
                        {
                            PolyLineSegment          xamSegment = xamPathSegment as PolyLineSegment;
                            winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // BezierSegment
                        if (xamPathSegment is BezierSegment)
                        {
                            BezierSegment xamSegment = xamPathSegment as BezierSegment;

                            winMedia.BezierSegment winSegment = new winMedia.BezierSegment
                            {
                                Point1 = ConvertPoint(xamSegment.Point1),
                                Point2 = ConvertPoint(xamSegment.Point2),
                                Point3 = ConvertPoint(xamSegment.Point3)
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolyBezierSegment
                        else if (xamPathSegment is PolyBezierSegment)
                        {
                            PolyBezierSegment          xamSegment = xamPathSegment as PolyBezierSegment;
                            winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // QuadraticBezierSegment
                        if (xamPathSegment is QuadraticBezierSegment)
                        {
                            QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment;

                            winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment
                            {
                                Point1 = ConvertPoint(xamSegment.Point1),
                                Point2 = ConvertPoint(xamSegment.Point2),
                            };

                            winPathFigure.Segments.Add(winSegment);
                        }

                        // PolyQuadraticBezierSegment
                        else if (xamPathSegment is PolyQuadraticBezierSegment)
                        {
                            PolyQuadraticBezierSegment          xamSegment = xamPathSegment as PolyQuadraticBezierSegment;
                            winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment();

                            foreach (Point point in xamSegment.Points)
                            {
                                winSegment.Points.Add(ConvertPoint(point));
                            }

                            winPathFigure.Segments.Add(winSegment);
                        }


                        // ArcSegment
                        else if (xamPathSegment is ArcSegment)
                        {
                            ArcSegment          xamSegment = xamPathSegment as ArcSegment;
                            winMedia.ArcSegment winSegment = new winMedia.ArcSegment();

                            winSegment.Size           = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height);
                            winSegment.RotationAngle  = xamSegment.RotationAngle;
                            winSegment.IsLargeArc     = xamSegment.IsLargeArc;
                            winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise;
                            winSegment.Point          = ConvertPoint(xamSegment.Point);

                            winPathFigure.Segments.Add(winSegment);
                        }
                    }
                }

                winGeometry = winPathGeometry;
            }

            // Set transform.
            if (geometry.Transform != null)
            {
                winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject();
            }

            return(winGeometry);
        }
Exemplo n.º 21
0
 /// <summary>
 /// Draws the scale ticks, with an invisible circle with r=MeterRadius bisecting each tick
 /// </summary>
 /// <param name="tickLength">The length of each tick</param>
 /// <param name="group">The geometry group to add each tick to</param>
 /// <param name="startAngle">The angle to start drawing ticks at, relative to the negative Y axis</param>
 private void DrawScale(double tickLength, GeometryGroup group, double startAngle = 0.0)
 {
     MeterTickPoints?.Clear();
     if (Intervals == null)
     {
         return;
     }
     foreach (var interval in Intervals)
     {
         DrawInterval(interval, tickLength, group, startAngle);
         startAngle += (interval.EndDegree - interval.StartDegree)*(Math.PI/180);
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// The draw ellipses.
        /// </summary>
        /// <param name="rectangles">
        /// The rectangles.
        /// </param>
        /// <param name="fill">
        /// The fill.
        /// </param>
        /// <param name="stroke">
        /// The stroke.
        /// </param>
        /// <param name="thickness">
        /// The thickness.
        /// </param>
        public void DrawEllipses(IList<OxyRect> rectangles, OxyColor fill, OxyColor stroke, double thickness)
        {
            var path = new Path();
            this.SetStroke(path, stroke, thickness);
            if (fill != null)
            {
                path.Fill = this.GetCachedBrush(fill);
            }

            var gg = new GeometryGroup { FillRule = FillRule.Nonzero };
            foreach (OxyRect rect in rectangles)
            {
                gg.Children.Add(
                    new EllipseGeometry
                        {
                            Center = new Point(rect.Left + (rect.Width / 2), rect.Top + (rect.Height / 2)),
                            RadiusX = rect.Width / 2,
                            RadiusY = rect.Height / 2
                        });
            }

            path.Data = gg;
            this.Add(path);
        }
Exemplo n.º 23
0
        private GeometryGroup GetBackgroudGeometry(IList<Point> points)
        {
            var path = new PathFigure { StartPoint = points[0] };
            path.Segments.Add(new LineSegment() { Point = points[1] });
            path.Segments.Add(GetCornerSegment(points[1], points[2], CellRadius, CellSize));
            path.Segments.Add(new LineSegment() { Point = points[3] });
            path.Segments.Add(GetCornerSegment(points[3], points[4], CellRadius, CellSize));
            path.Segments.Add(new LineSegment() { Point = points[5] });
            path.Segments.Add(GetCornerSegment(points[5], points[6], CellRadius, CellSize));
            path.Segments.Add(new LineSegment() { Point = points[7] });
            path.Segments.Add(GetCornerSegment(points[7], points[0], CellRadius, CellSize));
            path.IsClosed = true;

            var group = new GeometryGroup();
            var geom = new PathGeometry();
            geom.Figures.Add(path);
            group.Children.Add(geom);

            return group;
        }
        private void DrawEWNS_map()
        {
            if (this.Longitudes.Count() < 4 || this.Latitudes.Count() < 4)
            {
                return;
            }

            Size size = this.m_renderSize;// this.grdHostGrid.RenderSize;
            float[] ews = this.m_longitudes;
            float[] nss = this.m_latitudes;

            GeometryGroup rootGroup = new GeometryGroup();
            //创建起点和终点
            float startX = ews.First();
            float startY = nss.First();
            rootGroup.Children.Add(new EllipseGeometry() { Center = new Point(startX, startY), RadiusX = 10, RadiusY = 10 });
            rootGroup.Children.Add(new EllipseGeometry() { Center = new Point(startX, startY), RadiusX = 8, RadiusY = 8 });

            PathGeometry pg = new PathGeometry() { Figures = new PathFigureCollection() };
            PathFigure figure = new PathFigure() { IsClosed = false, StartPoint = new Point(startX, startY) };
            figure.IsFilled = false;


            PolyBezierSegment segments = this.CreateSegments(ews, nss);

            figure.Segments.Add(segments);
            pg.Figures.Add(figure);
            rootGroup.Children.Add(pg);
            this.grdHostGrid.Data = rootGroup;
        }
Exemplo n.º 25
0
 public CompositeFormattable(GeometryGroup owner)
 {
     _owner = owner;
 }