7fd59977 |
1 | // File: QANewDBRepNaming_PrimitiveCommands.cxx |
2 | // Created: Thu Dec 23 11:25:57 1999 |
3 | // Author: Vladislav ROMASHKO |
4 | // <vro@flox.nnov.matra-dtv.fr> |
5 | |
6 | |
7 | #include <QANewDBRepNaming.ixx> |
8 | |
9 | #include <Draw.hxx> |
10 | #include <Draw_Interpretor.hxx> |
11 | |
12 | #include <DBRep.hxx> |
13 | |
14 | #include <DDF.hxx> |
15 | |
16 | #include <TNaming_NamedShape.hxx> |
17 | #include <TNaming_Tool.hxx> |
18 | #include <TNaming_Builder.hxx> |
19 | |
20 | #include <TopoDS.hxx> |
21 | #include <TopoDS_Shape.hxx> |
22 | #include <TopoDS_Face.hxx> |
23 | #include <TopoDS_Wire.hxx> |
24 | #include <TopoDS_Edge.hxx> |
25 | #include <gp_Pln.hxx> |
26 | |
27 | #include <QANewBRepNaming_Box.hxx> |
28 | #include <QANewBRepNaming_Cylinder.hxx> |
29 | #include <QANewBRepNaming_Sphere.hxx> |
30 | #include <QANewBRepNaming_Prism.hxx> |
31 | #include <QANewBRepNaming_Revol.hxx> |
32 | #include <QANewBRepNaming_ImportShape.hxx> |
33 | |
34 | #include <BRepPrimAPI_MakeCylinder.hxx> |
35 | #include <BRepPrimAPI_MakeSphere.hxx> |
36 | |
37 | #include <BRepPrimAPI_MakePrism.hxx> |
38 | #include <BRepPrimAPI_MakeRevol.hxx> |
39 | #include <BRepPrimAPI_MakeBox.hxx> |
40 | |
41 | #include <BRepAdaptor_Surface.hxx> |
42 | |
43 | #include <TDataXtd_Geometry.hxx> |
44 | |
45 | #include <TopExp.hxx> |
46 | |
47 | #include <BRep_Tool.hxx> |
48 | |
49 | #include <assert.h> |
50 | #include <TopExp_Explorer.hxx> |
51 | |
52 | #include <QADNaming.hxx> |
53 | #include <BRepFilletAPI_MakeFillet.hxx> |
54 | #include <QANewBRepNaming_Fillet.hxx> |
55 | #include <BRepFilletAPI_MakeChamfer.hxx> |
56 | #include <QANewBRepNaming_Chamfer.hxx> |
57 | |
58 | //======================================================================= |
59 | //function : QANewDBRepNaming_NameBox |
60 | //purpose : NameCylinder Doc Label dx dy dz |
61 | //======================================================================= |
62 | |
63 | static Standard_Integer QANewDBRepNaming_NameBox (Draw_Interpretor& di, |
64 | Standard_Integer nb, |
65 | const char ** arg) |
66 | { |
67 | if(nb == 6) { |
68 | TDF_Label L; |
69 | if (!QADNaming::Entry(arg, L)) return 1; |
70 | |
71 | BRepPrimAPI_MakeBox mkBox(atof(arg[3]), atof(arg[4]), atof(arg[5])); |
72 | mkBox.Build(); |
73 | |
74 | if(!mkBox.IsDone()) { |
75 | di << "The box hasn't been built" << "\n"; |
76 | return 1; |
77 | } |
78 | |
79 | QANewBRepNaming_Box nameBox(L); |
80 | nameBox.Load(mkBox,QANewBRepNaming_SOLID); |
81 | return 0; |
82 | } |
83 | di << "QANewDBRepNaming_NameBox : Error" << "\n"; |
84 | return 1; |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : QANewDBRepNaming_NameCylinder |
89 | //purpose : NameCylinder Doc Label R H Angle [ShapeType(Shell/Solid)] |
90 | //======================================================================= |
91 | |
92 | static Standard_Integer QANewDBRepNaming_NameCylinder (Draw_Interpretor& di, |
93 | Standard_Integer nb, |
94 | const char ** arg) |
95 | { |
96 | if(nb == 6 || nb == 7) { |
97 | TDF_Label L; |
98 | if (!QADNaming::Entry(arg, L)) return 1; |
99 | |
100 | BRepPrimAPI_MakeCylinder mkCylinder(atof(arg[3]), atof(arg[4])); |
101 | if (atof(arg[5]) != 0.) { |
102 | // for Mandrake-10 - mkv,02.06.06 - mkCylinder = BRepPrimAPI_MakeCylinder(atof(arg[3]), atof(arg[4]), atof(arg[5])); |
103 | BRepPrimAPI_MakeCylinder MakeCylinder(atof(arg[3]), atof(arg[4]), atof(arg[5])); |
104 | mkCylinder = MakeCylinder; |
105 | } |
106 | mkCylinder.Build(); |
107 | |
108 | if(!mkCylinder.IsDone()) { |
109 | di << "The cylinder hasn't been built" << "\n"; |
110 | return 1; |
111 | } |
112 | |
113 | QANewBRepNaming_Cylinder nameCylinder(L); |
114 | if (nb == 6) nameCylinder.Load(mkCylinder, QANewBRepNaming_SHELL); |
115 | else if (atoi(arg[6]) == 0) nameCylinder.Load(mkCylinder, QANewBRepNaming_SHELL); |
116 | else nameCylinder.Load(mkCylinder, QANewBRepNaming_SOLID); |
117 | |
118 | return 0; |
119 | } |
120 | di << "QANewDBRepNaming_NameCylinder : Error" << "\n"; |
121 | return 1; |
122 | } |
123 | |
124 | |
125 | //======================================================================= |
126 | //function : QANewDBRepNaming_NameSphere |
127 | //purpose : NameSphere Doc Label R X Y Z Angle1 Angle2 Angle3 [ShapeType(Shell/Solid)] |
128 | //======================================================================= |
129 | |
130 | static Standard_Integer QANewDBRepNaming_NameSphere (Draw_Interpretor& di, |
131 | Standard_Integer nb, |
132 | const char ** arg) |
133 | { |
134 | TDF_Label L; |
135 | if (!QADNaming::Entry(arg, L)) return 1; |
136 | Standard_Real R = atof(arg[3]); |
137 | Standard_Real X = atof(arg[4]); |
138 | Standard_Real Y = atof(arg[5]); |
139 | Standard_Real Z = atof(arg[6]); |
140 | Standard_Real DX = atof(arg[7]); |
141 | Standard_Real DY = atof(arg[8]); |
142 | Standard_Real DZ = atof(arg[9]); |
143 | QANewBRepNaming_TypeOfPrimitive3D type = QANewBRepNaming_SHELL; |
144 | if (nb == 11) type = (QANewBRepNaming_TypeOfPrimitive3D) atoi(arg[10]); |
145 | |
146 | QANewBRepNaming_Sphere nameSphere(L); |
147 | BRepPrimAPI_MakeSphere mkSphere(R); |
148 | if (DX == 0 && DY == 0 && DZ == 0) { |
149 | // for Mandrake-10 - mkv,02.06.06 - mkSphere = BRepPrimAPI_MakeSphere(gp_Pnt(X, Y, Z), R); |
150 | BRepPrimAPI_MakeSphere MakeSphere1(gp_Pnt(X, Y, Z), R); |
151 | mkSphere = MakeSphere1; |
152 | } else { |
153 | // for Mandrake-10 - mkv,02.06.06 - mkSphere = BRepPrimAPI_MakeSphere(gp_Pnt(X, Y, Z), R, DX, DY, DZ); |
154 | BRepPrimAPI_MakeSphere MakeSphere2(gp_Pnt(X, Y, Z), R, DX, DY, DZ); |
155 | mkSphere = MakeSphere2; |
156 | } |
157 | mkSphere.Build(); |
158 | if(!mkSphere.IsDone()) { |
159 | di << "The sphere hasn't been built" << "\n"; |
160 | return 1; |
161 | } |
162 | nameSphere.Load(mkSphere, type); |
163 | return 0; |
164 | } |
165 | |
166 | //=========================================================================== |
167 | //function : QANewDBRepNaming_NamePrism |
168 | //purpose : NamePrism Doc Label BasisLabel H Direction(X Y Z) [Inf/Semi-Inf] |
169 | //=========================================================================== |
170 | |
171 | static Standard_Integer QANewDBRepNaming_NamePrism (Draw_Interpretor& di, |
172 | Standard_Integer nb, |
173 | const char ** arg) |
174 | { |
175 | if (nb < 5 || nb > 9 || nb == 6 || nb == 7) { |
176 | di << "QANewDBRepNaming_NamePrism : Error" << "\n"; |
177 | return 1; |
178 | } |
179 | |
180 | TDF_Label L,BL; |
181 | if (!QADNaming::Entry(arg, L)) return 1; |
182 | if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1; |
183 | |
184 | Standard_Real H = atof(arg[4]); |
185 | |
186 | Handle(TNaming_NamedShape) BasisNS; |
187 | if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1; |
188 | const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS); |
189 | |
190 | QANewBRepNaming_Prism namePrism(L); |
191 | |
192 | if (nb >= 8) { |
193 | gp_Dir Direction(atof(arg[5]), atof(arg[6]), atof(arg[7])); |
194 | gp_Vec Vector(Direction); |
195 | Vector.Normalize(); |
196 | Vector *= H; |
197 | |
198 | if (nb == 8) { |
199 | BRepPrimAPI_MakePrism mkPrism(Basis, Vector); |
200 | mkPrism.Build(); |
201 | |
202 | if(!mkPrism.IsDone()) { |
203 | di << "The prism hasn't been built" << "\n"; |
204 | return 1; |
205 | } |
206 | |
207 | namePrism.Load(mkPrism, Basis); |
208 | } |
209 | else if (nb == 9) { |
210 | BRepPrimAPI_MakePrism mkPrism(Basis, Direction, (Standard_Boolean)atoi(arg[8])); |
211 | mkPrism.Build(); |
212 | |
213 | if(!mkPrism.IsDone()) { |
214 | di << "The prism hasn't been built" << "\n"; |
215 | return 1; |
216 | } |
217 | |
218 | namePrism.Load(mkPrism, Basis); |
219 | } |
220 | } |
221 | |
222 | return 0; |
223 | } |
224 | |
225 | //=========================================================================== |
226 | //function : QANewDBRepNaming_NameRevol |
227 | //purpose : NameRevol Doc Label BasisLabel AxisLabel Angle |
228 | //=========================================================================== |
229 | |
230 | static Standard_Integer QANewDBRepNaming_NameRevol (Draw_Interpretor& di, |
231 | Standard_Integer nb, |
232 | const char ** arg) |
233 | { |
234 | if (nb < 5 || nb > 6) { |
235 | di << "QANewDBRepNaming_NameRevol : Error" << "\n"; |
236 | return 1; |
237 | } |
238 | |
239 | TDF_Label L, BL, AL; |
240 | if (!QADNaming::Entry(arg, L)) return 1; |
241 | |
242 | if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1; |
243 | if (!DDF::AddLabel(L.Data(), arg[4], AL)) return 1; |
244 | |
245 | Handle(TNaming_NamedShape) BasisNS, AxisNS; |
246 | if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1; |
247 | if (!AL.FindAttribute(TNaming_NamedShape::GetID(), AxisNS)) return 1; |
248 | const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS); |
249 | const TopoDS_Shape& Axis = TNaming_Tool::CurrentShape(AxisNS); |
250 | |
251 | if (Axis.ShapeType() != TopAbs_EDGE) return 1; |
252 | |
253 | gp_Ax1 axis; |
254 | TopoDS_Vertex fV = TopExp::FirstVertex(TopoDS::Edge(Axis), Standard_True); |
255 | TopoDS_Vertex lV = TopExp::LastVertex(TopoDS::Edge(Axis), Standard_True); |
256 | if (!fV.IsNull() || !lV.IsNull()) { |
257 | gp_Vec alocalV(BRep_Tool::Pnt(fV),BRep_Tool::Pnt(lV)); |
258 | gp_Dir Direction(alocalV); |
259 | // gp_Dir Direction(gp_Vec(BRep_Tool::Pnt(fV), BRep_Tool::Pnt(lV))); |
260 | axis.SetLocation(BRep_Tool::Pnt(fV)); |
261 | axis.SetDirection(Direction); |
262 | } |
263 | else { |
264 | TDataXtd_Geometry::Axis(AL, axis); |
265 | } |
266 | |
267 | QANewBRepNaming_Revol nameRevol(L); |
268 | |
269 | if(nb == 5) { |
270 | |
271 | BRepPrimAPI_MakeRevol mkRevol(Basis, axis); |
272 | mkRevol.Build(); |
273 | |
274 | if(!mkRevol.IsDone()) { |
275 | di << "The revol hasn't been built" << "\n"; |
276 | return 1; |
277 | } |
278 | |
279 | nameRevol.Load(mkRevol, Basis); |
280 | } |
281 | else if (nb == 6) { |
282 | |
283 | Standard_Real Angle = atof(arg[5]); |
284 | |
285 | BRepPrimAPI_MakeRevol mkRevol(Basis, axis, Angle); |
286 | mkRevol.Build(); |
287 | |
288 | if(!mkRevol.IsDone()) { |
289 | di << "The revol hasn't been built" << "\n"; |
290 | return 1; |
291 | } |
292 | |
293 | nameRevol.Load(mkRevol, Basis); |
294 | |
295 | } |
296 | |
297 | return 0; |
298 | } |
299 | |
300 | //=========================================================================== |
301 | //function : QANewDBRepNaming_NameFillet |
302 | //purpose : NameFillet Doc Label SourceShapeLabel PathLabel Radius |
303 | //=========================================================================== |
304 | |
305 | static Standard_Integer QANewDBRepNaming_NameFillet (Draw_Interpretor& di, |
306 | Standard_Integer nb, |
307 | const char ** arg) |
308 | { |
309 | if (nb != 6) { |
310 | di << "QANewDBRepNaming_NameFillet : Error" << "\n"; |
311 | return 1; |
312 | } |
313 | |
314 | TDF_Label L, BL, PL; |
315 | if (!QADNaming::Entry(arg, L)) return 1; |
316 | |
317 | if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1; |
318 | if (!DDF::AddLabel(L.Data(), arg[4], PL)) return 1; |
319 | Standard_Real aRadius = atoi(arg[5]); |
320 | Handle(TNaming_NamedShape) BasisNS, PathNS; |
321 | if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1; |
322 | if (!PL.FindAttribute(TNaming_NamedShape::GetID(), PathNS)) return 1; |
323 | const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS); |
324 | const TopoDS_Shape& Path = TNaming_Tool::CurrentShape(PathNS); |
325 | |
326 | BRepFilletAPI_MakeFillet aFillet(Basis); |
327 | TopExp_Explorer anExp(Path,TopAbs_EDGE); |
328 | if (anExp.More()) { |
329 | for(;anExp.More();anExp.Next()) { |
330 | aFillet.Add(aRadius,TopoDS::Edge(anExp.Current())); |
331 | } |
332 | } else aFillet.Add(aRadius,TopoDS::Edge(Path)); |
333 | aFillet.Build(); |
334 | if (!aFillet.IsDone()) return 1; |
335 | QANewBRepNaming_Fillet aNaming(L); |
336 | aNaming.Load(Basis, aFillet); |
337 | return 0; |
338 | } |
339 | |
340 | //=========================================================================== |
341 | //function : QANewDBRepNaming_NameChamfer |
342 | //purpose : NameChamfer Doc Label SourceShapeLabel EdgeLabel FaceLabel Distance1 Distance2 |
343 | //=========================================================================== |
344 | |
345 | static Standard_Integer QANewDBRepNaming_NameChamfer (Draw_Interpretor& di, |
346 | Standard_Integer nb, |
347 | const char ** arg) |
348 | { |
349 | if (nb != 8) { |
350 | di << "QANewDBRepNaming_NameChamfer : Error" << "\n"; |
351 | return 1; |
352 | } |
353 | |
354 | TDF_Label L, BL, EL, FL; |
355 | Standard_Real aDist1, aDist2; |
356 | |
357 | if (!QADNaming::Entry(arg, L)) return 1; |
358 | |
359 | if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1; |
360 | if (!DDF::AddLabel(L.Data(), arg[4], EL)) return 1; |
361 | if (!DDF::AddLabel(L.Data(), arg[5], FL)) return 1; |
362 | aDist1 = atoi(arg[6]); |
363 | aDist2 = atoi(arg[7]); |
364 | |
365 | Handle(TNaming_NamedShape) BasisNS, EdgeNS, FaceNS; |
366 | if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1; |
367 | if (!EL.FindAttribute(TNaming_NamedShape::GetID(), EdgeNS)) return 1; |
368 | if (!FL.FindAttribute(TNaming_NamedShape::GetID(), FaceNS)) return 1; |
369 | const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS); |
370 | const TopoDS_Shape& Edge = TNaming_Tool::CurrentShape(EdgeNS); |
371 | const TopoDS_Shape& Face = TNaming_Tool::CurrentShape(FaceNS); |
372 | |
373 | BRepFilletAPI_MakeChamfer aChamfer(Basis); |
374 | TopExp_Explorer anExp(Edge,TopAbs_EDGE); |
375 | if (anExp.More()) { |
376 | for(;anExp.More();anExp.Next()) { |
377 | aChamfer.Add(aDist1,aDist2,TopoDS::Edge(anExp.Current()),TopoDS::Face(Face)); |
378 | } |
379 | } else {aChamfer.Add(aDist1,aDist2,TopoDS::Edge(Edge),TopoDS::Face(Face));} |
380 | aChamfer.Build(); |
381 | if (!aChamfer.IsDone()) return 1; |
382 | QANewBRepNaming_Chamfer aNaming(L); |
383 | aNaming.Load(Basis, aChamfer); |
384 | return 0; |
385 | } |
386 | |
387 | //============================================================== |
388 | //function : QANewDBRepNaming_NameImportShape |
389 | //purpose : NameImportShape Doc Label DrawShape |
390 | //============================================================== |
391 | |
392 | static Standard_Integer QANewDBRepNaming_NameImportShape (Draw_Interpretor& di, |
393 | Standard_Integer nb, |
394 | const char ** arg) |
395 | { |
396 | if (nb != 4) { |
397 | di << "QANewDBRepNaming_NameImportShape : Error" << "\n"; |
398 | return 1; |
399 | } |
400 | |
401 | Handle(TDF_Data) D; |
402 | if (!DDF::GetDF(arg[1],D)) return 1; |
403 | TDF_Label L; |
404 | if (!DDF::AddLabel(D, arg[2], L)) return 1; |
405 | |
406 | const TopoDS_Shape& S = DBRep::Get(arg[3]); |
407 | |
408 | QANewBRepNaming_ImportShape nameIS(L); |
409 | nameIS.Load(S); |
410 | |
411 | return 0; |
412 | } |
413 | |
414 | |
415 | //======================================================================= |
416 | //function : PrimitiveCommands |
417 | //purpose : |
418 | //======================================================================= |
419 | |
420 | void QANewDBRepNaming::PrimitiveCommands (Draw_Interpretor& theCommands) |
421 | { |
422 | static Standard_Boolean done = Standard_False; |
423 | if (done) return; |
424 | done = Standard_True; |
425 | const char* g = "Naming algorithm commands for primitives" ; |
426 | |
427 | |
428 | theCommands.Add ("NameBox", |
429 | "NameBox Doc Label dx dy dz", |
430 | __FILE__, QANewDBRepNaming_NameBox, g); |
431 | |
432 | theCommands.Add ("NameCylinder", |
433 | "NameCylinder Doc Label R H Angle [ShapeType(Shell/Solid)]", |
434 | __FILE__, QANewDBRepNaming_NameCylinder, g); |
435 | |
436 | theCommands.Add ("NameSphere", |
437 | "NameSphere Doc Label R X Y Z Angle1 Angle2 Angle3 [ShapeType(Shell/Solid)]", |
438 | __FILE__, QANewDBRepNaming_NameSphere, g); |
439 | |
440 | theCommands.Add ("NamePrism", |
441 | "NamePrism Doc Label BasisLabel H Direction(X Y Z) Inf(1/0, by feafault = 0)", |
442 | __FILE__, QANewDBRepNaming_NamePrism, g); |
443 | |
444 | theCommands.Add ("NameRevol", |
445 | "NameRevol Doc Label BasisLabel AxisLabel Angle", |
446 | __FILE__, QANewDBRepNaming_NameRevol, g); |
447 | |
448 | theCommands.Add ("NameFillet", |
449 | "NameFillet Doc Label SourceShapeLabel PathLabel Radius", |
450 | __FILE__, QANewDBRepNaming_NameFillet, g); |
451 | |
452 | theCommands.Add ("NameChamfer", |
453 | "NameChamfer Doc Label SourceShapeLabel EdgeLabel FaceLabel Distance1 Distance2", |
454 | __FILE__, QANewDBRepNaming_NameChamfer, g); |
455 | |
456 | theCommands.Add ("NameImportShape", |
457 | "NameImportShape Doc Label DrawShape", |
458 | __FILE__, QANewDBRepNaming_NameImportShape, g); |
459 | |
460 | } |