/// <summary> /// Initialize new instance of <see cref="EllipseSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public EllipseSelection(XLayer layer, XEllipse shape, ShapeStyle style, BaseShape point) { _layer = layer; _ellipse = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="CubicBezierSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public CubicBezierSelection(XLayer layer, ICubicBezier shape, ShapeStyle style, BaseShape point) { _layer = layer; _cubicBezier = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="QuadraticBezierSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public QuadraticBezierSelection(XLayer layer, IQuadraticBezier shape, ShapeStyle style, BaseShape point) { _layer = layer; _quadraticBezier = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="LineSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public LineSelection(XLayer layer, ILine shape, ShapeStyle style, BaseShape point) { _layer = layer; _line = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="ImageSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public ImageSelection(XLayer layer, XImage shape, ShapeStyle style, BaseShape point) { _layer = layer; _image = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="RectangleSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public RectangleSelection(XLayer layer, XRectangle shape, ShapeStyle style, BaseShape point) { _layer = layer; _rectangle = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="ArcSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public ArcSelection(XLayer layer, IArc shape, ShapeStyle style, BaseShape point) { _layer = layer; _arc = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="PointSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public PointSelection(XLayer layer, XPoint shape, ShapeStyle style, BaseShape point) { _layer = layer; _shape = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="TextSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public TextSelection(XLayer layer, XText shape, ShapeStyle style, BaseShape point) { _layer = layer; _text = shape; _style = style; _point = point; }
/// <summary> /// Initialize new instance of <see cref="PathSelection"/> class. /// </summary> /// <param name="layer">The selection shapes layer.</param> /// <param name="shape">The selected shape.</param> /// <param name="style">The selection shapes style.</param> /// <param name="point">The selection point shape.</param> public PathSelection(XLayer layer, XPath shape, ShapeStyle style, BaseShape point) { _layer = layer; _path = shape; _style = style; _point = point; }
/// <summary> /// Creates a new <see cref="XEllipse"/> instance. /// </summary> /// <param name="x1">The X coordinate of <see cref="XText.TopLeft"/> corner point.</param> /// <param name="y1">The Y coordinate of <see cref="XText.TopLeft"/> corner point.</param> /// <param name="x2">The X coordinate of <see cref="XText.BottomRight"/> corner point.</param> /// <param name="y2">The Y coordinate of <see cref="XText.BottomRight"/> corner point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="text">The text string.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XEllipse"/> class.</returns> public static XEllipse Create(double x1, double y1, double x2, double y2, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string text = null, string name = "") { return new XEllipse() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, TopLeft = XPoint.Create(x1, y1, point), BottomRight = XPoint.Create(x2, y2, point), Text = text, }; }
/// <summary> /// Creates a new <see cref="XEllipse"/> instance. /// </summary> /// <param name="topLeft">The <see cref="XText.TopLeft"/> corner point.</param> /// <param name="bottomRight">The <see cref="XText.BottomRight"/> corner point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="text">The text string.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XEllipse"/> class.</returns> public static XEllipse Create(XPoint topLeft, XPoint bottomRight, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string text = null, string name = "") { return new XEllipse() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, TopLeft = topLeft, BottomRight = bottomRight, Text = text, }; }
/// <summary> /// Move edited shape. /// </summary> /// <param name="shape">The shape object.</param> public virtual void Move(BaseShape shape) { }
/// <summary> /// Finalize edited shape. /// </summary> /// <param name="shape">The shape object.</param> public virtual void Finalize(BaseShape shape) { }
private void Remove(BaseShape shape) { if (shape == null) return; shape.PropertyChanged -= ObserveShape; if (shape.Data != null) { Remove(shape.Data); } if (shape.State != null) { shape.State.PropertyChanged -= ObserveState; } if (shape is XPoint) { var point = shape as XPoint; if (point.Shape != null) { point.Shape.PropertyChanged -= ObserveShape; } } else if (shape is XLine) { var line = shape as XLine; if (line.Start != null) { line.Start.PropertyChanged -= ObserveShape; } if (line.End != null) { line.End.PropertyChanged -= ObserveShape; } } else if (shape is XRectangle) { var rectangle = shape as XRectangle; if (rectangle.TopLeft != null) { rectangle.TopLeft.PropertyChanged -= ObserveShape; } if (rectangle.BottomRight != null) { rectangle.BottomRight.PropertyChanged -= ObserveShape; } } else if (shape is XEllipse) { var ellipse = shape as XEllipse; if (ellipse.TopLeft != null) { ellipse.TopLeft.PropertyChanged -= ObserveShape; } if (ellipse.BottomRight != null) { ellipse.BottomRight.PropertyChanged -= ObserveShape; } } else if (shape is XArc) { var arc = shape as XArc; if (arc.Point1 != null) { arc.Point1.PropertyChanged -= ObserveShape; } if (arc.Point2 != null) { arc.Point2.PropertyChanged -= ObserveShape; } if (arc.Point3 != null) { arc.Point3.PropertyChanged -= ObserveShape; } if (arc.Point4 != null) { arc.Point4.PropertyChanged -= ObserveShape; } } else if (shape is XCubicBezier) { var cubicBezier = shape as XCubicBezier; if (cubicBezier.Point1 != null) { cubicBezier.Point1.PropertyChanged -= ObserveShape; } if (cubicBezier.Point2 != null) { cubicBezier.Point2.PropertyChanged -= ObserveShape; } if (cubicBezier.Point3 != null) { cubicBezier.Point3.PropertyChanged -= ObserveShape; } if (cubicBezier.Point4 != null) { cubicBezier.Point4.PropertyChanged -= ObserveShape; } } else if (shape is XQuadraticBezier) { var quadraticBezier = shape as XQuadraticBezier; if (quadraticBezier.Point1 != null) { quadraticBezier.Point1.PropertyChanged -= ObserveShape; } if (quadraticBezier.Point2 != null) { quadraticBezier.Point2.PropertyChanged -= ObserveShape; } if (quadraticBezier.Point3 != null) { quadraticBezier.Point3.PropertyChanged -= ObserveShape; } } else if (shape is XText) { var text = shape as XText; if (text.TopLeft != null) { text.TopLeft.PropertyChanged -= ObserveShape; } if (text.BottomRight != null) { text.BottomRight.PropertyChanged -= ObserveShape; } } else if (shape is XImage) { var image = shape as XImage; if (image.TopLeft != null) { image.TopLeft.PropertyChanged -= ObserveShape; } if (image.BottomRight != null) { image.BottomRight.PropertyChanged -= ObserveShape; } } else if (shape is XPath) { var path = shape as XPath; if (path.Geometry != null) { Remove(path.Geometry); } } else if (shape is XGroup) { var group = shape as XGroup; if (group != null) { if (group.Shapes != null) { Remove(group.Shapes); } if (group.Connectors != null) { Remove(group.Connectors); } } } }
/// <summary> /// Creates a new <see cref="XPoint"/> instance. /// </summary> /// <param name="x">The X coordinate of point.</param> /// <param name="y">The Y coordinate of point.</param> /// <param name="shape">The point template.</param> /// <param name="alignment">The point alignment.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XPoint"/> class.</returns> public static XPoint Create(double x = 0.0, double y = 0.0, BaseShape shape = null, PointAlignment alignment = PointAlignment.None, string name = "") { return new XPoint() { Name = name, Style = default(ShapeStyle), X = x, Y = y, Alignment = alignment, Shape = shape }; }
public void Group_Shapes_Do_Not_Update_Source() { var shape1 = new Class1(); var shape2 = new Class1(); var point1 = new XPoint(); var point2 = new XPoint(); var shapes = new BaseShape[] { shape1, shape2, point1, point2 }; var source = shapes.ToList(); XGroup.Group("g", shapes, null); Assert.Contains(shape1, source); Assert.Contains(shape2, source); Assert.Contains(point1, source); Assert.Contains(point2, source); Assert.Equal(4, source.Count); }
public void Group_Shapes_Remove_And_Add_To_Source() { var shape1 = new Class1(); var shape2 = new Class1(); var point1 = new XPoint(); var point2 = new XPoint(); var shapes = new BaseShape[] { shape1, shape2, point1, point2 }; var source = shapes.ToList(); var target = XGroup.Group("g", shapes, source); Assert.Equal("g", target.Name); Assert.Contains(shape1, target.Shapes); Assert.Contains(shape2, target.Shapes); Assert.Equal(2, target.Shapes.Length); Assert.Contains(point1, target.Connectors); Assert.Contains(point2, target.Connectors); Assert.Equal(2, target.Connectors.Length); Assert.Contains(target, source); Assert.Equal(1, source.Count); }
/// <summary> /// Creates a new <see cref="XLine"/> instance. /// </summary> /// <param name="x1">The X coordinate of <see cref="XLine.Start"/> point.</param> /// <param name="y1">The Y coordinate of <see cref="XLine.Start"/> point.</param> /// <param name="x2">The X coordinate of <see cref="XLine.End"/> point.</param> /// <param name="y2">The Y coordinate of <see cref="XLine.End"/> point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XLine"/> class.</returns> public static XLine Create(double x1, double y1, double x2, double y2, ShapeStyle style, BaseShape point, bool isStroked = true, string name = "") { return new XLine() { Name = name, Style = style, IsStroked = isStroked, IsFilled = false, Start = XPoint.Create(x1, y1, point), End = XPoint.Create(x2, y2, point) }; }
/// <summary> /// Adds <see cref="BaseShape"/> to <see cref="Shapes"/> collection. /// </summary> /// <param name="shape">The shape object.</param> public void AddShape(BaseShape shape) { shape.Owner = this; shape.State.Flags &= ~ShapeStateFlags.Standalone; Shapes = Shapes.Add(shape); }
/// <summary> /// Creates a new <see cref="XCubicBezier"/> instance. /// </summary> /// <param name="point1">The <see cref="XCubicBezier.Point1"/> point.</param> /// <param name="point2">The <see cref="XCubicBezier.Point2"/> point.</param> /// <param name="point3">The <see cref="XCubicBezier.Point3"/> point.</param> /// <param name="point4">The <see cref="XCubicBezier.Point4"/> point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XCubicBezier"/> class.</returns> public static XCubicBezier Create(XPoint point1, XPoint point2, XPoint point3, XPoint point4, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string name = "") { return new XCubicBezier() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, Point1 = point1, Point2 = point2, Point3 = point3, Point4 = point4 }; }
/// <summary> /// Creates a new <see cref="XCubicBezier"/> instance. /// </summary> /// <param name="x">The X coordinate of <see cref="XCubicBezier.Point1"/>, <see cref="XCubicBezier.Point2"/>, <see cref="XCubicBezier.Point3"/> and <see cref="XCubicBezier.Point4"/> points.</param> /// <param name="y">The Y coordinate of <see cref="XCubicBezier.Point1"/>, <see cref="XCubicBezier.Point2"/>, <see cref="XCubicBezier.Point3"/> and <see cref="XCubicBezier.Point4"/> points.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XCubicBezier"/> class.</returns> public static XCubicBezier Create(double x, double y, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string name = "") { return Create(x, y, x, y, x, y, x, y, style, point, isStroked, isFilled, name); }
/// <inheritdoc/> public override void Move(BaseShape shape) { base.Move(shape); _selection.Move(); }
/// <summary> /// Creates a new <see cref="XLine"/> instance. /// </summary> /// <param name="start">The <see cref="XLine.Start"/> point.</param> /// <param name="end">The <see cref="XLine.End"/> point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XLine"/> class.</returns> public static XLine Create(XPoint start, XPoint end, ShapeStyle style, BaseShape point, bool isStroked = true, string name = "") { return new XLine() { Name = name, Style = style, IsStroked = isStroked, IsFilled = false, Start = start, End = end }; }
/// <summary> /// Creates a new <see cref="XRectangle"/> instance. /// </summary> /// <param name="x1">The X coordinate of <see cref="XText.TopLeft"/> corner point.</param> /// <param name="y1">The Y coordinate of <see cref="XText.TopLeft"/> corner point.</param> /// <param name="x2">The X coordinate of <see cref="XText.BottomRight"/> corner point.</param> /// <param name="y2">The Y coordinate of <see cref="XText.BottomRight"/> corner point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="text">The text string.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XRectangle"/> class.</returns> public static XRectangle Create(double x1, double y1, double x2, double y2, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string text = null, string name = "") { return new XRectangle() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, TopLeft = XPoint.Create(x1, y1, point), BottomRight = XPoint.Create(x2, y2, point), Text = text, IsGrid = false, OffsetX = 30.0, OffsetY = 30.0, CellWidth = 30.0, CellHeight = 30.0 }; }
/// <summary> /// Ungroup shape. /// </summary> /// <param name="shape">The shape instance.</param> /// <param name="source">The source shapes collection.</param> /// <param name="isShapeFromGroup">The flag indicating whether shape originates from group.</param> public static void Ungroup(BaseShape shape, IList<BaseShape> source, bool isShapeFromGroup = false) { if (shape != null && source != null) { if (shape is XGroup) { var group = shape as XGroup; Ungroup(group.Shapes, source, isShapeFromGroup: true); Ungroup(group.Connectors, source, isShapeFromGroup: true); // Remove group from source collection. source.Remove(group); } else if (isShapeFromGroup) { if (shape is XPoint) { // Remove connector related state flags. shape.State.Flags &= ~(ShapeStateFlags.Connector | ShapeStateFlags.None | ShapeStateFlags.Input | ShapeStateFlags.Output); } // Add shape standalone flag. shape.State.Flags |= ShapeStateFlags.Standalone; // Add shape to source collection. source.Add(shape); } } }
/// <summary> /// Hit test point in shape bounds. /// </summary> /// <param name="shape"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTest(BaseShape shape, Vector2 v, double threshold, double dx, double dy) { if (shape is XPoint) { return HitTestPoint(shape as XPoint, v, threshold, dx, dy); } else if (shape is XLine) { return HitTestLine(shape as XLine, v, threshold, dx, dy); } else if (shape is XRectangle) { return HitTestRectangle(shape as XRectangle, v, threshold, dx, dy); } else if (shape is XEllipse) { return HitTestEllipse(shape as XEllipse, v, threshold, dx, dy); } else if (shape is XArc) { return HitTestArc(shape as XArc, v, threshold, dx, dy); } else if (shape is XCubicBezier) { return HitTestCubicBezier(shape as XCubicBezier, v, threshold, dx, dy); } else if (shape is XQuadraticBezier) { return HitTestQuadraticBezier(shape as XQuadraticBezier, v, threshold, dx, dy); } else if (shape is XText) { return HitTestText(shape as XText, v, threshold, dx, dy); } else if (shape is XImage) { return HitTestImage(shape as XImage, v, threshold, dx, dy); } else if (shape is XPath) { return HitTestPath(shape as XPath, v, threshold, dx, dy); } else if (shape is XGroup) { return HitTestGroup(shape as XGroup, v, threshold, dx, dy); } return null; }
/// <summary> /// Creates a new <see cref="XLine"/> instance. /// </summary> /// <param name="x">The X coordinate of <see cref="XLine.Start"/> and <see cref="XLine.End"/> points.</param> /// <param name="y">The Y coordinate of <see cref="XLine.Start"/> and <see cref="XLine.End"/> points.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XLine"/> class.</returns> public static XLine Create(double x, double y, ShapeStyle style, BaseShape point, bool isStroked = true, string name = "") { return Create(x, y, x, y, style, point, isStroked, name); }
/// <inheritdoc/> public override void Finalize(BaseShape shape) { base.Finalize(shape); var arc = shape as XArc; var a = WpfArc.FromXArc(arc); if (!_connectedPoint3) { arc.Point3.X = a.Start.X; arc.Point3.Y = a.Start.Y; } if (!_connectedPoint4) { arc.Point4.X = a.End.X; arc.Point4.Y = a.End.Y; } }
/// <summary> /// Creates a new <see cref="XCubicBezier"/> instance. /// </summary> /// <param name="x1">The X coordinate of <see cref="XCubicBezier.Point1"/> point.</param> /// <param name="y1">The Y coordinate of <see cref="XCubicBezier.Point1"/> point.</param> /// <param name="x2">The X coordinate of <see cref="XCubicBezier.Point2"/> point.</param> /// <param name="y2">The Y coordinate of <see cref="XCubicBezier.Point2"/> point.</param> /// <param name="x3">The X coordinate of <see cref="XCubicBezier.Point3"/> point.</param> /// <param name="y3">The Y coordinate of <see cref="XCubicBezier.Point3"/> point.</param> /// <param name="x4">The X coordinate of <see cref="XCubicBezier.Point4"/> point.</param> /// <param name="y4">The Y coordinate of <see cref="XCubicBezier.Point4"/> point.</param> /// <param name="style">The shape style.</param> /// <param name="point">The point template.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isFilled">The flag indicating whether shape is filled.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XCubicBezier"/> class.</returns> public static XCubicBezier Create(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string name = "") { return new XCubicBezier() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, Point1 = XPoint.Create(x1, y1, point), Point2 = XPoint.Create(x2, y2, point), Point3 = XPoint.Create(x3, y3, point), Point4 = XPoint.Create(x4, y4, point) }; }