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 <Draw_Segment3D.hxx>
33 #include <GProp_GProps.hxx>
34 #include <NCollection_Vector.hxx>
35 #include <Poly_Triangulation.hxx>
36 #include <Precision.hxx>
37 #include <Standard.hxx>
38 #include <TColStd_Array1OfInteger.hxx>
39 #include <TColStd_Array1OfReal.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <TopoDS_Compound.hxx>
45 #include <TopoDS_Iterator.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopTools_Array1OfShape.hxx>
48 #include <TopTools_ListOfShape.hxx>
49 #include <TopTools_MapOfShape.hxx>
54 extern Draw_Viewer dout;
57 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
58 #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg]))
61 //==========================================
63 //==========================================
65 Standard_EXPORT void DBRep_WriteColorOrientation ()
67 cout << "\nrouge FORWARD";
68 cout << "\nbleu REVERSED";
69 cout << "\nrose EXTERNAL";
70 cout << "\norange INTERNAL"<<endl;
73 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or)
82 case TopAbs_REVERSED :
86 case TopAbs_EXTERNAL :
90 case TopAbs_INTERNAL :
98 //==========================================
100 //==========================================
102 static Standard_Integer nbIsos = 2;
103 static Standard_Real size = 100.;
104 static Standard_Integer discret = 30;
105 static Standard_Boolean disptriangles = Standard_False;
106 static Standard_Boolean disppolygons = Standard_False;
107 static Standard_Real anglHLR = 35 * M_PI / 180;
108 static Standard_Real HAngMin = 1 * M_PI / 180;
109 static Standard_Real HAngMax = 35 * M_PI / 180;
110 static Standard_Boolean withHLR = Standard_False;
111 static Standard_Boolean withRg1 = Standard_True;
112 static Standard_Boolean withRgN = Standard_False;
113 static Standard_Boolean withHid = Standard_False;
115 //=======================================================================
117 //=======================================================================
119 static Standard_Integer isos (Draw_Interpretor& di,
120 Standard_Integer NbArg, const char **Arg)
125 di << "Current number of isos : " << nbIsos << "\n" ;
129 Standard_Integer NbIsos = 0 ;
130 Standard_Boolean Change = Standard_False ;
131 if (!Characters (NbArg) && Float (NbArg)) return 1 ;
132 if (!Characters (NbArg)) {
133 NbIsos = Draw::Atoi (Arg[NbArg]) ;
135 Change = Standard_True ;
140 di << "New current number of isos : " << nbIsos << "\n" ;
142 for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) {
143 Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
144 if (!Shape1.IsNull()) {
145 Handle (DBRep_DrawableShape) Shape2 =
146 Handle (DBRep_DrawableShape)::DownCast (Shape1) ;
147 if (!Shape2.IsNull()) {
149 Shape2->ChangeNbIsos (NbIsos) ;
151 di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
156 if (Change) dout.RepaintAll() ;
162 //=======================================================================
164 //=======================================================================
166 static Standard_Integer hlr (Draw_Interpretor& di,
167 Standard_Integer n, const char **a)
172 if (withRgN) di << " RgNLines";
174 if (withRg1) di << " Rg1Lines";
175 else di << " no RegLines";
177 if (withHid) di << " HiddenLines";
178 else di << " no HiddenLines";
181 di << "Angle of discretization : ";
182 di << anglHLR * 180 / M_PI << " degrees\n";
185 else di << " wireframe";
191 if (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False;
192 else if (!strcasecmp(a[1],"hlr" )) withHLR = Standard_True;
193 else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False;
194 else if (!strcasecmp(a[1],"hid" )) {
195 withHLR = Standard_True;
196 withHid = Standard_True;
198 else if (!strcasecmp(a[1],"norg1")) {
199 withRg1 = Standard_False;
200 withRgN = Standard_False;
202 else if (!strcasecmp(a[1],"rg1" )) {
203 withHLR = Standard_True;
204 withRg1 = Standard_True;
205 withRgN = Standard_False;
207 else if (!strcasecmp(a[1],"norgn")) {
208 withRgN = Standard_False;
210 else if (!strcasecmp(a[1],"rgn" )) {
211 withHLR = Standard_True;
212 withRg1 = Standard_True;
213 withRgN = Standard_True;
215 else if (!strcasecmp(a[1],"ang" )) {
216 di << "Angle de discretisation : ";
217 di << anglHLR * 180 / M_PI << " degres\n";
222 Standard_Integer nFirst = 2;
224 if (n >= 3 && !strcasecmp(a[1],"ang" )) {
227 Standard_Real ang = Draw::Atof(a[2]);
228 anglHLR = ang * M_PI / 180;
229 if (anglHLR < HAngMin) anglHLR = HAngMin;
230 if (anglHLR > HAngMax) anglHLR = HAngMax;
232 di << "Angle of discretization : ";
233 di << anglHLR * 180 / M_PI << " degrees\n";
236 if (n >= nFirst + 1) {
238 for (Standard_Integer i = nFirst ; i < n; i++) {
239 Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ;
241 Handle (DBRep_DrawableShape) S =
242 Handle (DBRep_DrawableShape)::DownCast (D) ;
244 Standard_Boolean localHLR, localRg1, localRgN, localHid;
245 Standard_Real localAng;
246 S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid,
248 if (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False;
249 else if (!strcasecmp(a[1],"hlr" )) localHLR = Standard_True;
250 else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False;
251 else if (!strcasecmp(a[1],"hid" )) {
252 localHLR = Standard_True;
253 localHid = Standard_True;
255 else if (!strcasecmp(a[1],"norg1")) {
256 localRg1 = Standard_False;
257 localRgN = Standard_False;
259 else if (!strcasecmp(a[1],"rg1" )) {
260 localHLR = Standard_True;
261 localRg1 = Standard_True;
262 localRgN = Standard_False;
264 else if (!strcasecmp(a[1],"norgn")) {
265 localRgN = Standard_False;
267 else if (!strcasecmp(a[1],"rgn" )) {
268 localHLR = Standard_True;
269 localRg1 = Standard_True;
270 localRgN = Standard_True;
272 else if (!strcasecmp(a[1],"ang" )) {
273 Standard_Real ang = Draw::Atof(a[2]);
274 localAng = ang * M_PI / 180;
277 S->DisplayHLR(localHLR, localRg1, localRgN, localHid,
289 //=======================================================================
291 //=======================================================================
293 static Standard_Integer dispor (Draw_Interpretor& ,
294 Standard_Integer n, const char** a)
296 Standard_Boolean d = !strcasecmp(a[0],"vori");
299 DBRep_WriteColorOrientation();
302 for (i = 1; i < n; i++) {
303 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
305 Handle(DBRep_DrawableShape) d2 =
306 Handle(DBRep_DrawableShape)::DownCast(d1);
308 d2->DisplayOrientation(d);
316 //=======================================================================
318 //=======================================================================
320 static Standard_Integer discretisation(Draw_Interpretor& di,
321 Standard_Integer n, const char** a)
324 di << "Current number of points : "<<discret<<"\n";
326 discret = Draw::Atoi(a[1]);
332 //=======================================================================
334 //=======================================================================
336 static Standard_Integer triangles(Draw_Interpretor& ,
337 Standard_Integer n, const char** a)
342 disptriangles = !disptriangles;
344 if (disptriangles) cout <<"Triangulations are always displayed"<<endl;
345 else cout <<"Triangulations are displayed only if there is no geometric representation"<<endl;
350 for (i = 1; i <= n-1; i++) {
351 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
353 Handle(DBRep_DrawableShape) d2 =
354 Handle(DBRep_DrawableShape)::DownCast(d1);
356 d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
366 //=======================================================================
368 //=======================================================================
370 static Standard_Integer tclean(Draw_Interpretor& ,
371 Standard_Integer n, const char** a)
375 for (Standard_Integer i = 1; i < n; i++) {
376 TopoDS_Shape S = DBRep::Get(a[i]);
382 //=======================================================================
384 //=======================================================================
386 static Standard_Integer polygons(Draw_Interpretor& ,
387 Standard_Integer n, const char** a)
392 disppolygons = !disppolygons;
394 if (disppolygons) cout <<"Polygons are always displayed"<<endl;
395 else cout <<"Polygons are displayed only if there is no geometric representation"<<endl;
400 for (i = 1; i <= n-1; i++) {
401 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
403 Handle(DBRep_DrawableShape) d2 =
404 Handle(DBRep_DrawableShape)::DownCast(d1);
406 d2->DisplayPolygons(!(d2->DisplayPolygons()));
417 //=======================================================================
419 //=======================================================================
421 static Standard_Integer compound(Draw_Interpretor& ,
422 Standard_Integer n, const char** a)
424 if (n <= 1) return 1;
428 for (Standard_Integer i = 1; i < n-1; i++) {
429 TopoDS_Shape S2 = DBRep::Get(a[i]);
430 if (!S2.IsNull()) B.Add(C,S2);
432 DBRep::Set(a[n-1],C);
436 //=======================================================================
438 //=======================================================================
440 static Standard_Integer emptycopy(Draw_Interpretor& ,
441 Standard_Integer n, const char** a)
443 if (n <= 1) return 1;
444 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
445 if (S.IsNull()) return 1;
451 //=======================================================================
453 //=======================================================================
455 static Standard_Integer add(Draw_Interpretor& ,
456 Standard_Integer n, const char** a)
460 TopoDS_Shape S1 = DBRep::Get(a[1]);
461 if (S1.IsNull()) return 1;
462 TopoDS_Shape S2 = DBRep::Get(a[2]);
463 if (S2.IsNull()) return 1;
469 //=======================================================================
471 //=======================================================================
473 static Standard_Integer explode(Draw_Interpretor& di,
474 Standard_Integer n, const char** a)
476 if (n <= 1) return 1;
477 TopoDS_Shape S = DBRep::Get(a[1]);
478 if (S.IsNull()) return 0;
480 strcpy(newname,a[1]);
482 while (*p != '\0') p++;
485 Standard_Integer i = 0;
487 TopoDS_Iterator itr(S);
491 DBRep::Set(newname,itr.Value());
492 di.AppendElement(newname);
498 TopAbs_ShapeEnum typ;
503 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
504 typ = TopAbs_COMPOUND;
506 typ = TopAbs_COMPSOLID;
511 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
513 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
543 TopTools_MapOfShape M;
545 TopExp_Explorer ex(S,typ);
546 for (; ex.More(); ex.Next()) {
547 const TopoDS_Shape& Sx = ex.Current();
548 Standard_Boolean added = M.Add(Sx);
552 DBRep::Set(newname,Sx);
553 di.AppendElement(newname);
560 //=======================================================================
561 // nexplode : stable numbered explode (from Serguey Nizhny)
562 //=======================================================================
564 static Standard_Integer nexplode(Draw_Interpretor& di,
565 Standard_Integer n, const char** a)
567 if (n <= 2) return 1;
568 TopoDS_Shape S = DBRep::Get(a[1]);
569 if (S.IsNull()) return 0;
571 strcpy(newname,a[1]);
573 while (*p != '\0') p++;
576 TopAbs_ShapeEnum typ;
597 TopTools_IndexedMapOfShape IMOStmp;
598 TopTools_MapOfShape MShape;
600 TopExp::MapShapes(S,typ,IMOStmp);
601 TopExp_Explorer Exp(S,typ);
602 Standard_Integer MaxShapes, Index = 0;
603 MaxShapes = IMOStmp.Extent()-1;
604 TopTools_Array1OfShape aShapes(1,MaxShapes);
608 if (MShape.Add(Exp.Current())) {
610 aShapes.SetValue(Index,Exp.Current());
615 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
618 Standard_Integer aTemp;
619 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
620 Standard_Boolean NoSort = Standard_True;
622 // Computing of CentreOfMass for edge and face
623 // and for vertex use its point
624 for (Index=1; Index <= MaxShapes; Index++) {
625 OrderInd.SetValue(Index,Index);
626 const TopoDS_Shape& aS = aShapes(Index);
627 if (aS.ShapeType() != TopAbs_VERTEX) {
628 BRepGProp::LinearProperties(aS, GPr);
629 GPoint = GPr.CentreOfMass();
632 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
634 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
639 NoSort = Standard_False;
640 for (Index=1; Index < MaxShapes; Index++) {
641 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
642 aTemp = OrderInd(Index);
643 OrderInd(Index) = OrderInd(Index+1);
644 OrderInd(Index+1) = aTemp;
645 NoSort = Standard_True;
649 // Check of equality of MidXYZ
650 for (Index=1; Index < MaxShapes; Index++) {
651 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
652 di<<"Warning! For this shape the results may be incorrect.\n";
655 for (Index=1 ;Index <= MaxShapes; Index++) {
656 Sprintf(p,"%d",Index);
657 DBRep::Set(newname,aShapes(OrderInd(Index)));
658 di.AppendElement(newname);
664 //=======================================================================
666 //=======================================================================
668 static Standard_Integer exwire(Draw_Interpretor& ,
669 Standard_Integer n, const char** a)
671 if (n <= 1) return 1;
672 TopoDS_Shape S = DBRep::Get(a[1]);
673 if (S.IsNull()) return 0;
674 if (S.ShapeType() != TopAbs_WIRE) return 0;
676 strcpy(newname,a[1]);
678 while (*p != '\0') p++;
681 Standard_Integer i = 0;
682 BRepTools_WireExplorer ex(TopoDS::Wire(S));
686 DBRep::Set(newname,ex.Current());
692 //=======================================================================
694 //=======================================================================
696 static Standard_Integer invert(Draw_Interpretor& ,
697 Standard_Integer n, const char** a)
699 if (n <= 1) return 1;
700 TopoDS_Shape S = DBRep::Get(a[1]);
701 if (S.IsNull()) return 0;
704 TopoDS_Shape NS = S.EmptyCopied();
705 NS.Closed (S.Closed());
707 TopoDS_Iterator itr(S);
709 B.Add(NS,itr.Value().Reversed());
717 //=======================================================================
718 // orientation, reverse, complement
719 //=======================================================================
721 static Standard_Integer orientation(Draw_Interpretor& ,
722 Standard_Integer n, const char** a)
724 if (n <= 1) return 1;
725 Standard_Integer cas = 0;
726 TopAbs_Orientation ori=TopAbs_FORWARD;
727 Standard_Integer last = n;
728 if (!strcasecmp(a[0],"orientation")) {
729 if (n <= 2) return 1;
734 ori = TopAbs_FORWARD;
738 ori = TopAbs_REVERSED;
742 ori = TopAbs_INTERNAL;
746 ori = TopAbs_EXTERNAL;
751 else if (!strcasecmp(a[0],"treverse")) {
755 else if (!strcasecmp(a[0],"complement")) {
759 for (Standard_Integer i = 1; i < last; i++) {
760 TopoDS_Shape S = DBRep::Get(a[i]);
774 #include <TCollection_AsciiString.hxx>
776 //=======================================================================
777 // numshapes same as nbshapes but the output is cout
778 //=======================================================================
780 static Standard_Integer numshapes(Draw_Interpretor& di,
781 Standard_Integer n, const char** a)
787 for (i = 1; i < n; i++) {
788 TopoDS_Shape S = DBRep::Get(a[i]);
790 BRepTools_ShapeSet BS;
792 di <<"Number of shapes in "<<a[i]<<"\n";
793 TCollection_AsciiString Astr;
795 di <<Astr.ToCString();
803 //=======================================================================
804 // function : DumpExtent
805 // purpose : Dumps the number of sub-shapes in <aStr>.
806 //=======================================================================
807 static void DumpExtent(const TopoDS_Shape& aS,
808 TCollection_AsciiString& aStr)
810 const int aNbTypes=8;
811 const char *pNames[aNbTypes+1]={
822 Standard_Integer i, aNb, aNbSh;
823 TopAbs_ShapeEnum aType;
824 TopTools_IndexedMapOfShape aM;
828 for (i=aNbTypes-1; i>=0; --i) {
830 aType=(TopAbs_ShapeEnum)i;
831 TopExp::MapShapes(aS, aType, aM);
833 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
836 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
839 //=======================================================================
841 //=======================================================================
843 static Standard_Integer nbshapes(Draw_Interpretor& di,
844 Standard_Integer n, const char** a)
849 Standard_Boolean aTotal;
852 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
854 for (i = 1; i < n; i++) {
855 TopoDS_Shape S = DBRep::Get(a[i]);
857 di<<"Number of shapes in "<<a[i]<<"\n";
858 TCollection_AsciiString Astr;
862 BRepTools_ShapeSet BS;
866 di<<Astr.ToCString();
873 //=======================================================================
875 //=======================================================================
877 static Standard_Integer countshapes(Draw_Interpretor& di,
878 Standard_Integer n, const char** a)
884 for (i = 1; i < n; i++) {
885 TopoDS_Shape Sh = DBRep::Get(a[i]);
886 Standard_Integer nbElem = 0;
888 di <<"Number of shapes in "<<a[i]<<"\n";
889 TopTools_MapOfShape M;
891 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
892 const TopoDS_Shape& S = ex.Current();
893 Standard_Boolean added = M.Add(S);
898 di << " VERTEX : " << nbElem << "\n";
901 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
902 const TopoDS_Shape& S = ex.Current();
903 Standard_Boolean added = M.Add(S);
908 di << " EDGE : " << nbElem << "\n";
911 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
912 const TopoDS_Shape& S = ex.Current();
913 Standard_Boolean added = M.Add(S);
918 di << " WIRE : " << nbElem << "\n";
921 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
922 const TopoDS_Shape& S = ex.Current();
923 Standard_Boolean added = M.Add(S);
928 di << " FACE : " << nbElem << "\n";
931 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
932 const TopoDS_Shape& S = ex.Current();
933 Standard_Boolean added = M.Add(S);
938 di << " SHELL : " << nbElem << "\n";
941 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
942 const TopoDS_Shape& S = ex.Current();
943 Standard_Boolean added = M.Add(S);
948 di << " SOLID : " << nbElem << "\n";
951 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
952 const TopoDS_Shape& S = ex.Current();
953 Standard_Boolean added = M.Add(S);
958 di << " COMPSOLID : " << nbElem << "\n";
961 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
962 const TopoDS_Shape& S = ex.Current();
963 Standard_Boolean added = M.Add(S);
968 di << " COMPOUND : " << nbElem << "\n";
971 di << " SHAPE : " << M.Extent() << "\n";
979 //=======================================================================
981 //=======================================================================
982 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
985 for(i = 2; i < n; i++) {
986 if (strstr ( a[i], "free" )) {
988 Sh.Free(Standard_False);
991 Sh.Free(Standard_True);
994 if (strstr ( a[i], "modified" )) {
996 Sh.Modified(Standard_False);
999 Sh.Modified(Standard_True);
1002 if (strstr ( a[i], "checked" )) {
1003 if(a[i][0] == '-') {
1004 Sh.Checked(Standard_False);
1007 Sh.Checked(Standard_True);
1010 if (strstr ( a[i], "orientable" )) {
1011 if(a[i][0] == '-') {
1012 Sh.Orientable(Standard_False);
1015 Sh.Orientable(Standard_True);
1018 if (strstr ( a[i], "closed" )) {
1019 if(a[i][0] == '-') {
1020 Sh.Closed(Standard_False);
1023 Sh.Closed(Standard_True);
1026 if (strstr ( a[i], "infinite" )) {
1027 if(a[i][0] == '-') {
1028 Sh.Infinite(Standard_False);
1031 Sh.Infinite(Standard_True);
1034 if (strstr ( a[i], "convex" )) {
1035 if(a[i][0] == '-') {
1036 Sh.Convex(Standard_False);
1039 Sh.Convex(Standard_True);
1042 if (strstr ( a[i], "locked" )) {
1043 if(a[i][0] == '-') {
1044 Sh.Locked(Standard_False);
1047 Sh.Locked(Standard_True);
1053 //=======================================================================
1055 //=======================================================================
1056 static Standard_Integer setFlags(Draw_Interpretor& ,
1057 Standard_Integer n, const char** a)
1059 if (n < 3) return 1;
1062 TopoDS_Shape Sh = DBRep::Get(a[1]);
1064 if (Sh.IsNull()) return 1;
1067 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1068 TopoDS_Shape S = ex.Current();
1072 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1073 TopoDS_Shape S = ex.Current();
1077 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1078 TopoDS_Shape S = ex.Current();
1085 //=======================================================================
1087 //=======================================================================
1088 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1092 //=======================================================================
1094 //=======================================================================
1096 //=======================================================================
1098 static Standard_Integer check(Draw_Interpretor& ,
1099 Standard_Integer n, const char** a)
1101 if (n < 2) return 1;
1105 for (i = 1; i < n; i++) {
1106 TopoDS_Shape S = DBRep::Get(a[i]);
1108 if (S.IsNull()) continue;
1109 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1111 C.Checked(Standard_False);
1112 BRepTools::Update(C);
1119 //=======================================================================
1121 //=======================================================================
1122 static Standard_Integer normals (Draw_Interpretor& theDI,
1123 Standard_Integer theArgNum,
1124 const char** theArgs)
1128 std::cout << "Syntax error: wrong number of arguments!\n";
1129 theDI.PrintHelp (theArgs[0]);
1133 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1134 if (aShape.IsNull())
1136 std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1140 Standard_Boolean toUseMesh = Standard_False;
1141 Standard_Real aLength = 10.0;
1142 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1143 for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1145 TCollection_AsciiString aParam (theArgs[anArgIter]);
1148 && aParam.IsRealValue())
1150 aLength = aParam.RealValue();
1151 if (Abs (aLength) <= gp::Resolution())
1153 std::cout << "Syntax error: length should not be zero\n";
1157 else if (aParam == "-usemesh"
1158 || aParam == "-mesh")
1160 toUseMesh = Standard_True;
1162 else if (aParam == "-length"
1163 || aParam == "-len")
1166 aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1167 if (Abs(aLength) <= gp::Resolution())
1169 std::cout << "Syntax error: length should not be zero\n";
1173 else if (aParam == "-nbalongu"
1174 || aParam == "-nbu")
1177 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1180 std::cout << "Syntax error: NbAlongU should be >=1\n";
1184 else if (aParam == "-nbalongv"
1185 || aParam == "-nbv")
1188 aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1191 std::cout << "Syntax error: NbAlongV should be >=1\n";
1195 else if (aParam == "-nbalong"
1196 || aParam == "-nbuv")
1199 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1200 aNbAlongV = aNbAlongU;
1203 std::cout << "Syntax error: NbAlong should be >=1\n";
1209 std::cout << "Syntax error: unknwon argument '" << aParam << "'\n";
1214 DBRep_WriteColorOrientation();
1216 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1219 DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1223 DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1226 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1228 const Draw_Color aColor = DBRep_ColorOrientation (aFaceIt.Key().Orientation());
1229 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1231 const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1232 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1240 //=======================================================================
1243 //=======================================================================
1244 void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1246 Handle(DBRep_DrawableShape) D =
1247 new DBRep_DrawableShape(S,
1255 D->DisplayTriangulation(disptriangles);
1256 D->DisplayPolygons(disppolygons);
1257 D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1260 //=======================================================================
1263 //=======================================================================
1264 TopoDS_Shape DBRep::Get(Standard_CString& name,
1265 const TopAbs_ShapeEnum typ,
1266 const Standard_Boolean complain)
1268 Standard_Boolean pick = name[0] == '.';
1270 Handle(DBRep_DrawableShape) D;
1271 Handle(Draw_Drawable3D) DD = Draw::Get(name,complain);
1273 D = Handle(DBRep_DrawableShape)::DownCast(DD);
1276 if (typ != TopAbs_SHAPE) {
1277 if (typ != S.ShapeType()) {
1278 // try to find prom pick
1281 DBRep_DrawableShape::LastPick(S,u,v);
1284 if (typ != S.ShapeType()) {
1286 cout << name << " is not a ";
1287 TopAbs::Print(typ,cout);
1289 TopAbs::Print(S.ShapeType(),cout);
1299 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1301 for ( Standard_Integer i=1; i < argc; i++ ) {
1302 Standard_Boolean turn = Standard_True;
1303 if ( argv[i][0] == '-' ) turn = Standard_False;
1304 else if ( argv[i][0] != '+' ) continue;
1305 if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn;
1306 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1307 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) {
1308 Standard_Address aPtr = 0;
1309 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1310 Draw_ProgressIndicator::StopIndicator() = aPtr;
1314 di << "Progress Indicator defaults: text mode is ";
1315 if ( Draw_ProgressIndicator::DefaultTextMode() ) {
1320 di<<", graphical mode is ";
1321 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1330 //=======================================================================
1332 //=======================================================================
1334 static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a)
1336 if (n <= 2) return 1;
1338 TopoDS_Shape aShape = DBRep::Get (a[1]);
1339 if (aShape.IsNull())
1341 di << a[1] << " is not a shape";
1345 if (!BinTools::Write (aShape, a[2]))
1347 di << "Cannot write to the file " << a[2];
1355 //=======================================================================
1357 //=======================================================================
1359 static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a)
1361 if (n <= 2) return 1;
1363 TopoDS_Shape aShape;
1364 if (!BinTools::Read (aShape, a[1]))
1366 di << "Cannot read from the file " << a[1];
1370 DBRep::Set (a[2], aShape);
1375 //=======================================================================
1376 //function : BasicCommands
1378 //=======================================================================
1380 static Standard_Boolean done = Standard_False;
1381 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1384 done = Standard_True;
1385 Draw::Commands(theCommands);
1387 const char* g = "Basic shape commands";
1389 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1390 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1391 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1392 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1393 theCommands.Add("tclean", "tclean [name1]..., erase triangulations and polygons on triangulations from shapes",__FILE__, tclean, g);
1394 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1395 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1396 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1397 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1398 theCommands.Add("add","add name1 name2",__FILE__,add,g);
1399 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1400 theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1401 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1402 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1403 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1405 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1406 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1407 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1408 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1409 theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh], display normals",__FILE__,normals,g);
1410 theCommands.Add("nbshapes",
1411 "\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.",
1412 __FILE__,nbshapes,g);
1413 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1414 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1415 theCommands.Add("setflags",
1416 "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 ",
1417 __FILE__,setFlags,g);
1419 // theCommands.Add("dumpmmgt",
1420 // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1421 theCommands.Add("purgemmgt",
1422 "returns the free memory from the system to the memory manager",
1423 __FILE__,purgemmgt,g);
1425 // Add command for DRAW-specific ProgressIndicator
1426 theCommands.Add ( "XProgress","XProgress [+|-t] [+|-g]: switch on/off textual and graphical mode of Progress Indicator",XProgress,"DE: General");
1428 theCommands.Add("binsave", "binsave shape filename\n"
1429 "\t\tsave the shape in the binary format file",
1430 __FILE__, binsave, g);
1431 theCommands.Add("binrestore", "binrestore filename shape\n"
1432 "\t\trestore the shape from the binary format file",
1433 __FILE__, binrestore, g);
1436 //=======================================================================
1437 //function : HLRMode
1439 //=======================================================================
1441 Standard_Boolean DBRep::HLRMode()
1444 //=======================================================================
1445 //function : Rg1Mode
1447 //=======================================================================
1449 Standard_Boolean DBRep::Rg1Mode()
1452 //=======================================================================
1453 //function : RgNMode
1455 //=======================================================================
1457 Standard_Boolean DBRep::RgNMode()
1460 //=======================================================================
1461 //function : HidMode
1463 //=======================================================================
1465 Standard_Boolean DBRep::HidMode()
1468 //=======================================================================
1469 //function : HLRAngle
1471 //=======================================================================
1473 Standard_Real DBRep::HLRAngle()
1476 //=======================================================================
1478 //purpose : save and restore shapes
1479 //=======================================================================
1481 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
1483 return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1486 static void ssave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1488 Handle(DBRep_DrawableShape)
1489 N = Handle(DBRep_DrawableShape)::DownCast(d);
1491 BRepTools_ShapeSet S(B);
1492 if(!Draw::GetProgressBar().IsNull())
1493 S.SetProgress(Draw::GetProgressBar());
1496 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1498 S.Write(N->Shape(),OS);
1501 static Handle(Draw_Drawable3D) srestore (istream& IS)
1504 BRepTools_ShapeSet S(B);
1505 if(!Draw::GetProgressBar().IsNull())
1506 S.SetProgress(Draw::GetProgressBar());
1508 Handle(DBRep_DrawableShape) N;
1509 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1511 TopoDS_Shape theShape;
1512 S.Read(theShape,IS );
1513 N = new DBRep_DrawableShape(theShape,
1521 N->DisplayTriangulation(disptriangles);
1522 N->DisplayPolygons(disppolygons);
1523 N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1529 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1530 stest,ssave,srestore);
1533 void dumps (const TopoDS_Shape& S)
1535 BRepTools::Dump(S,cout);
1538 //=======================================================================
1541 //=======================================================================
1543 Standard_Integer DBRep::NbIsos()
1547 //=======================================================================
1548 //function : Discretisation
1550 //=======================================================================
1552 Standard_Integer DBRep::Discretisation()