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