/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> public override void LeftDown(double x, double y) { double sx = _editor.Project.Options.SnapToGrid ? Editor.Snap(x, _editor.Project.Options.SnapX) : x; double sy = _editor.Project.Options.SnapToGrid ? Editor.Snap(y, _editor.Project.Options.SnapY) : y; switch (_currentState) { case State.None: { _shape = XPoint.Create(sx, sy, _editor.Project.Options.PointShape); if (_editor.Project.Options.TryToConnect) { if (!_editor.TryToSplitLine(x, y, _shape, true)) { _editor.AddWithHistory(_shape); } } else { _editor.AddWithHistory(_shape); } } break; } }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="treshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 GetPointBounds(XPoint point, double treshold, double dx, double dy) { double radius = treshold / 2.0; return new Rect2( point.X - radius + dx, point.Y - radius + dy, treshold, treshold); }
/// <summary> /// /// </summary> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="isStroked"></param> /// <param name="isSmoothJoin"></param> /// <returns></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> /// /// </summary> /// <param name="startPoint"></param> /// <param name="segments"></param> /// <param name="isFilled"></param> /// <param name="isClosed"></param> /// <returns></returns> public static XPathFigure Create( XPoint startPoint, IList<XPathSegment> segments, bool isFilled, bool isClosed) { return new XPathFigure() { StartPoint = startPoint, Segments = segments, IsFilled = isFilled, IsClosed = isClosed }; }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="size"></param> /// <param name="rotationAngle"></param> /// <param name="isLargeArc"></param> /// <param name="sweepDirection"></param> /// <param name="isStroked"></param> /// <param name="isSmoothJoin"></param> public void ArcTo( XPoint point, XPathSize size, double rotationAngle, bool isLargeArc = false, XSweepDirection sweepDirection = XSweepDirection.Clockwise, bool isStroked = true, bool isSmoothJoin = true) { var segment = XArcSegment.Create( point, size, rotationAngle, isLargeArc, sweepDirection, isStroked, isSmoothJoin); _figure.Segments.Add(segment); }
/// <summary> /// /// </summary> /// <param name="start"></param> /// <param name="end"></param> /// <param name="style"></param> /// <param name="point"></param> /// <param name="isStroked"></param> /// <param name="name"></param> /// <returns></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, Bindings = ImmutableArray.Create<ShapeBinding>(), Properties = ImmutableArray.Create<ShapeProperty>(), Start = start, End = end }; }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="size"></param> /// <param name="rotationAngle"></param> /// <param name="isLargeArc"></param> /// <param name="sweepDirection"></param> /// <param name="isStroked"></param> /// <param name="isSmoothJoin"></param> /// <returns></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> /// /// </summary> public override void Remove() { if (_topLeftHelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_topLeftHelperPoint); _topLeftHelperPoint = null; } if (_bottomRightHelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_bottomRightHelperPoint); _bottomRightHelperPoint = null; } }
/// <summary> /// /// </summary> public override void ToStateOne() { _topLeftHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_topLeftHelperPoint); _bottomRightHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_bottomRightHelperPoint); }
/// <summary> /// /// </summary> /// <param name="tl"></param> /// <param name="br"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static Rect2 Create( XPoint tl, XPoint br, double dx = 0.0, double dy = 0.0) { return(Rect2.Create(tl.X, tl.Y, br.X, br.Y, dx, dy)); }
/// <summary> /// /// </summary> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="isStroked"></param> /// <param name="isSmoothJoin"></param> public void QuadraticBezierTo( XPoint point1, XPoint point2, bool isStroked = true, bool isSmoothJoin = true) { var segment = XQuadraticBezierSegment.Create( point1, point2, isStroked, isSmoothJoin); _figure.Segments.Add(segment); }
/// <summary> /// /// </summary> public override void ToStateTwo() { if (_p1HelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } _startLine = XLine.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_startLine); _startHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_startHelperPoint); }
/// <summary> /// /// </summary> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="point3"></param> /// <param name="point4"></param> /// <param name="style"></param> /// <param name="point"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="name"></param> /// <returns></returns> public static XArc Create( XPoint point1, XPoint point2, XPoint point3, XPoint point4, ShapeStyle style, BaseShape point, bool isStroked = true, bool isFilled = false, string name = "") { return new XArc() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, Bindings = ImmutableArray.Create<ShapeBinding>(), Properties = ImmutableArray.Create<ShapeProperty>(), Point1 = point1, Point2 = point2, Point3 = point3, Point4 = point4 }; }
/// <summary> /// /// </summary> /// <param name="tl"></param> /// <param name="br"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> 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> /// /// </summary> /// <param name="topLeft"></param> /// <param name="bottomRight"></param> /// <param name="style"></param> /// <param name="point"></param> /// <param name="path"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="text"></param> /// <param name="name"></param> /// <returns></returns> public static XImage Create( XPoint topLeft, XPoint bottomRight, ShapeStyle style, BaseShape point, string path, bool isStroked = false, bool isFilled = false, string text = null, string name = "") { return new XImage() { Name = name, Style = style, IsStroked = isStroked, IsFilled = isFilled, Data = new Data() { Bindings = ImmutableArray.Create<ShapeBinding>(), Properties = ImmutableArray.Create<ShapeProperty>() }, TopLeft = topLeft, BottomRight = bottomRight, Path = path, Text = text }; }
/// <summary> /// /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="p3"></param> /// <param name="p4"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static GdiArc FromXArc(XPoint p1, XPoint p2, XPoint p3, XPoint p4, double dx, double dy) { double x1 = p1.X + dx; double y1 = p1.Y + dy; double x2 = p2.X + dx; double y2 = p2.Y + dy; double x3 = p3.X + dx; double y3 = p3.Y + dy; double x4 = p4.X + dx; double y4 = p4.Y + dy; var rect = Rect2.Create(x1, y1, x2, y2, dx, dy); 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 = Math.Atan2(y3 - cy, x3 - cx); double endAngle = Math.Atan2(y4 - cy, x4 - cx); double sweepAngle = (endAngle - startAngle) * 180.0 / Math.PI; if (sweepAngle < 0) sweepAngle += 360; startAngle *= 180.0 / Math.PI; endAngle *= 180.0 / Math.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> /// /// </summary> /// <param name="point"></param> public void AddConnectorAsNone(XPoint point) { point.Owner = this; point.State |= ShapeState.Connector | ShapeState.None; point.State &= ~ShapeState.Standalone; Connectors = Connectors.Add(point); }
/// <summary> /// /// </summary> public override void ToStateOne() { _style = _editor.Project.Options.HelperStyle; _ellipse = XEllipse.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_ellipse); _p1HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p1HelperPoint); _p2HelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_p2HelperPoint); _centerHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_centerHelperPoint); }
/// <summary> /// /// </summary> /// <param name="topLeft"></param> /// <param name="bottomRight"></param> /// <param name="style"></param> /// <param name="point"></param> /// <param name="text"></param> /// <param name="isStroked"></param> /// <param name="name"></param> /// <returns></returns> public static XText Create( XPoint topLeft, XPoint bottomRight, ShapeStyle style, BaseShape point, string text, bool isStroked = true, string name = "") { return new XText() { Name = name, Style = style, IsStroked = isStroked, Bindings = ImmutableArray.Create<ShapeBinding>(), Properties = ImmutableArray.Create<ShapeProperty>(), TopLeft = topLeft, BottomRight = bottomRight, Text = text }; }
/// <summary> /// /// </summary> public override void Remove() { if (_ellipse != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse); _ellipse = null; } if (_startLine != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startLine); _startLine = null; } if (_endLine != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endLine); _endLine = null; } if (_p1HelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } if (_centerHelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_centerHelperPoint); _centerHelperPoint = null; } if (_startHelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_startHelperPoint); _startHelperPoint = null; } if (_endHelperPoint != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_endHelperPoint); _endHelperPoint = null; } _style = null; }
/// <summary> /// /// </summary> /// <param name="topLeft"></param> /// <param name="bottomRight"></param> /// <param name="style"></param> /// <param name="point"></param> /// <param name="isStroked"></param> /// <param name="isFilled"></param> /// <param name="text"></param> /// <param name="name"></param> /// <returns></returns> public static XRectangle Create( XPoint topLeft, XPoint bottomRight, 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, Bindings = ImmutableArray.Create<ShapeBinding>(), Properties = ImmutableArray.Create<ShapeProperty>(), TopLeft = topLeft, BottomRight = bottomRight, Text = text, IsGrid = false, OffsetX = 30.0, OffsetY = 30.0, CellWidth = 30.0, CellHeight = 30.0 }; }
/// <summary> /// /// </summary> /// <param name="startPoint"></param> /// <param name="isFilled"></param> /// <param name="isClosed"></param> public void BeginFigure( XPoint startPoint, bool isFilled = true, bool isClosed = true) { _figure = XPathFigure.Create( startPoint, new List<XPathSegment>(), isFilled, isClosed); Figures.Add(_figure); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <returns></returns> public double Distance(XPoint point) { double dx = this.X - point.X; double dy = this.Y - point.Y; return Math.Sqrt(dx * dx + dy * dy); }
/// <summary> /// /// </summary> public override void ToStateThree() { if (_ellipse != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_ellipse); _ellipse = null; } _endLine = XLine.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endLine); _endHelperPoint = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_endHelperPoint); }
/// <summary> /// /// </summary> /// <param name="point"></param> public void AddConnectorAsOutput(XPoint point) { point.Owner = this; point.State.Flags |= ShapeStateFlags.Connector | ShapeStateFlags.Output; point.State.Flags &= ~ShapeStateFlags.Standalone; Connectors = Connectors.Add(point); }
/// <summary> /// /// </summary> public override void Remove() { if (_line12 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_line12); _line12 = null; } if (_line43 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_line43); _line43 = null; } if (_line23 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_line23); _line23 = null; } if (_helperPoint1 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_helperPoint1); _helperPoint1 = null; } if (_helperPoint2 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_helperPoint2); _helperPoint2 = null; } if (_helperPoint3 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_helperPoint3); _helperPoint3 = null; } if (_helperPoint4 != null) { _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Remove(_helperPoint4); _helperPoint4 = null; } _style = null; }
/// <summary> /// /// </summary> /// <param name="tl"></param> /// <param name="br"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> private static Rect2 CreateRect(XPoint tl, XPoint br, double dx, double dy) { return Rect2.Create(tl, br, dx, dy); }
/// <summary> /// /// </summary> public override void ToStateOne() { _style = _editor.Project.Options.HelperStyle; _helperPoint1 = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_helperPoint1); _helperPoint4 = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_helperPoint4); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="isStroked"></param> /// <param name="isSmoothJoin"></param> public void LineTo( XPoint point, bool isStroked = true, bool isSmoothJoin = true) { var segment = XLineSegment.Create( point, isStroked, isSmoothJoin); _figure.Segments.Add(segment); }
/// <summary> /// /// </summary> public override void ToStateThree() { _line43 = XLine.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_line43); _line23 = XLine.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_line23); _helperPoint3 = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_helperPoint3); }
/// <summary> /// /// </summary> public override void ToStateTwo() { _style = _editor.Project.Options.HelperStyle; _line12 = XLine.Create(0, 0, _style, null); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_line12); _helperPoint2 = XPoint.Create(0, 0, _editor.Project.Options.PointShape); _editor.Project.CurrentContainer.HelperLayer.Shapes = _editor.Project.CurrentContainer.HelperLayer.Shapes.Add(_helperPoint2); }
/// <summary> /// /// </summary> /// <param name="tl"></param> /// <param name="br"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> private static Rect2 CreateRect(XPoint tl, XPoint br, double dx, double dy) { return(Rect2.Create(tl, br, dx, dy)); }