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