0030347: Mesh, BRepMesh_ModelPostProcessor - NCollection_Array1 throws Standard_Range...
[occt.git] / src / BRepTest / BRepTest_SweepCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-07-22
2// Created by: Remi LEQUETTE
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepTest.hxx>
4f7d41ea 18
19#include <BRepTest_Objects.hxx>
20
7fd59977 21#include <DBRep.hxx>
22#include <Draw_Interpretor.hxx>
23#include <Draw_Appli.hxx>
24
25#include <BRepFill.hxx>
26#include <BRepBuilderAPI_PipeError.hxx>
27#include <BRepFill_Generator.hxx>
28#include <BRepPrimAPI_MakePrism.hxx>
29#include <BRepPrimAPI_MakeRevol.hxx>
30#include <BRepOffsetAPI_MakePipe.hxx>
31#include <BRepOffsetAPI_MakeEvolved.hxx>
32#include <BRepOffsetAPI_ThruSections.hxx>
33#include <BRepOffsetAPI_MakePipeShell.hxx>
2277323d 34#include <BRepOffsetAPI_MiddlePath.hxx>
7fd59977 35
36#include <BRepLib_MakeWire.hxx>
37#include <TopoDS.hxx>
38#include <TopTools_ListIteratorOfListOfShape.hxx>
39#include <TopExp_Explorer.hxx>
40
41#include <Precision.hxx>
42#include <Law_Interpol.hxx>
43#include <gp_Ax1.hxx>
44#include <gp_Ax2.hxx>
45#include <gp_Pnt2d.hxx>
46#include <TColgp_Array1OfPnt2d.hxx>
47
48static BRepOffsetAPI_MakePipeShell* Sweep= 0;
50258e77 49static BRepOffsetAPI_ThruSections* Generator = 0;
7fd59977 50
7fd59977 51#include <stdio.h>
52#include <Geom_Curve.hxx>
53#include <GeomAdaptor_HCurve.hxx>
54#include <GeomFill_Pipe.hxx>
55#include <Geom_Surface.hxx>
56#include <BRepBuilderAPI_MakeFace.hxx>
57#include <BRep_Tool.hxx>
58#include <gp_Pnt.hxx>
7fd59977 59#include <gp_Vec.hxx>
60#include <Geom_Circle.hxx>
61#include <gp_Ax2.hxx>
62
f9032cf2 63
7fd59977 64//=======================================================================
65// prism
66//=======================================================================
67
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
91322f44 75 gp_Vec V(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 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//=======================================================================
7fd59977 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
91322f44 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]));
7fd59977 113 gp_Ax1 A(P,D);
114
91322f44 115 Standard_Real angle = Draw::Atof(a[9]) * (M_PI / 180.0);
7fd59977 116
117 Standard_Boolean copy = n > 10;
118
7e4ff648 119
120 BRepPrimAPI_MakeRevol Revol(base, A, angle, copy);
121
122 TopoDS_Shape res = Revol.Shape();
7fd59977 123
124 DBRep::Set(a[1],res);
125
7e4ff648 126 //History
127 TopTools_ListOfShape anArgs;
128 anArgs.Append(base);
129 BRepTest_Objects::SetHistory(anArgs, Revol);
130
7fd59977 131 return 0;
132}
133
134
135//=======================================================================
136// pipe
137//=======================================================================
138
471ce736 139static Standard_Integer pipe(Draw_Interpretor& di,
7fd59977 140 Standard_Integer n, const char** a)
141{
471ce736 142 if (n == 1)
143 {
586db386 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";
471ce736 149 return 0;
150 }
151
152 if (n > 1 && n < 4) return 1;
7fd59977 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;
471ce736 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;
7fd59977 173
471ce736 174 TopoDS_Shape S = BRepOffsetAPI_MakePipe(TopoDS::Wire(Spine),
175 Profile,
176 Mode,
177 ForceApproxC1);
7fd59977 178
179 DBRep::Set(a[1],S);
180
181 return 0;
182}
471ce736 183
7fd59977 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;
91322f44 200 Standard_Real Radius = Draw::Atof(a[4]);
7fd59977 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)
91322f44 209 ByACR = (Draw::Atoi(a[k++]) ==1);
7fd59977 210 if(n > k)
91322f44 211 rotate = (Draw::Atoi(a[k++])==1);
7fd59977 212 GeomFill_Pipe aPipe(ProfileCurve,aAdaptCurve,cStart,ByACR,rotate);
213 aPipe.Perform(Standard_True);
a8b52677 214 if (!aPipe.IsDone())
215 {
216 cout << "GeomFill_Pipe cannot make a surface" << endl;
217 return 1;
218 }
7fd59977 219 Handle(Geom_Surface) Sur=aPipe.Surface();
220 TopoDS_Face F;
221 if(!Sur.IsNull())
1c72dff6 222 F = BRepBuilderAPI_MakeFace(Sur, Precision::Confusion());
7fd59977 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;
586db386 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";
7fd59977 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
50258e77 337 BRepFill_Generator aGenerator;
7fd59977 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
50258e77 344 aGenerator.AddWire(TopoDS::Wire(Shape));
7fd59977 345 }
346
50258e77 347 aGenerator.Perform();
7fd59977 348
50258e77 349 TopoDS_Shell Shell = aGenerator.Shell();
7fd59977 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
91322f44 379 Standard_Boolean issolid = ( Draw::Atoi(a[index]) == 1 );
380 Standard_Boolean isruled = ( Draw::Atoi(a[index+1]) == 1 );
7fd59977 381
50258e77 382 if (Generator != 0)
383 {
384 delete Generator;
385 Generator = 0;
386 }
387 Generator = new BRepOffsetAPI_ThruSections(issolid,isruled);
7fd59977 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 {
50258e77 396 Generator->AddWire(TopoDS::Wire(Shape));
7fd59977 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())
50258e77 407 Generator->AddVertex(TopoDS::Vertex(Shape));
7fd59977 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);
50258e77 426 Generator->CheckCompatibility(check);
7fd59977 427
50258e77 428 Generator->Build();
7fd59977 429
50258e77 430 if (Generator->IsDone()) {
431 TopoDS_Shape Shell = Generator->Shape();
a4bb1420 432 DBRep::Set(a[index-1], Shell);
4f7d41ea 433 // Save history of the lofting
948fe6ca 434 if (BRepTest_Objects::IsHistoryNeeded())
435 BRepTest_Objects::SetHistory(Generator->Wires(), *Generator);
a4bb1420 436 }
437 else {
438 cout << "Algorithm is not done" << endl;
439 }
50258e77 440
50258e77 441 return 0;
442}
443
7fd59977 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;
586db386 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";
7fd59977 488 return 0;
489 }
490
491 if (Sweep ==0) {
492 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 493 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 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 }
a31abc03 502 else if (!strcmp(a[1],"-DT")) {
503 Sweep->SetDiscreteMode();
504 }
7fd59977 505 else if (!strcmp(a[1],"-DX")) {
506 if (n!=3) {
507 //cout << "bad arguments !" << endl;
586db386 508 di << "bad arguments !\n";
7fd59977 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;
586db386 515 di << a[2] <<"is not a shape !\n";
7fd59977 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;
586db386 523 di << "bad arguments !\n";
7fd59977 524 return 1;
525 }
91322f44 526 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 527 Sweep->SetMode(D);;
528 }
529 else if (!strcmp(a[1],"-FX")) {
530 if ((n!=5)&&(n!=8)) {
531 //cout << "bad arguments !" << endl;
586db386 532 di << "bad arguments !\n";
7fd59977 533 return 1;
534 }
91322f44 535 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 536 if (n==8) {
91322f44 537 gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
7fd59977 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;
586db386 551 di << "bad arguments !\n";
7fd59977 552 return 1;
553 }
554 else
555 {
556 TopoDS_Shape Guide = DBRep::Get(a[2],TopAbs_WIRE);
dde68833 557 Standard_Boolean CurvilinearEquivalence = Draw::Atoi(a[3]) != 0;
f9032cf2 558 Standard_Integer KeepContact = Draw::Atoi(a[4]);
559 Sweep->SetMode(TopoDS::Wire(Guide),
560 CurvilinearEquivalence,
561 (BRepFill_TypeOfContact)KeepContact);
7fd59977 562 }
563 }
564
565 else {
566 //cout << "The option "<< a[1] << " is unknown !" << endl;
586db386 567 di << "The option "<< a[1] << " is unknown !\n";
7fd59977 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;
586db386 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";
7fd59977 591 return 0;
592 }
593
594 if (Sweep ==0) {
595 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 596 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 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);
8878d0ec 605 if (Section.IsNull() ||
606 (Section.ShapeType() != TopAbs_WIRE &&
607 Section.ShapeType() != TopAbs_VERTEX))
7fd59977 608 {
609 //cout << a[1] <<"is not a wire and is not a vertex!" << endl;
8878d0ec 610 di << a[1] <<" is not a wire and is not a vertex!\n";
7fd59977 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;
0d969553 620 // Reading of Vertex
7fd59977 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
0d969553 629 // Reading of the translation option
7fd59977 630 if ((n>cur) && !strcmp(a[cur],"-T")) {
631 cur++;
632 isT = Standard_True;
633 }
634
0d969553 635 // Reading of the rotation option
7fd59977 636 if ((n>cur) && !strcmp(a[cur],"-R")) {
637 cur++;
638 isR = Standard_True;
639 }
640
0d969553 641 // law ?
7fd59977 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";
0d969553 647 } else { //law of interpolation
7fd59977 648 Standard_Integer ii, L= nbreal/2;
649 TColgp_Array1OfPnt2d ParAndRad(1, L);
650 for (ii=1; ii<=L; ii++, cur+=2) {
f9032cf2 651 ParAndRad(ii).SetX(Draw::Atof(a[cur]));
652 ParAndRad(ii).SetY(Draw::Atof(a[cur+1]));
653 }
7fd59977 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;
586db386 688 di << a[1] <<"is not a wire !\n";
7fd59977 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;
586db386 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";
7fd59977 720 return 0;
721 }
722
723 Standard_Boolean mksolid = Standard_False;
724 if (Sweep ==0) {
725 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 726 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 727 return 1;
728 }
729
730 if (!Sweep->IsReady()) {
731 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
586db386 732 di << "You have forgotten the <<addsweep>> command !\n";
7fd59977 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
0d969553 741 // Reading Transition
7fd59977 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 }
0d969553 752 // Reading solid ?
7fd59977 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;
586db386 759 di << "Buildsweep : Not Done\n";
7fd59977 760 BRepBuilderAPI_PipeError Stat = Sweep->GetStatus();
761 if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) {
762 //cout << "Buildsweep : One Plane not intersect the guide" << endl;
586db386 763 di << "Buildsweep : One Plane not intersect the guide\n";
7fd59977 764 }
765 if (Stat == BRepBuilderAPI_ImpossibleContact) {
766 //cout << "BuildSweep : One section can not be in contact with the guide" << endl;
586db386 767 di << "BuildSweep : One section can not be in contact with the guide\n";
7fd59977 768 }
7fd59977 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;
586db386 775 if (!B) di << " BuildSweep : It is impossible to make a solid !\n";
7fd59977 776 }
777 result = Sweep->Shape();
778 DBRep::Set(a[1],result);
4f7d41ea 779 // Save history of sweep
948fe6ca 780 if (BRepTest_Objects::IsHistoryNeeded())
781 {
a922aab5 782 TopTools_ListOfShape aList;
783 Sweep->Profiles(aList);
784 TopoDS_Shape aSpine = Sweep->Spine();
785 aList.Append(aSpine);
786 BRepTest_Objects::SetHistory(aList, *Sweep);
948fe6ca 787 }
7fd59977 788 }
789
790 return 0;
791}
792
793//=======================================================================
107f794f 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//=======================================================================
7fd59977 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;
586db386 821 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 822 return 1;
823 }
824
825 if (!Sweep->IsReady()) {
826 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
586db386 827 di << "You have forgotten the <<addsweep>> command !\n";
7fd59977 828 return 1;
829 }
830
831 char name[100];
832 TopTools_ListOfShape List;
833 TopTools_ListIteratorOfListOfShape it;
834 Standard_Integer N, ii;
91322f44 835 N = Draw::Atoi(a[2]);
7fd59977 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
0d969553 849 // Calculate the result
7fd59977 850 Sweep->Simulate(N, List);
851 for (ii=1, it.Initialize(List); it.More(); it.Next(), ii++) {
91322f44 852 Sprintf(name,"%s_%d",a[1],ii);
7fd59977 853 DBRep::Set(name, it.Value());
854 }
855
856 return 0;
857}
858
859//=======================================================================
2277323d 860// middlepath
861//=======================================================================
35e08fe8 862static Standard_Integer middlepath(Draw_Interpretor& /*di*/,
2277323d 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//=======================================================================
7fd59977 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",
471ce736 909 "pipe result Wire_spine Profile [Mode [Approx]], no args to get help",
7fd59977 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);
7fd59977 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
953d87f3 944 theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help",
7fd59977 945 __FILE__,buildsweep,g);
946
107f794f 947 theCommands.Add("errorsweep", "errorsweep: returns the summary error on resulting surfaces reached by Sweep",
948 __FILE__,errorsweep,g);
949
7fd59977 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);
2277323d 954
955 theCommands.Add("middlepath", "middlepath res shape startshape endshape",
956 __FILE__,middlepath,g);
7fd59977 957}
958