Esempio n. 1
1
        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);
        }
Esempio n. 2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            var partPath = this.GetTemplateChild("PART_Path") as Path;
            if (partPath != null)
            {
                var pathGeometry = new PathGeometry();
                var ellipsePathFigure = new PathFigure() { StartPoint = new Point(0, 20) };
                ellipsePathFigure.Segments = new PathSegmentCollection();
                ellipsePathFigure.Segments.Add(new ArcSegment()
                {
                    Size = new Size(5.0 / 6.0 * this.Width, 25),
                    Point = new Point(this.Width, 20),
                    IsLargeArc = false,
                    SweepDirection = SweepDirection.Counterclockwise
                });
                pathGeometry.Figures.Add(ellipsePathFigure);

                var linePathFigure = new PathFigure();
                linePathFigure.Segments = new PathSegmentCollection();
                linePathFigure.Segments.Add(new LineSegment() { Point = new Point(this.Width, 0) });
                linePathFigure.Segments.Add(new LineSegment() { Point = new Point(this.Width, 20) });
                linePathFigure.Segments.Add(new LineSegment() { Point = new Point(0, 20) });
                
                pathGeometry.Figures.Add(linePathFigure);

                partPath.Data = pathGeometry;
            }

        }
Esempio n. 3
0
        public WpfMultiChart()
        {
            InitializeComponent();

            LoadImages();

            //do not show no data label by default
            ShowNoDataLabel(false);

            dataSeries = new List<TimeSeriesData>();
            plotSeries = new TimeSeriesData();
            shapeTransform = new MatrixTransform();
            chartClip = new PathGeometry();
            optimalGridLineSpacing = new Point(100, 50);
            adorner = new AdornerCursor2(ChartInteractiveCanvas, shapeTransform);
            adorner.CanvasSize = new Size(ChartInteractiveCanvas.ActualWidth, ChartInteractiveCanvas.ActualHeight);

            adorner.PanCursorImage = panCursor;

            panZoomCalculator = new PanZoomCalculator();

            ChartCanvas.SizeChanged += new SizeChangedEventHandler(ChartCanvas_SizeChanged);
            ChartCanvas.IsVisibleChanged += new DependencyPropertyChangedEventHandler(ChartCanvas_IsVisibleChanged);

            NoDataLabel.MouseMove += new MouseEventHandler(NoDataLabel_MouseMove);
            AttachEventsToCanvas(ChartInteractiveCanvas);

            ResizeChart();
        }
 public static XamlMedia.PathGeometry ToXaml(this IEnumerable<LinearRing> linearRings)
 {
     var pathGeometry = new XamlMedia.PathGeometry();
     foreach (var linearRing in linearRings)
         pathGeometry.Figures.Add(CreatePathFigure(linearRing));
     return pathGeometry;
 }
Esempio n. 5
0
		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);
		}
Esempio n. 6
0
        /// <summary>
        /// Returns a Windows Media Path Geometry from a Rhinocommon Arc
        /// </summary>
        /// <param name="input">Rhinocommon Arc</param>
        /// <returns>System Windows Media Path Geometry</returns>
        public static Sm.PathGeometry ToGeometry(this Rg.Arc input)
        {
            Sm.ArcSegment            arc               = new Sm.ArcSegment();
            Sm.PathFigure            figure            = new Sm.PathFigure();
            Sm.PathGeometry          geometry          = new Sm.PathGeometry();
            Sm.PathFigureCollection  figureCollection  = new Sm.PathFigureCollection();
            Sm.PathSegmentCollection segmentCollection = new Sm.PathSegmentCollection();

            figure.StartPoint = input.StartPoint.ToWindowsPoint();

            arc.Point = input.EndPoint.ToWindowsPoint();
            arc.Size  = new Sw.Size(input.Radius, input.Radius);
            if (Rg.Vector3d.VectorAngle(input.Plane.Normal, Rg.Vector3d.ZAxis) > 0)
            {
                arc.SweepDirection = Sm.SweepDirection.Counterclockwise;
            }
            else
            {
                arc.SweepDirection = Sm.SweepDirection.Clockwise;
            }
            arc.IsLargeArc = (input.Angle > Math.PI);

            segmentCollection.Add(arc);
            figure.Segments = segmentCollection;
            figureCollection.Add(figure);
            geometry.Figures = figureCollection;

            return(geometry);
        }
		public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e)
		{
			var createdItem = CreateItem(panel.Context, createItemType);

			var startPoint = e.GetPosition(clickedOn.View);
			var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn,
			                                                               new DesignItem[] { createdItem },
			                                                               new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) },
			                                                               PlacementType.AddItem);
			if (operation != null) {
				createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
				operation.Commit();
			}
			
			createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black);
			createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d);
			createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None);
			
			var figure = new PathFigure();
			var geometry = new PathGeometry();
			var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry);
			var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure);
			createdItem.Properties[Path.DataProperty].SetValue(geometry);
			//geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem);
			figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0,0));
			
			new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs) e);
		}
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            

            // allows the points to be rendered as an image that can be further manipulated
            PathGeometry geometry = new PathGeometry();
            this.Siz

            // Add all points to the geometry
            foreach (Points pointXY in _points)
            {
                PathFigure figure = new PathFigure();
                figure.StartPoint = pointXY.FromPoint;
                figure.Segments.Add(new LineSegment(pointXY.ToPoint, true));
                geometry.Figures.Add(figure);
            }

            // Add the first point to close the gap from the graph's end point
            // to graph's start point
            PathFigure lastFigure = new PathFigure();
            lastFigure.StartPoint = _points[_points.Count - 1].FromPoint;
            lastFigure.Segments.Add(new LineSegment(_firstPoint, true));
            geometry.Figures.Add(lastFigure);

            // Create a new drawing and drawing group in order to apply
            // a custom drawing effect
            GeometryDrawing drawing = new GeometryDrawing(this.Pen.Brush, this.Pen, geometry);
            DrawingGroup drawingGroup = new DrawingGroup();
            drawingGroup.Children.Add(drawing);
        }
Esempio n. 9
0
        /// <summary>
        /// Re-generate the path
        /// </summary>
        public void Draw()
        {
            if (Points.Count < 2)
            {
                pathGeometry = null;
            }
            else
            {
                PathFigure figure = new PathFigure();
                figure.StartPoint = contentObject.SourcePosition; figure.IsFilled = false; figure.IsClosed = false;
#if DEBUG_ON
                System.Console.WriteLine("{0} connection drawing lines ", System.DateTime.Now.Millisecond);
                foreach (Point p in contentObject.Stops)
                {
                    System.Console.Write("{0} ", p.ToString());
                }
#endif
                figure.Segments.Add(new PolyLineSegment(contentObject.Stops, true));
                PathGeometry geometry = new System.Windows.Media.PathGeometry();
                geometry.Figures.Add(figure);
                // draw different head for different types
                geometry.Figures.Add(DrawHead());
                geometry.Freeze();  // improve the performance
                pathGeometry = geometry;
                if (IsLoaded)
                {
                    InvalidateVisual();
                }
            }
        }
        public geometryLine(Canvas cvs)
        {
            rootPanel = cvs;
            //myPathFigure = new PathFigure();
            myPathGeometry = new PathGeometry();
            //myPathGeometry.Figures.Add(myPathFigure);

            myPath = new Path();
            myPath.Stroke = Brushes.Blue;
            myPath.StrokeThickness = 1;
            myPath.Data = myPathGeometry;
            rootPanel.Children.Add(myPath);

            myPathFigureOld = new PathFigure();
            myPathGeometryOld = new PathGeometry();
            myPathGeometryOld.Figures.Add(myPathFigureOld);

            myPathOld = new Path();
            myPathOld.Stroke = Brushes.Blue;
            myPathOld.StrokeThickness = 1;
            myPathOld.Data = myPathGeometryOld;

            rootPanel.Children.Add(myPathOld);
            myPathFigureTest = new PathFigure();
            myPathGeometry.Figures.Add(myPathFigureTest);

            isFirstPoint = true;
        }
        public void MoveImage(TimeSpan interval, PathGeometry beeFlyHerePath)
        {
            var storyboard = new Storyboard
            {
                RepeatBehavior = RepeatBehavior.Forever
            };

            var moveCircleAnimation = new DoubleAnimationUsingPath
            {
                PathGeometry = beeFlyHerePath,
                Source = PathAnimationSource.X,
                Duration = interval
            };

            Storyboard.SetTarget(moveCircleAnimation, this);
            Storyboard.SetTargetProperty(moveCircleAnimation, new PropertyPath("(Canvas.Left)"));

            var moveCircleAnimation2 = new DoubleAnimationUsingPath
            {
                PathGeometry = beeFlyHerePath,
                Source = PathAnimationSource.Y,
                Duration = interval
            };

            Storyboard.SetTarget(moveCircleAnimation2, this);
            Storyboard.SetTargetProperty(moveCircleAnimation2, new PropertyPath("(Canvas.Top)"));

            storyboard.Children.Add(moveCircleAnimation);
            storyboard.Children.Add(moveCircleAnimation2);

            storyboard.Begin();
        }
Esempio n. 12
0
 // Constructor
 public SineCurve()
 {
     polyLineSegment = new PolyLineSegment();
     PathFigure = new PathFigure(new Point(), new PathSegment[] { polyLineSegment }, false);
     pathGeometry = new PathGeometry(new PathFigure[] { PathFigure });
     OnRedrawPropertyChanged(new DependencyPropertyChangedEventArgs());
 }
Esempio n. 13
0
 internal static void DrawUnderlyingPolyline(PathGeometry pg, DEdge edge)
 {
     IEnumerable<WinPoint> points = edge.GeometryEdge.UnderlyingPolyline.Select(p => WinPoint(p));
     PathFigure pf = new PathFigure() { IsFilled = false, IsClosed = false, StartPoint = points.First() };
     foreach (WinPoint p in points)
     {
         if (p != points.First())
             pf.Segments.Add(new WinLineSegment() { Point = p });
         PathFigure circle = new PathFigure() { IsFilled = false, IsClosed = true, StartPoint = new WinPoint(p.X - edge.RadiusOfPolylineCorner, p.Y) };
         circle.Segments.Add(
            new ArcSegment()
            {
                Size = new WinSize(edge.RadiusOfPolylineCorner, edge.RadiusOfPolylineCorner),
                SweepDirection = SweepDirection.Clockwise,
                Point = new WinPoint(p.X + edge.RadiusOfPolylineCorner, p.Y)
            });
         circle.Segments.Add(
            new ArcSegment()
            {
                Size = new WinSize(edge.RadiusOfPolylineCorner, edge.RadiusOfPolylineCorner),
                SweepDirection = SweepDirection.Clockwise,
                Point = new WinPoint(p.X - edge.RadiusOfPolylineCorner, p.Y)
            });
         pg.Figures.Add(circle);
     }
     pg.Figures.Add(pf);
 }
Esempio n. 14
0
	private void SetPlayShape()
	{
		play.Children.Clear ();

		Path p = new Path();
		PathGeometry geometry = new PathGeometry ();
		PathFigure f = new PathFigure ();	
		f.Segments = new PathSegmentCollection ();

		p.Data = geometry;
		p.Fill = new SolidColorBrush(Colors.Red);
		p.Stroke = new SolidColorBrush(Colors.Black);
		geometry.Figures = new PathFigureCollection ();
		geometry.Figures.Add(f);

		LineSegment m = new LineSegment();
		m.Point = new Point(3, 2);
		f.Segments.Add(m);

		m = new LineSegment();	
		m.Point = new Point(14, 8.5);
		f.Segments.Add(m);

		m = new LineSegment();	
		m.Point = new Point(3, 15);
		f.Segments.Add(m);

		m = new LineSegment();	
		m.Point = new Point(3, 2);
		f.Segments.Add(m);

		play.Children.Add(p);
	}
Esempio n. 15
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;


        }
Esempio n. 16
0
        // Create the pen and triangle in a static constructor and freeze them to improve performance.
        static InsertionAdorner()
        {
            pen = new Pen
            {
                Brush = Brushes.Gray,
                Thickness = 2
            };
            pen.Freeze();

            LineSegment firstLine = new LineSegment(new Point(0, -5), false);
            firstLine.Freeze();
            LineSegment secondLine = new LineSegment(new Point(0, 5), false);
            secondLine.Freeze();

            PathFigure figure = new PathFigure
            {
                StartPoint = new Point(5, 0)
            };
            figure.Segments.Add(firstLine);
            figure.Segments.Add(secondLine);
            figure.Freeze();

            triangle = new PathGeometry();
            triangle.Figures.Add(figure);
            triangle.Freeze();
        }
        protected override Geometry GetOrCreateConnectorGeometry(Size renderSize)
        {
            var ellipse = Ellipse.CreateFromSize(renderSize);
            this.SetCurrentValue(EllipseProperty, ellipse);
            if (ellipse.IsZero)
            {
                return Geometry.Empty;
            }

            var direction = this.ConnectorOffset;
            var ip = ellipse.PointOnCircumference(direction);
            var vertexPoint = ip + this.ConnectorOffset;
            var ray = new Ray(vertexPoint, this.ConnectorOffset.Negated());

            var p1 = ConnectorPoint.Find(ray, this.ConnectorAngle / 2, this.StrokeThickness, ellipse);
            var p2 = ConnectorPoint.Find(ray, -this.ConnectorAngle / 2, this.StrokeThickness, ellipse);

            this.SetCurrentValue(ConnectorVertexPointProperty, vertexPoint);
            this.SetCurrentValue(ConnectorPoint1Property, p1);
            this.SetCurrentValue(ConnectorPoint2Property, p2);
            if (this.ConnectorGeometry is PathGeometry)
            {
                return this.ConnectorGeometry;
            }

            var figure = this.CreatePathFigureStartingAt(ConnectorPoint1Property);
            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorVertexPointProperty));
            figure.Segments.Add(this.CreateLineSegmentTo(ConnectorPoint2Property));
            var geometry = new PathGeometry();
            geometry.Figures.Add(figure);
            return geometry;
        }
Esempio n. 18
0
        /// <summary>
        ///     Main back conversion routine - converts PathGeometry object to its string equivalent
        /// </summary>
        /// <param name="geometry">Path Geometry object</param>
        /// <returns>String equivalent to PathGeometry contents</returns>
        public string ConvertBack(PathGeometry geometry)
        {
            if (null == geometry)
                throw new ArgumentException("Path Geometry cannot be null!");

            return parseBack(geometry);
        }
Esempio n. 19
0
        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();
            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();
            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
        //private WpfPoint _lastPoint;
        //internal void AddToRing(WpfPoint p, ref GraphicsPath ringPath)
        //{
        //    if (ringPath == null)
        //    {
        //        ringPath = new GraphicsPath(FillMode.Alternate);
        //        ringPath.StartFigure();
        //    }
        //    else
        //    {
        //        ringPath.AddLine(_lastPoint, p);
        //    }
        //    _lastPoint = p;
        //}

        //internal void EndRing(GraphicsPath ringPath)
        //{
        //    ringPath.CloseFigure();
        //    if (Path == null)
        //        Path = ringPath;
        //    else
        //        Path.AddPath(ringPath, false);
        //}

        ///<summary>
        /// Adds a <see cref="PathFigure"/> representing a polygon ring
        /// having the given coordinate sequence to the supplied <see cref="pathGeometry"/>
        ///</summary>
        ///<param name="pathGeometry">The path geometry.</param>
        ///<param name="coordinates">A coordinate sequence</param>
        ///<returns>The path for the coordinate sequence</returns>
        private static void AddRing(PathGeometry pathGeometry, Coordinate[] coordinates)
        {
            if (coordinates.Length <= 0)
                return;
            var figure = new PathFigure(ToPoint(coordinates[0]), ToPathSegments(coordinates), true);
            pathGeometry.Figures.Add(figure);
        }
        public Triangle()
        {
            InitializeComponent();

            l1 = new LineSegment();
            l2 = new LineSegment();

            f = new PathFigure();
            f.Segments.Add(l1);
            f.Segments.Add(l2);
            f.IsClosed = true;

            PathGeometry g = new PathGeometry();
            g.Figures.Add(f);

            Path p = new Path();
            this.SetBinding(FillProperty, new Binding("Fill") { Source = p, Mode = BindingMode.TwoWay });
            this.SetBinding(StrokeProperty, new Binding("Stroke") { Source = p, Mode = BindingMode.TwoWay });
            this.SetBinding(StrokeThicknessProperty, new Binding("StrokeThickness") { Source = p, Mode = BindingMode.TwoWay });
            p.Data = g;

            this.Fill = new SolidColorBrush(Colors.White);
            this.Stroke = new SolidColorBrush(Colors.Black);

            this.LayoutRoot.Children.Add(p);
        }
        /// <summary>
        /// Create the animation and add it to the master timeline
        /// </summary>
        protected override void CreateAnimation()
        {
            var geometry = new PathGeometry();
            geometry.AddGeometry(Geometry.Parse("M 10,100 C 10,300 300,-200 300,100"));

            var animationX = new DoubleAnimationUsingPath
                {
                    PathGeometry = geometry,
                    Duration = new Duration(this.AnimationConfiguration.Duration),
                    Source = PathAnimationSource.X
                };

            var animationY = new DoubleAnimationUsingPath
            {
                PathGeometry = geometry,
                Duration = new Duration(this.AnimationConfiguration.Duration),
                Source = PathAnimationSource.Y
            };

            Storyboard.SetTargetProperty(animationX, new PropertyPath(Canvas.LeftProperty));
            Storyboard.SetTargetProperty(animationY, new PropertyPath(Canvas.TopProperty));

            animationX.Freeze();
            animationY.Freeze();

            this.MasterStoryboard.Children.Add(animationX);
            this.MasterStoryboard.Children.Add(animationY);
        }
Esempio n. 23
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);
        }
Esempio n. 24
0
		public static void AddGeometries(WpfHexView hexView, Collection<VSTF.TextBounds> textBounds, bool isLineGeometry, bool clipToViewport, Thickness padding, double minWidth, ref PathGeometry geo, ref bool createOutlinedPath) {
			foreach (var bounds in textBounds) {
				double left = bounds.Left - padding.Left;
				double right = bounds.Right + padding.Right;
				double top, bottom;
				if (isLineGeometry) {
					top = bounds.Top - padding.Top;
					bottom = bounds.Bottom + padding.Bottom;
				}
				else {
					top = bounds.TextTop - padding.Top;
					bottom = bounds.TextBottom + padding.Bottom;
				}
				if (right - left < minWidth)
					right = left + minWidth;
				if (clipToViewport) {
					left = Math.Max(left, hexView.ViewportLeft);
					right = Math.Min(right, hexView.ViewportRight);
				}
				if (right <= left || bottom <= top)
					continue;
				const double MAX_HEIGHT = 1000000;
				const double MAX_WIDTH = 1000000;
				double width = Math.Min(right - left, MAX_WIDTH);
				double height = Math.Min(bottom - top, MAX_HEIGHT);

				if (geo == null)
					geo = new PathGeometry { FillRule = FillRule.Nonzero };
				else
					createOutlinedPath = true;
				geo.AddGeometry(new RectangleGeometry(new Rect(left, top, width, height)));
			}
		}
Esempio n. 25
0
 private void AddShape(WpfPathGeometry sgc, IGeometryCollection gc)
 {
     foreach (IGeometry geometry in gc.Geometries)
     {
         AddShape(sgc, geometry);
     }
 }
Esempio n. 26
0
        internal static PathGeometry GetPathGeometry(ConnectorInfo source, ConnectorInfo sink)
        {
            var rectSource = GetRectWithMargin(source, 0);
            var rectSink = GetRectWithMargin(sink, 13);

            var startPoint = GetOffsetPoint(source, rectSource);
            var endPoint = GetOffsetPoint(sink, rectSink);

            var midpoint = CalculateMidpoint(startPoint, new Point(endPoint.X, startPoint.Y));
            var distance = CalculateDistance(startPoint, midpoint);

            var p1 = CalculateEndpoint(startPoint, distance, GetAngel(source.Orientation));
            var p2 = CalculateEndpoint(endPoint, distance, GetAngel(sink.Orientation));
            var p3 = endPoint;

            var geometry = new PathGeometry();

            var pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;
            geometry.Figures.Add(pathFigure);

            var bs = new BezierSegment(p1, p2, p3, true);
            pathFigure.Segments.Add(bs);

            return geometry;
        }
Esempio n. 27
0
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     IsVirtualMark = new SolidColorBrush(Properties.Settings.Default.MarkVirtualColor);
     NotVirtualMark = new SolidColorBrush(Properties.Settings.Default.MarkNotColor);
     MarkDiameter = Properties.Settings.Default.MarkDiameter;
     RouteColor = new SolidColorBrush(Properties.Settings.Default.RouteColor);
     EVirtualMark.Fill = IsVirtualMark;
     ENotVirtualMark.Fill = NotVirtualMark;
     RecRoute.Fill = RouteColor;
     // Create the animation path.
     path = new Path();
     path.Stroke = RouteColor;
     path.StrokeThickness = 3;
     animationPath = new PathGeometry();
     pFigure = new PathFigure();
     route = new PolyLineSegment();
     path.Data = animationPath;
     pFigure.Segments.Add(route);
     animationPath.Figures.Add(pFigure);
     MapInit();
     //修改日期:2013-12-1
     //修改日期:2013-12-30
     BindWorkLineCombox();
     BindLineCombox(cbRoute_WorkLine.Text.Trim());
     LoadAllMark();
 }
Esempio n. 28
0
        public static m.PathGeometry ScalingPathGeometryOld(m.PathGeometry toDownsize, double scaling)
        {
            toDownsize = toDownsize.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure olfPf in toDownsize.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = olfPf.StartPoint;

                newStartPoint.X *= scaling;
                newStartPoint.Y *= scaling;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in olfPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.X *= scaling;
                        tmp.Y *= scaling;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Esempio n. 29
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);
        }
Esempio n. 30
0
        public BeautyFont(PathGeometry pathGeometry)
        {
            this._pathGeometry = pathGeometry;

            _pathGeometry.Figures.Clear();

            apt[0] = new Point[]{new Point(3,2),new Point(39,2),
                                 new Point(31,10),new Point(11,10)
            };

            apt[1] = new Point[]{new Point(2,3),new Point(10,11),
                                 new Point(10,31),new Point(2,35)
            };

            apt[2] = new Point[]{new Point(40,3),new Point(40,35),
                                 new Point(32,31),new Point(32,11)
            };

            apt[3] = new Point[]{new Point(3,36),new Point(11,32),
                                 new Point(31,32),new Point(39,36),
                                 new Point(31,40),new Point(11,40)
            };

            apt[4] = new Point[]{new Point(2,37),new Point(10,41),
                                 new Point(10,61),new Point(2,69)
            };

            apt[5] = new Point[]{new Point(40,37),new Point(40,69),
                                 new Point(32,61),new Point(32,41)
            };

            apt[6] = new Point[]{new Point(11,62),new Point(31,62),
                                 new Point(39,70),new Point(3,70)
            };
        }
Esempio n. 31
0
        public static m.PathGeometry CloseAllPathGeometries(m.PathGeometry toClose)
        {
            toClose = toClose.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure oldPf in toClose.Figures)
            {
                m.PathFigure newPf = new m.PathFigure {
                    StartPoint = oldPf.StartPoint
                };

                foreach (m.PathSegment oldPs in oldPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        ((m.PolyLineSegment)newPs).Points.Add(point);
                    }

                    ((m.PolyLineSegment)newPs).Points.Add(((m.PolyLineSegment)newPs).Points[0]);
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
		void Click_ConvertToFigures(object sender, System.Windows.RoutedEventArgs e)
		{
			var path = this.designItem.Component as Path;
			
			if (path.Data is StreamGeometry) {
				var sg = path.Data as StreamGeometry;
				
				var pg = sg.GetFlattenedPathGeometry();
				
//				foreach (var g in parts) {
//					
//				}
				
				var pgDes = designItem.Services.Component.RegisterComponentForDesigner(pg);
				designItem.Properties[Path.DataProperty].SetValue(pgDes);
			}
			else if (path.Data is PathGeometry) {
				var pg = path.Data as PathGeometry;
				
				var figs = pg.Figures;
				
				var newPg = new PathGeometry();
				var newPgDes = designItem.Services.Component.RegisterComponentForDesigner(newPg);
				
				foreach (var fig in figs) {
					newPgDes.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(FigureToDesignItem(fig));
				}
								
				designItem.Properties[Path.DataProperty].SetValue(newPg);
			}
			
		}
Esempio n. 33
0
        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);
        }
Esempio n. 34
0
 private void AddShape(WpfPathGeometry pathGeometry, IGeometry geometry)
 {
     if (geometry is IPolygon)
     {
         AddShape(pathGeometry, (IPolygon)geometry);
     }
     else if (geometry is ILinearRing)
     {
         AddShape(pathGeometry, (ILinearRing)geometry);
     }
     else if (geometry is ILineString)
     {
         AddShape(pathGeometry, (ILineString)geometry);
     }
     else if (geometry is IPoint)
     {
         AddShape(pathGeometry, (IPoint)geometry);
     }
     else if (geometry is IGeometryCollection)
     {
         AddShape(pathGeometry, (IGeometryCollection)geometry);
     }
     else
     {
         throw new ArgumentException(
                   "Unrecognized Geometry class: " + geometry.GetType());
     }
 }
Esempio n. 35
0
        /// <summary>
        /// 通过点的集合获取三次贝赛尔曲线
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        private SystemMedia.PathGeometry GetCurveGeometry(IEnumerable <Vector2D> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            var screenPoints = points.Select(x => ConvertVectorToScreenPoint(x)).ToArray();
            var bezier       = new SystemMedia.PolyBezierSegment(screenPoints, true);
            var pathFigure   = new SystemMedia.PathFigure();
            var pathGeometry = new SystemMedia.PathGeometry();

            pathFigure.Segments.Add(bezier);
            pathGeometry.Figures.Add(pathFigure);

            if (screenPoints.Length >= 1)
            {
                pathFigure.StartPoint = screenPoints[0];

                //因为此处使用的三次贝塞尔曲线要求点的数量为3的倍数,所以在未能正处情况下,重复最后一项至下一个三的倍数;
                var repeatCount = (3 - (screenPoints.Length % 3)) % 3;

                var lastScreenPoint = screenPoints[screenPoints.Length - 1];
                for (int i = 0; i < repeatCount; i++)
                {
                    bezier.Points.Add(lastScreenPoint);
                }
            }

            return(pathGeometry);
        }
Esempio n. 36
0
        public static m.PathGeometry InvertHorizontally(m.PathGeometry toInvert, double maxHeight)
        {
            toInvert = toInvert.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure oldPf in toInvert.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = oldPf.StartPoint;

                newStartPoint.Y = maxHeight - newStartPoint.Y;
                newStartPoint.X = newStartPoint.X;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in oldPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.Y = maxHeight - tmp.Y;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Esempio n. 37
0
        public Geometry GetShapeGeometry()
        {
            PathFigure outer = new PathFigure();
            outer.IsClosed = true;
            outer.StartPoint = new Point(0, 2.5);
            outer.Segments.Add(new LineSegment() { Point = new Point(2.5, 0) });
            outer.Segments.Add(new LineSegment() { Point = new Point(5, 2.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(7.5, 0) });
            outer.Segments.Add(new LineSegment() { Point = new Point(10, 2.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(9, 3.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(7.5, 2) });
            outer.Segments.Add(new LineSegment() { Point = new Point(6, 3.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(8.5, 6) });
            outer.Segments.Add(new LineSegment() { Point = new Point(5, 9.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(1.5, 6) });
            outer.Segments.Add(new LineSegment() { Point = new Point(4, 3.5) });
            outer.Segments.Add(new LineSegment() { Point = new Point(2.5, 2) });
            outer.Segments.Add(new LineSegment() { Point = new Point(1, 3.5) });

            PathFigure inner = new PathFigure();
            inner.StartPoint = new Point(3.5, 6);
            inner.IsClosed = true;
            inner.Segments.Add(new LineSegment() { Point = new Point(5, 7.5) });
            inner.Segments.Add(new LineSegment() { Point = new Point(6.5, 6) });
            inner.Segments.Add(new LineSegment() { Point = new Point(5, 4.5) });

            PathGeometry logoGeometry = new PathGeometry();
            logoGeometry.Figures.Add(inner);
            logoGeometry.Figures.Add(outer);

            return logoGeometry;
        }
Esempio n. 38
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PathGeometry oldPathGeometry = currentPathGeometry;
            currentPath.Data = currentPathGeometry = new PathGeometry();

            if (timer == null)
            {
                int index = 0;

                timer = new DispatcherTimer();
                timer.Interval = TimeSpan.FromMilliseconds(8);
                timer.Tick += delegate
                {
                    var nextPoint = GetNextPoint(oldPathGeometry, index);
                    if (nextPoint != null)
                    {
                        AddNewPosition(nextPoint.Item1, nextPoint.Item2);
                    }
                    else
                    {
                        timer.Stop();
                        timer = null;
                    }
                    index++;
                };

                timer.Start();
            }
        }
        /// <summary>
        /// Draw WPF path constructor
        /// </summary>
        /// <param name="MediaPath">System.Windows.Media path geometry</param>
        /// <param name="PathYAxis">Y Axix direction</param>
        public DrawWPFPath
        (
            SysMedia.PathGeometry MediaPath,
            YAxisDirection PathYAxis
        )
        {
            // save media path
            this.MediaPath = MediaPath;

            // save path rectangle and y axis direction
            PathBBoxX      = MediaPath.Bounds.X;
            PathBBoxY      = MediaPath.Bounds.Y;
            PathBBoxWidth  = MediaPath.Bounds.Width;
            PathBBoxHeight = MediaPath.Bounds.Height;
            this.PathYAxis = PathYAxis;

            // test arguments
            if (PathBBoxWidth == 0 && PathBBoxHeight == 0)
            {
                throw new ApplicationException("DrawWPFPath: Path bounding box is empty");
            }

            // initialization values
            FillRule     = MediaPath.FillRule == SysMedia.FillRule.EvenOdd ? FillRule.EvenOdd : FillRule.NonZero;
            BlendMode    = BlendMode.Normal;
            BrushOpacity = 1.0;
            PenOpacity   = 1.0;
            PenWidth     = -1;
            LineCap      = (PdfLineCap)(-1);
            LineJoin     = (PdfLineJoin)(-1);
            MiterLimit   = -1;
            return;
        }
Esempio n. 40
0
        public static IEnumerable <List <drawing.Point> > GeometryToListListPointsDrawing(m.Geometry toConvert, double resolution = 20, bool flattening = false)
        {
            m.PathGeometry allPointsContainer = GeometryToPathGeometry(toConvert, resolution, flattening);

            List <List <drawing.Point> > allPoints = new List <List <drawing.Point> >();

            foreach (m.PathFigure figures in allPointsContainer.Figures)
            {
                List <drawing.Point> allSegmentPoints = new List <drawing.Point>();

                foreach (m.PathSegment segment in figures.Segments)
                {
                    foreach (Point point in ((m.PolyLineSegment)segment).Points)
                    {
                        int           x  = Convert.ToInt32(Math.Round(point.X));
                        int           y  = Convert.ToInt32(Math.Round(point.Y));
                        drawing.Point np = new drawing.Point(x, y);

                        allSegmentPoints.Add(np);
                    }

                    Point tmp = ((m.PolyLineSegment)segment).Points[0];
                    //allSegmentPoints.Add(tmp); // fügt startpunkt hinzu damit der kreis geschlossen ist
                }
                allPoints.Add(allSegmentPoints);
            }

            return(allPoints);
        }
Esempio n. 41
0
        public static XamlMedia.Geometry ToXaml(this LineString lineString)
        {
            var pathGeometry = new XamlMedia.PathGeometry();

            pathGeometry.Figures.Add(CreatePathFigure(lineString));
            return(pathGeometry);
        }
Esempio n. 42
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.MainGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 2:
                this.Out = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.Out1 = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.MainPath = ((System.Windows.Shapes.Path)(target));
                return;

            case 5:
                this.PerformaceStartPoint1 = ((System.Windows.Media.PathGeometry)(target));
                return;

            case 6:
                this.PerformaceStartPoint = ((System.Windows.Media.PathFigure)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 43
0
        public static void UserDrawRoutesWPF(Route Route, DrawingContext dc, System.Windows.Media.Color color)
        {
            System.Windows.Point[] m_ScreenPnts = null;
            int PixelX = 0;
            int PixelY = 0;

            if (Route == null)
            {
                return;
            }
            if (Route.Points.Count() == 0)
            {
                return;
            }



            System.Windows.Media.SolidColorBrush curBrush = new System.Windows.Media.SolidColorBrush();


            curBrush.Color = color;// System.Windows.Media.Colors.Gold;


            System.Windows.Media.Pen pen = new System.Windows.Media.Pen(curBrush, 3);


            // m_ScreenPnts = new System.Windows.Point[Route.arr_legs.Length + 1];
            m_ScreenPnts = new System.Windows.Point[Route.Points.Count()];


            //VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.arr_legs[0].FromLongn, Route.arr_legs[0].FromLatn, ref PixelX, ref PixelY);
            //m_ScreenPnts[0].X = PixelX;
            //m_ScreenPnts[0].Y = PixelY;


            for (int i = 0; i < Route.Points.Count(); i++)
            {
                //VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.arr_legs[i].ToLongn, Route.arr_legs[i].ToLatn, ref PixelX, ref PixelY);
                //m_ScreenPnts[i + 1].X = PixelX;
                //m_ScreenPnts[i + 1].Y = PixelY;

                VMMainViewModel.Instance.ConvertCoordGroundToPixel(Route.Points[i].X, Route.Points[i].Y, ref PixelX, ref PixelY);
                m_ScreenPnts[i].X = PixelX;
                m_ScreenPnts[i].Y = PixelY;
            }

            System.Windows.Media.PathGeometry PathGmtr   = new System.Windows.Media.PathGeometry();
            System.Windows.Media.PathFigure   pathFigure = new System.Windows.Media.PathFigure();

            System.Windows.Media.PolyLineSegment myPolyLineSegment = new System.Windows.Media.PolyLineSegment();
            System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection(m_ScreenPnts);
            myPolyLineSegment.Points = pc;
            pathFigure.StartPoint    = m_ScreenPnts[0];
            pathFigure.Segments.Add(myPolyLineSegment);
            PathGmtr.Figures.Add(pathFigure);

            dc.DrawGeometry(null, pen, PathGmtr);
        }
Esempio n. 44
0
 public void ResetClip()
 {
     if (clipBounds != null)
     {
         Control.Pop();
         clipBounds = null;
         clipPath   = null;
     }
 }
Esempio n. 45
0
 public void SetClip(IGraphicsPath path)
 {
     TransformStack.PopAll();
     ResetClip();
     clipPath   = path.Clone().ToWpf();           // require a clone so changes to path don't affect current clip
     clipBounds = clipPath.Bounds.ToEtoF();
     ApplyClip();
     TransformStack.PushAll();
 }
Esempio n. 46
0
 public void SetClip(RectangleF rectangle)
 {
     TransformStack.PopAll();
     ResetClip();
     clipBounds = rectangle;
     clipPath   = null;
     ApplyClip();
     TransformStack.PushAll();
 }
Esempio n. 47
0
        public static XamlMedia.PathGeometry ToXaml(this IEnumerable <LinearRing> linearRings)
        {
            var pathGeometry = new XamlMedia.PathGeometry();

            foreach (var linearRing in linearRings)
            {
                pathGeometry.Figures.Add(CreatePathFigure(linearRing));
            }
            return(pathGeometry);
        }
Esempio n. 48
0
        public void AddPath(IGraphicsPath path, bool connect = false)
        {
            if (path.IsEmpty)
            {
                return;
            }

            var wpfPath = path.ToWpf();

            if (!wpfPath.Transform.Value.IsIdentity)
            {
                var newpath = new swm.PathGeometry();
                newpath.AddGeometry(wpfPath);
                wpfPath = newpath;
            }
            var en = wpfPath.Figures.GetEnumerator();

            if (connect)
            {
                // merge current figure (if any) and first figure of new path, if they are not closed paths
                if (figure != null && !figure.IsClosed && en.MoveNext())
                {
                    var firstFigure = en.Current;
                    if (!firstFigure.IsClosed)
                    {
                        figure.Segments.Add(new swm.LineSegment(firstFigure.StartPoint, true));
                        foreach (var seg in firstFigure.Segments)
                        {
                            figure.Segments.Add(seg);
                        }
                    }
                    else
                    {
                        Control.Figures.Add(firstFigure);
                    }
                }
            }
            swm.PathFigure pathFigure = null;
            while (en.MoveNext())
            {
                pathFigure = en.Current;
                Control.Figures.Add(pathFigure);
            }

            // continue with last figure of new path if not closed
            if (pathFigure != null && !pathFigure.IsClosed)
            {
                figure = pathFigure;
            }
            else
            {
                figure = null;
            }
        }
Esempio n. 49
0
        /// <summary>
        /// Extracts the the Coordinates out of a PathGeometry and puts them into a PolyLineSegment.
        /// </summary>
        /// <param name="allPointsContainer">The PathGeometry that Contains the all the Coordinates you want to convert</param>
        /// <returns></returns>
        public static List <m.PolyLineSegment> PathGeometryToPlsListOld(m.PathGeometry allPointsContainer)
        {
            allPointsContainer = allPointsContainer.GetFlattenedPathGeometry(1.0, m.ToleranceType.Absolute);

            return
                (allPointsContainer.Figures.Select(
                     figures =>
                     figures.Segments.SelectMany(segments => ((m.PolyLineSegment)segments).Points).ToList())
                 .Select(allPoints => new m.PolyLineSegment(allPoints, true))
                 .ToList());
        }
Esempio n. 50
0
 public void ResetClip()
 {
     if (clipBounds != null || clipPath != null)
     {
         RewindTransform();
         RewindClip();
         clipBounds = null;
         clipPath   = null;
         ApplyTransform();
     }
 }
Esempio n. 51
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.btnShow = ((System.Windows.Controls.Primitives.ToggleButton)(target));

            #line 17 "..\..\MainWindow.xaml"
                this.btnShow.Click += new System.Windows.RoutedEventHandler(this.btnShow_Click);

            #line default
            #line hidden
                return;

            case 2:
                this.btnDraw = ((System.Windows.Controls.Button)(target));

            #line 31 "..\..\MainWindow.xaml"
                this.btnDraw.Click += new System.Windows.RoutedEventHandler(this.BtnDraw_Click);

            #line default
            #line hidden
                return;

            case 3:
                this.CanvasPanel = ((System.Windows.Controls.Canvas)(target));
                return;

            case 4:
                this.TwoDEllipse = ((System.Windows.Shapes.Ellipse)(target));
                return;

            case 5:
                this.TwoDRectangle = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 6:
                this.TwoDRectangle2 = ((System.Windows.Shapes.Rectangle)(target));
                return;

            case 7:
                this.TwoDPath = ((System.Windows.Shapes.Path)(target));
                return;

            case 8:
                this.PathGeoMetry = ((System.Windows.Media.PathGeometry)(target));
                return;

            case 9:
                this.PathHeart = ((System.Windows.Shapes.Path)(target));
                return;
            }
            this._contentLoaded = true;
        }
Esempio n. 52
0
        /// <summary>
        /// Returns the pure PathGeometry to easily display at the screen.
        /// </summary>
        /// <returns></returns>
        public static m.PathGeometry GeometryToPathGeometry(m.Geometry toConvert, double resolution = 20, bool wannaFlat = false)
        {
            m.PathGeometry myPathGeometry = toConvert.GetOutlinedPathGeometry(resolution,
                                                                              m.ToleranceType.Relative);

            if (wannaFlat)
            {
                myPathGeometry = myPathGeometry.GetFlattenedPathGeometry(resolution, m.ToleranceType.Relative);
            }

            return(myPathGeometry);
        }
Esempio n. 53
0
        private void DrawLineCurveInternal(DrawingContext dc, double half, Pen pen, LineShape line, ref Point pt1, ref Point pt2, double dx, double dy)
        {
            double p1x = pt1.X;
            double p1y = pt1.Y;
            double p2x = pt2.X;
            double p2y = pt2.Y;

            LineShapeExtensions.GetCurvedLineBezierControlPoints(
                line.Style.LineStyle.CurveOrientation,
                line.Style.LineStyle.Curvature,
                line.Start.Alignment,
                line.End.Alignment,
                ref p1x, ref p1y,
                ref p2x, ref p2y);

            System.Windows.Media.PathGeometry pg = _curvedLineCache.Get(line);
            if (pg != null)
            {
                var pf = pg.Figures[0];
                pf.StartPoint = new Point(pt1.X + dx, pt1.Y + dy);
                pf.IsFilled   = false;
                var bs = pf.Segments[0] as BezierSegment;
                bs.Point1    = new Point(p1x + dx, p1y + dy);
                bs.Point2    = new Point(p2x + dx, p2y + dy);
                bs.Point3    = new Point(pt2.X + dx, pt2.Y + dy);
                bs.IsStroked = line.IsStroked;
            }
            else
            {
                var pf = new System.Windows.Media.PathFigure()
                {
                    StartPoint = new Point(pt1.X + dx, pt1.Y + dy),
                    IsFilled   = false
                };
                var bs = new BezierSegment(
                    new Point(p1x + dx, p1y + dy),
                    new Point(p2x + dx, p2y + dy),
                    new Point(pt2.X + dx, pt2.Y + dy),
                    line.IsStroked);
                //bs.Freeze();
                pf.Segments.Add(bs);
                //pf.Freeze();
                pg = new System.Windows.Media.PathGeometry();
                pg.Figures.Add(pf);
                //pg.Freeze();

                _curvedLineCache.Set(line, pg);
            }

            DrawPathGeometryInternal(dc, half, null, pen, line.IsStroked, false, pg);
        }
Esempio n. 54
0
 public void SetClip(IGraphicsPath path)
 {
     RewindTransform();
     RewindClip();
     path = path.Clone();
     if (transforms != null && transforms.Current != null)
     {
         path.Transform(transforms.Current);
     }
     clipPath   = path.ToWpf(); // require a clone so changes to path don't affect current clip
     clipBounds = clipPath.Bounds.ToEtoF();
     ApplyClip();
     ApplyTransform();
 }
Esempio n. 55
0
        ///<summary>
        /// Creates a <see cref="WpfGeometry"/> representing a <see cref="IGeometry"/>, according to the specified PointTransformation and PointShapeFactory (if relevant).
        ///</summary>
        public WpfGeometry ToShape(IGeometry geometry)
        {
            if (geometry.IsEmpty)
            {
                return(new WpfPathGeometry());
            }

            var p = new WpfPathGeometry();

            AddShape(p, geometry);

            p.Freeze();
            return(p);
        }
Esempio n. 56
0
        /// <summary>
        /// 直接根据视图位置,绘制WPF封闭区域;
        /// </summary>
        /// <param name="screenPoints"></param>
        /// <param name="brush"></param>
        /// <param name="pen"></param>
        private void NativeDrawFill(IEnumerable <Point> screenPoints, SystemMedia.Brush brush, SystemMedia.Pen pen)
        {
            if (screenPoints == null)
            {
                throw new ArgumentNullException(nameof(screenPoints));
            }
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            ValidateDrawingContext();

            pen.Freeze();



            //操作SystemMedia.PathGeometry中的Figures以绘制(封闭)区域
            var paths = new SystemMedia.PathGeometry();

            var pfc = new SystemMedia.PathFigureCollection();
            var pf  = new SystemMedia.PathFigure();

            pfc.Add(pf);

            //存储一个点表示当前的PathFigure的StartPoint是否被指定;
            var startPointSet = false;

            foreach (var p in screenPoints)
            {
                //若StartPoint未被设定(第一个节点),设定后继续下一次循环;
                if (!startPointSet)
                {
                    pf.StartPoint = p;
                    startPointSet = true;
                    continue;
                }

                //若若StartPoint被设定,则加入线段;
                var ps = new SystemMedia.LineSegment();
                ps.Point = p;
                pf.Segments.Add(ps);
            }


            pf.IsClosed   = true;
            paths.Figures = pfc;
            DrawingContext.DrawGeometry(brush, pen, paths);
        }
Esempio n. 57
0
        private void AddShape(WpfPathGeometry pathGeometry, IPolygon p)
        {
            AddShape(pathGeometry, p.Shell, true);
            var holes = p.Holes;

            if (holes == null)
            {
                return;
            }

            foreach (var hole in holes)
            {
                AddShape(pathGeometry, hole, true);
            }
        }
Esempio n. 58
0
        public static m.PathGeometry ScalingPathGeometry(m.PathGeometry toScale, double scaling, bool scaleAtZero = false)
        {
            toScale = toScale.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute);

            Point pointToScale = new Point();

            if (scaleAtZero)
            {
                pointToScale = new Point(0, 0);
            }
            else
            {
                Rect rect = GetMinimalMaxRect(toScale, 0);
                pointToScale = rect.BottomLeft;
            }


            m.PathGeometry toReturn = new m.PathGeometry();

            foreach (m.PathFigure olfPf in toScale.Figures)
            {
                m.PathFigure newPf = new m.PathFigure();

                Point newStartPoint = olfPf.StartPoint;

                newStartPoint.X = (newStartPoint.X - pointToScale.X) * scaling + pointToScale.X;
                newStartPoint.Y = (newStartPoint.Y - pointToScale.Y) * scaling + pointToScale.Y;

                newPf.StartPoint = newStartPoint;

                foreach (m.PathSegment oldPs in olfPf.Segments)
                {
                    m.PathSegment newPs = new m.PolyLineSegment();

                    foreach (Point point in ((m.PolyLineSegment)oldPs).Points)
                    {
                        Point tmp = point;
                        tmp.X = (tmp.X - pointToScale.X) * scaling + pointToScale.X;
                        tmp.Y = (tmp.Y - pointToScale.Y) * scaling + pointToScale.Y;

                        ((m.PolyLineSegment)newPs).Points.Add(tmp);
                    }
                    newPf.Segments.Add(newPs);
                }
                toReturn.Figures.Add(newPf);
            }
            return(toReturn);
        }
Esempio n. 59
0
 public void SetClip(RectangleF rectangle)
 {
     RewindTransform();
     RewindClip();
     if (transforms != null && transforms.Current != null)
     {
         clipBounds = transforms.Current.TransformRectangle(rectangle);
     }
     else
     {
         clipBounds = rectangle;
     }
     clipPath = null;
     ApplyClip();
     ApplyTransform();
 }
Esempio n. 60
0
        public void DrawPath(System.Windows.Media.PathGeometry seriesData, System.Drawing.Pen gdiPen, System.Drawing.Brush gdiBrush)
        {
            foreach (PathFigure figure in seriesData.Figures)
            {
                var points = figure.Segments.Cast <LineSegment>().Select(s => s.Point.AsDrawingPoint());

                var nextPoint = points.First();

                foreach (var point in points)
                {
                    var lastPoint = nextPoint;
                    nextPoint = point;
                    GDIGraphics.DrawLine(gdiPen, lastPoint, nextPoint);
                }
            }
        }