Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit b2a2395

Browse files
committed
patch
1 parent 84bf69a commit b2a2395

3 files changed

Lines changed: 98 additions & 54 deletions

File tree

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
#include "Iact/Workspace/SnapOnCurve2D.hxx"
2-
3-
const std::shared_ptr<SnapInfoCurve2D> SnapInfoCurve2D::Empty =
4-
std::make_shared<SnapInfoCurve2D>(SnapMode::None, gp_Pnt2d(0, 0), 0);
5-

src/Iact/Workspace/SnapOnCurve2D.hxx

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
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

2024
class 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
{
4045
public:
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

7560
private:
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

109106
private:
110107
gp_Pln _Plane; // 捕捉平面
108+
SnapModes SupportedModes; // 支持的捕捉模式
111109
bool _IsPlaneSet = false; // 标记平面是否被设置
112-
SnapModes _SupportedModes; // 支持的捕捉模式
113110
};
114111

115112
DEFINE_STANDARD_HANDLE(SnapOnCurve2D, SnapBase)

src/Occt/OcctHelper/AisHelper.hxx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,57 @@ class AisHelper
1515
public:
1616
static void DisableGlobalClipPlanes(const Handle(PrsMgr_PresentableObject)& object);
1717
static TopoDS_Shape GetShapeFromEntityOwner(const Handle(SelectMgr_EntityOwner) owner);
18+
19+
// 静态函数:从选择器中获取拾取的交互对象和形状
20+
static int GetPickedFromSelector(const Handle(StdSelect_ViewerSelector3d)& selector,
21+
std::vector<Handle(AIS_InteractiveObject)>& interactives,
22+
std::vector<TopoDS_Shape>& shapes)
23+
{
24+
int count = 0;
25+
bool doInteractives = !interactives.empty();
26+
bool doShapes = !shapes.empty();
27+
28+
// 清空输出向量
29+
interactives.clear();
30+
shapes.clear();
31+
32+
// 遍历拾取结果
33+
for(Standard_Integer aPickIter = 1; aPickIter <= selector->NbPicked(); ++aPickIter)
34+
{
35+
Handle(SelectMgr_EntityOwner) owner = selector->Picked(aPickIter);
36+
if(owner.IsNull() || !owner->HasSelectable())
37+
{
38+
continue;
39+
}
40+
41+
count++;
42+
43+
// 处理交互对象
44+
if(doInteractives)
45+
{
46+
Handle(AIS_InteractiveObject) interactive =
47+
Handle(AIS_InteractiveObject)::DownCast(owner->Selectable());
48+
interactives.push_back(interactive); // 空 Handle 表示 nullptr
49+
}
50+
51+
// 处理形状
52+
if(doShapes)
53+
{
54+
Handle(StdSelect_BRepOwner) brepOwner =
55+
Handle(StdSelect_BRepOwner)::DownCast(owner);
56+
if(!brepOwner.IsNull() && brepOwner->HasShape())
57+
{
58+
shapes.push_back(brepOwner->Shape());
59+
}
60+
else
61+
{
62+
shapes.push_back(TopoDS_Shape()); // 空形状表示 nullptr
63+
}
64+
}
65+
}
66+
67+
return count;
68+
}
1869
};
1970

2071
#endif // OCCT_OCCTHELPER_AISHELPER_H_

0 commit comments

Comments
 (0)