/// <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(); }
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; }
public void Load(byte[] audioData, AudioFormat format) { this.ClearGraph(); this.format = format; this.audioData = audioData; var graph = new PolyLineSegment(); int step = this.GetSampleStep(); int index = 0; int count = 0; double yScale = (this.audioCanvas.Height / 2) / short.MaxValue; int leftSampleCount = audioData.Length / 4; //assume 2 channels int actualLeftSampleCount = leftSampleCount / (step / 4); while (index < audioData.Length) { short sample = BitConverter.ToInt16(new byte[2] { audioData[index], audioData[index + 1] }, 0); double yPoint = sample * yScale + (this.audioCanvas.Height / 2); double xPoint = count * this.audioCanvas.Width / actualLeftSampleCount; graph.Points.Add(new Point() { X = xPoint, Y = yPoint }); index += step; count++; } this.figure.Segments.Add(graph); }
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); }
// 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 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); }
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 RoomControl(Room room, int numRows, double sw, double sh) { _numRows = numRows; _sw = sw; _sh = sh; InitializeComponent(); var insideEdges = new List<Coords>(); var outsideEdges = new List<Coords>(); foreach (var cell in room.Cells) { var rect = new Rect(cell.Col * _sw, (_numRows - cell.Row - 1) * _sh, _sw, _sh); var rectangle = new Rectangle { Width = rect.Width, Height = rect.Height }; Canvas.SetLeft(rectangle, rect.Left); Canvas.SetTop(rectangle, rect.Top); rectangle.Fill = new SolidColorBrush(_cellColour); RoomCanvas.Children.Add(rectangle); DetermineEdges(insideEdges, outsideEdges, room.Cells, cell.Col, cell.Row); } // TODO: we should probably de-dup insideEdges. // e.g. [(1, 1), (1, 0), (1, 0), (1, 1)] => [(1, 1), (1, 0)] var insideEdgeLinePoints = CalculateEdgeLinePoints(insideEdges); for (var i = 0; i < insideEdgeLinePoints.Count/2; i++) { var pt1 = insideEdgeLinePoints[i * 2]; var pt2 = insideEdgeLinePoints[i * 2 + 1]; var line = new Line { X1 = pt1.X, Y1 = pt1.Y, X2 = pt2.X, Y2 = pt2.Y, Stroke = new SolidColorBrush(_innerCellLineColour), StrokeThickness = InnerCellLineWidth }; RoomCanvas.Children.Add(line); } var combinedOutsideEdges = CombineOutsideEdges(outsideEdges); var outsideEdgeLinePoints = CalculateEdgeLinePoints(combinedOutsideEdges); var polyLineSegment = new PolyLineSegment(outsideEdgeLinePoints, true); var pathFigure = new PathFigure { StartPoint = outsideEdgeLinePoints.First() }; pathFigure.Segments.Add(polyLineSegment); var pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); var path = new Path { Stroke = new SolidColorBrush(_outerCellLineColour), StrokeThickness = OuterCellLineWidth, StrokeEndLineCap = PenLineCap.Square, Data = pathGeometry }; RoomCanvas.Children.Add(path); }
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 static void FillPolylineGeometry(this DrawingContext dc, Point startPoint, PointCollection points) { PathGeometry geometry = new PathGeometry(); PolyLineSegment segment = new PolyLineSegment(); segment.Points = points; PathFigure fig = new PathFigure(startPoint, new[] { segment }, true); geometry.Figures.Add(fig); dc.DrawGeometry(Brushes.Black, null, geometry); }
public static void DrawPolyline(this DrawingContext dc, Point startPoint, PointCollection points, Pen pen) { PathGeometry geometry = new PathGeometry(); PolyLineSegment segment = new PolyLineSegment(); segment.Points = points; PathFigure fig = new PathFigure(startPoint, new[] { segment }, false); geometry.Figures.Add(fig); dc.DrawGeometry(null, pen, geometry); }
public new void Tessellate(IRenderPackage package, TessellationParameters parameters) { // Offset for text adjustments double horizontalOffset = 0; // Get Conversion factor according to the documents units double factor = Revit.GeometryConversion.UnitConverter.DynamoToHostFactor(UnitType.UT_Length); // Get Text outline path at 0,0 PathGeometry path = CreateText(this.Value, this.Bold, this.Italic, new FontFamily(this.FontFamilyName), this.FontSize * Scale / factor, new System.Windows.Point(0, 0)); // Apply horizontal Text offset if (Alignment == HorizontalTextAlignment.Center) { horizontalOffset = path.Bounds.Width / 2; } if (Alignment == HorizontalTextAlignment.Right) { horizontalOffset = path.Bounds.Width; } // Walk thorugh all figures and draw lines foreach (PathFigure figure in path.Figures) { // Rotate the start point and apply offsets var startPoint = RotatePoint(new System.Windows.Point(figure.StartPoint.X - horizontalOffset, figure.StartPoint.Y * -1), this.Rotation); package.AddLineStripVertex(startPoint.X + Location.X, startPoint.Y + Location.Y, this.Location.Z); foreach (PathSegment segment in figure.Segments) { if (segment is System.Windows.Media.PolyLineSegment) { System.Windows.Media.PolyLineSegment pline = segment as System.Windows.Media.PolyLineSegment; for (int i = 0; i < pline.Points.Count; i++) { System.Windows.Point point = pline.Points[i]; // rotate point and apply offsets var pLinePoint = RotatePoint(new System.Windows.Point(point.X - horizontalOffset, point.Y * -1), this.Rotation); package.AddLineStripVertex(pLinePoint.X + Location.X, pLinePoint.Y + Location.Y, this.Location.Z); // send the same point again to continue drawing if (i < pline.Points.Count - 1) { package.AddLineStripVertex(pLinePoint.X + Location.X, pLinePoint.Y + Location.Y, this.Location.Z); } } } } } if (package.LineVertexCount > 0) { package.ApplyLineVertexColors(CreateColorByteArrayOfSize(package.LineVertexCount, DefR, DefG, DefB, DefA)); } }
public BorderPainter() { var brush = new SolidColorBrush(Colors.Orange); brush.Freeze(); _pen = new Pen(brush, 3); _transform = new ScaleTransform(0, 0); _geometry = new PathGeometry(); _geometry.FillRule = FillRule.EvenOdd; var figure = new PathFigure(); var polyline = new PolyLineSegment(); polyline.IsStroked = true; figure.Segments.Add(polyline); figure.IsClosed = true; _geometry.Figures.Add(figure); }
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> /// Initializes a new instance of ArrowLineBase. /// </summary> public ArrowLineBase() { pathgeo = new PathGeometry(); pathfigLine = new PathFigure(); polysegLine = new PolyLineSegment(); pathfigLine.Segments.Add(polysegLine); pathfigHead1 = new PathFigure(); polysegHead1 = new PolyLineSegment(); pathfigHead1.Segments.Add(polysegHead1); pathfigHead2 = new PathFigure(); polysegHead2 = new PolyLineSegment(); pathfigHead2.Segments.Add(polysegHead2); }
/// <summary> /// Creates a path geometry form a polygon. /// </summary> public static PathGeometry CreatePolygonGeometry(System.Windows.Point[] points, XFillMode fillMode, bool closed) { PolyLineSegment seg = new PolyLineSegment(); int count = points.Length; // For correct drawing the start point of the segment must not be the same as the first point for (int idx = 1; idx < count; idx++) seg.Points.Add(new System.Windows.Point(points[idx].X, points[idx].Y)); seg.IsStroked = true; PathFigure fig = new PathFigure(); fig.StartPoint = new System.Windows.Point(points[0].X, points[0].Y); fig.Segments.Add(seg); fig.IsClosed = closed; PathGeometry geo = new PathGeometry(); geo.FillRule = fillMode == XFillMode.Winding ? FillRule.Nonzero : FillRule.EvenOdd; geo.Figures.Add(fig); return geo; }
private static PathGeometry CreatePath(Line l1, Line l2) { var geometry = new PathGeometry(); var figure = new PathFigure { StartPoint = l1.StartPoint, IsClosed = true, IsFilled = true, }; var polyLineSegment = new PolyLineSegment(); polyLineSegment.Points.Add(l1.EndPoint); polyLineSegment.Points.Add(l2.EndPoint); polyLineSegment.Points.Add(l2.StartPoint); figure.Segments.Add(polyLineSegment); geometry.Figures.Add(figure); return geometry; }
private PathGeometry CreateLineCurveGeometry() { PathGeometry pathGeometry = new PathGeometry(); PathFigure pathFigure = new PathFigure(); pathGeometry.Figures.Add(pathFigure); pathFigure.StartPoint = (Point)GeometryOperation.ComputeIntersectionPoint((FrameworkElement)InternalChildren[0], (FrameworkElement)InternalChildren[1]); PolyLineSegment pls = new PolyLineSegment(); for(int i=1; i < InternalChildren.Count; i++) pls.Points.Add(GeometryOperation.ComputeIntersectionPoint((FrameworkElement)InternalChildren[i], ((FrameworkElement)InternalChildren[i-1]))); pathFigure.Segments.Add(pls); if(AreaBrush!=null) { pathFigure.Segments.Add(new LineSegment(new Point(_childrenPositions[_childrenPositions.Count - 1].X, GetHorizontalAxis(this)), false)); pathFigure.Segments.Add(new LineSegment(new Point(_childrenPositions[0].X, GetHorizontalAxis(this)), false)); } return pathGeometry; }
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> /// Gets a five-pointed star with the specified size and center. /// </summary> public static Geometry GetPentagram(double size, Vector center) { PathGeometry geo = new PathGeometry(); PathFigure figure = new PathFigure(); geo.Figures.Add(figure); PolyLineSegment seg = new PolyLineSegment(); figure.Segments.Add(seg); int[] order = new int[] { 0, 3, 1, 4, 2 }; for (int idx = 0; idx < 5; idx++) { double rad = order[idx] * 2 * Math.PI / 5 - Math.PI / 10; Point point = new Point(Math.Cos(rad) * size, Math.Sin(rad) * size) + center; if (idx == 0) figure.StartPoint = point; else seg.Points.Add(point); } return geo; }
protected override PathFigure CreateSourceCapGeometry(System.Windows.Point startPoint, System.Windows.Point endPoint, ref System.Windows.Point baseLineStart) { baseLineStart = startPoint; var size = this.SourceCapSize; var topLeft = new Point(startPoint.X - size.Width / 2, startPoint.Y - size.Height / 2); var result = new PathFigure(); result.StartPoint = topLeft; var rect = new PolyLineSegment(); rect.Points.Add(topLeft); rect.Points.Add(new Point(topLeft.X + size.Width, topLeft.Y)); rect.Points.Add(new Point(topLeft.X + size.Width, topLeft.Y + size.Height)); rect.Points.Add(new Point(topLeft.X, topLeft.Y + size.Height)); result.Segments.Add(rect); return result; }
static WrapModeComboBox() { PolyLineSegment triangleLinesSegment = new PolyLineSegment(); triangleLinesSegment.Points.Add(new Point(50, 0)); triangleLinesSegment.Points.Add(new Point(0, 50)); PathFigure triangleFigure = new PathFigure(); triangleFigure.IsClosed = true; triangleFigure.StartPoint = new Point(0, 0); triangleFigure.Segments.Add(triangleLinesSegment); PathGeometry triangleGeometry = new PathGeometry(); triangleGeometry.Figures.Add(triangleFigure); triangleDrawing = new GeometryDrawing(); triangleDrawing.Geometry = triangleGeometry; triangleDrawing.Brush = new SolidColorBrush(Color.FromArgb(255, 204, 204, 255)); Pen trianglePen = new Pen(Brushes.Black, 2); triangleDrawing.Pen = trianglePen; trianglePen.MiterLimit = 0; triangleDrawing.Freeze(); }
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); }
private Path GenerateSeriesPath(List<Tuple<double, double>> ansv) { var myPath = new Path { Height = MyCanvas.Height, Width = MyCanvas.Width, Stroke = Brushes.Black, StrokeThickness = 3 }; myPath.MouseLeftButtonUp += (sender, args) => { if (Equals((sender as Path).Stroke, Brushes.Black)) { (sender as Path).Stroke = Brushes.Red; ActiveLabel.Content = _seriesComments[MyCanvas.Children.IndexOf(sender as Path) - 3]; } else { (sender as Path).Stroke = Brushes.Black; ActiveLabel.Content = "Select plot for further info"; } }; var segment = new PolyLineSegment(); double scaleY = MyCanvas.Height / ansv.Max(item => item.Item2); double scaleX = MyCanvas.Width / ansv.Max(item => item.Item1); for (int i = 0; i < ansv.Count; i++) { segment.Points.Add(new Point(ansv[i].Item1 * scaleX, MyCanvas.Height - ansv[i].Item2 * scaleY)); } var fig = new PathFigure(); fig.Segments.Add(segment); fig.StartPoint = segment.Points.First(); var geom = new PathGeometry(); geom.Figures.Add(fig); myPath.Data = geom; return myPath; }
public static List <m.PolyLineSegment> PathGeometryToPlsList(m.PathGeometry allPointsContainer) { List <m.PolyLineSegment> toReturn = new List <m.PolyLineSegment>(); foreach (m.PathFigure figures in allPointsContainer.Figures) // figure = geschlossene umrisslinie { m.PolyLineSegment singlePls = new m.PolyLineSegment(); singlePls.Points.Add(figures.StartPoint); foreach (m.PathSegment segment in figures.Segments) { //segment = offener Linien Typ (z.B. Bezier, PolyLineSegment etc) if (segment is m.PolyLineSegment) { foreach (Point point in ((m.PolyLineSegment)segment).Points) { singlePls.Points.Add(point); } Point tmp = ((m.PolyLineSegment)segment).Points[0]; singlePls.Points.Add(tmp); // fügt startpunkt hinzu damit der kreis geschlossen ist } else if (segment is m.LineSegment) { Point tmp = ((m.LineSegment)segment).Point; singlePls.Points.Add(tmp); // fügt startpunkt hinzu damit der kreis geschlossen ist } else { throw new Exception( "zu konvertierende PathGeometry beinhaltet weder PolyLineSegments noch LineSegments"); } } toReturn.Add(singlePls); } return(toReturn); }
/// <summary> /// FinishSegment - called to completed any outstanding Segment which may be present. /// </summary> private void FinishSegment() { if (_currentSegmentPoints != null) { Debug.Assert(_currentFigure != null); int count = _currentSegmentPoints.Count; Debug.Assert(count > 0); // Is this the first segment? if (_segments == null) { // While we could always just retrieve _currentFigure.Segments (which would auto-promote) // it's more efficient to create the collection ourselves and set it explicitly. _segments = new PathSegmentCollection(); _currentFigure.Segments = _segments; } PathSegment segment; switch (_currentSegmentType) { case MIL_SEGMENT_TYPE.MilSegmentPolyLine: if (count == 1) { LineSegment lSegment = new LineSegment(); lSegment.Point = _currentSegmentPoints[0]; segment = lSegment; } else { PolyLineSegment pSegment = new PolyLineSegment(); pSegment.Points = _currentSegmentPoints; segment = pSegment; } break; case MIL_SEGMENT_TYPE.MilSegmentPolyBezier: if (count == 3) { BezierSegment bSegment = new BezierSegment(); bSegment.Point1 = _currentSegmentPoints[0]; bSegment.Point2 = _currentSegmentPoints[1]; bSegment.Point3 = _currentSegmentPoints[2]; segment = bSegment; } else { Debug.Assert(count % 3 == 0); PolyBezierSegment pSegment = new PolyBezierSegment(); pSegment.Points = _currentSegmentPoints; segment = pSegment; } break; case MIL_SEGMENT_TYPE.MilSegmentPolyQuadraticBezier: if (count == 2) { QuadraticBezierSegment qSegment = new QuadraticBezierSegment(); qSegment.Point1 = _currentSegmentPoints[0]; qSegment.Point2 = _currentSegmentPoints[1]; segment = qSegment; } else { Debug.Assert(count % 2 == 0); PolyQuadraticBezierSegment pSegment = new PolyQuadraticBezierSegment(); pSegment.Points = _currentSegmentPoints; segment = pSegment; } break; default: segment = null; Debug.Assert(false); break; } // Handle common PathSegment properties. if (_currentSegmentIsStroked != s_defaultValueForPathSegmentIsStroked) { segment.IsStroked = _currentSegmentIsStroked; } if (_currentSegmentIsSmoothJoin != s_defaultValueForPathSegmentIsSmoothJoin) { segment.IsSmoothJoin = _currentSegmentIsSmoothJoin; } _segments.Add(segment); _currentSegmentPoints = null; _currentSegmentType = MIL_SEGMENT_TYPE.MilSegmentNone; } }
// Fill a polygon with a brush public void FillPolygon(Brush brush, PointF[] pts, bool winding) { Point[] points = new Point[pts.Length]; for (int i = 0; i < pts.Length; ++i) points[i] = new Point(pts[i].X, pts[i].Y); PathSegment segment = new PolyLineSegment(points, true); PathFigure figure = new PathFigure(points[points.Length - 1], new PathSegment[] { segment }, true); PathGeometry geometry = new PathGeometry(new PathFigure[] { figure }, winding ? FillRule.Nonzero : FillRule.EvenOdd, System.Windows.Media.Transform.Identity); DrawingContext.DrawGeometry(brush, null, geometry); }
public void Draw() { PathFigure path = new PathFigure(); PathFigureCollection pathColl = new PathFigureCollection(); PolyLineSegment points = new PolyLineSegment(); PathSegmentCollection pathSeg = new PathSegmentCollection(); PathGeometry pathGeo = new PathGeometry(); Pen thinPen = new Pen(Brushes.Transparent, 0.0001); points.Points = tail.GetPoints(); path.StartPoint = startingPoint; pathSeg.Add(points); path.StartPoint = points.Points.ElementAt(0); path.Segments = pathSeg; pathColl.Add(path); pathGeo.Figures = pathColl; myPath.Data = pathGeo; }
private void UserDrawWPF(DrawingContext dc) { System.Windows.Media.Color m_LineColor = System.Windows.Media.Colors.Gold; System.Windows.Media.SolidColorBrush m_LineColorBrush = System.Windows.Media.Brushes.Gold; int m_LineWidth = 4; try { int PixelX = 0; int PixelY = 0; if (pntSource.X != 0.0 && pntSource.Y != 0.0) { VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntSource.X, pntSource.Y, ref PixelX, ref PixelY); ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_blue.png")); Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22); } if (pntTarget.X != 0.0 && pntTarget.Y != 0.0) { VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntTarget.X, pntTarget.Y, ref PixelX, ref PixelY); ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_red.png")); Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22); } if (m_PolygonPnts == null) { return; } // if (m_PolygonPnts.Count == 0) return; // m_LineColor = System.Windows.Media.Colors.Gold; // m_LineColorBrush.Color = System.Windows.Media.Colors.Gold; System.Windows.Media.Pen pen = new System.Windows.Media.Pen(m_LineColorBrush, m_LineWidth); pen.Thickness = m_LineWidth; pen.LineJoin = PenLineJoin.Round; System.Windows.Point[] m_ScreenPnts = new System.Windows.Point[m_PolygonPnts.Count]; for (int i = 0; i < m_PolygonPnts.Count; i++) { // int PixelX = 0; // int PixelY = 0; VMMainViewModel.Instance.ConvertCoordGroundToPixel(m_PolygonPnts[i].X, m_PolygonPnts[i].Y, ref PixelX, ref PixelY); m_ScreenPnts[i].X = PixelX; m_ScreenPnts[i].Y = PixelY; } if (m_ScreenPnts.Length > 1) { 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); pathFigure.IsClosed = false; dc.DrawGeometry(null, pen, PathGmtr); } if (dtGridRoute != null) { FormattedText frm = new FormattedText("o", System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.RightToLeft, new System.Windows.Media.Typeface("Arial"), 18, System.Windows.Media.Brushes.Red); for (int i = 0; i < dtGridRoute.Items.Count; i++) { if (dtGridRoute.SelectedIndex == i) { frm.SetFontSize(24); } else { frm.SetFontSize(18); } OsmRouteData DetailData = ((List <OsmRouteData>)dtGridRoute.ItemsSource)[i]; VMMainViewModel.Instance.ConvertCoordGroundToPixel(DetailData.X, DetailData.Y, ref PixelX, ref PixelY); frm.SetFontWeight(System.Windows.FontWeights.Bold); frm.TextAlignment = TextAlignment.Center; dc.DrawText(frm, new System.Windows.Point(PixelX - frm.Width / 2, PixelY - frm.Height / 2)); FormattedText frmNum = new FormattedText((i + 1).ToString(), System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Windows.FlowDirection.LeftToRight, new System.Windows.Media.Typeface("Arial"), 14, System.Windows.Media.Brushes.Red); frmNum.SetFontWeight(System.Windows.FontWeights.Bold); dc.DrawText(frmNum, new System.Windows.Point(PixelX, PixelY)); } } } catch (Exception ex) { } }
GetCurveThroughPoints ( IList<Point> points, Double tension, Double tolerance ) { Debug.Assert(points != null); Debug.Assert(points.Count >= 2); Debug.Assert(tolerance > 0); PolyLineSegment oPolyLineSegment = new PolyLineSegment(); if (points.Count == 2) { AddPointsToPolyLineSegment(oPolyLineSegment, points[0], points[0], points[1], points[1], tension, tolerance); } else { Int32 iPoints = points.Count; for (Int32 i = 0; i < iPoints; i++) { if (i == 0) { AddPointsToPolyLineSegment(oPolyLineSegment, points[0], points[0], points[1], points[2], tension, tolerance); } else if (i == iPoints - 2) { AddPointsToPolyLineSegment(oPolyLineSegment, points[i - 1], points[i], points[i + 1], points[i + 1], tension, tolerance); } else if (i != iPoints - 1) { AddPointsToPolyLineSegment(oPolyLineSegment, points[i - 1], points[i], points[i + 1], points[i + 2], tension, tolerance); } } } return ( GetPathGeometryFromPathSegments( points[0], false, oPolyLineSegment) ); }
private void UpdateElements() { ImagePS2D.Clip = new EllipseGeometry(new Point(ImagePS2D.ActualWidth / 2, 0), ImagePS2D.ActualWidth / 2, ImagePS2D.ActualHeight); ImageSimulated2D.Clip = new EllipseGeometry(new Point(ImageSimulated2D.ActualWidth, ImageSimulated2D.ActualHeight), ImageSimulated2D.ActualWidth, ImageSimulated2D.ActualHeight); if (PS2D == null) { ImagePS2D.Source = null; ImageSimulated2D.Source = null; CanvasCurves1D.Visibility = Visibility.Hidden; return; } CanvasCurves1D.Visibility = Visibility.Visible; ImagePS2D.Source = PS2D; ImageSimulated2D.Source = Simulated2D; double MinPS = float.MaxValue, MaxPS = -float.MaxValue; double MaxX = -float.MaxValue; if (PS1D == null && Simulated1D == null) { MinPS = 0; MaxPS = MaxX = 1; RectangleRange.Width = 0; } else { Canvas.SetLeft(RectangleRange, (double)FreqRangeMin * CanvasCurves1D.ActualWidth); RectangleRange.Width = (double) Math.Max(0, FreqRangeMax - FreqRangeMin) * CanvasCurves1D.ActualWidth; RectangleRange.Height = CanvasCurves1D.ActualHeight; // Min is absolute minimum, max is min(mean + 2.5 * stddev, absolute maximum). if (PS1D != null) { int IndexMin = (int)(FreqRangeMin * PS1D.Length); int IndexMax = (int) (FreqRangeMax * PS1D.Length); float2[] ForPS1D = PS1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); MinPS = ForPS1D.Aggregate(MinPS, (current, p) => Math.Min(current, p.Y)); float Max = MathHelper.Max(ForPS1D.Select(i => i.Y)); MaxPS = Math.Max(MaxPS, Math.Min(Max, MathHelper.Mean(ForPS1D.Select(i => i.Y)) + MathHelper.StdDev(ForPS1D.Select(i => i.Y)) * 3.0)); MaxX = Math.Max(MathHelper.Max(PS1D.Select(i => i.X)), MaxX); } if (Simulated1D != null) { int IndexMin = (int)(FreqRangeMin * Simulated1D.Length); int IndexMax = (int)(FreqRangeMax * Simulated1D.Length); float2[] ForSimulated1D = Simulated1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); MinPS = ForSimulated1D.Aggregate(MinPS, (current, p) => Math.Min(current, p.Y)); float Max = MathHelper.Max(ForSimulated1D.Select(i => i.Y)); MaxPS = Math.Max(MaxPS, Math.Min(Max, MathHelper.Mean(ForSimulated1D.Select(i => i.Y)) + MathHelper.StdDev(ForSimulated1D.Select(i => i.Y)) * 3.0)); MaxX = Math.Max(MathHelper.Max(Simulated1D.Select(i => i.X)), MaxX); } } double ExtentPS = MaxPS - MinPS; double HeightPS = 1.0 * CanvasCurves1D.ActualHeight - 8.0; double WidthPS = 1.0 * CanvasCurves1D.ActualWidth; double ScaleX = WidthPS / MaxX; double ScaleY = HeightPS / ExtentPS; double MinBottom = 0; if (PS1D != null) { int IndexMin = (int)(FreqRangeMin * PS1D.Length); int IndexMax = (int)(FreqRangeMax * PS1D.Length); float2[] ForPS1D = PS1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); List<Point> PlotPoints = PS1D.Select(point => new Point(point.X * ScaleX, HeightPS - (point.Y - MinPS) * ScaleY + 4.0)).ToList(); MinBottom = Math.Min(MinBottom, (MathHelper.Min(ForPS1D.Select(i => i.Y)) - MinPS) * ScaleY + (HeightPS - MathHelper.Max(PlotPoints.Select(point => (float)point.Y))) + 6.0); } if (Simulated1D != null) { int IndexMin = (int)(FreqRangeMin * Simulated1D.Length); int IndexMax = (int)(FreqRangeMax * Simulated1D.Length); float2[] ForSimulated1D = Simulated1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); List<Point> PlotPoints = Simulated1D.Select(point => new Point(point.X * ScaleX, HeightPS - (point.Y - MinPS) * ScaleY + 4.0)).ToList(); MinBottom = Math.Min(MinBottom, (MathHelper.Min(ForSimulated1D.Select(i => i.Y)) - MinPS) * ScaleY + (HeightPS - MathHelper.Max(PlotPoints.Select(point => (float)point.Y))) + 6.0); } if (PS1D != null) { int IndexMin = (int)(FreqRangeMin * PS1D.Length); int IndexMax = (int)(FreqRangeMax * PS1D.Length); float2[] ForPS1D = PS1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); List<Point> PlotPoints = PS1D.Select(point => new Point(point.X * ScaleX, HeightPS - (point.Y - MinPS) * ScaleY + 4.0)).ToList(); PolyLineSegment PlotSegment = new PolyLineSegment(PlotPoints, true); PathFigure PlotFigure = new PathFigure { Segments = new PathSegmentCollection { PlotSegment }, StartPoint = PlotPoints[0]}; PathPS1D.Data = new PathGeometry { Figures = new PathFigureCollection { PlotFigure } }; Canvas.SetBottom(PathPS1D, HeightPS - MathHelper.Max(PlotPoints.Select(point => (float)point.Y)) + 6.0); } if (Simulated1D != null) { int IndexMin = (int)(FreqRangeMin * Simulated1D.Length); int IndexMax = (int)(FreqRangeMax * Simulated1D.Length); float2[] ForSimulated1D = Simulated1D.Skip(IndexMin).Take(Math.Max(1, IndexMax - IndexMin)).ToArray(); List<Point> PlotPoints = ForSimulated1D.Select(point => new Point(point.X * ScaleX, HeightPS - (point.Y - MinPS) * ScaleY + 4.0)).ToList(); PolyLineSegment PlotSegment = new PolyLineSegment(PlotPoints, true); PathFigure PlotFigure = new PathFigure { Segments = new PathSegmentCollection { PlotSegment }, StartPoint = PlotPoints[0] }; PathSimulated1D.Data = new PathGeometry { Figures = new PathFigureCollection { PlotFigure } }; Canvas.SetBottom(PathSimulated1D, HeightPS - MathHelper.Max(PlotPoints.Select(point => (float)point.Y)) + 6.0); } if (Quality != null) { int QualityLimit = Quality.Length - 1; for (int i = 0; i < Quality.Length - 1; i++) if (Math.Max(Quality[i].Y, Quality[i + 1].Y) < (float) QualityThreshold) { QualityLimit = i; break; } float2[] QualityGood = Quality.Take(QualityLimit + 1).ToArray(); float2[] QualityBad = Quality.Skip(QualityLimit).ToArray(); float MinGlobal = MathHelper.Min(Quality.Select(v => v.Y)); if (QualityGood.Length > 1) { float MinGood = MathHelper.Min(QualityGood.Select(v => v.Y)); List<Point> PlotPoints = QualityGood.Select(point => new Point(point.X * ScaleX, (1.0 - point.Y) * 2.0 / 3.0 * HeightPS)).ToList(); PolyLineSegment PlotSegment = new PolyLineSegment(PlotPoints, true); PathFigure PlotFigure = new PathFigure { Segments = new PathSegmentCollection {PlotSegment}, StartPoint = PlotPoints[0] }; PathGoodQuality.Data = new PathGeometry {Figures = new PathFigureCollection {PlotFigure}}; CanvasGoodQuality.Height = MathHelper.Max(PlotPoints.Select(point => (float) point.Y)); Canvas.SetBottom(CanvasGoodQuality, HeightPS * 2.0 / 3.0 - MathHelper.Max(PlotPoints.Select(point => (float)point.Y))); } else PathGoodQuality.Data = null; if (QualityBad.Length > 1) { float MinBad = MathHelper.Min(QualityBad.Select(v => v.Y)); List<Point> PlotPoints = QualityBad.Select(point => new Point(point.X * ScaleX, (1.0 - point.Y) * 2.0 / 3.0 * HeightPS)).ToList(); PolyLineSegment PlotSegment = new PolyLineSegment(PlotPoints, true); PathFigure PlotFigure = new PathFigure { Segments = new PathSegmentCollection {PlotSegment}, StartPoint = PlotPoints[0] }; PathBadQuality.Data = new PathGeometry {Figures = new PathFigureCollection {PlotFigure}}; CanvasBadQuality.Height = MathHelper.Max(PlotPoints.Select(point => (float)point.Y)); Canvas.SetBottom(CanvasBadQuality, HeightPS * 2.0 / 3.0 - MathHelper.Max(PlotPoints.Select(point => (float)point.Y))); } else PathBadQuality.Data = null; } else { PathGoodQuality.Data = null; PathBadQuality.Data = null; } // Quality threshold { Canvas.SetBottom(PanelQualityThreshold, HeightPS * 2.0 / 3.0 * (double) QualityThreshold); TextQualityThreshold.Text = $"{QualityThreshold:0.00}"; double QualityMinX = 0; if (Quality != null) QualityMinX = MathHelper.Min(Quality.Select(i => i.X)); double QualityWidth = (MaxX - QualityMinX) * ScaleX; LineQualityThreshold.X2 = QualityWidth; } }
/// <summary> /// Draws a series of line segments that connect an array of points. /// </summary> public void DrawLines(XPen pen, XPoint[] points) { if (pen == null) throw new ArgumentNullException("pen"); if (points == null) throw new ArgumentNullException("points"); if (points.Length < 2) throw new ArgumentException("points", PSSR.PointArrayAtLeast(2)); if (this.drawGraphics) { #if GDI if (this.targetContext == XGraphicTargetContext.GDI) this.gfx.DrawLines(pen.RealizeGdiPen(), XGraphics.MakePointFArray(points)); #endif #if WPF if (this.targetContext == XGraphicTargetContext.WPF) { #if !SILVERLIGHT PolyLineSegment seg = new PolyLineSegment(XGraphics.MakePointArray(points), true); #else Point[] pts = XGraphics.MakePointArray(points); PointCollection collection = new PointCollection(); foreach (Point point in pts) collection.Add(point); PolyLineSegment seg = new PolyLineSegment(); seg.Points = collection; #endif PathFigure figure = new PathFigure(); figure.StartPoint = new System.Windows.Point(points[0].x, points[0].y); figure.Segments.Add(seg); PathGeometry geo = new PathGeometry(); geo.Figures.Add(figure); this.dc.DrawGeometry(null, pen.RealizeWpfPen(), geo); } #endif } if (this.renderer != null) this.renderer.DrawLines(pen, points); }
private void BuildPath ( PdfContents Contents, PaintOp PaintOperator ) { // every figure is a separated subpath and contains some segments foreach (SysMedia.PathFigure SubPath in MediaPath.Figures) { // get start of sub-path point PointD CurPoint = PathToDrawing(SubPath.StartPoint); PointD StartPoint = CurPoint; Contents.MoveTo(CurPoint); // process all points of one sub-path foreach (SysMedia.PathSegment Seg in SubPath.Segments) { // line segment if (Seg.GetType() == typeof(SysMedia.LineSegment)) { CurPoint = PathToDrawing(((SysMedia.LineSegment)Seg).Point); Contents.LineTo(CurPoint); } // polygon else if (Seg.GetType() == typeof(SysMedia.PolyLineSegment)) { SysMedia.PolyLineSegment LineSegArray = (SysMedia.PolyLineSegment)Seg; foreach (SysWin.Point PolyPoint in LineSegArray.Points) { CurPoint = PathToDrawing(PolyPoint); Contents.LineTo(CurPoint); } } // cubic bezier segment else if (Seg.GetType() == typeof(SysMedia.BezierSegment)) { SysMedia.BezierSegment BezierSeg = (SysMedia.BezierSegment)Seg; CurPoint = PathToDrawing(BezierSeg.Point3); Contents.DrawBezier(PathToDrawing(BezierSeg.Point1), PathToDrawing(BezierSeg.Point2), CurPoint); } // cubic bezier multi segments else if (Seg.GetType() == typeof(SysMedia.PolyBezierSegment)) { SysMedia.PolyBezierSegment BezierSegArray = (SysMedia.PolyBezierSegment)Seg; int Count = BezierSegArray.Points.Count; for (int Index = 0; Index < Count; Index += 3) { CurPoint = PathToDrawing(BezierSegArray.Points[Index + 2]); Contents.DrawBezier(PathToDrawing(BezierSegArray.Points[Index]), PathToDrawing(BezierSegArray.Points[Index + 1]), CurPoint); } } // quadratic bezier segment else if (Seg.GetType() == typeof(SysMedia.QuadraticBezierSegment)) { SysMedia.QuadraticBezierSegment BezierSeg = (SysMedia.QuadraticBezierSegment)Seg; PointD NextPoint = PathToDrawing(BezierSeg.Point2); Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSeg.Point1), NextPoint), BezierPointOne.Ignore); CurPoint = NextPoint; } // quadratic bezier multi segments else if (Seg.GetType() == typeof(SysMedia.PolyQuadraticBezierSegment)) { SysMedia.PolyQuadraticBezierSegment BezierSegArray = (SysMedia.PolyQuadraticBezierSegment)Seg; int Count = BezierSegArray.Points.Count; for (int Index = 0; Index < Count; Index += 2) { PointD NextPoint = PathToDrawing(BezierSegArray.Points[Index + 1]); Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSegArray.Points[Index]), NextPoint), BezierPointOne.Ignore); CurPoint = NextPoint; } } // draw arc else if (Seg.GetType() == typeof(SysMedia.ArcSegment)) { SysMedia.ArcSegment Arc = (SysMedia.ArcSegment)Seg; PointD NextPoint = PathToDrawing(Arc.Point); ArcType ArcType; if (Arc.SweepDirection == (PathYAxis == YAxisDirection.Down ? SysMedia.SweepDirection.Counterclockwise : SysMedia.SweepDirection.Clockwise)) { ArcType = Arc.IsLargeArc ? ArcType.LargeCounterClockWise : ArcType.SmallCounterClockWise; } else { ArcType = Arc.IsLargeArc ? ArcType.LargeClockWise : ArcType.SmallClockWise; } Contents.DrawArc(CurPoint, NextPoint, SizeToDrawing(Arc.Size), Arc.RotationAngle, ArcType, BezierPointOne.Ignore); CurPoint = NextPoint; } // should no happen else { throw new ApplicationException("Windows Media path: unknown path segment."); } } // for stroke set paint operator for each sub-path if (SubPath.IsClosed) { Contents.SetPaintOp(PaintOp.CloseSubPath); } } // paint operator Contents.SetPaintOp(PaintOperator); return; }
private void CreateProgressIndicator() { if (soundPlayer == null || timelineCanvas == null || progressCanvas == null) return; const double xLocation = 0.0d; progressLine.X1 = xLocation; progressLine.X2 = xLocation; progressLine.Y1 = timelineCanvas.RenderSize.Height; progressLine.Y2 = progressCanvas.RenderSize.Height; PolyLineSegment indicatorPolySegment = new PolyLineSegment(); indicatorPolySegment.Points.Add(new Point(xLocation, timelineCanvas.RenderSize.Height)); indicatorPolySegment.Points.Add(new Point(xLocation - indicatorTriangleWidth, timelineCanvas.RenderSize.Height - indicatorTriangleWidth)); indicatorPolySegment.Points.Add(new Point(xLocation + indicatorTriangleWidth, timelineCanvas.RenderSize.Height - indicatorTriangleWidth)); indicatorPolySegment.Points.Add(new Point(xLocation, timelineCanvas.RenderSize.Height)); PathGeometry indicatorGeometry = new PathGeometry(); PathFigure indicatorFigure = new PathFigure(); indicatorFigure.Segments.Add(indicatorPolySegment); indicatorGeometry.Figures.Add(indicatorFigure); progressIndicator.Data = indicatorGeometry; UpdateProgressIndicator(); }
private void UpdateWaveform() { const double minValue = 0; const double maxValue = 1.5; const double dbScale = (maxValue - minValue); if (soundPlayer == null || soundPlayer.WaveformData == null || waveformCanvas == null || waveformCanvas.RenderSize.Width < 1 || waveformCanvas.RenderSize.Height < 1) return; double leftRenderHeight; double rightRenderHeight; int pointCount = (int)(soundPlayer.WaveformData.Length / 2.0d); double pointThickness = waveformCanvas.RenderSize.Width / pointCount; double waveformSideHeight = waveformCanvas.RenderSize.Height / 2.0d; double centerHeight = waveformSideHeight; if (CenterLineBrush != null) { centerLine.X1 = 0; centerLine.X2 = waveformCanvas.RenderSize.Width; centerLine.Y1 = centerHeight; centerLine.Y2 = centerHeight; } if (soundPlayer.WaveformData != null && soundPlayer.WaveformData.Length > 1) { PolyLineSegment leftWaveformPolyLine = new PolyLineSegment(); leftWaveformPolyLine.Points.Add(new Point(0, centerHeight)); PolyLineSegment rightWaveformPolyLine = new PolyLineSegment(); rightWaveformPolyLine.Points.Add(new Point(0, centerHeight)); double xLocation = 0.0d; for (int i = 0; i < soundPlayer.WaveformData.Length; i += 2) { xLocation = (i / 2) * pointThickness; leftRenderHeight = ((soundPlayer.WaveformData[i] - minValue) / dbScale) * waveformSideHeight; leftWaveformPolyLine.Points.Add(new Point(xLocation, centerHeight - leftRenderHeight)); rightRenderHeight = ((soundPlayer.WaveformData[i + 1] - minValue) / dbScale) * waveformSideHeight; rightWaveformPolyLine.Points.Add(new Point(xLocation, centerHeight + rightRenderHeight)); } leftWaveformPolyLine.Points.Add(new Point(xLocation, centerHeight)); leftWaveformPolyLine.Points.Add(new Point(0, centerHeight)); rightWaveformPolyLine.Points.Add(new Point(xLocation, centerHeight)); rightWaveformPolyLine.Points.Add(new Point(0, centerHeight)); PathGeometry leftGeometry = new PathGeometry(); PathFigure leftPathFigure = new PathFigure(); leftPathFigure.Segments.Add(leftWaveformPolyLine); leftGeometry.Figures.Add(leftPathFigure); PathGeometry rightGeometry = new PathGeometry(); PathFigure rightPathFigure = new PathFigure(); rightPathFigure.Segments.Add(rightWaveformPolyLine); rightGeometry.Figures.Add(rightPathFigure); leftPath.Data = leftGeometry; rightPath.Data = rightGeometry; } else { leftPath.Data = null; rightPath.Data = null; } }
static PathGeometry CreateSpline(PointCollection pts, double tension, DoubleCollection tensions, bool isClosed, bool isFilled, double tolerance) { if (pts == null || pts.Count < 1) return null; PolyLineSegment polyLineSegment = new PolyLineSegment(); PathFigure pathFigure = new PathFigure(); pathFigure.IsClosed = isClosed; pathFigure.IsFilled = isFilled; pathFigure.StartPoint = pts[0]; pathFigure.Segments.Add(polyLineSegment); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); if (pts.Count < 2) return pathGeometry; else if (pts.Count == 2) { if (!isClosed) { Segment(polyLineSegment.Points, pts[0], pts[0], pts[1], pts[1], tension, tension, tolerance); } else { Segment(polyLineSegment.Points, pts[1], pts[0], pts[1], pts[0], tension, tension, tolerance); Segment(polyLineSegment.Points, pts[0], pts[1], pts[0], pts[1], tension, tension, tolerance); } } else { bool useTensionCollection = tensions != null && tensions.Count > 0; for (int i = 0; i < pts.Count; i++) { double T1 = useTensionCollection ? tensions[i % tensions.Count] : tension; double T2 = useTensionCollection ? tensions[(i + 1) % tensions.Count] : tension; if (i == 0) { Segment(polyLineSegment.Points, isClosed ? pts[pts.Count - 1] : pts[0], pts[0], pts[1], pts[2], T1, T2, tolerance); } else if (i == pts.Count - 2) { Segment(polyLineSegment.Points, pts[i - 1], pts[i], pts[i + 1], isClosed ? pts[0] : pts[i + 1], T1, T2, tolerance); } else if (i == pts.Count - 1) { if (isClosed) { Segment(polyLineSegment.Points, pts[i - 1], pts[i], pts[0], pts[1], T1, T2, tolerance); } } else { Segment(polyLineSegment.Points, pts[i - 1], pts[i], pts[i + 1], pts[i + 2], T1, T2, tolerance); } } } return pathGeometry; }
public dynConnector(dynNodeUI start, dynNodeUI end, int startIndex, int endIndex, int portType, bool visible) { //don't try to create a connector with a bad start, //end, or if we're trying to connector the same //port to itself. if (start == null || end == null || start == end) { throw new Exception("Attempting to create connector with invalid start or end nodes."); } pStart = start.OutPorts[startIndex]; dynPort endPort = null; if (portType == 0) endPort = end.InPorts[endIndex]; //connect the two ports //get start point pStart.Connect(this); BrushConverter bc = new BrushConverter(); strokeBrush = (Brush)bc.ConvertFrom("#313131"); #region bezier creation connector = new Path(); connector.Stroke = strokeBrush; connector.StrokeThickness = STROKE_THICKNESS; connector.Opacity = STROKE_OPACITY; connector.DataContext = this; Binding strokeBinding = new Binding("StrokeBrush"); connector.SetBinding(Path.StrokeProperty, strokeBinding); DoubleCollection dashArray = new DoubleCollection(); dashArray.Add(5); dashArray.Add(2); connector.StrokeDashArray = dashArray; PathGeometry connectorGeometry = new PathGeometry(); connectorPoints = new PathFigure(); connectorCurve = new BezierSegment(); connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y); connectorCurve.Point1 = connectorPoints.StartPoint; connectorCurve.Point2 = connectorPoints.StartPoint; connectorCurve.Point3 = connectorPoints.StartPoint; connectorPoints.Segments.Add(connectorCurve); connectorGeometry.Figures.Add(connectorPoints); connector.Data = connectorGeometry; dynSettings.Workbench.Children.Add(connector); #endregion #region polyline creation plineConnector = new Path(); plineConnector.Stroke = strokeBrush; plineConnector.StrokeThickness = STROKE_THICKNESS; plineConnector.Opacity = STROKE_OPACITY; plineConnector.StrokeDashArray = dashArray; PathGeometry plineGeometry = new PathGeometry(); //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx plineFigure = new PathFigure(); plineFigure.StartPoint = new Point(pStart.Center.X, pStart.Center.Y); Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint, connectorPoints.StartPoint, connectorPoints.StartPoint}; pline = new PolyLineSegment(polyLinePointArray, true); pline.Points = new PointCollection(polyLinePointArray); plineFigure.Segments.Add(pline); plineGeometry.Figures.Add(plineFigure); plineConnector.Data = plineGeometry; dynSettings.Workbench.Children.Add(plineConnector); #endregion endDot = new Ellipse(); endDot.Height = 6; endDot.Width = 6; endDot.Fill = Brushes.Black; endDot.StrokeThickness = 2; endDot.Stroke = Brushes.Black; endDot.IsHitTestVisible = false; endDot.MouseDown +=new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown); Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE / 2); Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE / 2); dynSettings.Workbench.Children.Add(endDot); endDot.Opacity = STROKE_OPACITY; endDot.IsHitTestVisible = false; endDot.MouseDown += new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown); this.Visible = visible; connector.MouseEnter += delegate { if (pEnd != null) Highlight(); }; connector.MouseLeave += delegate { Unhighlight(); }; plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); }; plineConnector.MouseLeave += delegate { Unhighlight(); }; isDrawing = true; //set this to not draggable Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false); Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false); //set the z order to the front //Canvas.SetZIndex(this, 300); Canvas.SetZIndex(this, 1); this.Connect(endPort); ConnectorType = dynSettings.Bench.ConnectorType; }
//Draws a polygon with different thiknesses at each end. Traces over a line. public static WPFMEDIA.PathGeometry PolygonLine(WPF.Point StartPoint, WPF.Point EndPoint, double StartWidth, double EndWidth) { //Get Current Angle Don't need the actual angle, radians is fine. double angle = CurrentAngle(StartPoint, EndPoint); double radians = Math.Atan2(StartPoint.Y - EndPoint.Y, StartPoint.X - EndPoint.X); //Take 90 deg double newAngle = angle + 90; double newRadians = radians + Math.PI / 2; //need to determine the shift. double shiftStartX = StartWidth * Math.Cos(newRadians); double shiftStartY = StartWidth * Math.Sin(newRadians); double shiftEndX = EndWidth * Math.Cos(newRadians); double shiftEndY = EndWidth * Math.Sin(newRadians); double newStartPointX1 = StartPoint.X - shiftStartX; double newStartPointY1 = StartPoint.Y - shiftStartY; double newStartPointX2 = StartPoint.X + shiftStartX; double newStartPointY2 = StartPoint.Y + shiftStartY; double newEndPointX1 = EndPoint.X - shiftEndX; double newEndPointY1 = EndPoint.Y - shiftEndY; double newEndPointX2 = EndPoint.X + shiftEndX; double newEndPointY2 = EndPoint.Y + shiftEndY; WPF.Point newStartPoint1 = new WPF.Point(newStartPointX1, newStartPointY1); WPF.Point newStartPoint2 = new WPF.Point(newStartPointX2, newStartPointY2); WPF.Point newEndPoint1 = new WPF.Point(newEndPointX1, newEndPointY1); WPF.Point newEndPoint2 = new WPF.Point(newEndPointX2, newEndPointY2); //Now we have all the points. Need to build a polygon shape. WPFMEDIA.PathGeometry rootPath = new System.Windows.Media.PathGeometry(); WPFMEDIA.PolyLineSegment poly = new System.Windows.Media.PolyLineSegment(); //poly.Points.Add(newStartPoint1); poly.Points.Add(newStartPoint2); poly.Points.Add(newEndPoint2); poly.Points.Add(newEndPoint1); WPFMEDIA.PathFigure newFigure = new WPFMEDIA.PathFigure(); newFigure.StartPoint = newStartPoint1; newFigure.Segments.Add(poly); rootPath.Figures.Add(newFigure); return rootPath; }
public dynConnector(dynPort port, Canvas workBench, Point mousePt) { //don't allow connections to start at an input port if (port.PortType != PortType.INPUT) { //get start point //this.workBench = workBench; pStart = port; pStart.Connect(this); BrushConverter bc = new BrushConverter(); strokeBrush = (Brush)bc.ConvertFrom("#313131"); #region bezier creation connector = new Path(); connector.Stroke = strokeBrush; connector.StrokeThickness = STROKE_THICKNESS; connector.Opacity = STROKE_OPACITY; connector.DataContext = this; Binding strokeBinding = new Binding("StrokeBrush"); connector.SetBinding(Path.StrokeProperty, strokeBinding); DoubleCollection dashArray = new DoubleCollection(); dashArray.Add(5); dashArray.Add(2); connector.StrokeDashArray = dashArray; PathGeometry connectorGeometry = new PathGeometry(); connectorPoints = new PathFigure(); connectorCurve = new BezierSegment(); connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y); connectorCurve.Point1 = connectorPoints.StartPoint; connectorCurve.Point2 = connectorPoints.StartPoint; connectorCurve.Point3 = connectorPoints.StartPoint; connectorPoints.Segments.Add(connectorCurve); connectorGeometry.Figures.Add(connectorPoints); connector.Data = connectorGeometry; workBench.Children.Add(connector); #endregion #region polyline creation plineConnector = new Path(); plineConnector.Stroke = strokeBrush; plineConnector.StrokeThickness = STROKE_THICKNESS; plineConnector.Opacity = STROKE_OPACITY; plineConnector.StrokeDashArray = dashArray; PathGeometry plineGeometry = new PathGeometry(); //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx plineFigure = new PathFigure(); plineFigure.StartPoint = connectorPoints.StartPoint; Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint, connectorPoints.StartPoint, connectorPoints.StartPoint}; pline = new PolyLineSegment(polyLinePointArray, true); pline.Points = new PointCollection(polyLinePointArray); plineFigure.Segments.Add(pline); plineGeometry.Figures.Add(plineFigure); plineConnector.Data = plineGeometry; dynSettings.Workbench.Children.Add(plineConnector); #endregion endDot = new Ellipse(); endDot.Height = 6; endDot.Width = 6; endDot.Fill = Brushes.Black; endDot.StrokeThickness = 2; endDot.Stroke = Brushes.Black; endDot.IsHitTestVisible = false; endDot.MouseDown += new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown); Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE / 2); Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE / 2); dynSettings.Workbench.Children.Add(endDot); endDot.Opacity = STROKE_OPACITY; connector.MouseEnter += delegate { if (pEnd != null) Highlight(); }; connector.MouseLeave += delegate { Unhighlight(); }; plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); }; plineConnector.MouseLeave += delegate { Unhighlight(); }; isDrawing = true; //set this to not draggable Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false); Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false); //set the z order to the front Canvas.SetZIndex(connector, 0); Canvas.SetZIndex(endDot, 1); ConnectorType = dynSettings.Bench.ConnectorType; } else { throw new InvalidPortException(); } }
private void ConvertPart(PathThumb senderThumb, PathPartConvertType convertType) { if (senderThumb.PathPoint.ParentObject is PathFigure) { var pathFigure = senderThumb.PathPoint.ParentObject as PathFigure; var pathSegment = senderThumb.PathPoint.Object as PathSegment; var idx = pathFigure.Segments.IndexOf(pathSegment); var point = senderThumb.PathPoint.Point; if (pathSegment is PolyLineSegment) { var poly = pathSegment as PolyLineSegment; var lst = poly.Points.Take(senderThumb.PathPoint.PolyLineIndex); var lst2 = poly.Points.Skip(senderThumb.PathPoint.PolyLineIndex + 1); var p = poly.Points[senderThumb.PathPoint.PolyLineIndex]; pathFigure.Segments.RemoveAt(idx); var p1 = new PolyLineSegment(); p1.Points.AddRange(lst); pathFigure.Segments.Insert(idx, p1); pathSegment = new LineSegment() {Point = p}; pathFigure.Segments.Insert(idx+1, pathSegment); var p2 = new PolyLineSegment(); p2.Points.AddRange(lst2); pathFigure.Segments.Insert(idx+2, p2); idx++; } else if (pathSegment is PolyBezierSegment) { //TODO } else if (pathSegment is PolyQuadraticBezierSegment) { //TODO } pathFigure.Segments.RemoveAt(idx); var midp = senderThumb.PathPoint.ParentPathPoint.Point - ((senderThumb.PathPoint.ParentPathPoint.Point - point) / 2); PathSegment newSegment = null; switch (convertType) { case PathPartConvertType.ToBezierSegment: newSegment = new BezierSegment() { Point1 = midp - new Vector(40, 40), Point2 = midp + new Vector(-40, 40), Point3 = point }; break; case PathPartConvertType.ToQuadricBezierSegment: newSegment = new QuadraticBezierSegment() { Point1 = point - new Vector(40, 40), Point2 = point }; break; case PathPartConvertType.ToArcSegment: newSegment = new ArcSegment() { Point = point, Size = new Size(20, 20) }; break; case PathPartConvertType.insertPoint: pathFigure.Segments.Insert(idx, pathSegment); newSegment = new LineSegment() { Point = midp, }; break; default: newSegment = new LineSegment() { Point = point }; break; } pathFigure.Segments.Insert(idx, newSegment); } this.ExtendedItem.ReapplyAllExtensions(); }
public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }
AddPointsToPolyLineSegment ( PolyLineSegment oPolyLineSegment, Point oPoint0, Point oPoint1, Point oPoint2, Point oPoint3, Double dTension, Double dTolerance ) { Debug.Assert(oPolyLineSegment != null); Debug.Assert(dTolerance > 0); Int32 iPoints = (Int32)( (Math.Abs(oPoint1.X - oPoint2.X) + Math.Abs(oPoint1.Y - oPoint2.Y) ) / dTolerance); PointCollection oPolyLineSegmentPoints = oPolyLineSegment.Points; if (iPoints <= 2) { oPolyLineSegmentPoints.Add(oPoint2); } else { Double dSX1 = dTension * (oPoint2.X - oPoint0.X); Double dSY1 = dTension * (oPoint2.Y - oPoint0.Y); Double dSX2 = dTension * (oPoint3.X - oPoint1.X); Double dSY2 = dTension * (oPoint3.Y - oPoint1.Y); Double dAX = dSX1 + dSX2 + 2 * oPoint1.X - 2 * oPoint2.X; Double dAY = dSY1 + dSY2 + 2 * oPoint1.Y - 2 * oPoint2.Y; Double dBX = -2 * dSX1 - dSX2 - 3 * oPoint1.X + 3 * oPoint2.X; Double dBY = -2 * dSY1 - dSY2 - 3 * oPoint1.Y + 3 * oPoint2.Y; Double dCX = dSX1; Double dCY = dSY1; Double dDX = oPoint1.X; Double dDY = oPoint1.Y; // Note that this starts at 1, not 0. for (int i = 1; i < iPoints; i++) { Double t = (Double)i / (iPoints - 1); Point oPoint = new Point( dAX * t * t * t + dBX * t * t + dCX * t + dDX, dAY * t * t * t + dBY * t * t + dCY * t + dDY ); oPolyLineSegmentPoints.Add(oPoint); } } }
internal unsafe void AddFigureToList(bool isFilled, bool isClosed, MilPoint2F *pPoints, UInt32 pointCount, byte *pSegTypes, UInt32 segmentCount) { if (pointCount >= 1 && segmentCount >= 1) { PathFigure figure = new PathFigure(); figure.IsFilled = isFilled; figure.StartPoint = new Point(pPoints->X, pPoints->Y); int pointIndex = 1; int sameSegCount = 0; for (int segIndex = 0; segIndex < segmentCount; segIndex += sameSegCount) { byte segType = (byte)(pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegTypeMask); sameSegCount = 1; // Look for a run of same-type segments for a PolyXXXSegment. while (((segIndex + sameSegCount) < segmentCount) && (pSegTypes[segIndex] == pSegTypes[segIndex + sameSegCount])) { sameSegCount++; } bool fStroked = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegIsAGap) == (byte)0; bool fSmooth = (pSegTypes[segIndex] & (byte)MILCoreSegFlags.SegSmoothJoin) != (byte)0; if (segType == (byte)MILCoreSegFlags.SegTypeLine) { if (pointIndex + sameSegCount > pointCount) { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } if (sameSegCount > 1) { PointCollection ptCollection = new PointCollection(); for (int i = 0; i < sameSegCount; i++) { ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y)); } ptCollection.Freeze(); PolyLineSegment polySeg = new PolyLineSegment(ptCollection, fStroked, fSmooth); polySeg.Freeze(); figure.Segments.Add(polySeg); } else { Debug.Assert(sameSegCount == 1); figure.Segments.Add(new LineSegment(new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y), fStroked, fSmooth)); } pointIndex += sameSegCount; } else if (segType == (byte)MILCoreSegFlags.SegTypeBezier) { int pointBezierCount = sameSegCount * 3; if (pointIndex + pointBezierCount > pointCount) { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } if (sameSegCount > 1) { PointCollection ptCollection = new PointCollection(); for (int i = 0; i < pointBezierCount; i++) { ptCollection.Add(new Point(pPoints[pointIndex + i].X, pPoints[pointIndex + i].Y)); } ptCollection.Freeze(); PolyBezierSegment polySeg = new PolyBezierSegment(ptCollection, fStroked, fSmooth); polySeg.Freeze(); figure.Segments.Add(polySeg); } else { Debug.Assert(sameSegCount == 1); figure.Segments.Add(new BezierSegment( new Point(pPoints[pointIndex].X, pPoints[pointIndex].Y), new Point(pPoints[pointIndex + 1].X, pPoints[pointIndex + 1].Y), new Point(pPoints[pointIndex + 2].X, pPoints[pointIndex + 2].Y), fStroked, fSmooth)); } pointIndex += pointBezierCount; } else { throw new System.InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError)); } } if (isClosed) { figure.IsClosed = true; } figure.Freeze(); Figures.Add(figure); // Do not bother adding empty figures. } }