0023282: Wrong triangulation on cone
[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";
a31abc03 434 di << " -DT : discrete trihedron" << "\n";
7fd59977 435 di << " -DX Surf : Tangent and Normal are given by Darboux trihedron," <<"\n";
436 di << " Surf have to be a shell or a face" <<"\n";
437 di << " -CN dx dy dz : BiNormal is given by dx dy dz" << "\n";
438 di << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed" <<"\n";
439 di << " -G guide 0|1(ACR|Plan) 0|1(contact|no contact) : with guide"<<"\n";
440 return 0;
441 }
442
443 if (Sweep ==0) {
444 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
445 di << "You have forgotten the <<mksweep>> command !"<< "\n";
446 return 1;
447 }
448 if (!strcmp(a[1],"-FR")) {
449 Sweep->SetMode(Standard_True);
450 }
451 else if (!strcmp(a[1],"-CF")) {
452 Sweep->SetMode(Standard_False);
453 }
a31abc03 454 else if (!strcmp(a[1],"-DT")) {
455 Sweep->SetDiscreteMode();
456 }
7fd59977 457 else if (!strcmp(a[1],"-DX")) {
458 if (n!=3) {
459 //cout << "bad arguments !" << endl;
460 di << "bad arguments !" << "\n";
461 return 1;
462 }
463 TopoDS_Shape Surf;
464 Surf = DBRep::Get(a[2],TopAbs_SHAPE);
465 if (Surf.IsNull()) {
466 //cout << a[2] <<"is not a shape !" << endl;
467 di << a[2] <<"is not a shape !" << "\n";
468 return 1;
469 }
470 Sweep->SetMode(Surf);
471 }
472 else if (!strcmp(a[1],"-CN")) {
473 if (n!=5) {
474 //cout << "bad arguments !" << endl;
475 di << "bad arguments !" << "\n";
476 return 1;
477 }
91322f44 478 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 479 Sweep->SetMode(D);;
480 }
481 else if (!strcmp(a[1],"-FX")) {
482 if ((n!=5)&&(n!=8)) {
483 //cout << "bad arguments !" << endl;
484 di << "bad arguments !" << "\n";
485 return 1;
486 }
91322f44 487 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 488 if (n==8) {
91322f44 489 gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
7fd59977 490 gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D, DN);
491 Sweep->SetMode(Axe);
492 }
493 else {
494 gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D);
495 Sweep->SetMode(Axe);
496 }
497 }
498 else if (!strcmp(a[1],"-G")) // contour guide
499 {
500 if (n != 5)
501 {
502 //cout << "bad arguments !" << endl;
503 di << "bad arguments !" << "\n";
504 return 1;
505 }
506 else
507 {
508 TopoDS_Shape Guide = DBRep::Get(a[2],TopAbs_WIRE);
91322f44 509 Sweep->SetMode(TopoDS::Wire(Guide), Draw::Atoi(a[3]), Draw::Atoi(a[4]));
7fd59977 510 }
511 }
512
513 else {
514 //cout << "The option "<< a[1] << " is unknown !" << endl;
515 di << "The option "<< a[1] << " is unknown !" << "\n";
516 return 1;
517 }
518 return 0;
519}
520
521
522//=======================================================================
523// addsweep
524//=======================================================================
525static Standard_Integer addsweep(Draw_Interpretor& di,
526 Standard_Integer n, const char** a)
527{
528 if ( n == 1) {
529 //cout << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :" << endl;
530 //cout << " -T : the wire/vertex have to be translated to assume contact"<< endl;
531 //cout << " with the spine" <<endl;
532 //cout << " -R : the wire have to be rotated to assume orthogonality"<<endl;
533 //cout << " with the spine's tangent" << endl;
534 di << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :" << "\n";
535 di << " -T : the wire/vertex have to be translated to assume contact"<< "\n";
536 di << " with the spine" <<"\n";
537 di << " -R : the wire have to be rotated to assume orthogonality"<<"\n";
538 di << " with the spine's tangent" << "\n";
539 return 0;
540 }
541
542 if (Sweep ==0) {
543 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
544 di << "You have forgotten the <<mksweep>> command !"<< "\n";
545 return 1;
546 }
547
548 TopoDS_Shape Section;
549 TopoDS_Vertex Vertex;
550 Handle(Law_Interpol) thelaw;
551
552 Section = DBRep::Get(a[1], TopAbs_SHAPE);
553 if (Section.ShapeType() != TopAbs_WIRE &&
554 Section.ShapeType() != TopAbs_VERTEX)
555 {
556 //cout << a[1] <<"is not a wire and is not a vertex!" << endl;
557 di << a[1] <<"is not a wire and is not a vertex!" << "\n";
558 return 1;
559 }
560
561 Standard_Boolean HasVertex=Standard_False,
562 isT=Standard_False,
563 isR=Standard_False;
564
565 if (n > 2) {
566 Standard_Integer cur = 2;
0d969553 567 // Reading of Vertex
7fd59977 568 TopoDS_Shape InputVertex(DBRep::Get(a[cur],TopAbs_VERTEX));
569 Vertex = TopoDS::Vertex(InputVertex);
570// Vertex = TopoDS::Vertex(DBRep::Get(a[cur],TopAbs_VERTEX));
571 if (!Vertex.IsNull()) {
572 cur++;
573 HasVertex = Standard_True;
574 }
575
0d969553 576 // Reading of the translation option
7fd59977 577 if ((n>cur) && !strcmp(a[cur],"-T")) {
578 cur++;
579 isT = Standard_True;
580 }
581
0d969553 582 // Reading of the rotation option
7fd59977 583 if ((n>cur) && !strcmp(a[cur],"-R")) {
584 cur++;
585 isR = Standard_True;
586 }
587
0d969553 588 // law ?
7fd59977 589 if (n>cur) {
590 Standard_Integer nbreal = n-cur;
591 if ( (nbreal < 4) || (nbreal % 2 != 0) ) {
592 //cout << "bad arguments ! :" <<a[cur] << endl;
593 di << "bad arguments ! :" <<a[cur] << "\n";
0d969553 594 } else { //law of interpolation
7fd59977 595 Standard_Integer ii, L= nbreal/2;
596 TColgp_Array1OfPnt2d ParAndRad(1, L);
597 for (ii=1; ii<=L; ii++, cur+=2) {
91322f44 598 ParAndRad(ii).SetX(Draw::Atof(a[cur]));
599 ParAndRad(ii).SetY(Draw::Atof(a[cur+1]));
7fd59977 600 }
601 thelaw = new (Law_Interpol) ();
602 thelaw->Set(ParAndRad,
603 Abs(ParAndRad(1).Y() - ParAndRad(L).Y()) < Precision::Confusion());
604 }
605 }
606 }
607
608 if (thelaw.IsNull()) {
609 if (HasVertex) Sweep->Add(Section, Vertex, isT, isR);
610 else Sweep->Add(Section, isT, isR);
611 }
612 else {
613 if (HasVertex) Sweep->SetLaw(Section, thelaw, Vertex, isT, isR);
614 else Sweep->SetLaw(Section, thelaw, isT, isR);
615 }
616
617 return 0;
618}
619
620//=======================================================================
621// deletesweep
622//=======================================================================
623static Standard_Integer deletesweep(Draw_Interpretor& di,
624 Standard_Integer n, const char** a)
625{
626 if ( n != 2) {
627 return 1;
628 }
629 TopoDS_Wire Section;
630 TopoDS_Shape InputShape(DBRep::Get(a[1],TopAbs_SHAPE));
631 Section = TopoDS::Wire(InputShape);
632// Section = TopoDS::Wire(DBRep::Get(a[1],TopAbs_SHAPE));
633 if (Section.IsNull()) {
634 //cout << a[1] <<"is not a wire !" << endl;
635 di << a[1] <<"is not a wire !" << "\n";
636 return 1;
637 }
638
639 Sweep->Delete(Section);
640
641 return 0;
642}
643
644//=======================================================================
645// buildsweep
646//=======================================================================
647static Standard_Integer buildsweep(Draw_Interpretor& di,
648 Standard_Integer n, const char** a)
649{
650 if ( n == 1) {
651 //cout << "build sweep result [-M/-C/-R] [-S] [tol] : options are" << endl;
652 //cout << " -M : Discontinuities are treated by Modfication of"<< endl;
653 //cout << " the sweeping mode : it is the default" <<endl;
654 //cout << " -C : Discontinuities are treated like Right Corner" << endl;
655 //cout << " Treatement is Extent && Intersect" << endl;
656 //cout << " -R : Discontinuities are treated like Round Corner" << endl;
657 //cout << " Treatement is Intersect and Fill" << endl;
658 //cout << " -S : To build a Solid" << endl;
659 di << "build sweep result [-M/-C/-R] [-S] [tol] : options are" << "\n";
660 di << " -M : Discontinuities are treated by Modfication of"<< "\n";
661 di << " the sweeping mode : it is the default" <<"\n";
662 di << " -C : Discontinuities are treated like Right Corner" << "\n";
663 di << " Treatement is Extent && Intersect" << "\n";
664 di << " -R : Discontinuities are treated like Round Corner" << "\n";
665 di << " Treatement is Intersect and Fill" << "\n";
666 di << " -S : To build a Solid" << "\n";
667 return 0;
668 }
669
670 Standard_Boolean mksolid = Standard_False;
671 if (Sweep ==0) {
672 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
673 di << "You have forgotten the <<mksweep>> command !"<< "\n";
674 return 1;
675 }
676
677 if (!Sweep->IsReady()) {
678 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
679 di << "You have forgotten the <<addsweep>> command !"<< "\n";
680 return 1;
681 }
682
683 TopoDS_Shape result;
684 Standard_Integer cur=2;
685 if (n>cur) {
686 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
687
0d969553 688 // Reading Transition
7fd59977 689 if (!strcmp(a[cur],"-C")) {
690 Transition = BRepBuilderAPI_RightCorner;
691 cur++;
692 }
693 else if (!strcmp(a[cur],"-R")) {
694 Transition = BRepBuilderAPI_RoundCorner;
695 cur++;
696 }
697 Sweep->SetTransitionMode(Transition);
698 }
0d969553 699 // Reading solid ?
7fd59977 700 if ((n>cur) && (!strcmp(a[cur],"-S")) ) mksolid = Standard_True;
701
702 // Calcul le resultat
703 Sweep->Build();
704 if (!Sweep->IsDone()) {
705 //cout << "Buildsweep : Not Done" << endl;
706 di << "Buildsweep : Not Done" << "\n";
707 BRepBuilderAPI_PipeError Stat = Sweep->GetStatus();
708 if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) {
709 //cout << "Buildsweep : One Plane not intersect the guide" << endl;
710 di << "Buildsweep : One Plane not intersect the guide" << "\n";
711 }
712 if (Stat == BRepBuilderAPI_ImpossibleContact) {
713 //cout << "BuildSweep : One section can not be in contact with the guide" << endl;
714 di << "BuildSweep : One section can not be in contact with the guide" << "\n";
715 }
716 return 1;
717 }
718 else {
719 if (mksolid) {
720 Standard_Boolean B;
721 B = Sweep->MakeSolid();
722 //if (!B) cout << " BuildSweep : It is impossible to make a solid !" << endl;
723 if (!B) di << " BuildSweep : It is impossible to make a solid !" << "\n";
724 }
725 result = Sweep->Shape();
726 DBRep::Set(a[1],result);
727 }
728
729 return 0;
730}
731
732//=======================================================================
733// simulsweep
734//=======================================================================
735static Standard_Integer simulsweep(Draw_Interpretor& di,
736 Standard_Integer n, const char** a)
737{
738 if ( (n!=3) && (n!=4) ) return 1;
739
740 if (Sweep ==0) {
741 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
742 di << "You have forgotten the <<mksweep>> command !"<< "\n";
743 return 1;
744 }
745
746 if (!Sweep->IsReady()) {
747 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
748 di << "You have forgotten the <<addsweep>> command !"<< "\n";
749 return 1;
750 }
751
752 char name[100];
753 TopTools_ListOfShape List;
754 TopTools_ListIteratorOfListOfShape it;
755 Standard_Integer N, ii;
91322f44 756 N = Draw::Atoi(a[2]);
7fd59977 757
758 if (n>3) {
759 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
760 // Lecture Transition
761 if (!strcmp(a[3],"-C")) {
762 Transition = BRepBuilderAPI_RightCorner;
763 }
764 else if (!strcmp(a[3],"-R")) {
765 Transition = BRepBuilderAPI_RoundCorner;
766 }
767 Sweep->SetTransitionMode(Transition);
768 }
769
0d969553 770 // Calculate the result
7fd59977 771 Sweep->Simulate(N, List);
772 for (ii=1, it.Initialize(List); it.More(); it.Next(), ii++) {
91322f44 773 Sprintf(name,"%s_%d",a[1],ii);
7fd59977 774 DBRep::Set(name, it.Value());
775 }
776
777 return 0;
778}
779
780//=======================================================================
2277323d 781// middlepath
782//=======================================================================
783static Standard_Integer middlepath(Draw_Interpretor& di,
784 Standard_Integer n, const char** a)
785{
786 if (n < 5) return 1;
787
788 TopoDS_Shape aShape = DBRep::Get(a[2]);
789 if (aShape.IsNull()) return 1;
790
791 TopoDS_Shape StartShape = DBRep::Get(a[3]);
792 if (StartShape.IsNull()) return 1;
793
794 TopoDS_Shape EndShape = DBRep::Get(a[4]);
795 if (EndShape.IsNull()) return 1;
796
797 BRepOffsetAPI_MiddlePath Builder(aShape, StartShape, EndShape);
798 Builder.Build();
799
800 TopoDS_Shape Result = Builder.Shape();
801 DBRep::Set(a[1], Result);
802
803 return 0;
804}
805
806//=======================================================================
7fd59977 807//function : SweepCommands
808//purpose :
809//=======================================================================
810
811void BRepTest::SweepCommands(Draw_Interpretor& theCommands)
812{
813 static Standard_Boolean done = Standard_False;
814 if (done) return;
815 done = Standard_True;
816
817 DBRep::BasicCommands(theCommands);
818
819 const char* g = "Sweep commands";
820
821 theCommands.Add("prism",
822 "prism result base dx dy dz [Copy | Inf | Seminf]",
823 __FILE__,prism,g);
824
825 theCommands.Add("revol",
826 "revol result base px py pz dx dy dz angle [Copy]",
827 __FILE__,revol,g);
828
829 theCommands.Add("pipe",
830 "pipe result Wire_spine Profile",
831 __FILE__,pipe,g);
832
833 theCommands.Add("evolved",
834 "evolved , no args to get help",
835 __FILE__,evolved,g);
836
837 theCommands.Add("evolvedsolid",
838 "evolved , no args to get help",
839 __FILE__,evolved,g);
840
841 theCommands.Add("pruled",
842 "pruled result Edge1/Wire1 Edge2/Wire2",
843 __FILE__,pruled,g);
844
845 theCommands.Add("gener", "gener result wire1 wire2 [..wire..]",
846 __FILE__,gener,g);
847
848 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)",
849 __FILE__,thrusections,g);
850
851
852 theCommands.Add("mksweep", "mksweep wire",
853 __FILE__,mksweep,g);
854
855 theCommands.Add("setsweep", "setsweep no args to get help",
856 __FILE__,setsweep,g);
857
858 theCommands.Add("addsweep",
859 "addsweep wire [vertex] [-M ] [-C] [auxiilaryshape]:no args to get help",
860 __FILE__,addsweep,g);
861
862 theCommands.Add("deletesweep",
863 "deletesweep wire, To delete a section",
864 __FILE__,deletesweep,g);
865
866 theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help"
867 __FILE__,buildsweep,g);
868
869 theCommands.Add("simulsweep", "simulsweep r [n] [option]"
870 __FILE__,simulsweep,g);
871 theCommands.Add("geompipe", "geompipe r spineedge profileedge radius [byACR [byrotate]]"
872 __FILE__,geompipe,g);
2277323d 873
874 theCommands.Add("middlepath", "middlepath res shape startshape endshape",
875 __FILE__,middlepath,g);
7fd59977 876}
877