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>
25 #include <DBRep_DrawableShape.hxx>
27 #include <Draw_Appli.hxx>
28 #include <Draw_ProgressIndicator.hxx>
29 #include <Draw_Segment3D.hxx>
32 #include <GProp_GProps.hxx>
33 #include <Poly_Triangulation.hxx>
34 #include <Precision.hxx>
35 #include <Standard.hxx>
36 #include <TColStd_Array1OfInteger.hxx>
37 #include <TColStd_Array1OfReal.hxx>
40 #include <TopExp_Explorer.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopTools_Array1OfShape.hxx>
46 #include <TopTools_ListOfShape.hxx>
47 #include <TopTools_MapOfShape.hxx>
52 extern Draw_Viewer dout;
55 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
56 #define Float(IArg) (strspn (Arg[IArg], "0123456789+-") != strlen (Arg[IArg]))
59 //==========================================
61 //==========================================
63 Standard_EXPORT void DBRep_WriteColorOrientation ()
65 cout << "\nrouge FORWARD";
66 cout << "\nbleu REVERSED";
67 cout << "\nrose EXTERNAL";
68 cout << "\norange INTERNAL"<<endl;
71 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or)
80 case TopAbs_REVERSED :
84 case TopAbs_EXTERNAL :
88 case TopAbs_INTERNAL :
96 //==========================================
98 //==========================================
100 static Standard_Integer nbIsos = 2;
101 static Standard_Real size = 100.;
102 static Standard_Integer discret = 30;
103 static Standard_Boolean disptriangles = Standard_False;
104 static Standard_Boolean disppolygons = Standard_False;
105 static Standard_Real anglHLR = 35 * M_PI / 180;
106 static Standard_Real HAngMin = 1 * M_PI / 180;
107 static Standard_Real HAngMax = 35 * M_PI / 180;
108 static Standard_Boolean withHLR = Standard_False;
109 static Standard_Boolean withRg1 = Standard_True;
110 static Standard_Boolean withRgN = Standard_False;
111 static Standard_Boolean withHid = Standard_False;
113 //=======================================================================
115 //=======================================================================
117 static Standard_Integer isos (Draw_Interpretor& di,
118 Standard_Integer NbArg, const char **Arg)
123 di << "Current number of isos : " << nbIsos << "\n" ;
127 Standard_Integer NbIsos = 0 ;
128 Standard_Boolean Change = Standard_False ;
129 if (!Characters (NbArg) && Float (NbArg)) return 1 ;
130 if (!Characters (NbArg)) {
131 NbIsos = Draw::Atoi (Arg[NbArg]) ;
133 Change = Standard_True ;
138 di << "New current number of isos : " << nbIsos << "\n" ;
140 for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) {
141 Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
142 if (!Shape1.IsNull()) {
143 Handle (DBRep_DrawableShape) Shape2 =
144 Handle (DBRep_DrawableShape)::DownCast (Shape1) ;
145 if (!Shape2.IsNull()) {
147 Shape2->ChangeNbIsos (NbIsos) ;
149 di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
154 if (Change) dout.RepaintAll() ;
160 //=======================================================================
162 //=======================================================================
164 static Standard_Integer hlr (Draw_Interpretor& di,
165 Standard_Integer n, const char **a)
170 if (withRgN) di << " RgNLines";
172 if (withRg1) di << " Rg1Lines";
173 else di << " no RegLines";
175 if (withHid) di << " HiddenLines";
176 else di << " no HiddenLines";
179 di << "Angle of discretization : ";
180 di << anglHLR * 180 / M_PI << " degrees" << "\n";
183 else di << " wireframe";
189 if (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False;
190 else if (!strcasecmp(a[1],"hlr" )) withHLR = Standard_True;
191 else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False;
192 else if (!strcasecmp(a[1],"hid" )) {
193 withHLR = Standard_True;
194 withHid = Standard_True;
196 else if (!strcasecmp(a[1],"norg1")) {
197 withRg1 = Standard_False;
198 withRgN = Standard_False;
200 else if (!strcasecmp(a[1],"rg1" )) {
201 withHLR = Standard_True;
202 withRg1 = Standard_True;
203 withRgN = Standard_False;
205 else if (!strcasecmp(a[1],"norgn")) {
206 withRgN = Standard_False;
208 else if (!strcasecmp(a[1],"rgn" )) {
209 withHLR = Standard_True;
210 withRg1 = Standard_True;
211 withRgN = Standard_True;
213 else if (!strcasecmp(a[1],"ang" )) {
214 di << "Angle de discretisation : ";
215 di << anglHLR * 180 / M_PI << " degres" << "\n";
220 Standard_Integer nFirst = 2;
222 if (n >= 3 && !strcasecmp(a[1],"ang" )) {
225 Standard_Real ang = Draw::Atof(a[2]);
226 anglHLR = ang * M_PI / 180;
227 if (anglHLR < HAngMin) anglHLR = HAngMin;
228 if (anglHLR > HAngMax) anglHLR = HAngMax;
230 di << "Angle of discretization : ";
231 di << anglHLR * 180 / M_PI << " degrees" << "\n";
234 if (n >= nFirst + 1) {
236 for (Standard_Integer i = nFirst ; i < n; i++) {
237 Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ;
239 Handle (DBRep_DrawableShape) S =
240 Handle (DBRep_DrawableShape)::DownCast (D) ;
242 Standard_Boolean localHLR, localRg1, localRgN, localHid;
243 Standard_Real localAng;
244 S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid,
246 if (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False;
247 else if (!strcasecmp(a[1],"hlr" )) localHLR = Standard_True;
248 else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False;
249 else if (!strcasecmp(a[1],"hid" )) {
250 localHLR = Standard_True;
251 localHid = Standard_True;
253 else if (!strcasecmp(a[1],"norg1")) {
254 localRg1 = Standard_False;
255 localRgN = Standard_False;
257 else if (!strcasecmp(a[1],"rg1" )) {
258 localHLR = Standard_True;
259 localRg1 = Standard_True;
260 localRgN = Standard_False;
262 else if (!strcasecmp(a[1],"norgn")) {
263 localRgN = Standard_False;
265 else if (!strcasecmp(a[1],"rgn" )) {
266 localHLR = Standard_True;
267 localRg1 = Standard_True;
268 localRgN = Standard_True;
270 else if (!strcasecmp(a[1],"ang" )) {
271 Standard_Real ang = Draw::Atof(a[2]);
272 localAng = ang * M_PI / 180;
275 S->DisplayHLR(localHLR, localRg1, localRgN, localHid,
287 //=======================================================================
289 //=======================================================================
291 static Standard_Integer dispor (Draw_Interpretor& ,
292 Standard_Integer n, const char** a)
294 Standard_Boolean d = !strcasecmp(a[0],"vori");
297 DBRep_WriteColorOrientation();
300 for (i = 1; i < n; i++) {
301 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
303 Handle(DBRep_DrawableShape) d2 =
304 Handle(DBRep_DrawableShape)::DownCast(d1);
306 d2->DisplayOrientation(d);
314 //=======================================================================
316 //=======================================================================
318 static Standard_Integer discretisation(Draw_Interpretor& di,
319 Standard_Integer n, const char** a)
322 di << "Current number of points : "<<discret<<"\n";
324 discret = Draw::Atoi(a[1]);
330 //=======================================================================
332 //=======================================================================
334 static Standard_Integer triangles(Draw_Interpretor& ,
335 Standard_Integer n, const char** a)
340 disptriangles = !disptriangles;
342 if (disptriangles) cout <<"Triangulations are always displayed"<<endl;
343 else cout <<"Triangulations are displayed only if there is no geometric representation"<<endl;
348 for (i = 1; i <= n-1; i++) {
349 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
351 Handle(DBRep_DrawableShape) d2 =
352 Handle(DBRep_DrawableShape)::DownCast(d1);
354 d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
364 //=======================================================================
366 //=======================================================================
368 static Standard_Integer tclean(Draw_Interpretor& ,
369 Standard_Integer n, const char** a)
373 for (Standard_Integer i = 1; i < n; i++) {
374 TopoDS_Shape S = DBRep::Get(a[i]);
380 //=======================================================================
382 //=======================================================================
384 static Standard_Integer polygons(Draw_Interpretor& ,
385 Standard_Integer n, const char** a)
390 disppolygons = !disppolygons;
392 if (disppolygons) cout <<"Polygons are always displayed"<<endl;
393 else cout <<"Polygons are displayed only if there is no geometric representation"<<endl;
398 for (i = 1; i <= n-1; i++) {
399 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
401 Handle(DBRep_DrawableShape) d2 =
402 Handle(DBRep_DrawableShape)::DownCast(d1);
404 d2->DisplayPolygons(!(d2->DisplayPolygons()));
415 //=======================================================================
417 //=======================================================================
419 static Standard_Integer compound(Draw_Interpretor& ,
420 Standard_Integer n, const char** a)
422 if (n <= 1) return 1;
426 for (Standard_Integer i = 1; i < n-1; i++) {
427 TopoDS_Shape S2 = DBRep::Get(a[i]);
428 if (!S2.IsNull()) B.Add(C,S2);
430 DBRep::Set(a[n-1],C);
434 //=======================================================================
436 //=======================================================================
438 static Standard_Integer emptycopy(Draw_Interpretor& ,
439 Standard_Integer n, const char** a)
441 if (n <= 1) return 1;
442 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
443 if (S.IsNull()) return 1;
449 //=======================================================================
451 //=======================================================================
453 static Standard_Integer add(Draw_Interpretor& ,
454 Standard_Integer n, const char** a)
458 TopoDS_Shape S1 = DBRep::Get(a[1]);
459 if (S1.IsNull()) return 1;
460 TopoDS_Shape S2 = DBRep::Get(a[2]);
461 if (S2.IsNull()) return 1;
467 //=======================================================================
469 //=======================================================================
471 static Standard_Integer explode(Draw_Interpretor& di,
472 Standard_Integer n, const char** a)
474 if (n <= 1) return 1;
475 TopoDS_Shape S = DBRep::Get(a[1]);
476 if (S.IsNull()) return 0;
478 strcpy(newname,a[1]);
480 while (*p != '\0') p++;
483 Standard_Integer i = 0;
485 TopoDS_Iterator itr(S);
489 DBRep::Set(newname,itr.Value());
490 di.AppendElement(newname);
496 TopAbs_ShapeEnum typ;
501 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
502 typ = TopAbs_COMPOUND;
504 typ = TopAbs_COMPSOLID;
509 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
511 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
541 TopTools_MapOfShape M;
543 TopExp_Explorer ex(S,typ);
544 for (; ex.More(); ex.Next()) {
545 const TopoDS_Shape& Sx = ex.Current();
546 Standard_Boolean added = M.Add(Sx);
550 DBRep::Set(newname,Sx);
551 di.AppendElement(newname);
558 //=======================================================================
559 // nexplode : stable numbered explode (from Serguey Nizhny)
560 //=======================================================================
562 static Standard_Integer nexplode(Draw_Interpretor& di,
563 Standard_Integer n, const char** a)
565 if (n <= 2) return 1;
566 TopoDS_Shape S = DBRep::Get(a[1]);
567 if (S.IsNull()) return 0;
569 strcpy(newname,a[1]);
571 while (*p != '\0') p++;
574 TopAbs_ShapeEnum typ;
590 TopTools_IndexedMapOfShape IMOStmp;
591 TopTools_MapOfShape MShape;
593 TopExp::MapShapes(S,typ,IMOStmp);
594 TopExp_Explorer Exp(S,typ);
595 Standard_Integer MaxShapes, Index = 0;
596 MaxShapes = IMOStmp.Extent()-1;
597 TopTools_Array1OfShape aShapes(1,MaxShapes);
601 if (MShape.Add(Exp.Current())) {
603 aShapes.SetValue(Index,Exp.Current());
608 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
611 // Standard_Integer InOfminX = 1,aTemp;
612 Standard_Integer aTemp;
613 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
614 Standard_Boolean NoSort = Standard_True;
616 // Computing of CentreOfMass
617 for (Index=1; Index <= MaxShapes; Index++) {
618 OrderInd.SetValue(Index,Index);
619 BRepGProp::LinearProperties(aShapes(Index),GPr);
620 gp_Pnt GPoint = GPr.CentreOfMass();
621 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
626 NoSort = Standard_False;
627 for (Index=1; Index < MaxShapes; Index++) {
628 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
629 aTemp = OrderInd(Index);
630 OrderInd(Index) = OrderInd(Index+1);
631 OrderInd(Index+1) = aTemp;
632 NoSort = Standard_True;
636 // Check of equality of MidXYZ
637 for (Index=1; Index < MaxShapes; Index++) {
638 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
639 di<<"Warning! For this shape the results may be incorrect."<<"\n";
642 for (Index=1 ;Index <= MaxShapes; Index++) {
643 Sprintf(p,"%d",Index);
644 DBRep::Set(newname,aShapes(OrderInd(Index)));
645 di.AppendElement(newname);
651 //=======================================================================
653 //=======================================================================
655 static Standard_Integer exwire(Draw_Interpretor& ,
656 Standard_Integer n, const char** a)
658 if (n <= 1) return 1;
659 TopoDS_Shape S = DBRep::Get(a[1]);
660 if (S.IsNull()) return 0;
661 if (S.ShapeType() != TopAbs_WIRE) return 0;
663 strcpy(newname,a[1]);
665 while (*p != '\0') p++;
668 Standard_Integer i = 0;
669 BRepTools_WireExplorer ex(TopoDS::Wire(S));
673 DBRep::Set(newname,ex.Current());
679 //=======================================================================
681 //=======================================================================
683 static Standard_Integer invert(Draw_Interpretor& ,
684 Standard_Integer n, const char** a)
686 if (n <= 1) return 1;
687 TopoDS_Shape S = DBRep::Get(a[1]);
688 if (S.IsNull()) return 0;
691 TopoDS_Shape NS = S.EmptyCopied();
692 NS.Closed (S.Closed());
694 TopoDS_Iterator itr(S);
696 B.Add(NS,itr.Value().Reversed());
704 //=======================================================================
705 // orientation, reverse, complement
706 //=======================================================================
708 static Standard_Integer orientation(Draw_Interpretor& ,
709 Standard_Integer n, const char** a)
711 if (n <= 1) return 1;
712 Standard_Integer cas = 0;
713 TopAbs_Orientation ori=TopAbs_FORWARD;
714 Standard_Integer last = n;
715 if (!strcasecmp(a[0],"orientation")) {
716 if (n <= 2) return 1;
721 ori = TopAbs_FORWARD;
725 ori = TopAbs_REVERSED;
729 ori = TopAbs_INTERNAL;
733 ori = TopAbs_EXTERNAL;
738 else if (!strcasecmp(a[0],"treverse")) {
742 else if (!strcasecmp(a[0],"complement")) {
746 for (Standard_Integer i = 1; i < last; i++) {
747 TopoDS_Shape S = DBRep::Get(a[i]);
761 #include <TCollection_AsciiString.hxx>
763 //=======================================================================
764 // numshapes same as nbshapes but the output is cout
765 //=======================================================================
767 static Standard_Integer numshapes(Draw_Interpretor& di,
768 Standard_Integer n, const char** a)
774 for (i = 1; i < n; i++) {
775 TopoDS_Shape S = DBRep::Get(a[i]);
777 BRepTools_ShapeSet BS;
779 di <<"Number of shapes in "<<a[i]<<"\n";
780 TCollection_AsciiString Astr;
782 di <<Astr.ToCString();
790 //=======================================================================
791 // function : DumpExtent
792 // purpose : Dumps the number of sub-shapes in <aStr>.
793 //=======================================================================
794 static void DumpExtent(const TopoDS_Shape& aS,
795 TCollection_AsciiString& aStr)
797 const int aNbTypes=8;
798 const char *pNames[aNbTypes+1]={
809 Standard_Integer i, aNb, aNbSh;
810 TopAbs_ShapeEnum aType;
811 TopTools_IndexedMapOfShape aM;
815 for (i=aNbTypes-1; i>=0; --i) {
817 aType=(TopAbs_ShapeEnum)i;
818 TopExp::MapShapes(aS, aType, aM);
820 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
823 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
826 //=======================================================================
828 //=======================================================================
830 static Standard_Integer nbshapes(Draw_Interpretor& di,
831 Standard_Integer n, const char** a)
836 Standard_Boolean aTotal;
839 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
841 for (i = 1; i < n; i++) {
842 TopoDS_Shape S = DBRep::Get(a[i]);
844 di<<"Number of shapes in "<<a[i]<<"\n";
845 TCollection_AsciiString Astr;
849 BRepTools_ShapeSet BS;
853 di<<Astr.ToCString();
860 //=======================================================================
862 //=======================================================================
864 static Standard_Integer countshapes(Draw_Interpretor& di,
865 Standard_Integer n, const char** a)
871 for (i = 1; i < n; i++) {
872 TopoDS_Shape Sh = DBRep::Get(a[i]);
873 Standard_Integer nbElem = 0;
875 di <<"Number of shapes in "<<a[i]<<"\n";
876 TopTools_MapOfShape M;
878 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
879 const TopoDS_Shape& S = ex.Current();
880 Standard_Boolean added = M.Add(S);
885 di << " VERTEX : " << nbElem << "\n";
888 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
889 const TopoDS_Shape& S = ex.Current();
890 Standard_Boolean added = M.Add(S);
895 di << " EDGE : " << nbElem << "\n";
898 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
899 const TopoDS_Shape& S = ex.Current();
900 Standard_Boolean added = M.Add(S);
905 di << " WIRE : " << nbElem << "\n";
908 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
909 const TopoDS_Shape& S = ex.Current();
910 Standard_Boolean added = M.Add(S);
915 di << " FACE : " << nbElem << "\n";
918 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
919 const TopoDS_Shape& S = ex.Current();
920 Standard_Boolean added = M.Add(S);
925 di << " SHELL : " << nbElem << "\n";
928 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
929 const TopoDS_Shape& S = ex.Current();
930 Standard_Boolean added = M.Add(S);
935 di << " SOLID : " << nbElem << "\n";
938 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
939 const TopoDS_Shape& S = ex.Current();
940 Standard_Boolean added = M.Add(S);
945 di << " COMPSOLID : " << nbElem << "\n";
948 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
949 const TopoDS_Shape& S = ex.Current();
950 Standard_Boolean added = M.Add(S);
955 di << " COMPOUND : " << nbElem << "\n";
958 di << " SHAPE : " << M.Extent() << "\n";
966 //=======================================================================
968 //=======================================================================
969 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
972 for(i = 2; i < n; i++) {
973 if (strstr ( a[i], "free" )) {
975 Sh.Free(Standard_False);
978 Sh.Free(Standard_True);
981 if (strstr ( a[i], "modified" )) {
983 Sh.Modified(Standard_False);
986 Sh.Modified(Standard_True);
989 if (strstr ( a[i], "checked" )) {
991 Sh.Checked(Standard_False);
994 Sh.Checked(Standard_True);
997 if (strstr ( a[i], "orientable" )) {
999 Sh.Orientable(Standard_False);
1002 Sh.Orientable(Standard_True);
1005 if (strstr ( a[i], "closed" )) {
1006 if(a[i][0] == '-') {
1007 Sh.Closed(Standard_False);
1010 Sh.Closed(Standard_True);
1013 if (strstr ( a[i], "infinite" )) {
1014 if(a[i][0] == '-') {
1015 Sh.Infinite(Standard_False);
1018 Sh.Infinite(Standard_True);
1021 if (strstr ( a[i], "convex" )) {
1022 if(a[i][0] == '-') {
1023 Sh.Convex(Standard_False);
1026 Sh.Convex(Standard_True);
1029 if (strstr ( a[i], "locked" )) {
1030 if(a[i][0] == '-') {
1031 Sh.Locked(Standard_False);
1034 Sh.Locked(Standard_True);
1040 //=======================================================================
1042 //=======================================================================
1043 static Standard_Integer setFlags(Draw_Interpretor& ,
1044 Standard_Integer n, const char** a)
1046 if (n < 3) return 1;
1049 TopoDS_Shape Sh = DBRep::Get(a[1]);
1051 if (Sh.IsNull()) return 1;
1054 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1055 TopoDS_Shape S = ex.Current();
1059 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1060 TopoDS_Shape S = ex.Current();
1064 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1065 TopoDS_Shape S = ex.Current();
1072 //=======================================================================
1074 //=======================================================================
1075 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1079 //=======================================================================
1081 //=======================================================================
1083 //=======================================================================
1085 static Standard_Integer check(Draw_Interpretor& ,
1086 Standard_Integer n, const char** a)
1088 if (n < 2) return 1;
1092 for (i = 1; i < n; i++) {
1093 TopoDS_Shape S = DBRep::Get(a[i]);
1095 if (S.IsNull()) continue;
1096 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1098 C.Checked(Standard_False);
1099 BRepTools::Update(C);
1106 //=======================================================================
1108 //=======================================================================
1110 static Standard_Integer normals(Draw_Interpretor& di,
1111 Standard_Integer n, const char** a)
1113 if (n <= 1) return 1;
1114 Standard_Real l = 1.;
1116 l = Draw::Atof(a[2]);
1118 TopoDS_Shape S = DBRep::Get(a[1]);
1119 if (S.IsNull()) return 1;
1121 DBRep_WriteColorOrientation();
1127 TopExp_Explorer ex(S,TopAbs_FACE);
1130 const TopoDS_Face& F = TopoDS::Face(ex.Current());
1132 // find the center of the minmax
1133 BRepAdaptor_Surface SF(F);
1135 Standard_Real u, v, x;
1137 u = SF.FirstUParameter();
1138 x = SF.LastUParameter();
1139 if (Precision::IsInfinite(u))
1140 u = (Precision::IsInfinite(x)) ? 0. : x;
1141 else if (!Precision::IsInfinite(x))
1144 v = SF.FirstVParameter();
1145 x = SF.LastVParameter();
1146 if (Precision::IsInfinite(v))
1147 v = (Precision::IsInfinite(x)) ? 0. : x;
1148 else if (!Precision::IsInfinite(x))
1151 SF.D1(u,v,P1,V1,V2);
1157 V.SetCoord(l/2.,0,0);
1158 di << "Null normal"<< "\n";
1164 col = DBRep_ColorOrientation(F.Orientation());
1166 Handle(Draw_Segment3D) seg = new Draw_Segment3D(P1,P2,col);
1176 //=======================================================================
1179 //=======================================================================
1180 void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1182 Handle(DBRep_DrawableShape) D =
1183 new DBRep_DrawableShape(S,
1191 D->DisplayTriangulation(disptriangles);
1192 D->DisplayPolygons(disppolygons);
1193 D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1196 //=======================================================================
1199 //=======================================================================
1200 TopoDS_Shape DBRep::Get(Standard_CString& name,
1201 const TopAbs_ShapeEnum typ,
1202 const Standard_Boolean complain)
1204 Standard_Boolean pick = name[0] == '.';
1206 Handle(DBRep_DrawableShape) D;
1207 Handle(Draw_Drawable3D) DD = Draw::Get(name,complain);
1209 D = Handle(DBRep_DrawableShape)::DownCast(DD);
1212 if (typ != TopAbs_SHAPE) {
1213 if (typ != S.ShapeType()) {
1214 // try to find prom pick
1217 DBRep_DrawableShape::LastPick(S,u,v);
1220 if (typ != S.ShapeType()) {
1222 cout << name << " is not a ";
1223 TopAbs::Print(typ,cout);
1225 TopAbs::Print(S.ShapeType(),cout);
1235 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1237 for ( Standard_Integer i=1; i < argc; i++ ) {
1238 Standard_Boolean turn = Standard_True;
1239 if ( argv[i][0] == '-' ) turn = Standard_False;
1240 else if ( argv[i][0] != '+' ) continue;
1241 if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn;
1242 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1243 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc ) {
1244 Standard_Address aPtr = 0;
1245 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1246 Draw_ProgressIndicator::StopIndicator() = aPtr;
1250 di << "Progress Indicator defaults: text mode is ";
1251 if ( Draw_ProgressIndicator::DefaultTextMode() ) {
1256 di<<", graphical mode is ";
1257 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1266 //=======================================================================
1267 //function : BasicCommands
1269 //=======================================================================
1271 static Standard_Boolean done = Standard_False;
1272 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1275 done = Standard_True;
1276 Draw::Commands(theCommands);
1278 const char* g = "Basic shape commands";
1280 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1281 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1282 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1283 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1284 theCommands.Add("tclean", "tclean [name1]..., erase triangulations and polygons on triangulations from shapes",__FILE__, tclean, g);
1285 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1286 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1287 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1288 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1289 theCommands.Add("add","add name1 name2",__FILE__,add,g);
1290 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1291 theCommands.Add("nexplode","stable numbered explode for edge and face: nexplode name [F/E]",__FILE__,nexplode,g);
1292 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1293 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1294 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1296 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1297 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1298 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1299 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1300 theCommands.Add("normals","normals s (length = 10), disp normals",__FILE__,normals,g);
1301 theCommands.Add("nbshapes",
1302 "\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.",
1303 __FILE__,nbshapes,g);
1304 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1305 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1306 theCommands.Add("setflags",
1307 "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 ",
1308 __FILE__,setFlags,g);
1310 // theCommands.Add("dumpmmgt",
1311 // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1312 theCommands.Add("purgemmgt",
1313 "returns the free memory from the system to the memory manager",
1314 __FILE__,purgemmgt,g);
1316 // Add command for DRAW-specific ProgressIndicator
1317 theCommands.Add ( "XProgress","XProgress [+|-t] [+|-g]: switch on/off textual and graphical mode of Progress Indicator",XProgress,"DE: General");
1320 //=======================================================================
1321 //function : HLRMode
1323 //=======================================================================
1325 Standard_Boolean DBRep::HLRMode()
1328 //=======================================================================
1329 //function : Rg1Mode
1331 //=======================================================================
1333 Standard_Boolean DBRep::Rg1Mode()
1336 //=======================================================================
1337 //function : RgNMode
1339 //=======================================================================
1341 Standard_Boolean DBRep::RgNMode()
1344 //=======================================================================
1345 //function : HidMode
1347 //=======================================================================
1349 Standard_Boolean DBRep::HidMode()
1352 //=======================================================================
1353 //function : HLRAngle
1355 //=======================================================================
1357 Standard_Real DBRep::HLRAngle()
1360 //=======================================================================
1362 //purpose : save and restore shapes
1363 //=======================================================================
1365 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
1367 return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1370 static void ssave(const Handle(Draw_Drawable3D)&d, ostream& OS)
1372 Handle(DBRep_DrawableShape)
1373 N = Handle(DBRep_DrawableShape)::DownCast(d);
1375 BRepTools_ShapeSet S(B);
1376 if(!Draw::GetProgressBar().IsNull())
1377 S.SetProgress(Draw::GetProgressBar());
1380 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1382 S.Write(N->Shape(),OS);
1385 static Handle(Draw_Drawable3D) srestore (istream& IS)
1388 BRepTools_ShapeSet S(B);
1389 if(!Draw::GetProgressBar().IsNull())
1390 S.SetProgress(Draw::GetProgressBar());
1392 Handle(DBRep_DrawableShape) N;
1393 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1395 TopoDS_Shape theShape;
1396 S.Read(theShape,IS );
1397 N = new DBRep_DrawableShape(theShape,
1405 N->DisplayTriangulation(disptriangles);
1406 N->DisplayPolygons(disppolygons);
1407 N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1413 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1414 stest,ssave,srestore);
1417 void dumps (const TopoDS_Shape& S)
1419 BRepTools::Dump(S,cout);
1422 //=======================================================================
1425 //=======================================================================
1427 Standard_Integer DBRep::NbIsos()
1431 //=======================================================================
1432 //function : Discretisation
1434 //=======================================================================
1436 Standard_Integer DBRep::Discretisation()