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.
17 #include <BinTools_ShapeSet.hxx>
18 #include <BRep_TEdge.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <BRepGProp.hxx>
21 #include <BRepTools.hxx>
22 #include <BRepTools_ShapeSet.hxx>
23 #include <BRepTools_WireExplorer.hxx>
24 #include <BinTools.hxx>
26 #include <DBRep_DrawableShape.hxx>
28 #include <Draw_Appli.hxx>
29 #include <Draw_ProgressIndicator.hxx>
30 #include <Message_ProgressRange.hxx>
31 #include <Draw_Segment3D.hxx>
34 #include <GProp_GProps.hxx>
35 #include <NCollection_Vector.hxx>
36 #include <OSD_OpenFile.hxx>
37 #include <Poly_Triangulation.hxx>
38 #include <Precision.hxx>
39 #include <Standard.hxx>
40 #include <TColStd_Array1OfInteger.hxx>
41 #include <TColStd_Array1OfReal.hxx>
44 #include <TopExp_Explorer.hxx>
46 #include <TopoDS_Compound.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopTools_Array1OfShape.hxx>
50 #include <TopTools_ListOfShape.hxx>
51 #include <TopTools_MapOfShape.hxx>
56 extern Draw_Viewer dout;
59 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
60 #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg]))
63 //==========================================
65 //==========================================
67 Standard_EXPORT void DBRep_WriteColorOrientation ()
69 std::cout << "\nrouge FORWARD";
70 std::cout << "\nbleu REVERSED";
71 std::cout << "\nrose EXTERNAL";
72 std::cout << "\norange INTERNAL"<<std::endl;
75 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or)
84 case TopAbs_REVERSED :
88 case TopAbs_EXTERNAL :
92 case TopAbs_INTERNAL :
100 //==========================================
102 //==========================================
104 static Standard_Integer nbIsos = 2;
105 static Standard_Real size = 100.;
106 static Standard_Integer discret = 30;
107 static Standard_Boolean disptriangles = Standard_False;
108 static Standard_Boolean disppolygons = Standard_False;
109 static Standard_Real anglHLR = 35 * M_PI / 180;
110 static Standard_Real HAngMin = 1 * M_PI / 180;
111 static Standard_Real HAngMax = 35 * M_PI / 180;
112 static Standard_Boolean withHLR = Standard_False;
113 static Standard_Boolean withRg1 = Standard_True;
114 static Standard_Boolean withRgN = Standard_False;
115 static Standard_Boolean withHid = Standard_False;
117 //=======================================================================
119 //=======================================================================
121 static Standard_Integer isos (Draw_Interpretor& di,
122 Standard_Integer NbArg, const char **Arg)
127 di << "Current number of isos : " << nbIsos << "\n" ;
131 Standard_Integer NbIsos = 0 ;
132 Standard_Boolean Change = Standard_False ;
133 if (!Characters (NbArg) && Float (NbArg)) return 1 ;
134 if (!Characters (NbArg)) {
135 NbIsos = Draw::Atoi (Arg[NbArg]) ;
137 Change = Standard_True ;
142 di << "New current number of isos : " << nbIsos << "\n" ;
144 for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) {
145 Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
146 if (!Shape1.IsNull()) {
147 Handle (DBRep_DrawableShape) Shape2 =
148 Handle (DBRep_DrawableShape)::DownCast (Shape1) ;
149 if (!Shape2.IsNull()) {
151 Shape2->ChangeNbIsos (NbIsos) ;
153 di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
158 if (Change) dout.RepaintAll() ;
164 //=======================================================================
166 //=======================================================================
168 static Standard_Integer hlr (Draw_Interpretor& di,
169 Standard_Integer n, const char **a)
174 if (withRgN) di << " RgNLines";
176 if (withRg1) di << " Rg1Lines";
177 else di << " no RegLines";
179 if (withHid) di << " HiddenLines";
180 else di << " no HiddenLines";
183 di << "Angle of discretization : ";
184 di << anglHLR * 180 / M_PI << " degrees\n";
187 else di << " wireframe";
193 if (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False;
194 else if (!strcasecmp(a[1],"hlr" )) withHLR = Standard_True;
195 else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False;
196 else if (!strcasecmp(a[1],"hid" )) {
197 withHLR = Standard_True;
198 withHid = Standard_True;
200 else if (!strcasecmp(a[1],"norg1")) {
201 withRg1 = Standard_False;
202 withRgN = Standard_False;
204 else if (!strcasecmp(a[1],"rg1" )) {
205 withHLR = Standard_True;
206 withRg1 = Standard_True;
207 withRgN = Standard_False;
209 else if (!strcasecmp(a[1],"norgn")) {
210 withRgN = Standard_False;
212 else if (!strcasecmp(a[1],"rgn" )) {
213 withHLR = Standard_True;
214 withRg1 = Standard_True;
215 withRgN = Standard_True;
217 else if (!strcasecmp(a[1],"ang" )) {
218 di << "Angle de discretisation : ";
219 di << anglHLR * 180 / M_PI << " degres\n";
224 Standard_Integer nFirst = 2;
226 if (n >= 3 && !strcasecmp(a[1],"ang" )) {
229 Standard_Real ang = Draw::Atof(a[2]);
230 anglHLR = ang * M_PI / 180;
231 if (anglHLR < HAngMin) anglHLR = HAngMin;
232 if (anglHLR > HAngMax) anglHLR = HAngMax;
234 di << "Angle of discretization : ";
235 di << anglHLR * 180 / M_PI << " degrees\n";
238 if (n >= nFirst + 1) {
240 for (Standard_Integer i = nFirst ; i < n; i++) {
241 Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ;
243 Handle (DBRep_DrawableShape) S =
244 Handle (DBRep_DrawableShape)::DownCast (D) ;
246 Standard_Boolean localHLR, localRg1, localRgN, localHid;
247 Standard_Real localAng;
248 S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid,
250 if (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False;
251 else if (!strcasecmp(a[1],"hlr" )) localHLR = Standard_True;
252 else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False;
253 else if (!strcasecmp(a[1],"hid" )) {
254 localHLR = Standard_True;
255 localHid = Standard_True;
257 else if (!strcasecmp(a[1],"norg1")) {
258 localRg1 = Standard_False;
259 localRgN = Standard_False;
261 else if (!strcasecmp(a[1],"rg1" )) {
262 localHLR = Standard_True;
263 localRg1 = Standard_True;
264 localRgN = Standard_False;
266 else if (!strcasecmp(a[1],"norgn")) {
267 localRgN = Standard_False;
269 else if (!strcasecmp(a[1],"rgn" )) {
270 localHLR = Standard_True;
271 localRg1 = Standard_True;
272 localRgN = Standard_True;
274 else if (!strcasecmp(a[1],"ang" )) {
275 Standard_Real ang = Draw::Atof(a[2]);
276 localAng = ang * M_PI / 180;
279 S->DisplayHLR(localHLR, localRg1, localRgN, localHid,
291 //=======================================================================
293 //=======================================================================
295 static Standard_Integer dispor (Draw_Interpretor& ,
296 Standard_Integer n, const char** a)
298 Standard_Boolean d = !strcasecmp(a[0],"vori");
301 DBRep_WriteColorOrientation();
304 for (i = 1; i < n; i++) {
305 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
307 Handle(DBRep_DrawableShape) d2 =
308 Handle(DBRep_DrawableShape)::DownCast(d1);
310 d2->DisplayOrientation(d);
318 //=======================================================================
320 //=======================================================================
322 static Standard_Integer discretisation(Draw_Interpretor& di,
323 Standard_Integer n, const char** a)
326 di << "Current number of points : "<<discret<<"\n";
328 discret = Draw::Atoi(a[1]);
334 //=======================================================================
336 //=======================================================================
338 static Standard_Integer triangles(Draw_Interpretor& ,
339 Standard_Integer n, const char** a)
344 disptriangles = !disptriangles;
346 if (disptriangles) std::cout <<"Triangulations are always displayed"<<std::endl;
347 else std::cout <<"Triangulations are displayed only if there is no geometric representation"<<std::endl;
352 for (i = 1; i <= n-1; i++) {
353 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
355 Handle(DBRep_DrawableShape) d2 =
356 Handle(DBRep_DrawableShape)::DownCast(d1);
358 d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
368 //=======================================================================
370 //=======================================================================
372 static Standard_Integer tclean(Draw_Interpretor& ,
373 Standard_Integer n, const char** a)
375 if (n == 1) return 1;
377 Standard_Integer aStart = 1;
378 Standard_Boolean toRemoveGeometry = Standard_False;
379 if (strcmp(a[1], "-geom") == 0)
382 toRemoveGeometry = Standard_True;
385 for (Standard_Integer i = aStart; i < n; i++) {
386 TopoDS_Shape S = DBRep::Get(a[i]);
387 if (toRemoveGeometry)
388 BRepTools::CleanGeometry(S);
395 //=======================================================================
397 //=======================================================================
399 static Standard_Integer polygons(Draw_Interpretor& ,
400 Standard_Integer n, const char** a)
405 disppolygons = !disppolygons;
407 if (disppolygons) std::cout <<"Polygons are always displayed"<<std::endl;
408 else std::cout <<"Polygons are displayed only if there is no geometric representation"<<std::endl;
413 for (i = 1; i <= n-1; i++) {
414 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
416 Handle(DBRep_DrawableShape) d2 =
417 Handle(DBRep_DrawableShape)::DownCast(d1);
419 d2->DisplayPolygons(!(d2->DisplayPolygons()));
430 //=======================================================================
432 //=======================================================================
434 static Standard_Integer compound(Draw_Interpretor& ,
435 Standard_Integer n, const char** a)
437 if (n <= 1) return 1;
441 for (Standard_Integer i = 1; i < n-1; i++) {
442 TopoDS_Shape S2 = DBRep::Get(a[i]);
443 if (!S2.IsNull()) B.Add(C,S2);
445 DBRep::Set(a[n-1],C);
449 //=======================================================================
451 //=======================================================================
453 static Standard_Integer emptycopy(Draw_Interpretor& ,
454 Standard_Integer n, const char** a)
456 if (n <= 1) return 1;
457 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
458 if (S.IsNull()) return 1;
464 //=======================================================================
466 //=======================================================================
468 static Standard_Integer add(Draw_Interpretor& ,
469 Standard_Integer n, const char** a)
473 TopoDS_Shape S1 = DBRep::Get(a[1]);
474 if (S1.IsNull()) return 1;
475 TopoDS_Shape S2 = DBRep::Get(a[2]);
476 if (S2.IsNull()) return 1;
482 //=======================================================================
484 //=======================================================================
486 static Standard_Integer explode(Draw_Interpretor& di,
487 Standard_Integer n, const char** a)
489 if (n <= 1) return 1;
490 TopoDS_Shape S = DBRep::Get(a[1]);
491 if (S.IsNull()) return 0;
493 strcpy(newname,a[1]);
495 while (*p != '\0') p++;
498 Standard_Integer i = 0;
500 TopoDS_Iterator itr(S);
504 DBRep::Set(newname,itr.Value());
505 di.AppendElement(newname);
511 TopAbs_ShapeEnum typ;
516 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
517 typ = TopAbs_COMPOUND;
519 typ = TopAbs_COMPSOLID;
524 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
526 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
556 TopTools_MapOfShape M;
558 TopExp_Explorer ex(S,typ);
559 for (; ex.More(); ex.Next()) {
560 const TopoDS_Shape& Sx = ex.Current();
561 Standard_Boolean added = M.Add(Sx);
565 DBRep::Set(newname,Sx);
566 di.AppendElement(newname);
573 //=======================================================================
574 // nexplode : stable numbered explode (from Serguey Nizhny)
575 //=======================================================================
577 static Standard_Integer nexplode(Draw_Interpretor& di,
578 Standard_Integer n, const char** a)
580 if (n <= 2) return 1;
581 TopoDS_Shape S = DBRep::Get(a[1]);
582 if (S.IsNull()) return 0;
584 strcpy(newname,a[1]);
586 while (*p != '\0') p++;
589 TopAbs_ShapeEnum typ;
610 TopTools_IndexedMapOfShape IMOStmp;
611 TopTools_MapOfShape MShape;
613 TopExp::MapShapes(S,typ,IMOStmp);
614 TopExp_Explorer Exp(S,typ);
615 Standard_Integer MaxShapes, Index = 0;
616 MaxShapes = IMOStmp.Extent()-1;
617 TopTools_Array1OfShape aShapes(1,MaxShapes);
621 if (MShape.Add(Exp.Current())) {
623 aShapes.SetValue(Index,Exp.Current());
628 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
631 Standard_Integer aTemp;
632 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
633 Standard_Boolean NoSort = Standard_True;
635 // Computing of CentreOfMass for edge and face
636 // and for vertex use its point
637 for (Index=1; Index <= MaxShapes; Index++) {
638 OrderInd.SetValue(Index,Index);
639 const TopoDS_Shape& aS = aShapes(Index);
640 if (aS.ShapeType() != TopAbs_VERTEX) {
641 BRepGProp::LinearProperties(aS, GPr);
642 GPoint = GPr.CentreOfMass();
645 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
647 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
652 NoSort = Standard_False;
653 for (Index=1; Index < MaxShapes; Index++) {
654 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
655 aTemp = OrderInd(Index);
656 OrderInd(Index) = OrderInd(Index+1);
657 OrderInd(Index+1) = aTemp;
658 NoSort = Standard_True;
662 // Check of equality of MidXYZ
663 for (Index=1; Index < MaxShapes; Index++) {
664 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
665 di<<"Warning! For this shape the results may be incorrect.\n";
668 for (Index=1 ;Index <= MaxShapes; Index++) {
669 Sprintf(p,"%d",Index);
670 DBRep::Set(newname,aShapes(OrderInd(Index)));
671 di.AppendElement(newname);
677 //=======================================================================
679 //=======================================================================
681 static Standard_Integer exwire(Draw_Interpretor& ,
682 Standard_Integer n, const char** a)
684 if (n <= 1) return 1;
685 TopoDS_Shape S = DBRep::Get(a[1]);
686 if (S.IsNull()) return 0;
687 if (S.ShapeType() != TopAbs_WIRE) return 0;
689 strcpy(newname,a[1]);
691 while (*p != '\0') p++;
694 Standard_Integer i = 0;
695 BRepTools_WireExplorer ex(TopoDS::Wire(S));
699 DBRep::Set(newname,ex.Current());
705 //=======================================================================
707 //=======================================================================
709 static Standard_Integer invert(Draw_Interpretor& ,
710 Standard_Integer n, const char** a)
712 if (n <= 1) return 1;
713 TopoDS_Shape S = DBRep::Get(a[1]);
714 if (S.IsNull()) return 0;
717 TopoDS_Shape NS = S.EmptyCopied();
718 NS.Closed (S.Closed());
720 TopoDS_Iterator itr(S);
722 B.Add(NS,itr.Value().Reversed());
730 //=======================================================================
731 // orientation, reverse, complement
732 //=======================================================================
734 static Standard_Integer orientation(Draw_Interpretor& ,
735 Standard_Integer n, const char** a)
737 if (n <= 1) return 1;
738 Standard_Integer cas = 0;
739 TopAbs_Orientation ori=TopAbs_FORWARD;
740 Standard_Integer last = n;
741 if (!strcasecmp(a[0],"orientation")) {
742 if (n <= 2) return 1;
747 ori = TopAbs_FORWARD;
751 ori = TopAbs_REVERSED;
755 ori = TopAbs_INTERNAL;
759 ori = TopAbs_EXTERNAL;
764 else if (!strcasecmp(a[0],"treverse")) {
768 else if (!strcasecmp(a[0],"complement")) {
772 for (Standard_Integer i = 1; i < last; i++) {
773 TopoDS_Shape S = DBRep::Get(a[i]);
787 #include <TCollection_AsciiString.hxx>
789 //=======================================================================
790 // numshapes same as nbshapes but the output is cout
791 //=======================================================================
793 static Standard_Integer numshapes(Draw_Interpretor& di,
794 Standard_Integer n, const char** a)
800 for (i = 1; i < n; i++) {
801 TopoDS_Shape S = DBRep::Get(a[i]);
803 BRepTools_ShapeSet BS;
805 di <<"Number of shapes in "<<a[i]<<"\n";
806 TCollection_AsciiString Astr;
808 di <<Astr.ToCString();
816 //=======================================================================
817 // function : DumpExtent
818 // purpose : Dumps the number of sub-shapes in <aStr>.
819 //=======================================================================
820 static void DumpExtent(const TopoDS_Shape& aS,
821 TCollection_AsciiString& aStr)
823 const int aNbTypes=8;
824 const char *pNames[aNbTypes+1]={
835 Standard_Integer i, aNb, aNbSh;
836 TopAbs_ShapeEnum aType;
837 TopTools_IndexedMapOfShape aM;
841 for (i=aNbTypes-1; i>=0; --i) {
843 aType=(TopAbs_ShapeEnum)i;
844 TopExp::MapShapes(aS, aType, aM);
846 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
849 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
852 //=======================================================================
854 //=======================================================================
856 static Standard_Integer nbshapes(Draw_Interpretor& di,
857 Standard_Integer n, const char** a)
862 Standard_Boolean aTotal;
865 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
867 for (i = 1; i < n; i++) {
868 TopoDS_Shape S = DBRep::Get(a[i]);
870 di<<"Number of shapes in "<<a[i]<<"\n";
871 TCollection_AsciiString Astr;
875 BRepTools_ShapeSet BS;
879 di<<Astr.ToCString();
886 //=======================================================================
888 //=======================================================================
890 static Standard_Integer countshapes(Draw_Interpretor& di,
891 Standard_Integer n, const char** a)
897 for (i = 1; i < n; i++) {
898 TopoDS_Shape Sh = DBRep::Get(a[i]);
899 Standard_Integer nbElem = 0;
901 di <<"Number of shapes in "<<a[i]<<"\n";
902 TopTools_MapOfShape M;
904 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
905 const TopoDS_Shape& S = ex.Current();
906 Standard_Boolean added = M.Add(S);
911 di << " VERTEX : " << nbElem << "\n";
914 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
915 const TopoDS_Shape& S = ex.Current();
916 Standard_Boolean added = M.Add(S);
921 di << " EDGE : " << nbElem << "\n";
924 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
925 const TopoDS_Shape& S = ex.Current();
926 Standard_Boolean added = M.Add(S);
931 di << " WIRE : " << nbElem << "\n";
934 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
935 const TopoDS_Shape& S = ex.Current();
936 Standard_Boolean added = M.Add(S);
941 di << " FACE : " << nbElem << "\n";
944 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
945 const TopoDS_Shape& S = ex.Current();
946 Standard_Boolean added = M.Add(S);
951 di << " SHELL : " << nbElem << "\n";
954 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
955 const TopoDS_Shape& S = ex.Current();
956 Standard_Boolean added = M.Add(S);
961 di << " SOLID : " << nbElem << "\n";
964 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
965 const TopoDS_Shape& S = ex.Current();
966 Standard_Boolean added = M.Add(S);
971 di << " COMPSOLID : " << nbElem << "\n";
974 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
975 const TopoDS_Shape& S = ex.Current();
976 Standard_Boolean added = M.Add(S);
981 di << " COMPOUND : " << nbElem << "\n";
984 di << " SHAPE : " << M.Extent() << "\n";
992 //=======================================================================
994 //=======================================================================
995 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
998 for(i = 2; i < n; i++) {
999 if (strstr ( a[i], "free" )) {
1000 if(a[i][0] == '-') {
1001 Sh.Free(Standard_False);
1004 Sh.Free(Standard_True);
1007 if (strstr ( a[i], "modified" )) {
1008 if(a[i][0] == '-') {
1009 Sh.Modified(Standard_False);
1012 Sh.Modified(Standard_True);
1015 if (strstr ( a[i], "checked" )) {
1016 if(a[i][0] == '-') {
1017 Sh.Checked(Standard_False);
1020 Sh.Checked(Standard_True);
1023 if (strstr ( a[i], "orientable" )) {
1024 if(a[i][0] == '-') {
1025 Sh.Orientable(Standard_False);
1028 Sh.Orientable(Standard_True);
1031 if (strstr ( a[i], "closed" )) {
1032 if(a[i][0] == '-') {
1033 Sh.Closed(Standard_False);
1036 Sh.Closed(Standard_True);
1039 if (strstr ( a[i], "infinite" )) {
1040 if(a[i][0] == '-') {
1041 Sh.Infinite(Standard_False);
1044 Sh.Infinite(Standard_True);
1047 if (strstr ( a[i], "convex" )) {
1048 if(a[i][0] == '-') {
1049 Sh.Convex(Standard_False);
1052 Sh.Convex(Standard_True);
1055 if (strstr ( a[i], "locked" )) {
1056 if(a[i][0] == '-') {
1057 Sh.Locked(Standard_False);
1060 Sh.Locked(Standard_True);
1066 //=======================================================================
1068 //=======================================================================
1069 static Standard_Integer setFlags(Draw_Interpretor& ,
1070 Standard_Integer n, const char** a)
1072 if (n < 3) return 1;
1075 TopoDS_Shape Sh = DBRep::Get(a[1]);
1077 if (Sh.IsNull()) return 1;
1080 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1081 TopoDS_Shape S = ex.Current();
1085 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1086 TopoDS_Shape S = ex.Current();
1090 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1091 TopoDS_Shape S = ex.Current();
1098 //=======================================================================
1100 //=======================================================================
1101 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1105 //=======================================================================
1107 //=======================================================================
1109 //=======================================================================
1111 static Standard_Integer check(Draw_Interpretor& ,
1112 Standard_Integer n, const char** a)
1114 if (n < 2) return 1;
1118 for (i = 1; i < n; i++) {
1119 TopoDS_Shape S = DBRep::Get(a[i]);
1121 if (S.IsNull()) continue;
1122 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1124 C.Checked(Standard_False);
1125 BRepTools::Update(C);
1132 //=======================================================================
1134 //=======================================================================
1135 static Standard_Integer normals (Draw_Interpretor& theDI,
1136 Standard_Integer theArgNum,
1137 const char** theArgs)
1141 std::cout << "Syntax error: wrong number of arguments!\n";
1142 theDI.PrintHelp (theArgs[0]);
1146 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1147 if (aShape.IsNull())
1149 std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1153 Standard_Boolean toUseMesh = Standard_False;
1154 Standard_Real aLength = 10.0;
1155 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1156 Standard_Boolean bPrint = Standard_False;
1157 for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1159 TCollection_AsciiString aParam (theArgs[anArgIter]);
1162 && aParam.IsRealValue())
1164 aLength = aParam.RealValue();
1165 if (Abs (aLength) <= gp::Resolution())
1167 std::cout << "Syntax error: length should not be zero\n";
1171 else if (aParam == "-usemesh"
1172 || aParam == "-mesh")
1174 toUseMesh = Standard_True;
1176 else if (aParam == "-length"
1177 || aParam == "-len")
1180 aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1181 if (Abs(aLength) <= gp::Resolution())
1183 std::cout << "Syntax error: length should not be zero\n";
1187 else if (aParam == "-nbalongu"
1188 || aParam == "-nbu")
1191 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1194 std::cout << "Syntax error: NbAlongU should be >=1\n";
1198 else if (aParam == "-nbalongv"
1199 || aParam == "-nbv")
1202 aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1205 std::cout << "Syntax error: NbAlongV should be >=1\n";
1209 else if (aParam == "-nbalong"
1210 || aParam == "-nbuv")
1213 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1214 aNbAlongV = aNbAlongU;
1217 std::cout << "Syntax error: NbAlong should be >=1\n";
1221 else if (aParam == "-print")
1223 bPrint = Standard_True;
1227 std::cout << "Syntax error: unknown argument '" << aParam << "'\n";
1232 DBRep_WriteColorOrientation();
1234 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1237 DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1241 DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1244 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1246 Standard_Boolean bReverse = Standard_False;
1247 TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation();
1248 const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri);
1249 if (aFaceOri == TopAbs_REVERSED)
1250 bReverse = Standard_True;
1252 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1254 const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1255 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1259 // Make the normal vector from the points
1260 gp_Vec aV(aVec.first, aVec.second);
1264 // Print values of the vector avoiding printing "-0" values
1265 theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", "
1266 << (aV.Y() == 0 ? 0 : aV.Y()) << ", "
1267 << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n";
1275 //=======================================================================
1278 //=======================================================================
1279 void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1281 Handle(DBRep_DrawableShape) D =
1282 new DBRep_DrawableShape(S,
1290 D->DisplayTriangulation(disptriangles);
1291 D->DisplayPolygons(disppolygons);
1292 D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1295 //=======================================================================
1296 //function : getShape
1298 //=======================================================================
1299 TopoDS_Shape DBRep::getShape (Standard_CString& theName,
1300 TopAbs_ShapeEnum theType,
1301 Standard_Boolean theToComplain)
1303 const Standard_Boolean toPick = theName[0] == '.';
1304 Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
1305 if (aDrawable.IsNull())
1307 return TopoDS_Shape();
1310 TopoDS_Shape aShape = aDrawable->Shape();
1311 if (theType != TopAbs_SHAPE
1312 && theType != aShape.ShapeType()
1315 // try to find prom pick
1317 DBRep_DrawableShape::LastPick (aShape, u, v);
1319 if (theType != TopAbs_SHAPE
1320 && theType != aShape.ShapeType())
1324 std::cout << theName << " is not a ";
1325 TopAbs::Print (theType, std::cout);
1326 std::cout << " but a ";
1327 TopAbs::Print (aShape.ShapeType(), std::cout);
1328 std::cout << std::endl;
1330 return TopoDS_Shape();
1335 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1337 for ( Standard_Integer i=1; i < argc; i++ )
1339 Standard_Boolean turn = Standard_True;
1340 if ( argv[i][0] == '-' ) turn = Standard_False;
1341 else if ( argv[i][0] != '+' ) continue;
1343 TCollection_AsciiString anArgCase (argv[i]);
1344 anArgCase.LowerCase();
1345 if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTclMode() = turn;
1346 else if (argv[i][1] == 'c') Draw_ProgressIndicator::DefaultConsoleMode() = turn;
1347 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1348 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
1350 Standard_Address aPtr = 0;
1351 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1352 Draw_ProgressIndicator::StopIndicator() = aPtr;
1356 di << "Progress Indicator defaults: tcl mode is ";
1357 if ( Draw_ProgressIndicator::DefaultTclMode() ) {
1362 di<<", console mode is ";
1363 if (Draw_ProgressIndicator::DefaultConsoleMode()) {
1369 di << ", graphical mode is ";
1370 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1379 //=======================================================================
1381 //=======================================================================
1382 static Standard_Integer writebrep (Draw_Interpretor& theDI,
1383 Standard_Integer theNbArgs,
1384 const char** theArgVec)
1386 Standard_Integer aVersion = -1;
1387 TCollection_AsciiString aShapeName, aFileName;
1388 TopoDS_Shape aShape;
1389 bool isBinaryFormat = false, isWithTriangles = true;
1390 if (!strcasecmp (theArgVec[0], "binsave"))
1392 isBinaryFormat = true;
1395 for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
1397 TCollection_AsciiString aParam (theArgVec[anArgIter]);
1399 if (aParam == "-binary")
1401 isBinaryFormat = true;
1402 if (anArgIter + 1 < theNbArgs
1403 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isBinaryFormat))
1408 else if (aParam == "-version"
1409 && anArgIter + 1 < theNbArgs)
1411 aVersion = Draw::Atoi (theArgVec[++anArgIter]);
1414 theDI << "Syntax error: unknown version";
1418 else if (aParam == "-notriangles"
1419 || aParam == "-triangles")
1421 isWithTriangles = true;
1422 if (anArgIter + 1 < theNbArgs
1423 && Draw::ParseOnOff (theArgVec[anArgIter + 1], isWithTriangles))
1427 if (aParam == "-notriangles")
1429 isWithTriangles = !isWithTriangles;
1432 else if (aShapeName.IsEmpty())
1434 aShapeName = theArgVec[anArgIter];
1435 aShape = DBRep::Get (aShapeName);
1436 if (aShape.IsNull())
1438 theDI << "Syntax error: " << aShapeName << " is not a shape";
1442 else if (aFileName.IsEmpty())
1444 aFileName = theArgVec[anArgIter];
1448 theDI << "Syntax error: unknown argument '" << aParam << "'";
1452 if (aFileName.IsEmpty())
1454 theDI << "Syntax error: wrong number of arguments";
1458 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
1461 if (aVersion > BinTools_FormatVersion_VERSION_3)
1463 theDI << "Syntax error: unknown format version";
1467 BinTools_FormatVersion aBinToolsVersion = aVersion > 0
1468 ? static_cast<BinTools_FormatVersion> (aVersion)
1469 : BinTools_FormatVersion_CURRENT;
1470 if (!BinTools::Write (aShape, aFileName.ToCString(), isWithTriangles, aBinToolsVersion, aProgress->Start()))
1472 theDI << "Cannot write to the file " << aFileName;
1478 if (aVersion > TopTools_FormatVersion_VERSION_2)
1480 theDI << "Syntax error: unknown format version";
1484 TopTools_FormatVersion aTopToolsVersion = aVersion > 0
1485 ? static_cast<TopTools_FormatVersion> (aVersion)
1486 : TopTools_FormatVersion_CURRENT;
1487 if (!BRepTools::Write (aShape, aFileName.ToCString(), isWithTriangles, aTopToolsVersion, aProgress->Start()))
1489 theDI << "Cannot write to the file " << aFileName;
1493 theDI << aShapeName;
1497 //=======================================================================
1499 //=======================================================================
1500 static Standard_Integer readbrep (Draw_Interpretor& theDI,
1501 Standard_Integer theNbArgs,
1502 const char** theArgVec)
1506 theDI << "Syntax error: wrong number of arguments";
1510 Standard_CString aFileName = theArgVec[1];
1511 Standard_CString aShapeName = theArgVec[2];
1512 bool isBinaryFormat = true;
1514 // probe file header to recognize format
1515 std::ifstream aFile;
1516 OSD_OpenStream (aFile, aFileName, std::ios::in | std::ios::binary);
1517 if (!aFile.is_open())
1519 theDI << "Error: cannot read the file '" << aFileName << "'";
1523 char aStringBuf[255] = {};
1524 aFile.read (aStringBuf, 255);
1527 theDI << "Error: cannot read the file '" << aFileName << "'";
1530 isBinaryFormat = !(::strncmp (aStringBuf, "DBRep_DrawableShape", 19) == 0);
1533 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI);
1534 TopoDS_Shape aShape;
1537 if (!BinTools::Read (aShape, aFileName, aProgress->Start()))
1539 theDI << "Error: cannot read from the file '" << aFileName << "'";
1545 if (!BRepTools::Read (aShape, aFileName, BRep_Builder(), aProgress->Start()))
1547 theDI << "Error: cannot read from the file '" << aFileName << "'";
1552 DBRep::Set (aShapeName, aShape);
1553 theDI << aShapeName;
1557 //=======================================================================
1559 //=======================================================================
1560 static Standard_Integer removeInternals (Draw_Interpretor& di,
1566 di.PrintHelp (a[0]);
1570 TopoDS_Shape aShape = DBRep::Get (a[1]);
1571 if (aShape.IsNull())
1573 di << a[1] << "is a null shape\n";
1577 Standard_Boolean isForce = Standard_False;
1580 isForce = (Draw::Atoi (a[2]) != 0);
1583 BRepTools::RemoveInternals (aShape, isForce);
1585 DBRep::Set (a[1], aShape);
1590 //=======================================================================
1591 //function : BasicCommands
1593 //=======================================================================
1595 static Standard_Boolean done = Standard_False;
1596 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1599 done = Standard_True;
1600 Draw::Commands(theCommands);
1602 const char* g = "Basic shape commands";
1604 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1605 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1606 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1607 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1608 theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n"
1609 "\t erase geometry objects from shapes - key is used or \n"
1610 "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n",
1611 __FILE__, tclean, g);
1612 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1613 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1614 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1615 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1616 theCommands.Add("add",
1618 "\n adds shape \"what\" to shape \"where\" ",
1620 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1621 theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1622 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1623 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1624 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1626 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1627 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1628 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1629 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1630 theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g);
1631 theCommands.Add("nbshapes",
1632 "\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.",
1633 __FILE__,nbshapes,g);
1634 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1635 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1636 theCommands.Add("setflags",
1637 "setflags shape_name flag1[flag2...]\n sets flags for shape(free, modidfied, checked, orientable, closed, infinite, convex, locked), for exmple <setflags a free> or <setflags a -free> if necessary unflag ",
1638 __FILE__,setFlags,g);
1640 // theCommands.Add("dumpmmgt",
1641 // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1642 theCommands.Add("purgemmgt",
1643 "returns the free memory from the system to the memory manager",
1644 __FILE__,purgemmgt,g);
1646 // Add command for DRAW-specific ProgressIndicator
1647 theCommands.Add ( "XProgress",
1648 "XProgress [+|-t] [+|-c] [+|-g]"
1649 "\n\t\t The options are:"
1650 "\n\t\t +|-t : switch on/off output to tcl of Progress Indicator"
1651 "\n\t\t +|-c : switch on/off output to cout of Progress Indicator"
1652 "\n\t\t +|-g : switch on/off graphical mode of Progress Indicator",
1653 XProgress,"DE: General");
1654 theCommands.Add("writebrep",
1655 "writebrep shape filename [-binary] [-version Version] [-noTriangles]"
1656 "\n\t\t: Save the shape in the ASCII (default) or binary format file."
1657 "\n\t\t: -binary write into the binary format (ASCII when unspecified)"
1658 "\n\t\t: -version a number of format version to save;"
1659 "\n\t\t: ASCII versions: 1, 2 (1 for ASCII when unspecified);"
1660 "\n\t\t: Binary versions: 1, 2 and 3 (1 for Binary when unspecified)."
1661 "\n\t\t: -noTriangles skip triangulation data (OFF when unspecified).",
1662 __FILE__, writebrep, g);
1663 theCommands.Add("readbrep",
1664 "readbrep filename shape"
1665 "\n\t\t: Restore the shape from the binary or ASCII format file.",
1666 __FILE__, readbrep, g);
1667 theCommands.Add("binsave", "binsave shape filename", __FILE__, writebrep, g);
1668 theCommands.Add("binrestore",
1669 "alias to readbrep command",
1670 __FILE__, readbrep, g);
1672 theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
1673 "\n\t\t Removes sub-shapes with internal orientation from the shape.\n"
1674 "\n\t\t Force flag disables the check on topological connectivity and"
1675 "removes all internal sub-shapes\n",
1676 __FILE__, removeInternals, g);
1679 //=======================================================================
1680 //function : HLRMode
1682 //=======================================================================
1684 Standard_Boolean DBRep::HLRMode()
1687 //=======================================================================
1688 //function : Rg1Mode
1690 //=======================================================================
1692 Standard_Boolean DBRep::Rg1Mode()
1695 //=======================================================================
1696 //function : RgNMode
1698 //=======================================================================
1700 Standard_Boolean DBRep::RgNMode()
1703 //=======================================================================
1704 //function : HidMode
1706 //=======================================================================
1708 Standard_Boolean DBRep::HidMode()
1711 //=======================================================================
1712 //function : HLRAngle
1714 //=======================================================================
1716 Standard_Real DBRep::HLRAngle()
1719 //=======================================================================
1721 //purpose : save and restore shapes
1722 //=======================================================================
1724 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
1726 return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1729 static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1731 Handle(DBRep_DrawableShape)
1732 N = Handle(DBRep_DrawableShape)::DownCast(d);
1734 BRepTools_ShapeSet S(B);
1736 Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1737 S.Write(OS, Message_ProgressIndicator::Start(aProgress));
1738 if (! aProgress.IsNull() && aProgress->UserBreak())
1740 S.Write(N->Shape(),OS);
1743 static Handle(Draw_Drawable3D) srestore (std::istream& IS)
1746 BRepTools_ShapeSet S(B);
1747 Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1748 S.Read(IS, Message_ProgressIndicator::Start(aProgress));
1749 Handle(DBRep_DrawableShape) N;
1750 if (! aProgress.IsNull() && aProgress->UserBreak())
1752 TopoDS_Shape theShape;
1753 S.Read(theShape,IS );
1754 N = new DBRep_DrawableShape(theShape,
1762 N->DisplayTriangulation(disptriangles);
1763 N->DisplayPolygons(disppolygons);
1764 N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1770 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1771 stest,ssave,srestore);
1774 void dumps (const TopoDS_Shape& S)
1776 BRepTools::Dump(S,std::cout);
1779 //=======================================================================
1782 //=======================================================================
1784 Standard_Integer DBRep::NbIsos()
1788 //=======================================================================
1789 //function : Discretisation
1791 //=======================================================================
1793 Standard_Integer DBRep::Discretisation()