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