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