コード例 #1
0
        public static void DrawGeometry(StreamGeometryContext ctx, System.Windows.Media.Geometry geo)
        {
            var pathGeometry = geo as PathGeometry ?? PathGeometry.CreateFromGeometry(geo);

            foreach (var figure in pathGeometry.Figures)
            {
                DrawFigure(ctx, figure);
            }
        }
コード例 #2
0
        /// <summary>
        /// http://stackoverflow.com/questions/2979834/how-to-draw-a-full-ellipse-in-a-streamgeometry-in-wpf
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="geo"></param>
        public static void DrawGeometry(this StreamGeometryContext ctx, Geometry geo)
        {
            var pathGeometry = geo as PathGeometry ?? PathGeometry.CreateFromGeometry(geo);

            foreach (var figure in pathGeometry.Figures)
            {
                ctx.DrawFigure(figure);
            }
        }
コード例 #3
0
        /// <summary>
        /// 路径走向
        /// </summary>
        /// <param name="orientation">0正向 1反向</param>
        /// <param name="data">路径数据</param>
        private void MatrixStory(int orientation, string data, int durationTime)
        {
            Border border = new Border();

            border.Width      = 10;
            border.Height     = 10;
            border.Visibility = Visibility.Collapsed;
            if (orientation == 0)
            {
                border.Background = new SolidColorBrush(Colors.Blue);
            }
            else
            {
                border.Background = new SolidColorBrush(Colors.Green);
                data = ConvertReverseData(data);
            }

            this.MyCanvas.Children.Add(border);
            Canvas.SetLeft(border, -border.Width / 2);
            Canvas.SetTop(border, -border.Height / 2);
            border.RenderTransformOrigin = new System.Windows.Point(0.5, 0.5);

            MatrixTransform matrix = new MatrixTransform();
            TransformGroup  groups = new TransformGroup();

            groups.Children.Add(matrix);
            border.RenderTransform = groups;
            //NameScope.SetNameScope(this, new NameScope());
            string registname = "matrix" + Guid.NewGuid().ToString().Replace("-", "");

            this.RegisterName(registname, matrix);
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            matrixAnimation.PathGeometry          = PathGeometry.CreateFromGeometry(Geometry.Parse(data));
            matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(durationTime));
            matrixAnimation.DoesRotateWithTangent = true;//旋转
            //matrixAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard story = new Storyboard();

            story.Children.Add(matrixAnimation);
            Storyboard.SetTargetName(matrixAnimation, registname);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            #region 控制显示与隐藏
            ObjectAnimationUsingKeyFrames ObjectAnimation = new ObjectAnimationUsingKeyFrames();
            ObjectAnimation.Duration = matrixAnimation.Duration;
            DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromMilliseconds(1));
            ObjectAnimation.KeyFrames.Add(kf1);
            story.Children.Add(ObjectAnimation);
            //Storyboard.SetTargetName(border, border.Name);
            Storyboard.SetTargetProperty(ObjectAnimation, new PropertyPath(UIElement.VisibilityProperty));
            #endregion
            story.FillBehavior = FillBehavior.Stop;
            story.Begin(border, true);
        }
コード例 #4
0
        private PathFigure GetPathFigureFromString(string pathData)
        {
            if (string.IsNullOrWhiteSpace(pathData))
            {
                return(null);
            }
            var        geometry = PathGeometry.CreateFromGeometry(PathGeometry.Parse(pathData));
            PathFigure figure   = geometry.Figures.FirstOrDefault();

            return(figure);
        }
コード例 #5
0
        private void drawRoundedRectange()
        {
            var geom = new RectangleGeometry();

            geom.Rect    = new Rect(0, 0, 300 - 30 * Width, 60);
            geom.RadiusX = 30;
            geom.RadiusY = 30;
            var pathGeometry = PathGeometry.CreateFromGeometry(geom);

            PathData = pathGeometry.ToString().Replace(',', '.').Replace(';', ',');
        }
コード例 #6
0
        private void drawEllipse()
        {
            var geom = new EllipseGeometry();

            geom.Center  = new Point((300 - 30 * Width) / 2, -30);
            geom.RadiusX = (300 - 30 * Width) / 2;
            geom.RadiusY = 30;
            var pathGeometry = PathGeometry.CreateFromGeometry(geom);

            PathData = pathGeometry.ToString().Replace(',', '.').Replace(';', ',');
        }
コード例 #7
0
        // test streamgeometry
        StreamGeometry CreateStreamGeometryFromMsaglCurve(ICurve iCurve)
        {
            var geometry   = new StreamGeometry();
            var pathFigure = new PathFigure
            {
                IsClosed   = true,
                IsFilled   = true,
                StartPoint = Common.WpfPoint(iCurve.Start)
            };

            var curve = iCurve as Curve;

            if (curve != null)
            {
                AddCurve(pathFigure, curve);
            }
            else
            {
                var rect = iCurve as RoundedRect;
                if (rect != null)
                {
                    AddCurve(pathFigure, rect.Curve);
                }
                else
                {
                    var ellipse = iCurve as Ellipse;
                    if (ellipse != null)
                    {
                        var ellGeom = new EllipseGeometry(Common.WpfPoint(ellipse.Center), ellipse.AxisA.Length,
                                                          ellipse.AxisB.Length);
                        pathFigure = PathGeometry.CreateFromGeometry(ellGeom).Figures[0];
                    }
                    var poly = iCurve as Polyline;
                    if (poly != null)
                    {
                        var p = poly.StartPoint.Next;
                        do
                        {
                            pathFigure.Segments.Add(new System.Windows.Media.LineSegment(Common.WpfPoint(p.Point),
                                                                                         true));

                            p = p.NextOnPolyline;
                        } while (p != poly.StartPoint);
                    }
                }
            }

            using (var ctx = geometry.Open())
            {
                DrawFigure(ctx, pathFigure);
            }
            geometry.Freeze();
            return(geometry);
        }
コード例 #8
0
        private string GenerateDrawingCommands()
        {
            var instrumentState = GetInstrumentState();
            var drawingGroup    = new DrawingGroup();
            var drawingContext  = drawingGroup.Append();

            drawingContext.PushTransform(new RotateTransform(_config.RotationDegrees, 2047, 2047));
            _drawingCommandRenderer.Render(drawingContext, instrumentState);
            drawingContext.Close();
            return(ShortenFloats(PathGeometry.CreateFromGeometry(drawingGroup.GetGeometry()).ToString()));
        }
コード例 #9
0
        private string GenerateDrawingCommands()
        {
            var instrumentState = GetInstrumentState();
            var drawingGroup    = new DrawingGroup();
            var drawingContext  = drawingGroup.Append();

            _drawingCommandRenderer.Render(drawingContext, instrumentState, USE_VECTOR_FONT);

            drawingContext.Close();
            return(PathGeometry.CreateFromGeometry(drawingGroup.GetGeometry()).ToString());
        }
コード例 #10
0
        StreamGeometry GetNodeDotEllipseStreamGeometry(double nodeDotWidth)
        {
            var geometry = new StreamGeometry();

            using (var ctx = geometry.Open()) {
                var ellipse = GetNodeDotEllipseGeometry(nodeDotWidth);
                var figure  = PathGeometry.CreateFromGeometry(ellipse).Figures[0];
                DrawFigure(ctx, figure);
            }
            geometry.Freeze();
            return(geometry);
        }
コード例 #11
0
        // Token: 0x06002DF6 RID: 11766 RVA: 0x000CE904 File Offset: 0x000CCB04
        public void ProcessPath(Path path, Matrix transform)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            Geometry data  = path.Data;
            bool     flag  = path.Fill != null;
            bool     flag2 = path.Stroke != null;

            if (data == null || (!flag && !flag2))
            {
                return;
            }
            Transform renderTransform = path.RenderTransform;

            if (renderTransform != null)
            {
                transform *= renderTransform.Value;
            }
            if (flag && this._ProcessFilledRect(transform, data.Bounds))
            {
                flag = false;
                if (!flag2)
                {
                    return;
                }
            }
            StreamGeometry streamGeometry = data as StreamGeometry;

            if (streamGeometry != null)
            {
                if (this._geometryWalker == null)
                {
                    this._geometryWalker = new GeometryWalker(this);
                }
                this._geometryWalker.FindLines(streamGeometry, flag2, flag, transform);
                return;
            }
            PathGeometry pathGeometry = PathGeometry.CreateFromGeometry(data);

            if (pathGeometry != null)
            {
                if (flag)
                {
                    this._ProcessSolidPath(transform, pathGeometry);
                }
                if (flag2)
                {
                    this._ProcessOutlinePath(transform, pathGeometry);
                }
            }
        }
コード例 #12
0
ファイル: MovementControl.cs プロジェクト: NemoImCap/WPF_Labs
        //public event PropertyChangedEventHandler PropertyChanged;
        #endregion

        public void Init(TimeSpan duration)
        {
            images    = new BitmapImage[10];
            images[0] = new BitmapImage(new Uri("/Images/hourse0.png", UriKind.Relative));
            images[1] = new BitmapImage(new Uri("/Images/hourse1.png", UriKind.Relative));
            images[2] = new BitmapImage(new Uri("/Images/hourse2.png", UriKind.Relative));
            images[3] = new BitmapImage(new Uri("/Images/hourse3.png", UriKind.Relative));
            images[4] = new BitmapImage(new Uri("/Images/hourse4.png", UriKind.Relative));
            images[5] = new BitmapImage(new Uri("/Images/hourse5.png", UriKind.Relative));
            images[6] = new BitmapImage(new Uri("/Images/hourse6.png", UriKind.Relative));
            images[7] = new BitmapImage(new Uri("/Images/hourse7.png", UriKind.Relative));
            images[8] = new BitmapImage(new Uri("/Images/hourse8.png", UriKind.Relative));
            images[9] = new BitmapImage(new Uri("/Images/hourse9.png", UriKind.Relative));

            dT.Tick += new EventHandler(dT_Tick);

            time          = TimeSpan.FromSeconds(duration.Seconds / Speed);
            dT.Interval   = new TimeSpan(0, 0, 0, 0, time.Seconds);
            sb.Completed += Sb_Completed;

            DoubleAnimationUsingPath animation  = new DoubleAnimationUsingPath();
            DoubleAnimationUsingPath animation2 = new DoubleAnimationUsingPath();

            ////Geometry.Parse("M 100,200 C 100,25 400,350 400,175 H 280")
            animation = new DoubleAnimationUsingPath
            {
                Duration       = time,
                RepeatBehavior = RepeatBehavior.Forever,
                PathGeometry   = PathGeometry.CreateFromGeometry(NewGeometry)
            };

            animation2 = new DoubleAnimationUsingPath
            {
                Duration       = time,
                RepeatBehavior = RepeatBehavior.Forever,
                PathGeometry   = PathGeometry.CreateFromGeometry(NewGeometry)
            };

            animation.Source  = PathAnimationSource.X;
            animation2.Source = PathAnimationSource.Y;

            //a.Duration = TimeSpan.FromSeconds(3);
            Storyboard.SetTarget(animation, this);
            Storyboard.SetTarget(animation2, this);



            Storyboard.SetTargetProperty(animation, new PropertyPath(XProperty));
            Storyboard.SetTargetProperty(animation2, new PropertyPath(YProperty));

            sb.Children.Add(animation);
            sb.Children.Add(animation2);
        }
コード例 #13
0
        public static PathGeometry AsPathGeometry(this Geometry original)
        {
            if (original == null)
            {
                return(null);
            }

            if (!(original is PathGeometry geometry))
            {
                return(PathGeometry.CreateFromGeometry(original));
            }
            return(geometry);
        }
コード例 #14
0
        private static void OnDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var ic = d as IconControl;

            if (ic != null && e.NewValue != null)
            {
                try {
                    ic.DataGeometry = PathGeometry.CreateFromGeometry(Geometry.Parse(e.NewValue.ToString()));
                } catch (Exception error) {
                    Console.WriteLine(error);
                }
            }
        }
コード例 #15
0
        /// <summary>
        ///     获取路径总长度
        /// </summary>
        /// <param name="geometry"></param>
        /// <returns></returns>
        public static double GetTotalLength(this Geometry geometry)
        {
            if (geometry == null)
            {
                return(0);
            }

            var pathGeometry = PathGeometry.CreateFromGeometry(geometry);

            pathGeometry.GetPointAtFractionLength(1e-4, out var point, out _);
            var length = (pathGeometry.Figures[0].StartPoint - point).Length * 1e+4;

            return(length);
        }
コード例 #16
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            string data    = this.path0.Data.ToString();
            var    result  = ConvertReverseData(data);
            Path   newpath = new Path();

            newpath.Data = PathGeometry.CreateFromGeometry(Geometry.Parse(result));
            newpath.HorizontalAlignment = HorizontalAlignment.Center;
            newpath.VerticalAlignment   = VerticalAlignment.Center;
            newpath.Stretch             = this.path0.Stretch;
            newpath.Stroke          = new SolidColorBrush(Colors.Red);
            newpath.StrokeThickness = 2;
            newpath.Width           = this.path0.Width;
            newpath.Height          = this.path0.Height;
            canvas.Children.Add(newpath);
        }
コード例 #17
0
 protected override void OnTextPropertyChanged(DependencyPropertyChangedEventArgs args)
 {
     if (string.IsNullOrEmpty(base.Text))
     {
         this.flattenedTextPathGeometry = null;
     }
     else
     {
         FormattedText formattedText = new FormattedText(base.Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, this.typeface, 100.0, base.Foreground);
         this.textLength = formattedText.Width;
         this.baseline   = formattedText.Baseline;
         Geometry geometry = formattedText.BuildGeometry(default(Point));
         this.flattenedTextPathGeometry = PathGeometry.CreateFromGeometry(geometry).GetFlattenedPathGeometry();
         this.warpedTextPathGeometry    = this.flattenedTextPathGeometry.CloneCurrentValue();
         this.GenerateWarpedGeometry();
     }
 }
コード例 #18
0
        private string GenerateDrawingCommands()
        {
            var instrumentState = GetInstrumentState();
            var drawingGroup    = new DrawingGroup();
            var drawingContext  = drawingGroup.Append();

            if (_config.TestPattern != 0)
            {
                new CalibrationTestPattern1RWRRenderer(VIEWBOX_WIDTH, VIEWBOX_HEIGHT).Render(drawingContext);
            }
            else
            {
                _drawingCommandRenderer.Render(drawingContext, instrumentState, USE_VECTOR_FONT);
            }
            drawingContext.Close();
            return(PathGeometry.CreateFromGeometry(drawingGroup.GetGeometry()).ToString());
        }
コード例 #19
0
        private void WriteImage(Path visual, ImageBrush brush)
        {
            System.Windows.Media.Imaging.BitmapFrame frame = brush.ImageSource as System.Windows.Media.Imaging.BitmapFrame;


            PDFImage img = PDFDocument.CreateObject <PDFImage>();

            string key = "R" + Page.Resources.ID + "I" + img.ID;

            Page.Resources.XObject[key] = img;

            img.ColorSpace       = "DeviceRGB";
            img.BitsPerComponent = 8;

            System.Windows.Media.Imaging.JpegBitmapEncoder enc = new JpegBitmapEncoder();


            /*TransformedBitmap tb = new TransformedBitmap(frame, new ScaleTransform {
             *      ScaleX = brush.Viewport.Width / frame.Width ,
             *      ScaleY = brush.Viewport.Height / frame.Height
             * });*/

            var tb = frame;

            img.Width  = tb.PixelWidth;
            img.Height = tb.PixelHeight;

            enc.Frames.Add(BitmapFrame.Create(tb));
            enc.QualityLevel = 100;
            enc.Save(img.Stream);

            Page.ContentStream.WriteLine("q");

            PathGeometry pg = PathGeometry.CreateFromGeometry(visual.Data);
            Point        p  = pg.Figures.First().StartPoint;

            p = TransformPoint(visual, p);



            Page.ContentStream.WriteLine("{0} 0 0 {1} {2} {3} cm", brush.Viewport.Width, brush.Viewport.Height, p.X, p.Y - brush.Viewport.Height);

            Page.ContentStream.WriteLine("/" + key + " Do");
            Page.ContentStream.WriteLine("Q");
        }
コード例 #20
0
        private void AddGeometry(Geometry geometry)
        {
            var native = _native;

            if (native == null)
            {
                _native = geometry;
            }
            else
            {
                if (!(native is PathGeometry pathGeometry))
                {
                    pathGeometry = PathGeometry.CreateFromGeometry(native);
                    _native      = pathGeometry;
                }
                pathGeometry.AddGeometry(geometry);
            }
        }
コード例 #21
0
ファイル: SevenSegments.cs プロジェクト: fguiet/kQuatreWPF
        private PathGeometry CreateEllipseGeometry(Point centerPoint,
                                                   PathGeometry pathGeometry,
                                                   double diameter)
        {
            EllipseGeometry ellipseGeometry;
            SkewTransform   transform;

            ellipseGeometry         = new EllipseGeometry();
            ellipseGeometry.Center  = centerPoint;
            ellipseGeometry.RadiusX = diameter;
            ellipseGeometry.RadiusY = diameter;

            pathGeometry = PathGeometry.CreateFromGeometry(ellipseGeometry);

            transform = new SkewTransform(-TiltAngle,
                                          0, centerPoint.X, centerPoint.Y);
            pathGeometry.Transform = transform;
            return(pathGeometry);
        }
コード例 #22
0
        private void OnStrokeCollected(SenderAwareEventArgs e)
        {
            var container = e.Sender as FrameworkElement;
            var eventArgs = e.OriginalEventArgs as StrokeEventArgs;

            Debug.Assert(eventArgs != null, "event args need to be != null");

            var pg = PathGeometry.CreateFromGeometry(eventArgs.Stroke.GetGeometry());

            var elementsInGeometry = HitTestHelper.GetElementsInGeometry <PipeView>(pg, container);

            var linksToDelete = elementsInGeometry.Select(view => view.DataContext).OfType <PipeViewModel>().ToArray();

            // As user if pipes should be deleted.
            if (linksToDelete.Any())
            {
                var deletePipes = MessageBox.Show("Do you want to delete pipes?", "Delete Pipes", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (deletePipes != MessageBoxResult.Yes)
                {
                    return;
                }
            }

            // TODO: add method to model, which is capable of deleting more than one link safely
            foreach (var vm in linksToDelete)
            {
                var source = vm.Source as BaseProcessor;
                var target = vm.Target as BaseProcessor;

                if (source != null)
                {
                    source.Targets.Remove(target);
                }

                if (target != null)
                {
                    target.Sources.Remove(source);
                }

                Pipes.Remove(vm);
            }
        }
コード例 #23
0
        private Path createPath(RoadInfoModel roadInfoModel)
        {
            Path path = new Path();

            path.Name    = roadInfoModel.RoadName;
            path.ToolTip = $"路段:{roadInfoModel.RoadName}\r\n状态:{ roadInfoModel.RoadStatus}\r\n开始地标:{ roadInfoModel.StartMarkPointInfoName}\r\n结束地标:{roadInfoModel.EndMarkPointInfoName}";
            //path.Data = PathGeometry.CreateFromGeometry(Geometry.Parse("M1,1 L230.67997,1 230.67997,70.67997 140.67998,70.67997 140.67998,135.68002 300.68,85.67999 C300.68,85.67999 300.68,140.68005 300.68,80.68002 300.68,20.679984 340.68002,40.679985 340.68002,40.679985 L383.18005,83.18003 383.18005,115.68004 325.68006,115.68")); ;
            path.Data = PathGeometry.CreateFromGeometry(Geometry.Parse(string.Format("M {0} {1} {2} {3}",
                                                                                     markPointList.First(a => a.Id == roadInfoModel.StartMarkPointInfo_Id).X *ratioX - offsetX, markPointList.First(a => a.Id == roadInfoModel.StartMarkPointInfo_Id).Y *ratioY - offsetY,
                                                                                     markPointList.First(a => a.Id == roadInfoModel.EndMarkPointInfo_Id).X *ratioX - offsetX, markPointList.First(a => a.Id == roadInfoModel.EndMarkPointInfo_Id).Y *ratioY - offsetY)));

            System.Diagnostics.Debug.Print($"名称{path.Name },坐标点{path.Data.ToString()}");

            //路线的状态颜色
            path.Stroke = Utility.Windows.ResourceHelper.FindResource("AgvRoadStatusBrush" + roadInfoModel.RoadStatus) as Brush;

            path.Stretch         = Stretch.None;
            path.StrokeLineJoin  = PenLineJoin.Round;
            path.StrokeThickness = 4;
            return(path);
        }
コード例 #24
0
        void ActionClicked(object sender, RoutedEventArgs e)
        {
            if (ActionSelected != null)
            {
                ActionSelected(((RadioButton)sender).Tag as BaseAction);
            }
            helperObject.RenderOpen().Close();
            if (!(((RadioButton)sender).Tag as BaseAction).IsHelperObjectNeded())
            {
                return;
            }

            if (helperTool != null)
            {
                helperTool.Deactivate();
                //helperTool.ObjectSelected -= helperSelected;
                helperTool = null;
            }



            if ((((RadioButton)sender).Tag as BaseAction).HelperObject == null)
            {
                //helperTool = new Tools.HelperSelectorTool((FrameworkElement)VisualTreeHelper.GetParent(AdornedElement), AdornedElement);
                //helperTool.Activate();
                //  helperTool.ObjectSelected += helperSelected;
            }
            else
            {
                if (!((((RadioButton)sender).Tag as BaseAction).HelperObject is PathGeometry))
                {
                    (((RadioButton)sender).Tag as BaseAction).HelperObject = PathGeometry.CreateFromGeometry((((RadioButton)sender).Tag as BaseAction).HelperObject);
                }
                DrawingContext c = helperObject.RenderOpen();
                c.DrawGeometry(null, new Pen(Brushes.Black, 1), (((RadioButton)sender).Tag as BaseAction).HelperObject);

                c.Close();
                InvalidateVisual();
            }
        }
コード例 #25
0
ファイル: Xaml2Emf.cs プロジェクト: ru-petrovi4/Ssz.Utils
        private static void InternalMakeDrawingSerializable(Drawing drawing, GeometryValueSerializer gvs)
        {
            var dg = drawing as DrawingGroup;

            if (dg is not null)
            {
                for (int i = 0; i < dg.Children.Count; ++i)
                {
                    InternalMakeDrawingSerializable(dg.Children[i], gvs);
                }
            }
            else
            {
                var gd = drawing as GeometryDrawing;
                if (gd is not null)
                {
                    var sg = gd.Geometry as StreamGeometry;
                    if (sg is not null && !gvs.CanConvertToString(sg, null))
                    {
                        gd.Geometry = PathGeometry.CreateFromGeometry(sg);
                    }
                }
            }
        }
コード例 #26
0
        private void Write(Path visual)
        {
            PathGeometry pg = PathGeometry.CreateFromGeometry(visual.Data);

            Uri url = FixedPage.GetNavigateUri(visual as UIElement);

            if (url != null)
            {
                var pa     = Page.Annotations;
                var bounds = pg.Bounds;

                Point topLeft     = TransformPoint(visual, bounds.TopLeft);
                Point bottomRight = TransformPoint(visual, bounds.BottomRight);

                pa.AddLink(url, new PDFRect {
                    Left = (int)topLeft.X, Top = (int)topLeft.Y, Width = (int)bottomRight.X, Height = (int)bottomRight.Y
                });
                return;
            }


            if (visual.Fill is ImageBrush)
            {
                WriteImage(visual, visual.Fill as ImageBrush);
                return;
            }

            if (visual.Stroke != null)
            {
                WriteStroke(visual.Stroke);
            }

            if (visual.Fill != null)
            {
                WriteFill(visual.Fill);
            }


            foreach (var item in pg.Figures)
            {
                var start = TransformPoint(visual, item.StartPoint);

                Page.ContentStream.WriteLine("{0} {1} m", start.X, start.Y);

                foreach (var s in item.Segments)
                {
                    WriteSegment(s);
                }

                if (item.IsClosed)
                {
                    Page.ContentStream.WriteLine("{0} {1} l", start.X, start.Y);
                }

                string op = "S";
                if (visual.Stroke != null && visual.Fill != null)
                {
                    op = "B";
                }
                else
                {
                    if (visual.Stroke != null)
                    {
                        op = "S";
                    }
                    if (visual.Fill != null)
                    {
                        op = "f";
                    }
                }

                Page.ContentStream.WriteLine(op);
            }
        }
コード例 #27
0
        //Border border = new Border();
        /// <summary>
        ///
        /// </summary>
        /// <param name="orientation">0正向 1反向</param>
        /// <param name="data">路径数据</param>
        private void MatrixStory(UserControls.AgvCar agvCar, PathModel pathModel)
        {
            //border.Width = 10;
            //border.Height = 10;
            //border.Visibility = Visibility.Visible;
            //if (orientation == 0)
            //{
            //    border.Background = new SolidColorBrush(Colors.Blue);
            //}
            //else
            //{
            //    border.Background = new SolidColorBrush(Colors.Green);
            //}
            //if (!this.MainContent.Children.Contains(agvCar))
            //{
            //    this.MainContent.Children.Add(agvCar);

            //}
            Canvas.SetLeft(agvCar, -agvCar.Width / 2);
            Canvas.SetTop(agvCar, -agvCar.Height / 2);
            agvCar.RenderTransformOrigin = new Point(0.5, 0.5);

            MatrixTransform matrix = new MatrixTransform();
            TransformGroup  groups = new TransformGroup();

            groups.Children.Add(matrix);
            agvCar.RenderTransform = groups;
            //NameScope.SetNameScope(this, new NameScope());
            string registname = "matrix" + Guid.NewGuid().ToString().Replace("-", "");

            agvCar.RegisterName(registname, matrix);
            MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

            //matrixAnimation.PathGeometry = PathGeometry.CreateFromGeometry(Geometry.Parse(    (  mainContent.FindChild(path.Key.ToString() + path.Value.ToString()) as Path )  .Data       ));
            matrixAnimation.PathGeometry          = PathGeometry.CreateFromGeometry(mainContent.FindChild <Path>(pathModel.Name).Data);
            matrixAnimation.Duration              = new Duration(TimeSpan.FromSeconds(10));
            matrixAnimation.DoesRotateWithTangent = false;//旋转
            matrixAnimation.AccelerationRatio     = 0.4;
            matrixAnimation.DecelerationRatio     = 0.4;
            //matrixAnimation.FillBehavior
            //matrixAnimation.FillBehavior = FillBehavior.Stop;
            Storyboard story = new Storyboard();

            story.Children.Add(matrixAnimation);
            Storyboard.SetTargetName(matrixAnimation, registname);
            Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));

            //#region 控制显示与隐藏
            //ObjectAnimationUsingKeyFrames ObjectAnimation = new ObjectAnimationUsingKeyFrames();
            //ObjectAnimation.Duration = matrixAnimation.Duration;
            //DiscreteObjectKeyFrame kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromMilliseconds(1));
            //ObjectAnimation.KeyFrames.Add(kf1);
            //story.Children.Add(ObjectAnimation);
            ////Storyboard.SetTargetName(border, border.Name);
            //Storyboard.SetTargetProperty(ObjectAnimation, new PropertyPath(UIElement.VisibilityProperty));
            //#endregion

            story.FillBehavior = FillBehavior.HoldEnd;
            agvCar.Tag         = story;

            story.Begin(agvCar, true);
        }
コード例 #28
0
        public void ProcessPath(Path path, Matrix transform)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Geometry geom   = path.Data;
            bool     fill   = path.Fill != null;
            bool     stroke = path.Stroke != null;

            if ((geom == null) || (!fill && !stroke))
            {
                return;
            }

            Transform transPath = path.RenderTransform;

            if (transPath != null)
            {
                transform *= transPath.Value;
            }

            // When filling, we may be able to determine from bounding box only
            if (fill && _ProcessFilledRect(transform, geom.Bounds))
            {
                fill = false;

                if (!stroke)
                {
                    return;
                }
            }

            StreamGeometry sgeo = geom as StreamGeometry;

            // Avoiding convert to PathGeometry if it's StreamGeometry, which can be walked

            if (sgeo != null)
            {
                if (_geometryWalker == null)
                {
                    _geometryWalker = new GeometryWalker(this);
                }

                _geometryWalker.FindLines(sgeo, stroke, fill, transform);
            }
            else
            {
                PathGeometry pathGeom = PathGeometry.CreateFromGeometry(geom);

                if (pathGeom != null)
                {
                    if (fill)
                    {
                        _ProcessSolidPath(transform, pathGeom);
                    }

                    if (stroke)
                    {
                        _ProcessOutlinePath(transform, pathGeom);
                    }
                }
            }
        }
コード例 #29
0
        /// <summary>
        ///  Converts a flat path to a <see cref="IGeometry"/>.
        /// </summary>
        ///  <param name="wpfGeometry">The geometry to convert</param>
        /// <returns>A Geometry representing the path</returns>
        public IGeometry Read(WpfGeometry wpfGeometry)
        {
            var pathGeometry = PathGeometry.CreateFromGeometry(wpfGeometry);

            /*
             * .Item1 ... Closed
             * .Item2 ... Filled
             * .Item3 ... List<Coordinate[]>
             */
            var pathPtSeq = ToCoordinates(pathGeometry);

            var geoms = new List <IGeometry>();

            var seqIndex = 0;

            while (seqIndex < pathPtSeq.Count)
            {
                // assume next seq is shell
                // TODO: test this
                var pts = pathPtSeq[seqIndex];
                if (pts.Item3.Length == 1)
                {
                    geoms.Add(_geometryFactory.CreatePoint(pts.Item3[0]));
                    seqIndex++;
                }
                else if (!(pts.Item1 || pts.Item2)) // neither closed nor filled
                {
                    geoms.Add(_geometryFactory.CreateLineString(pts.Item3));
                    seqIndex++;
                }
                else
                {
                    if (!pts.Item2)
                    {
                        geoms.Add(_geometryFactory.CreateLineString(pts.Item3));
                        continue;
                    }

                    var ringPts = ClosedCoordinateRing(pts.Item3);
                    var rings   = new List <IGeometry>(new[] { _geometryFactory.CreateLinearRing(ringPts) });
                    seqIndex++;

                    //if (seqIndex < pathPtSeq.Count)
                    //{
                    //    if (!(pathPtSeq[seqIndex].Item1 || pathPtSeq[seqIndex].Item2)) continue;

                    Coordinate[] holePts;
                    // add holes as long as rings are CCW
                    while (seqIndex < pathPtSeq.Count &&
                           (pathPtSeq[seqIndex].Item1 || pathPtSeq[seqIndex].Item2) &&
                           IsHole(holePts = pathPtSeq[seqIndex].Item3))
                    {
                        rings.Add(_geometryFactory.CreateLinearRing(holePts));
                        seqIndex++;
                    }

                    var noder         = new NetTopologySuite.Noding.Snapround.GeometryNoder(new NetTopologySuite.Geometries.PrecisionModel(100000000.0));
                    var nodedLinework = noder.Node(rings);

                    // Use the polygonizer
                    var p = new Polygonizer(pathGeometry.FillRule == FillRule.EvenOdd);
                    p.Add(nodedLinework.ToList <IGeometry>());
                    var tmpPolygons = p.GetPolygons();
                    if (pathGeometry.FillRule == FillRule.Nonzero)
                    {
                        var unionized =
                            CascadedPolygonUnion.Union(NetTopologySuite.Geometries.GeometryFactory.ToPolygonArray(tmpPolygons));
                        tmpPolygons = new List <IGeometry>(new[] { unionized });
                    }
                    geoms.AddRange(tmpPolygons);
                    //}
                }
            }

            return(BuildGeometry(geoms));
        }
コード例 #30
0
 private static IList <Coordinate[]> ToCoordinates(WpfGeometry wpfGeometry)
 {
     return(ToCoordinates(PathGeometry.CreateFromGeometry(wpfGeometry)));
 }