0030346: Modeling Algorithms - BRepPrimAPI_MakeRevol throws "BRepSweep_Translation...
[occt.git] / src / BRepTest / BRepTest_SweepCommands.cxx
... / ...
CommitLineData
1// Created on: 1993-07-22
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
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
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <BRepTest.hxx>
18
19#include <BRepTest_Objects.hxx>
20
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>
34#include <BRepOffsetAPI_MiddlePath.hxx>
35
36#include <BRepLib_MakeWire.hxx>
37#include <TopoDS.hxx>
38#include <TopTools_ListIteratorOfListOfShape.hxx>
39#include <TopExp_Explorer.hxx>
40
41#include <Precision.hxx>
42#include <Law_Interpol.hxx>
43#include <gp_Ax1.hxx>
44#include <gp_Ax2.hxx>
45#include <gp_Pnt2d.hxx>
46#include <TColgp_Array1OfPnt2d.hxx>
47
48static BRepOffsetAPI_MakePipeShell* Sweep = 0;
49static BRepOffsetAPI_ThruSections* Generator = 0;
50
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>
59#include <gp_Vec.hxx>
60#include <Geom_Circle.hxx>
61#include <gp_Ax2.hxx>
62
63
64//=======================================================================
65// prism
66//=======================================================================
67
68static Standard_Integer prism(Draw_Interpretor&, Standard_Integer n, const char** a)
69{
70 if (n < 6) return 1;
71
72 TopoDS_Shape base = DBRep::Get(a[2]);
73 if (base.IsNull()) return 1;
74
75 gp_Vec V(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]));
76
77 Standard_Boolean copy = Standard_False;
78 Standard_Boolean inf = Standard_False;
79 Standard_Boolean sinf = Standard_False;
80
81 if (n > 6) {
82 copy = (*a[6] == 'c') || (*a[6] == 'C');
83 inf = (*a[6] == 'i') || (*a[6] == 'I');
84 sinf = (*a[6] == 's') || (*a[6] == 'S');
85 }
86
87 TopoDS_Shape res;
88
89 BRepPrimAPI_MakePrism* Prism;
90 if (inf || sinf)
91 {
92 Prism = new BRepPrimAPI_MakePrism(base, gp_Dir(V), inf);
93 }
94 else
95 {
96 Prism = new BRepPrimAPI_MakePrism(base, V, copy);
97 }
98
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;
109
110 return 0;
111}
112
113
114//=======================================================================
115// revol
116//=======================================================================
117static Standard_Integer revol(Draw_Interpretor&,
118 Standard_Integer n, const char** a)
119{
120 if (n < 10) return 1;
121
122 TopoDS_Shape base = DBRep::Get(a[2]);
123 if (base.IsNull()) return 1;
124
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);
128
129 Standard_Real angle = Draw::Atof(a[9]) * (M_PI / 180.0);
130
131 Standard_Boolean copy = n > 10;
132
133
134 BRepPrimAPI_MakeRevol Revol(base, A, angle, copy);
135
136 TopoDS_Shape res = Revol.Shape();
137
138 DBRep::Set(a[1], res);
139
140 //History
141 TopTools_ListOfShape anArgs;
142 anArgs.Append(base);
143 BRepTest_Objects::SetHistory(anArgs, Revol);
144
145 return 0;
146}
147
148
149//=======================================================================
150// pipe
151//=======================================================================
152
153static Standard_Integer pipe(Draw_Interpretor& di,
154 Standard_Integer n, const char** a)
155{
156 if (n == 1)
157 {
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";
163 return 0;
164 }
165
166 if (n > 1 && n < 4) return 1;
167
168 TopoDS_Shape Spine = DBRep::Get(a[2], TopAbs_WIRE);
169 if (Spine.IsNull()) return 1;
170
171 TopoDS_Shape Profile = DBRep::Get(a[3]);
172 if (Profile.IsNull()) return 1;
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;
187
188 BRepOffsetAPI_MakePipe PipeBuilder(TopoDS::Wire(Spine),
189 Profile,
190 Mode,
191 ForceApproxC1);
192 TopoDS_Shape S = PipeBuilder.Shape();
193
194 DBRep::Set(a[1], S);
195
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 }
204
205 return 0;
206}
207
208//=======================================================================
209
210static Standard_Integer geompipe(Draw_Interpretor&,
211 Standard_Integer n, const char** a)
212{
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);
222 Standard_Boolean ByACR = Standard_False;
223 Standard_Boolean rotate = Standard_False;
224 Standard_Real Radius = Draw::Atof(a[4]);
225 gp_Pnt ctr;
226 gp_Vec norm;
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);
237 aPipe.Perform(Standard_True);
238 if (!aPipe.IsDone())
239 {
240 cout << "GeomFill_Pipe cannot make a surface" << endl;
241 return 1;
242 }
243 Handle(Geom_Surface) Sur = aPipe.Surface();
244 TopoDS_Face F;
245 if (!Sur.IsNull())
246 F = BRepBuilderAPI_MakeFace(Sur, Precision::Confusion());
247 DBRep::Set(a[1], F);
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{
258 if (n == 1) {
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;
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";
269 return 0;
270 }
271
272 if (n < 4) return 1;
273 Standard_Boolean IsAFace = Standard_False;
274 Standard_Boolean Solid = (!strcmp(a[0], "evolvedsolid"));
275
276
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;
282 }
283 if (Base.IsNull()) return 1;
284
285 TopoDS_Shape InpuTShape(DBRep::Get(a[3], TopAbs_WIRE, Standard_False));
286 TopoDS_Wire Prof = TopoDS::Wire(InpuTShape);
287 // TopoDS_Wire Prof =
288 // TopoDS::Wire(DBRep::Get(a[3],TopAbs_WIRE,Standard_False));
289 if (Prof.IsNull()) return 1;
290
291 if (IsAFace) {
292 TopoDS_Shape Volevo
293 = BRepOffsetAPI_MakeEvolved(TopoDS::Face(Base), Prof, GeomAbs_Arc, n == 4, Solid);
294 DBRep::Set(a[1], Volevo);
295 }
296 else {
297 TopoDS_Shape Volevo
298 = BRepOffsetAPI_MakeEvolved(TopoDS::Wire(Base), Prof, GeomAbs_Arc, n == 4, Solid);
299 DBRep::Set(a[1], Volevo);
300 }
301
302 return 0;
303}
304
305
306//=======================================================================
307//function : pruled
308//purpose :
309//=======================================================================
310
311static Standard_Integer pruled(Draw_Interpretor&,
312 Standard_Integer n, const char** a)
313{
314 if (n != 4) return 1;
315
316 Standard_Boolean YaWIRE = Standard_False;
317 TopoDS_Shape S1 = DBRep::Get(a[2], TopAbs_EDGE);
318 if (S1.IsNull()) {
319 S1 = DBRep::Get(a[2], TopAbs_WIRE);
320 if (S1.IsNull()) return 1;
321 YaWIRE = Standard_True;
322 }
323
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;
328 if (!YaWIRE) {
329 S1 = BRepLib_MakeWire(TopoDS::Edge(S1));
330 YaWIRE = Standard_True;
331 }
332 }
333 else if (YaWIRE) {
334 S2 = BRepLib_MakeWire(TopoDS::Edge(S2));
335 }
336
337 TopoDS_Shape Result;
338 if (YaWIRE) {
339 Result = BRepFill::Shell(TopoDS::Wire(S1), TopoDS::Wire(S2));
340 }
341 else {
342 Result = BRepFill::Face(TopoDS::Edge(S1), TopoDS::Edge(S2));
343 }
344
345 DBRep::Set(a[1], Result);
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{
357 if (n < 4) return 1;
358
359 TopoDS_Shape Shape;
360
361 BRepFill_Generator aGenerator;
362
363 for (Standard_Integer i = 2; i <= n - 1; i++) {
364 Shape = DBRep::Get(a[i], TopAbs_WIRE);
365 if (Shape.IsNull())
366 return 1;
367
368 aGenerator.AddWire(TopoDS::Wire(Shape));
369 }
370
371 aGenerator.Perform();
372
373 TopoDS_Shell Shell = aGenerator.Shell();
374
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{
389 if (n < 6) return 1;
390
391 Standard_Boolean check = Standard_True;
392 Standard_Boolean samenumber = Standard_True;
393 Standard_Integer index = 2;
394 // Lecture option
395 if (!strcmp(a[1], "-N")) {
396 if (n < 7) return 1;
397 check = Standard_False;
398 index++;
399 }
400
401 TopoDS_Shape Shape;
402
403 Standard_Boolean issolid = (Draw::Atoi(a[index]) == 1);
404 Standard_Boolean isruled = (Draw::Atoi(a[index + 1]) == 1);
405
406 if (Generator != 0)
407 {
408 delete Generator;
409 Generator = 0;
410 }
411 Generator = new BRepOffsetAPI_ThruSections(issolid, isruled);
412
413 Standard_Integer NbEdges = 0;
414 Standard_Boolean IsFirstWire = Standard_False;
415 for (Standard_Integer i = index + 2; i <= n - 1; i++) {
416 Standard_Boolean IsWire = Standard_True;
417 Shape = DBRep::Get(a[i], TopAbs_WIRE);
418 if (!Shape.IsNull())
419 {
420 Generator->AddWire(TopoDS::Wire(Shape));
421 if (!IsFirstWire)
422 IsFirstWire = Standard_True;
423 else
424 IsFirstWire = Standard_False;
425 }
426 else
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 }
435
436 Standard_Integer cpt = 0;
437 TopExp_Explorer PE;
438 for (PE.Init(Shape, TopAbs_EDGE); PE.More(); PE.Next()) {
439 cpt++;
440 }
441 if (IsFirstWire)
442 NbEdges = cpt;
443 else
444 if (IsWire && cpt != NbEdges)
445 samenumber = Standard_False;
446
447 }
448
449 check = (check || !samenumber);
450 Generator->CheckCompatibility(check);
451
452 Generator->Build();
453
454 if (Generator->IsDone()) {
455 TopoDS_Shape Shell = Generator->Shape();
456 DBRep::Set(a[index - 1], Shell);
457 // Save history of the lofting
458 if (BRepTest_Objects::IsHistoryNeeded())
459 BRepTest_Objects::SetHistory(Generator->Wires(), *Generator);
460 }
461 else {
462 cout << "Algorithm is not done" << endl;
463 }
464
465 return 0;
466}
467
468//=======================================================================
469// mksweep
470//=======================================================================
471static Standard_Integer mksweep(Draw_Interpretor&,
472 Standard_Integer n, const char** a)
473{
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;
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,
489 Standard_Integer n, const char** a)
490{
491 if (n == 1) {
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;
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";
507 di << " -DX Surf : Tangent and Normal are given by Darboux trihedron,\n";
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";
512 return 0;
513 }
514
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")) {
521 Sweep->SetMode(Standard_True);
522 }
523 else if (!strcmp(a[1], "-CF")) {
524 Sweep->SetMode(Standard_False);
525 }
526 else if (!strcmp(a[1], "-DT")) {
527 Sweep->SetDiscreteMode();
528 }
529 else if (!strcmp(a[1], "-DX")) {
530 if (n != 3) {
531 //cout << "bad arguments !" << endl;
532 di << "bad arguments !\n";
533 return 1;
534 }
535 TopoDS_Shape Surf;
536 Surf = DBRep::Get(a[2], TopAbs_SHAPE);
537 if (Surf.IsNull()) {
538 //cout << a[2] <<"is not a shape !" << endl;
539 di << a[2] << "is not a shape !\n";
540 return 1;
541 }
542 Sweep->SetMode(Surf);
543 }
544 else if (!strcmp(a[1], "-CN")) {
545 if (n != 5) {
546 //cout << "bad arguments !" << endl;
547 di << "bad arguments !\n";
548 return 1;
549 }
550 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
551 Sweep->SetMode(D);;
552 }
553 else if (!strcmp(a[1], "-FX")) {
554 if ((n != 5) && (n != 8)) {
555 //cout << "bad arguments !" << endl;
556 di << "bad arguments !\n";
557 return 1;
558 }
559 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
560 if (n == 8) {
561 gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
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 }
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
579 {
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);
586 }
587 }
588
589 else {
590 //cout << "The option "<< a[1] << " is unknown !" << endl;
591 di << "The option " << a[1] << " is unknown !\n";
592 return 1;
593 }
594 return 0;
595}
596
597
598//=======================================================================
599// addsweep
600//=======================================================================
601static Standard_Integer addsweep(Draw_Interpretor& di,
602 Standard_Integer n, const char** a)
603{
604 if (n == 1) {
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;
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";
615 return 0;
616 }
617
618 if (Sweep == 0) {
619 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
620 di << "You have forgotten the <<mksweep>> command !\n";
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);
629 if (Section.IsNull() ||
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 }
637
638 Standard_Boolean HasVertex = Standard_False,
639 isT = Standard_False,
640 isR = Standard_False;
641
642 if (n > 2) {
643 Standard_Integer cur = 2;
644 // Reading of Vertex
645 TopoDS_Shape InputVertex(DBRep::Get(a[cur], TopAbs_VERTEX));
646 Vertex = TopoDS::Vertex(InputVertex);
647 // Vertex = TopoDS::Vertex(DBRep::Get(a[cur],TopAbs_VERTEX));
648 if (!Vertex.IsNull()) {
649 cur++;
650 HasVertex = Standard_True;
651 }
652
653 // Reading of the translation option
654 if ((n > cur) && !strcmp(a[cur], "-T")) {
655 cur++;
656 isT = Standard_True;
657 }
658
659 // Reading of the rotation option
660 if ((n > cur) && !strcmp(a[cur], "-R")) {
661 cur++;
662 isR = Standard_True;
663 }
664
665 // law ?
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) {
676 ParAndRad(ii).SetX(Draw::Atof(a[cur]));
677 ParAndRad(ii).SetY(Draw::Atof(a[cur + 1]));
678 }
679 thelaw = new (Law_Interpol)();
680 thelaw->Set(ParAndRad,
681 Abs(ParAndRad(1).Y() - ParAndRad(L).Y()) < Precision::Confusion());
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,
702 Standard_Integer n, const char** a)
703{
704 if (n != 2) {
705 return 1;
706 }
707 TopoDS_Wire Section;
708 TopoDS_Shape InputShape(DBRep::Get(a[1], TopAbs_SHAPE));
709 Section = TopoDS::Wire(InputShape);
710 // Section = TopoDS::Wire(DBRep::Get(a[1],TopAbs_SHAPE));
711 if (Section.IsNull()) {
712 //cout << a[1] <<"is not a wire !" << endl;
713 di << a[1] << "is not a wire !\n";
714 return 1;
715 }
716
717 Sweep->Delete(Section);
718
719 return 0;
720}
721
722//=======================================================================
723// buildsweep
724//=======================================================================
725static Standard_Integer buildsweep(Draw_Interpretor& di,
726 Standard_Integer n, const char** a)
727{
728 if (n == 1) {
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;
737 di << "build sweep result [-M/-C/-R] [-S] [tol] : options are\n";
738 di << " -M : Discontinuities are treated by Modfication of\n";
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";
745 return 0;
746 }
747
748 Standard_Boolean mksolid = Standard_False;
749 if (Sweep == 0) {
750 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
751 di << "You have forgotten the <<mksweep>> command !\n";
752 return 1;
753 }
754
755 if (!Sweep->IsReady()) {
756 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
757 di << "You have forgotten the <<addsweep>> command !\n";
758 return 1;
759 }
760
761 TopoDS_Shape result;
762 Standard_Integer cur = 2;
763 if (n > cur) {
764 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
765
766 // Reading Transition
767 if (!strcmp(a[cur], "-C")) {
768 Transition = BRepBuilderAPI_RightCorner;
769 cur++;
770 }
771 else if (!strcmp(a[cur], "-R")) {
772 Transition = BRepBuilderAPI_RoundCorner;
773 cur++;
774 }
775 Sweep->SetTransitionMode(Transition);
776 }
777 // Reading solid ?
778 if ((n > cur) && (!strcmp(a[cur], "-S"))) mksolid = Standard_True;
779
780 // Calcul le resultat
781 Sweep->Build();
782 if (!Sweep->IsDone()) {
783 //cout << "Buildsweep : Not Done" << endl;
784 di << "Buildsweep : Not Done\n";
785 BRepBuilderAPI_PipeError Stat = Sweep->GetStatus();
786 if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) {
787 //cout << "Buildsweep : One Plane not intersect the guide" << endl;
788 di << "Buildsweep : One Plane not intersect the guide\n";
789 }
790 if (Stat == BRepBuilderAPI_ImpossibleContact) {
791 //cout << "BuildSweep : One section can not be in contact with the guide" << endl;
792 di << "BuildSweep : One section can not be in contact with the guide\n";
793 }
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;
800 if (!B) di << " BuildSweep : It is impossible to make a solid !\n";
801 }
802 result = Sweep->Shape();
803 DBRep::Set(a[1], result);
804 // Save history of sweep
805 if (BRepTest_Objects::IsHistoryNeeded())
806 {
807 TopTools_ListOfShape aList;
808 Sweep->Profiles(aList);
809 TopoDS_Shape aSpine = Sweep->Spine();
810 aList.Append(aSpine);
811 BRepTest_Objects::SetHistory(aList, *Sweep);
812 }
813 }
814
815 return 0;
816}
817
818//=======================================================================
819//function : errorsweep
820//purpose : returns the summary error on resulting surfaces
821// reached by Sweep
822//=======================================================================
823static Standard_Integer errorsweep(Draw_Interpretor& di,
824 Standard_Integer, const char**)
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//=======================================================================
837// simulsweep
838//=======================================================================
839static Standard_Integer simulsweep(Draw_Interpretor& di,
840 Standard_Integer n, const char** a)
841{
842 if ((n != 3) && (n != 4)) return 1;
843
844 if (Sweep == 0) {
845 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
846 di << "You have forgotten the <<mksweep>> command !\n";
847 return 1;
848 }
849
850 if (!Sweep->IsReady()) {
851 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
852 di << "You have forgotten the <<addsweep>> command !\n";
853 return 1;
854 }
855
856 char name[100];
857 TopTools_ListOfShape List;
858 TopTools_ListIteratorOfListOfShape it;
859 Standard_Integer N, ii;
860 N = Draw::Atoi(a[2]);
861
862 if (n > 3) {
863 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
864 // Lecture Transition
865 if (!strcmp(a[3], "-C")) {
866 Transition = BRepBuilderAPI_RightCorner;
867 }
868 else if (!strcmp(a[3], "-R")) {
869 Transition = BRepBuilderAPI_RoundCorner;
870 }
871 Sweep->SetTransitionMode(Transition);
872 }
873
874 // Calculate the result
875 Sweep->Simulate(N, List);
876 for (ii = 1, it.Initialize(List); it.More(); it.Next(), ii++) {
877 Sprintf(name, "%s_%d", a[1], ii);
878 DBRep::Set(name, it.Value());
879 }
880
881 return 0;
882}
883
884//=======================================================================
885// middlepath
886//=======================================================================
887static Standard_Integer middlepath(Draw_Interpretor& /*di*/,
888 Standard_Integer n, const char** a)
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;
897
898 TopoDS_Shape EndShape = DBRep::Get(a[4]);
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//=======================================================================
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";
924
925 theCommands.Add("prism",
926 "prism result base dx dy dz [Copy | Inf | Seminf]",
927 __FILE__, prism, g);
928
929 theCommands.Add("revol",
930 "revol result base px py pz dx dy dz angle [Copy]",
931 __FILE__, revol, g);
932
933 theCommands.Add("pipe",
934 "pipe result Wire_spine Profile [Mode [Approx]], no args to get help",
935 __FILE__, pipe, g);
936
937 theCommands.Add("evolved",
938 "evolved , no args to get help",
939 __FILE__, evolved, g);
940
941 theCommands.Add("evolvedsolid",
942 "evolved , no args to get help",
943 __FILE__, evolved, g);
944
945 theCommands.Add("pruled",
946 "pruled result Edge1/Wire1 Edge2/Wire2",
947 __FILE__, pruled, g);
948
949 theCommands.Add("gener", "gener result wire1 wire2 [..wire..]",
950 __FILE__, gener, g);
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)",
953 __FILE__, thrusections, g);
954
955 theCommands.Add("mksweep", "mksweep wire",
956 __FILE__, mksweep, g);
957
958 theCommands.Add("setsweep", "setsweep no args to get help",
959 __FILE__, setsweep, g);
960
961 theCommands.Add("addsweep",
962 "addsweep wire [vertex] [-M ] [-C] [auxiilaryshape]:no args to get help",
963 __FILE__, addsweep, g);
964
965 theCommands.Add("deletesweep",
966 "deletesweep wire, To delete a section",
967 __FILE__, deletesweep, g);
968
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);
974
975 theCommands.Add("simulsweep", "simulsweep r [n] [option]"
976 __FILE__, simulsweep, g);
977 theCommands.Add("geompipe", "geompipe r spineedge profileedge radius [byACR [byrotate]]"
978 __FILE__, geompipe, g);
979
980 theCommands.Add("middlepath", "middlepath res shape startshape endshape",
981 __FILE__, middlepath, g);
982}
983