public void BreakPathFigure(PathFigureViewModel pathFigure, ShapeStyleViewModel style, bool isStroked, bool isFilled, List <BaseShapeViewModel> result) { var factory = _serviceProvider.GetService <IFactory>(); var firstPoint = pathFigure.StartPoint; var lastPoint = pathFigure.StartPoint; foreach (var segment in pathFigure.Segments) { switch (segment) { case LineSegmentViewModel lineSegment: { var convertedStyle = style is { } ? (ShapeStyleViewModel)style?.Copy(null) : factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName); var convertedPathShape = factory.CreateLineShape( lastPoint, lineSegment.Point, convertedStyle, isStroked); lastPoint = lineSegment.Point; result.Add(convertedPathShape); } break;
public static void CreateFigure(this PathFigureViewModel pathFigure, SKPath path) { path.MoveTo( (float)(pathFigure.StartPoint.X), (float)(pathFigure.StartPoint.Y)); foreach (var segment in pathFigure.Segments) { if (segment is LineSegmentViewModel lineSegment) { path.LineTo( (float)(lineSegment.Point.X), (float)(lineSegment.Point.Y)); } else if (segment is QuadraticBezierSegmentViewModel quadraticBezierSegment) { path.QuadTo( (float)(quadraticBezierSegment.Point1.X), (float)(quadraticBezierSegment.Point1.Y), (float)(quadraticBezierSegment.Point2.X), (float)(quadraticBezierSegment.Point2.Y)); } else if (segment is CubicBezierSegmentViewModel cubicBezierSegment) { path.CubicTo( (float)(cubicBezierSegment.Point1.X), (float)(cubicBezierSegment.Point1.Y), (float)(cubicBezierSegment.Point2.X), (float)(cubicBezierSegment.Point2.Y), (float)(cubicBezierSegment.Point3.X), (float)(cubicBezierSegment.Point3.Y)); } else if (segment is ArcSegmentViewModel arcSegment) { path.ArcTo( (float)(arcSegment.Size.Width), (float)(arcSegment.Size.Height), (float)arcSegment.RotationAngle, arcSegment.IsLargeArc ? SKPathArcSize.Large : SKPathArcSize.Small, arcSegment.SweepDirection == SweepDirection.Clockwise ? SKPathDirection.Clockwise : SKPathDirection.CounterClockwise, (float)(arcSegment.Point.X), (float)(arcSegment.Point.Y)); } else { throw new NotSupportedException("Not supported segment type: " + segment.GetType()); } } if (pathFigure.IsClosed) { path.Close(); } }
public override object Copy(IDictionary <object, object>?shared) { var segments = _segments.CopyShared(shared).ToImmutable(); var copy = new PathFigureViewModel(ServiceProvider) { Name = Name, StartPoint = _startPoint?.CopyShared(shared), Segments = segments, IsClosed = IsClosed }; return(copy); }