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