1 // Created on: 1995-06-16
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
26 #include <Draw_Interpretor.hxx>
27 #include <Draw_Appli.hxx>
28 #include <DrawTrSurf.hxx>
30 #include <TopTools_ListOfShape.hxx>
31 #include <TopTools_ListIteratorOfListOfShape.hxx>
32 #include <TopTools_MapOfShape.hxx>
33 #include <TopTools_MapIteratorOfMapOfShape.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Wire.hxx>
37 #include <TopoDS_Shell.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TopoDS_Edge.hxx>
42 #include <Geom_RectangularTrimmedSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <Geom_CylindricalSurface.hxx>
47 #include <gp_Cylinder.hxx>
49 #include <BRepFeat_LocalOperation.hxx>
50 #include <BRepFeat_MakeCylindricalHole.hxx>
51 #include <BRepFeat_SplitShape.hxx>
52 #include <BRepFeat_Gluer.hxx>
54 #include <BRepFeat.hxx>
55 #include <BRepFeat_MakePrism.hxx>
56 #include <BRepFeat_MakeRevol.hxx>
57 #include <BRepFeat_MakePipe.hxx>
58 #include <BRepFeat_MakeDPrism.hxx>
59 #include <BRepFeat_MakeLinearForm.hxx>
60 #include <BRepFeat_MakeRevolutionForm.hxx>
62 #include <LocOpe_FindEdges.hxx>
63 #include <LocOpe_FindEdgesInFace.hxx>
65 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
66 #include <BRepOffsetAPI_MakeThickSolid.hxx>
67 #include <BRep_Tool.hxx>
68 #include <BRep_Builder.hxx>
70 #include <DBRep_DrawableShape.hxx>
71 #include <BRepTest.hxx>
73 #include <BRepFilletAPI_MakeFillet.hxx>
74 #include <ChFi3d_FilletShape.hxx>
76 #include <Precision.hxx>
79 //#define strcasecmp _stricmp Already defined
80 Standard_IMPORT Draw_Viewer dout;
86 static BRepFeat_MakeCylindricalHole theHole;
87 static Standard_Boolean WithControl = Standard_True;
89 Standard_Boolean DownCastingEnforcing = Standard_False;
91 static BRepFeat_MakePrism thePrism;
92 static BRepFeat_MakeDPrism theDPrism;
93 static BRepFeat_MakeRevol theRevol;
94 static BRepFeat_MakePipe thePipe;
95 static BRepFeat_MakeLinearForm theLF;
96 static BRepFeat_MakeRevolutionForm theRF;
98 static Standard_Boolean dprdef = Standard_False;
99 static Standard_Boolean prdef = Standard_False;
100 static Standard_Boolean rvdef = Standard_False;
101 static Standard_Boolean pidef = Standard_False;
102 static Standard_Boolean lfdef = Standard_False;
103 static Standard_Boolean rfdef = Standard_False;
105 static Standard_Real t3d = 1.e-4;
106 static Standard_Real t2d = 1.e-5;
107 static Standard_Real ta = 1.e-2;
108 static Standard_Real fl = 1.e-3;
109 static Standard_Real tapp_angle = 1.e-2;
110 static GeomAbs_Shape blend_cont = GeomAbs_C1;
111 static BRepFilletAPI_MakeFillet* Rakk = 0;
115 static void Print(Draw_Interpretor& di,
116 const BRepFeat_Status St)
118 di << " Error Status : ";
120 case BRepFeat_NoError:
124 case BRepFeat_InvalidPlacement:
125 di << "Invalid placement";
128 case BRepFeat_HoleTooLong:
129 di << "Hole too long";
134 static Standard_Integer Loc(Draw_Interpretor& theCommands,
135 Standard_Integer narg, const char** a)
137 if (narg<6) return 1;
138 TopoDS_Shape S = DBRep::Get(a[2]);
139 TopoDS_Shape T = DBRep::Get(a[3]);
141 Standard_Boolean Fuse;
142 if (!strcasecmp("F",a[4])) {
143 Fuse = Standard_True;
145 else if (!strcasecmp("C",a[4])) {
146 Fuse = Standard_False;
152 TopTools_ListOfShape LF;
153 for (Standard_Integer i=0; i<= narg-6; i++) {
154 TopoDS_Shape aLocalShape(DBRep::Get(a[i+5],TopAbs_FACE));
155 LF.Append(aLocalShape);
156 // LF.Append(TopoDS::Face(DBRep::Get(a[i+5],TopAbs_FACE)));
159 BRepFeat_LocalOperation BLoc(S);
160 BLoc.Perform(T,LF,Fuse);
161 BLoc.BuildPartsOfTool();
165 strcpy(newname,a[1]);
167 while (*p != '\0') p++;
170 TopTools_ListIteratorOfListOfShape its(BLoc.PartsOfTool());
173 for (; its.More(); its.Next()) {
176 DBRep::Set(newname,its.Value());
180 Standard_Integer qq,ww,ee,button;
183 TopoDS_Shape aLocalShape(DBRep::Get(".",TopAbs_SHELL));
184 S = TopoDS::Shell(aLocalShape);
185 // S = TopoDS::Shell(DBRep::Get(".",TopAbs_SHELL));
186 Draw::LastPick(qq,ww,ee,button);
194 BLoc.ActivatePart(S);
204 } while (button != 3);
210 DBRep::Set(a[1],BLoc);
214 theCommands << "Local operation not done" ;
220 static Standard_Integer HOLE1(Draw_Interpretor& theCommands,
221 Standard_Integer narg, const char** a)
223 if (narg<10 || narg == 11) return 1;
224 TopoDS_Shape S = DBRep::Get(a[2]);
226 gp_Pnt Or(atof(a[3]),atof(a[4]),atof(a[5]));
227 gp_Dir Di(atof(a[6]),atof(a[7]),atof(a[8]));
229 Standard_Real Radius = atof(a[9]);
231 theHole.Init(S,gp_Ax1(Or,Di));
234 theHole.Perform(Radius);
237 Standard_Real pfrom = atof(a[10]);
238 Standard_Real pto = atof(a[11]);
239 theHole.Perform(Radius,pfrom,pto,WithControl);
243 if (theHole.IsDone()) {
245 DBRep::Set(a[1],theHole);
249 theCommands << "Echec de MakeCylindricalHole";
250 Print(theCommands,theHole.Status());
254 static Standard_Integer HOLE2(Draw_Interpretor& theCommands,
255 Standard_Integer narg, const char** a)
257 if (narg<10) return 1;
258 TopoDS_Shape S = DBRep::Get(a[2]);
260 gp_Pnt Or(atof(a[3]),atof(a[4]),atof(a[5]));
261 gp_Dir Di(atof(a[6]),atof(a[7]),atof(a[8]));
263 Standard_Real Radius = atof(a[9]);
265 theHole.Init(S,gp_Ax1(Or,Di));
266 theHole.PerformThruNext(Radius,WithControl);
269 if (theHole.IsDone()) {
271 DBRep::Set(a[1],theHole);
275 theCommands << "Echec de MakeCylindricalHole";
276 Print(theCommands,theHole.Status());
280 static Standard_Integer HOLE3(Draw_Interpretor& theCommands,
281 Standard_Integer narg, const char** a)
283 if (narg<10) return 1;
284 TopoDS_Shape S = DBRep::Get(a[2]);
286 gp_Pnt Or(atof(a[3]),atof(a[4]),atof(a[5]));
287 gp_Dir Di(atof(a[6]),atof(a[7]),atof(a[8]));
289 Standard_Real Radius = atof(a[9]);
291 theHole.Init(S,gp_Ax1(Or,Di));
292 theHole.PerformUntilEnd(Radius,WithControl);
294 if (theHole.IsDone()) {
296 DBRep::Set(a[1],theHole);
300 theCommands << "Echec de MakeCylindricalHole";
301 Print(theCommands,theHole.Status());
306 static Standard_Integer HOLE4(Draw_Interpretor& theCommands,
307 Standard_Integer narg, const char** a)
309 if (narg<11) return 1;
310 TopoDS_Shape S = DBRep::Get(a[2]);
312 gp_Pnt Or(atof(a[3]),atof(a[4]),atof(a[5]));
313 gp_Dir Di(atof(a[6]),atof(a[7]),atof(a[8]));
315 Standard_Real Radius = atof(a[9]);
316 Standard_Real Length = atof(a[10]);
318 theHole.Init(S,gp_Ax1(Or,Di));
319 theHole.PerformBlind(Radius,Length,WithControl);
321 if (theHole.IsDone()) {
323 DBRep::Set(a[1],theHole);
327 theCommands << "Echec de MakeCylindricalHole";
328 Print(theCommands,theHole.Status());
332 static Standard_Integer CONTROL(Draw_Interpretor& theCommands,
333 Standard_Integer narg, const char** a)
336 WithControl = strcmp("0",a[1]);
339 theCommands << "Mode avec controle";
342 theCommands << "Mode sans controle";
348 //=======================================================================
351 //=======================================================================
353 static Standard_Integer PRW(Draw_Interpretor& theCommands,
354 Standard_Integer narg, const char** a)
356 if (narg<9) return 1;
357 TopoDS_Shape S = DBRep::Get(a[3]);
358 BRepFeat_MakePrism thePFace;
360 TopoDS_Shape FFrom,FUntil;
361 Standard_Integer borne;
362 Standard_Boolean fuse;
363 if (a[1][0] == 'f' || a[1][0] == 'F') {
364 fuse = Standard_True;
366 else if (a[1][0] == 'c' || a[1][0] == 'C') {
367 fuse = Standard_False;
373 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
377 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
381 V.SetCoord(atof(a[6]),atof(a[7]),atof(a[8]));
382 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
383 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
387 V.SetCoord(atof(a[5]),atof(a[6]),atof(a[7]));
388 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
393 V.SetCoord(atof(a[4]),atof(a[5]),atof(a[6]));
396 Standard_Real Length = V.Magnitude();
397 if (Length < Precision::Confusion()) {
401 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
402 TopoDS_Face F = TopoDS::Face(aLocalShape);
403 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
404 BRepFeat_SplitShape Spls(F);
405 for (Standard_Integer i = borne+1; i<narg; i++) {
408 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
409 wir = TopoDS::Wire(aLocalShape);
410 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
415 const char* Temp = a[i]+1;
416 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
417 wir = TopoDS::Wire(aLocalShape);
418 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
425 TopoDS_Shape ToPrism;
426 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
427 if (lleft.Extent() == 1) {
428 thePFace.Init(S,lleft.First(),F,V,fuse,Standard_True);
429 ToPrism = lleft.First();
435 TopTools_ListIteratorOfListOfShape it;
436 for (it.Initialize(lleft);it.More();it.Next()) {
437 B.Add(Sh,TopoDS::Face(it.Value()));
439 thePFace.Init(S,Sh,F,V,fuse,Standard_True);
443 // Recherche des faces de glissement, si on n`a pas sketche sur une face
444 // du shape de depart
446 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
447 TopExp_Explorer exp(S,TopAbs_FACE) ;
448 for ( ;exp.More();exp.Next()) {
449 if (exp.Current().IsSame(F)) {
455 LocOpe_FindEdgesInFace FEIF;
456 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
457 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
458 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
459 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
460 Su = Handle(Geom_RectangularTrimmedSurface)::
461 DownCast(Su)->BasisSurface();
463 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
464 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
465 if (pl.Contains(gp_Lin(pl.Location(),V),
466 Precision::Confusion(),
467 Precision::Angular())) {
468 FEIF.Set(ToPrism,fac);
469 for (FEIF.Init();FEIF.More();FEIF.Next()) {
470 thePFace.Add(FEIF.Edge(),fac);
474 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
476 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
477 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
478 FEIF.Set(ToPrism,fac);
479 for (FEIF.Init();FEIF.More();FEIF.Next()) {
480 thePFace.Add(FEIF.Edge(),fac);
488 thePFace.Perform(Length);
490 else if (borne == 8) {
491 thePFace.Perform(FUntil);
493 else if (borne == 9) {
494 if (!(FFrom.IsNull() || FUntil.IsNull())) {
495 thePFace.Perform(FFrom,FUntil);
497 else if (FFrom.IsNull()) {
498 if (!FUntil.IsNull()) {
499 thePFace.PerformFromEnd(FUntil);
502 thePFace.PerformThruAll();
506 // il faudrait inverser V et appeler PerfomFromEnd...
507 //cout << "Not Implemented" << endl;
508 theCommands << "Not Implemented" << "\n";
511 if (!thePFace.IsDone()) {
512 theCommands << "Local operation not done";
516 DBRep::Set(a[2],thePFace);
522 //=======================================================================
525 //=======================================================================
527 static Standard_Integer PRF(Draw_Interpretor& theCommands,
528 Standard_Integer narg, const char** a)
530 if (narg<8) return 1;
531 TopoDS_Shape S = DBRep::Get(a[3]);
532 BRepFeat_MakePrism thePFace;
533 Standard_Integer borne;
535 TopoDS_Shape FFrom,FUntil;
536 Standard_Boolean fuse;
537 if (a[1][0] == 'f' || a[1][0] == 'F') {
538 fuse = Standard_True;
540 else if (a[1][0] == 'c' || a[1][0] == 'C') {
541 fuse = Standard_False;
548 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
552 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
557 V.SetCoord(atof(a[6]),atof(a[7]),atof(a[8]));
558 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
559 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
563 V.SetCoord(atof(a[5]),atof(a[6]),atof(a[7]));
564 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
569 V.SetCoord(atof(a[4]),atof(a[5]),atof(a[6]));
571 Standard_Real Length = V.Magnitude();
572 if (Length < Precision::Confusion()) {
576 TopoDS_Shape ToPrism;
577 if (narg == borne+1) {
578 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
579 TopoDS_Face F = TopoDS::Face(aLocalShape);
580 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
581 thePFace.Init(S,F,F,V,fuse,Standard_True);
588 for (Standard_Integer i=borne; i<narg; i++) {
589 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
590 TopoDS_Face F = TopoDS::Face(aLocalShape);
591 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
596 thePFace.Init(S,She,TopoDS_Face(),V,fuse,Standard_False);
600 // Recherche des faces de glissement, on ne prisme pas une face
601 // du shape de depart
603 // for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
604 TopExp_Explorer exp(ToPrism,TopAbs_FACE) ;
605 for ( ;exp.More();exp.Next()) {
606 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
607 TopExp_Explorer exp2(S,TopAbs_FACE) ;
608 for ( ;exp2.More();exp2.Next()) {
609 if (exp2.Current().IsSame(exp.Current())) {
619 LocOpe_FindEdgesInFace FEIF;
620 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
621 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
622 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
623 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
624 Su = Handle(Geom_RectangularTrimmedSurface)::
625 DownCast(Su)->BasisSurface();
627 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
628 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
629 if (pl.Contains(gp_Lin(pl.Location(),V),
630 Precision::Confusion(),
631 Precision::Angular())) {
632 FEIF.Set(ToPrism,fac);
633 for (FEIF.Init();FEIF.More();FEIF.Next()) {
634 thePFace.Add(FEIF.Edge(),fac);
638 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
640 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
641 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
642 FEIF.Set(ToPrism,fac);
643 for (FEIF.Init();FEIF.More();FEIF.Next()) {
644 thePFace.Add(FEIF.Edge(),fac);
652 thePFace.Perform(Length);
654 else if (borne == 8) {
655 thePFace.Perform(FUntil);
657 else if (borne == 9) {
658 if (!(FFrom.IsNull() || FUntil.IsNull())) {
659 thePFace.Perform(FFrom,FUntil);
661 else if (FFrom.IsNull()) {
662 if (!FUntil.IsNull()) {
663 thePFace.PerformFromEnd(FUntil);
666 thePFace.PerformThruAll();
669 else { //FUntil.IsNull()
670 // il faudrait inverser V et appeler PerfomFromEnd...
671 //cout << "Not Implemented" << endl;
672 theCommands << "Not Implemented" << "\n";
675 if (!thePFace.IsDone()) {
676 theCommands << "Local operation not done";
680 DBRep::Set(a[2],thePFace);
687 //=======================================================================
690 //=======================================================================
692 static Standard_Integer SPLS(Draw_Interpretor& ,
693 Standard_Integer narg, const char** a)
695 Standard_Integer newnarg ;
697 if (narg<3) return 1;
698 TopoDS_Shape S = DBRep::Get(a[2]);
699 BRepFeat_SplitShape Spls(S);
700 Standard_Boolean pick = Standard_False;
703 Standard_Integer i = 3;
705 for ( newnarg=3; newnarg<narg; newnarg++) {
706 if (a[newnarg][0] == '@') {
712 (newnarg !=narg && ((narg-newnarg)<=2 || (narg-newnarg)%2 != 1))) {
717 pick = (a[i][0] == '.');
718 EF = DBRep::Get(a[i],TopAbs_FACE);
719 if (EF.IsNull()) return 1;
722 while (i < newnarg) {
724 DBRep_DrawableShape::LastPick(EF,u,v);
726 if (EF.ShapeType() == TopAbs_FACE) {
727 // face wire/edge ...
729 while (i < newnarg) {
731 Standard_Boolean rever = Standard_False;
732 if (a[i][0] == '-') {
735 pick = (a[i][1] == '.');
736 const char* Temp = a[i]+1;
737 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
738 rever = Standard_True;
741 pick = (a[i][0] == '.');
742 W = DBRep::Get(a[i],TopAbs_SHAPE,Standard_False);
745 return 1; // on n`a rien recupere
747 TopAbs_ShapeEnum wtyp = W.ShapeType();
748 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && pick) {
750 DBRep_DrawableShape::LastPick(W,u,v);
751 wtyp = W.ShapeType();
753 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE) {
754 EF = DBRep::Get(a[i]);
761 if (wtyp == TopAbs_WIRE) {
762 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
765 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
775 // ici, i vaut newnarg
776 for (i++; i<narg; i+=2) {
778 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
779 Es = TopoDS::Edge(aLocalShape);
780 // Es = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
784 aLocalShape = DBRep::Get(a[i+1],TopAbs_EDGE);
785 Ew = TopoDS::Edge(aLocalShape);
786 // Ew = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
790 Spls.Add(TopoDS::Edge(Ew),TopoDS::Edge(Es));
794 DBRep::Set(a[1],Spls);
798 //=======================================================================
799 //function : thickshell
801 //=======================================================================
803 Standard_Integer thickshell(Draw_Interpretor& ,
804 Standard_Integer n, const char** a)
807 //OSD_Chronometer Clock;
809 if ( n < 4) return 1;
810 TopoDS_Shape S = DBRep::Get(a[2]);
811 if (S.IsNull()) return 1;
813 Standard_Real Of = atof(a[3]);
815 GeomAbs_JoinType JT= GeomAbs_Arc;
818 if (!strcmp(a[4],"i"))
819 JT = GeomAbs_Intersection;
820 if (!strcmp(a[4],"t"))
821 JT = GeomAbs_Tangent;
824 Standard_Boolean Inter = Standard_False; //Standard_True;
825 Standard_Real Tol = Precision::Confusion();
829 BRepOffset_MakeOffset B;
830 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT, Standard_True);
835 //B.MakeThickSolid ();
839 DBRep::Set(a[1],B.Shape());
844 //=======================================================================
845 //function : offsetshape
847 //=======================================================================
849 Standard_Integer offsetshape(Draw_Interpretor& ,
850 Standard_Integer n, const char** a)
853 //OSD_Chronometer Clock;
855 if ( n < 4) return 1;
856 TopoDS_Shape S = DBRep::Get(a[2]);
857 if (S.IsNull()) return 1;
859 Standard_Real Of = atof(a[3]);
860 Standard_Boolean Inter = (!strcmp(a[0],"offsetcompshape"));
861 GeomAbs_JoinType JT= GeomAbs_Arc;
862 if (!strcmp(a[0],"offsetinter")) {
863 JT = GeomAbs_Intersection;
864 Inter = Standard_True;
867 BRepOffset_MakeOffset B;
868 Standard_Integer IB = 4;
869 Standard_Real Tol = Precision::Confusion();
871 TopoDS_Shape SF = DBRep::Get(a[4],TopAbs_FACE);
877 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT);
878 //------------------------------------------
879 // recuperation et chargement des bouchons.
880 //----------------------------------------
881 Standard_Boolean YaBouchon = Standard_False;
883 for (Standard_Integer i = IB ; i < n; i++) {
884 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
886 YaBouchon = Standard_True;
887 B.AddFace(TopoDS::Face(SF));
893 if (!YaBouchon) B.MakeOffsetShape();
894 else B.MakeThickSolid ();
897 DBRep::Set(a[1],B.Shape());
902 static BRepOffset_MakeOffset TheOffset;
903 static Standard_Real TheRadius;
904 static Standard_Boolean theYaBouchon;
905 static Standard_Real TheTolerance = Precision::Confusion();
906 static Standard_Boolean TheInter = Standard_False;
907 static GeomAbs_JoinType TheJoin = GeomAbs_Arc;
909 Standard_Integer offsetparameter(Draw_Interpretor& di,
910 Standard_Integer n, const char** a)
913 //cout << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << endl;
914 //cout << " Current Values" << endl;
915 //cout << " --> Tolerance :" << TheTolerance << endl;
916 //cout << " --> TheInter :";
917 di << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << "\n";
918 di << " Current Values" << "\n";
919 di << " --> Tolerance :" << TheTolerance << "\n";
920 di << " --> TheInter :";
922 //cout << "Complet" ;
928 //cout << endl << " --> TheJoin :";
929 di << "\n" << " --> TheJoin :";
932 //case GeomAbs_Arc: cout << " Arc"; break;
933 //case GeomAbs_Intersection: cout << " Intersection"; break;
934 case GeomAbs_Arc: di << " Arc"; break;
935 case GeomAbs_Intersection: di << " Intersection"; break;
947 if ( n < 4 ) return 1;
949 TheTolerance = 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 = 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 = atof(a[i+1]);
1006 TheOffset.SetOffsetOnFace(TopoDS::Face(SF),Of);
1013 //=======================================================================
1014 //function : offsetperform
1016 //=======================================================================
1018 Standard_Integer offsetperform(Draw_Interpretor&,
1019 Standard_Integer n, const char** a)
1021 if ( n < 2) return 1;
1023 if (theYaBouchon) TheOffset.MakeThickSolid ();
1024 else TheOffset.MakeOffsetShape();
1026 DBRep::Set(a[1],TheOffset.Shape());
1032 //=======================================================================
1035 //=======================================================================
1037 static Standard_Integer Debou(Draw_Interpretor& theCommands,
1038 Standard_Integer narg, const char** a)
1040 Standard_Integer i ;
1041 Standard_Integer newnarg ;
1043 if (narg<7) return 1;
1045 TopoDS_Shape S = DBRep::Get(a[2]);
1047 Standard_Boolean Fuse;
1048 if (!strcasecmp("F",a[3])) {
1049 Fuse = Standard_True;
1051 else if (!strcasecmp("C",a[3])) {
1052 Fuse = Standard_False;
1058 for ( newnarg = 4; newnarg < narg; newnarg++) {
1059 if (a[newnarg][0] == '@') {
1063 if (newnarg >= narg-1 || newnarg == 4) {
1068 TopTools_ListOfShape LF,LF2;
1069 for ( i=4; i<newnarg; i++) {
1070 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1071 LF.Append(aLocalShape);
1072 // LF.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1075 for (i=newnarg+1; i<narg; i++) {
1076 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1077 LF2.Append(aLocalShape);
1078 // LF2.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1081 BRepFeat_LocalOperation BLoc(S);
1082 BLoc.Perform(LF,LF2,Fuse);
1084 if (BLoc.IsDone()) {
1086 DBRep::Set(a[1],BLoc);
1090 theCommands << "Local operation not done" ;
1095 //=======================================================================
1098 //=======================================================================
1100 static Standard_Integer ROW(Draw_Interpretor& theCommands,
1101 Standard_Integer narg, const char** a)
1103 if (narg<13) return 1;
1104 TopoDS_Shape S = DBRep::Get(a[3]);
1105 BRepFeat_MakeRevol theRFace;
1108 Standard_Real Angle=0;
1109 TopoDS_Shape FFrom,FUntil;
1110 Standard_Integer i,borne;
1111 Standard_Boolean fuse;
1113 if (a[1][0] == 'f' || a[1][0] == 'F') {
1114 fuse = Standard_True;
1116 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1117 fuse = Standard_False;
1123 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1124 if (FFrom.IsNull()) {
1130 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1131 if (FUntil.IsNull()) {
1146 Or.SetCoord(atof(a[i]),atof(a[i+1]),atof(a[i+2]));
1147 D.SetCoord(atof(a[i+3]),atof(a[i+4]),atof(a[i+5]));
1148 gp_Ax1 theAxis(Or,D);
1150 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1151 TopoDS_Face F = TopoDS::Face(aLocalShape);
1152 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1153 BRepFeat_SplitShape Spls(F);
1154 for (i = borne+1; i<narg; i++) {
1156 if (a[i][0] !='-') {
1157 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
1158 wir = TopoDS::Wire(aLocalShape);
1159 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
1162 if (a[i][1] == '\0')
1164 const char* Temp = a[i]+1;
1165 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
1166 wir = TopoDS::Wire(aLocalShape);
1167 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
1174 TopoDS_Shape ToRotate;
1175 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1176 if (lleft.Extent() == 1) {
1177 theRFace.Init(S,lleft.First(),F,theAxis,fuse,Standard_True);
1178 ToRotate = lleft.First();
1184 TopTools_ListIteratorOfListOfShape it;
1185 for (it.Initialize(lleft);it.More();it.Next()) {
1186 B.Add(Sh,TopoDS::Face(it.Value()));
1188 theRFace.Init(S,Sh,F,theAxis,fuse,Standard_True);
1192 // Recherche des faces de glissement
1193 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
1194 TopExp_Explorer exp(S,TopAbs_FACE) ;
1195 for ( ;exp.More();exp.Next()) {
1196 if (exp.Current().IsSame(F)) {
1202 LocOpe_FindEdgesInFace FEIF;
1203 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1204 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1205 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1206 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1207 Su = Handle(Geom_RectangularTrimmedSurface)::
1208 DownCast(Su)->BasisSurface();
1210 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1211 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1212 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1213 FEIF.Set(ToRotate,fac);
1214 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1215 theRFace.Add(FEIF.Edge(),fac);
1219 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1221 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1222 if (cy.Axis().IsCoaxial(theAxis,
1223 Precision::Angular(),Precision::Confusion())) {
1224 FEIF.Set(ToRotate,fac);
1225 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1226 theRFace.Add(FEIF.Edge(),fac);
1234 if (FUntil.IsNull()) {
1235 theRFace.Perform(Angle);
1238 theRFace.Perform(FUntil);
1241 else { // borne == 12
1242 theRFace.Perform(FFrom,FUntil);
1245 if (!theRFace.IsDone()) {
1246 theCommands << "Local operation not done";
1250 DBRep::Set(a[2],theRFace);
1256 //=======================================================================
1259 //=======================================================================
1261 static Standard_Integer ROF(Draw_Interpretor& theCommands,
1262 Standard_Integer narg, const char** a)
1264 if (narg<12) return 1;
1265 TopoDS_Shape S = DBRep::Get(a[3]);
1266 BRepFeat_MakeRevol theRFace;
1269 Standard_Real Angle=0;
1270 TopoDS_Shape FFrom,FUntil;
1271 Standard_Integer i,borne;
1272 Standard_Boolean fuse;
1274 if (a[1][0] == 'f' || a[1][0] == 'F') {
1275 fuse = Standard_True;
1277 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1278 fuse = Standard_False;
1284 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1285 if (FFrom.IsNull()) {
1291 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1292 if (FUntil.IsNull()) {
1307 Or.SetCoord(atof(a[i]),atof(a[i+1]),atof(a[i+2]));
1308 D.SetCoord(atof(a[i+3]),atof(a[i+4]),atof(a[i+5]));
1309 gp_Ax1 theAxis(Or,D);
1311 TopoDS_Shape ToRotate;
1312 if (narg == borne+1) {
1313 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1314 TopoDS_Face F = TopoDS::Face(aLocalShape);
1315 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1316 theRFace.Init(S,F,F,theAxis,fuse,Standard_True);
1324 for (i=borne; i<narg; i++) {
1325 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1326 TopoDS_Face F = TopoDS::Face(aLocalShape);
1327 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
1332 theRFace.Init(S,She,TopoDS_Face(),theAxis,fuse,Standard_False);
1336 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1337 TopExp_Explorer exp(ToRotate,TopAbs_FACE) ;
1338 for ( ;exp.More();exp.Next()) {
1339 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1340 TopExp_Explorer exp2(S,TopAbs_FACE) ;
1341 for ( ;exp2.More();exp2.Next()) {
1342 if (exp2.Current().IsSame(exp.Current())) {
1352 LocOpe_FindEdgesInFace FEIF;
1353 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1354 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1355 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1356 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1357 Su = Handle(Geom_RectangularTrimmedSurface)::
1358 DownCast(Su)->BasisSurface();
1360 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1361 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1362 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1363 FEIF.Set(ToRotate,fac);
1364 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1365 theRFace.Add(FEIF.Edge(),fac);
1369 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1371 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1372 if (cy.Axis().IsCoaxial(theAxis,
1373 Precision::Angular(),Precision::Confusion())) {
1374 FEIF.Set(ToRotate,fac);
1375 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1376 theRFace.Add(FEIF.Edge(),fac);
1384 if (FUntil.IsNull()) {
1385 theRFace.Perform(Angle);
1388 theRFace.Perform(FUntil);
1391 else { // borne == 12
1392 theRFace.Perform(FFrom,FUntil);
1395 if (!theRFace.IsDone()) {
1396 theCommands << "Local operation not done";
1400 DBRep::Set(a[2],theRFace);
1406 //=======================================================================
1408 //purpose : Commande glue
1409 //=======================================================================
1411 static Standard_Integer GLU(Draw_Interpretor& ,
1412 Standard_Integer narg, const char** a)
1414 if (narg<6 || narg%2 != 0) return 1;
1415 TopoDS_Shape Sne = DBRep::Get(a[2]);
1416 TopoDS_Shape Sba = DBRep::Get(a[3]);
1418 Standard_Boolean pick;
1420 BRepFeat_Gluer theGl(Sne,Sba);
1421 TopoDS_Shape Fne,Fba;
1423 LocOpe_FindEdges fined;
1425 Standard_Integer i = 4;
1426 Standard_Boolean first = Standard_True;
1428 pick = (a[i][0] == '.');
1429 Fne = DBRep::Get(a[i]);
1433 TopAbs_ShapeEnum sht = Fne.ShapeType();
1434 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
1436 DBRep_DrawableShape::LastPick(Fne,u,v);
1437 sht = Fne.ShapeType();
1439 if (first && sht != TopAbs_FACE) {
1442 first = Standard_False;
1443 pick = (a[i+1][0] == '.');
1444 Fba = DBRep::Get(a[i+1]);
1448 if (pick && Fba.ShapeType() != sht) {
1450 DBRep_DrawableShape::LastPick(Fba,u,v);
1452 if (Fba.ShapeType() != sht) {
1455 if (sht == TopAbs_FACE) {
1456 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1457 const TopoDS_Face& f2 = TopoDS::Face(Fba);
1460 for (fined.InitIterator(); fined.More(); fined.Next()) {
1461 theGl.Bind(fined.EdgeFrom(),fined.EdgeTo());
1465 theGl.Bind(TopoDS::Edge(Fne),TopoDS::Edge(Fba));
1470 DBRep::Set(a[1],theGl);
1475 static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
1476 Standard_Integer narg, const char** a)
1479 if (strcasecmp(a[0],"FEATPRISM") &&
1480 strcasecmp(a[0],"FEATDPRISM") &&
1481 strcasecmp(a[0],"FEATREVOL") &&
1482 strcasecmp(a[0],"FEATPIPE") &&
1483 strcasecmp(a[0],"FEATLF") &&
1484 strcasecmp(a[0],"FEATRF")) {
1488 if ((!strcasecmp(a[0],"FEATPRISM") && narg !=9) ||
1489 (!strcasecmp(a[0],"FEATREVOL") && narg != 12) ||
1490 (!strcasecmp(a[0],"FEATDPRISM") && narg != 7) ||
1491 (!strcasecmp(a[0],"FEATPIPE") && narg != 7) ||
1492 (!strcasecmp(a[0],"FEATLF") && narg != 12) ||
1493 (!strcasecmp(a[0],"FEATRF") && narg != 14)) {
1494 theCommands << "invalid number of arguments";
1498 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1499 if (Sbase.IsNull()) {
1500 theCommands << "null basis shape";
1503 Standard_Integer Ifuse = atoi(a[narg-2]);
1504 Standard_Integer Imodif = atoi(a[narg-1]);
1506 Standard_Integer Fuse = Ifuse;
1507 Standard_Boolean Modify = (Imodif!=0);
1513 Handle(Geom_Plane) P;
1515 BRepFeat_StatusError se;
1517 if (strcasecmp(a[0],"FEATLF") && strcasecmp(a[0],"FEATRF")) {
1518 Pbase = DBRep::Get(a[2]);
1519 if (Pbase.IsNull()) {
1520 theCommands << "null shape to transform";
1523 TopoDS_Shape aLocalShape(DBRep::Get(a[3],TopAbs_FACE));
1524 Skface = TopoDS::Face(aLocalShape);
1525 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
1526 if (Skface.IsNull()) {
1527 theCommands << "null face of Sketch";
1532 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1533 W = TopoDS::Wire(aLocalShape);
1534 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1536 theCommands << "null profile for rib or slot";
1539 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1540 P = Handle(Geom_Plane)::DownCast(s);
1542 theCommands << "null plane to transform";
1546 if (narg == 9 || narg == 12 || narg == 14) {
1547 // Standard_Real X,Y,Z,X1,Y1,Z1;
1548 Standard_Real X,Y,Z;
1553 if (narg == 9) { // prism
1554 prdef = Standard_True;
1555 thePrism.Init(Sbase,Pbase,Skface,gp_Dir(X,Y,Z),Fuse,Modify);
1557 else if(narg == 14) {
1558 rfdef = Standard_True;
1563 Standard_Real H1 = atof(a[10]);
1564 Standard_Real H2 = atof(a[11]);
1565 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1566 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1567 if (!theRF.IsDone()) {
1568 se = theRF.CurrentStatusError();
1569 //BRepFeat::Print(se,cout) << endl;
1570 Standard_SStream aSStream;
1571 BRepFeat::Print(se,aSStream);
1572 theCommands << aSStream << "\n";
1576 else if(narg == 12 && strcasecmp(a[0],"FEATLF")) {
1577 rvdef = Standard_True;
1582 theRevol.Init(Sbase,Pbase,Skface,gp_Ax1(Or,gp_Dir(X,Y,Z)),
1586 lfdef = Standard_True;
1587 gp_Vec Direct(X,Y,Z);
1591 theLF.Init(Sbase, W, P, Direct, gp_Vec(X,Y,Z), Fuse,Modify);
1592 if (!theLF.IsDone()) {
1593 se = theLF.CurrentStatusError();
1594 //BRepFeat::Print(se,cout) << endl;
1595 Standard_SStream aSStream;
1596 BRepFeat::Print(se,aSStream);
1597 theCommands << aSStream << "\n";
1602 else if (narg == 7) {
1603 if (!strcasecmp(a[0],"FEATDPRISM")) {
1604 if (Pbase.ShapeType() != TopAbs_FACE) {
1605 theCommands << "Invalid DPrism base";
1608 Standard_Real Angle = atof(a[4])*M_PI/360;
1609 dprdef = Standard_True;
1610 theDPrism.Init(Sbase,TopoDS::Face(Pbase),Skface,Angle,Fuse,Modify);
1613 TopoDS_Shape aLocalShape(DBRep::Get(a[4],TopAbs_WIRE));
1614 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
1615 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
1616 if (Spine.IsNull()) {
1617 TopoDS_Shape Edspine =DBRep::Get(a[4],TopAbs_EDGE);
1618 if (Edspine.IsNull()) {
1619 theCommands << "null spine";
1624 B.Add(Spine,Edspine);
1626 pidef = Standard_True;
1627 thePipe.Init(Sbase,Pbase,Skface,Spine,Fuse,Modify);
1635 static Standard_Integer ADD(Draw_Interpretor& ,
1636 Standard_Integer narg, const char** a)
1638 Standard_Integer i ;
1639 if (narg < 4 || narg%2 != 0) {
1642 if (!strcasecmp("PRISM",a[1])) {
1646 for ( i=2; i<narg; i+=2) {
1647 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1648 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1649 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1653 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1654 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1655 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1659 thePrism.Add(edg,fac);
1662 else if (!strcasecmp("REVOL",a[1])) {
1666 for ( i=2; i<narg; i+=2) {
1667 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1668 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1669 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1673 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1674 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1675 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1679 theRevol.Add(edg,fac);
1682 else if (!strcasecmp("PIPE",a[1])) {
1686 for ( i=2; i<narg; i+=2) {
1687 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1688 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1689 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1693 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1694 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1695 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1699 thePipe.Add(edg,fac);
1710 static Standard_Integer PERF(Draw_Interpretor& theCommands,
1711 Standard_Integer narg, const char** a)
1716 if (strcasecmp(a[0],"FEATPERFORM") &&
1717 strcasecmp(a[0],"FEATPERFORMVAL")) {
1721 Standard_Integer Kas;
1722 if (!strcasecmp("PRISM",a[1])) {
1725 theCommands << "prism not defined";
1729 else if (!strcasecmp("REVOL",a[1])) {
1732 theCommands << "revol not defined";
1736 else if (!strcasecmp("PIPE",a[1])) {
1739 theCommands << "pipe not defined";
1742 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1743 theCommands << "invalid command for pipe";
1747 else if (!strcasecmp("DPRISM",a[1])) {
1750 theCommands << "dprism not defined";
1754 else if (!strcasecmp("LF",a[1])) {
1757 theCommands << "lf not defined";
1760 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1761 theCommands << "invalid command for lf";
1765 else if (!strcasecmp("RF",a[1])) {
1768 theCommands << "rf not defined";
1771 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1772 theCommands << "invalid command for rf";
1777 theCommands << "unknown argument : " << a[1];
1781 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1782 if (narg !=4 && narg != 5) {
1783 theCommands << "invalid number of arguments";
1787 Standard_Real Val = atof(a[3]);
1789 thePrism.Perform(Val);
1791 else if (Kas == 2) {
1793 theRevol.Perform(Val);
1795 else if (Kas == 4) {
1796 theDPrism.Perform(Val);
1798 else if (Kas == 5) {
1799 theCommands << "invalid command for lf";
1802 else if (Kas == 6) {
1803 theCommands << "invalid command for rf";
1807 else if(narg == 5) {
1808 Standard_Real Val = atof(a[3]);
1809 TopoDS_Shape FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
1811 thePrism.PerformUntilHeight(FUntil, Val);
1813 else if (Kas == 2) {
1815 theRevol.PerformUntilAngle(FUntil, Val);
1817 else if (Kas == 4) {
1818 theDPrism.PerformUntilHeight(FUntil, Val);
1821 theCommands << "invalid command for ribs or slots";
1826 else if (!strcasecmp(a[0],"FEATPERFORM")) {
1827 if (narg == 3) { // Thru all
1830 thePrism.PerformThruAll();
1833 theRevol.PerformThruAll();
1839 theDPrism.PerformThruAll();
1852 else if (narg == 4) { // Until
1853 TopoDS_Shape Funtil = DBRep::Get(a[3],TopAbs_SHAPE);
1857 if (Funtil.IsNull()) {
1858 thePrism.PerformUntilEnd();
1861 thePrism.Perform(Funtil);
1867 if (!Funtil.IsNull()) {
1868 theRevol.Perform(Funtil);
1877 if (!Funtil.IsNull()) {
1878 thePipe.Perform(Funtil);
1881 theCommands << "invalid command for ribs pipe";
1888 if (!Funtil.IsNull()) {
1889 theDPrism.Perform(Funtil);
1892 theDPrism.PerformUntilEnd();
1898 theCommands << "invalid command for lf";
1904 theCommands << "invalid command for rf";
1912 else if (narg == 5) {
1913 TopoDS_Shape Ffrom = DBRep::Get(a[3],TopAbs_SHAPE);
1914 TopoDS_Shape Funtil = DBRep::Get(a[4],TopAbs_SHAPE);
1915 if (Funtil.IsNull()) {
1921 if (Ffrom.IsNull()) {
1922 thePrism.PerformFromEnd(Funtil);
1925 thePrism.Perform(Ffrom,Funtil);
1931 if (Ffrom.IsNull()) {
1934 theRevol.Perform(Ffrom,Funtil);
1939 if (Ffrom.IsNull()) {
1942 thePipe.Perform(Ffrom,Funtil);
1947 if (Ffrom.IsNull()) {
1948 theDPrism.PerformFromEnd(Funtil);
1951 theDPrism.Perform(Ffrom,Funtil);
1962 BRepFeat_StatusError se;
1965 if (!thePrism.IsDone()) {
1966 se = thePrism.CurrentStatusError();
1967 //BRepFeat::Print(se,cout) << endl;
1968 Standard_SStream aSStream;
1969 BRepFeat::Print(se,aSStream);
1970 theCommands << aSStream << "\n";
1973 DBRep::Set(a[2],thePrism);
1977 if (!theRevol.IsDone()) {
1978 se = theRevol.CurrentStatusError();
1979 //BRepFeat::Print(se,cout) << endl;
1980 Standard_SStream aSStream;
1981 BRepFeat::Print(se,aSStream);
1982 theCommands << aSStream << "\n";
1985 DBRep::Set(a[2],theRevol);
1989 if (!thePipe.IsDone()) {
1990 se = thePipe.CurrentStatusError();
1991 //BRepFeat::Print(se,cout) << endl;
1992 Standard_SStream aSStream;
1993 BRepFeat::Print(se,aSStream);
1994 theCommands << aSStream << "\n";
1997 DBRep::Set(a[2],thePipe);
2001 if (!theDPrism.IsDone()) {
2002 se = theDPrism.CurrentStatusError();
2003 //BRepFeat::Print(se,cout) << endl;
2004 Standard_SStream aSStream;
2005 BRepFeat::Print(se,aSStream);
2006 theCommands << aSStream << "\n";
2009 DBRep::Set(a[2],theDPrism);
2013 if (!theLF.IsDone()) {
2014 se = theLF.CurrentStatusError();
2015 //BRepFeat::Print(se,cout) << endl;
2016 Standard_SStream aSStream;
2017 BRepFeat::Print(se,aSStream);
2018 theCommands << aSStream << "\n";
2021 DBRep::Set(a[2],theLF);
2025 if (!theRF.IsDone()) {
2026 se = theRF.CurrentStatusError();
2027 //BRepFeat::Print(se,cout) << endl;
2028 Standard_SStream aSStream;
2029 BRepFeat::Print(se,aSStream);
2030 theCommands << aSStream << "\n";
2033 DBRep::Set(a[2],theRF);
2042 static Standard_Integer BOSS(Draw_Interpretor& theCommands,
2043 Standard_Integer narg, const char** a)
2045 if (strcasecmp(a[0],"ENDEDGES") && strcasecmp(a[0],"FILLET")
2046 && strcasecmp(a[0],"BOSSAGE")) {
2050 if ((!strcasecmp(a[0],"ENDEDGES") && narg !=5) ||
2051 (!strcasecmp(a[0],"FILLET") && narg <5 && narg%2 != 1) ||
2052 (!strcasecmp(a[0],"BOSSAGE") && narg != 6)) {
2053 theCommands << "invalid number of arguments";
2057 Standard_Integer Kas=0;
2058 Standard_Integer dprsig=0;
2059 if (!strcasecmp("ENDEDGES",a[0])) {
2061 dprsig = atoi(a[4]);
2063 else if (!strcasecmp("FILLET",a[0])) {
2066 else if (!strcasecmp("BOSSAGE",a[0])) {
2068 dprsig = atoi(a[5]);
2071 TopoDS_Shape theShapeTop;
2072 TopoDS_Shape theShapeBottom;
2074 if (Kas == 1 || Kas == 3) {
2075 if (!strcasecmp("DPRISM",a[1])) {
2077 theCommands << "dprism not defined";
2082 theCommands << "unknown argument : " << a[1];
2086 theDPrism.BossEdges(dprsig);
2088 TopTools_ListOfShape theTopEdges, theLatEdges;
2089 theTopEdges = theDPrism.TopEdges();
2090 theLatEdges = theDPrism.LatEdges();
2092 TopTools_ListIteratorOfListOfShape it;
2095 B.MakeCompound(TopoDS::Compound(theShapeTop));
2096 it.Initialize(theTopEdges);
2097 for(; it.More(); it.Next()) {
2098 TopExp_Explorer exp;
2099 for (exp.Init(it.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
2100 B.Add(theShapeTop,exp.Current());
2103 DBRep::Set(a[2],theShapeTop);
2106 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2107 it.Initialize(theLatEdges);
2108 for(; it.More(); it.Next()) {
2109 B.Add(theShapeBottom,it.Value());
2111 DBRep::Set(a[3],theShapeBottom);
2113 if (Kas == 1) return 0;
2116 if (Kas == 2 || Kas == 3) {
2118 // Standard_Integer nrad;
2121 V = DBRep::Get(a[2],TopAbs_SHAPE);
2123 else if (Kas == 3) {
2127 if(V.IsNull()) return 1;
2128 ChFi3d_FilletShape FSh = ChFi3d_Rational;
2129 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
2130 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
2131 Rakk->SetContinuity(blend_cont, tapp_angle);
2135 Standard_Integer nbedge = 0;
2138 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
2139 Rad = atof(a[2*ii + 1]);
2140 if (Rad == 0.) continue;
2141 S = DBRep::Get(a[(2*ii+2)],TopAbs_SHAPE);
2142 TopExp_Explorer exp;
2143 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2144 E = TopoDS::Edge(exp.Current());
2152 else if (Kas == 3) {
2156 TopExp_Explorer exp;
2157 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2158 E = TopoDS::Edge(exp.Current());
2168 TopExp_Explorer exp;
2169 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2170 E = TopoDS::Edge(exp.Current());
2179 if(!nbedge) return 1;
2181 if(!Rakk->IsDone()) return 1;
2182 TopoDS_Shape res = Rakk->Shape();
2185 DBRep::Set(a[1],res);
2187 else if (Kas == 3) {
2188 DBRep::Set(a[2],res);
2198 //=======================================================================
2199 //function : FeatureCommands
2201 //=======================================================================
2203 void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
2205 static Standard_Boolean done = Standard_False;
2207 done = Standard_True;
2209 DBRep::BasicCommands(theCommands);
2211 const char* g = "TOPOLOGY Feature commands";
2213 theCommands.Add("localope",
2214 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2217 theCommands.Add("hole",
2218 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2221 theCommands.Add("firsthole",
2222 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2225 theCommands.Add("holend",
2226 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2229 theCommands.Add("blindhole",
2230 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2233 theCommands.Add("holecontrol",
2234 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2235 __FILE__,CONTROL,g);
2237 theCommands.Add("wprism",
2238 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2242 theCommands.Add("fprism",
2243 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2247 theCommands.Add("wrotate",
2248 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2252 theCommands.Add("frotate",
2253 "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...]",
2257 theCommands.Add("splitshape",
2258 "splitshape result shape face wire/edge [wire/edge ...][face wire/edge [wire/edge...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2262 theCommands.Add("thickshell",
2263 "thickshell r shape offset [jointype [tol] ]",
2264 __FILE__,thickshell,g);
2266 theCommands.Add("offsetshape",
2267 "offsetshape r shape offset [tol] [face ...]",
2268 __FILE__,offsetshape,g);
2270 theCommands.Add("offsetcompshape",
2271 "offsetcompshape r shape offset [face ...]",
2272 __FILE__,offsetshape,g);
2274 theCommands.Add("offsetparameter",
2275 "offsetparameter tol inter(a/i) join(a/i)",
2276 __FILE__,offsetparameter);
2278 theCommands.Add("offsetload",
2279 "offsetload shape offset bouchon1 bouchon2 ...",
2280 __FILE__,offsetload,g);
2282 theCommands.Add("offsetonface",
2283 "offsetonface face1 offset1 face2 offset2 ...",
2284 __FILE__,offsetonface,g);
2286 theCommands.Add("offsetperform",
2287 "offsetperform result",
2288 __FILE__,offsetperform,g);
2291 theCommands.Add("deboucle",
2292 " Essai de debouclage partiel: deboucle result shape F/C face [face...] @ face [face...]",
2296 theCommands.Add("glue",
2297 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2301 theCommands.Add("featprism",
2302 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2305 theCommands.Add("featrevol",
2306 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2309 theCommands.Add("featpipe",
2310 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2313 theCommands.Add("featdprism",
2314 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2317 theCommands.Add("featlf",
2318 "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)",
2321 theCommands.Add("featrf",
2322 "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)",
2325 theCommands.Add("addslide",
2326 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2329 theCommands.Add("featperform",
2330 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2333 theCommands.Add("featperformval",
2334 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2337 theCommands.Add("endedges",
2338 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2341 theCommands.Add("fillet",
2342 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2345 theCommands.Add("bossage",
2346 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",