0030364: Visualization, TKOpenGl - allow initializing a Surface-less EGL context
[occt.git] / src / BRepTest / BRepTest_SweepCommands.cxx
... / ...
CommitLineData
1// Created on: 1993-07-22
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
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
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <BRepTest.hxx>
18
19#include <BRepTest_Objects.hxx>
20
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>
34#include <BRepOffsetAPI_MiddlePath.hxx>
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;
49static BRepOffsetAPI_ThruSections* Generator = 0;
50
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>
59#include <gp_Vec.hxx>
60#include <Geom_Circle.hxx>
61#include <gp_Ax2.hxx>
62
63
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
75 gp_Vec V(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
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//=======================================================================
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
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]));
113 gp_Ax1 A(P,D);
114
115 Standard_Real angle = Draw::Atof(a[9]) * (M_PI / 180.0);
116
117 Standard_Boolean copy = n > 10;
118
119
120 BRepPrimAPI_MakeRevol Revol(base, A, angle, copy);
121
122 TopoDS_Shape res = Revol.Shape();
123
124 DBRep::Set(a[1],res);
125
126 //History
127 TopTools_ListOfShape anArgs;
128 anArgs.Append(base);
129 BRepTest_Objects::SetHistory(anArgs, Revol);
130
131 return 0;
132}
133
134
135//=======================================================================
136// pipe
137//=======================================================================
138
139static Standard_Integer pipe(Draw_Interpretor& di,
140 Standard_Integer n, const char** a)
141{
142 if (n == 1)
143 {
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";
149 return 0;
150 }
151
152 if (n > 1 && n < 4) return 1;
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;
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;
173
174 BRepOffsetAPI_MakePipe PipeBuilder(TopoDS::Wire(Spine),
175 Profile,
176 Mode,
177 ForceApproxC1);
178 TopoDS_Shape S = PipeBuilder.Shape();
179
180 DBRep::Set(a[1],S);
181
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
191 return 0;
192}
193
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;
210 Standard_Real Radius = Draw::Atof(a[4]);
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)
219 ByACR = (Draw::Atoi(a[k++]) ==1);
220 if(n > k)
221 rotate = (Draw::Atoi(a[k++])==1);
222 GeomFill_Pipe aPipe(ProfileCurve,aAdaptCurve,cStart,ByACR,rotate);
223 aPipe.Perform(Standard_True);
224 if (!aPipe.IsDone())
225 {
226 cout << "GeomFill_Pipe cannot make a surface" << endl;
227 return 1;
228 }
229 Handle(Geom_Surface) Sur=aPipe.Surface();
230 TopoDS_Face F;
231 if(!Sur.IsNull())
232 F = BRepBuilderAPI_MakeFace(Sur, Precision::Confusion());
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;
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";
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
347 BRepFill_Generator aGenerator;
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
354 aGenerator.AddWire(TopoDS::Wire(Shape));
355 }
356
357 aGenerator.Perform();
358
359 TopoDS_Shell Shell = aGenerator.Shell();
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
389 Standard_Boolean issolid = ( Draw::Atoi(a[index]) == 1 );
390 Standard_Boolean isruled = ( Draw::Atoi(a[index+1]) == 1 );
391
392 if (Generator != 0)
393 {
394 delete Generator;
395 Generator = 0;
396 }
397 Generator = new BRepOffsetAPI_ThruSections(issolid,isruled);
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 {
406 Generator->AddWire(TopoDS::Wire(Shape));
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())
417 Generator->AddVertex(TopoDS::Vertex(Shape));
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);
436 Generator->CheckCompatibility(check);
437
438 Generator->Build();
439
440 if (Generator->IsDone()) {
441 TopoDS_Shape Shell = Generator->Shape();
442 DBRep::Set(a[index-1], Shell);
443 // Save history of the lofting
444 if (BRepTest_Objects::IsHistoryNeeded())
445 BRepTest_Objects::SetHistory(Generator->Wires(), *Generator);
446 }
447 else {
448 cout << "Algorithm is not done" << endl;
449 }
450
451 return 0;
452}
453
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;
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";
498 return 0;
499 }
500
501 if (Sweep ==0) {
502 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
503 di << "You have forgotten the <<mksweep>> command !\n";
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 }
512 else if (!strcmp(a[1],"-DT")) {
513 Sweep->SetDiscreteMode();
514 }
515 else if (!strcmp(a[1],"-DX")) {
516 if (n!=3) {
517 //cout << "bad arguments !" << endl;
518 di << "bad arguments !\n";
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;
525 di << a[2] <<"is not a shape !\n";
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;
533 di << "bad arguments !\n";
534 return 1;
535 }
536 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
537 Sweep->SetMode(D);;
538 }
539 else if (!strcmp(a[1],"-FX")) {
540 if ((n!=5)&&(n!=8)) {
541 //cout << "bad arguments !" << endl;
542 di << "bad arguments !\n";
543 return 1;
544 }
545 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
546 if (n==8) {
547 gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
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;
561 di << "bad arguments !\n";
562 return 1;
563 }
564 else
565 {
566 TopoDS_Shape Guide = DBRep::Get(a[2],TopAbs_WIRE);
567 Standard_Boolean CurvilinearEquivalence = Draw::Atoi(a[3]) != 0;
568 Standard_Integer KeepContact = Draw::Atoi(a[4]);
569 Sweep->SetMode(TopoDS::Wire(Guide),
570 CurvilinearEquivalence,
571 (BRepFill_TypeOfContact)KeepContact);
572 }
573 }
574
575 else {
576 //cout << "The option "<< a[1] << " is unknown !" << endl;
577 di << "The option "<< a[1] << " is unknown !\n";
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;
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";
601 return 0;
602 }
603
604 if (Sweep ==0) {
605 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
606 di << "You have forgotten the <<mksweep>> command !\n";
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);
615 if (Section.IsNull() ||
616 (Section.ShapeType() != TopAbs_WIRE &&
617 Section.ShapeType() != TopAbs_VERTEX))
618 {
619 //cout << a[1] <<"is not a wire and is not a vertex!" << endl;
620 di << a[1] <<" is not a wire and is not a vertex!\n";
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;
630 // Reading of Vertex
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
639 // Reading of the translation option
640 if ((n>cur) && !strcmp(a[cur],"-T")) {
641 cur++;
642 isT = Standard_True;
643 }
644
645 // Reading of the rotation option
646 if ((n>cur) && !strcmp(a[cur],"-R")) {
647 cur++;
648 isR = Standard_True;
649 }
650
651 // law ?
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";
657 } else { //law of interpolation
658 Standard_Integer ii, L= nbreal/2;
659 TColgp_Array1OfPnt2d ParAndRad(1, L);
660 for (ii=1; ii<=L; ii++, cur+=2) {
661 ParAndRad(ii).SetX(Draw::Atof(a[cur]));
662 ParAndRad(ii).SetY(Draw::Atof(a[cur+1]));
663 }
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;
698 di << a[1] <<"is not a wire !\n";
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;
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";
730 return 0;
731 }
732
733 Standard_Boolean mksolid = Standard_False;
734 if (Sweep ==0) {
735 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
736 di << "You have forgotten the <<mksweep>> command !\n";
737 return 1;
738 }
739
740 if (!Sweep->IsReady()) {
741 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
742 di << "You have forgotten the <<addsweep>> command !\n";
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
751 // Reading Transition
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 }
762 // Reading solid ?
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;
769 di << "Buildsweep : Not Done\n";
770 BRepBuilderAPI_PipeError Stat = Sweep->GetStatus();
771 if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) {
772 //cout << "Buildsweep : One Plane not intersect the guide" << endl;
773 di << "Buildsweep : One Plane not intersect the guide\n";
774 }
775 if (Stat == BRepBuilderAPI_ImpossibleContact) {
776 //cout << "BuildSweep : One section can not be in contact with the guide" << endl;
777 di << "BuildSweep : One section can not be in contact with the guide\n";
778 }
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;
785 if (!B) di << " BuildSweep : It is impossible to make a solid !\n";
786 }
787 result = Sweep->Shape();
788 DBRep::Set(a[1],result);
789 // Save history of sweep
790 if (BRepTest_Objects::IsHistoryNeeded())
791 {
792 TopTools_ListOfShape aList;
793 Sweep->Profiles(aList);
794 TopoDS_Shape aSpine = Sweep->Spine();
795 aList.Append(aSpine);
796 BRepTest_Objects::SetHistory(aList, *Sweep);
797 }
798 }
799
800 return 0;
801}
802
803//=======================================================================
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//=======================================================================
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;
831 di << "You have forgotten the <<mksweep>> command !\n";
832 return 1;
833 }
834
835 if (!Sweep->IsReady()) {
836 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
837 di << "You have forgotten the <<addsweep>> command !\n";
838 return 1;
839 }
840
841 char name[100];
842 TopTools_ListOfShape List;
843 TopTools_ListIteratorOfListOfShape it;
844 Standard_Integer N, ii;
845 N = Draw::Atoi(a[2]);
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
859 // Calculate the result
860 Sweep->Simulate(N, List);
861 for (ii=1, it.Initialize(List); it.More(); it.Next(), ii++) {
862 Sprintf(name,"%s_%d",a[1],ii);
863 DBRep::Set(name, it.Value());
864 }
865
866 return 0;
867}
868
869//=======================================================================
870// middlepath
871//=======================================================================
872static Standard_Integer middlepath(Draw_Interpretor& /*di*/,
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//=======================================================================
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",
919 "pipe result Wire_spine Profile [Mode [Approx]], no args to get help",
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);
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
954 theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help",
955 __FILE__,buildsweep,g);
956
957 theCommands.Add("errorsweep", "errorsweep: returns the summary error on resulting surfaces reached by Sweep",
958 __FILE__,errorsweep,g);
959
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);
964
965 theCommands.Add("middlepath", "middlepath res shape startshape endshape",
966 __FILE__,middlepath,g);
967}
968