Esempio n. 1
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint unitPoint, List <IDrawObject> drawObjects, Type[] runningSnapTypes, Type userSnapType)
        {
            float thWidth = UCCanvas.GetThresholdWidth();

            if (runningSnapTypes != null)
            {
                foreach (Type snaptype in runningSnapTypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(this.P1, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.P1));
                        }
                        if (HitUtil.CircleHitPoint(this.P2, thWidth, unitPoint))
                        {
                            return(new VertextSnapPoint(canvas, this, this.P2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        UnitPoint p = MidPoint(canvas, this.P1, this.P2, unitPoint);
                        if (p != UnitPoint.Empty)
                        {
                            return(new MidpointSnapPoint(canvas, this, p));
                        }
                    }
                    if (snaptype == typeof(IntersectSnapPoint))
                    {
                        Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line;
                        if (otherline == null)
                        {
                            continue;
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }

            if (userSnapType == typeof(MidpointSnapPoint))
            {
                return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(this.P1, this.P2)));
            }
            if (userSnapType == typeof(IntersectSnapPoint))
            {
                Line otherline = Utils.Utils.FindObjectTypeInList(this, drawObjects, typeof(Line)) as Line;
                if (otherline == null)
                {
                    return(null);
                }
                UnitPoint p = HitUtil.LinesIntersectPoint(this.P1, this.P2, otherline.P1, otherline.P2);
                if (p != UnitPoint.Empty)
                {
                    return(new IntersectSnapPoint(canvas, this, p));
                }
            }
            if (userSnapType == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(unitPoint, this.P1);
                double d2 = HitUtil.Distance(unitPoint, this.P2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, this.P1));
                }
                return(new VertextSnapPoint(canvas, this, this.P2));
            }
            if (userSnapType == typeof(NearestSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint);
                if (p != UnitPoint.Empty)
                {
                    return(new NearestSnapPoint(canvas, this, p));
                }
            }
            if (userSnapType == typeof(PerpendicularSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(this.P1, this.P2, unitPoint);
                if (p != UnitPoint.Empty)
                {
                    return(new PerpendicularSnapPoint(canvas, this, p));
                }
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据给定类型返回点的快照信息
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <param name="otherobj"></param>
        /// <param name="runningsnaptypes"></param>
        /// <param name="usersnaptype"></param>
        /// <returns></returns>
        ISnapPoint IDrawObject.SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = ThresholdWidth(canvas, Width);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
                        {
                            return(new VertextSnapPoint(canvas, this, m_p2));
                        }
                    }
                    if (snaptype == typeof(MidpointSnapPoint))
                    {
                        UnitPoint p = MidPoint(canvas, m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new MidpointSnapPoint(canvas, this, p));
                        }
                    }
                    if (snaptype == typeof(IntersectSnapPoint))
                    {
                        Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle;
                        if (rectangle == null)
                        {
                            continue;
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }

            if (usersnaptype == typeof(MidpointSnapPoint))
            {
                return(new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2)));
            }
            if (usersnaptype == typeof(IntersectSnapPoint))
            {
                Rectangle rectangle = Utils.FindObjectTypeInList(this, otherobj, typeof(Rectangle)) as Rectangle;
                if (rectangle == null)
                {
                    return(null);
                }
                UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, rectangle.m_p1, rectangle.m_p2);
                if (p != UnitPoint.Empty)
                {
                    return(new IntersectSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(VertextSnapPoint))
            {
                double d1 = HitUtil.Distance(point, m_p1);
                double d2 = HitUtil.Distance(point, m_p2);
                if (d1 <= d2)
                {
                    return(new VertextSnapPoint(canvas, this, m_p1));
                }
                return(new VertextSnapPoint(canvas, this, m_p2));
            }
            if (usersnaptype == typeof(NearestSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                if (p != UnitPoint.Empty)
                {
                    return(new NearestSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(PerpendicularSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                if (p != UnitPoint.Empty)
                {
                    return(new PerpendicularSnapPoint(canvas, this, p));
                }
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="point"></param>
        /// <param name="snappoint"></param>
        /// <returns></returns>
        public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            List <IDrawObject>    drawitems = canvas.DataModel.GetHitObjects(canvas, point);
            List <DrawTools.Line> lines     = GetLines(drawitems);

            // add to source lines
            if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift)
            {
                foreach (DrawTools.Line line in lines)
                {
                    AddLine(point, line);
                }
                SetSelectHint();
                return(eDrawObjectMouseDown.Continue);
            }

            if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control)
            {
                foreach (DrawTools.Line line in lines)
                {
                    if (m_originalLines.ContainsKey(line))
                    {
                        RemoveLine(line);
                    }
                    else
                    {
                        AddLine(point, line);
                    }
                }
                SetSelectHint();
                return(eDrawObjectMouseDown.Continue);
            }

            if (drawitems.Count == 0)
            {
                return(eDrawObjectMouseDown.Continue);
            }

            // all lines have been added, now find edge to where to extend
            if (drawitems[0] is DrawTools.Line)
            {
                DrawTools.Line edge     = (DrawTools.Line)drawitems[0];
                bool           modified = false;
                foreach (LinePoints originalLp in m_originalLines.Values)
                {
                    UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2);
                    // lines intersect so shrink line
                    if (intersectpoint != UnitPoint.Empty)
                    {
                        LinePoints lp = new LinePoints();
                        lp.SetLine(originalLp.Line);
                        lp.MousePoint = originalLp.MousePoint;
                        m_modifiedLines.Add(lp.Line, lp);
                        lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint);
                        modified = true;
                        continue;
                    }
                    // lines do not intersect, find apparent intersect point on existing edge line
                    if (intersectpoint == UnitPoint.Empty)
                    {
                        UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(
                            edge.P1,
                            edge.P2,
                            originalLp.Line.P1,
                            originalLp.Line.P2,
                            false,
                            true);
                        if (apprarentISPoint == UnitPoint.Empty)
                        {
                            continue;
                        }

                        modified = true;
                        originalLp.Line.ExtendLineToPoint(apprarentISPoint);

                        LinePoints lp = new LinePoints();
                        lp.SetLine(originalLp.Line);
                        lp.MousePoint = point;
                        m_modifiedLines.Add(lp.Line, lp);
                    }
                }
                if (modified)
                {
                    canvas.DataModel.AfterEditObjects(this);
                }
                return(eDrawObjectMouseDown.Done);
            }

            if (drawitems[0] is DrawTools.Arc)
            {
                DrawTools.Arc edge = (DrawTools.Arc)drawitems[0];
                foreach (LinePoints originalLp in m_originalLines.Values)
                {
                }
                bool modified = false;
            }
            return(eDrawObjectMouseDown.Done);
        }
Esempio n. 4
0
        public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point);

            DrawTools.Line line = null;
            // find first line
            foreach (IDrawObject item in items)
            {
                if (item is DrawTools.Line)
                {
                    line = item as DrawTools.Line;
                    if (line != m_l1Original.Line)
                    {
                        break;
                    }
                }
            }
            if (line == null)
            {
                if (m_l1Original.Line == null)
                {
                    SetHint("No line selected. Select first line");
                }
                else
                {
                    SetHint("No line selected. Select second line");
                }
                return(eDrawObjectMouseDown.Continue);
            }
            if (m_l1Original.Line == null)
            {
                line.Highlighted = true;
                m_l1Original.SetLine(line);
                m_l1Original.MousePoint = point;
                SetHint("Select second line");
                return(eDrawObjectMouseDown.Continue);
            }
            if (m_l2Original.Line == null)
            {
                line.Highlighted = true;
                m_l2Original.SetLine(line);
                m_l2Original.MousePoint = point;

                UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(
                    m_l1Original.Line.P1,
                    m_l1Original.Line.P2,
                    m_l2Original.Line.P1,
                    m_l2Original.Line.P2);

                // if lines do not intersect then extend lines to intersect point
                if (intersectpoint == UnitPoint.Empty)
                {
                    UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2);
                    if (apprarentISPoint == UnitPoint.Empty)
                    {
                        return(eDrawObjectMouseDown.Done);
                    }
                    m_l1Original.Line.ExtendLineToPoint(apprarentISPoint);
                    m_l2Original.Line.ExtendLineToPoint(apprarentISPoint);
                    m_l1NewPoint.SetLine(m_l1Original.Line);
                    m_l2NewPoint.SetLine(m_l2Original.Line);
                    canvas.DataModel.AfterEditObjects(this);
                    return(eDrawObjectMouseDown.Done);
                }

                m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint);
                m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint);
                canvas.DataModel.AfterEditObjects(this);
                return(eDrawObjectMouseDown.Done);
            }
            return(eDrawObjectMouseDown.Done);
        }
Esempio n. 5
0
        public ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobjs, Type[] runningsnaptypes, Type usersnaptype)
        {
            try
            {
                if (Type == LineType.Line || Type == LineType.Dote)
                {
                    float thWidth = ThresholdWidth(canvas, Width);
                    if (runningsnaptypes != null)
                    {
                        foreach (Type snaptype in runningsnaptypes)
                        {
                            if (snaptype == typeof(VertextSnapPoint))
                            {
                                if (HitUtil.CircleHitPoint(m_p1, thWidth, point))
                                {
                                    return(new VertextSnapPoint(canvas, this, m_p1));
                                }
                                if (HitUtil.CircleHitPoint(m_p2, thWidth, point))
                                {
                                    return(new VertextSnapPoint(canvas, this, m_p2));
                                }
                            }
                            //if (snaptype == typeof(MidpointSnapPoint))
                            //{
                            //    UnitPoint p = MidPoint(canvas, m_p1, m_p2, point);
                            //    if (p != UnitPoint.Empty)
                            //        return new MidpointSnapPoint(canvas, this, p);
                            //}
                            if (snaptype == typeof(IntersectSnapPoint))
                            {
                                LineTool otherline = Utiles.FindObjectTypeInList(this, otherobjs, typeof(LineTool)) as LineTool;
                                if (otherline == null)
                                {
                                    continue;
                                }
                                UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2);
                                if (p != UnitPoint.Empty)
                                {
                                    return(new IntersectSnapPoint(canvas, this, p));
                                }
                            }
                        }
                        return(null);
                    }

                    //if (usersnaptype == typeof(MidpointSnapPoint))
                    //    return new MidpointSnapPoint(canvas, this, HitUtil.LineMidpoint(m_p1, m_p2));
                    if (usersnaptype == typeof(IntersectSnapPoint))
                    {
                        LineTool otherline = Utiles.FindObjectTypeInList(this, otherobjs, typeof(LineTool)) as LineTool;
                        if (otherline == null)
                        {
                            return(null);
                        }
                        UnitPoint p = HitUtil.LinesIntersectPoint(m_p1, m_p2, otherline.m_p1, otherline.m_p2);
                        if (p != UnitPoint.Empty)
                        {
                            return(new IntersectSnapPoint(canvas, this, p));
                        }
                    }
                    if (usersnaptype == typeof(VertextSnapPoint))
                    {
                        double d1 = HitUtil.Distance(point, m_p1);
                        double d2 = HitUtil.Distance(point, m_p2);
                        if (d1 <= d2)
                        {
                            return(new VertextSnapPoint(canvas, this, m_p1));
                        }
                        return(new VertextSnapPoint(canvas, this, m_p2));
                    }
                    if (usersnaptype == typeof(NearestSnapPoint))
                    {
                        UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new NearestSnapPoint(canvas, this, p));
                        }
                    }
                    if (usersnaptype == typeof(PerpendicularSnapPoint))
                    {
                        UnitPoint p = HitUtil.NearestPointOnLine(m_p1, m_p2, point);
                        if (p != UnitPoint.Empty)
                        {
                            return(new PerpendicularSnapPoint(canvas, this, p));
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            { throw ex; }
        }
Esempio n. 6
0
        public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            try
            {
                List <IDrawObject> items = canvas.DataModel.GetHitObjects(canvas, point);
                DrawTools.LineTool line  = null;
                foreach (IDrawObject item in items)
                {
                    if (item is DrawTools.LineTool)
                    {
                        line = item as DrawTools.LineTool;
                        if (line.Type == DrawTools.LineType.PointLine)
                        {
                            return(eDrawObjectMouseDownEnum.Done);
                        }
                        if (line != m_l1Original.Line)
                        {
                            break;
                        }
                    }
                }
                if (line == null)
                {
                    if (m_l1Original.Line == null)
                    {
                        SetHint("请选择第一个直线");
                    }
                    else
                    {
                        SetHint("请选择第二个直线");
                    }
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_l1Original.Line == null)
                {
                    line.Highlighted = true;
                    m_l1Original.SetLine(line);
                    m_l1Original.MousePoint = point;
                    SetHint("请选择第二个直线");
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_l2Original.Line == null)
                {
                    line.Highlighted = true;
                    m_l2Original.SetLine(line);
                    m_l2Original.MousePoint = point;

                    UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(
                        m_l1Original.Line.P1,
                        m_l1Original.Line.P2,
                        m_l2Original.Line.P1,
                        m_l2Original.Line.P2);

                    //如果两条实现没有相交,则将两条直线延长到交点
                    if (intersectpoint == UnitPoint.Empty)
                    {
                        UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(m_l1Original.Line.P1, m_l1Original.Line.P2, m_l2Original.Line.P1, m_l2Original.Line.P2);
                        if (apprarentISPoint == UnitPoint.Empty)
                        {
                            return(eDrawObjectMouseDownEnum.Done);
                        }
                        m_l1Original.Line.ExtendLineToPoint(apprarentISPoint);
                        m_l2Original.Line.ExtendLineToPoint(apprarentISPoint);
                        m_l1NewPoint.SetLine(m_l1Original.Line);
                        m_l2NewPoint.SetLine(m_l2Original.Line);
                        canvas.DataModel.AfterEditObjects(this);
                        return(eDrawObjectMouseDownEnum.Done);
                    }

                    m_l1NewPoint.SetNewPoints(m_l1Original.Line, m_l1Original.MousePoint, intersectpoint);
                    m_l2NewPoint.SetNewPoints(m_l2Original.Line, m_l2Original.MousePoint, intersectpoint);
                    canvas.DataModel.AfterEditObjects(this);
                    return(eDrawObjectMouseDownEnum.Done);
                }
                return(eDrawObjectMouseDownEnum.Done);
            }
            catch (Exception ex)
            { throw ex; }
        }
        public eDrawObjectMouseDownEnum OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint)
        {
            try
            {
                List <IDrawObject>        drawitems = canvas.DataModel.GetHitObjects(canvas, point);
                List <DrawTools.LineTool> lines     = GetLines(drawitems);
                if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Shift)
                {
                    foreach (DrawTools.LineTool line in lines)
                    {
                        AddLine(point, line);
                    }
                    SetSelectHint();
                    return(eDrawObjectMouseDownEnum.Continue);
                }
                if (m_originalLines.Count == 0 || Control.ModifierKeys == Keys.Control)
                {
                    foreach (DrawTools.LineTool line in lines)
                    {
                        if (m_originalLines.ContainsKey(line))
                        {
                            RemoveLine(line);
                        }
                        else
                        {
                            AddLine(point, line);
                        }
                    }
                    SetSelectHint();
                    return(eDrawObjectMouseDownEnum.Continue);
                }

                if (drawitems.Count == 0)
                {
                    return(eDrawObjectMouseDownEnum.Continue);
                }

                if (drawitems[0] is DrawTools.LineTool)
                {
                    DrawTools.LineTool edge = (DrawTools.LineTool)drawitems[0];
                    if (edge.Type == DrawTools.LineType.PointLine)
                    {
                        return(eDrawObjectMouseDownEnum.Done);
                    }
                    bool modified = false;
                    foreach (LinePoints originalLp in m_originalLines.Values)
                    {
                        UnitPoint intersectpoint = HitUtil.LinesIntersectPoint(edge.P1, edge.P2, originalLp.Line.P1, originalLp.Line.P2);
                        if (intersectpoint != UnitPoint.Empty)
                        {
                            LinePoints lp = new LinePoints();
                            lp.SetLine(originalLp.Line);
                            lp.MousePoint = originalLp.MousePoint;
                            m_modifiedLines.Add(lp.Line, lp);
                            lp.SetNewPoints(lp.Line, lp.MousePoint, intersectpoint);
                            modified = true;
                            continue;
                        }
                        if (intersectpoint == UnitPoint.Empty)
                        {
                            UnitPoint apprarentISPoint = HitUtil.FindApparentIntersectPoint(
                                edge.P1,
                                edge.P2,
                                originalLp.Line.P1,
                                originalLp.Line.P2,
                                false,
                                true);
                            if (apprarentISPoint == UnitPoint.Empty)
                            {
                                continue;
                            }

                            modified = true;
                            originalLp.Line.ExtendLineToPoint(apprarentISPoint);

                            LinePoints lp = new LinePoints();
                            lp.SetLine(originalLp.Line);
                            lp.MousePoint = point;
                            m_modifiedLines.Add(lp.Line, lp);
                        }
                    }
                    if (modified)
                    {
                        canvas.DataModel.AfterEditObjects(this);
                    }
                    return(eDrawObjectMouseDownEnum.Done);
                }
                return(eDrawObjectMouseDownEnum.Done);
            }
            catch (Exception ex)
            { throw ex; }
        }