internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { // Combine the transform argument with the internal transform Matrix matrix = GetCombinedMatrix(transform); // Get the figure collection PathFigureCollection result; if (matrix.IsIdentity) { // There is no need to transform, return the figure collection result = Figures; if (result == null) { result = new PathFigureCollection(); } } else { // Return a transformed copy of the figure collection result = new PathFigureCollection(); PathFigureCollection figures = Figures; int count = figures != null ? figures.Count : 0; for (int i = 0; i < count; ++i) { PathFigure figure = figures.Internal_GetItem(i); result.Add(figure.GetTransformedCopy(matrix)); } } Debug.Assert(result != null); return(result); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { Point [] points = GetPointList(); // Get the combined transform argument with the internal transform Matrix matrix = GetCombinedMatrix(transform); if (!matrix.IsIdentity) { for (int i = 0; i < points.Length; i++) { points[i] *= matrix; } } PathFigureCollection figureCollection = new PathFigureCollection(); figureCollection.Add( new PathFigure( points[0], new PathSegment[] { new BezierSegment(points[1], points[2], points[3], true, true), new BezierSegment(points[4], points[5], points[6], true, true), new BezierSegment(points[7], points[8], points[9], true, true), new BezierSegment(points[10], points[11], points[12], true, true) }, true ) ); return(figureCollection); }
/// <summary> /// /// </summary> public void AddGeometry(Geometry geometry) { if (geometry == null) { throw new System.ArgumentNullException("geometry"); } if (geometry.IsEmpty()) { return; } PathFigureCollection figureCollection = geometry.GetPathFigureCollection(); Debug.Assert(figureCollection != null); PathFigureCollection figures = Figures; if (figures == null) { figures = Figures = new PathFigureCollection(); } for (int i = 0; i < figureCollection.Count; ++i) { figures.Add(figureCollection.Internal_GetItem(i)); } }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { // Combine the transform argument with the internal transform Transform combined = new MatrixTransform(GetCombinedMatrix(transform)); PathFigureCollection result = new PathFigureCollection(); GeometryCollection children = Children; if (children != null) { for (int i = 0; i < children.Count; i++) { PathFigureCollection pathFigures = children.Internal_GetItem(i).GetTransformedFigureCollection(combined); if (pathFigures != null) { int count = pathFigures.Count; for (int j = 0; j < count; ++j) { result.Add(pathFigures[j]); } } } } return(result); }
/// <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); }
/// <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> /// 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); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { // This is lossy for consistency with other GetPathFigureCollection() implementations // however this limitation doesn't otherwise need to exist for LineGeometry. Point startPoint = StartPoint; Point endPoint = EndPoint; // Apply internal transform Transform internalTransform = Transform; if (internalTransform != null && !internalTransform.IsIdentity) { Matrix matrix = internalTransform.Value; startPoint *= matrix; endPoint *= matrix; } // Apply external transform if (transform != null && !transform.IsIdentity) { Matrix matrix = transform.Value; startPoint *= matrix; endPoint *= matrix; } PathFigureCollection collection = new PathFigureCollection(); collection.Add( new PathFigure( startPoint, new PathSegment[] { new LineSegment(endPoint, true) }, false // ==> not closed ) ); return(collection); }
/// <summary> /// Equilateral triangle of side 'sideLength', centered on the same point as if a circle of diameter 'sideLength' was there /// </summary> private static XamlMedia.PathGeometry CreateTriangle(double sideLength) { var altitude = Math.Sqrt(3) / 2.0 * sideLength; var inradius = altitude / 3.0; var circumradius = 2.0 * inradius; var top = new XamlPoint(0, -circumradius); var left = new XamlPoint(sideLength * -0.5, inradius); var right = new XamlPoint(sideLength * 0.5, inradius); var segments = new XamlMedia.PathSegmentCollection(); segments.Add(new XamlMedia.LineSegment(left, true)); segments.Add(new XamlMedia.LineSegment(right, true)); var figure = new XamlMedia.PathFigure(top, segments, true); var figures = new XamlMedia.PathFigureCollection(); figures.Add(figure); return(new XamlMedia.PathGeometry { Figures = figures }); }
/// <summary> /// Returns a Windows Media Bezier Spline Path Geometry from a Rhinocommon Curve /// </summary> /// <param name="input">Rhinocommon Curve</param> /// <returns>System Windows Media Bezier Curve Path Geometry </returns> public static Sm.PathGeometry ToGeometry(this Rg.Curve input) { Rg.NurbsCurve nurbsCurve = input.ToNurbsCurve(); nurbsCurve.MakePiecewiseBezier(true); Rg.BezierCurve[] bezier = Rg.BezierCurve.CreateCubicBeziers(nurbsCurve, 0, 0); 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 = bezier[0].GetControlVertex3d(0).ToWindowsPoint(); for (int i = 0; i < bezier.Count(); i++) { Sm.BezierSegment segment = new Sm.BezierSegment(bezier[i].GetControlVertex3d(1).ToWindowsPoint(), bezier[i].GetControlVertex3d(2).ToWindowsPoint(), bezier[i].GetControlVertex3d(3).ToWindowsPoint(), true); segmentCollection.Add(segment); } figure.Segments = segmentCollection; figureCollection.Add(figure); geometry.Figures = figureCollection; return(geometry); }
internal override PathFigureCollection GetTransformedFigureCollection(Transform transform) { if (IsEmpty()) { return(null); } // Combine the transform argument with the internal transform Matrix matrix = GetCombinedMatrix(transform); double radiusX = RadiusX; double radiusY = RadiusY; Rect rect = Rect; if (IsRounded(radiusX, radiusY)) { Point[] points = GetPointList(rect, radiusX, radiusY); // Transform if applicable. if (!matrix.IsIdentity) { for (int i = 0; i < points.Length; i++) { points[i] *= matrix; } } PathFigureCollection collection = new PathFigureCollection(); collection.Add( new PathFigure( points[0], new PathSegment[] { new BezierSegment(points[1], points[2], points[3], true, true), new LineSegment(points[4], true, true), new BezierSegment(points[5], points[6], points[7], true, true), new LineSegment(points[8], true, true), new BezierSegment(points[9], points[10], points[11], true, true), new LineSegment(points[12], true, true), new BezierSegment(points[13], points[14], points[15], true, true) }, true // closed ) ); return(collection); } else { PathFigureCollection collection = new PathFigureCollection(); collection.Add( new PathFigure( rect.TopLeft * matrix, new PathSegment[] { new PolyLineSegment( new Point[] { rect.TopRight *matrix, rect.BottomRight *matrix, rect.BottomLeft *matrix }, true) }, true // closed ) ); return(collection); } }