Пример #1
0
 public DataModel()
 {
     m_toolTypes.Clear();
     m_toolTypes[DrawTools.Line.ObjectType] = typeof(DrawTools.Line);
     m_toolTypes[DrawTools.Circle.ObjectType] = typeof(DrawTools.Circle);
     m_toolTypes[DrawTools.Arc.ObjectType] = typeof(DrawTools.Arc);
     m_toolTypes[DrawTools.Arc3Point.ObjectType] = typeof(DrawTools.Arc3Point);
     DefaultLayer();
     m_centerPoint = new UnitPoint(0,0);
 }
Пример #2
0
        public static bool IsPointInOval(UnitPoint center, float halfWidth, float halfHeight, UnitPoint testPoint)
        {
            OvalFun fun = (pCenter, a, b, pTest) => {
                float xx = (float)(pCenter.X - pTest.X);
                float yy = (float)(pCenter.Y - pTest.Y);
                return(xx * xx / (a * a) + yy * yy / (b * b));
            };
            double dist = Math.Abs(fun(center, halfWidth, halfHeight, testPoint));

            return(dist < 1.0f);
        }
Пример #3
0
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (m_lastCenterPoint != UnitPoint.Empty && Width != 0)
                SetCenterScreen(ToScreen(m_lastCenterPoint), false);
            m_lastCenterPoint = CenterPointUnit();
            m_staticImage = null;
            DoInvalidate(true);
        }
Пример #4
0
 public void DrawLine(ICanvas canvas, Pen pen, UnitPoint p1, UnitPoint p2)
 {
     PointF tmpp1 = ToScreen(p1);
     PointF tmpp2 = ToScreen(p2);
     canvas.Graphics.DrawLine(pen, tmpp1, tmpp2);
 }
Пример #5
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (m_selection != null)
            {
                Graphics dc = Graphics.FromHwnd(Handle);
                m_selection.SetMousePoint(dc, new PointF(e.X, e.Y));
                dc.Dispose();
                return;
            }

            if (m_commandType == eCommandType.pan && e.Button == MouseButtons.Left)
            {
                m_dragOffset.X = -(m_mousedownPoint.X - e.X);
                m_dragOffset.Y = -(m_mousedownPoint.Y - e.Y);
                m_lastCenterPoint = CenterPointUnit();
                DoInvalidate(true);
            }
            UnitPoint mousepoint;
            UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y));
            if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false)
            {
                Rectangle invalidaterect = Rectangle.Empty;
                ISnapPoint newsnap = null;
                mousepoint = GetMousePoint();
                if (RunningSnapsEnabled)
                    newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null);
                if (newsnap == null)
                    newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null);
                if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType()))
                {
                    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect));
                    invalidaterect.Inflate(2, 2);
                    RepaintStatic(invalidaterect); // remove old snappoint
                    m_snappoint = newsnap;
                }
                if (m_commandType == eCommandType.move)
                    Invalidate(invalidaterect);

                if (m_snappoint == null)
                    m_snappoint = newsnap;
            }
            m_owner.SetPositionInfo(unitpoint);
            m_owner.SetSnapInfo(m_snappoint);

            //UnitPoint mousepoint;
            if (m_snappoint != null)
                mousepoint = m_snappoint.SnapPoint;
            else
                mousepoint = GetMousePoint();

            if (m_newObject != null)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper)));
                invalidaterect.Inflate(2, 2);
                RepaintStatic(invalidaterect);

                m_newObject.OnMouseMove(m_canvaswrapper, mousepoint);
                RepaintObject(m_newObject);
            }
            if (m_snappoint != null)
                RepaintSnappoint(m_snappoint);

            if (m_moveHelper.HandleMouseMoveForMove(mousepoint))
                Refresh(); //Invalidate();

            RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint);
            if (rNoderect != RectangleF.Empty)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect));
                RepaintStatic(invalidaterect);

                CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
                dc.Graphics.Clip = new Region(ClientRectangle);
                //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect);
                m_nodeMoveHelper.DrawObjects(dc, rNoderect);
                if (m_snappoint != null)
                    RepaintSnappoint(m_snappoint);

                dc.Graphics.Dispose();
                dc.Dispose();
            }
        }
Пример #6
0
 public GridSnapPoint(ICanvas canvas, UnitPoint snappoint)
     : base(canvas, null, snappoint)
 {
 }
Пример #7
0
 PointF Translate(UnitPoint point)
 {
     return point.Point;
 }
Пример #8
0
        public static UnitPoint LinesIntersectPoint(UnitPoint lp1, UnitPoint lp2, UnitPoint lp3, UnitPoint lp4)
        {
            double x = 0;
            double y = 0;

            if (LinesIntersect(lp1, lp2, lp3, lp4, ref x, ref y, true, false, false))
            {
                return(new UnitPoint(x, y));
            }
            return(UnitPoint.Empty);
        }
Пример #9
0
        public static UnitPoint FindApparentIntersectPoint(UnitPoint lp1, UnitPoint lp2, UnitPoint lp3, UnitPoint lp4, bool extendA, bool extendB)
        {
            double x = 0;
            double y = 0;

            if (LinesIntersect(lp1, lp2, lp3, lp4, ref x, ref y, true, extendA, extendB))
            {
                return(new UnitPoint(x, y));
            }
            return(UnitPoint.Empty);
        }
Пример #10
0
        private static bool LinesIntersect(UnitPoint lp1, UnitPoint lp2, UnitPoint lp3, UnitPoint lp4, ref double x, ref double y,
                                           bool returnpoint,
                                           bool extendA,
                                           bool extendB)
        {
            // http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
            // line a is given by P1 and P2, point of intersect for line a (Pa) and b (Pb)
            // Pa = P1 + ua ( P2 - P1 )
            // Pb = P3 + ub ( P4 - P3 )

            // ua(x) = ub(x) and ua(y) = ub (y)
            // x1 + ua (x2 - x1) = x3 + ub (x4 - x3)
            // y1 + ua (y2 - y1) = y3 + ub (y4 - y3)

            // ua = ((x4-x3)(y1-y3) - (y4-y3)(x1-x3)) / ((x4-x3)(x2-x1) - (x4-x3)(y2-y1))
            // ub = ((x2-x1)(y1-y3) - (y2-y1)(x1-x3)) / ((y4-y3)(x2-x1) - (x4-x3)(y2-y1))

            // intersect point x = x1 + ua (x2 - x1)
            // intersect point y = y1 + ua (y2 - y1)
            double x1 = lp1.X;
            double x2 = lp2.X;
            double x3 = lp3.X;
            double x4 = lp4.X;
            double y1 = lp1.Y;
            double y2 = lp2.Y;
            double y3 = lp3.Y;
            double y4 = lp4.Y;

            double denominator = ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1));

            if (denominator == 0)             // lines are parallel
            {
                return(false);
            }
            double numerator_ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3));
            double numerator_ub = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3));
            double ua           = numerator_ua / denominator;
            double ub           = numerator_ub / denominator;

            // if a line is not extended then ua (or ub) must be between 0 and 1
            if (extendA == false)
            {
                if (ua < 0 || ua > 1)
                {
                    return(false);
                }
            }
            if (extendB == false)
            {
                if (ub < 0 || ub > 1)
                {
                    return(false);
                }
            }
            if (extendA || extendB)             // no need to chck range of ua and ub if check is one on lines
            {
                x = x1 + ua * (x2 - x1);
                y = y1 + ua * (y2 - y1);
                return(true);
            }
            if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1)
            {
                if (returnpoint)
                {
                    x = x1 + ua * (x2 - x1);
                    y = y1 + ua * (y2 - y1);
                }
                return(true);
            }
            return(false);
        }
Пример #11
0
        public static bool LinesIntersect(UnitPoint lp1, UnitPoint lp2, UnitPoint lp3, UnitPoint lp4)
        {
            double x = 0;
            double y = 0;

            return(LinesIntersect(lp1, lp2, lp3, lp4, ref x, ref y, false, false, false));
        }
Пример #12
0
        public static bool IsPointInLine(UnitPoint linepoint1, UnitPoint linepoint2, UnitPoint testpoint, float halflinewidth)
        {
            UnitPoint p1 = linepoint1;
            UnitPoint p2 = linepoint2;
            UnitPoint p3 = testpoint;

            // check bounding rect, this is faster than creating a new rectangle and call r.Contains
            double lineLeftPoint  = Math.Min(p1.X, p2.X) - halflinewidth;
            double lineRightPoint = Math.Max(p1.X, p2.X) + halflinewidth;

            if (testpoint.X < lineLeftPoint || testpoint.X > lineRightPoint)
            {
                return(false);
            }

            double lineBottomPoint = Math.Min(p1.Y, p2.Y) - halflinewidth;
            double lineTopPoint    = Math.Max(p1.Y, p2.Y) + halflinewidth;

            if (testpoint.Y < lineBottomPoint || testpoint.Y > lineTopPoint)
            {
                return(false);
            }

            // then check if it hits the endpoint
            if (CircleHitPoint(p1, halflinewidth, p3))
            {
                return(true);
            }
            if (CircleHitPoint(p2, halflinewidth, p3))
            {
                return(true);
            }

            if (p1.Y == p2.Y)             // line is horizontal
            {
                double min = Math.Min(p1.X, p2.X) - halflinewidth;
                double max = Math.Max(p1.X, p2.X) + halflinewidth;
                if (p3.X >= min && p3.X <= max)
                {
                    return(true);
                }
                return(false);
            }
            if (p1.X == p2.X)             // line is vertical
            {
                double min = Math.Min(p1.Y, p2.Y) - halflinewidth;
                double max = Math.Max(p1.Y, p2.Y) + halflinewidth;
                if (p3.Y >= min && p3.Y <= max)
                {
                    return(true);
                }
                return(false);
            }

            // using COS law
            // a^2 = b^2 + c^2 - 2bc COS A
            // A = ACOS ((a^2 - b^2 - c^2) / (-2bc))
            double xdiff   = Math.Abs(p2.X - p3.X);
            double ydiff   = Math.Abs(p2.Y - p3.Y);
            double aSquare = Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2);
            double a       = Math.Sqrt(aSquare);

            xdiff = Math.Abs(p1.X - p2.X);
            ydiff = Math.Abs(p1.Y - p2.Y);
            double bSquare = Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2);
            double b       = Math.Sqrt(bSquare);

            xdiff = Math.Abs(p1.X - p3.X);
            ydiff = Math.Abs(p1.Y - p3.Y);
            double cSquare = Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2);
            double c       = Math.Sqrt(cSquare);
            double A       = Math.Acos(((aSquare - bSquare - cSquare) / (-2 * b * c)));

            // once we have A we can find the height (distance from the line)
            // SIN(A) = (h / c)
            // h = SIN(A) * c;
            double h = Math.Sin(A) * c;

            // now if height is smaller than half linewidth, the hitpoint is within the line
            return(h <= halflinewidth);
        }
Пример #13
0
 static UnitPoint()
 {
     Empty     = new UnitPoint();
     Empty.m_x = double.NaN;
     Empty.m_y = double.NaN;
 }
Пример #14
0
        public static bool CircleIntersectWithLine(UnitPoint center, float radius, UnitPoint lp1, UnitPoint lp2)
        {
            // check if both points are inside the circle, in that case the line does not intersect the circle
            if ((Distance(center, lp1) < radius && Distance(center, lp2) < radius))
            {
                return(false);
            }

            // find the nearest point from the line to center, if that point is smaller than radius,
            // then the line does intersect the circle
            UnitPoint np   = NearestPointOnLine(lp1, lp2, center);
            double    dist = Distance(center, np);

            if (dist <= radius)
            {
                return(true);
            }
            return(false);
        }
Пример #15
0
 ISnapPoint ICanvasLayer.SnapPoint(ICanvas canvas, UnitPoint point, List<IDrawObject> otherobj)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #16
0
 public static UnitPoint OrthoPointD(UnitPoint lp1, UnitPoint lp2, double roundToAngleR)
 {
     return(OrthoPointR(lp1, lp2, DegressToRadians(roundToAngleR)));
 }
Пример #17
0
 public SnapPointBase(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
 {
     m_owner = owner;
     m_snappoint = snappoint;
     float size = (float)canvas.ToUnit(14);
     m_boundingRect.X = (float)(snappoint.X - size / 2);
     m_boundingRect.Y = (float)(snappoint.Y - size / 2);
     m_boundingRect.Width = size;
     m_boundingRect.Height = size;
 }
Пример #18
0
 public static UnitPoint OrthoPointR(UnitPoint lp1, UnitPoint lp2, double roundToAngleR)
 {
     return(NearestPointOnLine(lp1, lp2, lp2, roundToAngleR));
 }
Пример #19
0
 public EditCommandMove(UnitPoint offset, IEnumerable<IDrawObject> objects)
 {
     m_objects = new List<IDrawObject>(objects);
     m_offset = offset;
 }
Пример #20
0
 public static UnitPoint NearestPointOnLine(UnitPoint lp1, UnitPoint lp2, UnitPoint tp)
 {
     return(NearestPointOnLine(lp1, lp2, tp, false));
 }
Пример #21
0
 public UnitPoint CenterPointUnit()
 {
     UnitPoint p1 = ScreenTopLeftToUnitPoint();
     UnitPoint p2 = ScreenBottomRightToUnitPoint();
     UnitPoint center = new UnitPoint();
     center.X = (p1.X + p2.X) / 2;
     center.Y = (p1.Y + p2.Y) / 2;
     return center;
 }
Пример #22
0
 public static double LineSlope(UnitPoint p1, UnitPoint p2)
 {
     return((p2.Y - p1.Y) / (p2.X - p1.X));
 }
Пример #23
0
        public PointF ToScreen(UnitPoint point)
        {
            PointF transformedPoint = Translate(point);
            transformedPoint.Y = ScreenHeight() - transformedPoint.Y;
            transformedPoint.Y *= m_screenResolution * m_model.Zoom;
            transformedPoint.X *= m_screenResolution * m_model.Zoom;

            transformedPoint.X += m_panOffset.X + m_dragOffset.X;
            transformedPoint.Y += m_panOffset.Y + m_dragOffset.Y;
            return transformedPoint;
        }
Пример #24
0
 public MidpointSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint, int id = 0)
     : base(canvas, owner, snappoint)
 {
     m_id = id;
 }
Пример #25
0
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     UnitPoint p = GetMousePoint();
     float wheeldeltatick = 120;
     float zoomdelta = (1.25f * (Math.Abs(e.Delta) / wheeldeltatick));
     if (e.Delta < 0)
         m_model.Zoom = m_model.Zoom / zoomdelta;
     else
         m_model.Zoom = m_model.Zoom * zoomdelta;
     SetCenterScreen(ToScreen(p), true);
     m_lastCenterPoint = p;
     DoInvalidate(true);
     base.OnMouseWheel(e);
 }
Пример #26
0
 public DivisionSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #27
0
 public IDrawObject CreateObject(string type, UnitPoint point, ISnapPoint snappoint)
 {
     DrawingLayer layer = ActiveLayer as DrawingLayer;
     if (layer.Enabled == false)
         return null;
     DrawTools.DrawObjectBase newobj = CreateObject(type);
     if (newobj != null)
     {
         newobj.Layer = layer;
         newobj.InitializeFromModel(point, layer, snappoint);
     }
     return newobj as IDrawObject;
 }
Пример #28
0
 public PerpendicularSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #29
0
 public void MoveObjects(UnitPoint offset, IEnumerable<IDrawObject> objects)
 {
     if (m_undoBuffer.CanCapture)
         m_undoBuffer.AddCommand(new EditCommandMove(offset, objects));
     foreach (IDrawObject obj in objects)
         obj.Move(offset);
 }
Пример #30
0
 public TangentSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #31
0
 public static RectangleF GetRect(UnitPoint p1, UnitPoint p2, double width)
 {
     double x = Math.Min(p1.X, p2.X);
     double y = Math.Min(p1.Y, p2.Y);
     double w = Math.Abs(p1.X - p2.X);
     double h = Math.Abs(p1.Y - p2.Y);
     RectangleF rect = ScreenUtils.GetRect(x, y, w, h);
     rect.Inflate((float)width, (float)width);
     return rect;
 }
Пример #32
0
 public GridSnapPoint(ICanvas canvas, UnitPoint snappoint)
     : base(canvas, null, snappoint)
 {
 }
Пример #33
0
 public PerpendicularSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #34
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            m_mousedownPoint = new PointF(e.X, e.Y);             // used when panning
            m_dragOffset     = new PointF(0, 0);

            UnitPoint mousepoint = ToUnit(m_mousedownPoint);

            if (m_snappoint != null)
            {
                mousepoint = m_snappoint.SnapPoint;
            }

            if (m_commandType == eCommandType.editNode)
            {
                bool handled = false;
                if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled))
                {
                    FinishNodeEdit();
                    base.OnMouseDown(e);
                    return;
                }
            }
            if (m_commandType == eCommandType.select)
            {
                bool handled = false;
                if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled))
                {
                    m_commandType = eCommandType.editNode;
                    m_snappoint   = null;
                    base.OnMouseDown(e);
                    return;
                }
                m_selection = new SelectionRectangle(m_mousedownPoint);
            }
            if (m_commandType == eCommandType.move)
            {
                m_moveHelper.HandleMouseDownForMove(mousepoint, m_snappoint);
            }
            if (m_commandType == eCommandType.draw)
            {
                HandleMouseDownWhenDrawing(mousepoint, null);
                DoInvalidate(true);
            }
            if (m_commandType == eCommandType.edit)
            {
                if (m_editTool == null)
                {
                    m_editTool = m_model.GetEditTool(m_editToolId);
                }
                if (m_editTool != null)
                {
                    if (m_editTool.SupportSelection)
                    {
                        m_selection = new SelectionRectangle(m_mousedownPoint);
                    }

                    eDrawObjectMouseDown mouseresult = m_editTool.OnMouseDown(m_canvaswrapper, mousepoint, m_snappoint);

                    /*
                     * if (mouseresult == eDrawObjectMouseDown.Continue)
                     * {
                     *      if (m_editTool.SupportSelection)
                     *              m_selection = new SelectionRectangle(m_mousedownPoint);
                     * }
                     * */
                    if (mouseresult == eDrawObjectMouseDown.Done)
                    {
                        m_editTool.Finished();
                        m_editTool = m_model.GetEditTool(m_editToolId);                         // continue with new tool
                        //m_editTool = null;

                        if (m_editTool.SupportSelection)
                        {
                            m_selection = new SelectionRectangle(m_mousedownPoint);
                        }
                    }
                }
                DoInvalidate(true);
                UpdateCursor();
            }
            base.OnMouseDown(e);
        }
Пример #35
0
 public DivisionSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #36
0
 PointF Translate(UnitPoint point)
 {
     return(point.Point);
 }
Пример #37
0
 public MidpointSnapPoint(ICanvas canvas, IDrawObject owner, UnitPoint snappoint)
     : base(canvas, owner, snappoint)
 {
 }
Пример #38
0
 public void DrawLine(ICanvas canvas, Pen pen, UnitPoint p1, UnitPoint p2)
 {
     m_canvas.DrawLine(canvas, pen, p1, p2);
 }
Пример #39
0
 public override bool DoUndo(IModel data)
 {
     foreach (IDrawObject obj in m_objects)
     {
         UnitPoint offset = new UnitPoint(-m_offset.X, -m_offset.Y);
         obj.Move(offset);
     }
     return true;
 }
Пример #40
0
 public void DrawArc(ICanvas canvas, Pen pen, UnitPoint center, float radius, float beginangle, float angle)
 {
     m_canvas.DrawArc(canvas, pen, center, radius, beginangle, angle);
 }
Пример #41
0
 public PointF ToScreen(UnitPoint unitpoint)
 {
     return m_canvas.ToScreen(unitpoint);
 }
Пример #42
0
 /// <summary>
 /// 点的快照信息?(抛出异常)
 /// </summary>
 /// <param name="canvas"></param>
 /// <param name="point"></param>
 /// <param name="otherobj"></param>
 /// <returns></returns>
 ISnapPoint ICanvasLayer.SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Пример #43
0
 public void DrawArc(ICanvas canvas, Pen pen, UnitPoint center, float radius, float startAngle, float sweepAngle)
 {
     PointF p1 = ToScreen(center);
     radius = (float)Math.Round(ToScreen(radius));
     RectangleF r = new RectangleF(p1, new SizeF());
     r.Inflate(radius, radius);
     if (radius > 0 && radius < 1e8f )
         canvas.Graphics.DrawArc(pen, r, -startAngle, -sweepAngle);
 }
Пример #44
0
        public void FillRectangle(ICanvas canvas, Brush brush, UnitPoint ptUpperLeft, float width, float height)
        {
            PointF ptScreen = ToScreen(ptUpperLeft);

            canvas.Graphics.FillRectangle(brush, ptScreen.X, ptScreen.Y, ToScreen(width), ToScreen(height));
        }
Пример #45
0
 public void SetCenter(UnitPoint unitPoint)
 {
     PointF point = ToScreen(unitPoint);
     m_lastCenterPoint = unitPoint;
     SetCenterScreen(point, false);
 }
Пример #46
0
 public void DrawEllipse(ICanvas canvas, Pen pen, UnitPoint ptTopLeft, float width, float height)
 {
     m_canvas.DrawEllipse(canvas, pen, ptTopLeft, width, height);
 }
Пример #47
0
 protected virtual void HandleMouseDownWhenDrawing(UnitPoint mouseunitpoint, ISnapPoint snappoint)
 {
     if (m_commandType == eCommandType.draw)
     {
         if (m_newObject == null)
         {
             m_newObject = m_model.CreateObject(m_drawObjectId, mouseunitpoint, snappoint);
             if (m_newObject.GetType().ToString().IndexOf("Module")>0)
             {
                 eDrawObjectMouseDown result = m_newObject.OnMouseDown(m_canvaswrapper, mouseunitpoint, snappoint);
                 switch (result)
                 {
                     case eDrawObjectMouseDown.Done:
                         m_model.AddObject(m_model.ActiveLayer, m_newObject);
                         m_newObject = null;
                         DoInvalidate(true);
                         break;
                     case eDrawObjectMouseDown.DoneRepeat:
                         m_model.AddObject(m_model.ActiveLayer, m_newObject);
                         m_newObject = m_model.CreateObject(m_newObject.Id, m_newObject.RepeatStartingPoint, null);
                         DoInvalidate(true);
                         break;
                     case eDrawObjectMouseDown.Continue:
                         break;
                 }
             }
             else DoInvalidate(false, m_newObject.GetBoundingRect(m_canvaswrapper));
         }
         else
         {
             if (m_newObject != null)
             {
                 eDrawObjectMouseDown result = m_newObject.OnMouseDown(m_canvaswrapper, mouseunitpoint, snappoint);
                 switch (result)
                 {
                     case eDrawObjectMouseDown.Done:
                         m_model.AddObject(m_model.ActiveLayer, m_newObject);
                         m_newObject = null;
                         DoInvalidate(true);
                         break;
                     case eDrawObjectMouseDown.DoneRepeat:
                         m_model.AddObject(m_model.ActiveLayer, m_newObject);
                         m_newObject = m_model.CreateObject(m_newObject.Id, m_newObject.RepeatStartingPoint, null);
                         DoInvalidate(true);
                         break;
                     case eDrawObjectMouseDown.Continue:
                         break;
                 }
             }
         }
     }
 }
Пример #48
0
 public void FillEllipse(ICanvas canvas, Brush brush, UnitPoint ptTopLeft, float width, float height)
 {
     m_canvas.FillEllipse(canvas, brush, ptTopLeft, width, height);
 }
Пример #49
0
 public void DrawArc(ICanvas canvas, Pen pen, UnitPoint center, float radius, float beginangle, float angle)
 {
     m_canvas.DrawArc(canvas, pen, center, radius, beginangle, angle);
 }
Пример #50
0
 public PointF ToScreen(UnitPoint unitpoint)
 {
     return(m_canvas.ToScreen(unitpoint));
 }
Пример #51
0
 public void DrawLine(ICanvas canvas, Pen pen, UnitPoint p1, UnitPoint p2)
 {
     m_canvas.DrawLine(canvas, pen, p1, p2);
 }
Пример #52
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (m_rectBaseTextBox != null && m_rectBaseTextBox.Tag != null)
            {
                ((DrawTools.RectBase)m_rectBaseTextBox.Tag).Text     = m_rectBaseTextBox.Text;
                ((DrawTools.RectBase)m_rectBaseTextBox.Tag).Selected = false;
                Controls.Remove(m_rectBaseTextBox);
                m_model.ClearSelectedObjects();
                m_rectBaseTextBox = null;
                DoInvalidate(true);
                return;
            }
            if (e.Button == MouseButtons.Middle)
            {
                CommandEscape();
                CommandPan();
            }
            if (e.Button == MouseButtons.Right)
            {
                CommandEscape();
            }
            m_mousedownPoint = new PointF(e.X, e.Y); // used when panning
            m_dragOffset     = new PointF(0, 0);

            UnitPoint mousepoint = ToUnit(m_mousedownPoint);

            if (m_snappoint != null)
            {
                mousepoint = m_snappoint.SnapPoint;                //snap point: rect point
            }
            if (m_commandType == eCommandType.editNode)
            {
                //modify a obj's node, e.g: move node
                bool handled = false;
                if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled, m_snappoint))
                {
                    FinishNodeEdit();
                    base.OnMouseDown(e);
                    return;
                }
            }
            if (m_commandType == eCommandType.select)
            {
                //select an exsiting obj
                bool handled = false;
                if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled, m_snappoint))
                {
                    m_commandType = eCommandType.editNode;
                    m_snappoint   = null;
                    base.OnMouseDown(e);
                    return;
                }
                m_selection = new SelectionRectangle(m_mousedownPoint);
            }
            if (m_commandType == eCommandType.move)
            {
                m_moveHelper.HandleMouseDownForMove(mousepoint, m_snappoint);
            }
            if (m_commandType == eCommandType.draw)
            {
                //make a new obj and add it to model
                HandleMouseDownWhenDrawing(mousepoint, m_snappoint);
                DoInvalidate(true);
            }
            if (m_commandType == eCommandType.edit)
            {
                if (m_editTool == null)
                {
                    m_editTool = m_model.GetEditTool(m_editToolId);
                }
                if (m_editTool != null)
                {
                    if (m_editTool.SupportSelection)
                    {
                        m_selection = new SelectionRectangle(m_mousedownPoint);
                    }

                    eDrawObjectMouseDown mouseresult = m_editTool.OnMouseDown(m_canvaswrapper, mousepoint, m_snappoint);

                    /*
                     * if (mouseresult == eDrawObjectMouseDown.Continue)
                     * {
                     *      if (m_editTool.SupportSelection)
                     *              m_selection = new SelectionRectangle(m_mousedownPoint);
                     * }
                     * */
                    if (mouseresult == eDrawObjectMouseDown.Done)
                    {
                        m_editTool.Finished();
                        m_editTool = m_model.GetEditTool(m_editToolId);                         // continue with new tool
                        //m_editTool = null;

                        if (m_editTool.SupportSelection)
                        {
                            m_selection = new SelectionRectangle(m_mousedownPoint);
                        }
                    }
                }
                DoInvalidate(true);
                UpdateCursor();
            }
            base.OnMouseDown(e);
        }
Пример #53
0
 public void CopyObjects(UnitPoint offset, IEnumerable<IDrawObject> objects)
 {
     ClearSelectedObjects();
     List<IDrawObject> newobjects = new List<IDrawObject>();
     foreach (IDrawObject obj in objects)
     {
         IDrawObject newobj = obj.Clone();
         newobjects.Add(newobj);
         newobj.Move(offset);
         ((DrawingLayer)ActiveLayer).AddObject(newobj);
         AddSelectedObject(newobj);
     }
     if (m_undoBuffer.CanCapture)
         m_undoBuffer.AddCommand(new EditCommandAdd(ActiveLayer, newobjects));
 }
Пример #54
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (e.Button == MouseButtons.Right)
            {
                CommandEscape();
            }

            if (m_commandType == eCommandType.pan)
            {
                m_panOffset.X += m_dragOffset.X;
                m_panOffset.Y += m_dragOffset.Y;
                m_dragOffset   = new PointF(0, 0);
            }

            List <IDrawObject> hitlist       = null;
            Rectangle          screenSelRect = Rectangle.Empty;

            if (m_selection != null)
            {
                screenSelRect = m_selection.ScreenRect();
                RectangleF selectionRect = m_selection.Selection(m_canvaswrapper);
                if (selectionRect != RectangleF.Empty)
                {
                    // is any selection rectangle. use it for selection
                    hitlist = m_model.GetHitObjects(m_canvaswrapper, selectionRect, m_selection.AnyPoint());
                    DoInvalidate(true);
                }
                else
                {
                    // else use mouse point
                    UnitPoint mousepoint = ToUnit(new PointF(e.X, e.Y));
                    hitlist = m_model.GetHitObjects(m_canvaswrapper, mousepoint);
                    HitUtil.ActivateSymbolAtPoint(m_canvaswrapper, hitlist, mousepoint);
                }
                m_selection = null;
            }
            if (m_commandType == eCommandType.select)
            {
                if (hitlist != null)
                {
                    HandleSelection(hitlist);
                }
            }
            if (m_commandType == eCommandType.edit && m_editTool != null)
            {
                UnitPoint mousepoint = ToUnit(m_mousedownPoint);
                if (m_snappoint != null)
                {
                    mousepoint = m_snappoint.SnapPoint;
                }
                if (screenSelRect != Rectangle.Empty)
                {
                    m_editTool.SetHitObjects(mousepoint, hitlist);
                }
                m_editTool.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint);
            }
            if (m_commandType == eCommandType.draw && m_newObject != null)
            {
                UnitPoint mousepoint = ToUnit(m_mousedownPoint);
                if (m_snappoint != null)
                {
                    mousepoint = m_snappoint.SnapPoint;
                }
                m_newObject.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint);
            }
        }
Пример #55
0
 public List<IDrawObject> GetHitObjects(ICanvas canvas, UnitPoint point)
 {
     List<IDrawObject> selected = new List<IDrawObject>();
     foreach (ICanvasLayer layer in m_layers)
     {
         if (layer.Visible == false)
             continue;
         foreach (IDrawObject drawobject in layer.Objects)
         {
             if (drawobject.PointInObject(canvas, point))
                 selected.Add(drawobject);
         }
     }
     return selected;
 }
Пример #56
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            if (m_selection != null)
            {
                Graphics dc = Graphics.FromHwnd(Handle);
                m_selection.SetMousePoint(dc, new PointF(e.X, e.Y));
                dc.Dispose();
                return;
            }

            if (m_commandType == eCommandType.pan &&
                (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle))
            {
                m_dragOffset.X    = -(m_mousedownPoint.X - e.X);
                m_dragOffset.Y    = -(m_mousedownPoint.Y - e.Y);
                m_lastCenterPoint = CenterPointUnit();
                DoInvalidate(true);
            }
            UnitPoint mousepoint;
            UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y));

            if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false)
            {
                Rectangle  invalidaterect = Rectangle.Empty;
                ISnapPoint newsnap        = null;
                mousepoint = GetMousePoint();
                if (RunningSnapsEnabled)
                {
                    newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null);
                }
                if (newsnap == null)
                {
                    newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null);
                }
                if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType()))
                {
                    invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect));
                    invalidaterect.Inflate(2, 2);
                    RepaintStatic(invalidaterect);                     // remove old snappoint
                    m_snappoint = newsnap;
                }
                if (m_commandType == eCommandType.move)
                {
                    Invalidate(invalidaterect);
                }

                if (m_snappoint == null)
                {
                    m_snappoint = newsnap;
                }
            }
            m_owner.SetPositionInfo(unitpoint);
            m_owner.SetSnapInfo(m_snappoint);

            //UnitPoint mousepoint;
            if (m_snappoint != null)
            {
                mousepoint = m_snappoint.SnapPoint;
            }
            else
            {
                mousepoint = GetMousePoint();
            }

            if (m_newObject != null)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper)));
                invalidaterect.Inflate(2, 2);
                RepaintStatic(invalidaterect);

                m_newObject.OnMouseMove(m_canvaswrapper, mousepoint);
                RepaintObject(m_newObject);
            }
            if (m_snappoint != null)
            {
                RepaintSnappoint(m_snappoint);
            }

            if (m_moveHelper.HandleMouseMoveForMove(mousepoint))
            {
                Refresh();                 //Invalidate();
            }
            RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint);

            if (rNoderect != RectangleF.Empty)
            {
                Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect));
                RepaintStatic(invalidaterect);

                CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle);
                dc.Graphics.Clip = new Region(ClientRectangle);
                //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect);
                m_nodeMoveHelper.DrawObjects(dc, rNoderect);
                if (m_snappoint != null)
                {
                    RepaintSnappoint(m_snappoint);
                }

                dc.Graphics.Dispose();
                dc.Dispose();
            }
        }
Пример #57
0
 public void MoveNodes(UnitPoint position, IEnumerable<INodePoint> nodes)
 {
     if (m_undoBuffer.CanCapture)
         m_undoBuffer.AddCommand(new EditCommandNodeMove(nodes));
     foreach (INodePoint node in nodes)
     {
         node.SetPosition(position);
         node.Finish();
     }
 }
Пример #58
0
        public RectangleF HandleMouseMoveForNode(UnitPoint mouseunitpoint)
        {
            RectangleF r = RectangleF.Empty;
            if (m_nodes.Count == 0)
                return r;
            r = new RectangleF(m_originPoint.Point, new Size(0,0));
            r = RectangleF.Union(r, new RectangleF(mouseunitpoint.Point, new SizeF(0,0)));
            if (m_lastPoint != UnitPoint.Empty)
                r = RectangleF.Union(r, new RectangleF(m_lastPoint.Point, new SizeF(0, 0)));

            m_lastPoint = mouseunitpoint;
            foreach (INodePoint p in m_nodes)
            {
                if (r == RectangleF.Empty)
                    r = p.GetClone().GetBoundingRect(m_canvas);
                else
                    r = RectangleF.Union(r, p.GetClone().GetBoundingRect(m_canvas));
                p.SetPosition(mouseunitpoint);
                //m_canvas.RepaintObject(p.GetClone());
            }
            return r;
        }
Пример #59
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, Type[] runningsnaptypes, Type usersnaptype)
        {
            List<IDrawObject> objects = GetHitObjects(canvas, point);
            if (objects.Count == 0)
                return null;

            foreach (IDrawObject obj in objects)
            {
                ISnapPoint snap = obj.SnapPoint(canvas, point, objects, runningsnaptypes, usersnaptype);
                if (snap != null)
                    return snap;
            }
            return null;
        }
Пример #60
0
        public static bool IsPointInRect(UnitPoint center, float rectHalfWidth, float rectHalfHeight, UnitPoint testpoint, float halflinewidth)
        {
            double distX = Math.Abs(center.X - testpoint.X);
            double distY = Math.Abs(center.Y - testpoint.Y);

            if ((distX >= rectHalfWidth - halflinewidth) && (distX <= rectHalfWidth + halflinewidth) &&
                testpoint.Y <= center.Y + halflinewidth + rectHalfHeight &&
                testpoint.Y >= center.Y - halflinewidth - rectHalfHeight)
            {
                return(true);
            }
            if ((distY >= rectHalfHeight - halflinewidth) && (distY <= rectHalfHeight + halflinewidth) &&
                testpoint.X <= center.X + rectHalfWidth + halflinewidth &&
                testpoint.X >= center.X - rectHalfWidth - halflinewidth)
            {
                return(true);
            }
            return(false);
        }