1 // Created on: 1999-12-23
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <BRepFilletAPI_MakeChamfer.hxx>
21 #include <BRepFilletAPI_MakeFillet.hxx>
22 #include <BRepPrimAPI_MakeBox.hxx>
23 #include <BRepPrimAPI_MakeCylinder.hxx>
24 #include <BRepPrimAPI_MakePrism.hxx>
25 #include <BRepPrimAPI_MakeRevol.hxx>
26 #include <BRepPrimAPI_MakeSphere.hxx>
30 #include <Draw_Interpretor.hxx>
32 #include <QADNaming.hxx>
33 #include <QANewBRepNaming_Box.hxx>
34 #include <QANewBRepNaming_Chamfer.hxx>
35 #include <QANewBRepNaming_Cylinder.hxx>
36 #include <QANewBRepNaming_Fillet.hxx>
37 #include <QANewBRepNaming_ImportShape.hxx>
38 #include <QANewBRepNaming_Prism.hxx>
39 #include <QANewBRepNaming_Revol.hxx>
40 #include <QANewBRepNaming_Sphere.hxx>
41 #include <QANewDBRepNaming.hxx>
42 #include <TDataXtd_Geometry.hxx>
43 #include <TNaming_Builder.hxx>
44 #include <TNaming_NamedShape.hxx>
45 #include <TNaming_Tool.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <TopoDS_Wire.hxx>
54 //=======================================================================
55 //function : QANewDBRepNaming_NameBox
56 //purpose : NameCylinder Doc Label dx dy dz
57 //=======================================================================
58 static Standard_Integer QANewDBRepNaming_NameBox (Draw_Interpretor& di,
64 if (!QADNaming::Entry(arg, L)) return 1;
66 BRepPrimAPI_MakeBox mkBox(Draw::Atof(arg[3]), Draw::Atof(arg[4]), Draw::Atof(arg[5]));
70 di << "The box hasn't been built" << "\n";
74 QANewBRepNaming_Box nameBox(L);
75 nameBox.Load(mkBox,QANewBRepNaming_SOLID);
78 di << "QANewDBRepNaming_NameBox : Error" << "\n";
82 //=======================================================================
83 //function : QANewDBRepNaming_NameCylinder
84 //purpose : NameCylinder Doc Label R H Angle [ShapeType(Shell/Solid)]
85 //=======================================================================
87 static Standard_Integer QANewDBRepNaming_NameCylinder (Draw_Interpretor& di,
91 if(nb == 6 || nb == 7) {
93 if (!QADNaming::Entry(arg, L)) return 1;
95 BRepPrimAPI_MakeCylinder mkCylinder(Draw::Atof(arg[3]), Draw::Atof(arg[4]));
96 if (Draw::Atof(arg[5]) != 0.) {
97 // for Mandrake-10 - mkv,02.06.06 - mkCylinder = BRepPrimAPI_MakeCylinder(Draw::Atof(arg[3]), Draw::Atof(arg[4]), Draw::Atof(arg[5]));
98 BRepPrimAPI_MakeCylinder MakeCylinder(Draw::Atof(arg[3]), Draw::Atof(arg[4]), Draw::Atof(arg[5]));
99 mkCylinder = MakeCylinder;
103 if(!mkCylinder.IsDone()) {
104 di << "The cylinder hasn't been built" << "\n";
108 QANewBRepNaming_Cylinder nameCylinder(L);
109 if (nb == 6) nameCylinder.Load(mkCylinder, QANewBRepNaming_SHELL);
110 else if (Draw::Atoi(arg[6]) == 0) nameCylinder.Load(mkCylinder, QANewBRepNaming_SHELL);
111 else nameCylinder.Load(mkCylinder, QANewBRepNaming_SOLID);
115 di << "QANewDBRepNaming_NameCylinder : Error" << "\n";
120 //=======================================================================
121 //function : QANewDBRepNaming_NameSphere
122 //purpose : NameSphere Doc Label R X Y Z Angle1 Angle2 Angle3 [ShapeType(Shell/Solid)]
123 //=======================================================================
125 static Standard_Integer QANewDBRepNaming_NameSphere (Draw_Interpretor& di,
130 if (!QADNaming::Entry(arg, L)) return 1;
131 Standard_Real R = Draw::Atof(arg[3]);
132 Standard_Real X = Draw::Atof(arg[4]);
133 Standard_Real Y = Draw::Atof(arg[5]);
134 Standard_Real Z = Draw::Atof(arg[6]);
135 Standard_Real DX = Draw::Atof(arg[7]);
136 Standard_Real DY = Draw::Atof(arg[8]);
137 Standard_Real DZ = Draw::Atof(arg[9]);
138 QANewBRepNaming_TypeOfPrimitive3D type = QANewBRepNaming_SHELL;
139 if (nb == 11) type = (QANewBRepNaming_TypeOfPrimitive3D) Draw::Atoi(arg[10]);
141 QANewBRepNaming_Sphere nameSphere(L);
142 BRepPrimAPI_MakeSphere mkSphere(R);
143 if (DX == 0 && DY == 0 && DZ == 0) {
144 // for Mandrake-10 - mkv,02.06.06 - mkSphere = BRepPrimAPI_MakeSphere(gp_Pnt(X, Y, Z), R);
145 BRepPrimAPI_MakeSphere MakeSphere1(gp_Pnt(X, Y, Z), R);
146 mkSphere = MakeSphere1;
148 // for Mandrake-10 - mkv,02.06.06 - mkSphere = BRepPrimAPI_MakeSphere(gp_Pnt(X, Y, Z), R, DX, DY, DZ);
149 BRepPrimAPI_MakeSphere MakeSphere2(gp_Pnt(X, Y, Z), R, DX, DY, DZ);
150 mkSphere = MakeSphere2;
153 if(!mkSphere.IsDone()) {
154 di << "The sphere hasn't been built" << "\n";
157 nameSphere.Load(mkSphere, type);
161 //===========================================================================
162 //function : QANewDBRepNaming_NamePrism
163 //purpose : NamePrism Doc Label BasisLabel H Direction(X Y Z) [Inf/Semi-Inf]
164 //===========================================================================
166 static Standard_Integer QANewDBRepNaming_NamePrism (Draw_Interpretor& di,
170 if (nb < 5 || nb > 9 || nb == 6 || nb == 7) {
171 di << "QANewDBRepNaming_NamePrism : Error" << "\n";
176 if (!QADNaming::Entry(arg, L)) return 1;
177 if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1;
179 Standard_Real H = Draw::Atof(arg[4]);
181 Handle(TNaming_NamedShape) BasisNS;
182 if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1;
183 const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS);
185 QANewBRepNaming_Prism namePrism(L);
188 gp_Dir Direction(Draw::Atof(arg[5]), Draw::Atof(arg[6]), Draw::Atof(arg[7]));
189 gp_Vec Vector(Direction);
194 BRepPrimAPI_MakePrism mkPrism(Basis, Vector);
197 if(!mkPrism.IsDone()) {
198 di << "The prism hasn't been built" << "\n";
202 namePrism.Load(mkPrism, Basis);
205 BRepPrimAPI_MakePrism mkPrism(Basis, Direction, Draw::Atoi(arg[8]) != 0);
208 if(!mkPrism.IsDone()) {
209 di << "The prism hasn't been built" << "\n";
213 namePrism.Load(mkPrism, Basis);
220 //===========================================================================
221 //function : QANewDBRepNaming_NameRevol
222 //purpose : NameRevol Doc Label BasisLabel AxisLabel Angle
223 //===========================================================================
225 static Standard_Integer QANewDBRepNaming_NameRevol (Draw_Interpretor& di,
229 if (nb < 5 || nb > 6) {
230 di << "QANewDBRepNaming_NameRevol : Error" << "\n";
235 if (!QADNaming::Entry(arg, L)) return 1;
237 if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1;
238 if (!DDF::AddLabel(L.Data(), arg[4], AL)) return 1;
240 Handle(TNaming_NamedShape) BasisNS, AxisNS;
241 if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1;
242 if (!AL.FindAttribute(TNaming_NamedShape::GetID(), AxisNS)) return 1;
243 const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS);
244 const TopoDS_Shape& Axis = TNaming_Tool::CurrentShape(AxisNS);
246 if (Axis.ShapeType() != TopAbs_EDGE) return 1;
249 TopoDS_Vertex fV = TopExp::FirstVertex(TopoDS::Edge(Axis), Standard_True);
250 TopoDS_Vertex lV = TopExp::LastVertex(TopoDS::Edge(Axis), Standard_True);
251 if (!fV.IsNull() || !lV.IsNull()) {
252 gp_Vec alocalV(BRep_Tool::Pnt(fV),BRep_Tool::Pnt(lV));
253 gp_Dir Direction(alocalV);
254 // gp_Dir Direction(gp_Vec(BRep_Tool::Pnt(fV), BRep_Tool::Pnt(lV)));
255 axis.SetLocation(BRep_Tool::Pnt(fV));
256 axis.SetDirection(Direction);
259 TDataXtd_Geometry::Axis(AL, axis);
262 QANewBRepNaming_Revol nameRevol(L);
266 BRepPrimAPI_MakeRevol mkRevol(Basis, axis);
269 if(!mkRevol.IsDone()) {
270 di << "The revol hasn't been built" << "\n";
274 nameRevol.Load(mkRevol, Basis);
278 Standard_Real Angle = Draw::Atof(arg[5]);
280 BRepPrimAPI_MakeRevol mkRevol(Basis, axis, Angle);
283 if(!mkRevol.IsDone()) {
284 di << "The revol hasn't been built" << "\n";
288 nameRevol.Load(mkRevol, Basis);
295 //===========================================================================
296 //function : QANewDBRepNaming_NameFillet
297 //purpose : NameFillet Doc Label SourceShapeLabel PathLabel Radius
298 //===========================================================================
300 static Standard_Integer QANewDBRepNaming_NameFillet (Draw_Interpretor& di,
305 di << "QANewDBRepNaming_NameFillet : Error" << "\n";
310 if (!QADNaming::Entry(arg, L)) return 1;
312 if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1;
313 if (!DDF::AddLabel(L.Data(), arg[4], PL)) return 1;
314 Standard_Real aRadius = Draw::Atoi(arg[5]);
315 Handle(TNaming_NamedShape) BasisNS, PathNS;
316 if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1;
317 if (!PL.FindAttribute(TNaming_NamedShape::GetID(), PathNS)) return 1;
318 const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS);
319 const TopoDS_Shape& Path = TNaming_Tool::CurrentShape(PathNS);
321 BRepFilletAPI_MakeFillet aFillet(Basis);
322 TopExp_Explorer anExp(Path,TopAbs_EDGE);
324 for(;anExp.More();anExp.Next()) {
325 aFillet.Add(aRadius,TopoDS::Edge(anExp.Current()));
327 } else aFillet.Add(aRadius,TopoDS::Edge(Path));
329 if (!aFillet.IsDone()) return 1;
330 QANewBRepNaming_Fillet aNaming(L);
331 aNaming.Load(Basis, aFillet);
335 //===========================================================================
336 //function : QANewDBRepNaming_NameChamfer
337 //purpose : NameChamfer Doc Label SourceShapeLabel EdgeLabel FaceLabel Distance1 Distance2
338 //===========================================================================
340 static Standard_Integer QANewDBRepNaming_NameChamfer (Draw_Interpretor& di,
345 di << "QANewDBRepNaming_NameChamfer : Error" << "\n";
349 TDF_Label L, BL, EL, FL;
350 Standard_Real aDist1, aDist2;
352 if (!QADNaming::Entry(arg, L)) return 1;
354 if (!DDF::AddLabel(L.Data(), arg[3], BL)) return 1;
355 if (!DDF::AddLabel(L.Data(), arg[4], EL)) return 1;
356 if (!DDF::AddLabel(L.Data(), arg[5], FL)) return 1;
357 aDist1 = Draw::Atoi(arg[6]);
358 aDist2 = Draw::Atoi(arg[7]);
360 Handle(TNaming_NamedShape) BasisNS, EdgeNS, FaceNS;
361 if (!BL.FindAttribute(TNaming_NamedShape::GetID(), BasisNS)) return 1;
362 if (!EL.FindAttribute(TNaming_NamedShape::GetID(), EdgeNS)) return 1;
363 if (!FL.FindAttribute(TNaming_NamedShape::GetID(), FaceNS)) return 1;
364 const TopoDS_Shape& Basis = TNaming_Tool::CurrentShape(BasisNS);
365 const TopoDS_Shape& Edge = TNaming_Tool::CurrentShape(EdgeNS);
366 const TopoDS_Shape& Face = TNaming_Tool::CurrentShape(FaceNS);
368 BRepFilletAPI_MakeChamfer aChamfer(Basis);
369 TopExp_Explorer anExp(Edge,TopAbs_EDGE);
371 for(;anExp.More();anExp.Next()) {
372 aChamfer.Add(aDist1,aDist2,TopoDS::Edge(anExp.Current()),TopoDS::Face(Face));
374 } else {aChamfer.Add(aDist1,aDist2,TopoDS::Edge(Edge),TopoDS::Face(Face));}
376 if (!aChamfer.IsDone()) return 1;
377 QANewBRepNaming_Chamfer aNaming(L);
378 aNaming.Load(Basis, aChamfer);
382 //==============================================================
383 //function : QANewDBRepNaming_NameImportShape
384 //purpose : NameImportShape Doc Label DrawShape
385 //==============================================================
387 static Standard_Integer QANewDBRepNaming_NameImportShape (Draw_Interpretor& di,
392 di << "QANewDBRepNaming_NameImportShape : Error" << "\n";
397 if (!DDF::GetDF(arg[1],D)) return 1;
399 if (!DDF::AddLabel(D, arg[2], L)) return 1;
401 const TopoDS_Shape& S = DBRep::Get(arg[3]);
403 QANewBRepNaming_ImportShape nameIS(L);
410 //=======================================================================
411 //function : PrimitiveCommands
413 //=======================================================================
415 void QANewDBRepNaming::PrimitiveCommands (Draw_Interpretor& theCommands)
417 static Standard_Boolean done = Standard_False;
419 done = Standard_True;
420 const char* g = "Naming algorithm commands for primitives" ;
423 theCommands.Add ("NameBox",
424 "NameBox Doc Label dx dy dz",
425 __FILE__, QANewDBRepNaming_NameBox, g);
427 theCommands.Add ("NameCylinder",
428 "NameCylinder Doc Label R H Angle [ShapeType(Shell/Solid)]",
429 __FILE__, QANewDBRepNaming_NameCylinder, g);
431 theCommands.Add ("NameSphere",
432 "NameSphere Doc Label R X Y Z Angle1 Angle2 Angle3 [ShapeType(Shell/Solid)]",
433 __FILE__, QANewDBRepNaming_NameSphere, g);
435 theCommands.Add ("NamePrism",
436 "NamePrism Doc Label BasisLabel H Direction(X Y Z) Inf(1/0, by feafault = 0)",
437 __FILE__, QANewDBRepNaming_NamePrism, g);
439 theCommands.Add ("NameRevol",
440 "NameRevol Doc Label BasisLabel AxisLabel Angle",
441 __FILE__, QANewDBRepNaming_NameRevol, g);
443 theCommands.Add ("NameFillet",
444 "NameFillet Doc Label SourceShapeLabel PathLabel Radius",
445 __FILE__, QANewDBRepNaming_NameFillet, g);
447 theCommands.Add ("NameChamfer",
448 "NameChamfer Doc Label SourceShapeLabel EdgeLabel FaceLabel Distance1 Distance2",
449 __FILE__, QANewDBRepNaming_NameChamfer, g);
451 theCommands.Add ("NameImportShape",
452 "NameImportShape Doc Label DrawShape",
453 __FILE__, QANewDBRepNaming_NameImportShape, g);