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