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); }
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); }
/// <summary> /// コントロールの描画設定 /// </summary> /// <param name="element">設定するコントロール</param> /// <param name="value">0~100の数値</param> /// <param name="isFront">前景(true)/背景(false)</param> public static void SetValue(ref System.Windows.Shapes.Path element, Double value, Boolean isFront) { Double thick = element.StrokeThickness / 2d; Double angle = CalcAngle(value); var fig = new System.Windows.Media.PathFigure() { // 開始点の設定 StartPoint = new Point( element.Width / 2, element.Height - thick)//下側から円を描く }; Double radius = (element.Width / 2) - thick; // 半径 var endPoint = CalcEndPoint(angle, radius); // 終了点 Boolean isLargeArcFlg = angle >= STRAIGHT_ANGLE; // 描画コントロールの作成 var seg = new ArcSegment() { Point = new Point(endPoint.X + thick, endPoint.Y + thick), Size = new Size(radius, radius), IsLargeArc = isFront ? isLargeArcFlg : !isLargeArcFlg, SweepDirection = isFront ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, RotationAngle = 0, }; // コントロールの設定 fig.Segments.Clear(); fig.Segments.Add(seg); element.Data = new PathGeometry(new PathFigure[] { fig }); }
public PathFigure AddArc(int start, int end) { int horizontalPostion = 100; var startPoint = new Point(horizontalPostion, start); var endPoint = new Point(horizontalPostion, end); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = startPoint; ArcSegment arcSeg = new ArcSegment(); arcSeg.Point = endPoint; arcSeg.Size = new Size(25, 25); arcSeg.IsLargeArc = true; arcSeg.SweepDirection = SweepDirection.Clockwise; arcSeg.RotationAngle = 90; var arrowhead = new Polygon(); arrowhead.Stroke = Brushes.Black; arrowhead.StrokeThickness = 2; arrowhead.Points.Add(new Point(endPoint.X - 4, endPoint.Y)); arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y + 3)); arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y - 3)); arrowhead.Fill = Brushes.Black; PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(arcSeg); pathFigure.Segments = myPathSegmentCollection; _pathFigureCollection.Add(pathFigure); _root.Children.Add(arrowhead); return pathFigure; }
// Constructor public SineCurve() { polyLineSegment = new PolyLineSegment(); PathFigure = new PathFigure(new Point(), new PathSegment[] { polyLineSegment }, false); pathGeometry = new PathGeometry(new PathFigure[] { PathFigure }); OnRedrawPropertyChanged(new DependencyPropertyChangedEventArgs()); }
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; }
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); }
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; }
internal static double GetPathFigureLength(PathFigure pathFigure) { if (pathFigure == null) return 0; var isAlreadyFlattened = pathFigure.Segments.All(pathSegment => (pathSegment is PolyLineSegment) || (pathSegment is LineSegment)); var pathFigureFlattened = isAlreadyFlattened ? pathFigure : pathFigure.GetFlattenedPathFigure(); double length = 0; var pt1 = pathFigureFlattened.StartPoint; foreach (var pathSegment in pathFigureFlattened.Segments) { if (pathSegment is LineSegment) { var pt2 = ((LineSegment)pathSegment).Point; length += (pt2 - pt1).Length; pt1 = pt2; } else if (pathSegment is PolyLineSegment) { var pointCollection = ((PolyLineSegment)pathSegment).Points; foreach (var pt2 in pointCollection) { length += (pt2 - pt1).Length; pt1 = pt2; } } } return length; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.MainPath = ((System.Windows.Shapes.Path)(target)); #line 14 "..\..\..\PiePiece.xaml" this.MainPath.MouseEnter += new System.Windows.Input.MouseEventHandler(this.Path_MouseEnter); #line default #line hidden #line 14 "..\..\..\PiePiece.xaml" this.MainPath.MouseLeave += new System.Windows.Input.MouseEventHandler(this.Path_MouseLeave); #line default #line hidden return; case 2: this.Geometry = ((System.Windows.Media.PathFigure)(target)); return; case 3: this.SectorRotation = ((System.Windows.Media.RotateTransform)(target)); return; } this._contentLoaded = true; }
/// <summary> /// This is where the arrow shape is created. /// </summary> /// <returns></returns> private Geometry CreateShape() { double width = _rect.Width; double height = _rect.Height; double borderOffset = GetStrokeThickness() / 2d; PathGeometry g = new PathGeometry(); PathFigure figure = new PathFigure(); figure.IsClosed = true; figure.StartPoint = new Point(borderOffset, borderOffset); figure.Segments.Add(new LineSegment(new Point(width - TipOffset + borderOffset, borderOffset), true)); figure.Segments.Add(new LineSegment(new Point(width + borderOffset, height / 2d + borderOffset), true)); figure.Segments.Add(new LineSegment(new Point(width + borderOffset - TipOffset, height + borderOffset), true)); figure.Segments.Add(new LineSegment(new Point(borderOffset, height + borderOffset), true)); g.Figures.Add(figure); return g; }
/// <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); }
//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 static Tuple<Path, PathFigure, ArcSegment> CreateArcShape() { var arcSegment = new ArcSegment() { SweepDirection = SweepDirection.Counterclockwise, RotationAngle = 0 }; var figure = new PathFigure() { IsClosed = false, IsFilled = false, Segments = new PathSegmentCollection() { arcSegment } }; var path = new Path() { Data = new PathGeometry() { Figures = new PathFigureCollection() { figure } }, Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = 1 }; return Tuple.Create(path, figure, arcSegment); }
public PathGeometry GetPathGeometry(bool IsStroke, bool smoothe) { PathFigure pf = new PathFigure() { StartPoint = FirstPoint, IsClosed = true }; pf.Segments.AddCollection(GetSlicePathSegments(IsStroke, smoothe)); var l = new List<PathFigure>(); l.Add(pf); return new PathGeometry(l); }
/// <summary> /// Convert a Nucleus line to a WPF PathFigure /// </summary> /// <param name="line"></param> /// <returns></returns> public static Media.PathFigure Convert(Line line) { Media.PathFigure result = new Media.PathFigure(); result.StartPoint = Convert(line.StartPoint); result.Segments.Add(new Media.LineSegment(Convert(line.EndPoint), true)); return(result); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.canvas = ((System.Windows.Controls.Canvas)(target)); return; case 2: this.rangeStart = ((System.Windows.Media.PathFigure)(target)); return; case 3: this.rangeMiddle = ((System.Windows.Media.LineSegment)(target)); return; case 4: this.rangeEnd = ((System.Windows.Media.LineSegment)(target)); return; case 5: this.rangeSector = ((System.Windows.Shapes.Ellipse)(target)); return; case 6: this.rangeBorder = ((System.Windows.Shapes.Ellipse)(target)); return; case 7: this.dialProxy = ((System.Windows.Shapes.Ellipse)(target)); return; } this._contentLoaded = true; }
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); }
void StartNewFigure(Point startPoint) { figure = new swm.PathFigure(); figure.StartPoint = Generator.Convert(startPoint); figure.Segments = new swm.PathSegmentCollection(); Control.Figures.Add(figure); }
/// <summary> /// Convert a Nucleus arc into a WPF PathFigure /// </summary> /// <param name="arc"></param> /// <returns></returns> public static Media.PathFigure Convert(Arc arc) { Media.PathFigure result = new Media.PathFigure(); result.StartPoint = Convert(arc.StartPoint); double radius = arc.Circle.Radius; if (arc.Closed) { //Circle! result.Segments.Add(new Media.ArcSegment(Convert(arc.PointAt(0.5)), new W.Size(radius, radius), 0, true, Media.SweepDirection.Clockwise, true)); result.Segments.Add(new Media.ArcSegment(Convert(arc.EndPoint), new W.Size(radius, radius), 0, false, Media.SweepDirection.Clockwise, true)); } else { bool largeArc = arc.RadianMeasure.IsReflex; Media.SweepDirection dir = Media.SweepDirection.Clockwise; if (!arc.IsClockwise) { dir = Media.SweepDirection.Counterclockwise; } result.Segments.Add(new Media.ArcSegment(Convert(arc.EndPoint), new W.Size(radius, radius), 0, largeArc, dir, true)); } return(result); }
/// <summary> /// Draw Control /// </summary> /// <param name="Element"></param> /// <param name="ValueToSet"></param> /// <param name="IsFront"></param> public static void SetValue(ref System.Windows.Shapes.Path Element, double ValueToSet, bool IsFront) { double Thick = Element.StrokeThickness / 2d; var Fig = new System.Windows.Media.PathFigure() { StartPoint = new Point( Element.Width / 2, Element.Height - Thick)//Draw the circle from bottom to up side. }; double Angle = CalcAngle(ValueToSet); double Radius = (Element.Width / 2) - Thick; var EndPoint = CalcEndPoint(Angle, Radius); bool IsLargeArcFlg = Angle >= STRAIGHT_ANGLE; // Create Draw Control. var Seg = new ArcSegment() { Point = new Point(EndPoint.X + Thick, EndPoint.Y + Thick), Size = new Size(Radius, Radius), IsLargeArc = IsFront ? IsLargeArcFlg : !IsLargeArcFlg, SweepDirection = IsFront ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, RotationAngle = 0 }; //Setup control. Fig.Segments.Clear(); Fig.Segments.Add(Seg); Element.Data = new PathGeometry(new PathFigure[] { Fig }); }
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); }
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; }
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 System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.userControl = ((WPFPageSwitch.Views.CircularProgressBar)(target)); return; case 2: this.LayoutRoot = ((System.Windows.Controls.Grid)(target)); return; case 3: this.pathRoot = ((System.Windows.Shapes.Path)(target)); return; case 4: this.pathFigure = ((System.Windows.Media.PathFigure)(target)); return; case 5: this.arcSegment = ((System.Windows.Media.ArcSegment)(target)); return; } this._contentLoaded = true; }
private void DrawPath(IEnumerable<Vector2> path) { if (!path.Any()) throw new ArgumentException("Path cannot be empty."); var figure = new PathFigure(); var start = path.First(); figure.StartPoint = PointFromVector(start); foreach (var vector in path.Skip(1)) { var point = PointFromVector(vector); figure.Segments.Add(new LineSegment(point, true)); } var geometry = new PathGeometry(); geometry.Figures.Add(figure); var pathImage = new Path() { Stroke = Brushes.Black, StrokeThickness = 3, Data = geometry }; mainCanvas.Children.Add(pathImage); }
public PathFigure GetPathFigure(Point start, Point end) { var tickFigure = new PathFigure(); tickFigure.StartPoint = start; tickFigure.Segments.Add(new LineSegment { Point = end }); return tickFigure; }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.anglePath = ((System.Windows.Shapes.Path)(target)); return; case 2: this.angleFigure = ((System.Windows.Media.PathFigure)(target)); return; case 3: this.line1 = ((System.Windows.Media.LineSegment)(target)); return; case 4: this.line2 = ((System.Windows.Media.LineSegment)(target)); return; case 5: this.arc = ((System.Windows.Media.ArcSegment)(target)); return; } this._contentLoaded = true; }
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); }
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); }
/* 将相邻两点连线 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); }
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; } }
// 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(); }
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); }
PathGeometry CreateSplineSegment(PointCollection points) { if (points == null || points.Count < 1) return null; PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure(); PolyLineSegment polyLineSegment = new PolyLineSegment(); pathFigure.IsClosed = false; pathFigure.IsFilled = false; pathFigure.StartPoint = points[0]; for (int i = 1; i < points.Count; i++) { polyLineSegment.Points.Add(points[i]); } pathFigure.Segments.Add(polyLineSegment); pathGeometry.Figures.Add(pathFigure); // pathFigure.Freeze(); // return pathGeometry; }
internal override void AddToFigure( Matrix matrix, // The transformation matrix PathFigure figure, // The figure to add to ref Point current) // Out: Segment endpoint, not transformed { PointCollection points = Points; if (points != null && points.Count >= 2) { if (matrix.IsIdentity) { figure.Segments.Add(this); } else { PointCollection copy = new PointCollection(); Point pt = new Point(); int count = points.Count; for (int i=0; i<count; i++) { pt = points.Internal_GetItem(i); pt *= matrix; copy.Add(pt); } figure.Segments.Add(new PolyQuadraticBezierSegment(copy, IsStroked, IsSmoothJoin)); } current = points.Internal_GetItem(points.Count - 1); } }
private void RenderArc(double Angle, Path pathRoot, PathFigure pathFigure, ArcSegment arcSegment) { Point startPoint = new Point(Radius, 0); Point endPoint = ComputeCartesianCoordinate(Angle, Radius); endPoint.X += Radius; endPoint.Y += Radius; pathRoot.Width = Radius * 2 + StrokeThickness; pathRoot.Height = Radius * 2 + StrokeThickness; pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0); bool largeArc = Angle > 180.0; Size outerArcSize = new Size(Radius, Radius); pathFigure.StartPoint = startPoint; if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y)) { endPoint.X -= 0.01; } arcSegment.Point = endPoint; arcSegment.Size = outerArcSize; arcSegment.IsLargeArc = largeArc; }
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); }
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; }
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; }
/// <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(); }
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); }
/// <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); }
protected override void UpdateUIRepresentationCore() { var transform = Plotter.Viewport.Transform; PathGeometry geometry = PathGeometry; PointCollection points = Points; geometry.Clear(); if (points == null) { } else { PathFigure figure = new PathFigure(); if (points.Count > 0) { figure.StartPoint = points[0].DataToScreen(transform); if (points.Count > 1) { Point[] pointArray = new Point[points.Count - 1]; for (int i = 1; i < points.Count; i++) { pointArray[i - 1] = points[i].DataToScreen(transform); } figure.Segments.Add(new PolyLineSegment(pointArray, true)); figure.IsClosed = true; } } geometry.Figures.Add(figure); geometry.FillRule = this.FillRule; } }
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); }
public void CloseFigure() { if (figure != null) { if (!(figure.Segments.Count == 1 && figure.Segments[0] is swm.LineSegment)) { figure.IsClosed = true; } } figure = null; }
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; } }
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); }
/// <summary> /// 得到圆弧的几何图形; /// </summary> /// <param name="center"></param> /// <param name="screenRadius"></param> /// <param name="beginAngle"></param> /// <param name="angle"></param> /// <param name="smallAngle"></param> /// <returns></returns> private static SystemMedia.PathGeometry GetArcGeometry(Point startScreenPoint, Point endScreenPoint, double screenRadius, bool smallAngle, SystemMedia.SweepDirection sweepDirection) { var arcSegment = new SystemMedia.ArcSegment(endScreenPoint, new System.Windows.Size(screenRadius, screenRadius), 0D, !smallAngle, sweepDirection, true); var segments = new SystemMedia.PathSegment[] { arcSegment }; var pathFigure = new SystemMedia.PathFigure(startScreenPoint, segments, false); var figures = new SystemMedia.PathFigure[] { pathFigure }; arcSegment.Freeze(); pathFigure.Freeze(); return(new SystemMedia.PathGeometry(figures, SystemMedia.FillRule.EvenOdd, null)); }
void ConnectTo(sw.Point startPoint, bool startNewFigure = false) { if (startNewFigure || figure == null) { figure = new swm.PathFigure(); figure.StartPoint = startPoint; figure.Segments = new swm.PathSegmentCollection(); Control.Figures.Add(figure); } else { figure.Segments.Add(new swm.LineSegment(startPoint, true)); } }
/// <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); }
/// <summary> /// Convert a Nucleus PolyLine into a WPF PathFigure /// </summary> /// <param name="polyLine"></param> /// <returns></returns> public static Media.PathFigure Convert(PolyLine polyLine) { Media.PathFigure result = new Media.PathFigure(); result.StartPoint = Convert(polyLine.StartPoint); for (int i = 1; i < polyLine.Vertices.Count; i++) { Vertex v = polyLine.Vertices[i]; result.Segments.Add(new Media.LineSegment(Convert(v.Position), true)); } if (polyLine.Closed && polyLine.Vertices.Count > 0) { result.Segments.Add(new Media.LineSegment(Convert(polyLine.Vertices[0].Position), true)); } return(result); }
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); }
/// <summary> /// Convert a Nucleus PolyCurve into a WPF PathFigure /// </summary> /// <param name="polyCurve"></param> /// <returns></returns> public static Media.PathFigure Convert(PolyCurve polyCurve) { Media.PathFigure result = new Media.PathFigure(); if (polyCurve.SubCurves.Count > 0) { result.StartPoint = Convert(polyCurve.StartPoint); foreach (Curve crv in polyCurve.SubCurves) { if (crv is Line) { result.Segments.Add(new Media.LineSegment(Convert(crv.EndPoint), true)); } else if (crv is Arc) { Arc arc = ((Arc)crv); double radius = arc.Circle.Radius; if (arc.Closed) { //Circle! result.Segments.Add(new Media.ArcSegment(Convert(arc.PointAt(0.5)), new W.Size(radius, radius), 0, true, Media.SweepDirection.Clockwise, true)); result.Segments.Add(new Media.ArcSegment(Convert(arc.EndPoint), new W.Size(radius, radius), 0, false, Media.SweepDirection.Clockwise, true)); } else { bool largeArc = arc.RadianMeasure.IsReflex; Media.SweepDirection dir = Media.SweepDirection.Clockwise; if (!arc.IsClockwise) { dir = Media.SweepDirection.Counterclockwise; } result.Segments.Add(new Media.ArcSegment(Convert(arc.EndPoint), new W.Size(radius, radius), 0, largeArc, dir, true)); } } else if (crv is PolyLine) { for (int i = 1; i < crv.Vertices.Count; i++) { Vertex v = crv.Vertices[i]; result.Segments.Add(new Media.LineSegment(Convert(v.Position), true)); } } } } return(result); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.vis_line = ((System.Windows.Shapes.Path)(target)); return; case 2: this.Edg_start_point = ((System.Windows.Media.PathFigure)(target)); return; case 3: this.Edg_end_point = ((System.Windows.Media.LineSegment)(target)); return; } this._contentLoaded = true; }
public static m.PathGeometry ListWinShapesPolyLineToPathGeometryOLD(List <shapes.Polyline> toConvert) { m.PathGeometry myPathGeometry = new m.PathGeometry(); foreach (shapes.Polyline polyline in toConvert) { m.PathFigure pf = new m.PathFigure(); m.PolyLineSegment pls = new m.PolyLineSegment(); pls.Points = polyline.Points; pf.Segments.Add(pls); pf.StartPoint = polyline.Points[0]; myPathGeometry.Figures.Add(pf); } return(myPathGeometry); }
/// <summary> /// Returns a Windows Media Path Geometry from a Rhinocommon Polyline /// </summary> /// <param name="input">Rhinocommon Polyline</param> /// <returns>System Windows Media Path Geometry</returns> public static Sm.PathGeometry ToGeometry(this Rg.Polyline input) { 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[0].ToWindowsPoint(); for (int i = 1; i < input.Count; i++) { Sm.LineSegment line = new Sm.LineSegment(input[i].ToWindowsPoint(), true); segmentCollection.Add(line); } figure.Segments = segmentCollection; figureCollection.Add(figure); geometry.Figures = figureCollection; return(geometry); }
public static m.PathGeometry TranslatePathGeometry(m.PathGeometry toTranslate, double xOffset, double yOffset, bool textElement = false) { if (textElement) { yOffset *= -1; } toTranslate = toTranslate.GetFlattenedPathGeometry(1, m.ToleranceType.Absolute); m.PathGeometry toReturn = new m.PathGeometry(); foreach (m.PathFigure oldPf in toTranslate.Figures) { m.PathFigure newPf = new m.PathFigure(); Point newStartPoint = oldPf.StartPoint; newStartPoint.X = newStartPoint.X + xOffset; newStartPoint.Y = newStartPoint.Y + yOffset; 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.X = tmp.X + xOffset; tmp.Y = tmp.Y + yOffset; ((m.PolyLineSegment)newPs).Points.Add(tmp); } newPf.Segments.Add(newPs); } toReturn.Figures.Add(newPf); } return(toReturn); }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.userControl = ((ClientForFPGAService.CircularProgressBar)(target)); return; case 2: this.pathRoot = ((System.Windows.Shapes.Path)(target)); return; case 3: this.pathFigure = ((System.Windows.Media.PathFigure)(target)); return; case 4: this.arcSegment = ((System.Windows.Media.ArcSegment)(target)); return; } this._contentLoaded = true; }