0029694: Geom2dGcc_Circ2dTanCenGeo crash
[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
434 BRepTest_Objects::SetHistory(Generator->Wires(), *Generator);
a4bb1420 435 }
436 else {
437 cout << "Algorithm is not done" << endl;
438 }
50258e77 439
50258e77 440 return 0;
441}
442
7fd59977 443//=======================================================================
444// mksweep
445//=======================================================================
446static Standard_Integer mksweep(Draw_Interpretor& ,
447 Standard_Integer n, const char** a)
448{
449 if ( n != 2) return 1;
450 TopoDS_Shape Spine = DBRep::Get(a[1],TopAbs_WIRE);
451 if ( Spine.IsNull()) return 1;
452 if (Sweep !=0) {
453 delete Sweep;
454 Sweep = 0;
455 }
456 Sweep = new BRepOffsetAPI_MakePipeShell(TopoDS::Wire(Spine));
457 return 0;
458}
459
460//=======================================================================
461// setsweep
462//=======================================================================
463static Standard_Integer setsweep(Draw_Interpretor& di,
464 Standard_Integer n, const char** a)
465{
466 if ( n == 1) {
467 //cout << "setsweep options [arg1 [arg2 [...]]] : options are :" << endl;
468 //cout << " -FR : Tangent and Normal are given by Frenet trihedron" <<endl;
469 //cout << " -CF : Tangente is given by Frenet," << endl;
470 //cout << " the Normal is computed to minimize the torsion " << endl;
471 //cout << " -DX Surf : Tangent and Normal are given by Darboux trihedron,"
472 // <<endl;
473 //cout << " Surf have to be a shell or a face" <<endl;
474 //cout << " -CN dx dy dz : BiNormal is given by dx dy dz" << endl;
475 //cout << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed" <<endl;
476 //cout << " -G guide 0|1(ACR|Plan) 0|1(contact|no contact) : with guide"<<endl;
586db386 477 di << "setsweep options [arg1 [arg2 [...]]] : options are :\n";
478 di << " -FR : Tangent and Normal are given by Frenet trihedron\n";
479 di << " -CF : Tangente is given by Frenet,\n";
480 di << " the Normal is computed to minimize the torsion \n";
481 di << " -DT : discrete trihedron\n";
482 di << " -DX Surf : Tangent and Normal are given by Darboux trihedron,\n";
483 di << " Surf have to be a shell or a face\n";
484 di << " -CN dx dy dz : BiNormal is given by dx dy dz\n";
485 di << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed\n";
486 di << " -G guide 0|1(Plan|ACR) 0|1|2(no contact|contact|contact on border) : with guide\n";
7fd59977 487 return 0;
488 }
489
490 if (Sweep ==0) {
491 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 492 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 493 return 1;
494 }
495 if (!strcmp(a[1],"-FR")) {
496 Sweep->SetMode(Standard_True);
497 }
498 else if (!strcmp(a[1],"-CF")) {
499 Sweep->SetMode(Standard_False);
500 }
a31abc03 501 else if (!strcmp(a[1],"-DT")) {
502 Sweep->SetDiscreteMode();
503 }
7fd59977 504 else if (!strcmp(a[1],"-DX")) {
505 if (n!=3) {
506 //cout << "bad arguments !" << endl;
586db386 507 di << "bad arguments !\n";
7fd59977 508 return 1;
509 }
510 TopoDS_Shape Surf;
511 Surf = DBRep::Get(a[2],TopAbs_SHAPE);
512 if (Surf.IsNull()) {
513 //cout << a[2] <<"is not a shape !" << endl;
586db386 514 di << a[2] <<"is not a shape !\n";
7fd59977 515 return 1;
516 }
517 Sweep->SetMode(Surf);
518 }
519 else if (!strcmp(a[1],"-CN")) {
520 if (n!=5) {
521 //cout << "bad arguments !" << endl;
586db386 522 di << "bad arguments !\n";
7fd59977 523 return 1;
524 }
91322f44 525 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 526 Sweep->SetMode(D);;
527 }
528 else if (!strcmp(a[1],"-FX")) {
529 if ((n!=5)&&(n!=8)) {
530 //cout << "bad arguments !" << endl;
586db386 531 di << "bad arguments !\n";
7fd59977 532 return 1;
533 }
91322f44 534 gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
7fd59977 535 if (n==8) {
91322f44 536 gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7]));
7fd59977 537 gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D, DN);
538 Sweep->SetMode(Axe);
539 }
540 else {
541 gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D);
542 Sweep->SetMode(Axe);
543 }
544 }
545 else if (!strcmp(a[1],"-G")) // contour guide
546 {
547 if (n != 5)
548 {
549 //cout << "bad arguments !" << endl;
586db386 550 di << "bad arguments !\n";
7fd59977 551 return 1;
552 }
553 else
554 {
555 TopoDS_Shape Guide = DBRep::Get(a[2],TopAbs_WIRE);
dde68833 556 Standard_Boolean CurvilinearEquivalence = Draw::Atoi(a[3]) != 0;
f9032cf2 557 Standard_Integer KeepContact = Draw::Atoi(a[4]);
558 Sweep->SetMode(TopoDS::Wire(Guide),
559 CurvilinearEquivalence,
560 (BRepFill_TypeOfContact)KeepContact);
7fd59977 561 }
562 }
563
564 else {
565 //cout << "The option "<< a[1] << " is unknown !" << endl;
586db386 566 di << "The option "<< a[1] << " is unknown !\n";
7fd59977 567 return 1;
568 }
569 return 0;
570}
571
572
573//=======================================================================
574// addsweep
575//=======================================================================
576static Standard_Integer addsweep(Draw_Interpretor& di,
577 Standard_Integer n, const char** a)
578{
579 if ( n == 1) {
580 //cout << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :" << endl;
581 //cout << " -T : the wire/vertex have to be translated to assume contact"<< endl;
582 //cout << " with the spine" <<endl;
583 //cout << " -R : the wire have to be rotated to assume orthogonality"<<endl;
584 //cout << " with the spine's tangent" << endl;
586db386 585 di << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :\n";
586 di << " -T : the wire/vertex have to be translated to assume contact\n";
587 di << " with the spine\n";
588 di << " -R : the wire have to be rotated to assume orthogonality\n";
589 di << " with the spine's tangent\n";
7fd59977 590 return 0;
591 }
592
593 if (Sweep ==0) {
594 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 595 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 596 return 1;
597 }
598
599 TopoDS_Shape Section;
600 TopoDS_Vertex Vertex;
601 Handle(Law_Interpol) thelaw;
602
603 Section = DBRep::Get(a[1], TopAbs_SHAPE);
8878d0ec 604 if (Section.IsNull() ||
605 (Section.ShapeType() != TopAbs_WIRE &&
606 Section.ShapeType() != TopAbs_VERTEX))
7fd59977 607 {
608 //cout << a[1] <<"is not a wire and is not a vertex!" << endl;
8878d0ec 609 di << a[1] <<" is not a wire and is not a vertex!\n";
7fd59977 610 return 1;
611 }
612
613 Standard_Boolean HasVertex=Standard_False,
614 isT=Standard_False,
615 isR=Standard_False;
616
617 if (n > 2) {
618 Standard_Integer cur = 2;
0d969553 619 // Reading of Vertex
7fd59977 620 TopoDS_Shape InputVertex(DBRep::Get(a[cur],TopAbs_VERTEX));
621 Vertex = TopoDS::Vertex(InputVertex);
622// Vertex = TopoDS::Vertex(DBRep::Get(a[cur],TopAbs_VERTEX));
623 if (!Vertex.IsNull()) {
624 cur++;
625 HasVertex = Standard_True;
626 }
627
0d969553 628 // Reading of the translation option
7fd59977 629 if ((n>cur) && !strcmp(a[cur],"-T")) {
630 cur++;
631 isT = Standard_True;
632 }
633
0d969553 634 // Reading of the rotation option
7fd59977 635 if ((n>cur) && !strcmp(a[cur],"-R")) {
636 cur++;
637 isR = Standard_True;
638 }
639
0d969553 640 // law ?
7fd59977 641 if (n>cur) {
642 Standard_Integer nbreal = n-cur;
643 if ( (nbreal < 4) || (nbreal % 2 != 0) ) {
644 //cout << "bad arguments ! :" <<a[cur] << endl;
645 di << "bad arguments ! :" <<a[cur] << "\n";
0d969553 646 } else { //law of interpolation
7fd59977 647 Standard_Integer ii, L= nbreal/2;
648 TColgp_Array1OfPnt2d ParAndRad(1, L);
649 for (ii=1; ii<=L; ii++, cur+=2) {
f9032cf2 650 ParAndRad(ii).SetX(Draw::Atof(a[cur]));
651 ParAndRad(ii).SetY(Draw::Atof(a[cur+1]));
652 }
7fd59977 653 thelaw = new (Law_Interpol) ();
654 thelaw->Set(ParAndRad,
655 Abs(ParAndRad(1).Y() - ParAndRad(L).Y()) < Precision::Confusion());
656 }
657 }
658 }
659
660 if (thelaw.IsNull()) {
661 if (HasVertex) Sweep->Add(Section, Vertex, isT, isR);
662 else Sweep->Add(Section, isT, isR);
663 }
664 else {
665 if (HasVertex) Sweep->SetLaw(Section, thelaw, Vertex, isT, isR);
666 else Sweep->SetLaw(Section, thelaw, isT, isR);
667 }
668
669 return 0;
670}
671
672//=======================================================================
673// deletesweep
674//=======================================================================
675static Standard_Integer deletesweep(Draw_Interpretor& di,
676 Standard_Integer n, const char** a)
677{
678 if ( n != 2) {
679 return 1;
680 }
681 TopoDS_Wire Section;
682 TopoDS_Shape InputShape(DBRep::Get(a[1],TopAbs_SHAPE));
683 Section = TopoDS::Wire(InputShape);
684// Section = TopoDS::Wire(DBRep::Get(a[1],TopAbs_SHAPE));
685 if (Section.IsNull()) {
686 //cout << a[1] <<"is not a wire !" << endl;
586db386 687 di << a[1] <<"is not a wire !\n";
7fd59977 688 return 1;
689 }
690
691 Sweep->Delete(Section);
692
693 return 0;
694}
695
696//=======================================================================
697// buildsweep
698//=======================================================================
699static Standard_Integer buildsweep(Draw_Interpretor& di,
700 Standard_Integer n, const char** a)
701{
702 if ( n == 1) {
703 //cout << "build sweep result [-M/-C/-R] [-S] [tol] : options are" << endl;
704 //cout << " -M : Discontinuities are treated by Modfication of"<< endl;
705 //cout << " the sweeping mode : it is the default" <<endl;
706 //cout << " -C : Discontinuities are treated like Right Corner" << endl;
707 //cout << " Treatement is Extent && Intersect" << endl;
708 //cout << " -R : Discontinuities are treated like Round Corner" << endl;
709 //cout << " Treatement is Intersect and Fill" << endl;
710 //cout << " -S : To build a Solid" << endl;
586db386 711 di << "build sweep result [-M/-C/-R] [-S] [tol] : options are\n";
712 di << " -M : Discontinuities are treated by Modfication of\n";
713 di << " the sweeping mode : it is the default\n";
714 di << " -C : Discontinuities are treated like Right Corner\n";
715 di << " Treatement is Extent && Intersect\n";
716 di << " -R : Discontinuities are treated like Round Corner\n";
717 di << " Treatement is Intersect and Fill\n";
718 di << " -S : To build a Solid\n";
7fd59977 719 return 0;
720 }
721
722 Standard_Boolean mksolid = Standard_False;
723 if (Sweep ==0) {
724 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 725 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 726 return 1;
727 }
728
729 if (!Sweep->IsReady()) {
730 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
586db386 731 di << "You have forgotten the <<addsweep>> command !\n";
7fd59977 732 return 1;
733 }
734
735 TopoDS_Shape result;
736 Standard_Integer cur=2;
737 if (n>cur) {
738 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
739
0d969553 740 // Reading Transition
7fd59977 741 if (!strcmp(a[cur],"-C")) {
742 Transition = BRepBuilderAPI_RightCorner;
743 cur++;
744 }
745 else if (!strcmp(a[cur],"-R")) {
746 Transition = BRepBuilderAPI_RoundCorner;
747 cur++;
748 }
749 Sweep->SetTransitionMode(Transition);
750 }
0d969553 751 // Reading solid ?
7fd59977 752 if ((n>cur) && (!strcmp(a[cur],"-S")) ) mksolid = Standard_True;
753
754 // Calcul le resultat
755 Sweep->Build();
756 if (!Sweep->IsDone()) {
757 //cout << "Buildsweep : Not Done" << endl;
586db386 758 di << "Buildsweep : Not Done\n";
7fd59977 759 BRepBuilderAPI_PipeError Stat = Sweep->GetStatus();
760 if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) {
761 //cout << "Buildsweep : One Plane not intersect the guide" << endl;
586db386 762 di << "Buildsweep : One Plane not intersect the guide\n";
7fd59977 763 }
764 if (Stat == BRepBuilderAPI_ImpossibleContact) {
765 //cout << "BuildSweep : One section can not be in contact with the guide" << endl;
586db386 766 di << "BuildSweep : One section can not be in contact with the guide\n";
7fd59977 767 }
7fd59977 768 }
769 else {
770 if (mksolid) {
771 Standard_Boolean B;
772 B = Sweep->MakeSolid();
773 //if (!B) cout << " BuildSweep : It is impossible to make a solid !" << endl;
586db386 774 if (!B) di << " BuildSweep : It is impossible to make a solid !\n";
7fd59977 775 }
776 result = Sweep->Shape();
777 DBRep::Set(a[1],result);
4f7d41ea 778 // Save history of sweep
779 TopTools_ListOfShape aProfiles;
780 Sweep->Profiles(aProfiles);
781 BRepTest_Objects::SetHistory(aProfiles, *Sweep);
7fd59977 782 }
783
784 return 0;
785}
786
787//=======================================================================
107f794f 788//function : errorsweep
789//purpose : returns the summary error on resulting surfaces
790// reached by Sweep
791//=======================================================================
792static Standard_Integer errorsweep(Draw_Interpretor& di,
793 Standard_Integer, const char**)
794{
795 if (!Sweep->IsDone())
796 {
797 di << "Sweep is not done\n";
798 return 1;
799 }
800 Standard_Real ErrorOnSurfaces = Sweep->ErrorOnSurface();
801 di << "Tolerance on surfaces = " << ErrorOnSurfaces << "\n";
802 return 0;
803}
804
805//=======================================================================
7fd59977 806// simulsweep
807//=======================================================================
808static Standard_Integer simulsweep(Draw_Interpretor& di,
809 Standard_Integer n, const char** a)
810{
811 if ( (n!=3) && (n!=4) ) return 1;
812
813 if (Sweep ==0) {
814 //cout << "You have forgotten the <<mksweep>> command !"<< endl;
586db386 815 di << "You have forgotten the <<mksweep>> command !\n";
7fd59977 816 return 1;
817 }
818
819 if (!Sweep->IsReady()) {
820 //cout << "You have forgotten the <<addsweep>> command !"<< endl;
586db386 821 di << "You have forgotten the <<addsweep>> command !\n";
7fd59977 822 return 1;
823 }
824
825 char name[100];
826 TopTools_ListOfShape List;
827 TopTools_ListIteratorOfListOfShape it;
828 Standard_Integer N, ii;
91322f44 829 N = Draw::Atoi(a[2]);
7fd59977 830
831 if (n>3) {
832 BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed;
833 // Lecture Transition
834 if (!strcmp(a[3],"-C")) {
835 Transition = BRepBuilderAPI_RightCorner;
836 }
837 else if (!strcmp(a[3],"-R")) {
838 Transition = BRepBuilderAPI_RoundCorner;
839 }
840 Sweep->SetTransitionMode(Transition);
841 }
842
0d969553 843 // Calculate the result
7fd59977 844 Sweep->Simulate(N, List);
845 for (ii=1, it.Initialize(List); it.More(); it.Next(), ii++) {
91322f44 846 Sprintf(name,"%s_%d",a[1],ii);
7fd59977 847 DBRep::Set(name, it.Value());
848 }
849
850 return 0;
851}
852
853//=======================================================================
2277323d 854// middlepath
855//=======================================================================
35e08fe8 856static Standard_Integer middlepath(Draw_Interpretor& /*di*/,
2277323d 857 Standard_Integer n, const char** a)
858{
859 if (n < 5) return 1;
860
861 TopoDS_Shape aShape = DBRep::Get(a[2]);
862 if (aShape.IsNull()) return 1;
863
864 TopoDS_Shape StartShape = DBRep::Get(a[3]);
865 if (StartShape.IsNull()) return 1;
866
867 TopoDS_Shape EndShape = DBRep::Get(a[4]);
868 if (EndShape.IsNull()) return 1;
869
870 BRepOffsetAPI_MiddlePath Builder(aShape, StartShape, EndShape);
871 Builder.Build();
872
873 TopoDS_Shape Result = Builder.Shape();
874 DBRep::Set(a[1], Result);
875
876 return 0;
877}
878
879//=======================================================================
7fd59977 880//function : SweepCommands
881//purpose :
882//=======================================================================
883
884void BRepTest::SweepCommands(Draw_Interpretor& theCommands)
885{
886 static Standard_Boolean done = Standard_False;
887 if (done) return;
888 done = Standard_True;
889
890 DBRep::BasicCommands(theCommands);
891
892 const char* g = "Sweep commands";
893
894 theCommands.Add("prism",
895 "prism result base dx dy dz [Copy | Inf | Seminf]",
896 __FILE__,prism,g);
897
898 theCommands.Add("revol",
899 "revol result base px py pz dx dy dz angle [Copy]",
900 __FILE__,revol,g);
901
902 theCommands.Add("pipe",
471ce736 903 "pipe result Wire_spine Profile [Mode [Approx]], no args to get help",
7fd59977 904 __FILE__,pipe,g);
905
906 theCommands.Add("evolved",
907 "evolved , no args to get help",
908 __FILE__,evolved,g);
909
910 theCommands.Add("evolvedsolid",
911 "evolved , no args to get help",
912 __FILE__,evolved,g);
913
914 theCommands.Add("pruled",
915 "pruled result Edge1/Wire1 Edge2/Wire2",
916 __FILE__,pruled,g);
917
918 theCommands.Add("gener", "gener result wire1 wire2 [..wire..]",
919 __FILE__,gener,g);
920
921 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)",
922 __FILE__,thrusections,g);
7fd59977 923
924 theCommands.Add("mksweep", "mksweep wire",
925 __FILE__,mksweep,g);
926
927 theCommands.Add("setsweep", "setsweep no args to get help",
928 __FILE__,setsweep,g);
929
930 theCommands.Add("addsweep",
931 "addsweep wire [vertex] [-M ] [-C] [auxiilaryshape]:no args to get help",
932 __FILE__,addsweep,g);
933
934 theCommands.Add("deletesweep",
935 "deletesweep wire, To delete a section",
936 __FILE__,deletesweep,g);
937
953d87f3 938 theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help",
7fd59977 939 __FILE__,buildsweep,g);
940
107f794f 941 theCommands.Add("errorsweep", "errorsweep: returns the summary error on resulting surfaces reached by Sweep",
942 __FILE__,errorsweep,g);
943
7fd59977 944 theCommands.Add("simulsweep", "simulsweep r [n] [option]"
945 __FILE__,simulsweep,g);
946 theCommands.Add("geompipe", "geompipe r spineedge profileedge radius [byACR [byrotate]]"
947 __FILE__,geompipe,g);
2277323d 948
949 theCommands.Add("middlepath", "middlepath res shape startshape endshape",
950 __FILE__,middlepath,g);
7fd59977 951}
952