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