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