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_Builder.hxx>
51 #include <BRepFeat_MakeCylindricalHole.hxx>
52 #include <BRepFeat_SplitShape.hxx>
53 #include <BRepFeat_Gluer.hxx>
55 #include <BRepFeat.hxx>
56 #include <BRepFeat_MakePrism.hxx>
57 #include <BRepFeat_MakeRevol.hxx>
58 #include <BRepFeat_MakePipe.hxx>
59 #include <BRepFeat_MakeDPrism.hxx>
60 #include <BRepFeat_MakeLinearForm.hxx>
61 #include <BRepFeat_MakeRevolutionForm.hxx>
63 #include <LocOpe_FindEdges.hxx>
64 #include <LocOpe_FindEdgesInFace.hxx>
66 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
67 #include <BRepOffsetAPI_MakeThickSolid.hxx>
68 #include <BRep_Tool.hxx>
69 #include <BRep_Builder.hxx>
71 #include <DBRep_DrawableShape.hxx>
72 #include <BRepTest.hxx>
74 #include <BRepFilletAPI_MakeFillet.hxx>
75 #include <ChFi3d_FilletShape.hxx>
77 #include <Precision.hxx>
80 //#define strcasecmp _stricmp Already defined
81 Standard_IMPORT Draw_Viewer dout;
87 static BRepFeat_MakeCylindricalHole theHole;
88 static Standard_Boolean WithControl = Standard_True;
90 Standard_Boolean DownCastingEnforcing = Standard_False;
92 static BRepFeat_MakePrism thePrism;
93 static BRepFeat_MakeDPrism theDPrism;
94 static BRepFeat_MakeRevol theRevol;
95 static BRepFeat_MakePipe thePipe;
96 static BRepFeat_MakeLinearForm theLF;
97 static BRepFeat_MakeRevolutionForm theRF;
99 static Standard_Boolean dprdef = Standard_False;
100 static Standard_Boolean prdef = Standard_False;
101 static Standard_Boolean rvdef = Standard_False;
102 static Standard_Boolean pidef = Standard_False;
103 static Standard_Boolean lfdef = Standard_False;
104 static Standard_Boolean rfdef = Standard_False;
106 static Standard_Real t3d = 1.e-4;
107 static Standard_Real t2d = 1.e-5;
108 static Standard_Real ta = 1.e-2;
109 static Standard_Real fl = 1.e-3;
110 static Standard_Real tapp_angle = 1.e-2;
111 static GeomAbs_Shape blend_cont = GeomAbs_C1;
112 static BRepFilletAPI_MakeFillet* Rakk = 0;
116 static void Print(Draw_Interpretor& di,
117 const BRepFeat_Status St)
119 di << " Error Status : ";
121 case BRepFeat_NoError:
125 case BRepFeat_InvalidPlacement:
126 di << "Invalid placement";
129 case BRepFeat_HoleTooLong:
130 di << "Hole too long";
135 static Standard_Integer Loc(Draw_Interpretor& theCommands,
136 Standard_Integer narg, const char** a)
138 if (narg<6) return 1;
139 TopoDS_Shape S = DBRep::Get(a[2]);
140 TopoDS_Shape T = DBRep::Get(a[3]);
142 Standard_Boolean Fuse;
143 if (!strcasecmp("F",a[4])) {
144 Fuse = Standard_True;
146 else if (!strcasecmp("C",a[4])) {
147 Fuse = Standard_False;
153 TopTools_ListOfShape LF;
154 for (Standard_Integer i=0; i<= narg-6; i++) {
155 TopoDS_Shape aLocalShape(DBRep::Get(a[i+5],TopAbs_FACE));
156 LF.Append(aLocalShape);
157 // LF.Append(TopoDS::Face(DBRep::Get(a[i+5],TopAbs_FACE)));
160 //BRepFeat_LocalOperation BLoc(S);
161 //BLoc.Perform(T,LF,Fuse);
162 //BLoc.BuildPartsOfTool();
163 TopTools_ListOfShape parts;
164 BRepFeat_Builder BLoc;
166 BLoc.SetOperation(Fuse);
167 //BRepFeat_LocalOperation BLoc;
168 //BLoc.Init(S,T,Fuse);
170 BLoc.PartsOfTool(parts);
174 strcpy(newname,a[1]);
176 while (*p != '\0') p++;
179 TopTools_ListIteratorOfListOfShape its(parts);
182 for (; its.More(); its.Next()) {
185 DBRep::Set(newname,its.Value());
189 Standard_Integer qq,ww,ee,button;
192 TopoDS_Shape aLocalShape(DBRep::Get(".",TopAbs_SHELL));
193 S = TopoDS::Shell(aLocalShape);
194 // S = TopoDS::Shell(DBRep::Get(".",TopAbs_SHELL));
195 Draw::LastPick(qq,ww,ee,button);
200 //BLoc.RemovePart(S);
213 } while (button != 3);
216 BLoc.PerformResult();
217 if (!BLoc.ErrorStatus()) {
219 DBRep::Set(a[1],BLoc.Shape());
223 theCommands << "Local operation not done" ;
229 static Standard_Integer HOLE1(Draw_Interpretor& theCommands,
230 Standard_Integer narg, const char** a)
232 if (narg<10 || narg == 11) return 1;
233 TopoDS_Shape S = DBRep::Get(a[2]);
235 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
236 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
238 Standard_Real Radius = Draw::Atof(a[9]);
240 theHole.Init(S,gp_Ax1(Or,Di));
243 theHole.Perform(Radius);
246 Standard_Real pfrom = Draw::Atof(a[10]);
247 Standard_Real pto = Draw::Atof(a[11]);
248 theHole.Perform(Radius,pfrom,pto,WithControl);
252 if (!theHole.ErrorStatus()) {
254 DBRep::Set(a[1],theHole.Shape());
258 theCommands << "Echec de MakeCylindricalHole";
259 Print(theCommands,theHole.Status());
263 static Standard_Integer HOLE2(Draw_Interpretor& theCommands,
264 Standard_Integer narg, const char** a)
266 if (narg<10) return 1;
267 TopoDS_Shape S = DBRep::Get(a[2]);
269 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
270 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
272 Standard_Real Radius = Draw::Atof(a[9]);
274 theHole.Init(S,gp_Ax1(Or,Di));
275 theHole.PerformThruNext(Radius,WithControl);
278 if (!theHole.ErrorStatus()) {
280 DBRep::Set(a[1],theHole.Shape());
284 theCommands << "Echec de MakeCylindricalHole";
285 Print(theCommands,theHole.Status());
289 static Standard_Integer HOLE3(Draw_Interpretor& theCommands,
290 Standard_Integer narg, const char** a)
292 if (narg<10) return 1;
293 TopoDS_Shape S = DBRep::Get(a[2]);
295 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
296 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
298 Standard_Real Radius = Draw::Atof(a[9]);
300 theHole.Init(S,gp_Ax1(Or,Di));
301 theHole.PerformUntilEnd(Radius,WithControl);
303 if (!theHole.ErrorStatus()) {
305 DBRep::Set(a[1],theHole.Shape());
309 theCommands << "Echec de MakeCylindricalHole";
310 Print(theCommands,theHole.Status());
315 static Standard_Integer HOLE4(Draw_Interpretor& theCommands,
316 Standard_Integer narg, const char** a)
318 if (narg<11) return 1;
319 TopoDS_Shape S = DBRep::Get(a[2]);
321 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
322 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
324 Standard_Real Radius = Draw::Atof(a[9]);
325 Standard_Real Length = Draw::Atof(a[10]);
327 theHole.Init(S,gp_Ax1(Or,Di));
328 theHole.PerformBlind(Radius,Length,WithControl);
330 if (!theHole.ErrorStatus()) {
332 DBRep::Set(a[1],theHole.Shape());
336 theCommands << "Echec de MakeCylindricalHole";
337 Print(theCommands,theHole.Status());
341 static Standard_Integer CONTROL(Draw_Interpretor& theCommands,
342 Standard_Integer narg, const char** a)
345 WithControl = strcmp("0",a[1]);
348 theCommands << "Mode avec controle";
351 theCommands << "Mode sans controle";
357 //=======================================================================
360 //=======================================================================
362 static Standard_Integer PRW(Draw_Interpretor& theCommands,
363 Standard_Integer narg, const char** a)
365 if (narg<9) return 1;
366 TopoDS_Shape S = DBRep::Get(a[3]);
367 BRepFeat_MakePrism thePFace;
369 TopoDS_Shape FFrom,FUntil;
370 Standard_Integer borne;
371 Standard_Boolean fuse;
372 if (a[1][0] == 'f' || a[1][0] == 'F') {
373 fuse = Standard_True;
375 else if (a[1][0] == 'c' || a[1][0] == 'C') {
376 fuse = Standard_False;
382 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
386 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
390 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
391 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
392 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
396 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
397 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
402 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
405 Standard_Real Length = V.Magnitude();
406 if (Length < Precision::Confusion()) {
410 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
411 TopoDS_Face F = TopoDS::Face(aLocalShape);
412 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
413 BRepFeat_SplitShape Spls(F);
414 for (Standard_Integer i = borne+1; i<narg; i++) {
417 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
418 wir = TopoDS::Wire(aLocalShape);
419 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
424 const char* Temp = a[i]+1;
425 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
426 wir = TopoDS::Wire(aLocalShape);
427 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
434 TopoDS_Shape ToPrism;
435 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
436 if (lleft.Extent() == 1) {
437 thePFace.Init(S,lleft.First(),F,V,fuse,Standard_True);
438 ToPrism = lleft.First();
444 TopTools_ListIteratorOfListOfShape it;
445 for (it.Initialize(lleft);it.More();it.Next()) {
446 B.Add(Sh,TopoDS::Face(it.Value()));
448 thePFace.Init(S,Sh,F,V,fuse,Standard_True);
452 // Recherche des faces de glissement, si on n`a pas sketche sur une face
453 // du shape de depart
455 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
456 TopExp_Explorer exp(S,TopAbs_FACE) ;
457 for ( ;exp.More();exp.Next()) {
458 if (exp.Current().IsSame(F)) {
464 LocOpe_FindEdgesInFace FEIF;
465 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
466 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
467 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
468 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
469 Su = Handle(Geom_RectangularTrimmedSurface)::
470 DownCast(Su)->BasisSurface();
472 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
473 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
474 if (pl.Contains(gp_Lin(pl.Location(),V),
475 Precision::Confusion(),
476 Precision::Angular())) {
477 FEIF.Set(ToPrism,fac);
478 for (FEIF.Init();FEIF.More();FEIF.Next()) {
479 thePFace.Add(FEIF.Edge(),fac);
483 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
485 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
486 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
487 FEIF.Set(ToPrism,fac);
488 for (FEIF.Init();FEIF.More();FEIF.Next()) {
489 thePFace.Add(FEIF.Edge(),fac);
497 thePFace.Perform(Length);
499 else if (borne == 8) {
500 thePFace.Perform(FUntil);
502 else if (borne == 9) {
503 if (!(FFrom.IsNull() || FUntil.IsNull())) {
504 thePFace.Perform(FFrom,FUntil);
506 else if (FFrom.IsNull()) {
507 if (!FUntil.IsNull()) {
508 thePFace.PerformFromEnd(FUntil);
511 thePFace.PerformThruAll();
515 // il faudrait inverser V et appeler PerfomFromEnd...
516 //cout << "Not Implemented" << endl;
517 theCommands << "Not Implemented" << "\n";
520 if (!thePFace.IsDone()) {
521 theCommands << "Local operation not done";
525 DBRep::Set(a[2],thePFace);
531 //=======================================================================
534 //=======================================================================
536 static Standard_Integer PRF(Draw_Interpretor& theCommands,
537 Standard_Integer narg, const char** a)
539 if (narg<8) return 1;
540 TopoDS_Shape S = DBRep::Get(a[3]);
541 BRepFeat_MakePrism thePFace;
542 Standard_Integer borne;
544 TopoDS_Shape FFrom,FUntil;
545 Standard_Boolean fuse;
546 if (a[1][0] == 'f' || a[1][0] == 'F') {
547 fuse = Standard_True;
549 else if (a[1][0] == 'c' || a[1][0] == 'C') {
550 fuse = Standard_False;
557 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
561 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
566 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
567 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
568 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
572 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
573 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
578 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
580 Standard_Real Length = V.Magnitude();
581 if (Length < Precision::Confusion()) {
585 TopoDS_Shape ToPrism;
586 if (narg == borne+1) {
587 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
588 TopoDS_Face F = TopoDS::Face(aLocalShape);
589 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
590 thePFace.Init(S,F,F,V,fuse,Standard_True);
597 for (Standard_Integer i=borne; i<narg; i++) {
598 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
599 TopoDS_Face F = TopoDS::Face(aLocalShape);
600 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
605 thePFace.Init(S,She,TopoDS_Face(),V,fuse,Standard_False);
609 // Recherche des faces de glissement, on ne prisme pas une face
610 // du shape de depart
612 // for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
613 TopExp_Explorer exp(ToPrism,TopAbs_FACE) ;
614 for ( ;exp.More();exp.Next()) {
615 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
616 TopExp_Explorer exp2(S,TopAbs_FACE) ;
617 for ( ;exp2.More();exp2.Next()) {
618 if (exp2.Current().IsSame(exp.Current())) {
628 LocOpe_FindEdgesInFace FEIF;
629 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
630 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
631 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
632 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
633 Su = Handle(Geom_RectangularTrimmedSurface)::
634 DownCast(Su)->BasisSurface();
636 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
637 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
638 if (pl.Contains(gp_Lin(pl.Location(),V),
639 Precision::Confusion(),
640 Precision::Angular())) {
641 FEIF.Set(ToPrism,fac);
642 for (FEIF.Init();FEIF.More();FEIF.Next()) {
643 thePFace.Add(FEIF.Edge(),fac);
647 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
649 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
650 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
651 FEIF.Set(ToPrism,fac);
652 for (FEIF.Init();FEIF.More();FEIF.Next()) {
653 thePFace.Add(FEIF.Edge(),fac);
661 thePFace.Perform(Length);
663 else if (borne == 8) {
664 thePFace.Perform(FUntil);
666 else if (borne == 9) {
667 if (!(FFrom.IsNull() || FUntil.IsNull())) {
668 thePFace.Perform(FFrom,FUntil);
670 else if (FFrom.IsNull()) {
671 if (!FUntil.IsNull()) {
672 thePFace.PerformFromEnd(FUntil);
675 thePFace.PerformThruAll();
678 else { //FUntil.IsNull()
679 // il faudrait inverser V et appeler PerfomFromEnd...
680 //cout << "Not Implemented" << endl;
681 theCommands << "Not Implemented" << "\n";
684 if (!thePFace.IsDone()) {
685 theCommands << "Local operation not done";
689 DBRep::Set(a[2],thePFace);
696 //=======================================================================
699 //=======================================================================
701 static Standard_Integer SPLS(Draw_Interpretor& ,
702 Standard_Integer narg, const char** a)
704 Standard_Integer newnarg ;
706 if (narg<3) return 1;
707 TopoDS_Shape S = DBRep::Get(a[2]);
708 BRepFeat_SplitShape Spls(S);
709 Standard_Boolean pick = Standard_False;
712 Standard_Integer i = 3;
714 for ( newnarg=3; newnarg<narg; newnarg++) {
715 if (a[newnarg][0] == '@') {
721 (newnarg !=narg && ((narg-newnarg)<=2 || (narg-newnarg)%2 != 1))) {
726 pick = (a[i][0] == '.');
727 EF = DBRep::Get(a[i],TopAbs_FACE);
728 if (EF.IsNull()) return 1;
731 while (i < newnarg) {
733 DBRep_DrawableShape::LastPick(EF,u,v);
735 if (EF.ShapeType() == TopAbs_FACE) {
736 // face wire/edge ...
738 while (i < newnarg) {
740 Standard_Boolean rever = Standard_False;
741 if (a[i][0] == '-') {
744 pick = (a[i][1] == '.');
745 const char* Temp = a[i]+1;
746 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
747 rever = Standard_True;
750 pick = (a[i][0] == '.');
751 W = DBRep::Get(a[i],TopAbs_SHAPE,Standard_False);
754 return 1; // on n`a rien recupere
756 TopAbs_ShapeEnum wtyp = W.ShapeType();
757 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND && pick) {
759 DBRep_DrawableShape::LastPick(W,u,v);
760 wtyp = W.ShapeType();
762 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND) {
763 EF = DBRep::Get(a[i]);
770 if (wtyp == TopAbs_WIRE) {
771 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
773 else if (wtyp == TopAbs_EDGE) {
774 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
777 Spls.Add(TopoDS::Compound(W),TopoDS::Face(EF));
787 // ici, i vaut newnarg
788 for (i++; i<narg; i+=2) {
790 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
791 Es = TopoDS::Edge(aLocalShape);
792 // Es = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
796 aLocalShape = DBRep::Get(a[i+1],TopAbs_EDGE);
797 Ew = TopoDS::Edge(aLocalShape);
798 // Ew = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
802 Spls.Add(TopoDS::Edge(Ew),TopoDS::Edge(Es));
806 DBRep::Set(a[1],Spls);
810 //=======================================================================
811 //function : thickshell
813 //=======================================================================
815 Standard_Integer thickshell(Draw_Interpretor& ,
816 Standard_Integer n, const char** a)
819 //OSD_Chronometer Clock;
821 if ( n < 4) return 1;
822 TopoDS_Shape S = DBRep::Get(a[2]);
823 if (S.IsNull()) return 1;
825 Standard_Real Of = Draw::Atof(a[3]);
827 GeomAbs_JoinType JT= GeomAbs_Arc;
830 if (!strcmp(a[4],"i"))
831 JT = GeomAbs_Intersection;
832 if (!strcmp(a[4],"t"))
833 JT = GeomAbs_Tangent;
836 Standard_Boolean Inter = Standard_False; //Standard_True;
837 Standard_Real Tol = Precision::Confusion();
839 Tol = Draw::Atof(a[5]);
841 BRepOffset_MakeOffset B;
842 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT, Standard_True);
847 //B.MakeThickSolid ();
851 DBRep::Set(a[1],B.Shape());
856 //=======================================================================
857 //function : offsetshape
859 //=======================================================================
861 Standard_Integer offsetshape(Draw_Interpretor& ,
862 Standard_Integer n, const char** a)
865 //OSD_Chronometer Clock;
867 if ( n < 4) return 1;
868 TopoDS_Shape S = DBRep::Get(a[2]);
869 if (S.IsNull()) return 1;
871 Standard_Real Of = Draw::Atof(a[3]);
872 Standard_Boolean Inter = (!strcmp(a[0],"offsetcompshape"));
873 GeomAbs_JoinType JT= GeomAbs_Arc;
874 if (!strcmp(a[0],"offsetinter")) {
875 JT = GeomAbs_Intersection;
876 Inter = Standard_True;
879 BRepOffset_MakeOffset B;
880 Standard_Integer IB = 4;
881 Standard_Real Tol = Precision::Confusion();
883 TopoDS_Shape SF = DBRep::Get(a[4],TopAbs_FACE);
886 Tol = Draw::Atof(a[4]);
889 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT);
890 //------------------------------------------
891 // recuperation et chargement des bouchons.
892 //----------------------------------------
893 Standard_Boolean YaBouchon = Standard_False;
895 for (Standard_Integer i = IB ; i < n; i++) {
896 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
898 YaBouchon = Standard_True;
899 B.AddFace(TopoDS::Face(SF));
905 if (!YaBouchon) B.MakeOffsetShape();
906 else B.MakeThickSolid ();
909 DBRep::Set(a[1],B.Shape());
914 static BRepOffset_MakeOffset TheOffset;
915 static Standard_Real TheRadius;
916 static Standard_Boolean theYaBouchon;
917 static Standard_Real TheTolerance = Precision::Confusion();
918 static Standard_Boolean TheInter = Standard_False;
919 static GeomAbs_JoinType TheJoin = GeomAbs_Arc;
921 Standard_Integer offsetparameter(Draw_Interpretor& di,
922 Standard_Integer n, const char** a)
925 //cout << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << endl;
926 //cout << " Current Values" << endl;
927 //cout << " --> Tolerance :" << TheTolerance << endl;
928 //cout << " --> TheInter :";
929 di << " OffsetParameter Tol Inter(c/p) JoinType(a/i)" << "\n";
930 di << " Current Values" << "\n";
931 di << " --> Tolerance :" << TheTolerance << "\n";
932 di << " --> TheInter :";
934 //cout << "Complet" ;
940 //cout << endl << " --> TheJoin :";
941 di << "\n" << " --> TheJoin :";
944 //case GeomAbs_Arc: cout << " Arc"; break;
945 //case GeomAbs_Intersection: cout << " Intersection"; break;
946 case GeomAbs_Arc: di << " Arc"; break;
947 case GeomAbs_Intersection: di << " Intersection"; break;
957 if ( n < 4 ) return 1;
959 TheTolerance = Draw::Atof(a[1]);
960 TheInter = strcmp(a[2],"p");
962 if ( !strcmp(a[3],"a")) TheJoin = GeomAbs_Arc;
963 else if ( !strcmp(a[3],"i")) TheJoin = GeomAbs_Intersection;
964 else if ( !strcmp(a[3],"t")) TheJoin = GeomAbs_Tangent;
970 //=======================================================================
971 //function : offsetinit
973 //=======================================================================
975 Standard_Integer offsetload(Draw_Interpretor& ,
976 Standard_Integer n, const char** a)
978 if ( n < 2) return 1;
979 TopoDS_Shape S = DBRep::Get(a[1]);
980 if (S.IsNull()) return 1;
982 Standard_Real Of = Draw::Atof(a[2]);
984 // Standard_Boolean Inter = Standard_True;
986 TheOffset.Initialize(S,Of,TheTolerance,BRepOffset_Skin,TheInter,0,TheJoin);
987 //------------------------------------------
988 // recuperation et chargement des bouchons.
989 //----------------------------------------
990 for (Standard_Integer i = 3 ; i < n; i++) {
991 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
993 TheOffset.AddFace(TopoDS::Face(SF));
996 if (n < 4) theYaBouchon = Standard_False; //B.MakeOffsetShape();
997 else theYaBouchon = Standard_True; //B.MakeThickSolid ();
1003 //=======================================================================
1004 //function : offsetonface
1006 //=======================================================================
1008 Standard_Integer offsetonface(Draw_Interpretor&, Standard_Integer n, const char** a)
1010 if ( n < 3) return 1;
1012 for (Standard_Integer i = 1 ; i < n; i+=2) {
1013 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
1015 Standard_Real Of = Draw::Atof(a[i+1]);
1016 TheOffset.SetOffsetOnFace(TopoDS::Face(SF),Of);
1023 //=======================================================================
1024 //function : offsetperform
1026 //=======================================================================
1028 Standard_Integer offsetperform(Draw_Interpretor& theCommands,
1029 Standard_Integer theNArg, const char** a)
1031 if ( theNArg < 2) return 1;
1034 TheOffset.MakeThickSolid ();
1036 TheOffset.MakeOffsetShape();
1038 if(TheOffset.IsDone())
1040 DBRep::Set(a[1],TheOffset.Shape());
1044 theCommands << "ERROR. offsetperform operation not done.";
1052 //=======================================================================
1055 //=======================================================================
1057 static Standard_Integer Debou(Draw_Interpretor& theCommands,
1058 Standard_Integer narg, const char** a)
1060 Standard_Integer i ;
1061 Standard_Integer newnarg ;
1063 if (narg<7) return 1;
1065 TopoDS_Shape S = DBRep::Get(a[2]);
1067 Standard_Boolean Fuse;
1068 if (!strcasecmp("F",a[3])) {
1069 Fuse = Standard_True;
1071 else if (!strcasecmp("C",a[3])) {
1072 Fuse = Standard_False;
1078 for ( newnarg = 4; newnarg < narg; newnarg++) {
1079 if (a[newnarg][0] == '@') {
1083 if (newnarg >= narg-1 || newnarg == 4) {
1088 TopTools_ListOfShape LF,LF2;
1089 for ( i=4; i<newnarg; i++) {
1090 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1091 LF.Append(aLocalShape);
1092 // LF.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1095 for (i=newnarg+1; i<narg; i++) {
1096 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1097 LF2.Append(aLocalShape);
1098 // LF2.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1101 //BRepFeat_LocalOperation BLoc(S);
1102 //BLoc.Perform(LF,LF2,Fuse);
1104 BRepFeat_Builder BLoc;
1107 BLoc.PerformResult();
1108 if (!BLoc.ErrorStatus()) {
1110 DBRep::Set(a[1],BLoc.Shape());
1114 theCommands << "Local operation not done" ;
1119 //=======================================================================
1122 //=======================================================================
1124 static Standard_Integer ROW(Draw_Interpretor& theCommands,
1125 Standard_Integer narg, const char** a)
1127 if (narg<13) return 1;
1128 TopoDS_Shape S = DBRep::Get(a[3]);
1129 BRepFeat_MakeRevol theRFace;
1132 Standard_Real Angle=0;
1133 TopoDS_Shape FFrom,FUntil;
1134 Standard_Integer i,borne;
1135 Standard_Boolean fuse;
1137 if (a[1][0] == 'f' || a[1][0] == 'F') {
1138 fuse = Standard_True;
1140 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1141 fuse = Standard_False;
1147 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1148 if (FFrom.IsNull()) {
1149 Angle = Draw::Atof(a[4]);
1154 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1155 if (FUntil.IsNull()) {
1170 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1171 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1172 gp_Ax1 theAxis(Or,D);
1174 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1175 TopoDS_Face F = TopoDS::Face(aLocalShape);
1176 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1177 BRepFeat_SplitShape Spls(F);
1178 for (i = borne+1; i<narg; i++) {
1180 if (a[i][0] !='-') {
1181 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
1182 wir = TopoDS::Wire(aLocalShape);
1183 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
1186 if (a[i][1] == '\0')
1188 const char* Temp = a[i]+1;
1189 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
1190 wir = TopoDS::Wire(aLocalShape);
1191 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
1198 TopoDS_Shape ToRotate;
1199 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1200 if (lleft.Extent() == 1) {
1201 theRFace.Init(S,lleft.First(),F,theAxis,fuse,Standard_True);
1202 ToRotate = lleft.First();
1208 TopTools_ListIteratorOfListOfShape it;
1209 for (it.Initialize(lleft);it.More();it.Next()) {
1210 B.Add(Sh,TopoDS::Face(it.Value()));
1212 theRFace.Init(S,Sh,F,theAxis,fuse,Standard_True);
1216 // Recherche des faces de glissement
1217 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
1218 TopExp_Explorer exp(S,TopAbs_FACE) ;
1219 for ( ;exp.More();exp.Next()) {
1220 if (exp.Current().IsSame(F)) {
1226 LocOpe_FindEdgesInFace FEIF;
1227 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1228 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1229 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1230 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1231 Su = Handle(Geom_RectangularTrimmedSurface)::
1232 DownCast(Su)->BasisSurface();
1234 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1235 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1236 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1237 FEIF.Set(ToRotate,fac);
1238 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1239 theRFace.Add(FEIF.Edge(),fac);
1243 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1245 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1246 if (cy.Axis().IsCoaxial(theAxis,
1247 Precision::Angular(),Precision::Confusion())) {
1248 FEIF.Set(ToRotate,fac);
1249 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1250 theRFace.Add(FEIF.Edge(),fac);
1258 if (FUntil.IsNull()) {
1259 theRFace.Perform(Angle);
1262 theRFace.Perform(FUntil);
1265 else { // borne == 12
1266 theRFace.Perform(FFrom,FUntil);
1269 if (!theRFace.IsDone()) {
1270 theCommands << "Local operation not done";
1274 DBRep::Set(a[2],theRFace);
1280 //=======================================================================
1283 //=======================================================================
1285 static Standard_Integer ROF(Draw_Interpretor& theCommands,
1286 Standard_Integer narg, const char** a)
1288 if (narg<12) return 1;
1289 TopoDS_Shape S = DBRep::Get(a[3]);
1290 BRepFeat_MakeRevol theRFace;
1293 Standard_Real Angle=0;
1294 TopoDS_Shape FFrom,FUntil;
1295 Standard_Integer i,borne;
1296 Standard_Boolean fuse;
1298 if (a[1][0] == 'f' || a[1][0] == 'F') {
1299 fuse = Standard_True;
1301 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1302 fuse = Standard_False;
1308 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1309 if (FFrom.IsNull()) {
1310 Angle = Draw::Atof(a[4]);
1315 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1316 if (FUntil.IsNull()) {
1331 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1332 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1333 gp_Ax1 theAxis(Or,D);
1335 TopoDS_Shape ToRotate;
1336 if (narg == borne+1) {
1337 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1338 TopoDS_Face F = TopoDS::Face(aLocalShape);
1339 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1340 theRFace.Init(S,F,F,theAxis,fuse,Standard_True);
1348 for (i=borne; i<narg; i++) {
1349 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1350 TopoDS_Face F = TopoDS::Face(aLocalShape);
1351 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
1356 theRFace.Init(S,She,TopoDS_Face(),theAxis,fuse,Standard_False);
1360 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1361 TopExp_Explorer exp(ToRotate,TopAbs_FACE) ;
1362 for ( ;exp.More();exp.Next()) {
1363 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1364 TopExp_Explorer exp2(S,TopAbs_FACE) ;
1365 for ( ;exp2.More();exp2.Next()) {
1366 if (exp2.Current().IsSame(exp.Current())) {
1376 LocOpe_FindEdgesInFace FEIF;
1377 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1378 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1379 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1380 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1381 Su = Handle(Geom_RectangularTrimmedSurface)::
1382 DownCast(Su)->BasisSurface();
1384 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1385 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1386 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1387 FEIF.Set(ToRotate,fac);
1388 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1389 theRFace.Add(FEIF.Edge(),fac);
1393 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1395 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1396 if (cy.Axis().IsCoaxial(theAxis,
1397 Precision::Angular(),Precision::Confusion())) {
1398 FEIF.Set(ToRotate,fac);
1399 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1400 theRFace.Add(FEIF.Edge(),fac);
1408 if (FUntil.IsNull()) {
1409 theRFace.Perform(Angle);
1412 theRFace.Perform(FUntil);
1415 else { // borne == 12
1416 theRFace.Perform(FFrom,FUntil);
1419 if (!theRFace.IsDone()) {
1420 theCommands << "Local operation not done";
1424 DBRep::Set(a[2],theRFace);
1430 //=======================================================================
1432 //purpose : Commande glue
1433 //=======================================================================
1435 static Standard_Integer GLU(Draw_Interpretor& ,
1436 Standard_Integer narg, const char** a)
1438 if (narg<6 || narg%2 != 0) return 1;
1439 TopoDS_Shape Sne = DBRep::Get(a[2]);
1440 TopoDS_Shape Sba = DBRep::Get(a[3]);
1442 Standard_Boolean pick;
1444 BRepFeat_Gluer theGl(Sne,Sba);
1445 TopoDS_Shape Fne,Fba;
1447 LocOpe_FindEdges fined;
1449 Standard_Integer i = 4;
1450 Standard_Boolean first = Standard_True;
1452 pick = (a[i][0] == '.');
1453 Fne = DBRep::Get(a[i]);
1457 TopAbs_ShapeEnum sht = Fne.ShapeType();
1458 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
1460 DBRep_DrawableShape::LastPick(Fne,u,v);
1461 sht = Fne.ShapeType();
1463 if (first && sht != TopAbs_FACE) {
1466 first = Standard_False;
1467 pick = (a[i+1][0] == '.');
1468 Fba = DBRep::Get(a[i+1]);
1472 if (pick && Fba.ShapeType() != sht) {
1474 DBRep_DrawableShape::LastPick(Fba,u,v);
1476 if (Fba.ShapeType() != sht) {
1479 if (sht == TopAbs_FACE) {
1480 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1481 const TopoDS_Face& f2 = TopoDS::Face(Fba);
1484 for (fined.InitIterator(); fined.More(); fined.Next()) {
1485 theGl.Bind(fined.EdgeFrom(),fined.EdgeTo());
1489 theGl.Bind(TopoDS::Edge(Fne),TopoDS::Edge(Fba));
1494 DBRep::Set(a[1],theGl);
1499 static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
1500 Standard_Integer narg, const char** a)
1503 if (strcasecmp(a[0],"FEATPRISM") &&
1504 strcasecmp(a[0],"FEATDPRISM") &&
1505 strcasecmp(a[0],"FEATREVOL") &&
1506 strcasecmp(a[0],"FEATPIPE") &&
1507 strcasecmp(a[0],"FEATLF") &&
1508 strcasecmp(a[0],"FEATRF")) {
1512 if ((!strcasecmp(a[0],"FEATPRISM") && narg !=9) ||
1513 (!strcasecmp(a[0],"FEATREVOL") && narg != 12) ||
1514 (!strcasecmp(a[0],"FEATDPRISM") && narg != 7) ||
1515 (!strcasecmp(a[0],"FEATPIPE") && narg != 7) ||
1516 (!strcasecmp(a[0],"FEATLF") && narg != 12) ||
1517 (!strcasecmp(a[0],"FEATRF") && narg != 14)) {
1518 theCommands << "invalid number of arguments";
1522 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1523 if (Sbase.IsNull()) {
1524 theCommands << "null basis shape";
1527 Standard_Integer Ifuse = Draw::Atoi(a[narg-2]);
1528 Standard_Integer Imodif = Draw::Atoi(a[narg-1]);
1530 Standard_Integer Fuse = Ifuse;
1531 Standard_Boolean Modify = (Imodif!=0);
1537 Handle(Geom_Plane) P;
1539 BRepFeat_StatusError se;
1541 if (strcasecmp(a[0],"FEATLF") && strcasecmp(a[0],"FEATRF")) {
1542 Pbase = DBRep::Get(a[2]);
1543 if (Pbase.IsNull()) {
1544 theCommands << "null shape to transform";
1547 TopoDS_Shape aLocalShape(DBRep::Get(a[3],TopAbs_FACE));
1548 Skface = TopoDS::Face(aLocalShape);
1549 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
1550 if (Skface.IsNull()) {
1551 theCommands << "null face of Sketch";
1556 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1557 W = TopoDS::Wire(aLocalShape);
1558 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1560 theCommands << "null profile for rib or slot";
1563 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1564 P = Handle(Geom_Plane)::DownCast(s);
1566 theCommands << "null plane to transform";
1570 if (narg == 9 || narg == 12 || narg == 14) {
1571 // Standard_Real X,Y,Z,X1,Y1,Z1;
1572 Standard_Real X,Y,Z;
1573 X = Draw::Atof(a[4]);
1574 Y = Draw::Atof(a[5]);
1575 Z = Draw::Atof(a[6]);
1577 if (narg == 9) { // prism
1578 prdef = Standard_True;
1579 thePrism.Init(Sbase,Pbase,Skface,gp_Dir(X,Y,Z),Fuse,Modify);
1581 else if(narg == 14) {
1582 rfdef = Standard_True;
1584 X = Draw::Atof(a[7]);
1585 Y = Draw::Atof(a[8]);
1586 Z = Draw::Atof(a[9]);
1587 Standard_Real H1 = Draw::Atof(a[10]);
1588 Standard_Real H2 = Draw::Atof(a[11]);
1589 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1590 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1591 if (!theRF.IsDone()) {
1592 se = theRF.CurrentStatusError();
1593 //BRepFeat::Print(se,cout) << endl;
1594 Standard_SStream aSStream;
1595 BRepFeat::Print(se,aSStream);
1596 theCommands << aSStream << "\n";
1600 else if(narg == 12 && strcasecmp(a[0],"FEATLF")) {
1601 rvdef = Standard_True;
1603 X = Draw::Atof(a[7]);
1604 Y = Draw::Atof(a[8]);
1605 Z = Draw::Atof(a[9]);
1606 theRevol.Init(Sbase,Pbase,Skface,gp_Ax1(Or,gp_Dir(X,Y,Z)),
1610 lfdef = Standard_True;
1611 gp_Vec Direct(X,Y,Z);
1612 X = Draw::Atof(a[7]);
1613 Y = Draw::Atof(a[8]);
1614 Z = Draw::Atof(a[9]);
1615 theLF.Init(Sbase, W, P, Direct, gp_Vec(X,Y,Z), Fuse,Modify);
1616 if (!theLF.IsDone()) {
1617 se = theLF.CurrentStatusError();
1618 //BRepFeat::Print(se,cout) << endl;
1619 Standard_SStream aSStream;
1620 BRepFeat::Print(se,aSStream);
1621 theCommands << aSStream << "\n";
1626 else if (narg == 7) {
1627 if (!strcasecmp(a[0],"FEATDPRISM")) {
1628 if (Pbase.ShapeType() != TopAbs_FACE) {
1629 theCommands << "Invalid DPrism base";
1632 Standard_Real Angle = Draw::Atof(a[4])*M_PI/360;
1633 dprdef = Standard_True;
1634 theDPrism.Init(Sbase,TopoDS::Face(Pbase),Skface,Angle,Fuse,Modify);
1637 TopoDS_Shape aLocalShape(DBRep::Get(a[4],TopAbs_WIRE));
1638 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
1639 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
1640 if (Spine.IsNull()) {
1641 TopoDS_Shape Edspine =DBRep::Get(a[4],TopAbs_EDGE);
1642 if (Edspine.IsNull()) {
1643 theCommands << "null spine";
1648 B.Add(Spine,Edspine);
1650 pidef = Standard_True;
1651 thePipe.Init(Sbase,Pbase,Skface,Spine,Fuse,Modify);
1659 static Standard_Integer ADD(Draw_Interpretor& ,
1660 Standard_Integer narg, const char** a)
1662 Standard_Integer i ;
1663 if (narg < 4 || narg%2 != 0) {
1666 if (!strcasecmp("PRISM",a[1])) {
1670 for ( i=2; i<narg; i+=2) {
1671 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1672 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1673 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1677 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1678 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1679 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1683 thePrism.Add(edg,fac);
1686 else if (!strcasecmp("REVOL",a[1])) {
1690 for ( i=2; i<narg; i+=2) {
1691 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1692 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1693 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1697 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1698 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1699 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1703 theRevol.Add(edg,fac);
1706 else if (!strcasecmp("PIPE",a[1])) {
1710 for ( i=2; i<narg; i+=2) {
1711 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1712 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1713 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1717 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1718 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1719 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1723 thePipe.Add(edg,fac);
1734 static Standard_Integer PERF(Draw_Interpretor& theCommands,
1735 Standard_Integer narg, const char** a)
1740 if (strcasecmp(a[0],"FEATPERFORM") &&
1741 strcasecmp(a[0],"FEATPERFORMVAL")) {
1745 Standard_Integer Kas;
1746 if (!strcasecmp("PRISM",a[1])) {
1749 theCommands << "prism not defined";
1753 else if (!strcasecmp("REVOL",a[1])) {
1756 theCommands << "revol not defined";
1760 else if (!strcasecmp("PIPE",a[1])) {
1763 theCommands << "pipe not defined";
1766 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1767 theCommands << "invalid command for pipe";
1771 else if (!strcasecmp("DPRISM",a[1])) {
1774 theCommands << "dprism not defined";
1778 else if (!strcasecmp("LF",a[1])) {
1781 theCommands << "lf not defined";
1784 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1785 theCommands << "invalid command for lf";
1789 else if (!strcasecmp("RF",a[1])) {
1792 theCommands << "rf not defined";
1795 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1796 theCommands << "invalid command for rf";
1801 theCommands << "unknown argument : " << a[1];
1805 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1806 if (narg !=4 && narg != 5) {
1807 theCommands << "invalid number of arguments";
1811 Standard_Real Val = Draw::Atof(a[3]);
1813 thePrism.Perform(Val);
1815 else if (Kas == 2) {
1817 theRevol.Perform(Val);
1819 else if (Kas == 4) {
1820 theDPrism.Perform(Val);
1822 else if (Kas == 5) {
1823 theCommands << "invalid command for lf";
1826 else if (Kas == 6) {
1827 theCommands << "invalid command for rf";
1831 else if(narg == 5) {
1832 Standard_Real Val = Draw::Atof(a[3]);
1833 TopoDS_Shape FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
1835 thePrism.PerformUntilHeight(FUntil, Val);
1837 else if (Kas == 2) {
1839 theRevol.PerformUntilAngle(FUntil, Val);
1841 else if (Kas == 4) {
1842 theDPrism.PerformUntilHeight(FUntil, Val);
1845 theCommands << "invalid command for ribs or slots";
1850 else if (!strcasecmp(a[0],"FEATPERFORM")) {
1851 if (narg == 3) { // Thru all
1854 thePrism.PerformThruAll();
1857 theRevol.PerformThruAll();
1863 theDPrism.PerformThruAll();
1876 else if (narg == 4) { // Until
1877 TopoDS_Shape Funtil = DBRep::Get(a[3],TopAbs_SHAPE);
1881 if (Funtil.IsNull()) {
1882 thePrism.PerformUntilEnd();
1885 thePrism.Perform(Funtil);
1891 if (!Funtil.IsNull()) {
1892 theRevol.Perform(Funtil);
1901 if (!Funtil.IsNull()) {
1902 thePipe.Perform(Funtil);
1905 theCommands << "invalid command for ribs pipe";
1912 if (!Funtil.IsNull()) {
1913 theDPrism.Perform(Funtil);
1916 theDPrism.PerformUntilEnd();
1922 theCommands << "invalid command for lf";
1928 theCommands << "invalid command for rf";
1936 else if (narg == 5) {
1937 TopoDS_Shape Ffrom = DBRep::Get(a[3],TopAbs_SHAPE);
1938 TopoDS_Shape Funtil = DBRep::Get(a[4],TopAbs_SHAPE);
1939 if (Funtil.IsNull()) {
1945 if (Ffrom.IsNull()) {
1946 thePrism.PerformFromEnd(Funtil);
1949 thePrism.Perform(Ffrom,Funtil);
1955 if (Ffrom.IsNull()) {
1958 theRevol.Perform(Ffrom,Funtil);
1963 if (Ffrom.IsNull()) {
1966 thePipe.Perform(Ffrom,Funtil);
1971 if (Ffrom.IsNull()) {
1972 theDPrism.PerformFromEnd(Funtil);
1975 theDPrism.Perform(Ffrom,Funtil);
1986 BRepFeat_StatusError se;
1989 if (!thePrism.IsDone()) {
1990 se = thePrism.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],thePrism);
2001 if (!theRevol.IsDone()) {
2002 se = theRevol.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],theRevol);
2013 if (!thePipe.IsDone()) {
2014 se = thePipe.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],thePipe);
2025 if (!theDPrism.IsDone()) {
2026 se = theDPrism.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],theDPrism);
2037 if (!theLF.IsDone()) {
2038 se = theLF.CurrentStatusError();
2039 //BRepFeat::Print(se,cout) << endl;
2040 Standard_SStream aSStream;
2041 BRepFeat::Print(se,aSStream);
2042 theCommands << aSStream << "\n";
2045 DBRep::Set(a[2],theLF);
2049 if (!theRF.IsDone()) {
2050 se = theRF.CurrentStatusError();
2051 //BRepFeat::Print(se,cout) << endl;
2052 Standard_SStream aSStream;
2053 BRepFeat::Print(se,aSStream);
2054 theCommands << aSStream << "\n";
2057 DBRep::Set(a[2],theRF);
2066 static Standard_Integer BOSS(Draw_Interpretor& theCommands,
2067 Standard_Integer narg, const char** a)
2069 if (strcasecmp(a[0],"ENDEDGES") && strcasecmp(a[0],"FILLET")
2070 && strcasecmp(a[0],"BOSSAGE")) {
2074 if ((!strcasecmp(a[0],"ENDEDGES") && narg !=5) ||
2075 (!strcasecmp(a[0],"FILLET") && narg <5 && narg%2 != 1) ||
2076 (!strcasecmp(a[0],"BOSSAGE") && narg != 6)) {
2077 theCommands << "invalid number of arguments";
2081 Standard_Integer Kas=0;
2082 Standard_Integer dprsig=0;
2083 if (!strcasecmp("ENDEDGES",a[0])) {
2085 dprsig = Draw::Atoi(a[4]);
2087 else if (!strcasecmp("FILLET",a[0])) {
2090 else if (!strcasecmp("BOSSAGE",a[0])) {
2092 dprsig = Draw::Atoi(a[5]);
2095 TopoDS_Shape theShapeTop;
2096 TopoDS_Shape theShapeBottom;
2098 if (Kas == 1 || Kas == 3) {
2099 if (!strcasecmp("DPRISM",a[1])) {
2101 theCommands << "dprism not defined";
2106 theCommands << "unknown argument : " << a[1];
2110 theDPrism.BossEdges(dprsig);
2112 TopTools_ListOfShape theTopEdges, theLatEdges;
2113 theTopEdges = theDPrism.TopEdges();
2114 theLatEdges = theDPrism.LatEdges();
2116 TopTools_ListIteratorOfListOfShape it;
2119 B.MakeCompound(TopoDS::Compound(theShapeTop));
2120 it.Initialize(theTopEdges);
2121 for(; it.More(); it.Next()) {
2122 TopExp_Explorer exp;
2123 for (exp.Init(it.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
2124 B.Add(theShapeTop,exp.Current());
2127 DBRep::Set(a[2],theShapeTop);
2130 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2131 it.Initialize(theLatEdges);
2132 for(; it.More(); it.Next()) {
2133 B.Add(theShapeBottom,it.Value());
2135 DBRep::Set(a[3],theShapeBottom);
2137 if (Kas == 1) return 0;
2140 if (Kas == 2 || Kas == 3) {
2142 // Standard_Integer nrad;
2145 V = DBRep::Get(a[2],TopAbs_SHAPE);
2147 else if (Kas == 3) {
2151 if(V.IsNull()) return 1;
2152 ChFi3d_FilletShape FSh = ChFi3d_Rational;
2153 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
2154 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
2155 Rakk->SetContinuity(blend_cont, tapp_angle);
2159 Standard_Integer nbedge = 0;
2162 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
2163 Rad = Draw::Atof(a[2*ii + 1]);
2164 if (Rad == 0.) continue;
2165 S = DBRep::Get(a[(2*ii+2)],TopAbs_SHAPE);
2166 TopExp_Explorer exp;
2167 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2168 E = TopoDS::Edge(exp.Current());
2176 else if (Kas == 3) {
2177 Rad = Draw::Atof(a[3]);
2180 TopExp_Explorer exp;
2181 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2182 E = TopoDS::Edge(exp.Current());
2189 Rad = Draw::Atof(a[4]);
2192 TopExp_Explorer exp;
2193 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2194 E = TopoDS::Edge(exp.Current());
2203 if(!nbedge) return 1;
2205 if(!Rakk->IsDone()) return 1;
2206 TopoDS_Shape res = Rakk->Shape();
2209 DBRep::Set(a[1],res);
2211 else if (Kas == 3) {
2212 DBRep::Set(a[2],res);
2222 //=======================================================================
2223 //function : FeatureCommands
2225 //=======================================================================
2227 void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
2229 static Standard_Boolean done = Standard_False;
2231 done = Standard_True;
2233 DBRep::BasicCommands(theCommands);
2235 const char* g = "TOPOLOGY Feature commands";
2237 theCommands.Add("localope",
2238 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2241 theCommands.Add("hole",
2242 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2245 theCommands.Add("firsthole",
2246 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2249 theCommands.Add("holend",
2250 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2253 theCommands.Add("blindhole",
2254 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2257 theCommands.Add("holecontrol",
2258 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2259 __FILE__,CONTROL,g);
2261 theCommands.Add("wprism",
2262 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2266 theCommands.Add("fprism",
2267 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2271 theCommands.Add("wrotate",
2272 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2276 theCommands.Add("frotate",
2277 "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...]",
2281 theCommands.Add("splitshape",
2282 "splitshape result shape face wire/edge/compound [wire/edge/compound ...][face wire/edge/compound [wire/edge/compound...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2286 theCommands.Add("thickshell",
2287 "thickshell r shape offset [jointype [tol] ]",
2288 __FILE__,thickshell,g);
2290 theCommands.Add("offsetshape",
2291 "offsetshape r shape offset [tol] [face ...]",
2292 __FILE__,offsetshape,g);
2294 theCommands.Add("offsetcompshape",
2295 "offsetcompshape r shape offset [face ...]",
2296 __FILE__,offsetshape,g);
2298 theCommands.Add("offsetparameter",
2299 "offsetparameter tol inter(a/i) join(a/i)",
2300 __FILE__,offsetparameter);
2302 theCommands.Add("offsetload",
2303 "offsetload shape offset bouchon1 bouchon2 ...",
2304 __FILE__,offsetload,g);
2306 theCommands.Add("offsetonface",
2307 "offsetonface face1 offset1 face2 offset2 ...",
2308 __FILE__,offsetonface,g);
2310 theCommands.Add("offsetperform",
2311 "offsetperform result",
2312 __FILE__,offsetperform,g);
2315 theCommands.Add("deboucle",
2316 " Essai de debouclage partiel: deboucle result shape F/C face [face...] @ face [face...]",
2320 theCommands.Add("glue",
2321 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2325 theCommands.Add("featprism",
2326 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2329 theCommands.Add("featrevol",
2330 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2333 theCommands.Add("featpipe",
2334 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2337 theCommands.Add("featdprism",
2338 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2341 theCommands.Add("featlf",
2342 "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)",
2345 theCommands.Add("featrf",
2346 "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)",
2349 theCommands.Add("addslide",
2350 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2353 theCommands.Add("featperform",
2354 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2357 theCommands.Add("featperformval",
2358 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2361 theCommands.Add("endedges",
2362 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2365 theCommands.Add("fillet",
2366 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2369 theCommands.Add("bossage",
2370 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",