/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _helperPoint1 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_helperPoint1); _helperPoint4 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_helperPoint4); }
/// <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; }
/// <inheritdoc/> public override void LeftDown(double x, double y) { base.LeftDown(x, y); var editor = _serviceProvider.GetService<ProjectEditor>(); 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: { _point = XPoint.Create(sx, sy, editor.Project.Options.PointShape); if (editor.Project.Options.TryToConnect) { if (!editor.TryToSplitLine(x, y, _point, true)) { editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _point); } } else { editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _point); } } break; } }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _topLeftHelperPoint = XPoint.Create(0, 0, _point); _bottomRightHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint); _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint); }
/// <summary> /// Transfer selection state to <see cref="ToolState.Two"/>. /// </summary> public void ToStateTwo() { _line12 = XLine.Create(0, 0, _style, null); _helperPoint2 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_line12); _layer.Shapes = _layer.Shapes.Add(_helperPoint2); }
/// <inheritdoc/> public override void LineTo(XPoint point, bool isStroked = true, bool isSmoothJoin = true) { var segment = XLineSegment.Create( point, isStroked, isSmoothJoin); _currentFigure.Segments = _currentFigure.Segments.Add(segment); }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _startHelperPoint = XPoint.Create(0, 0, _point); _endHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_startHelperPoint); _layer.Shapes = _layer.Shapes.Add(_endHelperPoint); }
/// <inheritdoc/> public override void QuadraticBezierTo(XPoint point1, XPoint point2, bool isStroked = true, bool isSmoothJoin = true) { var segment = XQuadraticBezierSegment.Create( point1, point2, isStroked, isSmoothJoin); _currentFigure.Segments = _currentFigure.Segments.Add(segment); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTestPoint(XPoint point, Vector2 v, double threshold, double dx, double dy) { if (ShapeBounds.GetPointBounds(point, threshold, dx, dy).Contains(v)) { return point; } return null; }
/// <summary> /// Creates a new <see cref="XLineSegment"/> instance. /// </summary> /// <param name="point">The end point.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isSmoothJoin">The flag indicating whether shape is smooth join.</param> /// <returns>The new instance of the <see cref="XLineSegment"/> class.</returns> public static XLineSegment Create(XPoint point, bool isStroked, bool isSmoothJoin) { return new XLineSegment() { Point = point, IsStroked = isStroked, IsSmoothJoin = isSmoothJoin }; }
/// <summary> /// Transfer selection state to <see cref="ToolState.Three"/>. /// </summary> public void ToStateThree() { _line43 = XLine.Create(0, 0, _style, null); _line23 = XLine.Create(0, 0, _style, null); _helperPoint3 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_line43); _layer.Shapes = _layer.Shapes.Add(_line23); _layer.Shapes = _layer.Shapes.Add(_helperPoint3); }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _helperRectangle = XRectangle.Create(0, 0, _style, null); _topLeftHelperPoint = XPoint.Create(0, 0, _point); _bottomRightHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_helperRectangle); _layer.Shapes = _layer.Shapes.Add(_topLeftHelperPoint); _layer.Shapes = _layer.Shapes.Add(_bottomRightHelperPoint); }
/// <summary> /// Creates a new <see cref="XQuadraticBezierSegment"/> instance. /// </summary> /// <param name="point1">The control point.</param> /// <param name="point2">The end point.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isSmoothJoin">The flag indicating whether shape is smooth join.</param> /// <returns>The new instance of the <see cref="XQuadraticBezierSegment"/> class.</returns> public static XQuadraticBezierSegment Create(XPoint point1, XPoint point2, bool isStroked, bool isSmoothJoin) { return new XQuadraticBezierSegment() { Point1 = point1, Point2 = point2, IsStroked = isStroked, IsSmoothJoin = isSmoothJoin }; }
/// <summary> /// Transfer selection state to <see cref="ToolState.One"/>. /// </summary> public void ToStateOne() { _ellipse = XEllipse.Create(0, 0, _style, null); _p1HelperPoint = XPoint.Create(0, 0, _point); _p2HelperPoint = XPoint.Create(0, 0, _point); _centerHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_ellipse); _layer.Shapes = _layer.Shapes.Add(_p1HelperPoint); _layer.Shapes = _layer.Shapes.Add(_p2HelperPoint); _layer.Shapes = _layer.Shapes.Add(_centerHelperPoint); }
/// <inheritdoc/> XLine IShapeFactory.Line(XPoint start, XPoint end, bool isStroked) { var style = _editor.Project.CurrentStyleLibrary.Selected; var line = XLine.Create( start, end, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, line); return line; }
/// <inheritdoc/> public override void ArcTo(XPoint point, XPathSize size, double rotationAngle = 0.0, bool isLargeArc = false, XSweepDirection sweepDirection = XSweepDirection.Clockwise, bool isStroked = true, bool isSmoothJoin = true) { var segment = XArcSegment.Create( point, size, rotationAngle, isLargeArc, sweepDirection, isStroked, isSmoothJoin); _currentFigure.Segments = _currentFigure.Segments.Add(segment); }
/// <summary> /// Creates a new <see cref="XArcSegment"/> instance. /// </summary> /// <param name="point">The end point.</param> /// <param name="size">The arc size.</param> /// <param name="rotationAngle">The rotation angle.</param> /// <param name="isLargeArc">The is large flag.</param> /// <param name="sweepDirection">The sweep direction flag.</param> /// <param name="isStroked">The flag indicating whether shape is stroked.</param> /// <param name="isSmoothJoin">The flag indicating whether shape is smooth join.</param> /// <returns>The new instance of the <see cref="XArcSegment"/> class.</returns> public static XArcSegment Create(XPoint point, XPathSize size, double rotationAngle, bool isLargeArc, XSweepDirection sweepDirection, bool isStroked, bool isSmoothJoin) { return new XArcSegment() { Point = point, Size = size, RotationAngle = rotationAngle, IsLargeArc = isLargeArc, SweepDirection = sweepDirection, IsStroked = isStroked, IsSmoothJoin = isSmoothJoin }; }
/// <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, }; }
public void ShapesProperties_Gets_Shapes_And_Connectors_Properties() { var target = new XGroup(); var shape = new Class1(); shape.Data.Properties = shape.Data.Properties.Add(new XProperty()); target.Shapes = target.Shapes.Add(shape); var point = new XPoint(); point.Data.Properties = point.Data.Properties.Add(new XProperty()); target.Connectors = target.Connectors.Add(point); Assert.Equal(2, target.ShapesProperties.Length); }
/// <inheritdoc/> XArc IShapeFactory.Arc(XPoint point1, XPoint point2, XPoint point3, XPoint point4, bool isStroked, bool isFilled) { var style = _editor.Project.CurrentStyleLibrary.Selected; var arc = XArc.Create( point1, point2, point3, point4, _editor.Project.Options.CloneStyle ? style.Clone() : style, _editor.Project.Options.PointShape, isStroked, isFilled); _editor.Project.AddShape(_editor.Project.CurrentContainer.CurrentLayer, arc); return arc; }
/// <summary> /// Remove selection. /// </summary> public void Remove() { if (_topLeftHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_topLeftHelperPoint); _topLeftHelperPoint = null; } if (_bottomRightHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_bottomRightHelperPoint); _bottomRightHelperPoint = null; } _layer.Invalidate(); }
public void ShapesProperties_Cache_Should_Reset_After_Connectors_Updated() { var target = new XGroup(); var point1 = new XPoint(); point1.Data.Properties = point1.Data.Properties.Add(new XProperty()); target.Connectors = target.Connectors.Add(point1); Assert.Equal(1, target.ShapesProperties.Length); var point2 = new XPoint(); point2.Data.Properties = point2.Data.Properties.Add(new XProperty()); target.Connectors = target.Connectors.Add(point2); Assert.Equal(2, target.ShapesProperties.Length); }
/// <summary> /// Remove selection. /// </summary> public void Remove() { if (_startHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_startHelperPoint); _startHelperPoint = null; } if (_endHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_endHelperPoint); _endHelperPoint = null; } _layer.Invalidate(); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="rect"></param> /// <param name="selected"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTestPoint(XPoint point, Rect2 rect, ISet<BaseShape> selected, double threshold, double dx, double dy) { if (ShapeBounds.GetPointBounds(point, threshold, dx, dy).IntersectsWith(rect)) { if (selected != null) { selected.Add(point); } else { return true; } } return false; }
/// <summary> /// Transfer selection state to <see cref="ToolState.Two"/>. /// </summary> public void ToStateTwo() { if (_p1HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } _startLine = XLine.Create(0, 0, _style, null); _startHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_startLine); _layer.Shapes = _layer.Shapes.Add(_startHelperPoint); }
/// <summary> /// /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="p4"></param> /// <returns></returns> public static GdiArc FromXArc(XPoint p1, XPoint p2, XPoint p3, XPoint p4) { double x1 = p1.X; double y1 = p1.Y; double x2 = p2.X; double y2 = p2.Y; double x3 = p3.X; double y3 = p3.Y; double x4 = p4.X; double y4 = p4.Y; var rect = Rect2.Create(x1, y1, x2, y2); double cx = rect.X + rect.Width / 2.0; double cy = rect.Y + rect.Height / 2.0; double radiusX = cx - rect.X; double radiusY = cy - rect.Y; double startAngle = Atan2(y3 - cy, x3 - cx); double endAngle = Atan2(y4 - cy, x4 - cx); double sweepAngle = (endAngle - startAngle) * 180.0 / PI; if (sweepAngle < 0) sweepAngle += 360; startAngle *= 180.0 / PI; endAngle *= 180.0 / PI; return new GdiArc { X = rect.X, Y = rect.Y, Width = rect.Width, Height = rect.Height, RadiusX = radiusX, RadiusY = radiusY, StartAngle = startAngle, EndAngle = endAngle, SweepAngle = sweepAngle }; }
/// <summary> /// Transfer selection state to <see cref="ToolState.Three"/>. /// </summary> public void ToStateThree() { if (_ellipse != null) { _layer.Shapes = _layer.Shapes.Remove(_ellipse); _ellipse = null; } _endLine = XLine.Create(0, 0, _style, null); _endHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_endLine); _layer.Shapes = _layer.Shapes.Add(_endHelperPoint); }
/// <summary> /// Remove selection. /// </summary> public void Remove() { 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(); }
private static Rect CreateRect(XPoint tl, XPoint br, double dx, double dy) { double tlx = Math.Min(tl.X, br.X); double tly = Math.Min(tl.Y, br.Y); double brx = Math.Max(tl.X, br.X); double bry = Math.Max(tl.Y, br.Y); return new Rect( new Point(tlx + dx, tly + dy), new Point(brx + dx, bry + dy)); }
/// <summary> /// Calculates distance between points. /// </summary> /// <param name="point">The other point</param> /// <returns>The distance between points.</returns> public double DistanceTo(XPoint point) { double dx = this.X - point.X; double dy = this.Y - point.Y; return Sqrt(dx * dx + dy * dy); }