Exemplo n.º 1
0
 public void ToStatePoint4()
 {
     _helperPoint1 = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
     _layer.Shapes = _layer.Shapes.Add(_helperPoint1);
     _helperPoint4 = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
     _layer.Shapes = _layer.Shapes.Add(_helperPoint4);
 }
Exemplo n.º 2
0
        public void LineTo(PointShapeViewModel point)
        {
            var segment = _factory.CreateLineSegment(
                point);

            _currentFigure.Segments = _currentFigure.Segments.Add(segment);
        }
Exemplo n.º 3
0
        public void BeginDown(InputArgs args)
        {
            var factory = _serviceProvider.GetService <IFactory>();
            var editor  = _serviceProvider.GetService <ProjectEditorViewModel>();

            (decimal sx, decimal sy) = editor.TryToSnap(args);
            switch (_currentState)
            {
            case State.Point:
            {
                _point = factory.CreatePointShape(
                    (double)sx,
                    (double)sy);

                editor.SetShapeName(_point);

                if (editor.Project.Options.TryToConnect)
                {
                    if (!editor.TryToSplitLine(args.X, args.Y, _point, true))
                    {
                        editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _point);
                    }
                }
                else
                {
                    editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _point);
                }
            }
            break;
            }
        }
Exemplo n.º 4
0
    public static void TransformPoint(ref MatrixD matrix, PointShapeViewModel point)
    {
        var transformed = MatrixD.TransformPoint(matrix, new PointD((decimal)point.X, (decimal)point.Y));

        point.X = (double)transformed.X;
        point.Y = (double)transformed.Y;
    }
Exemplo n.º 5
0
 public PointDrawNode(PointShapeViewModel point, ShapeStyleViewModel pointStyleViewModel, double pointSize)
 {
     Style     = pointStyleViewModel;
     Point     = point;
     PointSize = pointSize;
     UpdateGeometry();
 }
 public static void AddConnectorAsNone(this ConnectableShapeViewModel shape, PointShapeViewModel point)
 {
     point.Owner      = shape;
     point.State     |= ShapeStateFlags.Connector | ShapeStateFlags.None;
     point.State     &= ~ShapeStateFlags.Standalone;
     shape.Connectors = shape.Connectors.Add(point);
 }
Exemplo n.º 7
0
        public void QuadraticBezierTo(PointShapeViewModel point1, PointShapeViewModel point2)
        {
            var segment = _factory.CreateQuadraticBezierSegment(
                point1,
                point2);

            _currentFigure.Segments = _currentFigure.Segments.Add(segment);
        }
Exemplo n.º 8
0
        public void ToStateEnd()
        {
            _startHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
            _endHelperPoint   = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_startHelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_endHelperPoint);
        }
Exemplo n.º 9
0
        public void ToStateBottomRight()
        {
            _topLeftHelperPoint     = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
            _bottomRightHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint);
        }
Exemplo n.º 10
0
    public static double DistanceTo(this PointShapeViewModel point, PointShapeViewModel other)
    {
        var dx = point.X - other.X;
        var dy = point.Y - other.Y;

        // ReSharper disable once ArrangeRedundantParentheses
        return(Sqrt((dx * dx) + (dy * dy)));
    }
Exemplo n.º 11
0
 public void LineTo(PointShapeViewModel point)
 {
     if (_currentFigure is not null)
     {
         var segment = _viewModelFactory.CreateLineSegment(point);
         _currentFigure.Segments = _currentFigure.Segments.Add(segment);
     }
 }
Exemplo n.º 12
0
        public void CubicBezierTo(PointShapeViewModel point1, PointShapeViewModel point2, PointShapeViewModel point3)
        {
            var segment = _factory.CreateCubicBezierSegment(
                point1,
                point2,
                point3);

            _currentFigure.Segments = _currentFigure.Segments.Add(segment);
        }
Exemplo n.º 13
0
    private static void CircleConstrain(PointShapeViewModel tl, PointShapeViewModel br, decimal cx, decimal cy, decimal px, decimal py)
    {
        decimal r = Max(Abs(cx - px), Abs(cy - py));

        tl.X = (double)(cx - r);
        tl.Y = (double)(cy - r);
        br.X = (double)(cx + r);
        br.Y = (double)(cy + r);
    }
Exemplo n.º 14
0
        public static SKRect CreateRect(PointShapeViewModel tl, PointShapeViewModel br)
        {
            float left   = (float)Math.Min(tl.X, br.X);
            float top    = (float)Math.Min(tl.Y, br.Y);
            float right  = (float)Math.Max(tl.X, br.X);
            float bottom = (float)Math.Max(tl.Y, br.Y);

            return(new SKRect(left, top, right, bottom));
        }
Exemplo n.º 15
0
        public void ToStatePoint2()
        {
            _line12        = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _styleViewModel);
            _line12.State |= ShapeStateFlags.Thickness;

            _helperPoint2 = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_line12);
            _layer.Shapes = _layer.Shapes.Add(_helperPoint2);
        }
Exemplo n.º 16
0
        public void ArcTo(PointShapeViewModel point, PathSizeViewModel size, double rotationAngle = 0.0, bool isLargeArc = false, SweepDirection sweepDirection = SweepDirection.Clockwise)
        {
            var segment = _factory.CreateArcSegment(
                point,
                size,
                rotationAngle,
                isLargeArc,
                sweepDirection);

            _currentFigure.Segments = _currentFigure.Segments.Add(segment);
        }
Exemplo n.º 17
0
        public void ToStateBottomRight()
        {
            _helperRectangle        = _serviceProvider.GetService <IFactory>().CreateRectangleShape(0, 0, _styleViewModel);
            _helperRectangle.State |= ShapeStateFlags.Thickness;

            _topLeftHelperPoint     = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
            _bottomRightHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_helperRectangle);
            _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint);
        }
Exemplo n.º 18
0
    public static bool IsPointMovable(PointShapeViewModel point, BaseShapeViewModel parent)
    {
        if (point.State.HasFlag(ShapeStateFlags.Locked) || (point.Owner is BaseShapeViewModel owner && owner.State.HasFlag(ShapeStateFlags.Locked)))
        {
            return(false);
        }

        if (point.State.HasFlag(ShapeStateFlags.Connector) && point.Owner != null && point.Owner != parent)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 19
0
    private static bool IsPointMovable(BaseShapeViewModel shape, PointShapeViewModel point)
    {
        if (point.State.HasFlag(ShapeStateFlags.Locked) || (point.Owner is BaseShapeViewModel ower && ower.State.HasFlag(ShapeStateFlags.Locked)))
        {
            return(false);
        }

        if (point.State.HasFlag(ShapeStateFlags.Connector) && point.Owner != shape)
        {
            return(false);
        }

        return(true);
    }
Exemplo n.º 20
0
        public void ToStatePoint2()
        {
            _ellipse        = _serviceProvider.GetService <IFactory>().CreateEllipseShape(0, 0, _styleViewModel);
            _ellipse.State |= ShapeStateFlags.Thickness;

            _p1HelperPoint     = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
            _p2HelperPoint     = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);
            _centerHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_ellipse);
            _layer.Shapes = _layer.Shapes.Add(_p1HelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_p2HelperPoint);
            _layer.Shapes = _layer.Shapes.Add(_centerHelperPoint);
        }
Exemplo n.º 21
0
    public override object Copy(IDictionary <object, object>?shared)
    {
        var copy = new PointShapeViewModel(ServiceProvider)
        {
            Name       = Name,
            State      = State,
            Style      = _style?.CopyShared(shared),
            IsStroked  = IsStroked,
            IsFilled   = IsFilled,
            Properties = _properties.CopyShared(shared).ToImmutable(),
            Record     = _record,
            X          = X,
            Y          = Y,
        };

        return(copy);
    }
Exemplo n.º 22
0
        public static AM.StreamGeometry ToStreamGeometry(PathGeometryViewModel xpg)
        {
            var sg = new AM.StreamGeometry();

            using (var sgc = sg.Open())
            {
                PointShapeViewModel previous = default;

                sgc.SetFillRule(xpg.FillRule == FillRule.Nonzero ? AM.FillRule.NonZero : AM.FillRule.EvenOdd);

                foreach (var xpf in xpg.Figures)
                {
                    sgc.BeginFigure(new A.Point(xpf.StartPoint.X, xpf.StartPoint.Y), false);

                    previous = xpf.StartPoint;

                    foreach (var segment in xpf.Segments)
                    {
                        if (segment is ArcSegmentViewModel arcSegment)
                        {
                            sgc.ArcTo(
                                new A.Point(arcSegment.Point.X, arcSegment.Point.Y),
                                new A.Size(arcSegment.Size.Width, arcSegment.Size.Height),
                                arcSegment.RotationAngle,
                                arcSegment.IsLargeArc,
                                arcSegment.SweepDirection == SweepDirection.Clockwise ? AM.SweepDirection.Clockwise : AM.SweepDirection.CounterClockwise);

                            previous = arcSegment.Point;
                        }
                        else if (segment is CubicBezierSegmentViewModel cubicBezierSegment)
                        {
                            sgc.CubicBezierTo(
                                new A.Point(cubicBezierSegment.Point1.X, cubicBezierSegment.Point1.Y),
                                new A.Point(cubicBezierSegment.Point2.X, cubicBezierSegment.Point2.Y),
                                new A.Point(cubicBezierSegment.Point3.X, cubicBezierSegment.Point3.Y));

                            previous = cubicBezierSegment.Point3;
                        }
                        else if (segment is LineSegmentViewModel lineSegment)
                        {
                            sgc.LineTo(
                                new A.Point(lineSegment.Point.X, lineSegment.Point.Y));

                            previous = lineSegment.Point;
                        }
                        else if (segment is QuadraticBezierSegmentViewModel quadraticBezierSegment)
                        {
                            sgc.QuadraticBezierTo(
                                new A.Point(
                                    quadraticBezierSegment.Point1.X,
                                    quadraticBezierSegment.Point1.Y),
                                new A.Point(
                                    quadraticBezierSegment.Point2.X,
                                    quadraticBezierSegment.Point2.Y));

                            previous = quadraticBezierSegment.Point2;
                        }
                        else
                        {
                            throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                        }
                    }

                    sgc.EndFigure(xpf.IsClosed);
                }
            }

            return(sg);
        }
Exemplo n.º 23
0
 public static int CompareY(PointShapeViewModel point1, PointShapeViewModel point2)
 {
     return((point1.Y > point2.Y) ? 1 : ((point1.Y < point2.Y) ? -1 : 0));
 }
Exemplo n.º 24
0
 public static void Rotate(PointShapeViewModel point, decimal radians, decimal centerX, decimal centerY, out decimal x, out decimal y)
 {
     x = ((decimal)point.X - centerX) * (decimal)Math.Cos((double)radians) - ((decimal)point.Y - centerY) * (decimal)Math.Sin((double)radians) + centerX;
     y = ((decimal)point.X - centerX) * (decimal)Math.Sin((double)radians) + ((decimal)point.Y - centerY) * (decimal)Math.Cos((double)radians) + centerY;
 }
Exemplo n.º 25
0
 public PointSelection(LayerContainerViewModel layer, PointShapeViewModel shape, ShapeStyleViewModel style)
 {
     _layer          = layer;
     _shapeViewModel = shape;
     _styleViewModel = style;
 }
Exemplo n.º 26
0
 public void BeginFigure(PointShapeViewModel startPoint, bool isClosed = true)
 {
     _currentFigure = _viewModelFactory.CreatePathFigure(startPoint, isClosed);
     _path.Figures  = _path.Figures.Add(_currentFigure);
 }
Exemplo n.º 27
0
 private static A.Point ToPoint(this PointShapeViewModel point) => new(point.X, point.Y);
Exemplo n.º 28
0
 public IPointDrawNode CreatePointDrawNode(PointShapeViewModel point, ShapeStyleViewModel pointStyleViewModel, double pointSize)
 {
     return(new PointDrawNode(point, pointStyleViewModel, pointSize));
 }
Exemplo n.º 29
0
 public static int CompareX(PointShapeViewModel point1, PointShapeViewModel point2)
 {
     return((point1.X > point2.X) ? 1 : ((point1.X < point2.X) ? -1 : 0));
 }