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