Ejemplo n.º 1
0
        private void EditorWindow_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (ActiveCommand != DrawCommands.Noun)
            {
                if (clickCount == 2 && ActiveCommand != DrawCommands.PolyLine)
                {
                    ActiveCommand = DrawCommands.Noun;
                    //GeometryEngine.AddShape(tempShape);
                    tempShape    = null;
                    tempPolyLine = null;
                    clickCount   = 0;
                }
                else if (clickCount == 2 && ActiveCommand == DrawCommands.PolyLine)

                {
                    if (tempShape == null)
                    {
                        ActiveCommand = DrawCommands.Noun;
                    }
                    else
                    {
                        GeometryEngine.AddShape(tempShape);
                    }

                    tempShape    = null;
                    tempPolyLine = null;
                    clickCount   = 0;
                }
                else
                {
                }
                return;
            }
        }
Ejemplo n.º 2
0
        public static IntersectionResult ParaoblaPolyLine(GCurve c, GPolyLine pl)
        {
            IntersectionResult result = new IntersectionResult();

            foreach (var line in pl.Lines)
            {
                var temp = CurveLine(c, line);
                if (temp.IntersectionPoints.Count != 0)

                {
                    result.IntersectionPoints.AddRange(temp.IntersectionPoints);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static IntersectionResult CirclePolyLine(GCircle circle, GPolyLine pl)
        {
            var result = new IntersectionResult();

            foreach (var line in pl.Lines)
            {
                var intersect = CircleLine(circle, line);
                if (intersect.IntersectionPoints.Count > 0)
                {
                    result.IntersectionPoints.
                    AddRange(intersect.IntersectionPoints);
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private void EditorWindow_MouseMove(object sender, MouseEventArgs e)
        {
            StatusBar.Message($"X: {e.X} , Y: {e.Y}");
            if (ActiveCommand != DrawCommands.Noun && clickCount >= 1)
            {
                //delta_Y = p2.Sub(e.Location);

                var offsetPoint = new PointF(offsetX, offsetY).Scale(Zoom);
                p2 = (new PointF(e.X, e.Y).Sub(offsetPoint)).Scale(1 / Zoom);


                switch (ActiveCommand)
                {
                case DrawCommands.Line:
                    #region Line
                    tempShape = new GLine(p1, p2);
                    #endregion

                    break;

                case DrawCommands.Circle:
                    #region Circle
                    tempShape = new GCircle(p1, p1.Distance(p2));
                    Debug.WriteLine($"x:{p1.X},Y:{p1.Y},R:{p1.Distance(p2)}");
                    Debug.WriteLine($"offsetX:{offsetX},OffsetY:{ offsetY}");
                    #endregion
                    break;

                case DrawCommands.Rectangle:
                    #region Rectangle
                    tempShape = new GRectangle(p1, p2);
                    #endregion
                    break;

                case DrawCommands.PolyLine:
                    #region PolyLine
                    tempShape = tempPolyLine;
                    if (clickCount == 1)
                    {
                        if (tempPolyLine == null)
                        {
                            tempPolyLine = new GPolyLine();
                            tempPolyLine.Lines.Add(new GLine(p1, p2));
                        }
                        else
                        {
                            tempPolyLine.Lines.LastOrDefault().EndPoint = p2;
                        }
                    }
                    else if (clickCount == 2)
                    {
                        //check end line position to exit or continue drawing.

                        var prevLine = tempPolyLine.Lines.LastOrDefault();
                        tempPolyLine.Lines.Add(new GLine(prevLine.EndPoint, p2));

                        if (p2.Distance(tempPolyLine.Lines.FirstOrDefault().StartPoint) < Setup.Snap)
                        {
                            GeometryEngine.AddShape(tempShape);
                            clickCount   = 0;
                            tempShape    = null;
                            tempPolyLine = null;
                            // ActiveCommand = DrawCommands.Noun;
                        }
                        else
                        {
                            clickCount--;
                        }
                    }
                    #endregion
                    break;

                case DrawCommands.Curve:

                    #region Curve

                    if (clickCount == 1)
                    {
                        tempShape = new GLine(p1, p2);
                    }

                    else if (clickCount == 2)
                    {
                        if (tempShape is GCurve)
                        {
                            ((GCurve)tempShape).Center = p2;
                        }
                        else
                        {
                            var l = (GLine)tempShape;

                            tempShape = new GCurve(l.StartPoint, p2, l.EndPoint);
                        }
                    }
                    else if (clickCount == 3)
                    {
                        ((GCurve)tempShape).Center = p2;
                        GeometryEngine.AddShape(tempShape);
                        clickCount = 0;
                    }

                    #endregion
                    break;

                case DrawCommands.Parabola:
                    #region Parabola
                    if (clickCount == 1)
                    {
                        tempShape = new GLine(p1, p2);
                    }

                    else if (clickCount == 2)
                    {
                        if (tempShape is GParabola)
                        {
                            ((GParabola)tempShape).Points[2] = p2;
                        }
                        else
                        {
                            var l = (GLine)tempShape;

                            tempShape = new GParabola(l.StartPoint, l.EndPoint, p2);
                        }
                    }
                    else if (clickCount == 3)
                    {
                        ((GParabola)tempShape).Points[2] = p2;
                        GeometryEngine.AddShape(tempShape);
                        clickCount = 0;
                    }
                    #endregion
                    break;

                case DrawCommands.Clear:
                    break;

                case DrawCommands.Noun:
                    break;

                default:
                    break;
                }
                EditorWindow.Invalidate();
            }
            else if (clickCount == 0)
            {
                MouseEventArgs mouse = e as MouseEventArgs;

                if (mouse.Button == MouseButtons.Left)
                {
                    Point mousePosNow = mouse.Location;

                    int deltaX = mousePosNow.X - mouseDown.X; // the distance the mouse has been moved since mouse was pressed
                    int deltaY = mousePosNow.Y - mouseDown.Y;

                    offsetX = (int)(startx + (deltaX / Zoom));  // calculate new offset of image based on the current zoom factor
                    offsetY = (int)(starty + (deltaY / Zoom));

                    EditorWindow.Invalidate();
                }
            }
        }