Esempio n. 1
0
        /// <inheritdoc/>
        public override void LeftDown(double x, double y)
        {
            base.LeftDown(x, y);

            double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x;
            double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y;

            switch (_currentState)
            {
            case ToolState.None:
            {
                _arc.Start = _editor.TryToGetConnectionPoint(sx, sy) ?? XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                if (!_toolPath._isInitialized)
                {
                    _toolPath.InitializeWorkingPath(_arc.Start);
                }
                else
                {
                    _arc.Start = _toolPath.GetLastPathPoint();
                }

                _arc.End = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.ArcTo(
                    _arc.End,
                    XPathSize.Create(
                        Abs(_arc.Start.X - _arc.End.X),
                        Abs(_arc.Start.Y - _arc.End.Y)),
                    _defaultRotationAngle,
                    _defaultIsLargeArc,
                    _defaultSweepDirection,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateOne();
                Move(null);
                _currentState           = ToolState.One;
                _editor.CancelAvailable = true;
            }
            break;

            case ToolState.One:
            {
                _arc.End.X = sx;
                _arc.End.Y = sy;
                if (_editor.Project.Options.TryToConnect)
                {
                    var end = _editor.TryToGetConnectionPoint(sx, sy);
                    if (end != null)
                    {
                        _arc.End = end;
                    }
                }
                _arc.Start = _arc.End;
                _arc.End   = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.ArcTo(
                    _arc.End,
                    XPathSize.Create(
                        Abs(_arc.Start.X - _arc.End.X),
                        Abs(_arc.Start.Y - _arc.End.Y)),
                    _defaultRotationAngle,
                    _defaultIsLargeArc,
                    _defaultSweepDirection,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();

                Move(null);
                _currentState = ToolState.One;
            }
            break;
            }
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public override void LeftDown(double x, double y)
        {
            base.LeftDown(x, y);

            double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x;
            double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y;

            switch (_currentState)
            {
            case ToolState.None:
            {
                _cubicBezier.Point1 = _editor.TryToGetConnectionPoint(sx, sy) ?? XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                if (!_toolPath._isInitialized)
                {
                    _toolPath.InitializeWorkingPath(_cubicBezier.Point1);
                }
                else
                {
                    _cubicBezier.Point1 = _toolPath.GetLastPathPoint();
                }

                _cubicBezier.Point2 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _cubicBezier.Point3 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _cubicBezier.Point4 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.CubicBezierTo(
                    _cubicBezier.Point2,
                    _cubicBezier.Point3,
                    _cubicBezier.Point4,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateOne();
                Move(null);
                _currentState           = ToolState.One;
                _editor.CancelAvailable = true;
            }
            break;

            case ToolState.One:
            {
                _cubicBezier.Point4.X = sx;
                _cubicBezier.Point4.Y = sy;
                if (_editor.Project.Options.TryToConnect)
                {
                    var point3 = _editor.TryToGetConnectionPoint(sx, sy);
                    if (point3 != null)
                    {
                        var figure      = _toolPath._geometry.Figures.LastOrDefault();
                        var cubicBezier = figure.Segments.LastOrDefault() as XCubicBezierSegment;
                        cubicBezier.Point3  = point3;
                        _cubicBezier.Point4 = point3;
                    }
                }
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateTwo();
                Move(null);
                _currentState = ToolState.Two;
            }
            break;

            case ToolState.Two:
            {
                _cubicBezier.Point2.X = sx;
                _cubicBezier.Point2.Y = sy;
                if (_editor.Project.Options.TryToConnect)
                {
                    var point1 = _editor.TryToGetConnectionPoint(sx, sy);
                    if (point1 != null)
                    {
                        var figure      = _toolPath._geometry.Figures.LastOrDefault();
                        var cubicBezier = figure.Segments.LastOrDefault() as XCubicBezierSegment;
                        cubicBezier.Point1  = point1;
                        _cubicBezier.Point2 = point1;
                    }
                }
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateThree();
                Move(null);
                _currentState = ToolState.Three;
            }
            break;

            case ToolState.Three:
            {
                _cubicBezier.Point3.X = sx;
                _cubicBezier.Point3.Y = sy;
                if (_editor.Project.Options.TryToConnect)
                {
                    var point2 = _editor.TryToGetConnectionPoint(sx, sy);
                    if (point2 != null)
                    {
                        var figure      = _toolPath._geometry.Figures.LastOrDefault();
                        var cubicBezier = figure.Segments.LastOrDefault() as XCubicBezierSegment;
                        cubicBezier.Point2  = point2;
                        _cubicBezier.Point3 = point2;
                    }
                }

                _cubicBezier.Point1 = _cubicBezier.Point4;
                _cubicBezier.Point2 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _cubicBezier.Point3 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _cubicBezier.Point4 = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.CubicBezierTo(
                    _cubicBezier.Point2,
                    _cubicBezier.Point3,
                    _cubicBezier.Point4,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                Remove();
                ToStateOne();
                Move(null);
                _currentState = ToolState.One;
            }
            break;
            }
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public override void LeftDown(double x, double y)
        {
            base.LeftDown(x, y);

            double sx = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, _editor.Project.Options.SnapX) : x;
            double sy = _editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, _editor.Project.Options.SnapY) : y;

            switch (_currentState)
            {
            case ToolState.None:
            {
                _line.Start = _editor.TryToGetConnectionPoint(sx, sy) ?? XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                if (!_toolPath._isInitialized)
                {
                    _toolPath.InitializeWorkingPath(_line.Start);
                }
                else
                {
                    _line.Start = _toolPath.GetLastPathPoint();
                }

                _line.End = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.LineTo(
                    _line.End,
                    _editor.Project.Options.DefaultIsStroked,
                    _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                ToStateOne();
                Move(null);
                _currentState           = ToolState.One;
                _editor.CancelAvailable = true;
            }
            break;

            case ToolState.One:
            {
                _line.End.X = sx;
                _line.End.Y = sy;
                if (_editor.Project.Options.TryToConnect)
                {
                    var end = _editor.TryToGetConnectionPoint(sx, sy);
                    if (end != null)
                    {
                        var figure = _toolPath._geometry.Figures.LastOrDefault();
                        var line   = figure.Segments.LastOrDefault() as XLineSegment;
                        line.Point = end;
                    }
                }

                _line.Start = _line.End;
                _line.End   = XPoint.Create(sx, sy, _editor.Project.Options.PointShape);
                _toolPath._context.LineTo(_line.End,
                                          _editor.Project.Options.DefaultIsStroked,
                                          _editor.Project.Options.DefaultIsSmoothJoin);
                _editor.Project.CurrentContainer.WorkingLayer.Invalidate();
                Move(null);
                _currentState = ToolState.One;
            }
            break;
            }
        }