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