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