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";
344 //=======================================================================
345 //function : reportOffsetState
346 //purpose : Print state of offset operation by error code.
347 //=======================================================================
348 static void reportOffsetState(Draw_Interpretor& theCommands,
349 const BRepOffset_Error theErrorCode)
353 case BRepOffset_NoError:
355 theCommands << "OK. Offset performed succesfully.";
358 case BRepOffset_BadNormalsOnGeometry:
360 theCommands << "ERROR. Degenerated normal on input data.";
363 case BRepOffset_C0Geometry:
365 theCommands << "ERROR. C0 continuity of input data.";
368 case BRepOffset_NullOffset:
370 theCommands << "ERROR. Null offset of all faces.";
373 case BRepOffset_NotConnectedShell:
375 theCommands << "ERROR. Incorrect set of faces to remove, the remaining shell is not connected.";
380 theCommands << "ERROR. offsetperform operation not done.";
386 //=======================================================================
389 //=======================================================================
391 static Standard_Integer PRW(Draw_Interpretor& theCommands,
392 Standard_Integer narg, const char** a)
394 if (narg<9) return 1;
395 TopoDS_Shape S = DBRep::Get(a[3]);
396 BRepFeat_MakePrism thePFace;
398 TopoDS_Shape FFrom,FUntil;
399 Standard_Integer borne;
400 Standard_Boolean fuse;
401 if (a[1][0] == 'f' || a[1][0] == 'F') {
402 fuse = Standard_True;
404 else if (a[1][0] == 'c' || a[1][0] == 'C') {
405 fuse = Standard_False;
411 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
415 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
419 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
420 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
421 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
425 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
426 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
431 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
434 Standard_Real Length = V.Magnitude();
435 if (Length < Precision::Confusion()) {
439 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
440 TopoDS_Face F = TopoDS::Face(aLocalShape);
441 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
442 BRepFeat_SplitShape Spls(F);
443 for (Standard_Integer i = borne+1; i<narg; i++) {
446 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
447 wir = TopoDS::Wire(aLocalShape);
448 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
453 const char* Temp = a[i]+1;
454 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
455 wir = TopoDS::Wire(aLocalShape);
456 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
463 TopoDS_Shape ToPrism;
464 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
465 if (lleft.Extent() == 1) {
466 thePFace.Init(S,lleft.First(),F,V,fuse,Standard_True);
467 ToPrism = lleft.First();
473 TopTools_ListIteratorOfListOfShape it;
474 for (it.Initialize(lleft);it.More();it.Next()) {
475 B.Add(Sh,TopoDS::Face(it.Value()));
477 Sh.Closed (BRep_Tool::IsClosed (Sh));
478 thePFace.Init(S,Sh,F,V,fuse,Standard_True);
482 // Recherche des faces de glissement, si on n`a pas sketche sur une face
483 // du shape de depart
485 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
486 TopExp_Explorer exp(S,TopAbs_FACE) ;
487 for ( ;exp.More();exp.Next()) {
488 if (exp.Current().IsSame(F)) {
494 LocOpe_FindEdgesInFace FEIF;
495 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
496 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
497 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
498 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
499 Su = Handle(Geom_RectangularTrimmedSurface)::
500 DownCast(Su)->BasisSurface();
502 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
503 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
504 if (pl.Contains(gp_Lin(pl.Location(),V),
505 Precision::Confusion(),
506 Precision::Angular())) {
507 FEIF.Set(ToPrism,fac);
508 for (FEIF.Init();FEIF.More();FEIF.Next()) {
509 thePFace.Add(FEIF.Edge(),fac);
513 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
515 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
516 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
517 FEIF.Set(ToPrism,fac);
518 for (FEIF.Init();FEIF.More();FEIF.Next()) {
519 thePFace.Add(FEIF.Edge(),fac);
527 thePFace.Perform(Length);
529 else if (borne == 8) {
530 thePFace.Perform(FUntil);
532 else if (borne == 9) {
533 if (!(FFrom.IsNull() || FUntil.IsNull())) {
534 thePFace.Perform(FFrom,FUntil);
536 else if (FFrom.IsNull()) {
537 if (!FUntil.IsNull()) {
538 thePFace.PerformFromEnd(FUntil);
541 thePFace.PerformThruAll();
545 // il faudrait inverser V et appeler PerfomFromEnd...
546 //cout << "Not Implemented" << endl;
547 theCommands << "Not Implemented\n";
550 if (!thePFace.IsDone()) {
551 theCommands << "Local operation not done";
555 DBRep::Set(a[2],thePFace);
561 //=======================================================================
564 //=======================================================================
566 static Standard_Integer PRF(Draw_Interpretor& theCommands,
567 Standard_Integer narg, const char** a)
569 if (narg<8) return 1;
570 TopoDS_Shape S = DBRep::Get(a[3]);
571 BRepFeat_MakePrism thePFace;
572 Standard_Integer borne;
574 TopoDS_Shape FFrom,FUntil;
575 Standard_Boolean fuse;
576 if (a[1][0] == 'f' || a[1][0] == 'F') {
577 fuse = Standard_True;
579 else if (a[1][0] == 'c' || a[1][0] == 'C') {
580 fuse = Standard_False;
587 if (a[4][0] == '.' || IsAlphabetic(a[4][0])) {
591 if (a[5][0] == '.' || IsAlphabetic(a[5][0])) {
596 V.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
597 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
598 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
602 V.SetCoord(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]));
603 FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
608 V.SetCoord(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
610 Standard_Real Length = V.Magnitude();
611 if (Length < Precision::Confusion()) {
615 TopoDS_Shape ToPrism;
616 if (narg == borne+1) {
617 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
618 TopoDS_Face F = TopoDS::Face(aLocalShape);
619 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
620 thePFace.Init(S,F,F,V,fuse,Standard_True);
627 for (Standard_Integer i=borne; i<narg; i++) {
628 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
629 TopoDS_Face F = TopoDS::Face(aLocalShape);
630 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
635 She.Closed (BRep_Tool::IsClosed (She));
636 thePFace.Init(S,She,TopoDS_Face(),V,fuse,Standard_False);
640 // Recherche des faces de glissement, on ne prisme pas une face
641 // du shape de depart
643 // for (TopExp_Explorer exp(ToPrism,TopAbs_FACE);exp.More();exp.Next()) {
644 TopExp_Explorer exp(ToPrism,TopAbs_FACE) ;
645 for ( ;exp.More();exp.Next()) {
646 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
647 TopExp_Explorer exp2(S,TopAbs_FACE) ;
648 for ( ;exp2.More();exp2.Next()) {
649 if (exp2.Current().IsSame(exp.Current())) {
659 LocOpe_FindEdgesInFace FEIF;
660 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
661 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
662 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
663 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
664 Su = Handle(Geom_RectangularTrimmedSurface)::
665 DownCast(Su)->BasisSurface();
667 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
668 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
669 if (pl.Contains(gp_Lin(pl.Location(),V),
670 Precision::Confusion(),
671 Precision::Angular())) {
672 FEIF.Set(ToPrism,fac);
673 for (FEIF.Init();FEIF.More();FEIF.Next()) {
674 thePFace.Add(FEIF.Edge(),fac);
678 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
680 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
681 if (V.IsParallel(cy.Axis().Direction(),Precision::Angular())) {
682 FEIF.Set(ToPrism,fac);
683 for (FEIF.Init();FEIF.More();FEIF.Next()) {
684 thePFace.Add(FEIF.Edge(),fac);
692 thePFace.Perform(Length);
694 else if (borne == 8) {
695 thePFace.Perform(FUntil);
697 else if (borne == 9) {
698 if (!(FFrom.IsNull() || FUntil.IsNull())) {
699 thePFace.Perform(FFrom,FUntil);
701 else if (FFrom.IsNull()) {
702 if (!FUntil.IsNull()) {
703 thePFace.PerformFromEnd(FUntil);
706 thePFace.PerformThruAll();
709 else { //FUntil.IsNull()
710 // il faudrait inverser V et appeler PerfomFromEnd...
711 //cout << "Not Implemented" << endl;
712 theCommands << "Not Implemented\n";
715 if (!thePFace.IsDone()) {
716 theCommands << "Local operation not done";
720 DBRep::Set(a[2],thePFace);
727 //=======================================================================
730 //=======================================================================
732 static Standard_Integer SPLS(Draw_Interpretor& ,
733 Standard_Integer narg, const char** a)
735 Standard_Integer newnarg ;
737 if (narg<3) return 1;
738 TopoDS_Shape S = DBRep::Get(a[2]);
739 BRepFeat_SplitShape Spls(S);
740 Standard_Boolean pick = Standard_False;
743 Standard_Integer i = 3;
745 for ( newnarg=3; newnarg<narg; newnarg++) {
746 if (a[newnarg][0] == '@') {
752 (newnarg !=narg && ((narg-newnarg)<=2 || (narg-newnarg)%2 != 1))) {
757 pick = (a[i][0] == '.');
758 EF = DBRep::Get(a[i],TopAbs_FACE);
759 if (EF.IsNull()) return 1;
762 while (i < newnarg) {
764 DBRep_DrawableShape::LastPick(EF,u,v);
766 if (EF.ShapeType() == TopAbs_FACE) {
767 // face wire/edge ...
769 while (i < newnarg) {
771 Standard_Boolean rever = Standard_False;
772 if (a[i][0] == '-') {
775 pick = (a[i][1] == '.');
776 const char* Temp = a[i]+1;
777 W = DBRep::Get(Temp,TopAbs_SHAPE,Standard_False);
778 rever = Standard_True;
781 pick = (a[i][0] == '.');
782 W = DBRep::Get(a[i],TopAbs_SHAPE,Standard_False);
785 return 1; // on n`a rien recupere
787 TopAbs_ShapeEnum wtyp = W.ShapeType();
788 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND && pick) {
789 DBRep_DrawableShape::LastPick(W,u,v);
790 wtyp = W.ShapeType();
792 if (wtyp != TopAbs_WIRE && wtyp != TopAbs_EDGE && wtyp != TopAbs_COMPOUND) {
793 EF = DBRep::Get(a[i]);
800 if (wtyp == TopAbs_WIRE) {
801 Spls.Add(TopoDS::Wire(W),TopoDS::Face(EF));
803 else if (wtyp == TopAbs_EDGE) {
804 Spls.Add(TopoDS::Edge(W),TopoDS::Face(EF));
807 Spls.Add(TopoDS::Compound(W),TopoDS::Face(EF));
817 // ici, i vaut newnarg
818 for (i++; i<narg; i+=2) {
820 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
821 Es = TopoDS::Edge(aLocalShape);
822 // Es = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
826 aLocalShape = DBRep::Get(a[i+1],TopAbs_EDGE);
827 Ew = TopoDS::Edge(aLocalShape);
828 // Ew = TopoDS::Edge(DBRep::Get(a[i+1],TopAbs_EDGE));
832 Spls.Add(TopoDS::Edge(Ew),TopoDS::Edge(Es));
836 DBRep::Set(a[1],Spls);
840 //=======================================================================
841 //function : thickshell
843 //=======================================================================
844 Standard_Integer thickshell(Draw_Interpretor& theCommands,
845 Standard_Integer n, const char** a)
847 if ( n < 4) return 1;
848 TopoDS_Shape S = DBRep::Get(a[2]);
849 if (S.IsNull()) return 1;
851 Standard_Real Of = Draw::Atof(a[3]);
853 GeomAbs_JoinType JT= GeomAbs_Arc;
856 if (!strcmp(a[4],"i"))
857 JT = GeomAbs_Intersection;
858 if (!strcmp(a[4],"t"))
859 JT = GeomAbs_Tangent;
862 Standard_Boolean Inter = Standard_False; //Standard_True;
863 Standard_Real Tol = Precision::Confusion();
865 Tol = Draw::Atof(a[5]);
867 BRepOffset_MakeOffset B;
868 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT,Standard_True);
872 const BRepOffset_Error aRetCode = B.Error();
873 reportOffsetState(theCommands, aRetCode);
875 DBRep::Set(a[1],B.Shape());
879 //=======================================================================
880 //function : offsetshape
882 //=======================================================================
884 Standard_Integer offsetshape(Draw_Interpretor& theCommands,
885 Standard_Integer n, const char** a)
887 if ( n < 4) return 1;
888 TopoDS_Shape S = DBRep::Get(a[2]);
889 if (S.IsNull()) return 1;
891 Standard_Real Of = Draw::Atof(a[3]);
892 Standard_Boolean Inter = (!strcmp(a[0],"offsetcompshape"));
893 GeomAbs_JoinType JT= GeomAbs_Arc;
894 if (!strcmp(a[0],"offsetinter"))
896 JT = GeomAbs_Intersection;
897 Inter = Standard_True;
900 BRepOffset_MakeOffset B;
901 Standard_Integer IB = 4;
902 Standard_Real Tol = Precision::Confusion();
905 TopoDS_Shape SF = DBRep::Get(a[4],TopAbs_FACE);
909 Tol = Draw::Atof(a[4]);
912 B.Initialize(S,Of,Tol,BRepOffset_Skin,Inter,0,JT);
913 //------------------------------------------
914 // recuperation et chargement des bouchons.
915 //----------------------------------------
916 Standard_Boolean YaBouchon = Standard_False;
918 for (Standard_Integer i = IB ; i < n; i++)
920 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
923 YaBouchon = Standard_True;
924 B.AddFace(TopoDS::Face(SF));
928 if (!YaBouchon) B.MakeOffsetShape();
929 else B.MakeThickSolid ();
931 const BRepOffset_Error aRetCode = B.Error();
932 reportOffsetState(theCommands, aRetCode);
934 DBRep::Set(a[1],B.Shape());
939 static BRepOffset_MakeOffset TheOffset;
940 static Standard_Real TheRadius;
941 static Standard_Boolean theYaBouchon;
942 static Standard_Real TheTolerance = Precision::Confusion();
943 static Standard_Boolean TheInter = Standard_False;
944 static GeomAbs_JoinType TheJoin = GeomAbs_Arc;
945 static Standard_Boolean RemoveIntEdges = Standard_False;
946 static Standard_Boolean RemoveInvalidFaces = Standard_False;
948 Standard_Integer offsetparameter(Draw_Interpretor& di,
949 Standard_Integer n, const char** a)
952 di << " OffsetParameter Tol Inter(c/p) JoinType(a/i/t) [RemoveInternalEdges(r/k) RemoveInvalidFaces(r/k)]\n";
953 di << " Current Values\n";
954 di << " --> Tolerance : " << TheTolerance << "\n";
955 di << " --> TheInter : ";
961 di << "\n --> TheJoin : ";
964 case GeomAbs_Arc: di << "Arc"; break;
965 case GeomAbs_Intersection: di << "Intersection"; break;
970 di << "\n --> Internal Edges : ";
971 if (RemoveIntEdges) {
978 di << "\n --> Invalid Faces : ";
979 if (RemoveInvalidFaces) {
990 if ( n < 4 ) return 1;
992 TheTolerance = Draw::Atof(a[1]);
993 TheInter = strcmp(a[2],"p");
995 if ( !strcmp(a[3],"a")) TheJoin = GeomAbs_Arc;
996 else if ( !strcmp(a[3],"i")) TheJoin = GeomAbs_Intersection;
997 else if ( !strcmp(a[3],"t")) TheJoin = GeomAbs_Tangent;
999 RemoveIntEdges = (n >= 5) ? !strcmp(a[4], "r") : Standard_False;
1000 RemoveInvalidFaces = (n == 6) ? !strcmp(a[5], "r") : Standard_False;
1005 //=======================================================================
1006 //function : offsetinit
1008 //=======================================================================
1010 Standard_Integer offsetload(Draw_Interpretor& ,
1011 Standard_Integer n, const char** a)
1013 if ( n < 2) return 1;
1014 TopoDS_Shape S = DBRep::Get(a[1]);
1015 if (S.IsNull()) return 1;
1017 Standard_Real Of = Draw::Atof(a[2]);
1019 // Standard_Boolean Inter = Standard_True;
1021 TheOffset.Initialize(S,Of,TheTolerance,BRepOffset_Skin,TheInter,0,TheJoin,
1022 Standard_False, RemoveIntEdges, RemoveInvalidFaces);
1023 //------------------------------------------
1024 // recuperation et chargement des bouchons.
1025 //----------------------------------------
1026 for (Standard_Integer i = 3 ; i < n; i++) {
1027 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
1029 TheOffset.AddFace(TopoDS::Face(SF));
1032 if (n < 4) theYaBouchon = Standard_False; //B.MakeOffsetShape();
1033 else theYaBouchon = Standard_True; //B.MakeThickSolid ();
1039 //=======================================================================
1040 //function : offsetonface
1042 //=======================================================================
1044 Standard_Integer offsetonface(Draw_Interpretor&, Standard_Integer n, const char** a)
1046 if ( n < 3) return 1;
1048 for (Standard_Integer i = 1 ; i < n; i+=2) {
1049 TopoDS_Shape SF = DBRep::Get(a[i],TopAbs_FACE);
1051 Standard_Real Of = Draw::Atof(a[i+1]);
1052 TheOffset.SetOffsetOnFace(TopoDS::Face(SF),Of);
1059 //=======================================================================
1060 //function : offsetperform
1062 //=======================================================================
1064 Standard_Integer offsetperform(Draw_Interpretor& theCommands,
1065 Standard_Integer theNArg, const char** a)
1067 if ( theNArg < 2) return 1;
1070 TheOffset.MakeThickSolid ();
1072 TheOffset.MakeOffsetShape();
1074 if(TheOffset.IsDone())
1076 DBRep::Set(a[1],TheOffset.Shape());
1080 const BRepOffset_Error aRetCode = TheOffset.Error();
1081 reportOffsetState(theCommands, aRetCode);
1088 //=======================================================================
1091 //=======================================================================
1093 static Standard_Integer ROW(Draw_Interpretor& theCommands,
1094 Standard_Integer narg, const char** a)
1096 if (narg<13) return 1;
1097 TopoDS_Shape S = DBRep::Get(a[3]);
1098 BRepFeat_MakeRevol theRFace;
1101 Standard_Real Angle=0;
1102 TopoDS_Shape FFrom,FUntil;
1103 Standard_Integer i,borne;
1104 Standard_Boolean fuse;
1106 if (a[1][0] == 'f' || a[1][0] == 'F') {
1107 fuse = Standard_True;
1109 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1110 fuse = Standard_False;
1116 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1117 if (FFrom.IsNull()) {
1118 Angle = Draw::Atof(a[4]);
1123 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1124 if (FUntil.IsNull()) {
1139 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1140 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1141 gp_Ax1 theAxis(Or,D);
1143 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1144 TopoDS_Face F = TopoDS::Face(aLocalShape);
1145 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1146 BRepFeat_SplitShape Spls(F);
1147 for (i = borne+1; i<narg; i++) {
1149 if (a[i][0] !='-') {
1150 aLocalShape = DBRep::Get(a[i],TopAbs_WIRE);
1151 wir = TopoDS::Wire(aLocalShape);
1152 // wir = TopoDS::Wire(DBRep::Get(a[i],TopAbs_WIRE));
1155 if (a[i][1] == '\0')
1157 const char* Temp = a[i]+1;
1158 aLocalShape = DBRep::Get(Temp,TopAbs_WIRE);
1159 wir = TopoDS::Wire(aLocalShape);
1160 // wir = TopoDS::Wire(DBRep::Get(Temp,TopAbs_WIRE));
1167 TopoDS_Shape ToRotate;
1168 const TopTools_ListOfShape& lleft = Spls.DirectLeft();
1169 if (lleft.Extent() == 1) {
1170 theRFace.Init(S,lleft.First(),F,theAxis,fuse,Standard_True);
1171 ToRotate = lleft.First();
1177 TopTools_ListIteratorOfListOfShape it;
1178 for (it.Initialize(lleft);it.More();it.Next()) {
1179 B.Add(Sh,TopoDS::Face(it.Value()));
1181 Sh.Closed (BRep_Tool::IsClosed (Sh));
1182 theRFace.Init(S,Sh,F,theAxis,fuse,Standard_True);
1186 // Recherche des faces de glissement
1187 // for (TopExp_Explorer exp(S,TopAbs_FACE);exp.More();exp.Next()) {
1188 TopExp_Explorer exp(S,TopAbs_FACE) ;
1189 for ( ;exp.More();exp.Next()) {
1190 if (exp.Current().IsSame(F)) {
1196 LocOpe_FindEdgesInFace FEIF;
1197 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1198 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1199 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1200 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1201 Su = Handle(Geom_RectangularTrimmedSurface)::
1202 DownCast(Su)->BasisSurface();
1204 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1205 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1206 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1207 FEIF.Set(ToRotate,fac);
1208 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1209 theRFace.Add(FEIF.Edge(),fac);
1213 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1215 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1216 if (cy.Axis().IsCoaxial(theAxis,
1217 Precision::Angular(),Precision::Confusion())) {
1218 FEIF.Set(ToRotate,fac);
1219 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1220 theRFace.Add(FEIF.Edge(),fac);
1228 if (FUntil.IsNull()) {
1229 theRFace.Perform(Angle);
1232 theRFace.Perform(FUntil);
1235 else { // borne == 12
1236 theRFace.Perform(FFrom,FUntil);
1239 if (!theRFace.IsDone()) {
1240 theCommands << "Local operation not done";
1244 DBRep::Set(a[2],theRFace);
1250 //=======================================================================
1253 //=======================================================================
1255 static Standard_Integer ROF(Draw_Interpretor& theCommands,
1256 Standard_Integer narg, const char** a)
1258 if (narg<12) return 1;
1259 TopoDS_Shape S = DBRep::Get(a[3]);
1260 BRepFeat_MakeRevol theRFace;
1263 Standard_Real Angle=0;
1264 TopoDS_Shape FFrom,FUntil;
1265 Standard_Integer i,borne;
1266 Standard_Boolean fuse;
1268 if (a[1][0] == 'f' || a[1][0] == 'F') {
1269 fuse = Standard_True;
1271 else if (a[1][0] == 'c' || a[1][0] == 'C') {
1272 fuse = Standard_False;
1278 FFrom = DBRep::Get(a[4],TopAbs_SHAPE);
1279 if (FFrom.IsNull()) {
1280 Angle = Draw::Atof(a[4]);
1285 FUntil = DBRep::Get(a[5],TopAbs_SHAPE);
1286 if (FUntil.IsNull()) {
1301 Or.SetCoord(Draw::Atof(a[i]),Draw::Atof(a[i+1]),Draw::Atof(a[i+2]));
1302 D.SetCoord(Draw::Atof(a[i+3]),Draw::Atof(a[i+4]),Draw::Atof(a[i+5]));
1303 gp_Ax1 theAxis(Or,D);
1305 TopoDS_Shape ToRotate;
1306 if (narg == borne+1) {
1307 TopoDS_Shape aLocalShape(DBRep::Get(a[borne],TopAbs_FACE));
1308 TopoDS_Face F = TopoDS::Face(aLocalShape);
1309 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[borne],TopAbs_FACE));
1310 theRFace.Init(S,F,F,theAxis,fuse,Standard_True);
1318 for (i=borne; i<narg; i++) {
1319 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
1320 TopoDS_Face F = TopoDS::Face(aLocalShape);
1321 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
1326 She.Closed (BRep_Tool::IsClosed (She));
1327 theRFace.Init(S,She,TopoDS_Face(),theAxis,fuse,Standard_False);
1331 // for (TopExp_Explorer exp(ToRotate,TopAbs_FACE);exp.More();exp.Next()) {
1332 TopExp_Explorer exp(ToRotate,TopAbs_FACE) ;
1333 for ( ;exp.More();exp.Next()) {
1334 // for (TopExp_Explorer exp2(S,TopAbs_FACE);exp2.More();exp2.Next()) {
1335 TopExp_Explorer exp2(S,TopAbs_FACE) ;
1336 for ( ;exp2.More();exp2.Next()) {
1337 if (exp2.Current().IsSame(exp.Current())) {
1347 LocOpe_FindEdgesInFace FEIF;
1348 for (exp.Init(S,TopAbs_FACE);exp.More();exp.Next()) {
1349 const TopoDS_Face& fac = TopoDS::Face(exp.Current());
1350 Handle(Geom_Surface) Su = BRep_Tool::Surface(fac);
1351 if (Su->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1352 Su = Handle(Geom_RectangularTrimmedSurface)::
1353 DownCast(Su)->BasisSurface();
1355 if (Su->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
1356 gp_Pln pl = Handle(Geom_Plane)::DownCast(Su)->Pln();
1357 if (pl.Axis().IsParallel(theAxis,Precision::Angular())) {
1358 FEIF.Set(ToRotate,fac);
1359 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1360 theRFace.Add(FEIF.Edge(),fac);
1364 else if (Su->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
1366 Handle(Geom_CylindricalSurface)::DownCast(Su)->Cylinder();
1367 if (cy.Axis().IsCoaxial(theAxis,
1368 Precision::Angular(),Precision::Confusion())) {
1369 FEIF.Set(ToRotate,fac);
1370 for (FEIF.Init();FEIF.More();FEIF.Next()) {
1371 theRFace.Add(FEIF.Edge(),fac);
1379 if (FUntil.IsNull()) {
1380 theRFace.Perform(Angle);
1383 theRFace.Perform(FUntil);
1386 else { // borne == 12
1387 theRFace.Perform(FFrom,FUntil);
1390 if (!theRFace.IsDone()) {
1391 theCommands << "Local operation not done";
1395 DBRep::Set(a[2],theRFace);
1401 //=======================================================================
1403 //purpose : Commande glue
1404 //=======================================================================
1406 static Standard_Integer GLU(Draw_Interpretor& ,
1407 Standard_Integer narg, const char** a)
1409 if (narg<6 || narg%2 != 0) return 1;
1410 TopoDS_Shape Sne = DBRep::Get(a[2]);
1411 TopoDS_Shape Sba = DBRep::Get(a[3]);
1413 Standard_Boolean pick;
1415 BRepFeat_Gluer theGl(Sne,Sba);
1416 TopoDS_Shape Fne,Fba;
1418 LocOpe_FindEdges fined;
1420 Standard_Integer i = 4;
1421 Standard_Boolean first = Standard_True;
1423 pick = (a[i][0] == '.');
1424 Fne = DBRep::Get(a[i]);
1428 TopAbs_ShapeEnum sht = Fne.ShapeType();
1429 if (pick && sht != TopAbs_FACE && sht != TopAbs_EDGE) {
1431 DBRep_DrawableShape::LastPick(Fne,u,v);
1432 sht = Fne.ShapeType();
1434 if (first && sht != TopAbs_FACE) {
1437 first = Standard_False;
1438 pick = (a[i+1][0] == '.');
1439 Fba = DBRep::Get(a[i+1]);
1443 if (pick && Fba.ShapeType() != sht) {
1445 DBRep_DrawableShape::LastPick(Fba,u,v);
1447 if (Fba.ShapeType() != sht) {
1450 if (sht == TopAbs_FACE) {
1451 const TopoDS_Face& f1 = TopoDS::Face(Fne);
1452 const TopoDS_Face& f2 = TopoDS::Face(Fba);
1455 for (fined.InitIterator(); fined.More(); fined.Next()) {
1456 theGl.Bind(fined.EdgeFrom(),fined.EdgeTo());
1460 theGl.Bind(TopoDS::Edge(Fne),TopoDS::Edge(Fba));
1465 DBRep::Set(a[1],theGl);
1470 static Standard_Integer DEFIN(Draw_Interpretor& theCommands,
1471 Standard_Integer narg, const char** a)
1474 if (strcasecmp(a[0],"FEATPRISM") &&
1475 strcasecmp(a[0],"FEATDPRISM") &&
1476 strcasecmp(a[0],"FEATREVOL") &&
1477 strcasecmp(a[0],"FEATPIPE") &&
1478 strcasecmp(a[0],"FEATLF") &&
1479 strcasecmp(a[0],"FEATRF")) {
1483 if ((!strcasecmp(a[0],"FEATPRISM") && narg !=9) ||
1484 (!strcasecmp(a[0],"FEATREVOL") && narg != 12) ||
1485 (!strcasecmp(a[0],"FEATDPRISM") && narg != 7) ||
1486 (!strcasecmp(a[0],"FEATPIPE") && narg != 7) ||
1487 (!strcasecmp(a[0],"FEATLF") && narg != 12) ||
1488 (!strcasecmp(a[0],"FEATRF") && narg != 14)) {
1489 theCommands << "invalid number of arguments";
1493 TopoDS_Shape Sbase = DBRep::Get(a[1]);
1494 if (Sbase.IsNull()) {
1495 theCommands << "null basis shape";
1498 Standard_Integer Ifuse = Draw::Atoi(a[narg-2]);
1499 Standard_Integer Imodif = Draw::Atoi(a[narg-1]);
1501 Standard_Integer Fuse = Ifuse;
1502 Standard_Boolean Modify = (Imodif!=0);
1508 Handle(Geom_Plane) P;
1510 BRepFeat_StatusError se;
1512 if (strcasecmp(a[0],"FEATLF") && strcasecmp(a[0],"FEATRF")) {
1513 Pbase = DBRep::Get(a[2]);
1514 if (Pbase.IsNull()) {
1515 theCommands << "null shape to transform";
1518 TopoDS_Shape aLocalShape(DBRep::Get(a[3],TopAbs_FACE));
1519 Skface = TopoDS::Face(aLocalShape);
1520 // Skface = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
1521 if (Skface.IsNull()) {
1522 theCommands << "null face of Sketch";
1527 TopoDS_Shape aLocalShape(DBRep::Get(a[2], TopAbs_WIRE));
1528 W = TopoDS::Wire(aLocalShape);
1529 // W = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1531 theCommands << "null profile for rib or slot";
1534 Handle(Geom_Surface) s = DrawTrSurf::GetSurface(a[3]);
1535 P = Handle(Geom_Plane)::DownCast(s);
1537 theCommands << "null plane to transform";
1541 if (narg == 9 || narg == 12 || narg == 14) {
1542 // Standard_Real X,Y,Z,X1,Y1,Z1;
1543 Standard_Real X,Y,Z;
1544 X = Draw::Atof(a[4]);
1545 Y = Draw::Atof(a[5]);
1546 Z = Draw::Atof(a[6]);
1548 if (narg == 9) { // prism
1549 prdef = Standard_True;
1550 thePrism.Init(Sbase,Pbase,Skface,gp_Dir(X,Y,Z),Fuse,Modify);
1552 else if(narg == 14) {
1553 rfdef = Standard_True;
1555 X = Draw::Atof(a[7]);
1556 Y = Draw::Atof(a[8]);
1557 Z = Draw::Atof(a[9]);
1558 Standard_Real H1 = Draw::Atof(a[10]);
1559 Standard_Real H2 = Draw::Atof(a[11]);
1560 gp_Ax1 ax1(Or, gp_Dir(X, Y, Z));
1561 theRF.Init(Sbase, W, P, ax1, H1, H2, Fuse, Modify);
1562 if (!theRF.IsDone()) {
1563 se = theRF.CurrentStatusError();
1564 //BRepFeat::Print(se,cout) << endl;
1565 Standard_SStream aSStream;
1566 BRepFeat::Print(se,aSStream);
1567 theCommands << aSStream << "\n";
1571 else if(narg == 12 && strcasecmp(a[0],"FEATLF")) {
1572 rvdef = Standard_True;
1574 X = Draw::Atof(a[7]);
1575 Y = Draw::Atof(a[8]);
1576 Z = Draw::Atof(a[9]);
1577 theRevol.Init(Sbase,Pbase,Skface,gp_Ax1(Or,gp_Dir(X,Y,Z)),
1581 lfdef = Standard_True;
1582 gp_Vec Direct(X,Y,Z);
1583 X = Draw::Atof(a[7]);
1584 Y = Draw::Atof(a[8]);
1585 Z = Draw::Atof(a[9]);
1586 theLF.Init(Sbase, W, P, Direct, gp_Vec(X,Y,Z), Fuse,Modify);
1587 if (!theLF.IsDone()) {
1588 se = theLF.CurrentStatusError();
1589 //BRepFeat::Print(se,cout) << endl;
1590 Standard_SStream aSStream;
1591 BRepFeat::Print(se,aSStream);
1592 theCommands << aSStream << "\n";
1597 else if (narg == 7) {
1598 if (!strcasecmp(a[0],"FEATDPRISM")) {
1599 if (Pbase.ShapeType() != TopAbs_FACE) {
1600 theCommands << "Invalid DPrism base";
1603 Standard_Real Angle = Draw::Atof(a[4])*M_PI/360;
1604 dprdef = Standard_True;
1605 theDPrism.Init(Sbase,TopoDS::Face(Pbase),Skface,Angle,Fuse,Modify);
1608 TopoDS_Shape aLocalShape(DBRep::Get(a[4],TopAbs_WIRE));
1609 TopoDS_Wire Spine = TopoDS::Wire(aLocalShape);
1610 // TopoDS_Wire Spine = TopoDS::Wire(DBRep::Get(a[4],TopAbs_WIRE));
1611 if (Spine.IsNull()) {
1612 TopoDS_Shape Edspine =DBRep::Get(a[4],TopAbs_EDGE);
1613 if (Edspine.IsNull()) {
1614 theCommands << "null spine";
1619 B.Add(Spine,Edspine);
1621 pidef = Standard_True;
1622 thePipe.Init(Sbase,Pbase,Skface,Spine,Fuse,Modify);
1630 static Standard_Integer ADD(Draw_Interpretor& ,
1631 Standard_Integer narg, const char** a)
1633 Standard_Integer i ;
1634 if (narg < 4 || narg%2 != 0) {
1637 if (!strcasecmp("PRISM",a[1])) {
1641 for ( i=2; i<narg; i+=2) {
1642 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1643 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1644 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1648 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1649 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1650 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1654 thePrism.Add(edg,fac);
1657 else if (!strcasecmp("REVOL",a[1])) {
1661 for ( i=2; i<narg; i+=2) {
1662 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1663 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1664 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1668 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1669 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1670 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1674 theRevol.Add(edg,fac);
1677 else if (!strcasecmp("PIPE",a[1])) {
1681 for ( i=2; i<narg; i+=2) {
1682 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
1683 TopoDS_Edge edg = TopoDS::Edge(aLocalShape);
1684 // TopoDS_Edge edg = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
1688 aLocalShape = DBRep::Get(a[i+1],TopAbs_FACE);
1689 TopoDS_Face fac = TopoDS::Face(aLocalShape);
1690 // TopoDS_Face fac = TopoDS::Face(DBRep::Get(a[i+1],TopAbs_FACE));
1694 thePipe.Add(edg,fac);
1705 static Standard_Integer PERF(Draw_Interpretor& theCommands,
1706 Standard_Integer narg, const char** a)
1711 if (strcasecmp(a[0],"FEATPERFORM") &&
1712 strcasecmp(a[0],"FEATPERFORMVAL")) {
1716 Standard_Integer Kas;
1717 if (!strcasecmp("PRISM",a[1])) {
1720 theCommands << "prism not defined";
1724 else if (!strcasecmp("REVOL",a[1])) {
1727 theCommands << "revol not defined";
1731 else if (!strcasecmp("PIPE",a[1])) {
1734 theCommands << "pipe not defined";
1737 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1738 theCommands << "invalid command for pipe";
1742 else if (!strcasecmp("DPRISM",a[1])) {
1745 theCommands << "dprism not defined";
1749 else if (!strcasecmp("LF",a[1])) {
1752 theCommands << "lf not defined";
1755 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1756 theCommands << "invalid command for lf";
1760 else if (!strcasecmp("RF",a[1])) {
1763 theCommands << "rf not defined";
1766 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1767 theCommands << "invalid command for rf";
1772 theCommands << "unknown argument : " << a[1];
1776 if (!strcasecmp(a[0],"FEATPERFORMVAL")) {
1777 if (narg !=4 && narg != 5) {
1778 theCommands << "invalid number of arguments";
1782 Standard_Real Val = Draw::Atof(a[3]);
1784 thePrism.Perform(Val);
1786 else if (Kas == 2) {
1788 theRevol.Perform(Val);
1790 else if (Kas == 4) {
1791 theDPrism.Perform(Val);
1793 else if (Kas == 5) {
1794 theCommands << "invalid command for lf";
1797 else if (Kas == 6) {
1798 theCommands << "invalid command for rf";
1802 else if(narg == 5) {
1803 Standard_Real Val = Draw::Atof(a[3]);
1804 TopoDS_Shape FUntil = DBRep::Get(a[4],TopAbs_SHAPE);
1806 thePrism.PerformUntilHeight(FUntil, Val);
1808 else if (Kas == 2) {
1810 theRevol.PerformUntilAngle(FUntil, Val);
1812 else if (Kas == 4) {
1813 theDPrism.PerformUntilHeight(FUntil, Val);
1816 theCommands << "invalid command for ribs or slots";
1821 else if (!strcasecmp(a[0],"FEATPERFORM")) {
1822 if (narg == 3) { // Thru all
1825 thePrism.PerformThruAll();
1828 theRevol.PerformThruAll();
1834 theDPrism.PerformThruAll();
1847 else if (narg == 4) { // Until
1848 TopoDS_Shape Funtil = DBRep::Get(a[3],TopAbs_SHAPE);
1852 if (Funtil.IsNull()) {
1853 thePrism.PerformUntilEnd();
1856 thePrism.Perform(Funtil);
1862 if (!Funtil.IsNull()) {
1863 theRevol.Perform(Funtil);
1872 if (!Funtil.IsNull()) {
1873 thePipe.Perform(Funtil);
1876 theCommands << "invalid command for ribs pipe";
1883 if (!Funtil.IsNull()) {
1884 theDPrism.Perform(Funtil);
1887 theDPrism.PerformUntilEnd();
1893 theCommands << "invalid command for lf";
1899 theCommands << "invalid command for rf";
1907 else if (narg == 5) {
1908 TopoDS_Shape Ffrom = DBRep::Get(a[3],TopAbs_SHAPE);
1909 TopoDS_Shape Funtil = DBRep::Get(a[4],TopAbs_SHAPE);
1910 if (Funtil.IsNull()) {
1916 if (Ffrom.IsNull()) {
1917 thePrism.PerformFromEnd(Funtil);
1920 thePrism.Perform(Ffrom,Funtil);
1926 if (Ffrom.IsNull()) {
1929 theRevol.Perform(Ffrom,Funtil);
1934 if (Ffrom.IsNull()) {
1937 thePipe.Perform(Ffrom,Funtil);
1942 if (Ffrom.IsNull()) {
1943 theDPrism.PerformFromEnd(Funtil);
1946 theDPrism.Perform(Ffrom,Funtil);
1957 BRepFeat_StatusError se;
1960 if (!thePrism.IsDone()) {
1961 se = thePrism.CurrentStatusError();
1962 //BRepFeat::Print(se,cout) << endl;
1963 Standard_SStream aSStream;
1964 BRepFeat::Print(se,aSStream);
1965 theCommands << aSStream << "\n";
1968 DBRep::Set(a[2],thePrism);
1972 if (!theRevol.IsDone()) {
1973 se = theRevol.CurrentStatusError();
1974 //BRepFeat::Print(se,cout) << endl;
1975 Standard_SStream aSStream;
1976 BRepFeat::Print(se,aSStream);
1977 theCommands << aSStream << "\n";
1980 DBRep::Set(a[2],theRevol);
1984 if (!thePipe.IsDone()) {
1985 se = thePipe.CurrentStatusError();
1986 //BRepFeat::Print(se,cout) << endl;
1987 Standard_SStream aSStream;
1988 BRepFeat::Print(se,aSStream);
1989 theCommands << aSStream << "\n";
1992 DBRep::Set(a[2],thePipe);
1996 if (!theDPrism.IsDone()) {
1997 se = theDPrism.CurrentStatusError();
1998 //BRepFeat::Print(se,cout) << endl;
1999 Standard_SStream aSStream;
2000 BRepFeat::Print(se,aSStream);
2001 theCommands << aSStream << "\n";
2004 DBRep::Set(a[2],theDPrism);
2008 if (!theLF.IsDone()) {
2009 se = theLF.CurrentStatusError();
2010 //BRepFeat::Print(se,cout) << endl;
2011 Standard_SStream aSStream;
2012 BRepFeat::Print(se,aSStream);
2013 theCommands << aSStream << "\n";
2016 DBRep::Set(a[2],theLF);
2020 if (!theRF.IsDone()) {
2021 se = theRF.CurrentStatusError();
2022 //BRepFeat::Print(se,cout) << endl;
2023 Standard_SStream aSStream;
2024 BRepFeat::Print(se,aSStream);
2025 theCommands << aSStream << "\n";
2028 DBRep::Set(a[2],theRF);
2037 static Standard_Integer BOSS(Draw_Interpretor& theCommands,
2038 Standard_Integer narg, const char** a)
2040 if (strcasecmp(a[0],"ENDEDGES") && strcasecmp(a[0],"FILLET")
2041 && strcasecmp(a[0],"BOSSAGE")) {
2045 if ((!strcasecmp(a[0],"ENDEDGES") && narg !=5) ||
2046 (!strcasecmp(a[0],"FILLET") && narg <5 && narg%2 != 1) ||
2047 (!strcasecmp(a[0],"BOSSAGE") && narg != 6)) {
2048 theCommands << "invalid number of arguments";
2052 Standard_Integer Kas=0;
2053 Standard_Integer dprsig=0;
2054 if (!strcasecmp("ENDEDGES",a[0])) {
2056 dprsig = Draw::Atoi(a[4]);
2058 else if (!strcasecmp("FILLET",a[0])) {
2061 else if (!strcasecmp("BOSSAGE",a[0])) {
2063 dprsig = Draw::Atoi(a[5]);
2066 TopoDS_Shape theShapeTop;
2067 TopoDS_Shape theShapeBottom;
2069 if (Kas == 1 || Kas == 3) {
2070 if (!strcasecmp("DPRISM",a[1])) {
2072 theCommands << "dprism not defined";
2077 theCommands << "unknown argument : " << a[1];
2081 theDPrism.BossEdges(dprsig);
2083 TopTools_ListOfShape theTopEdges, theLatEdges;
2084 theTopEdges = theDPrism.TopEdges();
2085 theLatEdges = theDPrism.LatEdges();
2087 TopTools_ListIteratorOfListOfShape it;
2090 B.MakeCompound(TopoDS::Compound(theShapeTop));
2091 it.Initialize(theTopEdges);
2092 for(; it.More(); it.Next()) {
2093 TopExp_Explorer exp;
2094 for (exp.Init(it.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
2095 B.Add(theShapeTop,exp.Current());
2098 DBRep::Set(a[2],theShapeTop);
2101 B.MakeCompound(TopoDS::Compound(theShapeBottom));
2102 it.Initialize(theLatEdges);
2103 for(; it.More(); it.Next()) {
2104 B.Add(theShapeBottom,it.Value());
2106 DBRep::Set(a[3],theShapeBottom);
2108 if (Kas == 1) return 0;
2111 if (Kas == 2 || Kas == 3) {
2113 // Standard_Integer nrad;
2116 V = DBRep::Get(a[2],TopAbs_SHAPE);
2118 else if (Kas == 3) {
2122 if(V.IsNull()) return 1;
2123 ChFi3d_FilletShape FSh = ChFi3d_Rational;
2124 Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
2125 Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
2126 Rakk->SetContinuity(blend_cont, tapp_angle);
2130 Standard_Integer nbedge = 0;
2133 for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
2134 Rad = Draw::Atof(a[2*ii + 1]);
2135 if (Rad == 0.) continue;
2136 S = DBRep::Get(a[(2*ii+2)],TopAbs_SHAPE);
2137 TopExp_Explorer exp;
2138 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2139 E = TopoDS::Edge(exp.Current());
2147 else if (Kas == 3) {
2148 Rad = Draw::Atof(a[3]);
2151 TopExp_Explorer exp;
2152 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2153 E = TopoDS::Edge(exp.Current());
2160 Rad = Draw::Atof(a[4]);
2163 TopExp_Explorer exp;
2164 for (exp.Init(S,TopAbs_EDGE); exp.More(); exp.Next()) {
2165 E = TopoDS::Edge(exp.Current());
2174 if(!nbedge) return 1;
2176 if(!Rakk->IsDone()) return 1;
2177 TopoDS_Shape res = Rakk->Shape();
2180 DBRep::Set(a[1],res);
2182 else if (Kas == 3) {
2183 DBRep::Set(a[2],res);
2193 //=======================================================================
2194 //function : FeatureCommands
2196 //=======================================================================
2198 void BRepTest::FeatureCommands (Draw_Interpretor& theCommands)
2200 static Standard_Boolean done = Standard_False;
2202 done = Standard_True;
2204 DBRep::BasicCommands(theCommands);
2206 const char* g = "TOPOLOGY Feature commands";
2208 theCommands.Add("localope",
2209 " Performs a local top. operation : localope result shape tool F/C (fuse/cut) face [face...]",
2212 theCommands.Add("hole",
2213 " Performs a hole : hole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius [Pfrom Pto]",
2216 theCommands.Add("firsthole",
2217 " Performs the first hole : firsthole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2220 theCommands.Add("holend",
2221 " Performs the hole til end : holend result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius",
2224 theCommands.Add("blindhole",
2225 " Performs the blind hole : blindhole result shape Or.X Or.Y Or.Z Dir.X Dir.Y Dir.Z Radius Length",
2228 theCommands.Add("holecontrol",
2229 "Sets/Unsets or display controls on holes : holecontrol [0/1]",
2230 __FILE__,CONTROL,g);
2232 theCommands.Add("wprism",
2233 "Prisms wires on a face : wprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ SkecthFace wire1 [wire2 ....]",
2237 theCommands.Add("fprism",
2238 "Prisms a set of faces of a shape : fprism f[use]/c[ut] result shape [[FaceFrom] FaceUntil] VecX VecY VecZ face1 [face2...]",
2242 theCommands.Add("wrotate",
2243 "Rotates wires on a face : wrotate f[use]/c[ut] result shape Angle/[FFrom] FUntil OX OY OZ DX DY DZ SkecthFace wire1 [wire2 ....]",
2247 theCommands.Add("frotate",
2248 "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...]",
2252 theCommands.Add("splitshape",
2253 "splitshape result shape face wire/edge/compound [wire/edge/compound ...][face wire/edge/compound [wire/edge/compound...] ...] [@ edgeonshape edgeonwire [edgeonshape edgeonwire...]]",
2257 theCommands.Add("thickshell",
2258 "thickshell r shape offset [jointype [tol] ]",
2259 __FILE__,thickshell,g);
2261 theCommands.Add("offsetshape",
2262 "offsetshape r shape offset [tol] [face ...]",
2263 __FILE__,offsetshape,g);
2265 theCommands.Add("offsetcompshape",
2266 "offsetcompshape r shape offset [face ...]",
2267 __FILE__,offsetshape,g);
2269 theCommands.Add("offsetparameter",
2270 "offsetparameter tol inter(a/i) join(a/i)",
2271 __FILE__,offsetparameter);
2273 theCommands.Add("offsetload",
2274 "offsetload shape offset bouchon1 bouchon2 ...",
2275 __FILE__,offsetload,g);
2277 theCommands.Add("offsetonface",
2278 "offsetonface face1 offset1 face2 offset2 ...",
2279 __FILE__,offsetonface,g);
2281 theCommands.Add("offsetperform",
2282 "offsetperform result",
2283 __FILE__,offsetperform,g);
2285 theCommands.Add("glue",
2286 "glue result shapenew shapebase facenew facebase [facenew facebase...] [edgenew edgebase [edgenew edgebase...]]",
2290 theCommands.Add("featprism",
2291 "Defines the arguments for a prism : featprism shape element skface Dirx Diry Dirz Fuse(0/1/2) Modify(0/1)",
2294 theCommands.Add("featrevol",
2295 "Defines the arguments for a revol : featrevol shape element skface Ox Oy Oz Dx Dy Dz Fuse(0/1/2) Modify(0/1)",
2298 theCommands.Add("featpipe",
2299 "Defines the arguments for a pipe : featpipe shape element skface spine Fuse(0/1/2) Modify(0/1)",
2302 theCommands.Add("featdprism",
2303 "Defines the arguments for a drafted prism : featdprism shape face skface angle Fuse(0/1/2) Modify(0/1)",
2306 theCommands.Add("featlf",
2307 "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)",
2310 theCommands.Add("featrf",
2311 "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)",
2314 theCommands.Add("addslide",
2315 " Adds sliding elements : addslide prism/revol/pipe edge face [edge face...]",
2318 theCommands.Add("featperform",
2319 " Performs the prism revol dprism linform or pipe :featperform prism/revol/pipe/dprism/lf result [[Ffrom] Funtil]",
2322 theCommands.Add("featperformval",
2323 " Performs the prism revol dprism or linform with a value :featperformval prism/revol/dprism/lf result value",
2326 theCommands.Add("endedges",
2327 " Return top and bottom edges of dprism :endedges dprism shapetop shapebottom First/LastShape (1/2)",
2330 theCommands.Add("fillet",
2331 " Perform fillet on compounds of edges :fillet result object rad1 comp1 rad2 comp2 ...",
2334 theCommands.Add("bossage",
2335 " Perform fillet on top and bottom edges of dprism :bossage dprism result radtop radbottom First/LastShape (1/2)",