1 // Created on: 1993-07-21
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1993-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.
19 #include <BRep_TEdge.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepGProp.hxx>
22 #include <BRepTools.hxx>
23 #include <BRepTools_ShapeSet.hxx>
24 #include <BRepTools_WireExplorer.hxx>
25 #include <BinTools.hxx>
26 #include <DBRep_DrawableShape.hxx>
27 #include <Draw_Appli.hxx>
28 #include <Draw_ProgressIndicator.hxx>
29 #include <Message_ProgressRange.hxx>
30 #include <Draw_Segment3D.hxx>
31 #include <GProp_GProps.hxx>
32 #include <NCollection_Vector.hxx>
33 #include <OSD_FileSystem.hxx>
34 #include <TColStd_Array1OfInteger.hxx>
35 #include <TColStd_Array1OfReal.hxx>
38 #include <TopExp_Explorer.hxx>
40 #include <TopoDS_Compound.hxx>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopTools_Array1OfShape.hxx>
43 #include <TopTools_MapOfShape.hxx>
48 extern Draw_Viewer dout;
51 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
52 #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg]))
55 //==========================================
57 //==========================================
59 Standard_EXPORT void DBRep_WriteColorOrientation ()
61 std::cout << "\nrouge FORWARD";
62 std::cout << "\nbleu REVERSED";
63 std::cout << "\nrose EXTERNAL";
64 std::cout << "\norange INTERNAL"<<std::endl;
67 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or)
76 case TopAbs_REVERSED :
80 case TopAbs_EXTERNAL :
84 case TopAbs_INTERNAL :
92 //=======================================================================
93 //function : Parameters
95 //=======================================================================
96 DBRep_Params& DBRep::Parameters()
98 static DBRep_Params aParams;
102 //=======================================================================
104 //=======================================================================
106 static Standard_Integer isos(Draw_Interpretor& di, Standard_Integer NbArg, const char **Arg)
108 DBRep_Params& aParams = DBRep::Parameters();
112 di << "Current number of isos : " << aParams.NbIsos << "\n" ;
116 Standard_Integer aNbIsos = 0;
117 Standard_Boolean Change = Standard_False ;
118 if (!Characters (NbArg) && Float (NbArg)) return 1 ;
119 if (!Characters (NbArg))
121 aNbIsos = Draw::Atoi (Arg[NbArg]);
123 Change = Standard_True ;
128 aParams.NbIsos = aNbIsos;
129 di << "New current number of isos : " << aParams.NbIsos << "\n";
133 for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++)
135 Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
136 if (!Shape1.IsNull())
138 Handle (DBRep_DrawableShape) Shape2 = Handle (DBRep_DrawableShape)::DownCast (Shape1);
139 if (!Shape2.IsNull())
143 Shape2->ChangeNbIsos (aNbIsos);
147 di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
152 if (Change) dout.RepaintAll() ;
158 //=======================================================================
160 //=======================================================================
162 static Standard_Integer hlr (Draw_Interpretor& di, Standard_Integer n, const char **a)
164 DBRep_Params& aParams = DBRep::Parameters();
170 di << (aParams.WithRgN
172 : (aParams.WithRg1 ? " Rg1Lines" : " no RegLines"));
173 di << (aParams.WithHid ? " HiddenLines" : " no HiddenLines");
177 di << "Angle of discretization : ";
178 di << aParams.HLRAngle * 180 / M_PI << " degrees\n";
181 else di << " wireframe";
188 if (!strcasecmp(a[1], "nohlr"))
190 aParams.WithHLR = Standard_False;
192 else if (!strcasecmp (a[1], "hlr"))
194 aParams.WithHLR = Standard_True;
196 else if (!strcasecmp (a[1], "nohid"))
198 aParams.WithHid = Standard_False;
200 else if (!strcasecmp(a[1], "hid"))
202 aParams.WithHLR = Standard_True;
203 aParams.WithHid = Standard_True;
205 else if (!strcasecmp(a[1], "norg1"))
207 aParams.WithRg1 = Standard_False;
208 aParams.WithRgN = Standard_False;
210 else if (!strcasecmp (a[1], "rg1"))
212 aParams.WithHLR = Standard_True;
213 aParams.WithRg1 = Standard_True;
214 aParams.WithRgN = Standard_False;
216 else if (!strcasecmp (a[1], "norgn"))
218 aParams.WithRgN = Standard_False;
220 else if (!strcasecmp (a[1], "rgn"))
222 aParams.WithHLR = Standard_True;
223 aParams.WithRg1 = Standard_True;
224 aParams.WithRgN = Standard_True;
226 else if (!strcasecmp (a[1], "ang"))
228 di << "Angle de discretisation : ";
229 di << aParams.HLRAngle * 180 / M_PI << " degres\n";
234 Standard_Integer nFirst = 2;
236 if (n >= 3 && !strcasecmp (a[1], "ang"))
241 Standard_Real ang = Draw::Atof(a[2]);
242 aParams.HLRAngle = ang * M_PI / 180;
243 if(aParams.HLRAngle < aParams.HAngMin)
245 aParams.HLRAngle = aParams.HAngMin;
247 if (aParams.HLRAngle > aParams.HAngMax)
249 aParams.HLRAngle = aParams.HAngMax;
252 di << "Angle of discretization : ";
253 di << aParams.HLRAngle * 180 / M_PI << " degrees\n";
256 for (Standard_Integer i = nFirst; i < n; i++)
258 Handle(Draw_Drawable3D) D = Draw::Get (a[i]);
259 Handle(DBRep_DrawableShape) S = Handle(DBRep_DrawableShape)::DownCast (D);
265 bool localHLR = false, localRg1 = false, localRgN = false, localHid = false;
266 Standard_Real localAng = 0.0;
267 S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid, localAng);
268 if (!strcasecmp (a[1], "nohlr"))
270 localHLR = Standard_False;
272 else if (!strcasecmp (a[1], "hlr"))
274 localHLR = Standard_True;
276 else if (!strcasecmp (a[1], "nohid"))
278 localHid = Standard_False;
280 else if (!strcasecmp (a[1], "hid"))
282 localHLR = Standard_True;
283 localHid = Standard_True;
285 else if (!strcasecmp (a[1], "norg1"))
287 localRg1 = Standard_False;
288 localRgN = Standard_False;
290 else if (!strcasecmp (a[1], "rg1"))
292 localHLR = Standard_True;
293 localRg1 = Standard_True;
294 localRgN = Standard_False;
296 else if (!strcasecmp (a[1], "norgn"))
298 localRgN = Standard_False;
300 else if (!strcasecmp (a[1], "rgn"))
302 localHLR = Standard_True;
303 localRg1 = Standard_True;
304 localRgN = Standard_True;
306 else if (!strcasecmp (a[1], "ang"))
308 Standard_Real ang = Draw::Atof (a[2]);
309 localAng = ang * M_PI / 180;
313 di << "Syntax error";
317 S->DisplayHLR (localHLR, localRg1, localRgN, localHid, localAng);
324 //=======================================================================
326 //=======================================================================
328 static Standard_Integer dispor (Draw_Interpretor&, Standard_Integer n, const char** a)
330 Standard_Boolean d = !strcasecmp(a[0],"vori");
333 DBRep_WriteColorOrientation();
336 for (Standard_Integer i = 1; i < n; i++)
338 Handle(Draw_Drawable3D) d1 = Draw::Get (a[i]);
339 if (Handle(DBRep_DrawableShape) d2 = Handle(DBRep_DrawableShape)::DownCast(d1))
341 d2->DisplayOrientation (d);
348 //=======================================================================
350 //=======================================================================
352 static Standard_Integer discretisation(Draw_Interpretor& di, Standard_Integer n, const char** a)
354 DBRep_Params& aParams = DBRep::Parameters();
357 di << "Current number of points : "<< aParams.Discretization <<"\n";
361 aParams.Discretization = Draw::Atoi(a[1]);
367 //=======================================================================
369 //=======================================================================
371 static Standard_Integer triangles(Draw_Interpretor&, Standard_Integer n, const char** a)
373 DBRep_Params& aParams = DBRep::Parameters();
380 aParams.DispTriangles = !aParams.DispTriangles;
384 for (Standard_Integer i = 1; i <= n-1; i++)
386 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
387 if (Handle(DBRep_DrawableShape) d2 = Handle(DBRep_DrawableShape)::DownCast(d1))
389 d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
398 //=======================================================================
400 //=======================================================================
402 static Standard_Integer tclean(Draw_Interpretor& di,
403 Standard_Integer n, const char** a)
405 Standard_Boolean toRemoveGeometry = Standard_False;
406 Standard_Boolean isForceClean = Standard_False;
413 TopoDS_Compound aCompound;
414 BRep_Builder().MakeCompound(aCompound);
415 for (Standard_Integer anArgIter = 1; anArgIter < n; ++anArgIter)
417 if (strcmp(a[anArgIter], "-geom") == 0)
419 toRemoveGeometry = Standard_True;
421 else if (strcmp(a[anArgIter], "-force") == 0)
423 isForceClean = Standard_True;
427 TopoDS_Shape aShape = DBRep::Get(a[anArgIter]);
430 di << "Syntax error : NULL shape '"<< a[anArgIter] << "'";
433 BRep_Builder().Add(aCompound, aShape);
436 if (aCompound.NbChildren() == 0)
438 di << "Syntax error : wrong number of arguments";
442 if (isForceClean && toRemoveGeometry)
444 di << "Syntax error: wrong usage of arguments: do not use 'force' and 'geom' flags together";
448 if (toRemoveGeometry)
449 BRepTools::CleanGeometry(aCompound);
451 BRepTools::Clean(aCompound, isForceClean);
455 //=======================================================================
457 //=======================================================================
459 static Standard_Integer polygons(Draw_Interpretor&, Standard_Integer n, const char** a)
461 DBRep_Params& aParams = DBRep::Parameters();
468 aParams.DisplayPolygons = !aParams.DisplayPolygons;
472 for (Standard_Integer i = 1; i <= n-1; i++)
474 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
475 if (Handle(DBRep_DrawableShape) d2 = Handle(DBRep_DrawableShape)::DownCast(d1))
477 d2->DisplayPolygons(!(d2->DisplayPolygons()));
486 //=======================================================================
488 //=======================================================================
490 static Standard_Integer compound(Draw_Interpretor& ,
491 Standard_Integer n, const char** a)
493 if (n <= 1) return 1;
497 for (Standard_Integer i = 1; i < n-1; i++) {
498 TopoDS_Shape S2 = DBRep::Get(a[i]);
499 if (!S2.IsNull()) B.Add(C,S2);
501 DBRep::Set(a[n-1],C);
505 //=======================================================================
507 //=======================================================================
509 static Standard_Integer emptycopy(Draw_Interpretor& ,
510 Standard_Integer n, const char** a)
512 if (n <= 1) return 1;
513 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
514 if (S.IsNull()) return 1;
520 //=======================================================================
522 //=======================================================================
524 static Standard_Integer add(Draw_Interpretor& ,
525 Standard_Integer n, const char** a)
529 TopoDS_Shape S1 = DBRep::Get(a[1]);
530 if (S1.IsNull()) return 1;
531 TopoDS_Shape S2 = DBRep::Get(a[2]);
532 if (S2.IsNull()) return 1;
538 //=======================================================================
540 //=======================================================================
542 static Standard_Integer explode(Draw_Interpretor& di,
543 Standard_Integer n, const char** a)
545 if (n <= 1) return 1;
546 TopoDS_Shape S = DBRep::Get(a[1]);
547 if (S.IsNull()) return 0;
549 strcpy(newname,a[1]);
551 while (*p != '\0') p++;
554 Standard_Integer i = 0;
556 TopoDS_Iterator itr(S);
560 DBRep::Set(newname,itr.Value());
561 di.AppendElement(newname);
567 TopAbs_ShapeEnum typ;
572 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
573 typ = TopAbs_COMPOUND;
575 typ = TopAbs_COMPSOLID;
580 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
582 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
612 TopTools_MapOfShape M;
614 TopExp_Explorer ex(S,typ);
615 for (; ex.More(); ex.Next()) {
616 const TopoDS_Shape& Sx = ex.Current();
617 Standard_Boolean added = M.Add(Sx);
621 DBRep::Set(newname,Sx);
622 di.AppendElement(newname);
629 //=======================================================================
630 // nexplode : stable numbered explode (from Serguey Nizhny)
631 //=======================================================================
633 static Standard_Integer nexplode(Draw_Interpretor& di,
634 Standard_Integer n, const char** a)
636 if (n <= 2) return 1;
637 TopoDS_Shape S = DBRep::Get(a[1]);
638 if (S.IsNull()) return 0;
640 strcpy(newname,a[1]);
642 while (*p != '\0') p++;
645 TopAbs_ShapeEnum typ;
666 TopTools_IndexedMapOfShape IMOStmp;
667 TopTools_MapOfShape MShape;
669 TopExp::MapShapes(S,typ,IMOStmp);
670 TopExp_Explorer Exp(S,typ);
671 Standard_Integer MaxShapes, Index = 0;
672 MaxShapes = IMOStmp.Extent()-1;
673 TopTools_Array1OfShape aShapes(1,MaxShapes);
677 if (MShape.Add(Exp.Current())) {
679 aShapes.SetValue(Index,Exp.Current());
684 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
687 Standard_Integer aTemp;
688 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
689 Standard_Boolean NoSort = Standard_True;
691 // Computing of CentreOfMass for edge and face
692 // and for vertex use its point
693 for (Index=1; Index <= MaxShapes; Index++) {
694 OrderInd.SetValue(Index,Index);
695 const TopoDS_Shape& aS = aShapes(Index);
696 if (aS.ShapeType() != TopAbs_VERTEX) {
697 BRepGProp::LinearProperties(aS, GPr);
698 GPoint = GPr.CentreOfMass();
701 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
703 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
708 NoSort = Standard_False;
709 for (Index=1; Index < MaxShapes; Index++) {
710 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
711 aTemp = OrderInd(Index);
712 OrderInd(Index) = OrderInd(Index+1);
713 OrderInd(Index+1) = aTemp;
714 NoSort = Standard_True;
718 // Check of equality of MidXYZ
719 for (Index=1; Index < MaxShapes; Index++) {
720 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
721 di<<"Warning! For this shape the results may be incorrect.\n";
724 for (Index=1 ;Index <= MaxShapes; Index++) {
725 Sprintf(p,"%d",Index);
726 DBRep::Set(newname,aShapes(OrderInd(Index)));
727 di.AppendElement(newname);
733 //=======================================================================
735 //=======================================================================
737 static Standard_Integer exwire(Draw_Interpretor& ,
738 Standard_Integer n, const char** a)
740 if (n <= 1) return 1;
741 TopoDS_Shape S = DBRep::Get(a[1]);
742 if (S.IsNull()) return 0;
743 if (S.ShapeType() != TopAbs_WIRE) return 0;
745 strcpy(newname,a[1]);
747 while (*p != '\0') p++;
750 Standard_Integer i = 0;
751 BRepTools_WireExplorer ex(TopoDS::Wire(S));
755 DBRep::Set(newname,ex.Current());
761 //=======================================================================
763 //=======================================================================
765 static Standard_Integer invert(Draw_Interpretor& ,
766 Standard_Integer n, const char** a)
768 if (n <= 1) return 1;
769 TopoDS_Shape S = DBRep::Get(a[1]);
770 if (S.IsNull()) return 0;
773 TopoDS_Shape NS = S.EmptyCopied();
774 NS.Closed (S.Closed());
776 TopoDS_Iterator itr(S);
778 B.Add(NS,itr.Value().Reversed());
786 //=======================================================================
787 // orientation, reverse, complement
788 //=======================================================================
790 static Standard_Integer orientation(Draw_Interpretor& ,
791 Standard_Integer n, const char** a)
793 if (n <= 1) return 1;
794 Standard_Integer cas = 0;
795 TopAbs_Orientation ori=TopAbs_FORWARD;
796 Standard_Integer last = n;
797 if (!strcasecmp(a[0],"orientation")) {
798 if (n <= 2) return 1;
803 ori = TopAbs_FORWARD;
807 ori = TopAbs_REVERSED;
811 ori = TopAbs_INTERNAL;
815 ori = TopAbs_EXTERNAL;
820 else if (!strcasecmp(a[0],"treverse")) {
824 else if (!strcasecmp(a[0],"complement")) {
828 for (Standard_Integer i = 1; i < last; i++) {
829 TopoDS_Shape S = DBRep::Get(a[i]);
843 #include <TCollection_AsciiString.hxx>
845 //=======================================================================
846 // numshapes same as nbshapes but the output is cout
847 //=======================================================================
849 static Standard_Integer numshapes(Draw_Interpretor& di,
850 Standard_Integer n, const char** a)
856 for (i = 1; i < n; i++) {
857 TopoDS_Shape S = DBRep::Get(a[i]);
859 BRepTools_ShapeSet BS;
861 di <<"Number of shapes in "<<a[i]<<"\n";
862 TCollection_AsciiString Astr;
864 di <<Astr.ToCString();
872 //=======================================================================
873 // function : DumpExtent
874 // purpose : Dumps the number of sub-shapes in <aStr>.
875 //=======================================================================
876 static void DumpExtent(const TopoDS_Shape& aS,
877 TCollection_AsciiString& aStr)
879 const int aNbTypes=8;
880 const char *pNames[aNbTypes+1]={
891 Standard_Integer i, aNb, aNbSh;
892 TopAbs_ShapeEnum aType;
893 TopTools_IndexedMapOfShape aM;
897 for (i=aNbTypes-1; i>=0; --i) {
899 aType=(TopAbs_ShapeEnum)i;
900 TopExp::MapShapes(aS, aType, aM);
902 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
905 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
908 //=======================================================================
910 //=======================================================================
912 static Standard_Integer nbshapes(Draw_Interpretor& di,
913 Standard_Integer n, const char** a)
918 Standard_Boolean aTotal;
921 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
923 for (i = 1; i < n; i++) {
924 TopoDS_Shape S = DBRep::Get(a[i]);
926 di<<"Number of shapes in "<<a[i]<<"\n";
927 TCollection_AsciiString Astr;
931 BRepTools_ShapeSet BS;
935 di<<Astr.ToCString();
942 //=======================================================================
944 //=======================================================================
946 static Standard_Integer countshapes(Draw_Interpretor& di,
947 Standard_Integer n, const char** a)
953 for (i = 1; i < n; i++) {
954 TopoDS_Shape Sh = DBRep::Get(a[i]);
955 Standard_Integer nbElem = 0;
957 di <<"Number of shapes in "<<a[i]<<"\n";
958 TopTools_MapOfShape M;
960 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
961 const TopoDS_Shape& S = ex.Current();
962 Standard_Boolean added = M.Add(S);
967 di << " VERTEX : " << nbElem << "\n";
970 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
971 const TopoDS_Shape& S = ex.Current();
972 Standard_Boolean added = M.Add(S);
977 di << " EDGE : " << nbElem << "\n";
980 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
981 const TopoDS_Shape& S = ex.Current();
982 Standard_Boolean added = M.Add(S);
987 di << " WIRE : " << nbElem << "\n";
990 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
991 const TopoDS_Shape& S = ex.Current();
992 Standard_Boolean added = M.Add(S);
997 di << " FACE : " << nbElem << "\n";
1000 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
1001 const TopoDS_Shape& S = ex.Current();
1002 Standard_Boolean added = M.Add(S);
1007 di << " SHELL : " << nbElem << "\n";
1010 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
1011 const TopoDS_Shape& S = ex.Current();
1012 Standard_Boolean added = M.Add(S);
1017 di << " SOLID : " << nbElem << "\n";
1020 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
1021 const TopoDS_Shape& S = ex.Current();
1022 Standard_Boolean added = M.Add(S);
1027 di << " COMPSOLID : " << nbElem << "\n";
1030 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
1031 const TopoDS_Shape& S = ex.Current();
1032 Standard_Boolean added = M.Add(S);
1037 di << " COMPOUND : " << nbElem << "\n";
1040 di << " SHAPE : " << M.Extent() << "\n";
1048 //=======================================================================
1050 //=======================================================================
1051 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
1054 for(i = 2; i < n; i++) {
1055 if (strstr ( a[i], "free" )) {
1056 if(a[i][0] == '-') {
1057 Sh.Free(Standard_False);
1060 Sh.Free(Standard_True);
1063 if (strstr ( a[i], "modified" )) {
1064 if(a[i][0] == '-') {
1065 Sh.Modified(Standard_False);
1068 Sh.Modified(Standard_True);
1071 if (strstr ( a[i], "checked" )) {
1072 if(a[i][0] == '-') {
1073 Sh.Checked(Standard_False);
1076 Sh.Checked(Standard_True);
1079 if (strstr ( a[i], "orientable" )) {
1080 if(a[i][0] == '-') {
1081 Sh.Orientable(Standard_False);
1084 Sh.Orientable(Standard_True);
1087 if (strstr ( a[i], "closed" )) {
1088 if(a[i][0] == '-') {
1089 Sh.Closed(Standard_False);
1092 Sh.Closed(Standard_True);
1095 if (strstr ( a[i], "infinite" )) {
1096 if(a[i][0] == '-') {
1097 Sh.Infinite(Standard_False);
1100 Sh.Infinite(Standard_True);
1103 if (strstr ( a[i], "convex" )) {
1104 if(a[i][0] == '-') {
1105 Sh.Convex(Standard_False);
1108 Sh.Convex(Standard_True);
1111 if (strstr ( a[i], "locked" )) {
1112 if(a[i][0] == '-') {
1113 Sh.Locked(Standard_False);
1116 Sh.Locked(Standard_True);
1122 //=======================================================================
1124 //=======================================================================
1125 static Standard_Integer setFlags(Draw_Interpretor& ,
1126 Standard_Integer n, const char** a)
1128 if (n < 3) return 1;
1131 TopoDS_Shape Sh = DBRep::Get(a[1]);
1133 if (Sh.IsNull()) return 1;
1136 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1137 const TopoDS_Shape& S = ex.Current();
1141 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1142 const TopoDS_Shape& S = ex.Current();
1146 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1147 const TopoDS_Shape& S = ex.Current();
1154 //=======================================================================
1156 //=======================================================================
1157 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1161 //=======================================================================
1163 //=======================================================================
1165 //=======================================================================
1167 static Standard_Integer check(Draw_Interpretor& ,
1168 Standard_Integer n, const char** a)
1170 if (n < 2) return 1;
1174 for (i = 1; i < n; i++) {
1175 TopoDS_Shape S = DBRep::Get(a[i]);
1177 if (S.IsNull()) continue;
1178 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1180 C.Checked(Standard_False);
1181 BRepTools::Update(C);
1188 //=======================================================================
1190 //=======================================================================
1191 static Standard_Integer normals (Draw_Interpretor& theDI,
1192 Standard_Integer theArgNum,
1193 const char** theArgs)
1197 std::cout << "Syntax error: wrong number of arguments!\n";
1198 theDI.PrintHelp (theArgs[0]);
1202 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1203 if (aShape.IsNull())
1205 std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1209 Standard_Boolean toUseMesh = Standard_False;
1210 Standard_Real aLength = 10.0;
1211 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1212 Standard_Boolean bPrint = Standard_False;
1213 for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1215 TCollection_AsciiString aParam (theArgs[anArgIter]);
1218 && aParam.IsRealValue())
1220 aLength = aParam.RealValue();
1221 if (Abs (aLength) <= gp::Resolution())
1223 std::cout << "Syntax error: length should not be zero\n";
1227 else if (aParam == "-usemesh"
1228 || aParam == "-mesh")
1230 toUseMesh = Standard_True;
1232 else if (aParam == "-length"
1233 || aParam == "-len")
1236 aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1237 if (Abs(aLength) <= gp::Resolution())
1239 std::cout << "Syntax error: length should not be zero\n";
1243 else if (aParam == "-nbalongu"
1244 || aParam == "-nbu")
1247 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1250 std::cout << "Syntax error: NbAlongU should be >=1\n";
1254 else if (aParam == "-nbalongv"
1255 || aParam == "-nbv")
1258 aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1261 std::cout << "Syntax error: NbAlongV should be >=1\n";
1265 else if (aParam == "-nbalong"
1266 || aParam == "-nbuv")
1269 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1270 aNbAlongV = aNbAlongU;
1273 std::cout << "Syntax error: NbAlong should be >=1\n";
1277 else if (aParam == "-print")
1279 bPrint = Standard_True;
1283 std::cout << "Syntax error: unknown argument '" << aParam << "'\n";
1288 DBRep_WriteColorOrientation();
1290 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1293 DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1297 DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1300 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1302 Standard_Boolean bReverse = Standard_False;
1303 TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation();
1304 const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri);
1305 if (aFaceOri == TopAbs_REVERSED)
1306 bReverse = Standard_True;
1308 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1310 const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1311 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1315 // Make the normal vector from the points
1316 gp_Vec aV(aVec.first, aVec.second);
1320 // Print values of the vector avoiding printing "-0" values
1321 theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", "
1322 << (aV.Y() == 0 ? 0 : aV.Y()) << ", "
1323 << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n";
1331 //=======================================================================
1334 //=======================================================================
1335 void DBRep::Set (const Standard_CString theName, const TopoDS_Shape& theShape)
1337 DBRep_Params& aParams = DBRep::Parameters();
1338 Handle(DBRep_DrawableShape) aDrawShape =
1339 new DBRep_DrawableShape (theShape, Draw_vert, Draw_jaune, Draw_rouge, Draw_bleu,
1340 aParams.Size, aParams.NbIsos, aParams.Discretization);
1341 aDrawShape->DisplayTriangulation (aParams.DispTriangles);
1342 aDrawShape->DisplayPolygons (aParams.DisplayPolygons);
1343 aDrawShape->DisplayHLR (aParams.WithHLR, aParams.WithRg1, aParams.WithRgN, aParams.WithHid, aParams.HLRAngle);
1344 Draw::Set (theName, aDrawShape);
1346 //=======================================================================
1347 //function : getShape
1349 //=======================================================================
1350 TopoDS_Shape DBRep::getShape (Standard_CString& theName,
1351 TopAbs_ShapeEnum theType,
1352 Standard_Boolean theToComplain)
1354 const Standard_Boolean toPick = theName[0] == '.';
1355 Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
1356 if (aDrawable.IsNull())
1358 return TopoDS_Shape();
1361 TopoDS_Shape aShape = aDrawable->Shape();
1362 if (theType != TopAbs_SHAPE
1363 && theType != aShape.ShapeType()
1366 // try to find prom pick
1368 DBRep_DrawableShape::LastPick (aShape, u, v);
1370 if (theType != TopAbs_SHAPE
1371 && theType != aShape.ShapeType())
1375 std::cout << theName << " is not a ";
1376 TopAbs::Print (theType, std::cout);
1377 std::cout << " but a ";
1378 TopAbs::Print (aShape.ShapeType(), std::cout);
1379 std::cout << std::endl;
1381 return TopoDS_Shape();
1386 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1388 for ( Standard_Integer i=1; i < argc; i++ )
1390 Standard_Boolean turn = Standard_True;
1391 if ( argv[i][0] == '-' ) turn = Standard_False;
1392 else if ( argv[i][0] != '+' ) continue;
1394 TCollection_AsciiString anArgCase (argv[i]);
1395 anArgCase.LowerCase();
1396 if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTclMode() = turn;
1397 else if (argv[i][1] == 'c') Draw_ProgressIndicator::DefaultConsoleMode() = turn;
1398 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1399 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
1401 Standard_Address aPtr = 0;
1402 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1403 Draw_ProgressIndicator::StopIndicator() = aPtr;
1407 di << "Progress Indicator defaults: tcl mode is ";
1408 if ( Draw_ProgressIndicator::DefaultTclMode() ) {
1413 di<<", console mode is ";
1414 if (Draw_ProgressIndicator::DefaultConsoleMode()) {
1420 di << ", graphical mode is ";
1421 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1430 //=======================================================================
1432 //=======================================================================
1433 static Standard_Integer writebrep (Draw_Interpretor& theDI,
1434 Standard_Integer theNbArgs,
1435 const char** theArgVec)
1437 Standard_Integer aVersion = -1;
1438 TCollection_AsciiString aShapeName, aFileName;
1439 TopoDS_Shape aShape;
1440 Standard_Boolean isBinaryFormat(Standard_False);
1441 Standard_Boolean isWithTriangles(Standard_True);
1442 Standard_Boolean isWithNormals(Standard_False);
1443 if (!strcasecmp (theArgVec[0], "binsave"))
1445 isBinaryFormat = Standard_True;
1448 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1450 TCollection_AsciiString aParam (theArgVec[anArgIter]);
1452 if (aParam == "-binary")
1454 isBinaryFormat = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
1456 else if (aParam == "-version"
1457 && anArgIter + 1 < theNbArgs)
1459 aVersion = Draw::Atoi (theArgVec[++anArgIter]);
1462 theDI << "Syntax error: unknown version";
1466 else if (aParam == "-notriangles"
1467 || aParam == "-triangles")
1469 isWithTriangles = Draw::ParseOnOffNoIterator (theNbArgs, theArgVec, anArgIter);
1471 else if (aParam == "-nonormals"
1472 || aParam == "-normals")
1474 isWithNormals = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
1475 if (aParam == "-nonormals")
1477 isWithNormals = !isWithNormals;
1480 else if (aShapeName.IsEmpty())
1482 aShapeName = theArgVec[anArgIter];
1483 aShape = DBRep::Get (aShapeName);
1484 if (aShape.IsNull())
1486 theDI << "Syntax error: " << aShapeName << " is not a shape";
1490 else if (aFileName.IsEmpty())
1492 aFileName = theArgVec[anArgIter];
1496 theDI << "Syntax error: unknown argument '" << aParam << "'";
1500 if (aFileName.IsEmpty())
1502 theDI << "Syntax error: wrong number of arguments";
1506 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
1509 if (aVersion > BinTools_FormatVersion_UPPER)
1511 theDI << "Syntax error: unknown format version";
1516 && aVersion < BinTools_FormatVersion_VERSION_4)
1518 theDI << "Error: vertex normals require binary format version 4 or later";
1522 BinTools_FormatVersion aBinToolsVersion = aVersion > 0
1523 ? static_cast<BinTools_FormatVersion> (aVersion)
1524 : BinTools_FormatVersion_CURRENT;
1525 if (!BinTools::Write (aShape, aFileName.ToCString(), isWithTriangles, isWithNormals, aBinToolsVersion, aProgress->Start()))
1527 theDI << "Cannot write to the file " << aFileName;
1533 if (aVersion > TopTools_FormatVersion_UPPER)
1535 theDI << "Syntax error: unknown format version";
1540 && aVersion < TopTools_FormatVersion_VERSION_3)
1542 theDI << "Error: vertex normals require ascii format version 3 or later";
1546 TopTools_FormatVersion aTopToolsVersion = aVersion > 0
1547 ? static_cast<TopTools_FormatVersion> (aVersion)
1548 : TopTools_FormatVersion_CURRENT;
1549 if (!BRepTools::Write (aShape, aFileName.ToCString(), isWithTriangles, isWithNormals, aTopToolsVersion, aProgress->Start()))
1551 theDI << "Cannot write to the file " << aFileName;
1555 theDI << aShapeName;
1559 //=======================================================================
1561 //=======================================================================
1562 static Standard_Integer readbrep (Draw_Interpretor& theDI,
1563 Standard_Integer theNbArgs,
1564 const char** theArgVec)
1568 theDI << "Syntax error: wrong number of arguments";
1572 Standard_CString aFileName = theArgVec[1];
1573 Standard_CString aShapeName = theArgVec[2];
1574 bool isBinaryFormat = true;
1576 // probe file header to recognize format
1577 const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
1578 std::shared_ptr<std::istream> aFile = aFileSystem->OpenIStream (aFileName, std::ios::in | std::ios::binary);
1579 if (aFile.get() == NULL)
1581 theDI << "Error: cannot read the file '" << aFileName << "'";
1585 char aStringBuf[255] = {};
1586 aFile->read (aStringBuf, 255);
1589 theDI << "Error: cannot read the file '" << aFileName << "'";
1592 isBinaryFormat = !(::strncmp (aStringBuf, "DBRep_DrawableShape", 19) == 0);
1595 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
1596 TopoDS_Shape aShape;
1599 if (!BinTools::Read (aShape, aFileName, aProgress->Start()))
1601 theDI << "Error: cannot read from the file '" << aFileName << "'";
1607 if (!BRepTools::Read (aShape, aFileName, BRep_Builder(), aProgress->Start()))
1609 theDI << "Error: cannot read from the file '" << aFileName << "'";
1614 DBRep::Set (aShapeName, aShape);
1615 theDI << aShapeName;
1619 //=======================================================================
1621 //=======================================================================
1622 static Standard_Integer removeInternals (Draw_Interpretor& di,
1628 di.PrintHelp (a[0]);
1632 TopoDS_Shape aShape = DBRep::Get (a[1]);
1633 if (aShape.IsNull())
1635 di << a[1] << "is a null shape\n";
1639 Standard_Boolean isForce = Standard_False;
1642 isForce = (Draw::Atoi (a[2]) != 0);
1645 BRepTools::RemoveInternals (aShape, isForce);
1647 DBRep::Set (a[1], aShape);
1652 //=======================================================================
1653 //function : BasicCommands
1655 //=======================================================================
1657 static Standard_Boolean done = Standard_False;
1658 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1661 done = Standard_True;
1662 Draw::Commands(theCommands);
1664 // Register save/restore tools
1665 DBRep_DrawableShape::RegisterFactory();
1667 const char* g = "Basic shape commands";
1669 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1670 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1671 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1672 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1673 theCommands.Add("tclean", "tclean [-force] [-geom] [name1]..., depending on using or not key -geom, \n"
1674 "\t\t -geom : erase geometry\n"
1675 "\t\t if [-geom] is omitted - erase triangulations and \n"
1676 "\t\t polygons on triangulations from shapes \n"
1677 "\t\t -force : force delete all representations not relevant to the given shape \n",
1678 __FILE__, tclean, g);
1679 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1680 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1681 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1682 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1683 theCommands.Add("add",
1685 "\n adds shape \"what\" to shape \"where\" ",
1687 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1688 theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1689 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1690 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1691 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1693 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1694 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1695 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1696 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1697 theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g);
1698 theCommands.Add("nbshapes",
1699 "\n nbshapes s - shows the number of sub-shapes in <s>;\n nbshapes s -t - shows the number of sub-shapes in <s> counting the same sub-shapes with different location as different sub-shapes.",
1700 __FILE__,nbshapes,g);
1701 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1702 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1703 theCommands.Add("setflags",
1704 "setflags shape_name flag1[flag2...]\n sets flags for shape(free, modified, checked, orientable, closed, infinite, convex, locked), for example <setflags a free> or <setflags a -free> if necessary unflag ",
1705 __FILE__,setFlags,g);
1707 theCommands.Add("purgemmgt",
1708 "returns the free memory from the system to the memory manager",
1709 __FILE__,purgemmgt,g);
1711 // Add command for DRAW-specific ProgressIndicator
1712 theCommands.Add ( "XProgress",
1713 "XProgress [+|-t] [+|-c] [+|-g]"
1714 "\n\t\t The options are:"
1715 "\n\t\t +|-t : switch on/off output to tcl of Progress Indicator"
1716 "\n\t\t +|-c : switch on/off output to cout of Progress Indicator"
1717 "\n\t\t +|-g : switch on/off graphical mode of Progress Indicator",
1718 __FILE__, XProgress,"DE: General");
1719 theCommands.Add("writebrep",
1720 "writebrep shape filename [-binary {0|1}]=0 [-version Version]=4"
1721 "\n\t\t: [-triangles {0|1}]=1 [-normals {0|1}]=0"
1722 "\n\t\t: Save the shape in the ASCII (default) or binary format file."
1723 "\n\t\t: -binary write into the binary format (ASCII when unspecified)"
1724 "\n\t\t: -version a number of format version to save;"
1725 "\n\t\t: ASCII versions: 1, 2 and 3 (3 for ASCII when unspecified);"
1726 "\n\t\t: Binary versions: 1, 2, 3 and 4 (4 for Binary when unspecified)."
1727 "\n\t\t: -triangles write triangulation data (TRUE when unspecified)."
1728 "\n\t\t: Ignored (always written) if face defines only triangulation (no surface)."
1729 "\n\t\t: -normals include vertex normals while writing triangulation data (FALSE when unspecified).",
1730 __FILE__, writebrep, g);
1731 theCommands.Add("readbrep",
1732 "readbrep filename shape"
1733 "\n\t\t: Restore the shape from the binary or ASCII format file.",
1734 __FILE__, readbrep, g);
1735 theCommands.Add("binsave", "binsave shape filename", __FILE__, writebrep, g);
1736 theCommands.Add("binrestore",
1737 "alias to readbrep command",
1738 __FILE__, readbrep, g);
1740 theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
1741 "\n\t\t Removes sub-shapes with internal orientation from the shape.\n"
1742 "\n\t\t Force flag disables the check on topological connectivity and"
1743 "removes all internal sub-shapes\n",
1744 __FILE__, removeInternals, g);