Beispiel #1
0
        /// <summary>
        /// Remove selection.
        /// </summary>
        public void Remove()
        {
            if (_line12 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_line12);
                _line12       = null;
            }

            if (_line32 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_line32);
                _line32       = null;
            }

            if (_helperPoint1 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint1);
                _helperPoint1 = null;
            }

            if (_helperPoint2 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint2);
                _helperPoint2 = null;
            }

            if (_helperPoint3 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint3);
                _helperPoint3 = null;
            }

            _layer.Invalidate();
        }
Beispiel #2
0
        /// <summary>
        /// Get <see cref="ILineShape"/> maximum length using <see cref="LineFixedLengthFlags"/>.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="ILineShape.End"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="ILineShape.End"/> point.</param>
        public static void GetMaxLength(this ILineShape line, ref double x1, ref double y1, ref double x2, ref double y2)
        {
            var ls = line.Style.LineStyle;

            if (ls.FixedLength.Flags == LineFixedLengthFlags.Disabled)
            {
                return;
            }

            if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.All))
            {
                GetMaxLengthAll(line, ref x1, ref y1, ref x2, ref y2);
            }
            else
            {
                if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Vertical))
                {
                    bool isVertical = Round(x1, 1) == Round(x2, 1);
                    if (isVertical)
                    {
                        GetMaxLengthVertical(line, ref y1, ref y2);
                    }
                }

                if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Horizontal))
                {
                    bool isHorizontal = Round(y1, 1) == Round(y2, 1);
                    if (isHorizontal)
                    {
                        GetMaxLengthHorizontal(line, ref x1, ref x2);
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initialize new instance of <see cref="ToolLineSelection"/> class.
 /// </summary>
 /// <param name="serviceProvider">The service provider.</param>
 /// <param name="layer">The selection shapes layer.</param>
 /// <param name="shape">The selected shape.</param>
 /// <param name="style">The selection shapes style.</param>
 public ToolLineSelection(IServiceProvider serviceProvider, ILayerContainer layer, ILineShape shape, IShapeStyle style)
 {
     _serviceProvider = serviceProvider;
     _layer           = layer;
     _line            = shape;
     _style           = style;
 }
Beispiel #4
0
        /// <summary>
        /// Get <see cref="ILineShape"/> maximum length for <see cref="LineFixedLengthFlags.All"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="ILineShape.End"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="ILineShape.End"/> point.</param>
        public static void GetMaxLengthAll(this ILineShape line, ref double x1, ref double y1, ref double x2, ref double y2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                double dx       = x1 - x2;
                double dy       = y1 - y2;
                double distance = Sqrt(dx * dx + dy * dy);
                x1 = x2 - (x2 - x1) / distance * ls.FixedLength.Length;
                y1 = y2 - (y2 - y1) / distance * ls.FixedLength.Length;
            }

            if (!shortenStart && shortenEnd)
            {
                double dx       = x2 - x1;
                double dy       = y2 - y1;
                double distance = Sqrt(dx * dx + dy * dy);
                x2 = x1 - (x1 - x2) / distance * ls.FixedLength.Length;
                y2 = y1 - (y1 - y2) / distance * ls.FixedLength.Length;
            }
        }
        /// <summary>
        /// Transfer selection state to Point2.
        /// </summary>
        public void ToStatePoint2()
        {
            _line12       = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style, null);
            _helperPoint2 = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0, _point);

            _layer.Shapes = _layer.Shapes.Add(_line12);
            _layer.Shapes = _layer.Shapes.Add(_helperPoint2);
        }
Beispiel #6
0
        /// <summary>
        /// Transfer selection state to Point3.
        /// </summary>
        public void ToStatePoint3()
        {
            _line43       = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style);
            _line23       = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style);
            _helperPoint3 = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_line43);
            _layer.Shapes = _layer.Shapes.Add(_line23);
            _layer.Shapes = _layer.Shapes.Add(_helperPoint3);
        }
        /// <summary>
        /// Transfer selection state to Point2.
        /// </summary>
        public void ToStatePoint2()
        {
            _line12              = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style);
            _line12.State.Flags |= ShapeStateFlags.Thickness;

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

            _layer.Shapes = _layer.Shapes.Add(_line12);
            _layer.Shapes = _layer.Shapes.Add(_helperPoint2);
        }
Beispiel #8
0
        /// <summary>
        /// Reset selection.
        /// </summary>
        public void Reset()
        {
            if (_ellipse != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_ellipse);
                _ellipse      = null;
            }

            if (_startLine != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_startLine);
                _startLine    = null;
            }

            if (_endLine != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_endLine);
                _endLine      = null;
            }

            if (_p1HelperPoint != null)
            {
                _layer.Shapes  = _layer.Shapes.Remove(_p1HelperPoint);
                _p1HelperPoint = null;
            }

            if (_p2HelperPoint != null)
            {
                _layer.Shapes  = _layer.Shapes.Remove(_p2HelperPoint);
                _p2HelperPoint = null;
            }

            if (_centerHelperPoint != null)
            {
                _layer.Shapes      = _layer.Shapes.Remove(_centerHelperPoint);
                _centerHelperPoint = null;
            }

            if (_startHelperPoint != null)
            {
                _layer.Shapes     = _layer.Shapes.Remove(_startHelperPoint);
                _startHelperPoint = null;
            }

            if (_endHelperPoint != null)
            {
                _layer.Shapes   = _layer.Shapes.Remove(_endHelperPoint);
                _endHelperPoint = null;
            }

            _layer.Invalidate();
        }
Beispiel #9
0
        /// <summary>
        /// Transfer selection state to Point4.
        /// </summary>
        public void ToStatePoint4()
        {
            if (_ellipse != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_ellipse);
                _ellipse      = null;
            }

            _endLine        = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style);
            _endHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_endLine);
            _layer.Shapes = _layer.Shapes.Add(_endHelperPoint);
        }
 public static SKPath ToSKPath(this IBaseShape shape, double dx, double dy, Func <double, float> scale)
 {
     return(shape switch
     {
         ILineShape lineShape => ToSKPath(lineShape, dx, dy, scale),
         IRectangleShape rectangleShape => ToSKPath(rectangleShape, dx, dy, scale),
         IEllipseShape ellipseShape => ToSKPath(ellipseShape, dx, dy, scale),
         IImageShape imageShape => ToSKPath(imageShape, dx, dy, scale),
         IArcShape arcShape => ToSKPath(arcShape, dx, dy, scale),
         ICubicBezierShape cubicBezierShape => ToSKPath(cubicBezierShape, dx, dy, scale),
         IQuadraticBezierShape quadraticBezierShape => ToSKPath(quadraticBezierShape, dx, dy, scale),
         ITextShape textShape => ToSKPath(textShape, dx, dy, scale),
         IPathShape pathShape => ToSKPath(pathShape, dx, dy, scale),
         IGroupShape groupShape => ToSKPath(groupShape.Shapes, dx, dy, scale),
         _ => null,
     });
Beispiel #11
0
        /// <summary>
        /// Reset selection.
        /// </summary>
        public void Reset()
        {
            if (_line12 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_line12);
                _line12       = null;
            }

            if (_line43 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_line43);
                _line43       = null;
            }

            if (_line23 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_line23);
                _line23       = null;
            }

            if (_helperPoint1 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint1);
                _helperPoint1 = null;
            }

            if (_helperPoint2 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint2);
                _helperPoint2 = null;
            }

            if (_helperPoint3 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint3);
                _helperPoint3 = null;
            }

            if (_helperPoint4 != null)
            {
                _layer.Shapes = _layer.Shapes.Remove(_helperPoint4);
                _helperPoint4 = null;
            }

            _layer.InvalidateLayer();
        }
Beispiel #12
0
        /// <summary>
        /// Transfer selection state to Point3.
        /// </summary>
        public void ToStatePoint3()
        {
            if (_p1HelperPoint != null)
            {
                _layer.Shapes  = _layer.Shapes.Remove(_p1HelperPoint);
                _p1HelperPoint = null;
            }

            if (_p2HelperPoint != null)
            {
                _layer.Shapes  = _layer.Shapes.Remove(_p2HelperPoint);
                _p2HelperPoint = null;
            }

            _startLine        = _serviceProvider.GetService <IFactory>().CreateLineShape(0, 0, _style);
            _startHelperPoint = _serviceProvider.GetService <IFactory>().CreatePointShape(0, 0);

            _layer.Shapes = _layer.Shapes.Add(_startLine);
            _layer.Shapes = _layer.Shapes.Add(_startHelperPoint);
        }
Beispiel #13
0
        /// <summary>
        /// Get <see cref="ILineShape"/> maximum length for <see cref="LineFixedLengthFlags.Horizontal"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="x1">The calculated X coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="x2">The calculated X coordinate for <see cref="ILineShape.End"/> point.</param>
        public static void GetMaxLengthHorizontal(this ILineShape line, ref double x1, ref double x2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                if (x2 > x1)
                {
                    x1 = x2 - ls.FixedLength.Length;
                }
                else
                {
                    x1 = x2 + ls.FixedLength.Length;
                }
            }

            if (!shortenStart && shortenEnd)
            {
                if (x2 > x1)
                {
                    x2 = x1 + ls.FixedLength.Length;
                }
                else
                {
                    x2 = x1 - ls.FixedLength.Length;
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// Get <see cref="ILineShape"/> maximum length for <see cref="LineFixedLengthFlags.Vertical"/> mode.
        /// </summary>
        /// <param name="line">The line shape.</param>
        /// <param name="y1">The calculated Y coordinate for <see cref="ILineShape.Start"/> point.</param>
        /// <param name="y2">The calculated Y coordinate for <see cref="ILineShape.End"/> point.</param>
        public static void GetMaxLengthVertical(this ILineShape line, ref double y1, ref double y2)
        {
            var ls = line.Style.LineStyle;

            bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default &&
                                line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) &&
                                ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start);

            bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default &&
                              line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) &&
                              ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End);

            if (shortenStart && !shortenEnd)
            {
                if (y2 > y1)
                {
                    y1 = y2 - ls.FixedLength.Length;
                }
                else
                {
                    y1 = y2 + ls.FixedLength.Length;
                }
            }

            if (!shortenStart && shortenEnd)
            {
                if (y2 > y1)
                {
                    y2 = y1 + ls.FixedLength.Length;
                }
                else
                {
                    y2 = y1 - ls.FixedLength.Length;
                }
            }
        }
Beispiel #15
0
 public void CopyStateTo(ILineShape element)
 {
     element.Descriptor = Descriptor;
 }
Beispiel #16
0
 public void CopyStateTo(ILineShape element)
 {
     element.Descriptor = Descriptor;
 }
Beispiel #17
0
 /// <inheritdoc/>
 public void Bind(ILineShape line, object db, object r)
 {
 }
Beispiel #18
0
 public LineDrawNode(ILineShape line, IShapeStyle style)
 {
     Style = style;
     Line  = line;
     UpdateGeometry();
 }
 public ILineDrawNode CreateLineDrawNode(ILineShape line, IShapeStyle style)
 {
     return(new LineDrawNode(line, style));
 }