Ejemplo n.º 1
0
        public bool SnapToVertical(PointF pt, float xVal, float snapDistance)
        {
            bool        flag       = false;
            float       num1       = snapDistance * snapDistance;
            PointF      pointF     = new PointF();
            IShapeCurve shapeCurve = (IShapeCurve)null;

            for (int index = 0; index < this.lines.Count; ++index)
            {
                if (this.lines[index].SnapToVertical(pt, xVal, snapDistance))
                {
                    float num2 = ShapePoint.DistSquared(this.lines[index].SnappedPoint, pt);
                    if ((double)num1 >= (double)num2)
                    {
                        num1       = num2;
                        pointF     = this.lines[index].SnappedPoint;
                        shapeCurve = this.lines[index];
                        flag       = true;
                    }
                }
            }
            if (flag)
            {
                this.snappedPoint = pointF;
                this.snappedCurve = shapeCurve;
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public bool SnapToCtrlPoints(PointF pt, float snapDistance)
        {
            float num1 = snapDistance * snapDistance;
            float num2 = num1 + 2f;
            float num3 = num1 + 2f;

            if (!this.points[0].IsModified)
            {
                num2 = ShapePoint.DistSquared(this.points[0].Location, pt);
            }
            if (!this.points[1].IsModified)
            {
                num3 = ShapePoint.DistSquared(this.points[1].Location, pt);
            }
            ShapePoint point;

            if ((double)num2 < (double)num3)
            {
                point = this.points[0];
            }
            else
            {
                num2  = num3;
                point = this.points[1];
            }
            if ((double)num2 >= (double)num1)
            {
                return(false);
            }
            this.snapCtrl = point;
            return(true);
        }
Ejemplo n.º 3
0
 public ShapeLine(ShapePoint from, ShapePoint to)
 {
     this.points    = new ShapePoint[2];
     this.points[0] = from;
     this.points[1] = to;
     this.snapPoint = new PointF();
     this.snapCtrl  = (ShapePoint)null;
 }
Ejemplo n.º 4
0
        private void DrawEndPoint(PaintEventArgs e, ShapePoint pt)
        {
            RectangleF r = new RectangleF();

            r.Location = zoom.PtToVisible(pt.Location);
            r.Inflate(2, 2);
            e.Graphics.FillEllipse(BrushControlPoints, r);
        }
Ejemplo n.º 5
0
 public ShapeLine(ShapePoint from, ShapePoint to)
 {
     points    = new ShapePoint[2];
     points[0] = from;
     points[1] = to;
     snapPoint = new PointF();
     snapCtrl  = null;
 }
Ejemplo n.º 6
0
        private void DrawEndPoint(PaintEventArgs e, ShapePoint pt)
        {
            RectangleF rect = new RectangleF();

            rect.Location = this.zoom.PtToVisible(pt.Location);
            rect.Inflate(2f, 2f);
            e.Graphics.FillEllipse(this.BrushControlPoints, rect);
        }
Ejemplo n.º 7
0
 public ShapeBezier()
 {
     this.detailLevel    = 32;
     this.ctrl           = new ShapePoint[4];
     this.points         = new ShapePoint[this.detailLevel];
     this.snappedCtrl    = (ShapePoint)null;
     this.snappedPoint   = new PointF();
     this.snapSegmentNum = -1;
 }
Ejemplo n.º 8
0
        public ShapeBezier()
        {
            detailLevel = 32;
            ctrl        = new ShapePoint[4];
            points      = new ShapePoint[detailLevel];

            snappedCtrl    = null;
            snappedPoint   = new PointF();
            snapSegmentNum = -1;
        }
Ejemplo n.º 9
0
        //Rectangle Shape
        public void CreateRectangleShape(PointF from, PointF to)
        {
            ShapePoint[] pt = new ShapePoint[4]
            {
                new ShapePoint(from), new ShapePoint(to.X, from.Y),
                new ShapePoint(to), new ShapePoint(from.X, to.Y)
            };

            CreateClosedShape(pt);
        }
Ejemplo n.º 10
0
        private RectangleF SegmentBoundingRect(RectangleF rect, ShapePoint pt1, ShapePoint pt2)
        {
            rect.X = Math.Min(pt1.X, pt2.X);
            rect.Y = Math.Min(pt1.Y, pt2.Y);

            rect.Width  = Math.Abs(pt1.X - pt2.X);
            rect.Height = Math.Abs(pt1.Y - pt2.Y);

            return(rect);
        }
Ejemplo n.º 11
0
        public bool AppendLine(PointF to)
        {
            ShapePoint lastPoint = this.shape.GetLastPoint();

            if (lastPoint == null)
            {
                return(false);
            }
            this.shape.Add((IShapeCurve) new ShapeLine(lastPoint, new ShapePoint(to)));
            return(true);
        }
Ejemplo n.º 12
0
        public bool AppendBezier(PointF ctrl1, PointF ctrl2, PointF to)
        {
            ShapePoint lastPoint = this.shape.GetLastPoint();

            if (lastPoint == null)
            {
                return(false);
            }
            this.shape.Add((IShapeCurve) new ShapeBezier(lastPoint, new ShapePoint(ctrl1), new ShapePoint(ctrl2), new ShapePoint(to)));
            return(true);
        }
Ejemplo n.º 13
0
        public bool CloseFigureUsingLine()
        {
            ShapePoint firstPoint = this.shape.GetFirstPoint();
            ShapePoint lastPoint  = this.shape.GetLastPoint();

            if (firstPoint == null || lastPoint == null)
            {
                return(false);
            }
            this.shape.Add((IShapeCurve) new ShapeLine(lastPoint, firstPoint));
            return(true);
        }
Ejemplo n.º 14
0
        public bool CloseFigureUsingBezier(PointF ctrl1, PointF ctrl2)
        {
            ShapePoint firstPoint = this.shape.GetFirstPoint();
            ShapePoint lastPoint  = this.shape.GetLastPoint();

            if (firstPoint == null || lastPoint == null)
            {
                return(false);
            }
            this.shape.Add((IShapeCurve) new ShapeBezier(lastPoint, new ShapePoint(ctrl1), new ShapePoint(ctrl2), firstPoint));
            return(true);
        }
Ejemplo n.º 15
0
        public bool SnapToCurveExtension(PointF pt, float snapDistance)
        {
            PointF point1 = new PointF();
            PointF point2 = new PointF();

            bool finalSnapResult = true;

            int   snapResult = 0;
            float dist1 = 0, dist2 = 0;

            if (!ctrl[0].IsModified && !ctrl[1].IsModified)
            {
                snapResult += SnapToExtension(ref point1, pt, ctrl[0], ctrl[1], snapDistance, ref dist1) ? 1 : 0;
            }

            if (!ctrl[3].IsModified && !ctrl[2].IsModified)
            {
                snapResult += SnapToExtension(ref point2, pt, ctrl[3], ctrl[2], snapDistance, ref dist2) ? 2 : 0;
            }

            switch (snapResult)
            {
            default:
            case 0:
                // none is snapped
                finalSnapResult = false;
                break;

            case 1:
                // point1 is snapped to extension 1
                snappedPoint = point1;
                break;

            case 2:
                // point2 is snapped to extension 2
                snappedPoint = point2;
                break;

            case 3:
                // both lines are snapped-to-, should find closer one
                if (ShapePoint.DistSquared(pt, point1) <= ShapePoint.DistSquared(pt, point2))
                {
                    snappedPoint = point1;
                }
                else
                {
                    snappedPoint = point2;
                }
                break;
            }

            return(finalSnapResult);
        }
Ejemplo n.º 16
0
        // SnapToGrid types:
        // 1 - snap to horizontal
        // 2 - snap to vertical
        // 3 - snap to both
        public bool SnapToGrid(PointF pt, PointF gridPt, int type, float snapDistance)
        {
            bool        snappingOccured = false;
            int         tmpRes          = 0; // temporary result to find the closer snapped point
            PointF      point1          = new PointF();
            IShapeCurve snapCurve       = null;

            if ((type & 0x01) != 0)
            {
                tmpRes   += SnapToHorizontal(pt, gridPt.Y, snapDistance) ? 1 : 0;
                point1    = snappedPoint;
                snapCurve = snappedCurve;
            }

            if ((type & 0x02) != 0)
            {
                tmpRes += SnapToVertical(pt, gridPt.X, snapDistance) ? 2 : 0;
            }

            switch (tmpRes)
            {
            default:
            case 0:
                // no snapping occured
                snappingOccured = false;
                break;

            case 1:
                // only horizontal snapping occured
                // snappedPoint already contains the right snapping point
                snappingOccured = true;
                break;

            case 2:
                // only vertical snapping occured
                // snappedPoint already contains the right snapping point
                snappingOccured = true;
                break;

            case 3:
                // take the closer point and snap to it
                if (ShapePoint.DistSquared(pt, point1) < ShapePoint.DistSquared(pt, snappedPoint))
                {
                    snappedPoint = point1;
                    snappedCurve = snapCurve;
                }

                snappingOccured = true;
                break;
            }

            return(snappingOccured);
        }
Ejemplo n.º 17
0
 public bool CreateClosedShape(List <PointF> points)
 {
     if (points == null || points.Count < 2)
     {
         return(false);
     }
     ShapePoint[] pts = new ShapePoint[points.Count];
     for (int index = 0; index < pts.Length; ++index)
     {
         pts[index] = new ShapePoint(points[index]);
     }
     return(this.CreateClosedShape(pts));
 }
Ejemplo n.º 18
0
 public void Reset()
 {
     if (this.lines == null)
     {
         this.lines = new List <IShapeCurve>();
     }
     else
     {
         this.lines.Clear();
     }
     this.snappedCtrl  = (ShapePoint)null;
     this.snappedPoint = new PointF();
 }
Ejemplo n.º 19
0
        private void OnMouseDown(object sender, MouseEventArgs e)
        {
            if (snappedCtrlPoint != null)
            {
                if (ShapePoint.DistSquared(zoom.VisibleToPt(e.Location), snappedCtrlPoint.Location) > snapDistConst * snapDistConst)
                {
                    snappedCtrlPoint = null;
                }

                SelectedProperty = snappedCtrlPoint;
            }

            if (snappedCurve != null)
            {
                SelectedProperty = snappedCurve;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (snappedCtrlPoint != null)
                {
                    snappedCtrlPoint.IsModified = true;
                    isDragging = true;
                }
            }

            if ((e.Button == MouseButtons.Middle) ||
                ((e.Button == MouseButtons.Right) && (Control.ModifierKeys == Keys.Shift)))
            {
                Cursor.Current = Cursors.Hand;
                isScrolling    = true;
                scrollStartPos = e.Location;
                areaStartPos   = zoom.Location;
                return;
            }

            if (e.Button == MouseButtons.Right)
            {
                if (ShowSnappedPointMenu(e))
                {
                    return;
                }

                if (ShowSnappedLineMenu(e))
                {
                    return;
                }

                contextMenuGeneral.Show(PointToScreen(e.Location));
            }
        }
Ejemplo n.º 20
0
 public ShapeBezier(ShapePoint from, ShapePoint control1, ShapePoint control2, ShapePoint to)
 {
     this.detailLevel    = 32;
     this.ctrl           = new ShapePoint[4];
     this.ctrl[0]        = from;
     this.ctrl[1]        = control1;
     this.ctrl[2]        = control2;
     this.ctrl[3]        = to;
     this.snappedCtrl    = (ShapePoint)null;
     this.snappedPoint   = new PointF();
     this.points         = new ShapePoint[this.detailLevel];
     this.snapSegmentNum = -1;
     this.GenerateSegments();
 }
Ejemplo n.º 21
0
 private static bool SnapToCurveSegment(
     ref PointF snapPoint,
     PointF pt,
     ShapePoint from,
     ShapePoint to,
     float snapDistance,
     ref float dist)
 {
     if (!ShapeBezier.SnapToExtension(ref snapPoint, pt, from, to, snapDistance, ref dist))
     {
         return(false);
     }
     return(ShapeBezier.IsPointOnSegment(snapPoint.X, snapPoint.Y, from, to));
 }
Ejemplo n.º 22
0
        public void Reset()
        {
            if (lines == null)
            {
                lines = new List <IShapeCurve>();
            }
            else
            {
                lines.Clear();
            }

            snappedCtrl  = null;
            snappedPoint = new PointF();
        }
Ejemplo n.º 23
0
        public void DeserializeProperties(string propertiesString)
        {
            string[] tokens = propertiesString.Split(':');

            IShapeCurve curve = null;

            ShapePoint startPt = new ShapePoint();
            ShapePoint endPt   = startPt;



            for (int i = 1; i < tokens.Length - 1; i++)
            {
                string[] strpt = tokens[i].Split(',');

                endPt.Set(float.Parse(strpt[0], CultureInfo.InvariantCulture), float.Parse(strpt[1], CultureInfo.InvariantCulture));

                if (bool.Parse(strpt[2]))
                {
                    // Bezier curve
                    curve = new ShapeBezier();

                    curve.ControlPoints[0] = endPt;
                    //bool b = CultureInfo.CurrentCulture.UseUserOverride;
                    NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat;
                    curve.ControlPoints[1] = new ShapePoint(float.Parse(strpt[3], CultureInfo.InvariantCulture), float.Parse(strpt[4], CultureInfo.InvariantCulture));
                    curve.ControlPoints[2] = new ShapePoint(float.Parse(strpt[5], CultureInfo.InvariantCulture), float.Parse(strpt[6], CultureInfo.InvariantCulture));

                    endPt = new ShapePoint();
                    curve.ControlPoints[3] = endPt;
                }
                else
                {
                    // Straight Line
                    curve = new ShapeLine();

                    curve.ControlPoints[0] = endPt;

                    endPt = new ShapePoint();
                    curve.ControlPoints[1] = endPt;
                }
                this.Add(curve);
            }

            // Attach the end of the last line to the first point to close the shape
            if (curve != null)
            {
                curve.LastPoint = startPt;
            }
        }
Ejemplo n.º 24
0
        private static bool SnapToExtension(
            ref PointF snapPoint,
            PointF pt,
            ShapePoint from,
            ShapePoint to,
            float snapDistance,
            ref float dist)
        {
            float num1 = to.X - from.X;
            float num2 = to.Y - from.Y;

            if ((double)num1 == 0.0 || (double)num2 == 0.0)
            {
                if ((double)num1 == 0.0 && (double)num2 == 0.0)
                {
                    return(false);
                }
                snapPoint = pt;
                if ((double)num1 == 0.0)
                {
                    dist = Math.Abs(pt.X - to.X);
                    if ((double)dist >= (double)snapDistance)
                    {
                        return(false);
                    }
                    snapPoint.X = to.X;
                }
                else
                {
                    dist = Math.Abs(pt.Y - to.Y);
                    if ((double)dist >= (double)snapDistance)
                    {
                        return(false);
                    }
                    snapPoint.Y = to.Y;
                }
                return(true);
            }
            float num3 = (float)(((double)num1 * ((double)from.Y - (double)pt.Y) - (double)num2 * ((double)from.X - (double)pt.X)) / Math.Sqrt((double)num1 * (double)num1 + (double)num2 * (double)num2));

            dist = Math.Abs(num3);
            if ((double)dist > (double)snapDistance)
            {
                return(false);
            }
            snapPoint.Y = pt.Y + (float)((double)Math.Sign(num1) * (double)num3 / Math.Sqrt(1.0 + (double)num2 * (double)num2 / ((double)num1 * (double)num1)));
            snapPoint.X = from.X + (snapPoint.Y - from.Y) * num1 / num2;
            return(true);
        }
Ejemplo n.º 25
0
        public bool AppendLine(PointF to)
        {
            ShapePoint pt = shape.GetLastPoint();

            if (pt == null)
            {
                return(false);
            }

            ShapeLine line = new ShapeLine(pt, new ShapePoint(to));

            shape.Add(line);

            return(true);
        }
Ejemplo n.º 26
0
 public void Reset()
 {
     this.snappingOccured         = false;
     this.drawsGuideLines         = true;
     this.isDragging              = false;
     this.isScrolling             = false;
     this.snappedPoint            = new PointF(0.0f, 0.0f);
     this.snappedCtrlPoint        = (ShapePoint)null;
     this.snappedCurve            = (IShapeCurve)null;
     this.zoom.ZoomFactor         = 1f;
     this.snapToGrid.SnapRelative = 0.2f;
     this.SetSnapping(RadShapeEditorControl.SnapTypes.SnapToGrid | RadShapeEditorControl.SnapTypes.SnapToCtrl | RadShapeEditorControl.SnapTypes.SnapToCurves | RadShapeEditorControl.SnapTypes.SnapToExtensions);
     this.scrollStartPos = new PointF(0.0f, 0.0f);
     this.areaStartPos   = new PointF(0.0f, 0.0f);
 }
Ejemplo n.º 27
0
        protected void OnMouseMove(object sender, MouseEventArgs e)
        {
            ActivateShapeEditor();

            snappingOccured = false;

            StopOnDebug();

            if (isScrolling)
            {
                Point pos = new Point(
                    (int)Math.Round(scrollStartPos.X - e.Location.X + areaStartPos.X),
                    (int)Math.Round(scrollStartPos.Y - e.Location.Y + areaStartPos.Y)
                    );

                zoom.Location = pos;
                Refresh();
                //PointF.Subtract(scrollStartPos, areaStartPos);
                //return;
            }

            if (isDragging)
            {
                if (!ClientRectangle.Contains(e.Location) && (!scrollTimer.Enabled))
                {
                    scrollTimer.Enabled = true;
                }
                //scrollTimer.Start();

                snappingOccured           = DoSnap(zoom.VisibleToPt(e.Location), snapDistConst);
                snappedCtrlPoint.Location = snappedPoint;
            }
            else
            {
                snappingOccured  = false;
                snappedCtrlPoint = null;
                snappedCurve     = null;

                StopOnDebug();

                if (snappingOccured = DoSnap(zoom.VisibleToPt(e.Location), snapDistConst))
                {
                    snappedCtrlPoint = shape.SnappedCtrlPoint;
                }
            }

            Refresh();
        }
Ejemplo n.º 28
0
        public bool CloseFigureUsingLine()
        {
            ShapePoint first = shape.GetFirstPoint();
            ShapePoint last  = shape.GetLastPoint();

            if ((first == null) || (last == null))
            {
                return(false);
            }

            ShapeLine line = new ShapeLine(last, first);

            shape.Add(line);

            return(true);
        }
Ejemplo n.º 29
0
        public void InsertPoint(IShapeCurve curve, PointF atPoint)
        {
            if (curve == null)
            {
                return;
            }

            if (curve is ShapeLine)
            {
                ShapePoint end     = curve.LastPoint;
                ShapePoint middle  = new ShapePoint(atPoint);
                ShapeLine  newLine = new ShapeLine(middle, end);
                curve.LastPoint = middle;
                lines.Insert(lines.IndexOf(curve) + 1, newLine);
                return;
            }

            if (curve is ShapeBezier)
            {
                PointF tg1 = new PointF(), tg2 = new PointF();

                ShapePoint end    = snappedCurve.LastPoint;
                ShapePoint middle = new ShapePoint(snappedPoint);

                if (!(curve as ShapeBezier).TangentAt(snappedPoint, ref tg1, ref tg2))
                {
                    return;
                }

                ShapeBezier newBezier = new ShapeBezier();

                newBezier.ControlPoints[0] = middle;
                newBezier.ControlPoints[1] = new ShapePoint(tg2);
                newBezier.ControlPoints[2] = curve.ControlPoints[2];
                newBezier.ControlPoints[3] = curve.LastPoint;

                curve.ControlPoints[2] = new ShapePoint(tg1);
                curve.ControlPoints[3] = middle;

                curve.Update();
                newBezier.Update();

                lines.Insert(lines.IndexOf(curve) + 1, newBezier);

                return;
            }
        }
Ejemplo n.º 30
0
        private static bool SnapToCurveSegment(ref PointF snapPoint, PointF pt, ShapePoint from, ShapePoint to, float snapDistance, ref float dist)
        {
            //RectangleF rect = new RectangleF(
            //    Math.Min(from.X, to.X), Math.Min(from.Y, to.Y),
            //    Math.Abs(from.X - to.X), Math.Abs(from.Y - to.Y));

            //rect.Inflate(snapDistance, snapDistance);

            //if (!rect.Contains(pt)) return false;

            if (!SnapToExtension(ref snapPoint, pt, from, to, snapDistance, ref dist))
            {
                return(false);
            }

            return(IsPointOnSegment(snapPoint.X, snapPoint.Y, from, to));
        }