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