Example #1
0
 /// <summary>
 /// 鼠标移动正切?如果m_tanSnap.Owner is IArc,则设置端点P1为圆上的切点,p2为传入的值,如果p1为空,则设置p1p2均为圆弧的中点
 /// </summary>
 /// <param name="canvas"></param>
 /// <param name="point"></param>
 protected virtual void MouseMoveTangent(ICanvas canvas, UnitPoint point)
 {
     if (m_tanSnap.Owner is IArc)
     {
         IArc src = m_tanSnap.Owner as IArc;
         m_p1 = HitUtil.TangentPointOnCircle(src.Center, src.Radius, point, m_tanReverse);
         m_p2 = point;
         if (m_p1 == UnitPoint.Empty)
         {
             m_p2 = m_p1 = src.Center;
         }
     }
 }
Example #2
0
        public virtual ISnapPoint SnapPoint(ICanvas canvas, UnitPoint point, List <IDrawObject> otherobj, Type[] runningsnaptypes, Type usersnaptype)
        {
            float thWidth = Line.ThresholdWidth(canvas, Width, ThresholdPixel);

            if (runningsnaptypes != null)
            {
                foreach (Type snaptype in runningsnaptypes)
                {
                    if (snaptype == typeof(QuadrantSnapPoint))
                    {
                        UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90);
                        if (p != UnitPoint.Empty && HitUtil.PointInPoint(p, point, thWidth))
                        {
                            return(new QuadrantSnapPoint(canvas, this, p));
                        }
                    }

                    //if (snaptype == typeof(DivisionSnapPoint))
                    //{
                    //    double angle = 360 / 8;
                    //    UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, angle);
                    //    if (p != UnitPoint.Empty && HitUtil.PointInPoint(p, point, thWidth))
                    //        return new DivisionSnapPoint(canvas, this, p);
                    //}

                    if (snaptype == typeof(CenterSnapPoint))
                    {
                        if (HitUtil.PointInPoint(m_center, point, thWidth))
                        {
                            return(new CenterSnapPoint(canvas, this, m_center));
                        }
                    }

                    if (snaptype == typeof(VertextSnapPoint))
                    {
                        if (HitUtil.PointInPoint(P1, point, thWidth))
                        {
                            return(new VertextSnapPoint(canvas, this, P1));
                        }
                        if (HitUtil.PointInPoint(P3, point, thWidth))
                        {
                            return(new VertextSnapPoint(canvas, this, P3));
                        }
                    }
                }
                return(null);
            }

            if (usersnaptype == typeof(NearestSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0);
                if (p != UnitPoint.Empty)
                {
                    return(new NearestSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(PerpendicularSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 0);
                if (p != UnitPoint.Empty)
                {
                    return(new PerpendicularSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(QuadrantSnapPoint))
            {
                UnitPoint p = HitUtil.NearestPointOnCircle(m_center, m_radius, point, 90);
                if (p != UnitPoint.Empty)
                {
                    return(new QuadrantSnapPoint(canvas, this, p));
                }
            }
            if (usersnaptype == typeof(TangentSnapPoint))
            {
                IDrawObject drawingObject = canvas.CurrentObject;
                UnitPoint   p             = UnitPoint.Empty;
                if (drawingObject is LineEdit)
                {
                    UnitPoint mousepoint = point;
                    point = ((LineEdit)drawingObject).P1;
                    UnitPoint p1 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, false);
                    UnitPoint p2 = HitUtil.TangentPointOnCircle(m_center, m_radius, point, true);
                    double    d1 = HitUtil.Distance(mousepoint, p1);
                    double    d2 = HitUtil.Distance(mousepoint, p2);
                    if (d1 <= d2)
                    {
                        return(new TangentSnapPoint(canvas, this, p1));
                    }
                    else
                    {
                        return(new TangentSnapPoint(canvas, this, p2));
                    }
                }
                //if (p != PointF.Empty)
                return(new TangentSnapPoint(canvas, this, p));
            }
            if (usersnaptype == typeof(CenterSnapPoint))
            {
                return(new CenterSnapPoint(canvas, this, m_center));
            }

            return(null);
        }