/// <summary> /// 鼠标垂直移动?如果是perSnap.Owner线则设置p1为点到直线最近距离直线上的点,p2为传入的点,如果是IArc则设置p1为到圆最近距离的点,p2为传入的点 /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> protected virtual void MouseMovePerpendicular(ICanvas canvas, UnitPoint point) { if (m_perSnap.Owner is Line) { Line src = m_perSnap.Owner as Line; m_p1 = HitUtil.NearestPointOnLine(src.P1, src.P2, point, true); m_p2 = point; } if (m_perSnap.Owner is IArc) { IArc src = m_perSnap.Owner as IArc; m_p1 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, point, 0); m_p2 = point; } }
public eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { Selected = false; OnMouseMove(canvas, point); if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Line) { Line src = snappoint.Owner as Line; m_p2 = HitUtil.NearestPointOnLine(src.P1, src.P2, m_p1, true); return(eDrawObjectMouseDown.DoneRepeat); } if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Arc) { Arc src = snappoint.Owner as Arc; m_p2 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, m_p1, 0); return(eDrawObjectMouseDown.DoneRepeat); } if (snappoint is SnapPointBase && snappoint.Owner is RectBase) { NodePointCubicBezier.ePoint pointType = HitUtil.Distance(point, m_p1) < HitUtil.Distance(point, m_p2) ? NodePointCubicBezier.ePoint.P1 : NodePointCubicBezier.ePoint.P2; RectBase rect = snappoint.Owner as RectBase; rect.AttachConnectionCrvNode(new NodePointCubicBezier(this, pointType)); if (pointType == NodePointCubicBezier.ePoint.P1) { m_p1 = point; } else { m_p2 = point; } UpdateCtrlPts(); return(eDrawObjectMouseDown.Done); } if (Control.ModifierKeys == Keys.Control) { point = HitUtil.OrthoPointD(m_p1, point, 45); } m_p2 = point; UpdateCtrlPts(); return(eDrawObjectMouseDown.Done); }
/// <summary> /// 按下鼠标时寻找点到直线最近距离直线上的点或距离园最近的点以角度找邻点 /// </summary> /// <param name="canvas"></param> /// <param name="point"></param> /// <param name="snappoint"></param> /// <returns></returns> public virtual eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { Selected = false; if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Line) { Line src = snappoint.Owner as Line; m_p2 = HitUtil.NearestPointOnLine(src.P1, src.P2, m_p1, true); return(eDrawObjectMouseDown.DoneRepeat); } if (snappoint is PerpendicularSnapPoint && snappoint.Owner is Arc) { Arc src = snappoint.Owner as Arc; m_p2 = HitUtil.NearestPointOnCircle(src.Center, src.Radius, m_p1, 0); return(eDrawObjectMouseDown.DoneRepeat); } if (Control.ModifierKeys == Keys.Control) { point = HitUtil.OrthoPointD(m_p1, point, 45); } m_p2 = point; return(eDrawObjectMouseDown.DoneRepeat); }
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); }