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