11#ifndef IACT_SNAPPING_SnapOnCurve2D_HXX
22#define IACT_SNAPPING_SnapOnCurve2D_HXX
33
4- #include < Standard_Handle.hxx>
5- #include < gp_Pln.hxx>
6- #include < gp_Pnt2d.hxx>
7- #include < TopoDS_Shape.hxx>
8- #include < TopoDS_Edge.hxx>
9- #include < Geom_Curve.hxx>
10- #include < Geom2d_Curve.hxx>
11- #include < Geom2dAPI_InterCurveCurve.hxx>
4+ #include < AIS_InteractiveContext.hxx>
5+ #include < AIS_InteractiveObject.hxx>
126#include < BRep_Tool.hxx>
137#include < BRepLib.hxx>
8+ #include < Geom2d_Circle.hxx>
9+ #include < Geom2d_Line.hxx>
10+ #include < Geom2dAPI_InterCurveCurve.hxx>
1411#include < GeomAPI.hxx>
12+ #include < gp_Dir2d.hxx>
13+ #include < gp_Pln.hxx>
14+ #include < gp_Pnt2d.hxx>
15+ #include < IntRes2d_IntersectionPoint.hxx>
16+ #include < ProjLib.hxx>
17+ #include < TopoDS.hxx>
18+ #include < TopoDS_Edge.hxx>
1519
1620#include " Iact/InteractiveContext.hxx"
17- #include " Iact/WorkspaceController.hxx"
1821#include " Iact/Workspace/SnapBase.hxx"
22+ #include " Iact/WorkspaceController.hxx"
1923
2024class SnapInfoCurve2D
2125{
@@ -31,60 +35,39 @@ public:
3135 : Mode(mode), Point(point), Parameter(param), TargetParameter(0 )
3236 {}
3337
34- static const std::shared_ptr<SnapInfoCurve2D> Empty;
38+ SnapInfoCurve2D ()
39+ : SnapInfoCurve2D(SnapMode::None, gp_Pnt2d(0 , 0 ), 0 )
40+ {}
3541};
3642
37- // 2D曲线捕捉处理器,支持边捕捉
38- class SnapOnCurve2D : public SnapBase
43+ class SnapOnCurve2D
3944{
4045public:
4146 // 构造函数
4247 SnapOnCurve2D ()
43- : _SupportedModes (SnapMode::Edge)
48+ : SupportedModes (SnapMode::Edge)
4449 {}
4550
46- // 析构函数
4751 virtual ~SnapOnCurve2D () = default ;
4852
49- // 获取或设置捕捉平面
50- const gp_Pln& Plane () const
53+ SnapInfoCurve2D Snap ( const Handle (Geom2d_Curve)& curve,
54+ const Handle(MouseEventData)& mouseEvent)
5155 {
52- return _IsPlaneSet ? _Plane : GetWorkspaceController ()->workspace ()->WorkingPlane ();
53- }
54-
55- void SetPlane (const gp_Pln& plane)
56- {
57- _Plane = plane;
58- _IsPlaneSet = true ;
59- }
60-
61- // 执行捕捉,返回捕捉点
62- gp_Pnt2d Snap (const Handle (Geom2d_Curve)& curve, const Handle(MouseEventData)& mouseEvent)
63- {
64- return ProcessSnap (curve, {}/* mouseEvent->DetectedBrepShape()*/ );
65- }
66-
67- protected:
68- // 清理资源
69- virtual void Cleanup () override
70- {
71- _IsPlaneSet = false ;
72- SnapBase::Cleanup ();
56+ SnapInfoCurve2D snapInfo;
57+ return snapInfo;
7358 }
7459
7560private:
76- // 处理边捕捉
77- gp_Pnt2d ProcessSnap (const Handle (Geom2d_Curve)& curve, const TopoDS_Shape& shapeToSnap)
61+ SnapInfoCurve2D _Snap (const Handle (Geom2d_Curve)& curve,
62+ const TopoDS_Shape& shapeToSnap,
63+ const Handle(AIS_InteractiveObject)& aisObject)
7864 {
79- if (!InteractiveContext::Current ()->GetEditorState ()->IsSnappingEnabled () ||
80- !InteractiveContext::Current ()->GetEditorState ()->IsSnapToEdgeSelected ())
81- {
82- return gp_Pnt2d (0.0 , 0.0 );
83- }
65+ SnapInfoCurve2D snapInfo;
8466
85- if (!shapeToSnap.IsNull () && shapeToSnap.ShapeType () == TopAbs_ShapeEnum::TopAbs_EDGE)
67+ if (SupportedModes & SnapMode::Edge
68+ && shapeToSnap.ShapeType () == TopAbs_ShapeEnum::TopAbs_EDGE)
8669 {
87- TopoDS_Edge edge = TopoDS::Edge (shapeToSnap);
70+ auto edge = TopoDS::Edge (shapeToSnap);
8871 double umin, umax;
8972 Handle (Geom_Curve) edgeCurve = BRep_Tool::Curve (edge, umin, umax);
9073 if (edgeCurve.IsNull () && BRepLib::BuildCurve3d (edge))
@@ -94,22 +77,36 @@ private:
9477
9578 if (!edgeCurve.IsNull ())
9679 {
97- Handle (Geom2d_Curve) projected2dCurve = GeomAPI::To2d (edgeCurve, Plane () );
80+ Handle (Geom2d_Curve) projected2dCurve = GeomAPI::To2d (edgeCurve, _Plane );
9881 Geom2dAPI_InterCurveCurve intersect (curve, projected2dCurve);
9982 if (intersect.NbPoints () > 0 )
10083 {
101- return intersect.Point (1 );
84+ IntRes2d_IntersectionPoint Point1 = intersect.Intersector ().Point (1 );
85+ SnapInfoCurve2D result (SnapMode::Edge, intersect.Point (1 ), Point1.ParamOnFirst ());
86+ result.TargetParameter = Point1.ParamOnSecond ();
87+ result.TargetBrepShape = shapeToSnap;
88+ result.TargetAisObject = aisObject;
89+ return result;
10290 }
10391 }
10492 }
10593
106- return gp_Pnt2d (0.0 , 0.0 );
94+ return snapInfo;
95+ }
96+
97+ SnapInfoCurve2D _SnapGrid (const Handle (Geom2d_Curve)& curve,
98+ int screenPointX,
99+ int screenPointY)
100+ {
101+ SnapInfoCurve2D snapInfo;
102+ double currentDistance = 10.0 ;
103+ return snapInfo;
107104 }
108105
109106private:
110107 gp_Pln _Plane; // 捕捉平面
108+ SnapModes SupportedModes; // 支持的捕捉模式
111109 bool _IsPlaneSet = false ; // 标记平面是否被设置
112- SnapModes _SupportedModes; // 支持的捕捉模式
113110};
114111
115112DEFINE_STANDARD_HANDLE (SnapOnCurve2D, SnapBase)
0 commit comments