コード例 #1
0
ファイル: LineTool.cs プロジェクト: wsmyaopeng/agv-wcs
        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; }
        }