-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeSimpleClamp.h
More file actions
283 lines (250 loc) · 8.49 KB
/
MakeSimpleClamp.h
File metadata and controls
283 lines (250 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#pragma once
#include "BRepAdaptor_Curve.hxx"
#include "BRepBuilderAPI_MakeEdge.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "BRepBuilderAPI_MakeWire.hxx"
#include "TopoDS_Edge.hxx"
#include "TopoDS_Shape.hxx"
#include <BRep_Builder.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS_Face.hxx>
#include <vector>
//! 所有板均无厚度
namespace OCCTK {
namespace SimpleClamp {
#pragma region Utility
public struct BasePlate {
TopoDS_Shape Shape() {
// 根据边界框尺寸创建立方体
gp_Pnt theLowLeft(X - offsetX, Y - offsetY, Z);
gp_Pnt theTopRight(X + dX + offsetX, Y + dY + offsetY, Z);
gp_Pnt p1, p2, p3, p4;
p1 = theLowLeft;
p2 = gp_Pnt(theLowLeft.X(), theTopRight.Y(), Z);
p3 = theTopRight;
p4 = gp_Pnt(theTopRight.X(), theLowLeft.Y(), Z);
// 创建边
BRepBuilderAPI_MakeEdge l1(p1, p2);
BRepBuilderAPI_MakeEdge l2(p2, p3);
BRepBuilderAPI_MakeEdge l3(p3, p4);
BRepBuilderAPI_MakeEdge l4(p4, p1);
// 创建线段
BRepBuilderAPI_MakeWire wire;
wire.Add(l1);
wire.Add(l2);
wire.Add(l3);
wire.Add(l4);
// 创建面
BRepBuilderAPI_MakeFace face(wire.Wire(), true);
if (mySlotShape.IsNull()) {
TopoDS_Compound test;
mySlotBuilder.MakeCompound(test);
mySlotShape = test;
return face.Shape();
}
else {
return BRepAlgoAPI_Cut(face.Shape(), mySlotShape).Shape();
}
}
double X;
double Y;
double Z;
double dX;
double dY;
double offsetX;
double offsetY;
double offsetZ;
//double lowestZ;// 零件最低点
double hight;// 零件高度
TopoDS_Shape mySlotShape = TopoDS_Shape();
BRep_Builder mySlotBuilder = BRep_Builder();
};
// 横截方向必须垂直于XY方向,Z值由底板决定
public class PlatePose {
public:
PlatePose() {};
PlatePose(const gp_Pnt thePnt, const gp_Dir theDir) { point = thePnt, dir = theDir; }
gp_Pnt point;
gp_Dir dir; // dir 与 pln 在同一平面
gp_Pln Plane() {
if (myPlant != nullptr) return *myPlant;
myPlant = new gp_Pln(point, dir);
return *myPlant;
}
// 拷贝构造函数
PlatePose(const PlatePose& other) :point(other.point), dir(other.dir) {
if (other.myPlant) {
myPlant = other.myPlant;
}
}
// 拷贝赋值运算符
PlatePose& operator=(const PlatePose& other) {
if (this != &other) {
point = other.point;
dir = other.dir;
}
return *this;
}
private:
gp_Pln* myPlant = nullptr;
};
public class myEdge {
public:
myEdge() {};
// 构造函数使用初始化列表
myEdge(TopoDS_Edge theEdge)
: edge(theEdge) // 初始化列表初始化 edge 和 dir
{
gp_Pnt a, b;
BRepAdaptor_Curve aBAC(theEdge);
start = aBAC.Value(aBAC.FirstParameter());
end = aBAC.Value(aBAC.LastParameter());
middle = aBAC.Value(aBAC.FirstParameter() + (aBAC.LastParameter() - aBAC.FirstParameter()) / 2);
};
gp_Pnt2d start2D() {
return gp_Pnt2d(start.X(), start.Y());
}
gp_Pnt2d end2D() {
return gp_Pnt2d(end.X(), end.Y());
}
TopoDS_Edge edge;
gp_Pnt start;
gp_Pnt end;
gp_Pnt middle;
bool dir = true;
// 拷贝赋值操作符
myEdge& operator=(const myEdge& other) {
if (this != &other) {
edge = other.edge;
start = other.start;
end = other.end;
middle = other.middle;
dir = other.dir;
}
return *this;
}
// 重载 operator== 操作符,用于比较两个 myEdge 对象是否相等
bool operator==(const myEdge& other) const {
return start.IsEqual(other.start, 1e-4) && end.IsEqual(other.end, 1e-4);
}
};
using Ring = std::vector<myEdge>;
public struct VerticalPiece {
VerticalPiece() {};
VerticalPiece(PlatePose thePose, myEdge theMyEdge, double theZ) :pose(thePose), myEdge(theMyEdge), Z(theZ) {}
PlatePose pose;
myEdge myEdge;
double Z;
double order;// 用于记录排序的依据
// 由 Edge 和 Z 值生成形状
TopoDS_Shape Shape() {
if (myShape.IsNull()) return myShape;
gp_Pnt p2 = myEdge.start;
gp_Pnt p3 = myEdge.end;
gp_Pnt p1(p2.X(), p2.Y(), Z);
gp_Pnt p4(p3.X(), p3.Y(), Z);
BRepBuilderAPI_MakeWire aWireMk = BRepBuilderAPI_MakeWire();
aWireMk.Add(BRepBuilderAPI_MakeEdge(p1, p2));
aWireMk.Add(myEdge.edge);
aWireMk.Add(BRepBuilderAPI_MakeEdge(p3, p4));
aWireMk.Add(BRepBuilderAPI_MakeEdge(p4, p1));
if (!aWireMk.IsDone()) {
myShape = myEdge.edge;
return myShape;
}
BRepBuilderAPI_MakeFace PieceProfile = BRepBuilderAPI_MakeFace(aWireMk.Wire());
if (!PieceProfile.IsDone()) {
myShape = myEdge.edge;
return myShape; myShape = myEdge.edge;
return myShape;
}
myShape = PieceProfile;
return myShape;
};
double Length() const {
if (myLength != -1.0) return myLength;
gp_Pnt2d a(myEdge.start.X(), myEdge.start.Y());
gp_Pnt2d b(myEdge.end.X(), myEdge.end.Y());
myLength = a.Distance(b);
return myLength;
}
bool operator==(const VerticalPiece& other) const {
return this->myEdge == other.myEdge;
}
private:
TopoDS_Shape myShape;
mutable double myLength = -1.0;// 使用一个无效的默认值来表示长度尚未计算
};
public struct VerticalPlate {
public:
TopoDS_Shape shape;
TopoDS_Shape numberedShape;
std::vector<VerticalPiece> pieces = std::vector<VerticalPiece>();
PlatePose pose;
gp_Pnt start;
gp_Pnt end;
double Z;
double clearances;
double minSupportLen;
double cuttingDistance;
double avoidanceHeight;
double connectionThickness;// 板厚
double slotLength = 6.0;//todo 暂不开放 连接槽长度
double slotHight = 10.0;//todo 暂不开放 连接槽高度
double filletRadius;
bool auxiliary = false;
double auxiliaryHight = 100.0;
double auxiliaryWidth = 30.0;
std::vector<gp_Pnt> cutPoints;
TCollection_AsciiString numberString = "unset";
bool singlePlate = false;
BRepBuilderAPI_MakeWire _unclosedWire;
};
///==============================Function==============================
// 根据theEdge和Z创建Piece
inline TopoDS_Face MakePiece(myEdge theEdge, double theZ) {
gp_Pnt p1, p2, p3, p4;
p1 = theEdge.start;
p2 = theEdge.end;
p3 = gp_Pnt(p2.X(), p2.Y(), theZ);
p4 = gp_Pnt(p1.X(), p1.Y(), theZ);
// 创建边
TopoDS_Edge l1 = theEdge.edge;
BRepBuilderAPI_MakeEdge l2(p2, p3);
BRepBuilderAPI_MakeEdge l3(p3, p4);
BRepBuilderAPI_MakeEdge l4(p4, p1);
// 创建线段
BRepBuilderAPI_MakeWire wire;
wire.Add(l1);
wire.Add(l2);
wire.Add(l3);
wire.Add(l4);
// 创建面
BRepBuilderAPI_MakeFace face(wire.Wire(), true);
return face.Face();
}
#pragma endregion
///==============================
///生成底板
///==============================
BasePlate MakeBasePlate(TopoDS_Shape theWorkpiece, double theOffsetZ, double theOffsetX, double theOffsetY);
///==============================
///生成竖板
///==============================
VerticalPlate MakeVerticalPlate(TopoDS_Shape theWorkpiece, BasePlate theBasePlate, PlatePose theDir, double theClearances, double theMinSupportLen, double theCutDistance);
VerticalPlate SuturePiece(VerticalPlate& thePlate, const BasePlate theBase, double theConnectionHight, double theConnectionThickness);
VerticalPlate SlotVerticalPlate(VerticalPlate& thePlate, std::vector<VerticalPlate> otherPlates, double theFilletRadius, bool middleToDown);
BasePlate SlotBasePlate(BasePlate& theBasePlate, std::vector<VerticalPlate> middleDownPlates, std::vector<VerticalPlate> middleUpPlates);
VerticalPlate AddSupportPlate(VerticalPlate thePlate, bool middleToDown);
VerticalPlate BrandNumberVerticalPlate(VerticalPlate thePlate, double hight);
VerticalPlate BrandNumberVerticalPlate(VerticalPlate thePlate, gp_Pnt aimPoint, double hight);
BasePlate BrandNumberBasePlate(BasePlate thePlate, double hight);
///==============================
///得到结果
///==============================
TopoDS_Shape DeployPlates(BasePlate theBasePlate, std::vector<VerticalPlate> middleToDownPlates, std::vector<VerticalPlate> middleToUpPlates);
}
}