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