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