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.
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 <Poly_Triangulation.hxx>
37 #include <Precision.hxx>
38 #include <Standard.hxx>
39 #include <TColStd_Array1OfInteger.hxx>
40 #include <TColStd_Array1OfReal.hxx>
43 #include <TopExp_Explorer.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopTools_Array1OfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
55 extern Draw_Viewer dout;
58 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
59 #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg]))
62 //==========================================
64 //==========================================
66 Standard_EXPORT void DBRep_WriteColorOrientation ()
68 std::cout << "\nrouge FORWARD";
69 std::cout << "\nbleu REVERSED";
70 std::cout << "\nrose EXTERNAL";
71 std::cout << "\norange INTERNAL"<<std::endl;
74 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or)
83 case TopAbs_REVERSED :
87 case TopAbs_EXTERNAL :
91 case TopAbs_INTERNAL :
99 //==========================================
101 //==========================================
103 static Standard_Integer nbIsos = 2;
104 static Standard_Real size = 100.;
105 static Standard_Integer discret = 30;
106 static Standard_Boolean disptriangles = Standard_False;
107 static Standard_Boolean disppolygons = Standard_False;
108 static Standard_Real anglHLR = 35 * M_PI / 180;
109 static Standard_Real HAngMin = 1 * M_PI / 180;
110 static Standard_Real HAngMax = 35 * M_PI / 180;
111 static Standard_Boolean withHLR = Standard_False;
112 static Standard_Boolean withRg1 = Standard_True;
113 static Standard_Boolean withRgN = Standard_False;
114 static Standard_Boolean withHid = Standard_False;
116 //=======================================================================
118 //=======================================================================
120 static Standard_Integer isos (Draw_Interpretor& di,
121 Standard_Integer NbArg, const char **Arg)
126 di << "Current number of isos : " << nbIsos << "\n" ;
130 Standard_Integer NbIsos = 0 ;
131 Standard_Boolean Change = Standard_False ;
132 if (!Characters (NbArg) && Float (NbArg)) return 1 ;
133 if (!Characters (NbArg)) {
134 NbIsos = Draw::Atoi (Arg[NbArg]) ;
136 Change = Standard_True ;
141 di << "New current number of isos : " << nbIsos << "\n" ;
143 for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) {
144 Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
145 if (!Shape1.IsNull()) {
146 Handle (DBRep_DrawableShape) Shape2 =
147 Handle (DBRep_DrawableShape)::DownCast (Shape1) ;
148 if (!Shape2.IsNull()) {
150 Shape2->ChangeNbIsos (NbIsos) ;
152 di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
157 if (Change) dout.RepaintAll() ;
163 //=======================================================================
165 //=======================================================================
167 static Standard_Integer hlr (Draw_Interpretor& di,
168 Standard_Integer n, const char **a)
173 if (withRgN) di << " RgNLines";
175 if (withRg1) di << " Rg1Lines";
176 else di << " no RegLines";
178 if (withHid) di << " HiddenLines";
179 else di << " no HiddenLines";
182 di << "Angle of discretization : ";
183 di << anglHLR * 180 / M_PI << " degrees\n";
186 else di << " wireframe";
192 if (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False;
193 else if (!strcasecmp(a[1],"hlr" )) withHLR = Standard_True;
194 else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False;
195 else if (!strcasecmp(a[1],"hid" )) {
196 withHLR = Standard_True;
197 withHid = Standard_True;
199 else if (!strcasecmp(a[1],"norg1")) {
200 withRg1 = Standard_False;
201 withRgN = Standard_False;
203 else if (!strcasecmp(a[1],"rg1" )) {
204 withHLR = Standard_True;
205 withRg1 = Standard_True;
206 withRgN = Standard_False;
208 else if (!strcasecmp(a[1],"norgn")) {
209 withRgN = Standard_False;
211 else if (!strcasecmp(a[1],"rgn" )) {
212 withHLR = Standard_True;
213 withRg1 = Standard_True;
214 withRgN = Standard_True;
216 else if (!strcasecmp(a[1],"ang" )) {
217 di << "Angle de discretisation : ";
218 di << anglHLR * 180 / M_PI << " degres\n";
223 Standard_Integer nFirst = 2;
225 if (n >= 3 && !strcasecmp(a[1],"ang" )) {
228 Standard_Real ang = Draw::Atof(a[2]);
229 anglHLR = ang * M_PI / 180;
230 if (anglHLR < HAngMin) anglHLR = HAngMin;
231 if (anglHLR > HAngMax) anglHLR = HAngMax;
233 di << "Angle of discretization : ";
234 di << anglHLR * 180 / M_PI << " degrees\n";
237 if (n >= nFirst + 1) {
239 for (Standard_Integer i = nFirst ; i < n; i++) {
240 Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ;
242 Handle (DBRep_DrawableShape) S =
243 Handle (DBRep_DrawableShape)::DownCast (D) ;
245 Standard_Boolean localHLR, localRg1, localRgN, localHid;
246 Standard_Real localAng;
247 S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid,
249 if (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False;
250 else if (!strcasecmp(a[1],"hlr" )) localHLR = Standard_True;
251 else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False;
252 else if (!strcasecmp(a[1],"hid" )) {
253 localHLR = Standard_True;
254 localHid = Standard_True;
256 else if (!strcasecmp(a[1],"norg1")) {
257 localRg1 = Standard_False;
258 localRgN = Standard_False;
260 else if (!strcasecmp(a[1],"rg1" )) {
261 localHLR = Standard_True;
262 localRg1 = Standard_True;
263 localRgN = Standard_False;
265 else if (!strcasecmp(a[1],"norgn")) {
266 localRgN = Standard_False;
268 else if (!strcasecmp(a[1],"rgn" )) {
269 localHLR = Standard_True;
270 localRg1 = Standard_True;
271 localRgN = Standard_True;
273 else if (!strcasecmp(a[1],"ang" )) {
274 Standard_Real ang = Draw::Atof(a[2]);
275 localAng = ang * M_PI / 180;
278 S->DisplayHLR(localHLR, localRg1, localRgN, localHid,
290 //=======================================================================
292 //=======================================================================
294 static Standard_Integer dispor (Draw_Interpretor& ,
295 Standard_Integer n, const char** a)
297 Standard_Boolean d = !strcasecmp(a[0],"vori");
300 DBRep_WriteColorOrientation();
303 for (i = 1; i < n; i++) {
304 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
306 Handle(DBRep_DrawableShape) d2 =
307 Handle(DBRep_DrawableShape)::DownCast(d1);
309 d2->DisplayOrientation(d);
317 //=======================================================================
319 //=======================================================================
321 static Standard_Integer discretisation(Draw_Interpretor& di,
322 Standard_Integer n, const char** a)
325 di << "Current number of points : "<<discret<<"\n";
327 discret = Draw::Atoi(a[1]);
333 //=======================================================================
335 //=======================================================================
337 static Standard_Integer triangles(Draw_Interpretor& ,
338 Standard_Integer n, const char** a)
343 disptriangles = !disptriangles;
345 if (disptriangles) std::cout <<"Triangulations are always displayed"<<std::endl;
346 else std::cout <<"Triangulations are displayed only if there is no geometric representation"<<std::endl;
351 for (i = 1; i <= n-1; i++) {
352 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
354 Handle(DBRep_DrawableShape) d2 =
355 Handle(DBRep_DrawableShape)::DownCast(d1);
357 d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
367 //=======================================================================
369 //=======================================================================
371 static Standard_Integer tclean(Draw_Interpretor& ,
372 Standard_Integer n, const char** a)
374 if (n == 1) return 1;
376 Standard_Integer aStart = 1;
377 Standard_Boolean toRemoveGeometry = Standard_False;
378 if (strcmp(a[1], "-geom") == 0)
381 toRemoveGeometry = Standard_True;
384 for (Standard_Integer i = aStart; i < n; i++) {
385 TopoDS_Shape S = DBRep::Get(a[i]);
386 if (toRemoveGeometry)
387 BRepTools::CleanGeometry(S);
394 //=======================================================================
396 //=======================================================================
398 static Standard_Integer polygons(Draw_Interpretor& ,
399 Standard_Integer n, const char** a)
404 disppolygons = !disppolygons;
406 if (disppolygons) std::cout <<"Polygons are always displayed"<<std::endl;
407 else std::cout <<"Polygons are displayed only if there is no geometric representation"<<std::endl;
412 for (i = 1; i <= n-1; i++) {
413 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
415 Handle(DBRep_DrawableShape) d2 =
416 Handle(DBRep_DrawableShape)::DownCast(d1);
418 d2->DisplayPolygons(!(d2->DisplayPolygons()));
429 //=======================================================================
431 //=======================================================================
433 static Standard_Integer compound(Draw_Interpretor& ,
434 Standard_Integer n, const char** a)
436 if (n <= 1) return 1;
440 for (Standard_Integer i = 1; i < n-1; i++) {
441 TopoDS_Shape S2 = DBRep::Get(a[i]);
442 if (!S2.IsNull()) B.Add(C,S2);
444 DBRep::Set(a[n-1],C);
448 //=======================================================================
450 //=======================================================================
452 static Standard_Integer emptycopy(Draw_Interpretor& ,
453 Standard_Integer n, const char** a)
455 if (n <= 1) return 1;
456 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
457 if (S.IsNull()) return 1;
463 //=======================================================================
465 //=======================================================================
467 static Standard_Integer add(Draw_Interpretor& ,
468 Standard_Integer n, const char** a)
472 TopoDS_Shape S1 = DBRep::Get(a[1]);
473 if (S1.IsNull()) return 1;
474 TopoDS_Shape S2 = DBRep::Get(a[2]);
475 if (S2.IsNull()) return 1;
481 //=======================================================================
483 //=======================================================================
485 static Standard_Integer explode(Draw_Interpretor& di,
486 Standard_Integer n, const char** a)
488 if (n <= 1) return 1;
489 TopoDS_Shape S = DBRep::Get(a[1]);
490 if (S.IsNull()) return 0;
492 strcpy(newname,a[1]);
494 while (*p != '\0') p++;
497 Standard_Integer i = 0;
499 TopoDS_Iterator itr(S);
503 DBRep::Set(newname,itr.Value());
504 di.AppendElement(newname);
510 TopAbs_ShapeEnum typ;
515 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
516 typ = TopAbs_COMPOUND;
518 typ = TopAbs_COMPSOLID;
523 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
525 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
555 TopTools_MapOfShape M;
557 TopExp_Explorer ex(S,typ);
558 for (; ex.More(); ex.Next()) {
559 const TopoDS_Shape& Sx = ex.Current();
560 Standard_Boolean added = M.Add(Sx);
564 DBRep::Set(newname,Sx);
565 di.AppendElement(newname);
572 //=======================================================================
573 // nexplode : stable numbered explode (from Serguey Nizhny)
574 //=======================================================================
576 static Standard_Integer nexplode(Draw_Interpretor& di,
577 Standard_Integer n, const char** a)
579 if (n <= 2) return 1;
580 TopoDS_Shape S = DBRep::Get(a[1]);
581 if (S.IsNull()) return 0;
583 strcpy(newname,a[1]);
585 while (*p != '\0') p++;
588 TopAbs_ShapeEnum typ;
609 TopTools_IndexedMapOfShape IMOStmp;
610 TopTools_MapOfShape MShape;
612 TopExp::MapShapes(S,typ,IMOStmp);
613 TopExp_Explorer Exp(S,typ);
614 Standard_Integer MaxShapes, Index = 0;
615 MaxShapes = IMOStmp.Extent()-1;
616 TopTools_Array1OfShape aShapes(1,MaxShapes);
620 if (MShape.Add(Exp.Current())) {
622 aShapes.SetValue(Index,Exp.Current());
627 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
630 Standard_Integer aTemp;
631 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
632 Standard_Boolean NoSort = Standard_True;
634 // Computing of CentreOfMass for edge and face
635 // and for vertex use its point
636 for (Index=1; Index <= MaxShapes; Index++) {
637 OrderInd.SetValue(Index,Index);
638 const TopoDS_Shape& aS = aShapes(Index);
639 if (aS.ShapeType() != TopAbs_VERTEX) {
640 BRepGProp::LinearProperties(aS, GPr);
641 GPoint = GPr.CentreOfMass();
644 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
646 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
651 NoSort = Standard_False;
652 for (Index=1; Index < MaxShapes; Index++) {
653 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
654 aTemp = OrderInd(Index);
655 OrderInd(Index) = OrderInd(Index+1);
656 OrderInd(Index+1) = aTemp;
657 NoSort = Standard_True;
661 // Check of equality of MidXYZ
662 for (Index=1; Index < MaxShapes; Index++) {
663 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
664 di<<"Warning! For this shape the results may be incorrect.\n";
667 for (Index=1 ;Index <= MaxShapes; Index++) {
668 Sprintf(p,"%d",Index);
669 DBRep::Set(newname,aShapes(OrderInd(Index)));
670 di.AppendElement(newname);
676 //=======================================================================
678 //=======================================================================
680 static Standard_Integer exwire(Draw_Interpretor& ,
681 Standard_Integer n, const char** a)
683 if (n <= 1) return 1;
684 TopoDS_Shape S = DBRep::Get(a[1]);
685 if (S.IsNull()) return 0;
686 if (S.ShapeType() != TopAbs_WIRE) return 0;
688 strcpy(newname,a[1]);
690 while (*p != '\0') p++;
693 Standard_Integer i = 0;
694 BRepTools_WireExplorer ex(TopoDS::Wire(S));
698 DBRep::Set(newname,ex.Current());
704 //=======================================================================
706 //=======================================================================
708 static Standard_Integer invert(Draw_Interpretor& ,
709 Standard_Integer n, const char** a)
711 if (n <= 1) return 1;
712 TopoDS_Shape S = DBRep::Get(a[1]);
713 if (S.IsNull()) return 0;
716 TopoDS_Shape NS = S.EmptyCopied();
717 NS.Closed (S.Closed());
719 TopoDS_Iterator itr(S);
721 B.Add(NS,itr.Value().Reversed());
729 //=======================================================================
730 // orientation, reverse, complement
731 //=======================================================================
733 static Standard_Integer orientation(Draw_Interpretor& ,
734 Standard_Integer n, const char** a)
736 if (n <= 1) return 1;
737 Standard_Integer cas = 0;
738 TopAbs_Orientation ori=TopAbs_FORWARD;
739 Standard_Integer last = n;
740 if (!strcasecmp(a[0],"orientation")) {
741 if (n <= 2) return 1;
746 ori = TopAbs_FORWARD;
750 ori = TopAbs_REVERSED;
754 ori = TopAbs_INTERNAL;
758 ori = TopAbs_EXTERNAL;
763 else if (!strcasecmp(a[0],"treverse")) {
767 else if (!strcasecmp(a[0],"complement")) {
771 for (Standard_Integer i = 1; i < last; i++) {
772 TopoDS_Shape S = DBRep::Get(a[i]);
786 #include <TCollection_AsciiString.hxx>
788 //=======================================================================
789 // numshapes same as nbshapes but the output is cout
790 //=======================================================================
792 static Standard_Integer numshapes(Draw_Interpretor& di,
793 Standard_Integer n, const char** a)
799 for (i = 1; i < n; i++) {
800 TopoDS_Shape S = DBRep::Get(a[i]);
802 BRepTools_ShapeSet BS;
804 di <<"Number of shapes in "<<a[i]<<"\n";
805 TCollection_AsciiString Astr;
807 di <<Astr.ToCString();
815 //=======================================================================
816 // function : DumpExtent
817 // purpose : Dumps the number of sub-shapes in <aStr>.
818 //=======================================================================
819 static void DumpExtent(const TopoDS_Shape& aS,
820 TCollection_AsciiString& aStr)
822 const int aNbTypes=8;
823 const char *pNames[aNbTypes+1]={
834 Standard_Integer i, aNb, aNbSh;
835 TopAbs_ShapeEnum aType;
836 TopTools_IndexedMapOfShape aM;
840 for (i=aNbTypes-1; i>=0; --i) {
842 aType=(TopAbs_ShapeEnum)i;
843 TopExp::MapShapes(aS, aType, aM);
845 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
848 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
851 //=======================================================================
853 //=======================================================================
855 static Standard_Integer nbshapes(Draw_Interpretor& di,
856 Standard_Integer n, const char** a)
861 Standard_Boolean aTotal;
864 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
866 for (i = 1; i < n; i++) {
867 TopoDS_Shape S = DBRep::Get(a[i]);
869 di<<"Number of shapes in "<<a[i]<<"\n";
870 TCollection_AsciiString Astr;
874 BRepTools_ShapeSet BS;
878 di<<Astr.ToCString();
885 //=======================================================================
887 //=======================================================================
889 static Standard_Integer countshapes(Draw_Interpretor& di,
890 Standard_Integer n, const char** a)
896 for (i = 1; i < n; i++) {
897 TopoDS_Shape Sh = DBRep::Get(a[i]);
898 Standard_Integer nbElem = 0;
900 di <<"Number of shapes in "<<a[i]<<"\n";
901 TopTools_MapOfShape M;
903 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
904 const TopoDS_Shape& S = ex.Current();
905 Standard_Boolean added = M.Add(S);
910 di << " VERTEX : " << nbElem << "\n";
913 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
914 const TopoDS_Shape& S = ex.Current();
915 Standard_Boolean added = M.Add(S);
920 di << " EDGE : " << nbElem << "\n";
923 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
924 const TopoDS_Shape& S = ex.Current();
925 Standard_Boolean added = M.Add(S);
930 di << " WIRE : " << nbElem << "\n";
933 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
934 const TopoDS_Shape& S = ex.Current();
935 Standard_Boolean added = M.Add(S);
940 di << " FACE : " << nbElem << "\n";
943 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
944 const TopoDS_Shape& S = ex.Current();
945 Standard_Boolean added = M.Add(S);
950 di << " SHELL : " << nbElem << "\n";
953 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
954 const TopoDS_Shape& S = ex.Current();
955 Standard_Boolean added = M.Add(S);
960 di << " SOLID : " << nbElem << "\n";
963 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
964 const TopoDS_Shape& S = ex.Current();
965 Standard_Boolean added = M.Add(S);
970 di << " COMPSOLID : " << nbElem << "\n";
973 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
974 const TopoDS_Shape& S = ex.Current();
975 Standard_Boolean added = M.Add(S);
980 di << " COMPOUND : " << nbElem << "\n";
983 di << " SHAPE : " << M.Extent() << "\n";
991 //=======================================================================
993 //=======================================================================
994 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
997 for(i = 2; i < n; i++) {
998 if (strstr ( a[i], "free" )) {
1000 Sh.Free(Standard_False);
1003 Sh.Free(Standard_True);
1006 if (strstr ( a[i], "modified" )) {
1007 if(a[i][0] == '-') {
1008 Sh.Modified(Standard_False);
1011 Sh.Modified(Standard_True);
1014 if (strstr ( a[i], "checked" )) {
1015 if(a[i][0] == '-') {
1016 Sh.Checked(Standard_False);
1019 Sh.Checked(Standard_True);
1022 if (strstr ( a[i], "orientable" )) {
1023 if(a[i][0] == '-') {
1024 Sh.Orientable(Standard_False);
1027 Sh.Orientable(Standard_True);
1030 if (strstr ( a[i], "closed" )) {
1031 if(a[i][0] == '-') {
1032 Sh.Closed(Standard_False);
1035 Sh.Closed(Standard_True);
1038 if (strstr ( a[i], "infinite" )) {
1039 if(a[i][0] == '-') {
1040 Sh.Infinite(Standard_False);
1043 Sh.Infinite(Standard_True);
1046 if (strstr ( a[i], "convex" )) {
1047 if(a[i][0] == '-') {
1048 Sh.Convex(Standard_False);
1051 Sh.Convex(Standard_True);
1054 if (strstr ( a[i], "locked" )) {
1055 if(a[i][0] == '-') {
1056 Sh.Locked(Standard_False);
1059 Sh.Locked(Standard_True);
1065 //=======================================================================
1067 //=======================================================================
1068 static Standard_Integer setFlags(Draw_Interpretor& ,
1069 Standard_Integer n, const char** a)
1071 if (n < 3) return 1;
1074 TopoDS_Shape Sh = DBRep::Get(a[1]);
1076 if (Sh.IsNull()) return 1;
1079 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1080 TopoDS_Shape S = ex.Current();
1084 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1085 TopoDS_Shape S = ex.Current();
1089 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1090 TopoDS_Shape S = ex.Current();
1097 //=======================================================================
1099 //=======================================================================
1100 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1104 //=======================================================================
1106 //=======================================================================
1108 //=======================================================================
1110 static Standard_Integer check(Draw_Interpretor& ,
1111 Standard_Integer n, const char** a)
1113 if (n < 2) return 1;
1117 for (i = 1; i < n; i++) {
1118 TopoDS_Shape S = DBRep::Get(a[i]);
1120 if (S.IsNull()) continue;
1121 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1123 C.Checked(Standard_False);
1124 BRepTools::Update(C);
1131 //=======================================================================
1133 //=======================================================================
1134 static Standard_Integer normals (Draw_Interpretor& theDI,
1135 Standard_Integer theArgNum,
1136 const char** theArgs)
1140 std::cout << "Syntax error: wrong number of arguments!\n";
1141 theDI.PrintHelp (theArgs[0]);
1145 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1146 if (aShape.IsNull())
1148 std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1152 Standard_Boolean toUseMesh = Standard_False;
1153 Standard_Real aLength = 10.0;
1154 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1155 Standard_Boolean bPrint = Standard_False;
1156 for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1158 TCollection_AsciiString aParam (theArgs[anArgIter]);
1161 && aParam.IsRealValue())
1163 aLength = aParam.RealValue();
1164 if (Abs (aLength) <= gp::Resolution())
1166 std::cout << "Syntax error: length should not be zero\n";
1170 else if (aParam == "-usemesh"
1171 || aParam == "-mesh")
1173 toUseMesh = Standard_True;
1175 else if (aParam == "-length"
1176 || aParam == "-len")
1179 aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1180 if (Abs(aLength) <= gp::Resolution())
1182 std::cout << "Syntax error: length should not be zero\n";
1186 else if (aParam == "-nbalongu"
1187 || aParam == "-nbu")
1190 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1193 std::cout << "Syntax error: NbAlongU should be >=1\n";
1197 else if (aParam == "-nbalongv"
1198 || aParam == "-nbv")
1201 aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1204 std::cout << "Syntax error: NbAlongV should be >=1\n";
1208 else if (aParam == "-nbalong"
1209 || aParam == "-nbuv")
1212 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1213 aNbAlongV = aNbAlongU;
1216 std::cout << "Syntax error: NbAlong should be >=1\n";
1220 else if (aParam == "-print")
1222 bPrint = Standard_True;
1226 std::cout << "Syntax error: unknown argument '" << aParam << "'\n";
1231 DBRep_WriteColorOrientation();
1233 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1236 DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1240 DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1243 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1245 Standard_Boolean bReverse = Standard_False;
1246 TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation();
1247 const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri);
1248 if (aFaceOri == TopAbs_REVERSED)
1249 bReverse = Standard_True;
1251 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1253 const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1254 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1258 // Make the normal vector from the points
1259 gp_Vec aV(aVec.first, aVec.second);
1263 // Print values of the vector avoiding printing "-0" values
1264 theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", "
1265 << (aV.Y() == 0 ? 0 : aV.Y()) << ", "
1266 << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n";
1274 //=======================================================================
1277 //=======================================================================
1278 void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1280 Handle(DBRep_DrawableShape) D =
1281 new DBRep_DrawableShape(S,
1289 D->DisplayTriangulation(disptriangles);
1290 D->DisplayPolygons(disppolygons);
1291 D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1294 //=======================================================================
1295 //function : getShape
1297 //=======================================================================
1298 TopoDS_Shape DBRep::getShape (Standard_CString& theName,
1299 TopAbs_ShapeEnum theType,
1300 Standard_Boolean theToComplain)
1302 const Standard_Boolean toPick = theName[0] == '.';
1303 Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
1304 if (aDrawable.IsNull())
1306 return TopoDS_Shape();
1309 TopoDS_Shape aShape = aDrawable->Shape();
1310 if (theType != TopAbs_SHAPE
1311 && theType != aShape.ShapeType()
1314 // try to find prom pick
1316 DBRep_DrawableShape::LastPick (aShape, u, v);
1318 if (theType != TopAbs_SHAPE
1319 && theType != aShape.ShapeType())
1323 std::cout << theName << " is not a ";
1324 TopAbs::Print (theType, std::cout);
1325 std::cout << " but a ";
1326 TopAbs::Print (aShape.ShapeType(), std::cout);
1327 std::cout << std::endl;
1329 return TopoDS_Shape();
1334 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1336 for ( Standard_Integer i=1; i < argc; i++ )
1338 Standard_Boolean turn = Standard_True;
1339 if ( argv[i][0] == '-' ) turn = Standard_False;
1340 else if ( argv[i][0] != '+' ) continue;
1342 TCollection_AsciiString anArgCase (argv[i]);
1343 anArgCase.LowerCase();
1344 if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTclMode() = turn;
1345 else if (argv[i][1] == 'c') Draw_ProgressIndicator::DefaultConsoleMode() = turn;
1346 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1347 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
1349 Standard_Address aPtr = 0;
1350 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1351 Draw_ProgressIndicator::StopIndicator() = aPtr;
1355 di << "Progress Indicator defaults: tcl mode is ";
1356 if ( Draw_ProgressIndicator::DefaultTclMode() ) {
1361 di<<", console mode is ";
1362 if (Draw_ProgressIndicator::DefaultConsoleMode()) {
1368 di << ", graphical mode is ";
1369 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1378 //=======================================================================
1380 //=======================================================================
1382 static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a)
1384 if (n <= 2) return 1;
1386 TopoDS_Shape aShape = DBRep::Get (a[1]);
1387 if (aShape.IsNull())
1389 di << a[1] << " is not a shape";
1393 if (!BinTools::Write (aShape, a[2]))
1395 di << "Cannot write to the file " << a[2];
1403 //=======================================================================
1405 //=======================================================================
1407 static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a)
1409 if (n <= 2) return 1;
1411 TopoDS_Shape aShape;
1412 if (!BinTools::Read (aShape, a[1]))
1414 di << "Cannot read from the file " << a[1];
1418 DBRep::Set (a[2], aShape);
1423 //=======================================================================
1425 //=======================================================================
1426 static Standard_Integer removeInternals (Draw_Interpretor& di,
1432 di.PrintHelp (a[0]);
1436 TopoDS_Shape aShape = DBRep::Get (a[1]);
1437 if (aShape.IsNull())
1439 di << a[1] << "is a null shape\n";
1443 Standard_Boolean isForce = Standard_False;
1446 isForce = (Draw::Atoi (a[2]) != 0);
1449 BRepTools::RemoveInternals (aShape, isForce);
1451 DBRep::Set (a[1], aShape);
1456 //=======================================================================
1457 //function : BasicCommands
1459 //=======================================================================
1461 static Standard_Boolean done = Standard_False;
1462 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1465 done = Standard_True;
1466 Draw::Commands(theCommands);
1468 const char* g = "Basic shape commands";
1470 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1471 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1472 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1473 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1474 theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n"
1475 "\t erase geometry objects from shapes - key is used or \n"
1476 "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n",
1477 __FILE__, tclean, g);
1478 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1479 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1480 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1481 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1482 theCommands.Add("add",
1484 "\n adds shape \"what\" to shape \"where\" ",
1486 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1487 theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1488 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1489 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1490 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1492 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1493 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1494 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1495 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1496 theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g);
1497 theCommands.Add("nbshapes",
1498 "\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.",
1499 __FILE__,nbshapes,g);
1500 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1501 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1502 theCommands.Add("setflags",
1503 "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 ",
1504 __FILE__,setFlags,g);
1506 // theCommands.Add("dumpmmgt",
1507 // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1508 theCommands.Add("purgemmgt",
1509 "returns the free memory from the system to the memory manager",
1510 __FILE__,purgemmgt,g);
1512 // Add command for DRAW-specific ProgressIndicator
1513 theCommands.Add ( "XProgress",
1514 "XProgress [+|-t] [+|-c] [+|-g]"
1515 "\n\t\t The options are:"
1516 "\n\t\t +|-t : switch on/off output to tcl of Progress Indicator"
1517 "\n\t\t +|-c : switch on/off output to cout of Progress Indicator"
1518 "\n\t\t +|-g : switch on/off graphical mode of Progress Indicator",
1519 XProgress,"DE: General");
1521 theCommands.Add("binsave", "binsave shape filename\n"
1522 "\t\tsave the shape in the binary format file",
1523 __FILE__, binsave, g);
1524 theCommands.Add("binrestore", "binrestore filename shape\n"
1525 "\t\trestore the shape from the binary format file",
1526 __FILE__, binrestore, g);
1528 theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
1529 "\n\t\t Removes sub-shapes with internal orientation from the shape.\n"
1530 "\n\t\t Force flag disables the check on topological connectivity and"
1531 "removes all internal sub-shapes\n",
1532 __FILE__, removeInternals, g);
1535 //=======================================================================
1536 //function : HLRMode
1538 //=======================================================================
1540 Standard_Boolean DBRep::HLRMode()
1543 //=======================================================================
1544 //function : Rg1Mode
1546 //=======================================================================
1548 Standard_Boolean DBRep::Rg1Mode()
1551 //=======================================================================
1552 //function : RgNMode
1554 //=======================================================================
1556 Standard_Boolean DBRep::RgNMode()
1559 //=======================================================================
1560 //function : HidMode
1562 //=======================================================================
1564 Standard_Boolean DBRep::HidMode()
1567 //=======================================================================
1568 //function : HLRAngle
1570 //=======================================================================
1572 Standard_Real DBRep::HLRAngle()
1575 //=======================================================================
1577 //purpose : save and restore shapes
1578 //=======================================================================
1580 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
1582 return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1585 static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1587 Handle(DBRep_DrawableShape)
1588 N = Handle(DBRep_DrawableShape)::DownCast(d);
1590 BRepTools_ShapeSet S(B);
1592 Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1593 S.Write(OS, Message_ProgressIndicator::Start(aProgress));
1594 if (! aProgress.IsNull() && aProgress->UserBreak())
1596 S.Write(N->Shape(),OS);
1599 static Handle(Draw_Drawable3D) srestore (std::istream& IS)
1602 BRepTools_ShapeSet S(B);
1603 Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1604 S.Read(IS, Message_ProgressIndicator::Start(aProgress));
1605 Handle(DBRep_DrawableShape) N;
1606 if (! aProgress.IsNull() && aProgress->UserBreak())
1608 TopoDS_Shape theShape;
1609 S.Read(theShape,IS );
1610 N = new DBRep_DrawableShape(theShape,
1618 N->DisplayTriangulation(disptriangles);
1619 N->DisplayPolygons(disppolygons);
1620 N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1626 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1627 stest,ssave,srestore);
1630 void dumps (const TopoDS_Shape& S)
1632 BRepTools::Dump(S,std::cout);
1635 //=======================================================================
1638 //=======================================================================
1640 Standard_Integer DBRep::NbIsos()
1644 //=======================================================================
1645 //function : Discretisation
1647 //=======================================================================
1649 Standard_Integer DBRep::Discretisation()