1 // Created on: 1995-06-16
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Draw_Interpretor.hxx>
18 #include <Draw_Appli.hxx>
19 #include <DrawTrSurf.hxx>
21 #include <TopTools_ListOfShape.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopTools_MapOfShape.hxx>
24 #include <TopTools_MapIteratorOfMapOfShape.hxx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TopoDS_Wire.hxx>
28 #include <TopoDS_Shell.hxx>
29 #include <TopoDS_Compound.hxx>
30 #include <TopoDS_Edge.hxx>
33 #include <Geom_RectangularTrimmedSurface.hxx>
34 #include <Geom_Plane.hxx>
35 #include <Geom_CylindricalSurface.hxx>
38 #include <gp_Cylinder.hxx>
40 //#include <BRepFeat_LocalOperation.hxx>
41 #include <BRepFeat_Builder.hxx>
42 #include <BRepFeat_MakeCylindricalHole.hxx>
43 #include <BRepFeat_SplitShape.hxx>
44 #include <BRepFeat_Gluer.hxx>
46 #include <BRepFeat.hxx>
47 #include <BRepFeat_MakePrism.hxx>
48 #include <BRepFeat_MakeRevol.hxx>
49 #include <BRepFeat_MakePipe.hxx>
50 #include <BRepFeat_MakeDPrism.hxx>
51 #include <BRepFeat_MakeLinearForm.hxx>
52 #include <BRepFeat_MakeRevolutionForm.hxx>
54 #include <LocOpe_FindEdges.hxx>
55 #include <LocOpe_FindEdgesInFace.hxx>
57 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
58 #include <BRepOffsetAPI_MakeThickSolid.hxx>
59 #include <BRep_Tool.hxx>
60 #include <BRep_Builder.hxx>
62 #include <DBRep_DrawableShape.hxx>
63 #include <BRepTest.hxx>
65 #include <BRepFilletAPI_MakeFillet.hxx>
66 #include <ChFi3d_FilletShape.hxx>
68 #include <Precision.hxx>
71 //#define strcasecmp _stricmp Already defined
72 Standard_IMPORT Draw_Viewer dout;
75 static BRepFeat_MakeCylindricalHole theHole;
76 static Standard_Boolean WithControl = Standard_True;
78 Standard_Boolean DownCastingEnforcing = Standard_False;
80 static BRepFeat_MakePrism thePrism;
81 static BRepFeat_MakeDPrism theDPrism;
82 static BRepFeat_MakeRevol theRevol;
83 static BRepFeat_MakePipe thePipe;
84 static BRepFeat_MakeLinearForm theLF;
85 static BRepFeat_MakeRevolutionForm theRF;
87 static Standard_Boolean dprdef = Standard_False;
88 static Standard_Boolean prdef = Standard_False;
89 static Standard_Boolean rvdef = Standard_False;
90 static Standard_Boolean pidef = Standard_False;
91 static Standard_Boolean lfdef = Standard_False;
92 static Standard_Boolean rfdef = Standard_False;
94 static Standard_Real t3d = 1.e-4;
95 static Standard_Real t2d = 1.e-5;
96 static Standard_Real ta = 1.e-2;
97 static Standard_Real fl = 1.e-3;
98 static Standard_Real tapp_angle = 1.e-2;
99 static GeomAbs_Shape blend_cont = GeomAbs_C1;
100 static BRepFilletAPI_MakeFillet* Rakk = 0;
104 static void Print(Draw_Interpretor& di,
105 const BRepFeat_Status St)
107 di << " Error Status : ";
109 case BRepFeat_NoError:
113 case BRepFeat_InvalidPlacement:
114 di << "Invalid placement";
117 case BRepFeat_HoleTooLong:
118 di << "Hole too long";
123 static Standard_Integer Loc(Draw_Interpretor& theCommands,
124 Standard_Integer narg, const char** a)
126 if (narg<6) return 1;
127 TopoDS_Shape S = DBRep::Get(a[2]);
128 TopoDS_Shape T = DBRep::Get(a[3]);
130 Standard_Boolean Fuse;
131 if (!strcasecmp("F",a[4])) {
132 Fuse = Standard_True;
134 else if (!strcasecmp("C",a[4])) {
135 Fuse = Standard_False;
141 TopTools_ListOfShape LF;
142 for (Standard_Integer i=0; i<= narg-6; i++) {
143 TopoDS_Shape aLocalShape(DBRep::Get(a[i+5],TopAbs_FACE));
144 LF.Append(aLocalShape);
145 // LF.Append(TopoDS::Face(DBRep::Get(a[i+5],TopAbs_FACE)));
148 //BRepFeat_LocalOperation BLoc(S);
149 //BLoc.Perform(T,LF,Fuse);
150 //BLoc.BuildPartsOfTool();
151 TopTools_ListOfShape parts;
152 BRepFeat_Builder BLoc;
154 BLoc.SetOperation(Fuse);
155 //BRepFeat_LocalOperation BLoc;
156 //BLoc.Init(S,T,Fuse);
158 BLoc.PartsOfTool(parts);
162 strcpy(newname,a[1]);
164 while (*p != '\0') p++;
167 TopTools_ListIteratorOfListOfShape its(parts);
170 for (; its.More(); its.Next()) {
173 DBRep::Set(newname,its.Value());
177 Standard_Integer qq,ww,ee,button;
180 TopoDS_Shape aLocalShape(DBRep::Get(".",TopAbs_SHELL));
181 S = TopoDS::Shell(aLocalShape);
182 // S = TopoDS::Shell(DBRep::Get(".",TopAbs_SHELL));
183 Draw::LastPick(qq,ww,ee,button);
188 //BLoc.RemovePart(S);
201 } while (button != 3);
204 BLoc.PerformResult();
205 if (!BLoc.ErrorStatus()) {
207 DBRep::Set(a[1],BLoc.Shape());
211 theCommands << "Local operation not done" ;
217 static Standard_Integer HOLE1(Draw_Interpretor& theCommands,
218 Standard_Integer narg, const char** a)
220 if (narg<10 || narg == 11) return 1;
221 TopoDS_Shape S = DBRep::Get(a[2]);
223 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
224 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
226 Standard_Real Radius = Draw::Atof(a[9]);
228 theHole.Init(S,gp_Ax1(Or,Di));
231 theHole.Perform(Radius);
234 Standard_Real pfrom = Draw::Atof(a[10]);
235 Standard_Real pto = Draw::Atof(a[11]);
236 theHole.Perform(Radius,pfrom,pto,WithControl);
240 if (!theHole.ErrorStatus()) {
242 DBRep::Set(a[1],theHole.Shape());
246 theCommands << "Echec de MakeCylindricalHole";
247 Print(theCommands,theHole.Status());
251 static Standard_Integer HOLE2(Draw_Interpretor& theCommands,
252 Standard_Integer narg, const char** a)
254 if (narg<10) return 1;
255 TopoDS_Shape S = DBRep::Get(a[2]);
257 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
258 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
260 Standard_Real Radius = Draw::Atof(a[9]);
262 theHole.Init(S,gp_Ax1(Or,Di));
263 theHole.PerformThruNext(Radius,WithControl);
266 if (!theHole.ErrorStatus()) {
268 DBRep::Set(a[1],theHole.Shape());
272 theCommands << "Echec de MakeCylindricalHole";
273 Print(theCommands,theHole.Status());
277 static Standard_Integer HOLE3(Draw_Interpretor& theCommands,
278 Standard_Integer narg, const char** a)
280 if (narg<10) return 1;
281 TopoDS_Shape S = DBRep::Get(a[2]);
283 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
284 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
286 Standard_Real Radius = Draw::Atof(a[9]);
288 theHole.Init(S,gp_Ax1(Or,Di));
289 theHole.PerformUntilEnd(Radius,WithControl);
291 if (!theHole.ErrorStatus()) {
293 DBRep::Set(a[1],theHole.Shape());
297 theCommands << "Echec de MakeCylindricalHole";
298 Print(theCommands,theHole.Status());
303 static Standard_Integer HOLE4(Draw_Interpretor& theCommands,
304 Standard_Integer narg, const char** a)
306 if (narg<11) return 1;
307 TopoDS_Shape S = DBRep::Get(a[2]);
309 gp_Pnt Or(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
310 gp_Dir Di(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
312 Standard_Real Radius = Draw::Atof(a[9]);
313 Standard_Real Length = Draw::Atof(a[10]);
315 theHole.Init(S,gp_Ax1(Or,Di));
316 theHole.PerformBlind(Radius,Length,WithControl);
318 if (!theHole.ErrorStatus()) {
320 DBRep::Set(a[1],theHole.Shape());
324 theCommands << "Echec de MakeCylindricalHole";
325 Print(theCommands,theHole.Status());
329 static Standard_Integer CONTROL(Draw_Interpretor& theCommands,
330 Standard_Integer narg, const char** a)
333 WithControl = strcmp("0",a[1]);
336 theCommands << "Mode avec controle";
339 theCommands << "Mode sans controle";
345 //=======================================================================
348 //=======================================================================
350 static Standard_Integer PRW(Draw_Interpretor& theCommands,
351 Standard_Integer narg, const char** a)
353 if (narg<9) return 1;
354 TopoDS_Shape S = DBRep::Get(a[3]);
355 BRepFeat_MakePrism thePFace;
357 TopoDS_Shape FFrom,FUntil;
358 Standard_Integer borne;
359 Standard_Boolean fuse;
360 if (a[1][0] == 'f' || a[1][0] == 'F') {
361 fuse = Standard_True;
363 else if (a[1][0] == 'c' || a[1][0] == 'C') {
364 fuse = Standard_False;
370 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
374 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
378 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
379 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
380 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
384 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
385 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
390 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
393 Standard_Real Length = V.Magnitude();
394 if (Length < Precision::Confusion()) {
398 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
399 TopoDS_Face F = TopoDS::Face(aLocalShape);
400 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
401 BRepFeat_SplitShape Spls(F);
402 for (Standard_Integer i = borne+1; i<narg; i++) {
405 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
406 wir = TopoDS::Wire(aLocalShape);
407 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
412 const char* Temp = a[i]+1;
413 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
414 wir = TopoDS::Wire(aLocalShape);
415 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
422 TopoDS_Shape ToPrism;
423 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
424 if (lleft.Extent() == 1) {
425 thePFace.Init(S,lleft.First(),F,V,fuse,Standard_True);
426 ToPrism = lleft.First();
432 TopTools_ListIteratorOfListOfShape it;
433 for (it.Initialize(lleft);it.More();it.Next()) {
434 B.Add(Sh,TopoDS::Face(it.Value()));
436 thePFace.Init(S,Sh,F,V,fuse,Standard_True);
440 // Recherche des faces de glissement, si on n`a pas sketche sur une face
441 // du shape de depart
443 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
444 TopExp_Explorer exp(S,TopAbs_FACE) ;
445 for ( ;exp.More();exp.Next()) {
446 if (exp.Current().IsSame(F)) {
452 LocOpe_FindEdgesInFace FEIF;
453 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
454 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
455 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
456 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
457 Su = Handle(Geom_RectangularTrimmedSurface)::
458 DownCast(Su)->BasisSurface();
460 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
461 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
462 if (pl.Contains(gp_Lin(pl.Location(),V),
463 Precision::Confusion(),
464 Precision::Angular())) {
465 FEIF.Set(ToPrism,fac);
466 for (FEIF.Init();FEIF.More();FEIF.Next()) {
467 thePFace.Add(FEIF.Edge(),fac);
471 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
473 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
474 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
475 FEIF.Set(ToPrism,fac);
476 for (FEIF.Init();FEIF.More();FEIF.Next()) {
477 thePFace.Add(FEIF.Edge(),fac);
485 thePFace.Perform(Length);
487 else if (borne == 8) {
488 thePFace.Perform(FUntil);
490 else if (borne == 9) {
491 if (!(FFrom.IsNull() || FUntil.IsNull())) {
492 thePFace.Perform(FFrom,FUntil);
494 else if (FFrom.IsNull()) {
495 if (!FUntil.IsNull()) {
496 thePFace.PerformFromEnd(FUntil);
499 thePFace.PerformThruAll();
503 // il faudrait inverser V et appeler PerfomFromEnd...
504 //cout << "Not Implemented" << endl;
505 theCommands << "Not Implemented" << "\n";
508 if (!thePFace.IsDone()) {
509 theCommands << "Local operation not done";
513 DBRep::Set(a[2],thePFace);
519 //=======================================================================
522 //=======================================================================
524 static Standard_Integer PRF(Draw_Interpretor& theCommands,
525 Standard_Integer narg, const char** a)
527 if (narg<8) return 1;
528 TopoDS_Shape S = DBRep::Get(a[3]);
529 BRepFeat_MakePrism thePFace;
530 Standard_Integer borne;
532 TopoDS_Shape FFrom,FUntil;
533 Standard_Boolean fuse;
534 if (a[1][0] == 'f' || a[1][0] == 'F') {
535 fuse = Standard_True;
537 else if (a[1][0] == 'c' || a[1][0] == 'C') {
538 fuse = Standard_False;
545 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
549 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
554 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
555 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
556 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
560 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
561 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
566 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
568 Standard_Real Length = V.Magnitude();
569 if (Length < Precision::Confusion()) {
573 TopoDS_Shape ToPrism;
574 if (narg == borne+1) {
575 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
576 TopoDS_Face F = TopoDS::Face(aLocalShape);
577 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
578 thePFace.Init(S,F,F,V,fuse,Standard_True);
585 for (Standard_Integer i=borne; i<narg; i++) {
586 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
587 TopoDS_Face F = TopoDS::Face(aLocalShape);
588 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
593 thePFace.Init(S,She,TopoDS_Face(),V,fuse,Standard_False);
597 // Recherche des faces de glissement, on ne prisme pas une face
598 // du shape de depart
600 // for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
601 TopExp_Explorer exp(ToPrism,TopAbs_FACE) ;
602 for ( ;exp.More();exp.Next()) {
603 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
604 TopExp_Explorer exp2(S,TopAbs_FACE) ;
605 for ( ;exp2.More();exp2.Next()) {
606 if (exp2.Current().IsSame(exp.Current())) {
616 LocOpe_FindEdgesInFace FEIF;
617 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
618 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
619 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
620 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
621 Su = Handle(Geom_RectangularTrimmedSurface)::
622 DownCast(Su)->BasisSurface();
624 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
625 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
626 if (pl.Contains(gp_Lin(pl.Location(),V),
627 Precision::Confusion(),
628 Precision::Angular())) {
629 FEIF.Set(ToPrism,fac);
630 for (FEIF.Init();FEIF.More();FEIF.Next()) {
631 thePFace.Add(FEIF.Edge(),fac);
635 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
637 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
638 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
639 FEIF.Set(ToPrism,fac);
640 for (FEIF.Init();FEIF.More();FEIF.Next()) {
641 thePFace.Add(FEIF.Edge(),fac);
649 thePFace.Perform(Length);
651 else if (borne == 8) {
652 thePFace.Perform(FUntil);
654 else if (borne == 9) {
655 if (!(FFrom.IsNull() || FUntil.IsNull())) {
656 thePFace.Perform(FFrom,FUntil);
658 else if (FFrom.IsNull()) {
659 if (!FUntil.IsNull()) {
660 thePFace.PerformFromEnd(FUntil);
663 thePFace.PerformThruAll();
666 else { //FUntil.IsNull()
667 // il faudrait inverser V et appeler PerfomFromEnd...
668 //cout << "Not Implemented" << endl;
669 theCommands << "Not Implemented" << "\n";
672 if (!thePFace.IsDone()) {
673 theCommands << "Local operation not done";
677 DBRep::Set(a[2],thePFace);
684 //=======================================================================
687 //=======================================================================
689 static Standard_Integer SPLS(Draw_Interpretor& ,
690 Standard_Integer narg, const char** a)
692 Standard_Integer newnarg ;
694 if (narg<3) return 1;
695 TopoDS_Shape S = DBRep::Get(a[2]);
696 BRepFeat_SplitShape Spls(S);
697 Standard_Boolean pick = Standard_False;
700 Standard_Integer i = 3;
702 for ( newnarg=3; newnarg<narg; newnarg++) {
703 if (a[newnarg][0] == '@') {
709 (newnarg !=narg && ((narg-newnarg)<=2 || (narg-newnarg)%2 != 1))) {
714 pick = (a[i][0] == '.');
715 EF = DBRep::Get(a[i],TopAbs_FACE);
716 if (EF.IsNull()) return 1;
719 while (i < newnarg) {
721 DBRep_DrawableShape::LastPick(EF,u,v);
723 if (EF.ShapeType() == TopAbs_FACE) {
724 // face wire/edge ...
726 while (i < newnarg) {
728 Standard_Boolean rever = Standard_False;
729 if (a[i][0] == '-') {
732 pick = (a[i][1] == '.');
733 const char* Temp = a[i]+1;
734 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
735 rever = Standard_True;
738 pick = (a[i][0] == '.');
739 W = DBRep::Get(a[i],TopAbs_SHAPE,Standard_False);
742 return 1; // on n`a rien recupere
744 TopAbs_ShapeEnum wtyp = W.ShapeType();
745 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND && pick) {
747 DBRep_DrawableShape::LastPick(W,u,v);
748 wtyp = W.ShapeType();
750 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND) {
751 EF = DBRep::Get(a[i]);
758 if (wtyp == TopAbs_WIRE) {
759 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
761 else if (wtyp == TopAbs_EDGE) {
762 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
765 Spls.Add(TopoDS::Compound(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 = Draw::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();
827 Tol = Draw::Atof(a[5]);
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 = Draw::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);
874 Tol = Draw::Atof(a[4]);
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;
945 if ( n < 4 ) return 1;
947 TheTolerance = Draw::Atof(a[1]);
948 TheInter = strcmp(a[2],"p");
950 if ( !strcmp(a[3],"a")) TheJoin = GeomAbs_Arc;
951 else if ( !strcmp(a[3],"i")) TheJoin = GeomAbs_Intersection;
952 else if ( !strcmp(a[3],"t")) TheJoin = GeomAbs_Tangent;
958 //=======================================================================
959 //function : offsetinit
961 //=======================================================================
963 Standard_Integer offsetload(Draw_Interpretor& ,
964 Standard_Integer n, const char** a)
966 if ( n < 2) return 1;
967 TopoDS_Shape S = DBRep::Get(a[1]);
968 if (S.IsNull()) return 1;
970 Standard_Real Of = Draw::Atof(a[2]);
972 // Standard_Boolean Inter = Standard_True;
974 TheOffset.Initialize(S,Of,TheTolerance,BRepOffset_Skin,TheInter,0,TheJoin);
975 //------------------------------------------
976 // recuperation et chargement des bouchons.
977 //----------------------------------------
978 for (Standard_Integer i = 3 ; i < n; i++) {
979 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
981 TheOffset.AddFace(TopoDS::Face(SF));
984 if (n < 4) theYaBouchon = Standard_False; //B.MakeOffsetShape();
985 else theYaBouchon = Standard_True; //B.MakeThickSolid ();
991 //=======================================================================
992 //function : offsetonface
994 //=======================================================================
996 Standard_Integer offsetonface(Draw_Interpretor&, Standard_Integer n, const char** a)
998 if ( n < 3) return 1;
1000 for (Standard_Integer i = 1 ; i < n; i+=2) {
1001 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
1003 Standard_Real Of = Draw::Atof(a[i+1]);
1004 TheOffset.SetOffsetOnFace(TopoDS::Face(SF),Of);
1011 //=======================================================================
1012 //function : offsetperform
1014 //=======================================================================
1016 Standard_Integer offsetperform(Draw_Interpretor& theCommands,
1017 Standard_Integer theNArg, const char** a)
1019 if ( theNArg < 2) return 1;
1022 TheOffset.MakeThickSolid ();
1024 TheOffset.MakeOffsetShape();
1026 if(TheOffset.IsDone())
1028 DBRep::Set(a[1],TheOffset.Shape());
1032 theCommands << "ERROR. offsetperform operation not done.";
1040 //=======================================================================
1043 //=======================================================================
1045 static Standard_Integer Debou(Draw_Interpretor& theCommands,
1046 Standard_Integer narg, const char** a)
1048 Standard_Integer i ;
1049 Standard_Integer newnarg ;
1051 if (narg<7) return 1;
1053 TopoDS_Shape S = DBRep::Get(a[2]);
1055 Standard_Boolean Fuse;
1056 if (!strcasecmp("F",a[3])) {
1057 Fuse = Standard_True;
1059 else if (!strcasecmp("C",a[3])) {
1060 Fuse = Standard_False;
1066 for ( newnarg = 4; newnarg < narg; newnarg++) {
1067 if (a[newnarg][0] == '@') {
1071 if (newnarg >= narg-1 || newnarg == 4) {
1076 TopTools_ListOfShape LF,LF2;
1077 for ( i=4; i<newnarg; i++) {
1078 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1079 LF.Append(aLocalShape);
1080 // LF.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1083 for (i=newnarg+1; i<narg; i++) {
1084 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1085 LF2.Append(aLocalShape);
1086 // LF2.Append(TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)));
1089 //BRepFeat_LocalOperation BLoc(S);
1090 //BLoc.Perform(LF,LF2,Fuse);
1092 BRepFeat_Builder BLoc;
1095 BLoc.PerformResult();
1096 if (!BLoc.ErrorStatus()) {
1098 DBRep::Set(a[1],BLoc.Shape());
1102 theCommands << "Local operation not done" ;
1107 //=======================================================================
1110 //=======================================================================
1112 static Standard_Integer ROW(Draw_Interpretor& theCommands,
1113 Standard_Integer narg, const char** a)
1115 if (narg<13) return 1;
1116 TopoDS_Shape S = DBRep::Get(a[3]);
1117 BRepFeat_MakeRevol theRFace;
1120 Standard_Real Angle=0;
1121 TopoDS_Shape FFrom,FUntil;
1122 Standard_Integer i,borne;
1123 Standard_Boolean fuse;
1125 if (a[1][0] == 'f' || a[1][0] == 'F') {
1126 fuse = Standard_True;
1128 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1129 fuse = Standard_False;
1135 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1136 if (FFrom.IsNull()) {
1137 Angle = Draw::Atof(a[4]);
1142 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1143 if (FUntil.IsNull()) {
1158 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1159 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1160 gp_Ax1 theAxis(Or,D);
1162 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1163 TopoDS_Face F = TopoDS::Face(aLocalShape);
1164 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1165 BRepFeat_SplitShape Spls(F);
1166 for (i = borne+1; i<narg; i++) {
1168 if (a[i][0] !='-') {
1169 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
1170 wir = TopoDS::Wire(aLocalShape);
1171 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
1174 if (a[i][1] == '\0')
1176 const char* Temp = a[i]+1;
1177 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
1178 wir = TopoDS::Wire(aLocalShape);
1179 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
1186 TopoDS_Shape ToRotate;
1187 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1188 if (lleft.Extent() == 1) {
1189 theRFace.Init(S,lleft.First(),F,theAxis,fuse,Standard_True);
1190 ToRotate = lleft.First();
1196 TopTools_ListIteratorOfListOfShape it;
1197 for (it.Initialize(lleft);it.More();it.Next()) {
1198 B.Add(Sh,TopoDS::Face(it.Value()));
1200 theRFace.Init(S,Sh,F,theAxis,fuse,Standard_True);
1204 // Recherche des faces de glissement
1205 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
1206 TopExp_Explorer exp(S,TopAbs_FACE) ;
1207 for ( ;exp.More();exp.Next()) {
1208 if (exp.Current().IsSame(F)) {
1214 LocOpe_FindEdgesInFace FEIF;
1215 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1216 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1217 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1218 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1219 Su = Handle(Geom_RectangularTrimmedSurface)::
1220 DownCast(Su)->BasisSurface();
1222 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1223 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1224 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1225 FEIF.Set(ToRotate,fac);
1226 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1227 theRFace.Add(FEIF.Edge(),fac);
1231 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1233 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1234 if (cy.Axis().IsCoaxial(theAxis,
1235 Precision::Angular(),Precision::Confusion())) {
1236 FEIF.Set(ToRotate,fac);
1237 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1238 theRFace.Add(FEIF.Edge(),fac);
1246 if (FUntil.IsNull()) {
1247 theRFace.Perform(Angle);
1250 theRFace.Perform(FUntil);
1253 else { // borne == 12
1254 theRFace.Perform(FFrom,FUntil);
1257 if (!theRFace.IsDone()) {
1258 theCommands << "Local operation not done";
1262 DBRep::Set(a[2],theRFace);
1268 //=======================================================================
1271 //=======================================================================
1273 static Standard_Integer ROF(Draw_Interpretor& theCommands,
1274 Standard_Integer narg, const char** a)
1276 if (narg<12) return 1;
1277 TopoDS_Shape S = DBRep::Get(a[3]);
1278 BRepFeat_MakeRevol theRFace;
1281 Standard_Real Angle=0;
1282 TopoDS_Shape FFrom,FUntil;
1283 Standard_Integer i,borne;
1284 Standard_Boolean fuse;
1286 if (a[1][0] == 'f' || a[1][0] == 'F') {
1287 fuse = Standard_True;
1289 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1290 fuse = Standard_False;
1296 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1297 if (FFrom.IsNull()) {
1298 Angle = Draw::Atof(a[4]);
1303 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1304 if (FUntil.IsNull()) {
1319 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1320 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1321 gp_Ax1 theAxis(Or,D);
1323 TopoDS_Shape ToRotate;
1324 if (narg == borne+1) {
1325 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1326 TopoDS_Face F = TopoDS::Face(aLocalShape);
1327 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1328 theRFace.Init(S,F,F,theAxis,fuse,Standard_True);
1336 for (i=borne; i<narg; i++) {
1337 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1338 TopoDS_Face F = TopoDS::Face(aLocalShape);
1339 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
1344 theRFace.Init(S,She,TopoDS_Face(),theAxis,fuse,Standard_False);
1348 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1349 TopExp_Explorer exp(ToRotate,TopAbs_FACE) ;
1350 for ( ;exp.More();exp.Next()) {
1351 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1352 TopExp_Explorer exp2(S,TopAbs_FACE) ;
1353 for ( ;exp2.More();exp2.Next()) {
1354 if (exp2.Current().IsSame(exp.Current())) {
1364 LocOpe_FindEdgesInFace FEIF;
1365 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1366 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1367 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1368 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1369 Su = Handle(Geom_RectangularTrimmedSurface)::
1370 DownCast(Su)->BasisSurface();
1372 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1373 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1374 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1375 FEIF.Set(ToRotate,fac);
1376 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1377 theRFace.Add(FEIF.Edge(),fac);
1381 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1383 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1384 if (cy.Axis().IsCoaxial(theAxis,
1385 Precision::Angular(),Precision::Confusion())) {
1386 FEIF.Set(ToRotate,fac);
1387 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1388 theRFace.Add(FEIF.Edge(),fac);
1396 if (FUntil.IsNull()) {
1397 theRFace.Perform(Angle);
1400 theRFace.Perform(FUntil);
1403 else { // borne == 12
1404 theRFace.Perform(FFrom,FUntil);
1407 if (!theRFace.IsDone()) {
1408 theCommands << "Local operation not done";
1412 DBRep::Set(a[2],theRFace);
1418 //=======================================================================
1420 //purpose : Commande glue
1421 //=======================================================================
1423 static Standard_Integer GLU(Draw_Interpretor& ,
1424 Standard_Integer narg, const char** a)
1426 if (narg<6 || narg%2 != 0) return 1;
1427 TopoDS_Shape Sne = DBRep::Get(a[2]);
1428 TopoDS_Shape Sba = DBRep::Get(a[3]);
1430 Standard_Boolean pick;
1432 BRepFeat_Gluer theGl(Sne,Sba);
1433 TopoDS_Shape Fne,Fba;
1435 LocOpe_FindEdges fined;
1437 Standard_Integer i = 4;
1438 Standard_Boolean first = Standard_True;
1440 pick = (a[i][0] == '.');
1441 Fne = DBRep::Get(a[i]);
1445 TopAbs_ShapeEnum sht = Fne.ShapeType();
1446 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
1448 DBRep_DrawableShape::LastPick(Fne,u,v);
1449 sht = Fne.ShapeType();
1451 if (first && sht != TopAbs_FACE) {
1454 first = Standard_False;
1455 pick = (a[i+1][0] == '.');
1456 Fba = DBRep::Get(a[i+1]);
1460 if (pick && Fba.ShapeType() != sht) {
1462 DBRep_DrawableShape::LastPick(Fba,u,v);
1464 if (Fba.ShapeType() != sht) {
1467 if (sht == TopAbs_FACE) {
1468 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1469 const TopoDS_Face& f2 = TopoDS::Face(Fba);
1472 for (fined.InitIterator(); fined.More(); fined.Next()) {
1473 theGl.Bind(fined.EdgeFrom(),fined.EdgeTo());
1477 theGl.Bind(TopoDS::Edge(Fne),TopoDS::Edge(Fba));
1482 DBRep::Set(a[1],theGl);
1487 static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
1488 Standard_Integer narg, const char** a)
1491 if (strcasecmp(a[0],"FEATPRISM") &&
1492 strcasecmp(a[0],"FEATDPRISM") &&
1493 strcasecmp(a[0],"FEATREVOL") &&
1494 strcasecmp(a[0],"FEATPIPE") &&
1495 strcasecmp(a[0],"FEATLF") &&
1496 strcasecmp(a[0],"FEATRF")) {
1500 if ((!strcasecmp(a[0],"FEATPRISM") && narg !=9) ||
1501 (!strcasecmp(a[0],"FEATREVOL") && narg != 12) ||
1502 (!strcasecmp(a[0],"FEATDPRISM") && narg != 7) ||
1503 (!strcasecmp(a[0],"FEATPIPE") && narg != 7) ||
1504 (!strcasecmp(a[0],"FEATLF") && narg != 12) ||
1505 (!strcasecmp(a[0],"FEATRF") && narg != 14)) {
1506 theCommands << "invalid number of arguments";
1510 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1511 if (Sbase.IsNull()) {
1512 theCommands << "null basis shape";
1515 Standard_Integer Ifuse = Draw::Atoi(a[narg-2]);
1516 Standard_Integer Imodif = Draw::Atoi(a[narg-1]);
1518 Standard_Integer Fuse = Ifuse;
1519 Standard_Boolean Modify = (Imodif!=0);
1525 Handle(Geom_Plane) P;
1527 BRepFeat_StatusError se;
1529 if (strcasecmp(a[0],"FEATLF") && strcasecmp(a[0],"FEATRF")) {
1530 Pbase = DBRep::Get(a[2]);
1531 if (Pbase.IsNull()) {
1532 theCommands << "null shape to transform";
1535 TopoDS_Shape aLocalShape(DBRep::Get(a[3],TopAbs_FACE));
1536 Skface = TopoDS::Face(aLocalShape);
1537 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
1538 if (Skface.IsNull()) {
1539 theCommands << "null face of Sketch";
1544 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1545 W = TopoDS::Wire(aLocalShape);
1546 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1548 theCommands << "null profile for rib or slot";
1551 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1552 P = Handle(Geom_Plane)::DownCast(s);
1554 theCommands << "null plane to transform";
1558 if (narg == 9 || narg == 12 || narg == 14) {
1559 // Standard_Real X,Y,Z,X1,Y1,Z1;
1560 Standard_Real X,Y,Z;
1561 X = Draw::Atof(a[4]);
1562 Y = Draw::Atof(a[5]);
1563 Z = Draw::Atof(a[6]);
1565 if (narg == 9) { // prism
1566 prdef = Standard_True;
1567 thePrism.Init(Sbase,Pbase,Skface,gp_Dir(X,Y,Z),Fuse,Modify);
1569 else if(narg == 14) {
1570 rfdef = Standard_True;
1572 X = Draw::Atof(a[7]);
1573 Y = Draw::Atof(a[8]);
1574 Z = Draw::Atof(a[9]);
1575 Standard_Real H1 = Draw::Atof(a[10]);
1576 Standard_Real H2 = Draw::Atof(a[11]);
1577 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1578 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1579 if (!theRF.IsDone()) {
1580 se = theRF.CurrentStatusError();
1581 //BRepFeat::Print(se,cout) << endl;
1582 Standard_SStream aSStream;
1583 BRepFeat::Print(se,aSStream);
1584 theCommands << aSStream << "\n";
1588 else if(narg == 12 && strcasecmp(a[0],"FEATLF")) {
1589 rvdef = Standard_True;
1591 X = Draw::Atof(a[7]);
1592 Y = Draw::Atof(a[8]);
1593 Z = Draw::Atof(a[9]);
1594 theRevol.Init(Sbase,Pbase,Skface,gp_Ax1(Or,gp_Dir(X,Y,Z)),
1598 lfdef = Standard_True;
1599 gp_Vec Direct(X,Y,Z);
1600 X = Draw::Atof(a[7]);
1601 Y = Draw::Atof(a[8]);
1602 Z = Draw::Atof(a[9]);
1603 theLF.Init(Sbase, W, P, Direct, gp_Vec(X,Y,Z), Fuse,Modify);
1604 if (!theLF.IsDone()) {
1605 se = theLF.CurrentStatusError();
1606 //BRepFeat::Print(se,cout) << endl;
1607 Standard_SStream aSStream;
1608 BRepFeat::Print(se,aSStream);
1609 theCommands << aSStream << "\n";
1614 else if (narg == 7) {
1615 if (!strcasecmp(a[0],"FEATDPRISM")) {
1616 if (Pbase.ShapeType() != TopAbs_FACE) {
1617 theCommands << "Invalid DPrism base";
1620 Standard_Real Angle = Draw::Atof(a[4])*M_PI/360;
1621 dprdef = Standard_True;
1622 theDPrism.Init(Sbase,TopoDS::Face(Pbase),Skface,Angle,Fuse,Modify);
1625 TopoDS_Shape aLocalShape(DBRep::Get(a[4],TopAbs_WIRE));
1626 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
1627 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
1628 if (Spine.IsNull()) {
1629 TopoDS_Shape Edspine =DBRep::Get(a[4],TopAbs_EDGE);
1630 if (Edspine.IsNull()) {
1631 theCommands << "null spine";
1636 B.Add(Spine,Edspine);
1638 pidef = Standard_True;
1639 thePipe.Init(Sbase,Pbase,Skface,Spine,Fuse,Modify);
1647 static Standard_Integer ADD(Draw_Interpretor& ,
1648 Standard_Integer narg, const char** a)
1650 Standard_Integer i ;
1651 if (narg < 4 || narg%2 != 0) {
1654 if (!strcasecmp("PRISM",a[1])) {
1658 for ( i=2; i<narg; i+=2) {
1659 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1660 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1661 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1665 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1666 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1667 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1671 thePrism.Add(edg,fac);
1674 else if (!strcasecmp("REVOL",a[1])) {
1678 for ( i=2; i<narg; i+=2) {
1679 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1680 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1681 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1685 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1686 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1687 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1691 theRevol.Add(edg,fac);
1694 else if (!strcasecmp("PIPE",a[1])) {
1698 for ( i=2; i<narg; i+=2) {
1699 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1700 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1701 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1705 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1706 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1707 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1711 thePipe.Add(edg,fac);
1722 static Standard_Integer PERF(Draw_Interpretor& theCommands,
1723 Standard_Integer narg, const char** a)
1728 if (strcasecmp(a[0],"FEATPERFORM") &&
1729 strcasecmp(a[0],"FEATPERFORMVAL")) {
1733 Standard_Integer Kas;
1734 if (!strcasecmp("PRISM",a[1])) {
1737 theCommands << "prism not defined";
1741 else if (!strcasecmp("REVOL",a[1])) {
1744 theCommands << "revol not defined";
1748 else if (!strcasecmp("PIPE",a[1])) {
1751 theCommands << "pipe not defined";
1754 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1755 theCommands << "invalid command for pipe";
1759 else if (!strcasecmp("DPRISM",a[1])) {
1762 theCommands << "dprism not defined";
1766 else if (!strcasecmp("LF",a[1])) {
1769 theCommands << "lf not defined";
1772 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1773 theCommands << "invalid command for lf";
1777 else if (!strcasecmp("RF",a[1])) {
1780 theCommands << "rf not defined";
1783 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1784 theCommands << "invalid command for rf";
1789 theCommands << "unknown argument : " << a[1];
1793 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1794 if (narg !=4 && narg != 5) {
1795 theCommands << "invalid number of arguments";
1799 Standard_Real Val = Draw::Atof(a[3]);
1801 thePrism.Perform(Val);
1803 else if (Kas == 2) {
1805 theRevol.Perform(Val);
1807 else if (Kas == 4) {
1808 theDPrism.Perform(Val);
1810 else if (Kas == 5) {
1811 theCommands << "invalid command for lf";
1814 else if (Kas == 6) {
1815 theCommands << "invalid command for rf";
1819 else if(narg == 5) {
1820 Standard_Real Val = Draw::Atof(a[3]);
1821 TopoDS_Shape FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
1823 thePrism.PerformUntilHeight(FUntil, Val);
1825 else if (Kas == 2) {
1827 theRevol.PerformUntilAngle(FUntil, Val);
1829 else if (Kas == 4) {
1830 theDPrism.PerformUntilHeight(FUntil, Val);
1833 theCommands << "invalid command for ribs or slots";
1838 else if (!strcasecmp(a[0],"FEATPERFORM")) {
1839 if (narg == 3) { // Thru all
1842 thePrism.PerformThruAll();
1845 theRevol.PerformThruAll();
1851 theDPrism.PerformThruAll();
1864 else if (narg == 4) { // Until
1865 TopoDS_Shape Funtil = DBRep::Get(a[3],TopAbs_SHAPE);
1869 if (Funtil.IsNull()) {
1870 thePrism.PerformUntilEnd();
1873 thePrism.Perform(Funtil);
1879 if (!Funtil.IsNull()) {
1880 theRevol.Perform(Funtil);
1889 if (!Funtil.IsNull()) {
1890 thePipe.Perform(Funtil);
1893 theCommands << "invalid command for ribs pipe";
1900 if (!Funtil.IsNull()) {
1901 theDPrism.Perform(Funtil);
1904 theDPrism.PerformUntilEnd();
1910 theCommands << "invalid command for lf";
1916 theCommands << "invalid command for rf";
1924 else if (narg == 5) {
1925 TopoDS_Shape Ffrom = DBRep::Get(a[3],TopAbs_SHAPE);
1926 TopoDS_Shape Funtil = DBRep::Get(a[4],TopAbs_SHAPE);
1927 if (Funtil.IsNull()) {
1933 if (Ffrom.IsNull()) {
1934 thePrism.PerformFromEnd(Funtil);
1937 thePrism.Perform(Ffrom,Funtil);
1943 if (Ffrom.IsNull()) {
1946 theRevol.Perform(Ffrom,Funtil);
1951 if (Ffrom.IsNull()) {
1954 thePipe.Perform(Ffrom,Funtil);
1959 if (Ffrom.IsNull()) {
1960 theDPrism.PerformFromEnd(Funtil);
1963 theDPrism.Perform(Ffrom,Funtil);
1974 BRepFeat_StatusError se;
1977 if (!thePrism.IsDone()) {
1978 se = thePrism.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],thePrism);
1989 if (!theRevol.IsDone()) {
1990 se = theRevol.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],theRevol);
2001 if (!thePipe.IsDone()) {
2002 se = thePipe.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],thePipe);
2013 if (!theDPrism.IsDone()) {
2014 se = theDPrism.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],theDPrism);
2025 if (!theLF.IsDone()) {
2026 se = theLF.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],theLF);
2037 if (!theRF.IsDone()) {
2038 se = theRF.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],theRF);
2054 static Standard_Integer BOSS(Draw_Interpretor& theCommands,
2055 Standard_Integer narg, const char** a)
2057 if (strcasecmp(a[0],"ENDEDGES") && strcasecmp(a[0],"FILLET")
2058 && strcasecmp(a[0],"BOSSAGE")) {
2062 if ((!strcasecmp(a[0],"ENDEDGES") && narg !=5) ||
2063 (!strcasecmp(a[0],"FILLET") && narg <5 && narg%2 != 1) ||
2064 (!strcasecmp(a[0],"BOSSAGE") && narg != 6)) {
2065 theCommands << "invalid number of arguments";
2069 Standard_Integer Kas=0;
2070 Standard_Integer dprsig=0;
2071 if (!strcasecmp("ENDEDGES",a[0])) {
2073 dprsig = Draw::Atoi(a[4]);
2075 else if (!strcasecmp("FILLET",a[0])) {
2078 else if (!strcasecmp("BOSSAGE",a[0])) {
2080 dprsig = Draw::Atoi(a[5]);
2083 TopoDS_Shape theShapeTop;
2084 TopoDS_Shape theShapeBottom;
2086 if (Kas == 1 || Kas == 3) {
2087 if (!strcasecmp("DPRISM",a[1])) {
2089 theCommands << "dprism not defined";
2094 theCommands << "unknown argument : " << a[1];
2098 theDPrism.BossEdges(dprsig);
2100 TopTools_ListOfShape theTopEdges, theLatEdges;
2101 theTopEdges = theDPrism.TopEdges();
2102 theLatEdges = theDPrism.LatEdges();
2104 TopTools_ListIteratorOfListOfShape it;
2107 B.MakeCompound(TopoDS::Compound(theShapeTop));
2108 it.Initialize(theTopEdges);
2109 for(; it.More(); it.Next()) {
2110 TopExp_Explorer exp;
2111 for (exp.Init(it.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
2112 B.Add(theShapeTop,exp.Current());
2115 DBRep::Set(a[2],theShapeTop);
2118 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2119 it.Initialize(theLatEdges);
2120 for(; it.More(); it.Next()) {
2121 B.Add(theShapeBottom,it.Value());
2123 DBRep::Set(a[3],theShapeBottom);
2125 if (Kas == 1) return 0;
2128 if (Kas == 2 || Kas == 3) {
2130 // Standard_Integer nrad;
2133 V = DBRep::Get(a[2],TopAbs_SHAPE);
2135 else if (Kas == 3) {
2139 if(V.IsNull()) return 1;
2140 ChFi3d_FilletShape FSh = ChFi3d_Rational;
2141 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
2142 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
2143 Rakk->SetContinuity(blend_cont, tapp_angle);
2147 Standard_Integer nbedge = 0;
2150 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
2151 Rad = Draw::Atof(a[2*ii + 1]);
2152 if (Rad == 0.) continue;
2153 S = DBRep::Get(a[(2*ii+2)],TopAbs_SHAPE);
2154 TopExp_Explorer exp;
2155 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2156 E = TopoDS::Edge(exp.Current());
2164 else if (Kas == 3) {
2165 Rad = Draw::Atof(a[3]);
2168 TopExp_Explorer exp;
2169 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2170 E = TopoDS::Edge(exp.Current());
2177 Rad = Draw::Atof(a[4]);
2180 TopExp_Explorer exp;
2181 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2182 E = TopoDS::Edge(exp.Current());
2191 if(!nbedge) return 1;
2193 if(!Rakk->IsDone()) return 1;
2194 TopoDS_Shape res = Rakk->Shape();
2197 DBRep::Set(a[1],res);
2199 else if (Kas == 3) {
2200 DBRep::Set(a[2],res);
2210 //=======================================================================
2211 //function : FeatureCommands
2213 //=======================================================================
2215 void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
2217 static Standard_Boolean done = Standard_False;
2219 done = Standard_True;
2221 DBRep::BasicCommands(theCommands);
2223 const char* g = "TOPOLOGY Feature commands";
2225 theCommands.Add("localope",
2226 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2229 theCommands.Add("hole",
2230 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2233 theCommands.Add("firsthole",
2234 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2237 theCommands.Add("holend",
2238 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2241 theCommands.Add("blindhole",
2242 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2245 theCommands.Add("holecontrol",
2246 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2247 __FILE__,CONTROL,g);
2249 theCommands.Add("wprism",
2250 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2254 theCommands.Add("fprism",
2255 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2259 theCommands.Add("wrotate",
2260 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2264 theCommands.Add("frotate",
2265 "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...]",
2269 theCommands.Add("splitshape",
2270 "splitshape result shape face wire/edge/compound [wire/edge/compound ...][face wire/edge/compound [wire/edge/compound...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2274 theCommands.Add("thickshell",
2275 "thickshell r shape offset [jointype [tol] ]",
2276 __FILE__,thickshell,g);
2278 theCommands.Add("offsetshape",
2279 "offsetshape r shape offset [tol] [face ...]",
2280 __FILE__,offsetshape,g);
2282 theCommands.Add("offsetcompshape",
2283 "offsetcompshape r shape offset [face ...]",
2284 __FILE__,offsetshape,g);
2286 theCommands.Add("offsetparameter",
2287 "offsetparameter tol inter(a/i) join(a/i)",
2288 __FILE__,offsetparameter);
2290 theCommands.Add("offsetload",
2291 "offsetload shape offset bouchon1 bouchon2 ...",
2292 __FILE__,offsetload,g);
2294 theCommands.Add("offsetonface",
2295 "offsetonface face1 offset1 face2 offset2 ...",
2296 __FILE__,offsetonface,g);
2298 theCommands.Add("offsetperform",
2299 "offsetperform result",
2300 __FILE__,offsetperform,g);
2303 theCommands.Add("deboucle",
2304 " Essai de debouclage partiel: deboucle result shape F/C face [face...] @ face [face...]",
2308 theCommands.Add("glue",
2309 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2313 theCommands.Add("featprism",
2314 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2317 theCommands.Add("featrevol",
2318 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2321 theCommands.Add("featpipe",
2322 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2325 theCommands.Add("featdprism",
2326 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2329 theCommands.Add("featlf",
2330 "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)",
2333 theCommands.Add("featrf",
2334 "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)",
2337 theCommands.Add("addslide",
2338 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2341 theCommands.Add("featperform",
2342 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2345 theCommands.Add("featperformval",
2346 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2349 theCommands.Add("endedges",
2350 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2353 theCommands.Add("fillet",
2354 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2357 theCommands.Add("bossage",
2358 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",