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 std::cout << "\nrouge FORWARD";
68 std::cout << "\nbleu REVERSED";
69 std::cout << "\nrose EXTERNAL";
70 std::cout << "\norange INTERNAL"<<std::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) std::cout <<"Triangulations are always displayed"<<std::endl;
345 else std::cout <<"Triangulations are displayed only if there is no geometric representation"<<std::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)
373 if (n == 1) return 1;
375 Standard_Integer aStart = 1;
376 Standard_Boolean toRemoveGeometry = Standard_False;
377 if (strcmp(a[1], "-geom") == 0)
380 toRemoveGeometry = Standard_True;
383 for (Standard_Integer i = aStart; i < n; i++) {
384 TopoDS_Shape S = DBRep::Get(a[i]);
385 if (toRemoveGeometry)
386 BRepTools::CleanGeometry(S);
393 //=======================================================================
395 //=======================================================================
397 static Standard_Integer polygons(Draw_Interpretor& ,
398 Standard_Integer n, const char** a)
403 disppolygons = !disppolygons;
405 if (disppolygons) std::cout <<"Polygons are always displayed"<<std::endl;
406 else std::cout <<"Polygons are displayed only if there is no geometric representation"<<std::endl;
411 for (i = 1; i <= n-1; i++) {
412 Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
414 Handle(DBRep_DrawableShape) d2 =
415 Handle(DBRep_DrawableShape)::DownCast(d1);
417 d2->DisplayPolygons(!(d2->DisplayPolygons()));
428 //=======================================================================
430 //=======================================================================
432 static Standard_Integer compound(Draw_Interpretor& ,
433 Standard_Integer n, const char** a)
435 if (n <= 1) return 1;
439 for (Standard_Integer i = 1; i < n-1; i++) {
440 TopoDS_Shape S2 = DBRep::Get(a[i]);
441 if (!S2.IsNull()) B.Add(C,S2);
443 DBRep::Set(a[n-1],C);
447 //=======================================================================
449 //=======================================================================
451 static Standard_Integer emptycopy(Draw_Interpretor& ,
452 Standard_Integer n, const char** a)
454 if (n <= 1) return 1;
455 TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
456 if (S.IsNull()) return 1;
462 //=======================================================================
464 //=======================================================================
466 static Standard_Integer add(Draw_Interpretor& ,
467 Standard_Integer n, const char** a)
471 TopoDS_Shape S1 = DBRep::Get(a[1]);
472 if (S1.IsNull()) return 1;
473 TopoDS_Shape S2 = DBRep::Get(a[2]);
474 if (S2.IsNull()) return 1;
480 //=======================================================================
482 //=======================================================================
484 static Standard_Integer explode(Draw_Interpretor& di,
485 Standard_Integer n, const char** a)
487 if (n <= 1) return 1;
488 TopoDS_Shape S = DBRep::Get(a[1]);
489 if (S.IsNull()) return 0;
491 strcpy(newname,a[1]);
493 while (*p != '\0') p++;
496 Standard_Integer i = 0;
498 TopoDS_Iterator itr(S);
502 DBRep::Set(newname,itr.Value());
503 di.AppendElement(newname);
509 TopAbs_ShapeEnum typ;
514 if ((a[2][1] == 'd')||(a[2][1] == 'D'))
515 typ = TopAbs_COMPOUND;
517 typ = TopAbs_COMPSOLID;
522 if ((a[2][1] == 'O')||(a[2][1] == 'o'))
524 else if ((a[2][1] == 'H')||(a[2][1] == 'h'))
554 TopTools_MapOfShape M;
556 TopExp_Explorer ex(S,typ);
557 for (; ex.More(); ex.Next()) {
558 const TopoDS_Shape& Sx = ex.Current();
559 Standard_Boolean added = M.Add(Sx);
563 DBRep::Set(newname,Sx);
564 di.AppendElement(newname);
571 //=======================================================================
572 // nexplode : stable numbered explode (from Serguey Nizhny)
573 //=======================================================================
575 static Standard_Integer nexplode(Draw_Interpretor& di,
576 Standard_Integer n, const char** a)
578 if (n <= 2) return 1;
579 TopoDS_Shape S = DBRep::Get(a[1]);
580 if (S.IsNull()) return 0;
582 strcpy(newname,a[1]);
584 while (*p != '\0') p++;
587 TopAbs_ShapeEnum typ;
608 TopTools_IndexedMapOfShape IMOStmp;
609 TopTools_MapOfShape MShape;
611 TopExp::MapShapes(S,typ,IMOStmp);
612 TopExp_Explorer Exp(S,typ);
613 Standard_Integer MaxShapes, Index = 0;
614 MaxShapes = IMOStmp.Extent()-1;
615 TopTools_Array1OfShape aShapes(1,MaxShapes);
619 if (MShape.Add(Exp.Current())) {
621 aShapes.SetValue(Index,Exp.Current());
626 TColStd_Array1OfInteger OrderInd(1,MaxShapes);
629 Standard_Integer aTemp;
630 TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
631 Standard_Boolean NoSort = Standard_True;
633 // Computing of CentreOfMass for edge and face
634 // and for vertex use its point
635 for (Index=1; Index <= MaxShapes; Index++) {
636 OrderInd.SetValue(Index,Index);
637 const TopoDS_Shape& aS = aShapes(Index);
638 if (aS.ShapeType() != TopAbs_VERTEX) {
639 BRepGProp::LinearProperties(aS, GPr);
640 GPoint = GPr.CentreOfMass();
643 GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
645 MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
650 NoSort = Standard_False;
651 for (Index=1; Index < MaxShapes; Index++) {
652 if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
653 aTemp = OrderInd(Index);
654 OrderInd(Index) = OrderInd(Index+1);
655 OrderInd(Index+1) = aTemp;
656 NoSort = Standard_True;
660 // Check of equality of MidXYZ
661 for (Index=1; Index < MaxShapes; Index++) {
662 if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
663 di<<"Warning! For this shape the results may be incorrect.\n";
666 for (Index=1 ;Index <= MaxShapes; Index++) {
667 Sprintf(p,"%d",Index);
668 DBRep::Set(newname,aShapes(OrderInd(Index)));
669 di.AppendElement(newname);
675 //=======================================================================
677 //=======================================================================
679 static Standard_Integer exwire(Draw_Interpretor& ,
680 Standard_Integer n, const char** a)
682 if (n <= 1) return 1;
683 TopoDS_Shape S = DBRep::Get(a[1]);
684 if (S.IsNull()) return 0;
685 if (S.ShapeType() != TopAbs_WIRE) return 0;
687 strcpy(newname,a[1]);
689 while (*p != '\0') p++;
692 Standard_Integer i = 0;
693 BRepTools_WireExplorer ex(TopoDS::Wire(S));
697 DBRep::Set(newname,ex.Current());
703 //=======================================================================
705 //=======================================================================
707 static Standard_Integer invert(Draw_Interpretor& ,
708 Standard_Integer n, const char** a)
710 if (n <= 1) return 1;
711 TopoDS_Shape S = DBRep::Get(a[1]);
712 if (S.IsNull()) return 0;
715 TopoDS_Shape NS = S.EmptyCopied();
716 NS.Closed (S.Closed());
718 TopoDS_Iterator itr(S);
720 B.Add(NS,itr.Value().Reversed());
728 //=======================================================================
729 // orientation, reverse, complement
730 //=======================================================================
732 static Standard_Integer orientation(Draw_Interpretor& ,
733 Standard_Integer n, const char** a)
735 if (n <= 1) return 1;
736 Standard_Integer cas = 0;
737 TopAbs_Orientation ori=TopAbs_FORWARD;
738 Standard_Integer last = n;
739 if (!strcasecmp(a[0],"orientation")) {
740 if (n <= 2) return 1;
745 ori = TopAbs_FORWARD;
749 ori = TopAbs_REVERSED;
753 ori = TopAbs_INTERNAL;
757 ori = TopAbs_EXTERNAL;
762 else if (!strcasecmp(a[0],"treverse")) {
766 else if (!strcasecmp(a[0],"complement")) {
770 for (Standard_Integer i = 1; i < last; i++) {
771 TopoDS_Shape S = DBRep::Get(a[i]);
785 #include <TCollection_AsciiString.hxx>
787 //=======================================================================
788 // numshapes same as nbshapes but the output is cout
789 //=======================================================================
791 static Standard_Integer numshapes(Draw_Interpretor& di,
792 Standard_Integer n, const char** a)
798 for (i = 1; i < n; i++) {
799 TopoDS_Shape S = DBRep::Get(a[i]);
801 BRepTools_ShapeSet BS;
803 di <<"Number of shapes in "<<a[i]<<"\n";
804 TCollection_AsciiString Astr;
806 di <<Astr.ToCString();
814 //=======================================================================
815 // function : DumpExtent
816 // purpose : Dumps the number of sub-shapes in <aStr>.
817 //=======================================================================
818 static void DumpExtent(const TopoDS_Shape& aS,
819 TCollection_AsciiString& aStr)
821 const int aNbTypes=8;
822 const char *pNames[aNbTypes+1]={
833 Standard_Integer i, aNb, aNbSh;
834 TopAbs_ShapeEnum aType;
835 TopTools_IndexedMapOfShape aM;
839 for (i=aNbTypes-1; i>=0; --i) {
841 aType=(TopAbs_ShapeEnum)i;
842 TopExp::MapShapes(aS, aType, aM);
844 aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
847 aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
850 //=======================================================================
852 //=======================================================================
854 static Standard_Integer nbshapes(Draw_Interpretor& di,
855 Standard_Integer n, const char** a)
860 Standard_Boolean aTotal;
863 aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
865 for (i = 1; i < n; i++) {
866 TopoDS_Shape S = DBRep::Get(a[i]);
868 di<<"Number of shapes in "<<a[i]<<"\n";
869 TCollection_AsciiString Astr;
873 BRepTools_ShapeSet BS;
877 di<<Astr.ToCString();
884 //=======================================================================
886 //=======================================================================
888 static Standard_Integer countshapes(Draw_Interpretor& di,
889 Standard_Integer n, const char** a)
895 for (i = 1; i < n; i++) {
896 TopoDS_Shape Sh = DBRep::Get(a[i]);
897 Standard_Integer nbElem = 0;
899 di <<"Number of shapes in "<<a[i]<<"\n";
900 TopTools_MapOfShape M;
902 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
903 const TopoDS_Shape& S = ex.Current();
904 Standard_Boolean added = M.Add(S);
909 di << " VERTEX : " << nbElem << "\n";
912 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
913 const TopoDS_Shape& S = ex.Current();
914 Standard_Boolean added = M.Add(S);
919 di << " EDGE : " << nbElem << "\n";
922 for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
923 const TopoDS_Shape& S = ex.Current();
924 Standard_Boolean added = M.Add(S);
929 di << " WIRE : " << nbElem << "\n";
932 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
933 const TopoDS_Shape& S = ex.Current();
934 Standard_Boolean added = M.Add(S);
939 di << " FACE : " << nbElem << "\n";
942 for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
943 const TopoDS_Shape& S = ex.Current();
944 Standard_Boolean added = M.Add(S);
949 di << " SHELL : " << nbElem << "\n";
952 for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
953 const TopoDS_Shape& S = ex.Current();
954 Standard_Boolean added = M.Add(S);
959 di << " SOLID : " << nbElem << "\n";
962 for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
963 const TopoDS_Shape& S = ex.Current();
964 Standard_Boolean added = M.Add(S);
969 di << " COMPSOLID : " << nbElem << "\n";
972 for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
973 const TopoDS_Shape& S = ex.Current();
974 Standard_Boolean added = M.Add(S);
979 di << " COMPOUND : " << nbElem << "\n";
982 di << " SHAPE : " << M.Extent() << "\n";
990 //=======================================================================
992 //=======================================================================
993 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
996 for(i = 2; i < n; i++) {
997 if (strstr ( a[i], "free" )) {
999 Sh.Free(Standard_False);
1002 Sh.Free(Standard_True);
1005 if (strstr ( a[i], "modified" )) {
1006 if(a[i][0] == '-') {
1007 Sh.Modified(Standard_False);
1010 Sh.Modified(Standard_True);
1013 if (strstr ( a[i], "checked" )) {
1014 if(a[i][0] == '-') {
1015 Sh.Checked(Standard_False);
1018 Sh.Checked(Standard_True);
1021 if (strstr ( a[i], "orientable" )) {
1022 if(a[i][0] == '-') {
1023 Sh.Orientable(Standard_False);
1026 Sh.Orientable(Standard_True);
1029 if (strstr ( a[i], "closed" )) {
1030 if(a[i][0] == '-') {
1031 Sh.Closed(Standard_False);
1034 Sh.Closed(Standard_True);
1037 if (strstr ( a[i], "infinite" )) {
1038 if(a[i][0] == '-') {
1039 Sh.Infinite(Standard_False);
1042 Sh.Infinite(Standard_True);
1045 if (strstr ( a[i], "convex" )) {
1046 if(a[i][0] == '-') {
1047 Sh.Convex(Standard_False);
1050 Sh.Convex(Standard_True);
1053 if (strstr ( a[i], "locked" )) {
1054 if(a[i][0] == '-') {
1055 Sh.Locked(Standard_False);
1058 Sh.Locked(Standard_True);
1064 //=======================================================================
1066 //=======================================================================
1067 static Standard_Integer setFlags(Draw_Interpretor& ,
1068 Standard_Integer n, const char** a)
1070 if (n < 3) return 1;
1073 TopoDS_Shape Sh = DBRep::Get(a[1]);
1075 if (Sh.IsNull()) return 1;
1078 for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1079 TopoDS_Shape S = ex.Current();
1083 for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1084 TopoDS_Shape S = ex.Current();
1088 for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1089 TopoDS_Shape S = ex.Current();
1096 //=======================================================================
1098 //=======================================================================
1099 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1103 //=======================================================================
1105 //=======================================================================
1107 //=======================================================================
1109 static Standard_Integer check(Draw_Interpretor& ,
1110 Standard_Integer n, const char** a)
1112 if (n < 2) return 1;
1116 for (i = 1; i < n; i++) {
1117 TopoDS_Shape S = DBRep::Get(a[i]);
1119 if (S.IsNull()) continue;
1120 for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1122 C.Checked(Standard_False);
1123 BRepTools::Update(C);
1130 //=======================================================================
1132 //=======================================================================
1133 static Standard_Integer normals (Draw_Interpretor& theDI,
1134 Standard_Integer theArgNum,
1135 const char** theArgs)
1139 std::cout << "Syntax error: wrong number of arguments!\n";
1140 theDI.PrintHelp (theArgs[0]);
1144 TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1145 if (aShape.IsNull())
1147 std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1151 Standard_Boolean toUseMesh = Standard_False;
1152 Standard_Real aLength = 10.0;
1153 Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1154 Standard_Boolean bPrint = Standard_False;
1155 for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1157 TCollection_AsciiString aParam (theArgs[anArgIter]);
1160 && aParam.IsRealValue())
1162 aLength = aParam.RealValue();
1163 if (Abs (aLength) <= gp::Resolution())
1165 std::cout << "Syntax error: length should not be zero\n";
1169 else if (aParam == "-usemesh"
1170 || aParam == "-mesh")
1172 toUseMesh = Standard_True;
1174 else if (aParam == "-length"
1175 || aParam == "-len")
1178 aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1179 if (Abs(aLength) <= gp::Resolution())
1181 std::cout << "Syntax error: length should not be zero\n";
1185 else if (aParam == "-nbalongu"
1186 || aParam == "-nbu")
1189 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1192 std::cout << "Syntax error: NbAlongU should be >=1\n";
1196 else if (aParam == "-nbalongv"
1197 || aParam == "-nbv")
1200 aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1203 std::cout << "Syntax error: NbAlongV should be >=1\n";
1207 else if (aParam == "-nbalong"
1208 || aParam == "-nbuv")
1211 aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1212 aNbAlongV = aNbAlongU;
1215 std::cout << "Syntax error: NbAlong should be >=1\n";
1219 else if (aParam == "-print")
1221 bPrint = Standard_True;
1225 std::cout << "Syntax error: unknown argument '" << aParam << "'\n";
1230 DBRep_WriteColorOrientation();
1232 NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1235 DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1239 DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1242 for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1244 Standard_Boolean bReverse = Standard_False;
1245 TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation();
1246 const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri);
1247 if (aFaceOri == TopAbs_REVERSED)
1248 bReverse = Standard_True;
1250 for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1252 const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1253 Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1257 // Make the normal vector from the points
1258 gp_Vec aV(aVec.first, aVec.second);
1262 // Print values of the vector avoiding printing "-0" values
1263 theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", "
1264 << (aV.Y() == 0 ? 0 : aV.Y()) << ", "
1265 << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n";
1273 //=======================================================================
1276 //=======================================================================
1277 void DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1279 Handle(DBRep_DrawableShape) D =
1280 new DBRep_DrawableShape(S,
1288 D->DisplayTriangulation(disptriangles);
1289 D->DisplayPolygons(disppolygons);
1290 D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1293 //=======================================================================
1294 //function : getShape
1296 //=======================================================================
1297 TopoDS_Shape DBRep::getShape (Standard_CString& theName,
1298 TopAbs_ShapeEnum theType,
1299 Standard_Boolean theToComplain)
1301 const Standard_Boolean toPick = theName[0] == '.';
1302 Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
1303 if (aDrawable.IsNull())
1305 return TopoDS_Shape();
1308 TopoDS_Shape aShape = aDrawable->Shape();
1309 if (theType != TopAbs_SHAPE
1310 && theType != aShape.ShapeType()
1313 // try to find prom pick
1315 DBRep_DrawableShape::LastPick (aShape, u, v);
1317 if (theType != TopAbs_SHAPE
1318 && theType != aShape.ShapeType())
1322 std::cout << theName << " is not a ";
1323 TopAbs::Print (theType, std::cout);
1324 std::cout << " but a ";
1325 TopAbs::Print (aShape.ShapeType(), std::cout);
1326 std::cout << std::endl;
1328 return TopoDS_Shape();
1333 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1335 for ( Standard_Integer i=1; i < argc; i++ )
1337 Standard_Boolean turn = Standard_True;
1338 if ( argv[i][0] == '-' ) turn = Standard_False;
1339 else if ( argv[i][0] != '+' ) continue;
1341 TCollection_AsciiString anArgCase (argv[i]);
1342 anArgCase.LowerCase();
1343 if (anArgCase == "-tcloutput")
1345 Draw_ProgressIndicator::DefaultTclOutput() = Standard_True;
1348 else if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTextMode() = turn;
1349 else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1350 else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
1352 Standard_Address aPtr = 0;
1353 if (sscanf (argv[++i], "%p", &aPtr) == 1)
1354 Draw_ProgressIndicator::StopIndicator() = aPtr;
1358 di << "Progress Indicator defaults: text mode is ";
1359 if ( Draw_ProgressIndicator::DefaultTextMode() ) {
1364 di<<", graphical mode is ";
1365 if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1374 //=======================================================================
1376 //=======================================================================
1378 static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a)
1380 if (n <= 2) return 1;
1382 TopoDS_Shape aShape = DBRep::Get (a[1]);
1383 if (aShape.IsNull())
1385 di << a[1] << " is not a shape";
1389 if (!BinTools::Write (aShape, a[2]))
1391 di << "Cannot write to the file " << a[2];
1399 //=======================================================================
1401 //=======================================================================
1403 static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a)
1405 if (n <= 2) return 1;
1407 TopoDS_Shape aShape;
1408 if (!BinTools::Read (aShape, a[1]))
1410 di << "Cannot read from the file " << a[1];
1414 DBRep::Set (a[2], aShape);
1419 //=======================================================================
1421 //=======================================================================
1422 static Standard_Integer removeInternals (Draw_Interpretor& di,
1428 di.PrintHelp (a[0]);
1432 TopoDS_Shape aShape = DBRep::Get (a[1]);
1433 if (aShape.IsNull())
1435 di << a[1] << "is a null shape\n";
1439 Standard_Boolean isForce = Standard_False;
1442 isForce = (Draw::Atoi (a[2]) != 0);
1445 BRepTools::RemoveInternals (aShape, isForce);
1447 DBRep::Set (a[1], aShape);
1452 //=======================================================================
1453 //function : BasicCommands
1455 //=======================================================================
1457 static Standard_Boolean done = Standard_False;
1458 void DBRep::BasicCommands(Draw_Interpretor& theCommands)
1461 done = Standard_True;
1462 Draw::Commands(theCommands);
1464 const char* g = "Basic shape commands";
1466 theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1467 theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1468 theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1469 theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1470 theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n"
1471 "\t erase geometry objects from shapes - key is used or \n"
1472 "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n",
1473 __FILE__, tclean, g);
1474 theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1475 theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1476 theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1477 theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1478 theCommands.Add("add",
1480 "\n adds shape \"what\" to shape \"where\" ",
1482 theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1483 theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1484 theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1485 theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1486 theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1488 theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1489 theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1490 theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1491 theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1492 theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g);
1493 theCommands.Add("nbshapes",
1494 "\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.",
1495 __FILE__,nbshapes,g);
1496 theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1497 theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1498 theCommands.Add("setflags",
1499 "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 ",
1500 __FILE__,setFlags,g);
1502 // theCommands.Add("dumpmmgt",
1503 // "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1504 theCommands.Add("purgemmgt",
1505 "returns the free memory from the system to the memory manager",
1506 __FILE__,purgemmgt,g);
1508 // Add command for DRAW-specific ProgressIndicator
1509 theCommands.Add ( "XProgress",
1510 "XProgress [+|-t] [+|-g] [-tclOutput]"
1511 "\n\t\t: The options are:"
1512 "\n\t\t: +|-t, +|-g : switch on/off textual and graphical mode of Progress Indicator"
1513 "\n\t\t: -tclOutput : switch on data output mode in tcl"
1514 "\n\t\t: Allows to control the output form of Progress Indicator",
1515 XProgress,"DE: General");
1517 theCommands.Add("binsave", "binsave shape filename\n"
1518 "\t\tsave the shape in the binary format file",
1519 __FILE__, binsave, g);
1520 theCommands.Add("binrestore", "binrestore filename shape\n"
1521 "\t\trestore the shape from the binary format file",
1522 __FILE__, binrestore, g);
1524 theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
1525 "\n\t\t Removes sub-shapes with internal orientation from the shape.\n"
1526 "\n\t\t Force flag disables the check on topological connectivity and"
1527 "removes all internal sub-shapes\n",
1528 __FILE__, removeInternals, g);
1531 //=======================================================================
1532 //function : HLRMode
1534 //=======================================================================
1536 Standard_Boolean DBRep::HLRMode()
1539 //=======================================================================
1540 //function : Rg1Mode
1542 //=======================================================================
1544 Standard_Boolean DBRep::Rg1Mode()
1547 //=======================================================================
1548 //function : RgNMode
1550 //=======================================================================
1552 Standard_Boolean DBRep::RgNMode()
1555 //=======================================================================
1556 //function : HidMode
1558 //=======================================================================
1560 Standard_Boolean DBRep::HidMode()
1563 //=======================================================================
1564 //function : HLRAngle
1566 //=======================================================================
1568 Standard_Real DBRep::HLRAngle()
1571 //=======================================================================
1573 //purpose : save and restore shapes
1574 //=======================================================================
1576 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d)
1578 return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1581 static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1583 Handle(DBRep_DrawableShape)
1584 N = Handle(DBRep_DrawableShape)::DownCast(d);
1586 BRepTools_ShapeSet S(B);
1588 S.Write (OS, Draw::GetProgressBar());
1589 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1591 S.Write(N->Shape(),OS);
1594 static Handle(Draw_Drawable3D) srestore (std::istream& IS)
1597 BRepTools_ShapeSet S(B);
1598 S.Read (IS, Draw::GetProgressBar());
1599 Handle(DBRep_DrawableShape) N;
1600 if(!Draw::GetProgressBar().IsNull() && Draw::GetProgressBar()->UserBreak())
1602 TopoDS_Shape theShape;
1603 S.Read(theShape,IS );
1604 N = new DBRep_DrawableShape(theShape,
1612 N->DisplayTriangulation(disptriangles);
1613 N->DisplayPolygons(disppolygons);
1614 N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1620 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1621 stest,ssave,srestore);
1624 void dumps (const TopoDS_Shape& S)
1626 BRepTools::Dump(S,std::cout);
1629 //=======================================================================
1632 //=======================================================================
1634 Standard_Integer DBRep::NbIsos()
1638 //=======================================================================
1639 //function : Discretisation
1641 //=======================================================================
1643 Standard_Integer DBRep::Discretisation()