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