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