b311480e |
1 | // Created on: 1993-07-22 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-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 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public 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. |
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 <BRepTest.hxx> |
18 | #include <DBRep.hxx> |
19 | #include <Draw_Interpretor.hxx> |
20 | #include <Draw_Appli.hxx> |
21 | |
22 | #include <BRepFill.hxx> |
23 | #include <BRepBuilderAPI_PipeError.hxx> |
24 | #include <BRepFill_Generator.hxx> |
25 | #include <BRepPrimAPI_MakePrism.hxx> |
26 | #include <BRepPrimAPI_MakeRevol.hxx> |
27 | #include <BRepOffsetAPI_MakePipe.hxx> |
28 | #include <BRepOffsetAPI_MakeEvolved.hxx> |
29 | #include <BRepOffsetAPI_ThruSections.hxx> |
30 | #include <BRepOffsetAPI_MakePipeShell.hxx> |
2277323d |
31 | #include <BRepOffsetAPI_MiddlePath.hxx> |
7fd59977 |
32 | |
33 | #include <BRepLib_MakeWire.hxx> |
34 | #include <TopoDS.hxx> |
35 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
36 | #include <TopExp_Explorer.hxx> |
37 | |
38 | #include <Precision.hxx> |
39 | #include <Law_Interpol.hxx> |
40 | #include <gp_Ax1.hxx> |
41 | #include <gp_Ax2.hxx> |
42 | #include <gp_Pnt2d.hxx> |
43 | #include <TColgp_Array1OfPnt2d.hxx> |
44 | |
45 | static BRepOffsetAPI_MakePipeShell* Sweep= 0; |
46 | |
47 | //#ifdef WNT |
48 | #include <stdio.h> |
49 | #include <Geom_Curve.hxx> |
50 | #include <GeomAdaptor_HCurve.hxx> |
51 | #include <GeomFill_Pipe.hxx> |
52 | #include <Geom_Surface.hxx> |
53 | #include <BRepBuilderAPI_MakeFace.hxx> |
54 | #include <BRep_Tool.hxx> |
55 | #include <gp_Pnt.hxx> |
56 | //#endi#include <gp_Vec.hxx> |
57 | #include <gp_Vec.hxx> |
58 | #include <Geom_Circle.hxx> |
59 | #include <gp_Ax2.hxx> |
60 | |
f9032cf2 |
61 | |
7fd59977 |
62 | //======================================================================= |
63 | // prism |
64 | //======================================================================= |
65 | |
66 | static Standard_Integer prism(Draw_Interpretor& , Standard_Integer n, const char** a) |
67 | { |
68 | if (n < 6) return 1; |
69 | |
70 | TopoDS_Shape base = DBRep::Get(a[2]); |
71 | if (base.IsNull()) return 1; |
72 | |
91322f44 |
73 | gp_Vec V(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5])); |
7fd59977 |
74 | |
75 | Standard_Boolean copy = Standard_False; |
76 | Standard_Boolean inf = Standard_False; |
77 | Standard_Boolean sinf = Standard_False; |
78 | |
79 | if (n > 6) { |
80 | copy = (*a[6] == 'c') || (*a[6] == 'C'); |
81 | inf = (*a[6] == 'i') || (*a[6] == 'I'); |
82 | sinf = (*a[6] == 's') || (*a[6] == 'S'); |
83 | } |
84 | |
85 | TopoDS_Shape res; |
86 | |
87 | if (inf || sinf) |
88 | res = BRepPrimAPI_MakePrism(base,gp_Dir(V),inf); |
89 | else |
90 | res = BRepPrimAPI_MakePrism(base,V,copy); |
91 | |
92 | DBRep::Set(a[1],res); |
93 | |
94 | return 0; |
95 | } |
96 | |
97 | |
98 | //======================================================================= |
99 | // revol |
100 | //======================================================================= |
101 | |
102 | static Standard_Integer revol(Draw_Interpretor& , |
103 | Standard_Integer n, const char** a) |
104 | { |
105 | if (n < 10) return 1; |
106 | |
107 | TopoDS_Shape base = DBRep::Get(a[2]); |
108 | if (base.IsNull()) return 1; |
109 | |
91322f44 |
110 | gp_Pnt P(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5])); |
111 | gp_Dir D(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8])); |
7fd59977 |
112 | gp_Ax1 A(P,D); |
113 | |
91322f44 |
114 | Standard_Real angle = Draw::Atof(a[9]) * (M_PI / 180.0); |
7fd59977 |
115 | |
116 | Standard_Boolean copy = n > 10; |
117 | |
118 | TopoDS_Shape res = BRepPrimAPI_MakeRevol(base,A,angle,copy); |
119 | |
120 | DBRep::Set(a[1],res); |
121 | |
122 | return 0; |
123 | } |
124 | |
125 | |
126 | //======================================================================= |
127 | // pipe |
128 | //======================================================================= |
129 | |
471ce736 |
130 | static Standard_Integer pipe(Draw_Interpretor& di, |
7fd59977 |
131 | Standard_Integer n, const char** a) |
132 | { |
471ce736 |
133 | if (n == 1) |
134 | { |
135 | di << "pipe result Wire_spine Profile [Mode [Approx]]" << "\n"; |
136 | di << "Mode = 0 - CorrectedFrenet," << "\n"; |
137 | di << " = 1 - Frenet," << "\n"; |
138 | di << " = 2 - DiscreteTrihedron" << "\n"; |
139 | di << "Approx - force C1-approximation if result is C0" << "\n"; |
140 | return 0; |
141 | } |
142 | |
143 | if (n > 1 && n < 4) return 1; |
7fd59977 |
144 | |
145 | TopoDS_Shape Spine = DBRep::Get(a[2],TopAbs_WIRE); |
146 | if ( Spine.IsNull()) return 1; |
147 | |
148 | TopoDS_Shape Profile = DBRep::Get(a[3]); |
149 | if ( Profile.IsNull()) return 1; |
471ce736 |
150 | |
151 | GeomFill_Trihedron Mode = GeomFill_IsCorrectedFrenet; |
152 | if (n >= 5) |
153 | { |
154 | Standard_Integer iMode = atoi(a[4]); |
155 | if (iMode == 1) |
156 | Mode = GeomFill_IsFrenet; |
157 | else if (iMode == 2) |
158 | Mode = GeomFill_IsDiscreteTrihedron; |
159 | } |
160 | |
161 | Standard_Boolean ForceApproxC1 = Standard_False; |
162 | if (n >= 6) |
163 | ForceApproxC1 = Standard_True; |
7fd59977 |
164 | |
471ce736 |
165 | TopoDS_Shape S = BRepOffsetAPI_MakePipe(TopoDS::Wire(Spine), |
166 | Profile, |
167 | Mode, |
168 | ForceApproxC1); |
7fd59977 |
169 | |
170 | DBRep::Set(a[1],S); |
171 | |
172 | return 0; |
173 | } |
471ce736 |
174 | |
7fd59977 |
175 | //======================================================================= |
176 | |
177 | static Standard_Integer geompipe(Draw_Interpretor& , |
178 | Standard_Integer n, const char** a) |
179 | { |
180 | TopoDS_Shape Spine = DBRep::Get(a[2],TopAbs_EDGE); |
181 | if ( Spine.IsNull()) return 1; |
182 | if ( n < 5) return 1; |
183 | TopoDS_Shape Profile = DBRep::Get(a[3],TopAbs_EDGE); |
184 | if ( Profile.IsNull()) return 1; |
185 | Standard_Real aSpFirst,aSpLast,aPrFirst,aPrLast; |
186 | Handle(Geom_Curve) SpineCurve = BRep_Tool::Curve(TopoDS::Edge(Spine),aSpFirst,aSpLast); |
187 | Handle(Geom_Curve) ProfileCurve = BRep_Tool::Curve(TopoDS::Edge(Profile),aPrFirst,aPrLast); |
188 | Handle(GeomAdaptor_HCurve) aAdaptCurve = new GeomAdaptor_HCurve(SpineCurve,aSpFirst,aSpLast); |
189 | Standard_Boolean ByACR = Standard_False; |
190 | Standard_Boolean rotate = Standard_False; |
91322f44 |
191 | Standard_Real Radius = Draw::Atof(a[4]); |
7fd59977 |
192 | gp_Pnt ctr; |
193 | gp_Vec norm; |
194 | ProfileCurve->D1(aSpFirst,ctr,norm); |
195 | gp_Vec xAxisStart(ctr,SpineCurve->Value(aSpFirst)); |
196 | gp_Ax2 aAx2Start(ctr,norm,xAxisStart); |
197 | Handle(Geom_Circle) cStart=new Geom_Circle(aAx2Start,Radius); |
198 | Standard_Integer k =5; |
199 | if(n > k) |
91322f44 |
200 | ByACR = (Draw::Atoi(a[k++]) ==1); |
7fd59977 |
201 | if(n > k) |
91322f44 |
202 | rotate = (Draw::Atoi(a[k++])==1); |
7fd59977 |
203 | GeomFill_Pipe aPipe(ProfileCurve,aAdaptCurve,cStart,ByACR,rotate); |
204 | aPipe.Perform(Standard_True); |
205 | Handle(Geom_Surface) Sur=aPipe.Surface(); |
206 | TopoDS_Face F; |
207 | if(!Sur.IsNull()) |
1c72dff6 |
208 | F = BRepBuilderAPI_MakeFace(Sur, Precision::Confusion()); |
7fd59977 |
209 | DBRep::Set(a[1],F); |
210 | return 0; |
211 | } |
212 | |
213 | //======================================================================= |
214 | //function : evolved |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | Standard_Integer evolved(Draw_Interpretor& di, Standard_Integer n, const char** a) |
219 | { |
220 | if ( n == 1) { |
221 | //cout << " 1) evolved result base profil : "<< endl; |
222 | //cout << " The relative position of the profil on the base" << endl; |
223 | //cout << " is given in the referencial axis. " << endl; |
224 | //cout << " 2) evolved result base profil o : "<< endl; |
225 | //cout << " This position is automatically computed." << endl; |
226 | di << " 1) evolved result base profil : "<< "\n"; |
227 | di << " The relative position of the profil on the base" << "\n"; |
228 | di << " is given in the referencial axis. " << "\n"; |
229 | di << " 2) evolved result base profil o : "<< "\n"; |
230 | di << " This position is automatically computed." << "\n"; |
231 | return 0; |
232 | } |
233 | |
234 | if ( n < 4 ) return 1; |
235 | Standard_Boolean IsAFace = Standard_False; |
236 | Standard_Boolean Solid = (!strcmp(a[0],"evolvedsolid")); |
237 | |
238 | |
239 | |
240 | TopoDS_Shape Base = DBRep::Get(a[2],TopAbs_WIRE,Standard_False); |
241 | if ( Base.IsNull()) { |
242 | Base = DBRep::Get(a[2],TopAbs_FACE,Standard_False); |
243 | IsAFace = Standard_True; |
244 | } |
245 | if ( Base.IsNull()) return 1; |
246 | |
247 | TopoDS_Shape InpuTShape(DBRep::Get(a[3],TopAbs_WIRE,Standard_False)); |
248 | TopoDS_Wire Prof = TopoDS::Wire(InpuTShape); |
249 | // TopoDS_Wire Prof = |
250 | // TopoDS::Wire(DBRep::Get(a[3],TopAbs_WIRE,Standard_False)); |
251 | if ( Prof.IsNull()) return 1; |
252 | |
253 | if (IsAFace) { |
254 | TopoDS_Shape Volevo |
255 | = BRepOffsetAPI_MakeEvolved(TopoDS::Face(Base),Prof,GeomAbs_Arc,n == 4,Solid); |
256 | DBRep::Set(a[1],Volevo); |
257 | } |
258 | else { |
259 | TopoDS_Shape Volevo |
260 | = BRepOffsetAPI_MakeEvolved(TopoDS::Wire(Base),Prof,GeomAbs_Arc,n == 4,Solid); |
261 | DBRep::Set(a[1],Volevo); |
262 | } |
263 | |
264 | return 0; |
265 | } |
266 | |
267 | |
268 | //======================================================================= |
269 | //function : pruled |
270 | //purpose : |
271 | //======================================================================= |
272 | |
273 | static Standard_Integer pruled(Draw_Interpretor& , |
274 | Standard_Integer n, const char** a) |
275 | { |
276 | if ( n != 4) return 1; |
277 | |
278 | Standard_Boolean YaWIRE = Standard_False; |
279 | TopoDS_Shape S1 = DBRep::Get(a[2],TopAbs_EDGE); |
280 | if ( S1.IsNull()) { |
281 | S1 = DBRep::Get(a[2],TopAbs_WIRE); |
282 | if (S1.IsNull()) return 1; |
283 | YaWIRE = Standard_True; |
284 | } |
285 | |
286 | TopoDS_Shape S2 = DBRep::Get(a[3],TopAbs_EDGE); |
287 | if ( S2.IsNull()) { |
288 | S2 = DBRep::Get(a[3],TopAbs_WIRE); |
289 | if ( S2.IsNull()) return 1; |
290 | if (!YaWIRE) { |
291 | S1 = BRepLib_MakeWire(TopoDS::Edge(S1)); |
292 | YaWIRE = Standard_True; |
293 | } |
294 | } |
295 | else if ( YaWIRE) { |
296 | S2 = BRepLib_MakeWire(TopoDS::Edge(S2)); |
297 | } |
298 | |
299 | TopoDS_Shape Result; |
300 | if ( YaWIRE) { |
301 | Result = BRepFill::Shell(TopoDS::Wire(S1),TopoDS::Wire(S2)); |
302 | } |
303 | else { |
304 | Result = BRepFill::Face(TopoDS::Edge(S1),TopoDS::Edge(S2)); |
305 | } |
306 | |
307 | DBRep::Set(a[1],Result); |
308 | return 0; |
309 | } |
310 | |
311 | |
312 | //======================================================================= |
313 | //function : gener |
314 | //purpose : Create a surface between generating wires |
315 | //======================================================================= |
316 | |
317 | Standard_Integer gener(Draw_Interpretor&, Standard_Integer n, const char** a) |
318 | { |
319 | if ( n < 4) return 1; |
320 | |
321 | TopoDS_Shape Shape; |
322 | |
323 | BRepFill_Generator Generator; |
324 | |
325 | for ( Standard_Integer i = 2; i<= n-1 ; i++) { |
326 | Shape = DBRep::Get(a[i],TopAbs_WIRE); |
327 | if ( Shape.IsNull()) |
328 | return 1; |
329 | |
330 | Generator.AddWire(TopoDS::Wire(Shape)); |
331 | } |
332 | |
333 | Generator.Perform(); |
334 | |
335 | TopoDS_Shell Shell = Generator.Shell(); |
336 | |
337 | DBRep::Set(a[1], Shell); |
338 | |
339 | |
340 | return 0; |
341 | } |
342 | |
343 | |
344 | //======================================================================= |
345 | //function : thrusections |
346 | //purpose : |
347 | //======================================================================= |
348 | |
349 | Standard_Integer thrusections(Draw_Interpretor&, Standard_Integer n, const char** a) |
350 | { |
351 | if (n<6) return 1; |
352 | |
353 | Standard_Boolean check = Standard_True; |
354 | Standard_Boolean samenumber = Standard_True; |
355 | Standard_Integer index = 2; |
356 | // Lecture option |
357 | if (!strcmp(a[1],"-N")) { |
358 | if (n<7) return 1; |
359 | check = Standard_False; |
360 | index++; |
361 | } |
362 | |
363 | TopoDS_Shape Shape; |
364 | |
91322f44 |
365 | Standard_Boolean issolid = ( Draw::Atoi(a[index]) == 1 ); |
366 | Standard_Boolean isruled = ( Draw::Atoi(a[index+1]) == 1 ); |
7fd59977 |
367 | |
368 | BRepOffsetAPI_ThruSections Generator(issolid,isruled); |
369 | |
370 | Standard_Integer NbEdges = 0; |
371 | Standard_Boolean IsFirstWire = Standard_False; |
372 | for ( Standard_Integer i = index+2; i<= n-1 ; i++) { |
373 | Standard_Boolean IsWire = Standard_True; |
374 | Shape = DBRep::Get(a[i], TopAbs_WIRE); |
375 | if (!Shape.IsNull()) |
376 | { |
377 | Generator.AddWire(TopoDS::Wire(Shape)); |
378 | if (!IsFirstWire) |
379 | IsFirstWire = Standard_True; |
380 | else |
381 | IsFirstWire = Standard_False; |
382 | } |
383 | else |
384 | { |
385 | Shape = DBRep::Get(a[i], TopAbs_VERTEX); |
386 | IsWire = Standard_False; |
387 | if (!Shape.IsNull()) |
388 | Generator.AddVertex(TopoDS::Vertex(Shape)); |
389 | else |
390 | return 1; |
391 | } |
392 | |
393 | Standard_Integer cpt = 0; |
394 | TopExp_Explorer PE; |
395 | for (PE.Init(Shape, TopAbs_EDGE); PE.More(); PE.Next()) { |
396 | cpt++; |
397 | } |
398 | if (IsFirstWire) |
399 | NbEdges = cpt; |
400 | else |
401 | if (IsWire && cpt != NbEdges) |
402 | samenumber = Standard_False; |
403 | |
404 | } |
405 | |
406 | check = (check || !samenumber); |
407 | Generator.CheckCompatibility(check); |
408 | |
409 | Generator.Build(); |
410 | |
411 | TopoDS_Shape Shell = Generator.Shape(); |
412 | |
413 | DBRep::Set(a[index-1], Shell); |
414 | |
415 | return 0; |
416 | } |
417 | |
418 | //======================================================================= |
419 | // mksweep |
420 | //======================================================================= |
421 | static Standard_Integer mksweep(Draw_Interpretor& , |
422 | Standard_Integer n, const char** a) |
423 | { |
424 | if ( n != 2) return 1; |
425 | TopoDS_Shape Spine = DBRep::Get(a[1],TopAbs_WIRE); |
426 | if ( Spine.IsNull()) return 1; |
427 | if (Sweep !=0) { |
428 | delete Sweep; |
429 | Sweep = 0; |
430 | } |
431 | Sweep = new BRepOffsetAPI_MakePipeShell(TopoDS::Wire(Spine)); |
432 | return 0; |
433 | } |
434 | |
435 | //======================================================================= |
436 | // setsweep |
437 | //======================================================================= |
438 | static Standard_Integer setsweep(Draw_Interpretor& di, |
439 | Standard_Integer n, const char** a) |
440 | { |
441 | if ( n == 1) { |
442 | //cout << "setsweep options [arg1 [arg2 [...]]] : options are :" << endl; |
443 | //cout << " -FR : Tangent and Normal are given by Frenet trihedron" <<endl; |
444 | //cout << " -CF : Tangente is given by Frenet," << endl; |
445 | //cout << " the Normal is computed to minimize the torsion " << endl; |
446 | //cout << " -DX Surf : Tangent and Normal are given by Darboux trihedron," |
447 | // <<endl; |
448 | //cout << " Surf have to be a shell or a face" <<endl; |
449 | //cout << " -CN dx dy dz : BiNormal is given by dx dy dz" << endl; |
450 | //cout << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed" <<endl; |
451 | //cout << " -G guide 0|1(ACR|Plan) 0|1(contact|no contact) : with guide"<<endl; |
452 | di << "setsweep options [arg1 [arg2 [...]]] : options are :" << "\n"; |
453 | di << " -FR : Tangent and Normal are given by Frenet trihedron" <<"\n"; |
454 | di << " -CF : Tangente is given by Frenet," << "\n"; |
455 | di << " the Normal is computed to minimize the torsion " << "\n"; |
a31abc03 |
456 | di << " -DT : discrete trihedron" << "\n"; |
7fd59977 |
457 | di << " -DX Surf : Tangent and Normal are given by Darboux trihedron," <<"\n"; |
458 | di << " Surf have to be a shell or a face" <<"\n"; |
459 | di << " -CN dx dy dz : BiNormal is given by dx dy dz" << "\n"; |
460 | di << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed" <<"\n"; |
f9032cf2 |
461 | di << " -G guide 0|1(Plan|ACR) 0|1|2(no contact|contact|contact on border) : with guide"<<"\n"; |
7fd59977 |
462 | return 0; |
463 | } |
464 | |
465 | if (Sweep ==0) { |
466 | //cout << "You have forgotten the <<mksweep>> command !"<< endl; |
467 | di << "You have forgotten the <<mksweep>> command !"<< "\n"; |
468 | return 1; |
469 | } |
470 | if (!strcmp(a[1],"-FR")) { |
471 | Sweep->SetMode(Standard_True); |
472 | } |
473 | else if (!strcmp(a[1],"-CF")) { |
474 | Sweep->SetMode(Standard_False); |
475 | } |
a31abc03 |
476 | else if (!strcmp(a[1],"-DT")) { |
477 | Sweep->SetDiscreteMode(); |
478 | } |
7fd59977 |
479 | else if (!strcmp(a[1],"-DX")) { |
480 | if (n!=3) { |
481 | //cout << "bad arguments !" << endl; |
482 | di << "bad arguments !" << "\n"; |
483 | return 1; |
484 | } |
485 | TopoDS_Shape Surf; |
486 | Surf = DBRep::Get(a[2],TopAbs_SHAPE); |
487 | if (Surf.IsNull()) { |
488 | //cout << a[2] <<"is not a shape !" << endl; |
489 | di << a[2] <<"is not a shape !" << "\n"; |
490 | return 1; |
491 | } |
492 | Sweep->SetMode(Surf); |
493 | } |
494 | else if (!strcmp(a[1],"-CN")) { |
495 | if (n!=5) { |
496 | //cout << "bad arguments !" << endl; |
497 | di << "bad arguments !" << "\n"; |
498 | return 1; |
499 | } |
91322f44 |
500 | gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4])); |
7fd59977 |
501 | Sweep->SetMode(D);; |
502 | } |
503 | else if (!strcmp(a[1],"-FX")) { |
504 | if ((n!=5)&&(n!=8)) { |
505 | //cout << "bad arguments !" << endl; |
506 | di << "bad arguments !" << "\n"; |
507 | return 1; |
508 | } |
91322f44 |
509 | gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4])); |
7fd59977 |
510 | if (n==8) { |
91322f44 |
511 | gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7])); |
7fd59977 |
512 | gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D, DN); |
513 | Sweep->SetMode(Axe); |
514 | } |
515 | else { |
516 | gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D); |
517 | Sweep->SetMode(Axe); |
518 | } |
519 | } |
520 | else if (!strcmp(a[1],"-G")) // contour guide |
521 | { |
522 | if (n != 5) |
523 | { |
524 | //cout << "bad arguments !" << endl; |
525 | di << "bad arguments !" << "\n"; |
526 | return 1; |
527 | } |
528 | else |
529 | { |
530 | TopoDS_Shape Guide = DBRep::Get(a[2],TopAbs_WIRE); |
f9032cf2 |
531 | Standard_Integer CurvilinearEquivalence = Draw::Atoi(a[3]); |
532 | Standard_Integer KeepContact = Draw::Atoi(a[4]); |
533 | Sweep->SetMode(TopoDS::Wire(Guide), |
534 | CurvilinearEquivalence, |
535 | (BRepFill_TypeOfContact)KeepContact); |
7fd59977 |
536 | } |
537 | } |
538 | |
539 | else { |
540 | //cout << "The option "<< a[1] << " is unknown !" << endl; |
541 | di << "The option "<< a[1] << " is unknown !" << "\n"; |
542 | return 1; |
543 | } |
544 | return 0; |
545 | } |
546 | |
547 | |
548 | //======================================================================= |
549 | // addsweep |
550 | //======================================================================= |
551 | static Standard_Integer addsweep(Draw_Interpretor& di, |
552 | Standard_Integer n, const char** a) |
553 | { |
554 | if ( n == 1) { |
555 | //cout << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :" << endl; |
556 | //cout << " -T : the wire/vertex have to be translated to assume contact"<< endl; |
557 | //cout << " with the spine" <<endl; |
558 | //cout << " -R : the wire have to be rotated to assume orthogonality"<<endl; |
559 | //cout << " with the spine's tangent" << endl; |
560 | di << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :" << "\n"; |
561 | di << " -T : the wire/vertex have to be translated to assume contact"<< "\n"; |
562 | di << " with the spine" <<"\n"; |
563 | di << " -R : the wire have to be rotated to assume orthogonality"<<"\n"; |
564 | di << " with the spine's tangent" << "\n"; |
565 | return 0; |
566 | } |
567 | |
568 | if (Sweep ==0) { |
569 | //cout << "You have forgotten the <<mksweep>> command !"<< endl; |
570 | di << "You have forgotten the <<mksweep>> command !"<< "\n"; |
571 | return 1; |
572 | } |
573 | |
574 | TopoDS_Shape Section; |
575 | TopoDS_Vertex Vertex; |
576 | Handle(Law_Interpol) thelaw; |
577 | |
578 | Section = DBRep::Get(a[1], TopAbs_SHAPE); |
579 | if (Section.ShapeType() != TopAbs_WIRE && |
580 | Section.ShapeType() != TopAbs_VERTEX) |
581 | { |
582 | //cout << a[1] <<"is not a wire and is not a vertex!" << endl; |
583 | di << a[1] <<"is not a wire and is not a vertex!" << "\n"; |
584 | return 1; |
585 | } |
586 | |
587 | Standard_Boolean HasVertex=Standard_False, |
588 | isT=Standard_False, |
589 | isR=Standard_False; |
590 | |
591 | if (n > 2) { |
592 | Standard_Integer cur = 2; |
0d969553 |
593 | // Reading of Vertex |
7fd59977 |
594 | TopoDS_Shape InputVertex(DBRep::Get(a[cur],TopAbs_VERTEX)); |
595 | Vertex = TopoDS::Vertex(InputVertex); |
596 | // Vertex = TopoDS::Vertex(DBRep::Get(a[cur],TopAbs_VERTEX)); |
597 | if (!Vertex.IsNull()) { |
598 | cur++; |
599 | HasVertex = Standard_True; |
600 | } |
601 | |
0d969553 |
602 | // Reading of the translation option |
7fd59977 |
603 | if ((n>cur) && !strcmp(a[cur],"-T")) { |
604 | cur++; |
605 | isT = Standard_True; |
606 | } |
607 | |
0d969553 |
608 | // Reading of the rotation option |
7fd59977 |
609 | if ((n>cur) && !strcmp(a[cur],"-R")) { |
610 | cur++; |
611 | isR = Standard_True; |
612 | } |
613 | |
0d969553 |
614 | // law ? |
7fd59977 |
615 | if (n>cur) { |
616 | Standard_Integer nbreal = n-cur; |
617 | if ( (nbreal < 4) || (nbreal % 2 != 0) ) { |
618 | //cout << "bad arguments ! :" <<a[cur] << endl; |
619 | di << "bad arguments ! :" <<a[cur] << "\n"; |
0d969553 |
620 | } else { //law of interpolation |
7fd59977 |
621 | Standard_Integer ii, L= nbreal/2; |
622 | TColgp_Array1OfPnt2d ParAndRad(1, L); |
623 | for (ii=1; ii<=L; ii++, cur+=2) { |
f9032cf2 |
624 | ParAndRad(ii).SetX(Draw::Atof(a[cur])); |
625 | ParAndRad(ii).SetY(Draw::Atof(a[cur+1])); |
626 | } |
7fd59977 |
627 | thelaw = new (Law_Interpol) (); |
628 | thelaw->Set(ParAndRad, |
629 | Abs(ParAndRad(1).Y() - ParAndRad(L).Y()) < Precision::Confusion()); |
630 | } |
631 | } |
632 | } |
633 | |
634 | if (thelaw.IsNull()) { |
635 | if (HasVertex) Sweep->Add(Section, Vertex, isT, isR); |
636 | else Sweep->Add(Section, isT, isR); |
637 | } |
638 | else { |
639 | if (HasVertex) Sweep->SetLaw(Section, thelaw, Vertex, isT, isR); |
640 | else Sweep->SetLaw(Section, thelaw, isT, isR); |
641 | } |
642 | |
643 | return 0; |
644 | } |
645 | |
646 | //======================================================================= |
647 | // deletesweep |
648 | //======================================================================= |
649 | static Standard_Integer deletesweep(Draw_Interpretor& di, |
650 | Standard_Integer n, const char** a) |
651 | { |
652 | if ( n != 2) { |
653 | return 1; |
654 | } |
655 | TopoDS_Wire Section; |
656 | TopoDS_Shape InputShape(DBRep::Get(a[1],TopAbs_SHAPE)); |
657 | Section = TopoDS::Wire(InputShape); |
658 | // Section = TopoDS::Wire(DBRep::Get(a[1],TopAbs_SHAPE)); |
659 | if (Section.IsNull()) { |
660 | //cout << a[1] <<"is not a wire !" << endl; |
661 | di << a[1] <<"is not a wire !" << "\n"; |
662 | return 1; |
663 | } |
664 | |
665 | Sweep->Delete(Section); |
666 | |
667 | return 0; |
668 | } |
669 | |
670 | //======================================================================= |
671 | // buildsweep |
672 | //======================================================================= |
673 | static Standard_Integer buildsweep(Draw_Interpretor& di, |
674 | Standard_Integer n, const char** a) |
675 | { |
676 | if ( n == 1) { |
677 | //cout << "build sweep result [-M/-C/-R] [-S] [tol] : options are" << endl; |
678 | //cout << " -M : Discontinuities are treated by Modfication of"<< endl; |
679 | //cout << " the sweeping mode : it is the default" <<endl; |
680 | //cout << " -C : Discontinuities are treated like Right Corner" << endl; |
681 | //cout << " Treatement is Extent && Intersect" << endl; |
682 | //cout << " -R : Discontinuities are treated like Round Corner" << endl; |
683 | //cout << " Treatement is Intersect and Fill" << endl; |
684 | //cout << " -S : To build a Solid" << endl; |
685 | di << "build sweep result [-M/-C/-R] [-S] [tol] : options are" << "\n"; |
686 | di << " -M : Discontinuities are treated by Modfication of"<< "\n"; |
687 | di << " the sweeping mode : it is the default" <<"\n"; |
688 | di << " -C : Discontinuities are treated like Right Corner" << "\n"; |
689 | di << " Treatement is Extent && Intersect" << "\n"; |
690 | di << " -R : Discontinuities are treated like Round Corner" << "\n"; |
691 | di << " Treatement is Intersect and Fill" << "\n"; |
692 | di << " -S : To build a Solid" << "\n"; |
693 | return 0; |
694 | } |
695 | |
696 | Standard_Boolean mksolid = Standard_False; |
697 | if (Sweep ==0) { |
698 | //cout << "You have forgotten the <<mksweep>> command !"<< endl; |
699 | di << "You have forgotten the <<mksweep>> command !"<< "\n"; |
700 | return 1; |
701 | } |
702 | |
703 | if (!Sweep->IsReady()) { |
704 | //cout << "You have forgotten the <<addsweep>> command !"<< endl; |
705 | di << "You have forgotten the <<addsweep>> command !"<< "\n"; |
706 | return 1; |
707 | } |
708 | |
709 | TopoDS_Shape result; |
710 | Standard_Integer cur=2; |
711 | if (n>cur) { |
712 | BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed; |
713 | |
0d969553 |
714 | // Reading Transition |
7fd59977 |
715 | if (!strcmp(a[cur],"-C")) { |
716 | Transition = BRepBuilderAPI_RightCorner; |
717 | cur++; |
718 | } |
719 | else if (!strcmp(a[cur],"-R")) { |
720 | Transition = BRepBuilderAPI_RoundCorner; |
721 | cur++; |
722 | } |
723 | Sweep->SetTransitionMode(Transition); |
724 | } |
0d969553 |
725 | // Reading solid ? |
7fd59977 |
726 | if ((n>cur) && (!strcmp(a[cur],"-S")) ) mksolid = Standard_True; |
727 | |
728 | // Calcul le resultat |
729 | Sweep->Build(); |
730 | if (!Sweep->IsDone()) { |
731 | //cout << "Buildsweep : Not Done" << endl; |
732 | di << "Buildsweep : Not Done" << "\n"; |
733 | BRepBuilderAPI_PipeError Stat = Sweep->GetStatus(); |
734 | if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) { |
735 | //cout << "Buildsweep : One Plane not intersect the guide" << endl; |
736 | di << "Buildsweep : One Plane not intersect the guide" << "\n"; |
737 | } |
738 | if (Stat == BRepBuilderAPI_ImpossibleContact) { |
739 | //cout << "BuildSweep : One section can not be in contact with the guide" << endl; |
740 | di << "BuildSweep : One section can not be in contact with the guide" << "\n"; |
741 | } |
742 | return 1; |
743 | } |
744 | else { |
745 | if (mksolid) { |
746 | Standard_Boolean B; |
747 | B = Sweep->MakeSolid(); |
748 | //if (!B) cout << " BuildSweep : It is impossible to make a solid !" << endl; |
749 | if (!B) di << " BuildSweep : It is impossible to make a solid !" << "\n"; |
750 | } |
751 | result = Sweep->Shape(); |
752 | DBRep::Set(a[1],result); |
753 | } |
754 | |
755 | return 0; |
756 | } |
757 | |
758 | //======================================================================= |
759 | // simulsweep |
760 | //======================================================================= |
761 | static Standard_Integer simulsweep(Draw_Interpretor& di, |
762 | Standard_Integer n, const char** a) |
763 | { |
764 | if ( (n!=3) && (n!=4) ) return 1; |
765 | |
766 | if (Sweep ==0) { |
767 | //cout << "You have forgotten the <<mksweep>> command !"<< endl; |
768 | di << "You have forgotten the <<mksweep>> command !"<< "\n"; |
769 | return 1; |
770 | } |
771 | |
772 | if (!Sweep->IsReady()) { |
773 | //cout << "You have forgotten the <<addsweep>> command !"<< endl; |
774 | di << "You have forgotten the <<addsweep>> command !"<< "\n"; |
775 | return 1; |
776 | } |
777 | |
778 | char name[100]; |
779 | TopTools_ListOfShape List; |
780 | TopTools_ListIteratorOfListOfShape it; |
781 | Standard_Integer N, ii; |
91322f44 |
782 | N = Draw::Atoi(a[2]); |
7fd59977 |
783 | |
784 | if (n>3) { |
785 | BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed; |
786 | // Lecture Transition |
787 | if (!strcmp(a[3],"-C")) { |
788 | Transition = BRepBuilderAPI_RightCorner; |
789 | } |
790 | else if (!strcmp(a[3],"-R")) { |
791 | Transition = BRepBuilderAPI_RoundCorner; |
792 | } |
793 | Sweep->SetTransitionMode(Transition); |
794 | } |
795 | |
0d969553 |
796 | // Calculate the result |
7fd59977 |
797 | Sweep->Simulate(N, List); |
798 | for (ii=1, it.Initialize(List); it.More(); it.Next(), ii++) { |
91322f44 |
799 | Sprintf(name,"%s_%d",a[1],ii); |
7fd59977 |
800 | DBRep::Set(name, it.Value()); |
801 | } |
802 | |
803 | return 0; |
804 | } |
805 | |
2277323d |
806 | //======================================================================= |
807 | // middlepath |
808 | //======================================================================= |
35e08fe8 |
809 | static Standard_Integer middlepath(Draw_Interpretor& /*di*/, |
2277323d |
810 | Standard_Integer n, const char** a) |
811 | { |
812 | if (n < 5) return 1; |
813 | |
814 | TopoDS_Shape aShape = DBRep::Get(a[2]); |
815 | if (aShape.IsNull()) return 1; |
816 | |
817 | TopoDS_Shape StartShape = DBRep::Get(a[3]); |
818 | if (StartShape.IsNull()) return 1; |
819 | |
820 | TopoDS_Shape EndShape = DBRep::Get(a[4]); |
821 | if (EndShape.IsNull()) return 1; |
822 | |
823 | BRepOffsetAPI_MiddlePath Builder(aShape, StartShape, EndShape); |
824 | Builder.Build(); |
825 | |
826 | TopoDS_Shape Result = Builder.Shape(); |
827 | DBRep::Set(a[1], Result); |
828 | |
829 | return 0; |
830 | } |
831 | |
7fd59977 |
832 | //======================================================================= |
833 | //function : SweepCommands |
834 | //purpose : |
835 | //======================================================================= |
836 | |
837 | void BRepTest::SweepCommands(Draw_Interpretor& theCommands) |
838 | { |
839 | static Standard_Boolean done = Standard_False; |
840 | if (done) return; |
841 | done = Standard_True; |
842 | |
843 | DBRep::BasicCommands(theCommands); |
844 | |
845 | const char* g = "Sweep commands"; |
846 | |
847 | theCommands.Add("prism", |
848 | "prism result base dx dy dz [Copy | Inf | Seminf]", |
849 | __FILE__,prism,g); |
850 | |
851 | theCommands.Add("revol", |
852 | "revol result base px py pz dx dy dz angle [Copy]", |
853 | __FILE__,revol,g); |
854 | |
855 | theCommands.Add("pipe", |
471ce736 |
856 | "pipe result Wire_spine Profile [Mode [Approx]], no args to get help", |
7fd59977 |
857 | __FILE__,pipe,g); |
858 | |
859 | theCommands.Add("evolved", |
860 | "evolved , no args to get help", |
861 | __FILE__,evolved,g); |
862 | |
863 | theCommands.Add("evolvedsolid", |
864 | "evolved , no args to get help", |
865 | __FILE__,evolved,g); |
866 | |
867 | theCommands.Add("pruled", |
868 | "pruled result Edge1/Wire1 Edge2/Wire2", |
869 | __FILE__,pruled,g); |
870 | |
871 | theCommands.Add("gener", "gener result wire1 wire2 [..wire..]", |
872 | __FILE__,gener,g); |
873 | |
874 | theCommands.Add("thrusections", "thrusections [-N] result issolid isruled shape1 shape2 [..shape..], the option -N means no check on wires, shapes must be wires or vertices (only first or last)", |
875 | __FILE__,thrusections,g); |
876 | |
877 | |
878 | theCommands.Add("mksweep", "mksweep wire", |
879 | __FILE__,mksweep,g); |
880 | |
881 | theCommands.Add("setsweep", "setsweep no args to get help", |
882 | __FILE__,setsweep,g); |
883 | |
884 | theCommands.Add("addsweep", |
885 | "addsweep wire [vertex] [-M ] [-C] [auxiilaryshape]:no args to get help", |
886 | __FILE__,addsweep,g); |
887 | |
888 | theCommands.Add("deletesweep", |
889 | "deletesweep wire, To delete a section", |
890 | __FILE__,deletesweep,g); |
891 | |
892 | theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help" |
893 | __FILE__,buildsweep,g); |
894 | |
895 | theCommands.Add("simulsweep", "simulsweep r [n] [option]" |
896 | __FILE__,simulsweep,g); |
897 | theCommands.Add("geompipe", "geompipe r spineedge profileedge radius [byACR [byrotate]]" |
898 | __FILE__,geompipe,g); |
2277323d |
899 | |
900 | theCommands.Add("middlepath", "middlepath res shape startshape endshape", |
901 | __FILE__,middlepath,g); |
7fd59977 |
902 | } |
903 | |