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