1 // Created on: 1995-06-16
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Draw_Interpretor.hxx>
18 #include <Draw_Appli.hxx>
19 #include <DrawTrSurf.hxx>
21 #include <TopTools_ListOfShape.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopTools_MapOfShape.hxx>
24 #include <TopTools_MapIteratorOfMapOfShape.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TopoDS_Wire.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <TopoDS_Compound.hxx>
30 #include <TopoDS_Edge.hxx>
33 #include <Geom_RectangularTrimmedSurface.hxx>
34 #include <Geom_Plane.hxx>
35 #include <Geom_CylindricalSurface.hxx>
38 #include <gp_Cylinder.hxx>
40 //#include <BRepFeat_LocalOperation.hxx>
41 #include <BRepFeat_Builder.hxx>
42 #include <BRepFeat_MakeCylindricalHole.hxx>
43 #include <BRepFeat_SplitShape.hxx>
44 #include <BRepFeat_Gluer.hxx>
46 #include <BRepFeat.hxx>
47 #include <BRepFeat_MakePrism.hxx>
48 #include <BRepFeat_MakeRevol.hxx>
49 #include <BRepFeat_MakePipe.hxx>
50 #include <BRepFeat_MakeDPrism.hxx>
51 #include <BRepFeat_MakeLinearForm.hxx>
52 #include <BRepFeat_MakeRevolutionForm.hxx>
54 #include <LocOpe_FindEdges.hxx>
55 #include <LocOpe_FindEdgesInFace.hxx>
57 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
58 #include <BRepOffsetAPI_MakeThickSolid.hxx>
59 #include <BRep_Tool.hxx>
60 #include <BRep_Builder.hxx>
62 #include <DBRep_DrawableShape.hxx>
63 #include <BRepTest.hxx>
65 #include <BRepFilletAPI_MakeFillet.hxx>
66 #include <ChFi3d_FilletShape.hxx>
68 #include <Precision.hxx>
71 //#define strcasecmp _stricmp Already defined
72 Standard_IMPORT Draw_Viewer dout;
75 static BRepFeat_MakeCylindricalHole theHole;
76 static Standard_Boolean WithControl = Standard_True;
78 Standard_Boolean DownCastingEnforcing = Standard_False;
80 static BRepFeat_MakePrism thePrism;
81 static BRepFeat_MakeDPrism theDPrism;
82 static BRepFeat_MakeRevol theRevol;
83 static BRepFeat_MakePipe thePipe;
84 static BRepFeat_MakeLinearForm theLF;
85 static BRepFeat_MakeRevolutionForm theRF;
87 static Standard_Boolean dprdef = Standard_False;
88 static Standard_Boolean prdef = Standard_False;
89 static Standard_Boolean rvdef = Standard_False;
90 static Standard_Boolean pidef = Standard_False;
91 static Standard_Boolean lfdef = Standard_False;
92 static Standard_Boolean rfdef = Standard_False;
94 static Standard_Real t3d = 1.e-4;
95 static Standard_Real t2d = 1.e-5;
96 static Standard_Real ta = 1.e-2;
97 static Standard_Real fl = 1.e-3;
98 static Standard_Real tapp_angle = 1.e-2;
99 static GeomAbs_Shape blend_cont = GeomAbs_C1;
100 static BRepFilletAPI_MakeFillet* Rakk = 0;
104 static void Print(Draw_Interpretor& di,
105 const BRepFeat_Status St)
107 di << " Error Status : ";
109 case BRepFeat_NoError:
113 case BRepFeat_InvalidPlacement:
114 di << "Invalid placement";
117 case BRepFeat_HoleTooLong:
118 di << "Hole too long";
123 static Standard_Integer Loc(Draw_Interpretor& theCommands,
124 Standard_Integer narg, const char** a)
126 if (narg<6) return 1;
127 TopoDS_Shape S = DBRep::Get(a[2]);
128 TopoDS_Shape T = DBRep::Get(a[3]);
130 Standard_Boolean Fuse;
131 if (!strcasecmp("F",a[4])) {
132 Fuse = Standard_True;
134 else if (!strcasecmp("C",a[4])) {
135 Fuse = Standard_False;
141 TopTools_ListOfShape LF;
142 for (Standard_Integer i=0; i<= narg-6; i++) {
143 TopoDS_Shape aLocalShape(DBRep::Get(a[i+5],TopAbs_FACE));
144 LF.Append(aLocalShape);
145 // LF.Append(TopoDS::Face(DBRep::Get(a[i+5],TopAbs_FACE)));
148 //BRepFeat_LocalOperation BLoc(S);
149 //BLoc.Perform(T,LF,Fuse);
150 //BLoc.BuildPartsOfTool();
151 TopTools_ListOfShape parts;
152 BRepFeat_Builder BLoc;
154 BLoc.SetOperation(Fuse);
155 //BRepFeat_LocalOperation BLoc;
156 //BLoc.Init(S,T,Fuse);
158 BLoc.PartsOfTool(parts);
162 strcpy(newname,a[1]);
164 while (*p != '\0') p++;
167 TopTools_ListIteratorOfListOfShape its(parts);
170 for (; its.More(); its.Next()) {
173 DBRep::Set(newname,its.Value());
177 Standard_Integer qq,ww,ee,button;
180 TopoDS_Shape aLocalShape(DBRep::Get(".",TopAbs_SHELL));
181 S = TopoDS::Shell(aLocalShape);
182 // S = TopoDS::Shell(DBRep::Get(".",TopAbs_SHELL));
183 Draw::LastPick(qq,ww,ee,button);
188 //BLoc.RemovePart(S);
201 } while (button != 3);
204 BLoc.PerformResult();
205 if (!BLoc.ErrorStatus()) {
207 DBRep::Set(a[1],BLoc.Shape());
211 theCommands << "Local operation not done" ;
217 static Standard_Integer HOLE1(Draw_Interpretor& theCommands,
218 Standard_Integer narg, const char** a)
220 if (narg<10 || narg == 11) return 1;
221 TopoDS_Shape S = DBRep::Get(a[2]);
223 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
224 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
226 Standard_Real Radius = Draw::Atof(a[9]);
228 theHole.Init(S,gp_Ax1(Or,Di));
231 theHole.Perform(Radius);
234 Standard_Real pfrom = Draw::Atof(a[10]);
235 Standard_Real pto = Draw::Atof(a[11]);
236 theHole.Perform(Radius,pfrom,pto,WithControl);
240 if (!theHole.ErrorStatus()) {
242 DBRep::Set(a[1],theHole.Shape());
246 theCommands << "Echec de MakeCylindricalHole";
247 Print(theCommands,theHole.Status());
251 static Standard_Integer HOLE2(Draw_Interpretor& theCommands,
252 Standard_Integer narg, const char** a)
254 if (narg<10) return 1;
255 TopoDS_Shape S = DBRep::Get(a[2]);
257 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
258 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
260 Standard_Real Radius = Draw::Atof(a[9]);
262 theHole.Init(S,gp_Ax1(Or,Di));
263 theHole.PerformThruNext(Radius,WithControl);
266 if (!theHole.ErrorStatus()) {
268 DBRep::Set(a[1],theHole.Shape());
272 theCommands << "Echec de MakeCylindricalHole";
273 Print(theCommands,theHole.Status());
277 static Standard_Integer HOLE3(Draw_Interpretor& theCommands,
278 Standard_Integer narg, const char** a)
280 if (narg<10) return 1;
281 TopoDS_Shape S = DBRep::Get(a[2]);
283 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
284 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
286 Standard_Real Radius = Draw::Atof(a[9]);
288 theHole.Init(S,gp_Ax1(Or,Di));
289 theHole.PerformUntilEnd(Radius,WithControl);
291 if (!theHole.ErrorStatus()) {
293 DBRep::Set(a[1],theHole.Shape());
297 theCommands << "Echec de MakeCylindricalHole";
298 Print(theCommands,theHole.Status());
303 static Standard_Integer HOLE4(Draw_Interpretor& theCommands,
304 Standard_Integer narg, const char** a)
306 if (narg<11) return 1;
307 TopoDS_Shape S = DBRep::Get(a[2]);
309 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
310 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
312 Standard_Real Radius = Draw::Atof(a[9]);
313 Standard_Real Length = Draw::Atof(a[10]);
315 theHole.Init(S,gp_Ax1(Or,Di));
316 theHole.PerformBlind(Radius,Length,WithControl);
318 if (!theHole.ErrorStatus()) {
320 DBRep::Set(a[1],theHole.Shape());
324 theCommands << "Echec de MakeCylindricalHole";
325 Print(theCommands,theHole.Status());
329 static Standard_Integer CONTROL(Draw_Interpretor& theCommands,
330 Standard_Integer narg, const char** a)
333 WithControl = strcmp("0",a[1]);
336 theCommands << "Mode avec controle";
339 theCommands << "Mode sans controle";
345 //=======================================================================
348 //=======================================================================
350 static Standard_Integer PRW(Draw_Interpretor& theCommands,
351 Standard_Integer narg, const char** a)
353 if (narg<9) return 1;
354 TopoDS_Shape S = DBRep::Get(a[3]);
355 BRepFeat_MakePrism thePFace;
357 TopoDS_Shape FFrom,FUntil;
358 Standard_Integer borne;
359 Standard_Boolean fuse;
360 if (a[1][0] == 'f' || a[1][0] == 'F') {
361 fuse = Standard_True;
363 else if (a[1][0] == 'c' || a[1][0] == 'C') {
364 fuse = Standard_False;
370 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
374 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
378 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
379 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
380 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
384 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
385 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
390 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
393 Standard_Real Length = V.Magnitude();
394 if (Length < Precision::Confusion()) {
398 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
399 TopoDS_Face F = TopoDS::Face(aLocalShape);
400 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
401 BRepFeat_SplitShape Spls(F);
402 for (Standard_Integer i = borne+1; i<narg; i++) {
405 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
406 wir = TopoDS::Wire(aLocalShape);
407 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
412 const char* Temp = a[i]+1;
413 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
414 wir = TopoDS::Wire(aLocalShape);
415 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
422 TopoDS_Shape ToPrism;
423 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
424 if (lleft.Extent() == 1) {
425 thePFace.Init(S,lleft.First(),F,V,fuse,Standard_True);
426 ToPrism = lleft.First();
432 TopTools_ListIteratorOfListOfShape it;
433 for (it.Initialize(lleft);it.More();it.Next()) {
434 B.Add(Sh,TopoDS::Face(it.Value()));
436 Sh.Closed (BRep_Tool::IsClosed (Sh));
437 thePFace.Init(S,Sh,F,V,fuse,Standard_True);
441 // Recherche des faces de glissement, si on n`a pas sketche sur une face
442 // du shape de depart
444 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
445 TopExp_Explorer exp(S,TopAbs_FACE) ;
446 for ( ;exp.More();exp.Next()) {
447 if (exp.Current().IsSame(F)) {
453 LocOpe_FindEdgesInFace FEIF;
454 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
455 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
456 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
457 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
458 Su = Handle(Geom_RectangularTrimmedSurface)::
459 DownCast(Su)->BasisSurface();
461 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
462 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
463 if (pl.Contains(gp_Lin(pl.Location(),V),
464 Precision::Confusion(),
465 Precision::Angular())) {
466 FEIF.Set(ToPrism,fac);
467 for (FEIF.Init();FEIF.More();FEIF.Next()) {
468 thePFace.Add(FEIF.Edge(),fac);
472 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
474 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
475 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
476 FEIF.Set(ToPrism,fac);
477 for (FEIF.Init();FEIF.More();FEIF.Next()) {
478 thePFace.Add(FEIF.Edge(),fac);
486 thePFace.Perform(Length);
488 else if (borne == 8) {
489 thePFace.Perform(FUntil);
491 else if (borne == 9) {
492 if (!(FFrom.IsNull() || FUntil.IsNull())) {
493 thePFace.Perform(FFrom,FUntil);
495 else if (FFrom.IsNull()) {
496 if (!FUntil.IsNull()) {
497 thePFace.PerformFromEnd(FUntil);
500 thePFace.PerformThruAll();
504 // il faudrait inverser V et appeler PerfomFromEnd...
505 //cout << "Not Implemented" << endl;
506 theCommands << "Not Implemented" << "\n";
509 if (!thePFace.IsDone()) {
510 theCommands << "Local operation not done";
514 DBRep::Set(a[2],thePFace);
520 //=======================================================================
523 //=======================================================================
525 static Standard_Integer PRF(Draw_Interpretor& theCommands,
526 Standard_Integer narg, const char** a)
528 if (narg<8) return 1;
529 TopoDS_Shape S = DBRep::Get(a[3]);
530 BRepFeat_MakePrism thePFace;
531 Standard_Integer borne;
533 TopoDS_Shape FFrom,FUntil;
534 Standard_Boolean fuse;
535 if (a[1][0] == 'f' || a[1][0] == 'F') {
536 fuse = Standard_True;
538 else if (a[1][0] == 'c' || a[1][0] == 'C') {
539 fuse = Standard_False;
546 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
550 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
555 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
556 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
557 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
561 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
562 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
567 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
569 Standard_Real Length = V.Magnitude();
570 if (Length < Precision::Confusion()) {
574 TopoDS_Shape ToPrism;
575 if (narg == borne+1) {
576 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
577 TopoDS_Face F = TopoDS::Face(aLocalShape);
578 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
579 thePFace.Init(S,F,F,V,fuse,Standard_True);
586 for (Standard_Integer i=borne; i<narg; i++) {
587 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
588 TopoDS_Face F = TopoDS::Face(aLocalShape);
589 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
594 She.Closed (BRep_Tool::IsClosed (She));
595 thePFace.Init(S,She,TopoDS_Face(),V,fuse,Standard_False);
599 // Recherche des faces de glissement, on ne prisme pas une face
600 // du shape de depart
602 // for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
603 TopExp_Explorer exp(ToPrism,TopAbs_FACE) ;
604 for ( ;exp.More();exp.Next()) {
605 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
606 TopExp_Explorer exp2(S,TopAbs_FACE) ;
607 for ( ;exp2.More();exp2.Next()) {
608 if (exp2.Current().IsSame(exp.Current())) {
618 LocOpe_FindEdgesInFace FEIF;
619 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
620 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
621 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
622 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
623 Su = Handle(Geom_RectangularTrimmedSurface)::
624 DownCast(Su)->BasisSurface();
626 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
627 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
628 if (pl.Contains(gp_Lin(pl.Location(),V),
629 Precision::Confusion(),
630 Precision::Angular())) {
631 FEIF.Set(ToPrism,fac);
632 for (FEIF.Init();FEIF.More();FEIF.Next()) {
633 thePFace.Add(FEIF.Edge(),fac);
637 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
639 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
640 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
641 FEIF.Set(ToPrism,fac);
642 for (FEIF.Init();FEIF.More();FEIF.Next()) {
643 thePFace.Add(FEIF.Edge(),fac);
651 thePFace.Perform(Length);
653 else if (borne == 8) {
654 thePFace.Perform(FUntil);
656 else if (borne == 9) {
657 if (!(FFrom.IsNull() || FUntil.IsNull())) {
658 thePFace.Perform(FFrom,FUntil);
660 else if (FFrom.IsNull()) {
661 if (!FUntil.IsNull()) {
662 thePFace.PerformFromEnd(FUntil);
665 thePFace.PerformThruAll();
668 else { //FUntil.IsNull()
669 // il faudrait inverser V et appeler PerfomFromEnd...
670 //cout << "Not Implemented" << endl;
671 theCommands << "Not Implemented" << "\n";
674 if (!thePFace.IsDone()) {
675 theCommands << "Local operation not done";
679 DBRep::Set(a[2],thePFace);
686 //=======================================================================
689 //=======================================================================
691 static Standard_Integer SPLS(Draw_Interpretor& ,
692 Standard_Integer narg, const char** a)
694 Standard_Integer newnarg ;
696 if (narg<3) return 1;
697 TopoDS_Shape S = DBRep::Get(a[2]);
698 BRepFeat_SplitShape Spls(S);
699 Standard_Boolean pick = Standard_False;
702 Standard_Integer i = 3;
704 for ( newnarg=3; newnarg<narg; newnarg++) {
705 if (a[newnarg][0] == '@') {
711 (newnarg !=narg && ((narg-newnarg)<=2 || (narg-newnarg)%2 != 1))) {
716 pick = (a[i][0] == '.');
717 EF = DBRep::Get(a[i],TopAbs_FACE);
718 if (EF.IsNull()) return 1;
721 while (i < newnarg) {
723 DBRep_DrawableShape::LastPick(EF,u,v);
725 if (EF.ShapeType() == TopAbs_FACE) {
726 // face wire/edge ...
728 while (i < newnarg) {
730 Standard_Boolean rever = Standard_False;
731 if (a[i][0] == '-') {
734 pick = (a[i][1] == '.');
735 const char* Temp = a[i]+1;
736 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
737 rever = Standard_True;
740 pick = (a[i][0] == '.');
741 W = DBRep::Get(a[i],TopAbs_SHAPE,Standard_False);
744 return 1; // on n`a rien recupere
746 TopAbs_ShapeEnum wtyp = W.ShapeType();
747 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND && pick) {
749 DBRep_DrawableShape::LastPick(W,u,v);
750 wtyp = W.ShapeType();
752 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND) {
753 EF = DBRep::Get(a[i]);
760 if (wtyp == TopAbs_WIRE) {
761 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
763 else if (wtyp == TopAbs_EDGE) {
764 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
767 Spls.Add(TopoDS::Compound(W),TopoDS::Face(EF));
777 // ici, i vaut newnarg
778 for (i++; i<narg; i+=2) {
780 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
781 Es = TopoDS::Edge(aLocalShape);
782 // Es = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
786 aLocalShape = DBRep::Get(a[i+1],TopAbs_EDGE);
787 Ew = TopoDS::Edge(aLocalShape);
788 // Ew = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
792 Spls.Add(TopoDS::Edge(Ew),TopoDS::Edge(Es));
796 DBRep::Set(a[1],Spls);
800 //=======================================================================
801 //function : thickshell
803 //=======================================================================
805 Standard_Integer thickshell(Draw_Interpretor& ,
806 Standard_Integer n, const char** a)
809 //OSD_Chronometer Clock;
811 if ( n < 4) return 1;
812 TopoDS_Shape S = DBRep::Get(a[2]);
813 if (S.IsNull()) return 1;
815 Standard_Real Of = Draw::Atof(a[3]);
817 GeomAbs_JoinType JT= GeomAbs_Arc;
820 if (!strcmp(a[4],"i"))
821 JT = GeomAbs_Intersection;
822 if (!strcmp(a[4],"t"))
823 JT = GeomAbs_Tangent;
826 Standard_Boolean Inter = Standard_False; //Standard_True;
827 Standard_Real Tol = Precision::Confusion();
829 Tol = Draw::Atof(a[5]);
831 BRepOffset_MakeOffset B;
832 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT, Standard_True);
837 //B.MakeThickSolid ();
841 DBRep::Set(a[1],B.Shape());
846 //=======================================================================
847 //function : offsetshape
849 //=======================================================================
851 Standard_Integer offsetshape(Draw_Interpretor& ,
852 Standard_Integer n, const char** a)
855 //OSD_Chronometer Clock;
857 if ( n < 4) return 1;
858 TopoDS_Shape S = DBRep::Get(a[2]);
859 if (S.IsNull()) return 1;
861 Standard_Real Of = Draw::Atof(a[3]);
862 Standard_Boolean Inter = (!strcmp(a[0],"offsetcompshape"));
863 GeomAbs_JoinType JT= GeomAbs_Arc;
864 if (!strcmp(a[0],"offsetinter")) {
865 JT = GeomAbs_Intersection;
866 Inter = Standard_True;
869 BRepOffset_MakeOffset B;
870 Standard_Integer IB = 4;
871 Standard_Real Tol = Precision::Confusion();
873 TopoDS_Shape SF = DBRep::Get(a[4],TopAbs_FACE);
876 Tol = Draw::Atof(a[4]);
879 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT);
880 //------------------------------------------
881 // recuperation et chargement des bouchons.
882 //----------------------------------------
883 Standard_Boolean YaBouchon = Standard_False;
885 for (Standard_Integer i = IB ; i < n; i++) {
886 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
888 YaBouchon = Standard_True;
889 B.AddFace(TopoDS::Face(SF));
895 if (!YaBouchon) B.MakeOffsetShape();
896 else B.MakeThickSolid ();
899 DBRep::Set(a[1],B.Shape());
904 static BRepOffset_MakeOffset TheOffset;
905 static Standard_Real TheRadius;
906 static Standard_Boolean theYaBouchon;
907 static Standard_Real TheTolerance = Precision::Confusion();
908 static Standard_Boolean TheInter = Standard_False;
909 static GeomAbs_JoinType TheJoin = GeomAbs_Arc;
911 Standard_Integer offsetparameter(Draw_Interpretor& di,
912 Standard_Integer n, const char** a)
915 //cout << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << endl;
916 //cout << " Current Values" << endl;
917 //cout << " --> Tolerance :" << TheTolerance << endl;
918 //cout << " --> TheInter :";
919 di << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << "\n";
920 di << " Current Values" << "\n";
921 di << " --> Tolerance :" << TheTolerance << "\n";
922 di << " --> TheInter :";
924 //cout << "Complet" ;
930 //cout << endl << " --> TheJoin :";
931 di << "\n" << " --> TheJoin :";
934 //case GeomAbs_Arc: cout << " Arc"; break;
935 //case GeomAbs_Intersection: cout << " Intersection"; break;
936 case GeomAbs_Arc: di << " Arc"; break;
937 case GeomAbs_Intersection: di << " Intersection"; break;
947 if ( n < 4 ) return 1;
949 TheTolerance = Draw::Atof(a[1]);
950 TheInter = strcmp(a[2],"p");
952 if ( !strcmp(a[3],"a")) TheJoin = GeomAbs_Arc;
953 else if ( !strcmp(a[3],"i")) TheJoin = GeomAbs_Intersection;
954 else if ( !strcmp(a[3],"t")) TheJoin = GeomAbs_Tangent;
960 //=======================================================================
961 //function : offsetinit
963 //=======================================================================
965 Standard_Integer offsetload(Draw_Interpretor& ,
966 Standard_Integer n, const char** a)
968 if ( n < 2) return 1;
969 TopoDS_Shape S = DBRep::Get(a[1]);
970 if (S.IsNull()) return 1;
972 Standard_Real Of = Draw::Atof(a[2]);
974 // Standard_Boolean Inter = Standard_True;
976 TheOffset.Initialize(S,Of,TheTolerance,BRepOffset_Skin,TheInter,0,TheJoin);
977 //------------------------------------------
978 // recuperation et chargement des bouchons.
979 //----------------------------------------
980 for (Standard_Integer i = 3 ; i < n; i++) {
981 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
983 TheOffset.AddFace(TopoDS::Face(SF));
986 if (n < 4) theYaBouchon = Standard_False; //B.MakeOffsetShape();
987 else theYaBouchon = Standard_True; //B.MakeThickSolid ();
993 //=======================================================================
994 //function : offsetonface
996 //=======================================================================
998 Standard_Integer offsetonface(Draw_Interpretor&, Standard_Integer n, const char** a)
1000 if ( n < 3) return 1;
1002 for (Standard_Integer i = 1 ; i < n; i+=2) {
1003 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
1005 Standard_Real Of = Draw::Atof(a[i+1]);
1006 TheOffset.SetOffsetOnFace(TopoDS::Face(SF),Of);
1013 //=======================================================================
1014 //function : offsetperform
1016 //=======================================================================
1018 Standard_Integer offsetperform(Draw_Interpretor& theCommands,
1019 Standard_Integer theNArg, const char** a)
1021 if ( theNArg < 2) return 1;
1024 TheOffset.MakeThickSolid ();
1026 TheOffset.MakeOffsetShape();
1028 if(TheOffset.IsDone())
1030 DBRep::Set(a[1],TheOffset.Shape());
1034 theCommands << "ERROR. offsetperform operation not done.";
1042 //=======================================================================
1045 //=======================================================================
1047 static Standard_Integer Debou(Draw_Interpretor& theCommands,
1048 Standard_Integer narg, const char** a)
1050 Standard_Integer i ;
1051 Standard_Integer newnarg ;
1053 if (narg<7) return 1;
1055 TopoDS_Shape S = DBRep::Get(a[2]);
1057 Standard_Boolean Fuse;
1058 if (!strcasecmp("F",a[3])) {
1059 Fuse = Standard_True;
1061 else if (!strcasecmp("C",a[3])) {
1062 Fuse = Standard_False;
1068 for ( newnarg = 4; newnarg < narg; newnarg++) {
1069 if (a[newnarg][0] == '@') {
1073 if (newnarg >= narg-1 || newnarg == 4) {
1078 TopTools_ListOfShape LF,LF2;
1079 for ( i=4; i<newnarg; i++) {
1080 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1081 LF.Append(aLocalShape);
1082 // LF.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1085 for (i=newnarg+1; i<narg; i++) {
1086 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1087 LF2.Append(aLocalShape);
1088 // LF2.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1091 //BRepFeat_LocalOperation BLoc(S);
1092 //BLoc.Perform(LF,LF2,Fuse);
1094 BRepFeat_Builder BLoc;
1097 BLoc.PerformResult();
1098 if (!BLoc.ErrorStatus()) {
1100 DBRep::Set(a[1],BLoc.Shape());
1104 theCommands << "Local operation not done" ;
1109 //=======================================================================
1112 //=======================================================================
1114 static Standard_Integer ROW(Draw_Interpretor& theCommands,
1115 Standard_Integer narg, const char** a)
1117 if (narg<13) return 1;
1118 TopoDS_Shape S = DBRep::Get(a[3]);
1119 BRepFeat_MakeRevol theRFace;
1122 Standard_Real Angle=0;
1123 TopoDS_Shape FFrom,FUntil;
1124 Standard_Integer i,borne;
1125 Standard_Boolean fuse;
1127 if (a[1][0] == 'f' || a[1][0] == 'F') {
1128 fuse = Standard_True;
1130 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1131 fuse = Standard_False;
1137 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1138 if (FFrom.IsNull()) {
1139 Angle = Draw::Atof(a[4]);
1144 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1145 if (FUntil.IsNull()) {
1160 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1161 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1162 gp_Ax1 theAxis(Or,D);
1164 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1165 TopoDS_Face F = TopoDS::Face(aLocalShape);
1166 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1167 BRepFeat_SplitShape Spls(F);
1168 for (i = borne+1; i<narg; i++) {
1170 if (a[i][0] !='-') {
1171 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
1172 wir = TopoDS::Wire(aLocalShape);
1173 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
1176 if (a[i][1] == '\0')
1178 const char* Temp = a[i]+1;
1179 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
1180 wir = TopoDS::Wire(aLocalShape);
1181 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
1188 TopoDS_Shape ToRotate;
1189 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1190 if (lleft.Extent() == 1) {
1191 theRFace.Init(S,lleft.First(),F,theAxis,fuse,Standard_True);
1192 ToRotate = lleft.First();
1198 TopTools_ListIteratorOfListOfShape it;
1199 for (it.Initialize(lleft);it.More();it.Next()) {
1200 B.Add(Sh,TopoDS::Face(it.Value()));
1202 Sh.Closed (BRep_Tool::IsClosed (Sh));
1203 theRFace.Init(S,Sh,F,theAxis,fuse,Standard_True);
1207 // Recherche des faces de glissement
1208 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
1209 TopExp_Explorer exp(S,TopAbs_FACE) ;
1210 for ( ;exp.More();exp.Next()) {
1211 if (exp.Current().IsSame(F)) {
1217 LocOpe_FindEdgesInFace FEIF;
1218 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1219 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1220 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1221 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1222 Su = Handle(Geom_RectangularTrimmedSurface)::
1223 DownCast(Su)->BasisSurface();
1225 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1226 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1227 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1228 FEIF.Set(ToRotate,fac);
1229 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1230 theRFace.Add(FEIF.Edge(),fac);
1234 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1236 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1237 if (cy.Axis().IsCoaxial(theAxis,
1238 Precision::Angular(),Precision::Confusion())) {
1239 FEIF.Set(ToRotate,fac);
1240 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1241 theRFace.Add(FEIF.Edge(),fac);
1249 if (FUntil.IsNull()) {
1250 theRFace.Perform(Angle);
1253 theRFace.Perform(FUntil);
1256 else { // borne == 12
1257 theRFace.Perform(FFrom,FUntil);
1260 if (!theRFace.IsDone()) {
1261 theCommands << "Local operation not done";
1265 DBRep::Set(a[2],theRFace);
1271 //=======================================================================
1274 //=======================================================================
1276 static Standard_Integer ROF(Draw_Interpretor& theCommands,
1277 Standard_Integer narg, const char** a)
1279 if (narg<12) return 1;
1280 TopoDS_Shape S = DBRep::Get(a[3]);
1281 BRepFeat_MakeRevol theRFace;
1284 Standard_Real Angle=0;
1285 TopoDS_Shape FFrom,FUntil;
1286 Standard_Integer i,borne;
1287 Standard_Boolean fuse;
1289 if (a[1][0] == 'f' || a[1][0] == 'F') {
1290 fuse = Standard_True;
1292 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1293 fuse = Standard_False;
1299 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1300 if (FFrom.IsNull()) {
1301 Angle = Draw::Atof(a[4]);
1306 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1307 if (FUntil.IsNull()) {
1322 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1323 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1324 gp_Ax1 theAxis(Or,D);
1326 TopoDS_Shape ToRotate;
1327 if (narg == borne+1) {
1328 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1329 TopoDS_Face F = TopoDS::Face(aLocalShape);
1330 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1331 theRFace.Init(S,F,F,theAxis,fuse,Standard_True);
1339 for (i=borne; i<narg; i++) {
1340 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1341 TopoDS_Face F = TopoDS::Face(aLocalShape);
1342 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
1347 She.Closed (BRep_Tool::IsClosed (She));
1348 theRFace.Init(S,She,TopoDS_Face(),theAxis,fuse,Standard_False);
1352 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1353 TopExp_Explorer exp(ToRotate,TopAbs_FACE) ;
1354 for ( ;exp.More();exp.Next()) {
1355 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1356 TopExp_Explorer exp2(S,TopAbs_FACE) ;
1357 for ( ;exp2.More();exp2.Next()) {
1358 if (exp2.Current().IsSame(exp.Current())) {
1368 LocOpe_FindEdgesInFace FEIF;
1369 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1370 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1371 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1372 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1373 Su = Handle(Geom_RectangularTrimmedSurface)::
1374 DownCast(Su)->BasisSurface();
1376 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1377 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1378 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1379 FEIF.Set(ToRotate,fac);
1380 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1381 theRFace.Add(FEIF.Edge(),fac);
1385 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1387 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1388 if (cy.Axis().IsCoaxial(theAxis,
1389 Precision::Angular(),Precision::Confusion())) {
1390 FEIF.Set(ToRotate,fac);
1391 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1392 theRFace.Add(FEIF.Edge(),fac);
1400 if (FUntil.IsNull()) {
1401 theRFace.Perform(Angle);
1404 theRFace.Perform(FUntil);
1407 else { // borne == 12
1408 theRFace.Perform(FFrom,FUntil);
1411 if (!theRFace.IsDone()) {
1412 theCommands << "Local operation not done";
1416 DBRep::Set(a[2],theRFace);
1422 //=======================================================================
1424 //purpose : Commande glue
1425 //=======================================================================
1427 static Standard_Integer GLU(Draw_Interpretor& ,
1428 Standard_Integer narg, const char** a)
1430 if (narg<6 || narg%2 != 0) return 1;
1431 TopoDS_Shape Sne = DBRep::Get(a[2]);
1432 TopoDS_Shape Sba = DBRep::Get(a[3]);
1434 Standard_Boolean pick;
1436 BRepFeat_Gluer theGl(Sne,Sba);
1437 TopoDS_Shape Fne,Fba;
1439 LocOpe_FindEdges fined;
1441 Standard_Integer i = 4;
1442 Standard_Boolean first = Standard_True;
1444 pick = (a[i][0] == '.');
1445 Fne = DBRep::Get(a[i]);
1449 TopAbs_ShapeEnum sht = Fne.ShapeType();
1450 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
1452 DBRep_DrawableShape::LastPick(Fne,u,v);
1453 sht = Fne.ShapeType();
1455 if (first && sht != TopAbs_FACE) {
1458 first = Standard_False;
1459 pick = (a[i+1][0] == '.');
1460 Fba = DBRep::Get(a[i+1]);
1464 if (pick && Fba.ShapeType() != sht) {
1466 DBRep_DrawableShape::LastPick(Fba,u,v);
1468 if (Fba.ShapeType() != sht) {
1471 if (sht == TopAbs_FACE) {
1472 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1473 const TopoDS_Face& f2 = TopoDS::Face(Fba);
1476 for (fined.InitIterator(); fined.More(); fined.Next()) {
1477 theGl.Bind(fined.EdgeFrom(),fined.EdgeTo());
1481 theGl.Bind(TopoDS::Edge(Fne),TopoDS::Edge(Fba));
1486 DBRep::Set(a[1],theGl);
1491 static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
1492 Standard_Integer narg, const char** a)
1495 if (strcasecmp(a[0],"FEATPRISM") &&
1496 strcasecmp(a[0],"FEATDPRISM") &&
1497 strcasecmp(a[0],"FEATREVOL") &&
1498 strcasecmp(a[0],"FEATPIPE") &&
1499 strcasecmp(a[0],"FEATLF") &&
1500 strcasecmp(a[0],"FEATRF")) {
1504 if ((!strcasecmp(a[0],"FEATPRISM") && narg !=9) ||
1505 (!strcasecmp(a[0],"FEATREVOL") && narg != 12) ||
1506 (!strcasecmp(a[0],"FEATDPRISM") && narg != 7) ||
1507 (!strcasecmp(a[0],"FEATPIPE") && narg != 7) ||
1508 (!strcasecmp(a[0],"FEATLF") && narg != 12) ||
1509 (!strcasecmp(a[0],"FEATRF") && narg != 14)) {
1510 theCommands << "invalid number of arguments";
1514 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1515 if (Sbase.IsNull()) {
1516 theCommands << "null basis shape";
1519 Standard_Integer Ifuse = Draw::Atoi(a[narg-2]);
1520 Standard_Integer Imodif = Draw::Atoi(a[narg-1]);
1522 Standard_Integer Fuse = Ifuse;
1523 Standard_Boolean Modify = (Imodif!=0);
1529 Handle(Geom_Plane) P;
1531 BRepFeat_StatusError se;
1533 if (strcasecmp(a[0],"FEATLF") && strcasecmp(a[0],"FEATRF")) {
1534 Pbase = DBRep::Get(a[2]);
1535 if (Pbase.IsNull()) {
1536 theCommands << "null shape to transform";
1539 TopoDS_Shape aLocalShape(DBRep::Get(a[3],TopAbs_FACE));
1540 Skface = TopoDS::Face(aLocalShape);
1541 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
1542 if (Skface.IsNull()) {
1543 theCommands << "null face of Sketch";
1548 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1549 W = TopoDS::Wire(aLocalShape);
1550 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1552 theCommands << "null profile for rib or slot";
1555 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1556 P = Handle(Geom_Plane)::DownCast(s);
1558 theCommands << "null plane to transform";
1562 if (narg == 9 || narg == 12 || narg == 14) {
1563 // Standard_Real X,Y,Z,X1,Y1,Z1;
1564 Standard_Real X,Y,Z;
1565 X = Draw::Atof(a[4]);
1566 Y = Draw::Atof(a[5]);
1567 Z = Draw::Atof(a[6]);
1569 if (narg == 9) { // prism
1570 prdef = Standard_True;
1571 thePrism.Init(Sbase,Pbase,Skface,gp_Dir(X,Y,Z),Fuse,Modify);
1573 else if(narg == 14) {
1574 rfdef = Standard_True;
1576 X = Draw::Atof(a[7]);
1577 Y = Draw::Atof(a[8]);
1578 Z = Draw::Atof(a[9]);
1579 Standard_Real H1 = Draw::Atof(a[10]);
1580 Standard_Real H2 = Draw::Atof(a[11]);
1581 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1582 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1583 if (!theRF.IsDone()) {
1584 se = theRF.CurrentStatusError();
1585 //BRepFeat::Print(se,cout) << endl;
1586 Standard_SStream aSStream;
1587 BRepFeat::Print(se,aSStream);
1588 theCommands << aSStream << "\n";
1592 else if(narg == 12 && strcasecmp(a[0],"FEATLF")) {
1593 rvdef = Standard_True;
1595 X = Draw::Atof(a[7]);
1596 Y = Draw::Atof(a[8]);
1597 Z = Draw::Atof(a[9]);
1598 theRevol.Init(Sbase,Pbase,Skface,gp_Ax1(Or,gp_Dir(X,Y,Z)),
1602 lfdef = Standard_True;
1603 gp_Vec Direct(X,Y,Z);
1604 X = Draw::Atof(a[7]);
1605 Y = Draw::Atof(a[8]);
1606 Z = Draw::Atof(a[9]);
1607 theLF.Init(Sbase, W, P, Direct, gp_Vec(X,Y,Z), Fuse,Modify);
1608 if (!theLF.IsDone()) {
1609 se = theLF.CurrentStatusError();
1610 //BRepFeat::Print(se,cout) << endl;
1611 Standard_SStream aSStream;
1612 BRepFeat::Print(se,aSStream);
1613 theCommands << aSStream << "\n";
1618 else if (narg == 7) {
1619 if (!strcasecmp(a[0],"FEATDPRISM")) {
1620 if (Pbase.ShapeType() != TopAbs_FACE) {
1621 theCommands << "Invalid DPrism base";
1624 Standard_Real Angle = Draw::Atof(a[4])*M_PI/360;
1625 dprdef = Standard_True;
1626 theDPrism.Init(Sbase,TopoDS::Face(Pbase),Skface,Angle,Fuse,Modify);
1629 TopoDS_Shape aLocalShape(DBRep::Get(a[4],TopAbs_WIRE));
1630 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
1631 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
1632 if (Spine.IsNull()) {
1633 TopoDS_Shape Edspine =DBRep::Get(a[4],TopAbs_EDGE);
1634 if (Edspine.IsNull()) {
1635 theCommands << "null spine";
1640 B.Add(Spine,Edspine);
1642 pidef = Standard_True;
1643 thePipe.Init(Sbase,Pbase,Skface,Spine,Fuse,Modify);
1651 static Standard_Integer ADD(Draw_Interpretor& ,
1652 Standard_Integer narg, const char** a)
1654 Standard_Integer i ;
1655 if (narg < 4 || narg%2 != 0) {
1658 if (!strcasecmp("PRISM",a[1])) {
1662 for ( i=2; i<narg; i+=2) {
1663 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1664 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1665 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1669 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1670 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1671 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1675 thePrism.Add(edg,fac);
1678 else if (!strcasecmp("REVOL",a[1])) {
1682 for ( i=2; i<narg; i+=2) {
1683 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1684 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1685 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1689 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1690 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1691 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1695 theRevol.Add(edg,fac);
1698 else if (!strcasecmp("PIPE",a[1])) {
1702 for ( i=2; i<narg; i+=2) {
1703 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1704 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1705 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1709 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1710 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1711 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1715 thePipe.Add(edg,fac);
1726 static Standard_Integer PERF(Draw_Interpretor& theCommands,
1727 Standard_Integer narg, const char** a)
1732 if (strcasecmp(a[0],"FEATPERFORM") &&
1733 strcasecmp(a[0],"FEATPERFORMVAL")) {
1737 Standard_Integer Kas;
1738 if (!strcasecmp("PRISM",a[1])) {
1741 theCommands << "prism not defined";
1745 else if (!strcasecmp("REVOL",a[1])) {
1748 theCommands << "revol not defined";
1752 else if (!strcasecmp("PIPE",a[1])) {
1755 theCommands << "pipe not defined";
1758 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1759 theCommands << "invalid command for pipe";
1763 else if (!strcasecmp("DPRISM",a[1])) {
1766 theCommands << "dprism not defined";
1770 else if (!strcasecmp("LF",a[1])) {
1773 theCommands << "lf not defined";
1776 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1777 theCommands << "invalid command for lf";
1781 else if (!strcasecmp("RF",a[1])) {
1784 theCommands << "rf not defined";
1787 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1788 theCommands << "invalid command for rf";
1793 theCommands << "unknown argument : " << a[1];
1797 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1798 if (narg !=4 && narg != 5) {
1799 theCommands << "invalid number of arguments";
1803 Standard_Real Val = Draw::Atof(a[3]);
1805 thePrism.Perform(Val);
1807 else if (Kas == 2) {
1809 theRevol.Perform(Val);
1811 else if (Kas == 4) {
1812 theDPrism.Perform(Val);
1814 else if (Kas == 5) {
1815 theCommands << "invalid command for lf";
1818 else if (Kas == 6) {
1819 theCommands << "invalid command for rf";
1823 else if(narg == 5) {
1824 Standard_Real Val = Draw::Atof(a[3]);
1825 TopoDS_Shape FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
1827 thePrism.PerformUntilHeight(FUntil, Val);
1829 else if (Kas == 2) {
1831 theRevol.PerformUntilAngle(FUntil, Val);
1833 else if (Kas == 4) {
1834 theDPrism.PerformUntilHeight(FUntil, Val);
1837 theCommands << "invalid command for ribs or slots";
1842 else if (!strcasecmp(a[0],"FEATPERFORM")) {
1843 if (narg == 3) { // Thru all
1846 thePrism.PerformThruAll();
1849 theRevol.PerformThruAll();
1855 theDPrism.PerformThruAll();
1868 else if (narg == 4) { // Until
1869 TopoDS_Shape Funtil = DBRep::Get(a[3],TopAbs_SHAPE);
1873 if (Funtil.IsNull()) {
1874 thePrism.PerformUntilEnd();
1877 thePrism.Perform(Funtil);
1883 if (!Funtil.IsNull()) {
1884 theRevol.Perform(Funtil);
1893 if (!Funtil.IsNull()) {
1894 thePipe.Perform(Funtil);
1897 theCommands << "invalid command for ribs pipe";
1904 if (!Funtil.IsNull()) {
1905 theDPrism.Perform(Funtil);
1908 theDPrism.PerformUntilEnd();
1914 theCommands << "invalid command for lf";
1920 theCommands << "invalid command for rf";
1928 else if (narg == 5) {
1929 TopoDS_Shape Ffrom = DBRep::Get(a[3],TopAbs_SHAPE);
1930 TopoDS_Shape Funtil = DBRep::Get(a[4],TopAbs_SHAPE);
1931 if (Funtil.IsNull()) {
1937 if (Ffrom.IsNull()) {
1938 thePrism.PerformFromEnd(Funtil);
1941 thePrism.Perform(Ffrom,Funtil);
1947 if (Ffrom.IsNull()) {
1950 theRevol.Perform(Ffrom,Funtil);
1955 if (Ffrom.IsNull()) {
1958 thePipe.Perform(Ffrom,Funtil);
1963 if (Ffrom.IsNull()) {
1964 theDPrism.PerformFromEnd(Funtil);
1967 theDPrism.Perform(Ffrom,Funtil);
1978 BRepFeat_StatusError se;
1981 if (!thePrism.IsDone()) {
1982 se = thePrism.CurrentStatusError();
1983 //BRepFeat::Print(se,cout) << endl;
1984 Standard_SStream aSStream;
1985 BRepFeat::Print(se,aSStream);
1986 theCommands << aSStream << "\n";
1989 DBRep::Set(a[2],thePrism);
1993 if (!theRevol.IsDone()) {
1994 se = theRevol.CurrentStatusError();
1995 //BRepFeat::Print(se,cout) << endl;
1996 Standard_SStream aSStream;
1997 BRepFeat::Print(se,aSStream);
1998 theCommands << aSStream << "\n";
2001 DBRep::Set(a[2],theRevol);
2005 if (!thePipe.IsDone()) {
2006 se = thePipe.CurrentStatusError();
2007 //BRepFeat::Print(se,cout) << endl;
2008 Standard_SStream aSStream;
2009 BRepFeat::Print(se,aSStream);
2010 theCommands << aSStream << "\n";
2013 DBRep::Set(a[2],thePipe);
2017 if (!theDPrism.IsDone()) {
2018 se = theDPrism.CurrentStatusError();
2019 //BRepFeat::Print(se,cout) << endl;
2020 Standard_SStream aSStream;
2021 BRepFeat::Print(se,aSStream);
2022 theCommands << aSStream << "\n";
2025 DBRep::Set(a[2],theDPrism);
2029 if (!theLF.IsDone()) {
2030 se = theLF.CurrentStatusError();
2031 //BRepFeat::Print(se,cout) << endl;
2032 Standard_SStream aSStream;
2033 BRepFeat::Print(se,aSStream);
2034 theCommands << aSStream << "\n";
2037 DBRep::Set(a[2],theLF);
2041 if (!theRF.IsDone()) {
2042 se = theRF.CurrentStatusError();
2043 //BRepFeat::Print(se,cout) << endl;
2044 Standard_SStream aSStream;
2045 BRepFeat::Print(se,aSStream);
2046 theCommands << aSStream << "\n";
2049 DBRep::Set(a[2],theRF);
2058 static Standard_Integer BOSS(Draw_Interpretor& theCommands,
2059 Standard_Integer narg, const char** a)
2061 if (strcasecmp(a[0],"ENDEDGES") && strcasecmp(a[0],"FILLET")
2062 && strcasecmp(a[0],"BOSSAGE")) {
2066 if ((!strcasecmp(a[0],"ENDEDGES") && narg !=5) ||
2067 (!strcasecmp(a[0],"FILLET") && narg <5 && narg%2 != 1) ||
2068 (!strcasecmp(a[0],"BOSSAGE") && narg != 6)) {
2069 theCommands << "invalid number of arguments";
2073 Standard_Integer Kas=0;
2074 Standard_Integer dprsig=0;
2075 if (!strcasecmp("ENDEDGES",a[0])) {
2077 dprsig = Draw::Atoi(a[4]);
2079 else if (!strcasecmp("FILLET",a[0])) {
2082 else if (!strcasecmp("BOSSAGE",a[0])) {
2084 dprsig = Draw::Atoi(a[5]);
2087 TopoDS_Shape theShapeTop;
2088 TopoDS_Shape theShapeBottom;
2090 if (Kas == 1 || Kas == 3) {
2091 if (!strcasecmp("DPRISM",a[1])) {
2093 theCommands << "dprism not defined";
2098 theCommands << "unknown argument : " << a[1];
2102 theDPrism.BossEdges(dprsig);
2104 TopTools_ListOfShape theTopEdges, theLatEdges;
2105 theTopEdges = theDPrism.TopEdges();
2106 theLatEdges = theDPrism.LatEdges();
2108 TopTools_ListIteratorOfListOfShape it;
2111 B.MakeCompound(TopoDS::Compound(theShapeTop));
2112 it.Initialize(theTopEdges);
2113 for(; it.More(); it.Next()) {
2114 TopExp_Explorer exp;
2115 for (exp.Init(it.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
2116 B.Add(theShapeTop,exp.Current());
2119 DBRep::Set(a[2],theShapeTop);
2122 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2123 it.Initialize(theLatEdges);
2124 for(; it.More(); it.Next()) {
2125 B.Add(theShapeBottom,it.Value());
2127 DBRep::Set(a[3],theShapeBottom);
2129 if (Kas == 1) return 0;
2132 if (Kas == 2 || Kas == 3) {
2134 // Standard_Integer nrad;
2137 V = DBRep::Get(a[2],TopAbs_SHAPE);
2139 else if (Kas == 3) {
2143 if(V.IsNull()) return 1;
2144 ChFi3d_FilletShape FSh = ChFi3d_Rational;
2145 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
2146 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
2147 Rakk->SetContinuity(blend_cont, tapp_angle);
2151 Standard_Integer nbedge = 0;
2154 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
2155 Rad = Draw::Atof(a[2*ii + 1]);
2156 if (Rad == 0.) continue;
2157 S = DBRep::Get(a[(2*ii+2)],TopAbs_SHAPE);
2158 TopExp_Explorer exp;
2159 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2160 E = TopoDS::Edge(exp.Current());
2168 else if (Kas == 3) {
2169 Rad = Draw::Atof(a[3]);
2172 TopExp_Explorer exp;
2173 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2174 E = TopoDS::Edge(exp.Current());
2181 Rad = Draw::Atof(a[4]);
2184 TopExp_Explorer exp;
2185 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2186 E = TopoDS::Edge(exp.Current());
2195 if(!nbedge) return 1;
2197 if(!Rakk->IsDone()) return 1;
2198 TopoDS_Shape res = Rakk->Shape();
2201 DBRep::Set(a[1],res);
2203 else if (Kas == 3) {
2204 DBRep::Set(a[2],res);
2214 //=======================================================================
2215 //function : FeatureCommands
2217 //=======================================================================
2219 void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
2221 static Standard_Boolean done = Standard_False;
2223 done = Standard_True;
2225 DBRep::BasicCommands(theCommands);
2227 const char* g = "TOPOLOGY Feature commands";
2229 theCommands.Add("localope",
2230 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2233 theCommands.Add("hole",
2234 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2237 theCommands.Add("firsthole",
2238 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2241 theCommands.Add("holend",
2242 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2245 theCommands.Add("blindhole",
2246 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2249 theCommands.Add("holecontrol",
2250 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2251 __FILE__,CONTROL,g);
2253 theCommands.Add("wprism",
2254 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2258 theCommands.Add("fprism",
2259 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2263 theCommands.Add("wrotate",
2264 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2268 theCommands.Add("frotate",
2269 "Rotates a set of faces of a shape : frotate f[use]/c[ut] result shape Angle/[FaceFrom] FaceUntil OX OY OZ DX DY DZ face1 [face2...]",
2273 theCommands.Add("splitshape",
2274 "splitshape result shape face wire/edge/compound [wire/edge/compound ...][face wire/edge/compound [wire/edge/compound...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2278 theCommands.Add("thickshell",
2279 "thickshell r shape offset [jointype [tol] ]",
2280 __FILE__,thickshell,g);
2282 theCommands.Add("offsetshape",
2283 "offsetshape r shape offset [tol] [face ...]",
2284 __FILE__,offsetshape,g);
2286 theCommands.Add("offsetcompshape",
2287 "offsetcompshape r shape offset [face ...]",
2288 __FILE__,offsetshape,g);
2290 theCommands.Add("offsetparameter",
2291 "offsetparameter tol inter(a/i) join(a/i)",
2292 __FILE__,offsetparameter);
2294 theCommands.Add("offsetload",
2295 "offsetload shape offset bouchon1 bouchon2 ...",
2296 __FILE__,offsetload,g);
2298 theCommands.Add("offsetonface",
2299 "offsetonface face1 offset1 face2 offset2 ...",
2300 __FILE__,offsetonface,g);
2302 theCommands.Add("offsetperform",
2303 "offsetperform result",
2304 __FILE__,offsetperform,g);
2307 theCommands.Add("deboucle",
2308 " Essai de debouclage partiel: deboucle result shape F/C face [face...] @ face [face...]",
2312 theCommands.Add("glue",
2313 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2317 theCommands.Add("featprism",
2318 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2321 theCommands.Add("featrevol",
2322 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2325 theCommands.Add("featpipe",
2326 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2329 theCommands.Add("featdprism",
2330 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2333 theCommands.Add("featlf",
2334 "Defines the arguments for a linear rib or slot : featlf shape wire plane DirX DirY DirZ DirX DirY DirZ Fuse(0/1/2) Modify(0/1)",
2337 theCommands.Add("featrf",
2338 "Defines the arguments for a rib or slot of revolution : featrf shape wire plane X Y Z DirX DirY DirZ Size Size Fuse(0/1/2) Modify(0/1)",
2341 theCommands.Add("addslide",
2342 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2345 theCommands.Add("featperform",
2346 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2349 theCommands.Add("featperformval",
2350 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2353 theCommands.Add("endedges",
2354 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2357 theCommands.Add("fillet",
2358 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2361 theCommands.Add("bossage",
2362 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",