0025748: Parallel version of progress indicator
[occt.git] / src / DBRep / DBRep.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
25 #include <DBRep.hxx>
26 #include <DBRep_DrawableShape.hxx>
27 #include <Draw.hxx>
28 #include <Draw_Appli.hxx>
29 #include <Draw_ProgressIndicator.hxx>
30 #include <Message_ProgressRange.hxx>
31 #include <Draw_Segment3D.hxx>
32 #include <gp_Ax2.hxx>
33 #include <GProp.hxx>
34 #include <GProp_GProps.hxx>
35 #include <NCollection_Vector.hxx>
36 #include <Poly_Triangulation.hxx>
37 #include <Precision.hxx>
38 #include <Standard.hxx>
39 #include <TColStd_Array1OfInteger.hxx>
40 #include <TColStd_Array1OfReal.hxx>
41 #include <TopAbs.hxx>
42 #include <TopExp.hxx>
43 #include <TopExp_Explorer.hxx>
44 #include <TopoDS.hxx>
45 #include <TopoDS_Compound.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopoDS_Shape.hxx>
48 #include <TopTools_Array1OfShape.hxx>
49 #include <TopTools_ListOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
51
52 #include <stdio.h>
53 // memory management
54 #ifdef _WIN32
55 extern Draw_Viewer dout;
56 #endif
57
58 #define Characters(IArg) (strspn (Arg[IArg], "0123456789.+-eE") != strlen (Arg[IArg]))
59 #define Float(IArg)      (strspn (Arg[IArg], "0123456789+-")    != strlen (Arg[IArg]))
60
61
62 //==========================================
63 // useful methods
64 //==========================================
65
66 Standard_EXPORT void DBRep_WriteColorOrientation ()
67 {
68   std::cout << "\nrouge  FORWARD";
69   std::cout << "\nbleu   REVERSED";
70   std::cout << "\nrose   EXTERNAL";
71   std::cout << "\norange INTERNAL"<<std::endl;
72 }
73
74 Standard_EXPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or) 
75 {
76   Draw_Color col;
77   switch (Or) {
78
79   case TopAbs_FORWARD :
80     col = Draw_rouge;
81     break;
82     
83   case TopAbs_REVERSED :
84     col = Draw_bleu;
85     break;
86     
87   case TopAbs_EXTERNAL :
88     col = Draw_rose;
89     break;
90     
91   case TopAbs_INTERNAL :
92     col = Draw_orange;
93     break;
94     
95   }
96   return col;
97 }
98
99 //==========================================
100 // static variables
101 //==========================================
102
103 static Standard_Integer nbIsos  = 2;
104 static Standard_Real    size    = 100.;
105 static Standard_Integer discret = 30;
106 static Standard_Boolean disptriangles = Standard_False;
107 static Standard_Boolean disppolygons = Standard_False;
108 static Standard_Real    anglHLR = 35 * M_PI / 180;
109 static Standard_Real    HAngMin =  1 * M_PI / 180;
110 static Standard_Real    HAngMax = 35 * M_PI / 180;
111 static Standard_Boolean withHLR = Standard_False;
112 static Standard_Boolean withRg1 = Standard_True;
113 static Standard_Boolean withRgN = Standard_False;
114 static Standard_Boolean withHid = Standard_False;
115
116 //=======================================================================
117 // isos
118 //=======================================================================
119
120 static Standard_Integer isos (Draw_Interpretor& di,
121                               Standard_Integer NbArg, const char **Arg)
122 {
123   NbArg-- ;
124   
125   if (NbArg <= 0) {
126     di << "Current number of isos : " << nbIsos << "\n" ;
127     return 0 ;
128   }
129
130   Standard_Integer NbIsos = 0 ;
131   Standard_Boolean Change = Standard_False ;
132   if (!Characters (NbArg) && Float (NbArg)) return 1 ;
133   if (!Characters (NbArg)) {
134     NbIsos = Draw::Atoi (Arg[NbArg]) ;
135     NbArg-- ;
136     Change = Standard_True ;
137   }
138
139   if (NbArg <= 0) {
140     nbIsos = NbIsos ;
141     di << "New current number of isos : " << nbIsos << "\n" ;
142   } else {
143     for (Standard_Integer IArg = 1 ; IArg <= NbArg ; IArg++) {
144       Handle (Draw_Drawable3D) Shape1 = Draw::Get (Arg[IArg]) ;
145       if (!Shape1.IsNull()) {
146         Handle (DBRep_DrawableShape) Shape2 =
147           Handle (DBRep_DrawableShape)::DownCast (Shape1) ;     
148         if (!Shape2.IsNull()) {
149           if (Change) {
150             Shape2->ChangeNbIsos (NbIsos) ;
151           } else {
152             di << "Number of isos for " << Arg[IArg] << " : " << Shape2->NbIsos() << "\n";
153           }
154         }
155       }
156     }
157     if (Change) dout.RepaintAll() ;
158   }
159
160   return 0 ;
161 }
162
163 //=======================================================================
164 // hlr
165 //=======================================================================
166
167 static Standard_Integer hlr (Draw_Interpretor& di,
168                              Standard_Integer n, const char **a)
169 {
170   if (n <= 1) {
171     if (withHLR) {
172       di << " HLR";
173       if (withRgN) di << " RgNLines";
174       else {
175         if (withRg1) di << " Rg1Lines";
176         else         di << " no RegLines";
177       }
178       if (withHid) di << " HiddenLines";
179       else         di << " no HiddenLines";
180       di << "\n";
181       if (withHLR) {
182         di << "Angle of discretization : ";
183         di << anglHLR * 180 / M_PI << " degrees\n";
184       }
185     }
186     else di << " wireframe";
187     di << "\n";
188     return 0 ;
189   }
190
191   if (n == 2) {
192     if      (!strcasecmp(a[1],"nohlr")) withHLR = Standard_False;
193     else if (!strcasecmp(a[1],"hlr"  )) withHLR = Standard_True;
194     else if (!strcasecmp(a[1],"nohid")) withHid = Standard_False;
195     else if (!strcasecmp(a[1],"hid"  )) {
196       withHLR = Standard_True;
197       withHid = Standard_True;
198     }
199     else if (!strcasecmp(a[1],"norg1")) {
200       withRg1 = Standard_False;
201       withRgN = Standard_False;
202     }
203     else if (!strcasecmp(a[1],"rg1"  )) {
204       withHLR = Standard_True;
205       withRg1 = Standard_True;
206       withRgN = Standard_False;
207     }
208     else if (!strcasecmp(a[1],"norgn")) {
209       withRgN = Standard_False;
210     }
211     else if (!strcasecmp(a[1],"rgn"  )) {
212       withHLR = Standard_True;
213       withRg1 = Standard_True;
214       withRgN = Standard_True;
215     }
216     else if (!strcasecmp(a[1],"ang"  )) {
217       di << "Angle de discretisation : ";
218       di << anglHLR * 180 / M_PI << " degres\n";
219     }
220     else return 1;
221   }
222
223   Standard_Integer nFirst = 2;
224
225   if (n >= 3 && !strcasecmp(a[1],"ang"  )) {
226     nFirst = 3;
227     if (n == 3) {
228       Standard_Real ang = Draw::Atof(a[2]);
229       anglHLR = ang * M_PI / 180;
230       if (anglHLR < HAngMin) anglHLR = HAngMin;
231       if (anglHLR > HAngMax) anglHLR = HAngMax;
232     }
233     di << "Angle of discretization : ";
234     di << anglHLR * 180 / M_PI << " degrees\n";
235   }
236
237   if (n >= nFirst + 1) {
238
239     for (Standard_Integer i = nFirst ; i < n; i++) {
240       Handle (Draw_Drawable3D) D = Draw::Get (a[i]) ;
241       if (!D.IsNull()) {
242         Handle (DBRep_DrawableShape) S =
243           Handle (DBRep_DrawableShape)::DownCast (D) ;  
244         if (!S.IsNull()) {
245           Standard_Boolean localHLR, localRg1, localRgN, localHid;
246           Standard_Real localAng;
247           S->GetDisplayHLR(localHLR, localRg1, localRgN, localHid,
248                            localAng);
249           if      (!strcasecmp(a[1],"nohlr")) localHLR = Standard_False;
250           else if (!strcasecmp(a[1],"hlr"  )) localHLR = Standard_True;
251           else if (!strcasecmp(a[1],"nohid")) localHid = Standard_False;
252           else if (!strcasecmp(a[1],"hid"  )) {
253             localHLR = Standard_True;
254             localHid = Standard_True;
255           }
256           else if (!strcasecmp(a[1],"norg1")) {
257             localRg1 = Standard_False;
258             localRgN = Standard_False;
259           }
260           else if (!strcasecmp(a[1],"rg1"  )) {
261             localHLR = Standard_True;
262             localRg1 = Standard_True;
263             localRgN = Standard_False;
264           }
265           else if (!strcasecmp(a[1],"norgn")) {
266             localRgN = Standard_False;
267           }
268           else if (!strcasecmp(a[1],"rgn"  )) {
269             localHLR = Standard_True;
270             localRg1 = Standard_True;
271             localRgN = Standard_True;
272           }
273           else if (!strcasecmp(a[1],"ang"  )) {
274             Standard_Real ang = Draw::Atof(a[2]);
275             localAng = ang * M_PI / 180;
276           }
277           else return 1;
278           S->DisplayHLR(localHLR, localRg1, localRgN, localHid,
279                         localAng);
280         }
281       }
282     }
283   }
284   dout.RepaintAll() ;
285
286   return 0 ;
287 }
288
289
290 //=======================================================================
291 // dispor, dispcon
292 //=======================================================================
293
294 static Standard_Integer dispor (Draw_Interpretor& ,
295                                 Standard_Integer n, const char** a)
296 {
297   Standard_Boolean d = !strcasecmp(a[0],"vori");
298
299   if (d)
300     DBRep_WriteColorOrientation();
301
302   Standard_Integer i;
303   for (i = 1; i < n; i++) {
304     Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
305     if (!d1.IsNull()) {
306       Handle(DBRep_DrawableShape) d2 = 
307         Handle(DBRep_DrawableShape)::DownCast(d1);
308       if (!d2.IsNull()) {
309         d2->DisplayOrientation(d);
310       Draw::Repaint();
311       }
312     }
313   }
314   return 0;
315 }
316
317 //=======================================================================
318 // discretisation
319 //=======================================================================
320
321 static Standard_Integer discretisation(Draw_Interpretor& di,
322                                        Standard_Integer n, const char** a)
323 {
324   if (n <= 1)
325     di << "Current number of points : "<<discret<<"\n";
326   else {
327     discret = Draw::Atoi(a[1]);
328   }
329   return 0;
330 }
331
332
333 //=======================================================================
334 // triangles
335 //=======================================================================
336
337 static Standard_Integer triangles(Draw_Interpretor& , 
338                                   Standard_Integer n, const char** a)
339 {
340   if (n < 1) return 1;
341
342   if (n == 1) {
343     disptriangles = !disptriangles;
344 #ifdef OCCT_DEBUG
345     if (disptriangles) std::cout <<"Triangulations are always displayed"<<std::endl;
346     else std::cout <<"Triangulations are displayed only if there is no geometric representation"<<std::endl;
347 #endif
348   }
349   else {
350     Standard_Integer i;
351     for (i = 1; i <= n-1; i++) {
352       Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
353       if (!d1.IsNull()) {
354         Handle(DBRep_DrawableShape) d2 = 
355           Handle(DBRep_DrawableShape)::DownCast(d1);
356         if (!d2.IsNull()) {
357           d2->DisplayTriangulation(!(d2->DisplayTriangulation()));
358         }
359       }
360     }
361   }
362
363   Draw::Repaint();
364   return 0;
365 }
366
367 //=======================================================================
368 // tclean
369 //=======================================================================
370
371 static Standard_Integer tclean(Draw_Interpretor& , 
372                                Standard_Integer n, const char** a)
373 {
374   if (n == 1) return 1;
375
376   Standard_Integer aStart = 1;
377   Standard_Boolean toRemoveGeometry = Standard_False;
378   if (strcmp(a[1], "-geom") == 0)
379   {
380     aStart++;
381     toRemoveGeometry = Standard_True;
382   }
383
384   for (Standard_Integer i = aStart; i < n; i++) {
385     TopoDS_Shape S = DBRep::Get(a[i]);
386     if (toRemoveGeometry)
387       BRepTools::CleanGeometry(S);
388     else
389       BRepTools::Clean(S);
390   }
391   return 0;
392 }
393
394 //=======================================================================
395 // polygons
396 //=======================================================================
397
398 static Standard_Integer polygons(Draw_Interpretor& , 
399                                  Standard_Integer n, const char** a)
400 {
401   if (n < 1)  return 1;
402
403   if (n == 1) {
404     disppolygons = !disppolygons;
405 #ifdef OCCT_DEBUG
406     if (disppolygons) std::cout <<"Polygons are always displayed"<<std::endl;
407     else std::cout <<"Polygons are displayed only if there is no geometric representation"<<std::endl;
408 #endif
409   }
410   else {
411     Standard_Integer i;
412     for (i = 1; i <= n-1; i++) {
413       Handle(Draw_Drawable3D) d1 = Draw::Get(a[i]);
414       if (!d1.IsNull()) {
415         Handle(DBRep_DrawableShape) d2 = 
416           Handle(DBRep_DrawableShape)::DownCast(d1);
417         if (!d2.IsNull()) {
418           d2->DisplayPolygons(!(d2->DisplayPolygons()));
419         }
420       }
421     }
422   }
423
424   Draw::Repaint();
425   return 0;
426 }
427
428
429 //=======================================================================
430 // compound
431 //=======================================================================
432
433 static Standard_Integer compound(Draw_Interpretor& ,
434                                  Standard_Integer n, const char** a)
435 {
436   if (n <= 1) return 1;
437   BRep_Builder B;
438   TopoDS_Compound C;
439   B.MakeCompound(C);
440   for (Standard_Integer i = 1; i < n-1; i++) {
441     TopoDS_Shape S2 = DBRep::Get(a[i]);
442     if (!S2.IsNull()) B.Add(C,S2);
443   }
444   DBRep::Set(a[n-1],C);
445   return 0;
446 }
447
448 //=======================================================================
449 // emptycopy
450 //=======================================================================
451
452 static Standard_Integer emptycopy(Draw_Interpretor& ,
453                                   Standard_Integer n, const char** a)
454 {
455   if (n <= 1) return 1;
456   TopoDS_Shape S = DBRep::Get(a[(n == 2) ? 1 : 2]);
457   if (S.IsNull()) return 1;
458   S.EmptyCopy();
459   DBRep::Set(a[1],S);
460   return 0;
461 }
462
463 //=======================================================================
464 // add
465 //=======================================================================
466
467 static Standard_Integer add(Draw_Interpretor& ,
468                             Standard_Integer n, const char** a)
469 {
470   if (n < 3) return 1;
471   BRep_Builder B;
472   TopoDS_Shape S1 = DBRep::Get(a[1]);
473   if (S1.IsNull()) return 1;
474   TopoDS_Shape S2 = DBRep::Get(a[2]);
475   if (S2.IsNull()) return 1;
476   B.Add(S2,S1);
477   DBRep::Set(a[2],S2);
478   return 0;
479 }
480
481 //=======================================================================
482 // explode
483 //=======================================================================
484
485 static Standard_Integer explode(Draw_Interpretor& di,
486                                 Standard_Integer n, const char** a)
487 {
488   if (n <= 1) return 1;
489   TopoDS_Shape S = DBRep::Get(a[1]);
490   if (S.IsNull()) return 0;
491   char newname[1024];
492   strcpy(newname,a[1]);
493   char* p = newname;
494   while (*p != '\0') p++;
495   *p = '_';
496   p++;
497   Standard_Integer i = 0;
498   if (n == 2) {
499     TopoDS_Iterator itr(S);
500     while (itr.More()) {
501       i++;
502       Sprintf(p,"%d",i);
503       DBRep::Set(newname,itr.Value());
504       di.AppendElement(newname);
505       itr.Next();
506     }
507   }
508   else {
509     // explode a type
510     TopAbs_ShapeEnum typ;
511     switch (a[2][0]) {
512       
513     case 'C' :
514     case 'c' :
515       if ((a[2][1] == 'd')||(a[2][1] == 'D')) 
516         typ = TopAbs_COMPOUND;
517       else
518         typ = TopAbs_COMPSOLID;
519       break;
520       
521     case 'S' :
522     case 's' :
523       if ((a[2][1] == 'O')||(a[2][1] == 'o')) 
524         typ = TopAbs_SOLID;
525       else if ((a[2][1] == 'H')||(a[2][1] == 'h')) 
526         typ = TopAbs_SHELL;
527       else
528         return 1;
529       break;
530       
531     case 'F' :
532     case 'f' :
533       typ = TopAbs_FACE;
534       break;
535       
536     case 'W' :
537     case 'w' :
538       typ = TopAbs_WIRE;
539       break;
540       
541     case 'E' :
542     case 'e' :
543       typ = TopAbs_EDGE;
544       break;
545       
546     case 'V' :
547     case 'v' :
548       typ = TopAbs_VERTEX;
549       break;
550       
551       default :
552         return 1;
553     }
554     
555     TopTools_MapOfShape M;
556     M.Add(S);
557     TopExp_Explorer ex(S,typ);
558     for (; ex.More(); ex.Next()) {
559       const TopoDS_Shape& Sx = ex.Current();
560       Standard_Boolean added = M.Add(Sx);
561       if (added) {
562         i++;
563         Sprintf(p,"%d",i);
564         DBRep::Set(newname,Sx);
565         di.AppendElement(newname);
566       }
567     }
568   }
569   return 0;
570 }
571
572 //=======================================================================
573 // nexplode : stable numbered explode (from Serguey Nizhny)
574 //=======================================================================
575
576 static Standard_Integer nexplode(Draw_Interpretor& di, 
577                                  Standard_Integer n, const char** a)
578
579   if (n <= 2) return 1;
580   TopoDS_Shape S = DBRep::Get(a[1]);
581   if (S.IsNull()) return 0;
582   char newname[1024];
583   strcpy(newname,a[1]);
584   char* p = newname;
585   while (*p != '\0') p++;
586   *p = '_';
587   p++;
588   TopAbs_ShapeEnum typ;
589   // explode a type
590   switch (a[2][0]) {    
591   case 'F' :
592   case 'f' :
593     typ = TopAbs_FACE;
594     break;
595     
596   case 'E' :
597   case 'e' :
598     typ = TopAbs_EDGE;
599     break;
600     
601   case 'V' :
602   case 'v' :
603     typ = TopAbs_VERTEX;
604     break;
605     
606     default :
607       return 1;
608   }
609   TopTools_IndexedMapOfShape IMOStmp;
610   TopTools_MapOfShape MShape;
611   IMOStmp.Add(S);
612   TopExp::MapShapes(S,typ,IMOStmp);
613   TopExp_Explorer Exp(S,typ);
614   Standard_Integer MaxShapes, Index = 0;
615   MaxShapes = IMOStmp.Extent()-1;
616   TopTools_Array1OfShape aShapes(1,MaxShapes);
617   
618   // explode 
619   while (Exp.More()) {
620     if (MShape.Add(Exp.Current())) {
621       Index++;
622       aShapes.SetValue(Index,Exp.Current());
623     }
624     Exp.Next();
625   }
626   //
627   TColStd_Array1OfInteger OrderInd(1,MaxShapes);
628   gp_Pnt GPoint;
629   GProp_GProps GPr;
630   Standard_Integer aTemp;
631   TColStd_Array1OfReal MidXYZ(1,MaxShapes); //X,Y,Z;
632   Standard_Boolean NoSort = Standard_True;
633   //
634   // Computing of CentreOfMass for edge and face
635   // and for vertex use its point
636   for (Index=1; Index <= MaxShapes; Index++) {
637     OrderInd.SetValue(Index,Index);
638     const TopoDS_Shape& aS = aShapes(Index);
639     if (aS.ShapeType() != TopAbs_VERTEX) {
640       BRepGProp::LinearProperties(aS, GPr);
641       GPoint = GPr.CentreOfMass();
642     }
643     else {
644       GPoint = BRep_Tool::Pnt(TopoDS::Vertex(aS));
645     }
646     MidXYZ.SetValue(Index, GPoint.X()*999 + GPoint.Y()*99 +
647                     GPoint.Z()*0.9);
648   }   
649   // Sorting
650   while(NoSort) {
651     NoSort = Standard_False;
652     for (Index=1; Index < MaxShapes; Index++) {
653       if (MidXYZ(OrderInd(Index)) > MidXYZ(OrderInd(Index+1))) {
654         aTemp = OrderInd(Index);
655         OrderInd(Index) = OrderInd(Index+1);
656         OrderInd(Index+1) = aTemp;
657         NoSort = Standard_True;
658       }
659     }
660   }
661   // Check of equality of MidXYZ
662   for (Index=1; Index < MaxShapes; Index++) {
663     if (MidXYZ(OrderInd(Index+1)) == MidXYZ(OrderInd(Index)))
664       di<<"Warning! For this shape the results may be incorrect.\n";
665   }
666   
667   for (Index=1 ;Index <= MaxShapes; Index++) {
668     Sprintf(p,"%d",Index);
669     DBRep::Set(newname,aShapes(OrderInd(Index)));
670     di.AppendElement(newname);    
671   }
672   
673   return 0;
674 }
675
676 //=======================================================================
677 // exwire
678 //=======================================================================
679
680 static Standard_Integer exwire(Draw_Interpretor& ,
681                                Standard_Integer n, const char** a)
682 {
683   if (n <= 1) return 1;
684   TopoDS_Shape S = DBRep::Get(a[1]);
685   if (S.IsNull()) return 0;
686   if (S.ShapeType() != TopAbs_WIRE) return 0;
687   char newname[1024];
688   strcpy(newname,a[1]);
689   char* p = newname;
690   while (*p != '\0') p++;
691   *p = '_';
692   p++;
693   Standard_Integer i = 0;
694   BRepTools_WireExplorer ex(TopoDS::Wire(S));
695   while (ex.More()) {
696     i++;
697     Sprintf(p,"%d",i);
698     DBRep::Set(newname,ex.Current());
699     ex.Next();
700   }
701   return 0;
702 }
703
704 //=======================================================================
705 // invert
706 //=======================================================================
707
708 static Standard_Integer invert(Draw_Interpretor& ,
709                                Standard_Integer n, const char** a)
710 {
711   if (n <= 1) return 1;
712   TopoDS_Shape S = DBRep::Get(a[1]);
713   if (S.IsNull()) return 0;
714   
715   BRep_Builder B;
716   TopoDS_Shape NS = S.EmptyCopied();
717   NS.Closed (S.Closed());
718
719   TopoDS_Iterator itr(S);
720   while (itr.More()) {
721     B.Add(NS,itr.Value().Reversed());
722     itr.Next();
723   }
724   DBRep::Set(a[1],NS);
725   
726   return 0;
727 }
728
729 //=======================================================================
730 // orientation, reverse, complement
731 //=======================================================================
732
733 static Standard_Integer orientation(Draw_Interpretor& ,
734                                     Standard_Integer n, const char** a)
735 {
736   if (n <= 1) return 1;
737   Standard_Integer cas = 0;
738   TopAbs_Orientation ori=TopAbs_FORWARD;
739   Standard_Integer last = n;
740   if (!strcasecmp(a[0],"orientation")) {
741     if (n <= 2) return 1;
742     last--;
743     switch (*a[n-1]) {
744         
745       case 'F' :
746         ori = TopAbs_FORWARD;
747         break;
748         
749       case 'R' :
750         ori = TopAbs_REVERSED;
751         break;
752         
753       case 'I' :
754         ori = TopAbs_INTERNAL;
755         break;
756         
757       case 'E' :
758         ori = TopAbs_EXTERNAL;
759         break;
760       }
761   }
762
763   else if (!strcasecmp(a[0],"treverse")) {
764     cas = -1;
765   }
766
767   else if (!strcasecmp(a[0],"complement")) {
768     cas = -2;
769   }
770
771   for (Standard_Integer i = 1; i < last; i++) {
772     TopoDS_Shape S = DBRep::Get(a[i]);
773     if (!S.IsNull()) {
774       if (cas == -2)
775         S.Complement();
776       else if (cas == -1)
777         S.Reverse();
778       else
779         S.Orientation(ori);
780       DBRep::Set(a[i],S);
781     }
782   }
783   return 0;
784 }
785
786 #include <TCollection_AsciiString.hxx>
787
788 //=======================================================================
789 // numshapes same as nbshapes but the output is cout
790 //=======================================================================
791
792 static Standard_Integer numshapes(Draw_Interpretor& di,
793                                  Standard_Integer n, const char** a)
794 {
795   if (n < 2) return 1;
796
797   Standard_Integer i;
798   TopExp_Explorer ex;
799   for (i = 1; i < n; i++) {
800     TopoDS_Shape S = DBRep::Get(a[i]);
801     if (!S.IsNull()) {
802       BRepTools_ShapeSet BS;
803       BS.Add(S);
804       di <<"Number of shapes in "<<a[i]<<"\n";
805       TCollection_AsciiString Astr; 
806       BS.DumpExtent(Astr);
807       di <<Astr.ToCString();
808       di << "\n" ;
809     }
810   }
811
812   return 0;
813 }
814
815 //=======================================================================
816 // function : DumpExtent
817 // purpose  : Dumps the number of sub-shapes in <aStr>.
818 //=======================================================================
819 static void DumpExtent(const TopoDS_Shape& aS,
820                        TCollection_AsciiString& aStr)
821 {
822   const int aNbTypes=8;
823   const char *pNames[aNbTypes+1]={
824     " SHAPE     : ",
825     " COMPOUND  : ",
826     " COMPSOLID : ",
827     " SOLID     : ",
828     " SHELL     : ",
829     " FACE      : ",
830     " WIRE      : ",
831     " EDGE      : ",
832     " VERTEX    : "
833   };
834   Standard_Integer i, aNb, aNbSh;
835   TopAbs_ShapeEnum aType;
836   TopTools_IndexedMapOfShape aM;
837   //
838   aNbSh=0;
839   //
840   for (i=aNbTypes-1; i>=0; --i) {
841     aM.Clear();
842     aType=(TopAbs_ShapeEnum)i;
843     TopExp::MapShapes(aS, aType, aM);
844     aNb=aM.Extent();
845     aStr=aStr+pNames[i+1]+TCollection_AsciiString(aNb)+"\n";
846     aNbSh+=aNb;
847   }
848   aStr=aStr+pNames[0]+TCollection_AsciiString(aNbSh)+"\n";
849 }
850
851 //=======================================================================
852 // nbshapes
853 //=======================================================================
854
855 static Standard_Integer nbshapes(Draw_Interpretor& di,
856                                  Standard_Integer n, const char** a)
857 {
858   if (n < 2) return 1;
859
860   Standard_Integer i;
861   Standard_Boolean aTotal;
862   TopExp_Explorer ex;
863   //
864   aTotal = !strcmp(a[n-1], "-t") ? Standard_True : Standard_False;
865   //
866   for (i = 1; i < n; i++) {
867     TopoDS_Shape S = DBRep::Get(a[i]);
868     if (!S.IsNull()) {
869       di<<"Number of shapes in "<<a[i]<<"\n";
870       TCollection_AsciiString Astr; 
871       if (aTotal) {
872         DumpExtent(S, Astr);
873       } else {
874         BRepTools_ShapeSet BS;
875         BS.Add(S);
876         BS.DumpExtent(Astr);
877       }
878       di<<Astr.ToCString();
879     }
880   }
881
882   return 0;
883 }
884
885 //=======================================================================
886 // 
887 //=======================================================================
888
889 static Standard_Integer countshapes(Draw_Interpretor& di,
890                                     Standard_Integer n, const char** a)
891 {
892   if (n < 2) return 1;
893
894   Standard_Integer i;
895   TopExp_Explorer ex;
896   for (i = 1; i < n; i++) {
897     TopoDS_Shape Sh = DBRep::Get(a[i]);
898     Standard_Integer nbElem = 0;
899     if (!Sh.IsNull()) {
900       di <<"Number of shapes in "<<a[i]<<"\n";
901       TopTools_MapOfShape M;
902
903       for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
904         const TopoDS_Shape& S = ex.Current();
905         Standard_Boolean added = M.Add(S);
906         if (added) {
907           nbElem++;
908         }
909       }
910       di << " VERTEX     : " << nbElem << "\n";
911       nbElem = 0;
912     
913       for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
914         const TopoDS_Shape& S = ex.Current();
915         Standard_Boolean added = M.Add(S);
916         if (added) {
917           nbElem++;
918         }
919       }
920       di << " EDGE       : " << nbElem << "\n";
921       nbElem = 0;
922
923       for (ex.Init (Sh,TopAbs_WIRE); ex.More(); ex.Next()) {
924         const TopoDS_Shape& S = ex.Current();
925         Standard_Boolean added = M.Add(S);
926         if (added) {
927           nbElem++;
928         }
929       }
930       di << " WIRE       : " << nbElem << "\n";
931       nbElem = 0;
932
933       for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
934         const TopoDS_Shape& S = ex.Current();
935         Standard_Boolean added = M.Add(S);
936         if (added) {
937           nbElem++;
938         }
939       }
940       di << " FACE       : " << nbElem << "\n";
941       nbElem = 0;
942
943       for (ex.Init (Sh,TopAbs_SHELL); ex.More(); ex.Next()) {
944         const TopoDS_Shape& S = ex.Current();
945         Standard_Boolean added = M.Add(S);
946         if (added) {
947           nbElem++;
948         }
949       }
950       di << " SHELL      : " << nbElem << "\n";
951       nbElem = 0;
952
953       for (ex.Init (Sh,TopAbs_SOLID); ex.More(); ex.Next()) {
954         const TopoDS_Shape& S = ex.Current();
955         Standard_Boolean added = M.Add(S);
956         if (added) {
957           nbElem++;
958         }
959       }
960       di << " SOLID      : " << nbElem << "\n";
961       nbElem = 0;
962
963       for (ex.Init (Sh,TopAbs_COMPSOLID); ex.More(); ex.Next()) {
964         const TopoDS_Shape& S = ex.Current();
965         Standard_Boolean added = M.Add(S);
966         if (added) {
967           nbElem++;
968         }
969       }
970       di << " COMPSOLID  : " << nbElem << "\n";
971       nbElem = 0;
972       
973       for (ex.Init (Sh,TopAbs_COMPOUND); ex.More(); ex.Next()) {
974         const TopoDS_Shape& S = ex.Current();
975         Standard_Boolean added = M.Add(S);
976         if (added) {
977           nbElem++;
978         }
979       }
980       di << " COMPOUND   : " << nbElem << "\n";
981       nbElem = 0;
982
983       di << " SHAPE      : " << M.Extent() << "\n";
984       di << "\n" ;
985     }
986 }
987
988   return 0;
989 }
990
991 //=======================================================================
992 // 
993 //=======================================================================
994 void setProp(TopoDS_Shape Sh, const char** a, Standard_Integer n)
995 {
996   Standard_Integer i;
997   for(i = 2; i < n; i++) {
998     if (strstr ( a[i], "free" )) {
999       if(a[i][0] == '-') {
1000         Sh.Free(Standard_False);
1001       }
1002       else {
1003         Sh.Free(Standard_True);
1004       }
1005     }
1006     if (strstr ( a[i], "modified" )) {
1007       if(a[i][0] == '-') {
1008         Sh.Modified(Standard_False);
1009       }
1010       else {
1011         Sh.Modified(Standard_True);
1012       }
1013     }
1014     if (strstr ( a[i], "checked" )) {
1015       if(a[i][0] == '-') {
1016         Sh.Checked(Standard_False);
1017       }
1018       else {
1019         Sh.Checked(Standard_True);
1020       }
1021     }
1022     if (strstr ( a[i], "orientable" )) {
1023       if(a[i][0] == '-') {
1024         Sh.Orientable(Standard_False);
1025       }
1026       else {
1027         Sh.Orientable(Standard_True);
1028       }
1029     }
1030     if (strstr ( a[i], "closed" )) {
1031       if(a[i][0] == '-') {
1032         Sh.Closed(Standard_False);
1033       }
1034       else {
1035         Sh.Closed(Standard_True);
1036       }
1037     }
1038     if (strstr ( a[i], "infinite" )) {
1039       if(a[i][0] == '-') {
1040         Sh.Infinite(Standard_False);
1041       }
1042       else {
1043         Sh.Infinite(Standard_True);
1044       }
1045     }
1046     if (strstr ( a[i], "convex" )) {
1047       if(a[i][0] == '-') {
1048         Sh.Convex(Standard_False);
1049       }
1050       else {
1051         Sh.Convex(Standard_True);
1052       }
1053     }
1054     if (strstr ( a[i], "locked" )) {
1055       if(a[i][0] == '-') {
1056         Sh.Locked(Standard_False);
1057       }
1058       else {
1059         Sh.Locked(Standard_True);
1060       }
1061     }
1062   }
1063 }
1064
1065 //=======================================================================
1066 // 
1067 //=======================================================================
1068 static Standard_Integer setFlags(Draw_Interpretor& ,
1069                                     Standard_Integer n, const char** a)
1070 {
1071   if (n < 3) return 1;
1072
1073   TopExp_Explorer ex;
1074   TopoDS_Shape Sh = DBRep::Get(a[1]);
1075
1076   if (Sh.IsNull()) return 1;
1077
1078   setProp(Sh, a, n);
1079   for (ex.Init (Sh,TopAbs_VERTEX); ex.More(); ex.Next()) {
1080     TopoDS_Shape S = ex.Current();
1081     setProp(S, a, n);
1082   }
1083
1084   for (ex.Init (Sh,TopAbs_EDGE); ex.More(); ex.Next()) {
1085     TopoDS_Shape S = ex.Current();
1086     setProp(S, a, n);
1087   }
1088
1089   for (ex.Init (Sh,TopAbs_FACE); ex.More(); ex.Next()) {
1090     TopoDS_Shape S = ex.Current();
1091     setProp(S, a, n);
1092   }
1093
1094   return 0;
1095 }
1096
1097 //=======================================================================
1098 //memory management
1099 //=======================================================================
1100 static Standard_Integer purgemmgt(Draw_Interpretor&, Standard_Integer , const char**) {
1101   Standard::Purge();
1102   return 0;
1103 }
1104 //=======================================================================
1105
1106 //=======================================================================
1107 // check
1108 //=======================================================================
1109
1110 static Standard_Integer check(Draw_Interpretor& ,
1111                               Standard_Integer n, const char** a)
1112 {
1113   if (n < 2) return 1;
1114
1115   Standard_Integer i;
1116   TopExp_Explorer ex;
1117   for (i = 1; i < n; i++) {
1118     TopoDS_Shape S = DBRep::Get(a[i]);
1119     TopoDS_Shape C;
1120     if (S.IsNull()) continue;
1121     for (ex.Init(S,TopAbs_FACE);ex.More();ex.Next()) {
1122       C = ex.Current();
1123       C.Checked(Standard_False);
1124       BRepTools::Update(C);
1125     }
1126   }
1127
1128   return 0;
1129 }
1130
1131 //=======================================================================
1132 // normals
1133 //=======================================================================
1134 static Standard_Integer normals (Draw_Interpretor& theDI,
1135                                  Standard_Integer  theArgNum,
1136                                  const char**      theArgs)
1137 {
1138   if (theArgNum < 2)
1139   {
1140     std::cout << "Syntax error: wrong number of arguments!\n";
1141     theDI.PrintHelp (theArgs[0]);
1142     return 1;
1143   }
1144
1145   TopoDS_Shape aShape = DBRep::Get (theArgs[1]);
1146   if (aShape.IsNull())
1147   {
1148     std::cout << "Error: shape with name " << theArgs[1] << " is not found\n";
1149     return 1;
1150   }
1151
1152   Standard_Boolean toUseMesh = Standard_False;
1153   Standard_Real    aLength   = 10.0;
1154   Standard_Integer aNbAlongU = 1, aNbAlongV = 1;
1155   Standard_Boolean bPrint = Standard_False;
1156   for (Standard_Integer anArgIter = 2; anArgIter< theArgNum; ++anArgIter)
1157   {
1158     TCollection_AsciiString aParam (theArgs[anArgIter]);
1159     aParam.LowerCase();
1160     if (anArgIter == 2
1161      && aParam.IsRealValue())
1162     {
1163       aLength = aParam.RealValue();
1164       if (Abs (aLength) <= gp::Resolution())
1165       {
1166         std::cout << "Syntax error: length should not be zero\n";
1167         return 1;
1168       }
1169     }
1170     else if (aParam == "-usemesh"
1171           || aParam == "-mesh")
1172     {
1173       toUseMesh = Standard_True;
1174     }
1175     else if (aParam == "-length"
1176           || aParam == "-len")
1177     {
1178       ++anArgIter;
1179       aLength = anArgIter < theArgNum ? Draw::Atof(theArgs[anArgIter]) : 0.0;
1180       if (Abs(aLength) <= gp::Resolution())
1181       {
1182         std::cout << "Syntax error: length should not be zero\n";
1183         return 1;
1184       }
1185     }
1186     else if (aParam == "-nbalongu"
1187           || aParam == "-nbu")
1188     {
1189       ++anArgIter;
1190       aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1191       if (aNbAlongU < 1)
1192       {
1193         std::cout << "Syntax error: NbAlongU should be >=1\n";
1194         return 1;
1195       }
1196     }
1197     else if (aParam == "-nbalongv"
1198           || aParam == "-nbv")
1199     {
1200       ++anArgIter;
1201       aNbAlongV = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1202       if (aNbAlongV < 1)
1203       {
1204         std::cout << "Syntax error: NbAlongV should be >=1\n";
1205         return 1;
1206       }
1207     }
1208     else if (aParam == "-nbalong"
1209           || aParam == "-nbuv")
1210     {
1211       ++anArgIter;
1212       aNbAlongU = anArgIter< theArgNum ? Draw::Atoi (theArgs[anArgIter]) : 0;
1213       aNbAlongV = aNbAlongU;
1214       if (aNbAlongU < 1)
1215       {
1216         std::cout << "Syntax error: NbAlong should be >=1\n";
1217         return 1;
1218       }
1219     }
1220     else if (aParam == "-print")
1221     {
1222       bPrint = Standard_True;
1223     }
1224     else
1225     {
1226       std::cout << "Syntax error: unknown argument '" << aParam << "'\n";
1227       return 1;
1228     }
1229   }
1230
1231   DBRep_WriteColorOrientation();
1232
1233   NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > > aNormals;
1234   if (toUseMesh)
1235   {
1236     DBRep_DrawableShape::addMeshNormals (aNormals, aShape, aLength);
1237   }
1238   else
1239   {
1240     DBRep_DrawableShape::addSurfaceNormals (aNormals, aShape, aLength, aNbAlongU, aNbAlongV);
1241   }
1242
1243   for (NCollection_DataMap<TopoDS_Face, NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> > >::Iterator aFaceIt (aNormals); aFaceIt.More(); aFaceIt.Next())
1244   {
1245     Standard_Boolean bReverse = Standard_False;
1246     TopAbs_Orientation aFaceOri = aFaceIt.Key().Orientation();
1247     const Draw_Color aColor = DBRep_ColorOrientation (aFaceOri);
1248     if (aFaceOri == TopAbs_REVERSED)
1249       bReverse = Standard_True;
1250
1251     for (NCollection_Vector<std::pair<gp_Pnt, gp_Pnt> >::Iterator aNormalsIt (aFaceIt.Value()); aNormalsIt.More(); aNormalsIt.Next())
1252     {
1253       const std::pair<gp_Pnt, gp_Pnt>& aVec = aNormalsIt.Value();
1254       Handle(Draw_Segment3D) aSeg = new Draw_Segment3D(aVec.first, aVec.second, aColor);
1255       dout << aSeg;
1256       if (bPrint)
1257       {
1258         // Make the normal vector from the points
1259         gp_Vec aV(aVec.first, aVec.second);
1260         if (bReverse)
1261           aV.Reverse();
1262
1263         // Print values of the vector avoiding printing "-0" values
1264         theDI << "(" << (aV.X() == 0 ? 0 : aV.X()) << ", "
1265                      << (aV.Y() == 0 ? 0 : aV.Y()) << ", "
1266                      << (aV.Z() == 0 ? 0 : aV.Z()) << ")\n";
1267       }
1268     }
1269   }
1270
1271   return 0;
1272 }
1273
1274 //=======================================================================
1275 //function : Set
1276 //purpose  : 
1277 //=======================================================================
1278 void  DBRep::Set(const Standard_CString Name, const TopoDS_Shape& S)
1279 {
1280   Handle(DBRep_DrawableShape) D =
1281     new DBRep_DrawableShape(S,
1282                             Draw_vert,
1283                             Draw_jaune,
1284                             Draw_rouge,
1285                             Draw_bleu,
1286                             size,
1287                             nbIsos,
1288                             discret);
1289   D->DisplayTriangulation(disptriangles);
1290   D->DisplayPolygons(disppolygons);
1291   D->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1292   Draw::Set(Name,D);
1293 }
1294 //=======================================================================
1295 //function : getShape
1296 //purpose  :
1297 //=======================================================================
1298 TopoDS_Shape DBRep::getShape (Standard_CString& theName,
1299                               TopAbs_ShapeEnum theType,
1300                               Standard_Boolean theToComplain)
1301 {
1302   const Standard_Boolean toPick = theName[0] == '.';
1303   Handle(DBRep_DrawableShape) aDrawable = Handle(DBRep_DrawableShape)::DownCast (Draw::Get (theName));
1304   if (aDrawable.IsNull())
1305   {
1306     return TopoDS_Shape();
1307   }
1308
1309   TopoDS_Shape aShape = aDrawable->Shape();
1310   if (theType != TopAbs_SHAPE
1311    && theType != aShape.ShapeType()
1312    && toPick)
1313   {
1314     // try to find prom pick
1315     Standard_Real u, v;
1316     DBRep_DrawableShape::LastPick (aShape, u, v);
1317   }
1318   if (theType != TopAbs_SHAPE
1319    && theType != aShape.ShapeType())
1320   {
1321     if (theToComplain)
1322     {
1323       std::cout << theName << " is not a ";
1324       TopAbs::Print (theType, std::cout);
1325       std::cout << " but a ";
1326       TopAbs::Print (aShape.ShapeType(), std::cout);
1327       std::cout << std::endl;
1328     }
1329     return TopoDS_Shape();
1330   }
1331   return aShape;
1332 }
1333
1334 static Standard_Integer XProgress (Draw_Interpretor& di, Standard_Integer argc, const char **argv)
1335 {
1336   for ( Standard_Integer i=1; i < argc; i++ )
1337   {
1338     Standard_Boolean turn = Standard_True;
1339     if ( argv[i][0] == '-' ) turn = Standard_False;
1340     else if ( argv[i][0] != '+' ) continue;
1341
1342     TCollection_AsciiString anArgCase (argv[i]);
1343     anArgCase.LowerCase();
1344     if ( argv[i][1] == 't' ) Draw_ProgressIndicator::DefaultTclMode() = turn;
1345     else if (argv[i][1] == 'c') Draw_ProgressIndicator::DefaultConsoleMode() = turn;
1346     else if ( argv[i][1] == 'g' ) Draw_ProgressIndicator::DefaultGraphMode() = turn;
1347     else if ( ! strcmp ( argv[i], "-stop" ) && i+1 < argc )
1348     {
1349       Standard_Address aPtr = 0;
1350       if (sscanf (argv[++i], "%p", &aPtr) == 1)
1351         Draw_ProgressIndicator::StopIndicator() = aPtr;
1352       return 0;
1353     }
1354   }
1355   di << "Progress Indicator defaults: tcl mode is ";
1356   if ( Draw_ProgressIndicator::DefaultTclMode() ) {
1357     di<<"ON";
1358   } else {
1359     di<<"OFF";
1360   }
1361   di<<", console mode is ";
1362   if (Draw_ProgressIndicator::DefaultConsoleMode()) {
1363     di << "ON";
1364   }
1365   else {
1366     di << "OFF";
1367   }
1368   di << ", graphical mode is ";
1369   if ( Draw_ProgressIndicator::DefaultGraphMode() ) {
1370     di<<"ON";
1371   } else {
1372     di<<"OFF";
1373   }
1374   di<< "\n";
1375   return 0;
1376 }
1377
1378 //=======================================================================
1379 // binsave
1380 //=======================================================================
1381
1382 static Standard_Integer binsave(Draw_Interpretor& di, Standard_Integer n, const char** a)
1383 {
1384   if (n <= 2) return 1;
1385
1386   TopoDS_Shape aShape = DBRep::Get (a[1]);
1387   if (aShape.IsNull())
1388   {
1389     di << a[1] << " is not a shape";
1390     return 1;
1391   }
1392
1393   if (!BinTools::Write (aShape, a[2]))
1394   {
1395     di << "Cannot write to the file " << a[2];
1396     return 1;
1397   }
1398
1399   di << a[1];
1400   return 0;
1401 }
1402
1403 //=======================================================================
1404 // binrestore
1405 //=======================================================================
1406
1407 static Standard_Integer binrestore(Draw_Interpretor& di, Standard_Integer n, const char** a)
1408 {
1409   if (n <= 2) return 1;
1410
1411   TopoDS_Shape aShape;
1412   if (!BinTools::Read (aShape, a[1]))
1413   {
1414     di << "Cannot read from the file " << a[1];
1415     return 1;
1416   }
1417
1418   DBRep::Set (a[2], aShape);
1419   di << a[2];
1420   return 0;
1421 }
1422
1423 //=======================================================================
1424 // removeinternals
1425 //=======================================================================
1426 static Standard_Integer removeInternals (Draw_Interpretor& di,
1427                                          Standard_Integer n,
1428                                          const char** a)
1429 {
1430   if (n < 2)
1431   {
1432     di.PrintHelp (a[0]);
1433     return 1;
1434   }
1435
1436   TopoDS_Shape aShape = DBRep::Get (a[1]);
1437   if (aShape.IsNull())
1438   {
1439     di << a[1] << "is a null shape\n";
1440     return 1;
1441   }
1442
1443   Standard_Boolean isForce = Standard_False;
1444   if (n > 2)
1445   {
1446     isForce = (Draw::Atoi (a[2]) != 0);
1447   }
1448
1449   BRepTools::RemoveInternals (aShape, isForce);
1450
1451   DBRep::Set (a[1], aShape);
1452
1453   return 0;
1454 }
1455
1456 //=======================================================================
1457 //function : BasicCommands
1458 //purpose  : 
1459 //=======================================================================
1460
1461 static Standard_Boolean done = Standard_False;
1462 void  DBRep::BasicCommands(Draw_Interpretor& theCommands)
1463 {
1464   if (done) return;
1465   done = Standard_True;
1466   Draw::Commands(theCommands);
1467
1468   const char* g = "Basic shape commands";
1469
1470   theCommands.Add("isos","isos [name1 ...] [nbisos]",__FILE__,isos,g);
1471   theCommands.Add("hlr" ,"[no]hlr, rg1, rgn, hid, ang",__FILE__,hlr ,g);
1472   theCommands.Add("vori","vori [name1 ...], edges are colored by orientation (see vconn)",__FILE__,dispor,g);
1473   theCommands.Add("triangles", "triangles [name1]..., display triangles of shapes if exists",__FILE__, triangles, g);
1474   theCommands.Add("tclean", "tclean [-geom] [name1]..., depending on using or not key -geom, \n" 
1475                    "\t erase geometry objects from shapes - key is used or \n"
1476                    "\t erase triangulations and polygons on triangulations from shapes - key is omitted \n",
1477                     __FILE__, tclean, g); 
1478   theCommands.Add("polygons", "polygons [name1]..., display polygons of shapes if exists",__FILE__, polygons, g);
1479   theCommands.Add("vconn","vconn [name1 ...] , edges are colored by number of faces (see vori)",__FILE__,dispor,g);
1480   theCommands.Add("discretisation","discretisation [nbpoints]",__FILE__,discretisation,g);
1481   theCommands.Add("compound","compound [name1 name2 ..] compound",__FILE__,compound,g);
1482   theCommands.Add("add",
1483                   "add what where"
1484                   "\n  adds shape \"what\" to shape \"where\" ",
1485                   __FILE__,add,g);
1486   theCommands.Add("explode","explode name [Cd/C/So/Sh/F/W/E/V]",__FILE__,explode,g);
1487   theCommands.Add("nexplode","stable numbered explode for vertex, edge and face: nexplode name [V/E/F]",__FILE__,nexplode,g);
1488   theCommands.Add("exwire","exwire wirename",__FILE__,exwire,g);
1489   theCommands.Add("emptycopy","emptycopy [copyshape] originalshape",__FILE__,emptycopy,g);
1490   theCommands.Add("check","check shape1 shape2 ...",__FILE__,check,g);
1491
1492   theCommands.Add("orientation","orientation name1 name2.. F/R/E/I",__FILE__,orientation,g);
1493   theCommands.Add("treverse","treverse name1 name2 ...",__FILE__,orientation,g);
1494   theCommands.Add("complement","complement name1 name2 ...",__FILE__,orientation,g);
1495   theCommands.Add("invert","invert name, reverse subshapes",__FILE__,invert,g);
1496   theCommands.Add("normals","normals shape [Length {10}] [-NbAlongU {1}] [-NbAlongV {1}] [-UseMesh] [-print], display normals",__FILE__,normals,g);
1497   theCommands.Add("nbshapes",
1498                   "\n nbshapes s - shows the number of sub-shapes in <s>;\n nbshapes s -t - shows the number of sub-shapes in <s> counting the same sub-shapes with different location as different sub-shapes.",
1499                   __FILE__,nbshapes,g);
1500   theCommands.Add("numshapes","numshapes s; size of shape",__FILE__,numshapes,g);
1501   theCommands.Add("countshapes","countshapes s; count of shape",__FILE__,countshapes,g);
1502   theCommands.Add("setflags",
1503                   "setflags shape_name flag1[flag2...]\n sets flags for shape(free, modidfied, checked, orientable, closed, infinite, convex, locked), for exmple <setflags a free> or <setflags a -free> if necessary unflag ",
1504                   __FILE__,setFlags,g);
1505
1506 //  theCommands.Add("dumpmmgt",
1507 //                "dump le contenu du gestionnaire de memoire",__FILE__,dumpmmgt,g);
1508   theCommands.Add("purgemmgt",
1509                   "returns the free memory from the system to the memory manager",
1510                   __FILE__,purgemmgt,g);
1511   
1512   // Add command for DRAW-specific ProgressIndicator
1513   theCommands.Add ( "XProgress",
1514                     "XProgress [+|-t] [+|-c] [+|-g]"
1515                     "\n\t\t The options are:"
1516                     "\n\t\t   +|-t :  switch on/off output to tcl of Progress Indicator"
1517                     "\n\t\t   +|-c :  switch on/off output to cout of Progress Indicator"
1518                     "\n\t\t   +|-g :  switch on/off graphical mode of Progress Indicator",
1519                     XProgress,"DE: General");
1520
1521   theCommands.Add("binsave", "binsave shape filename\n"
1522                   "\t\tsave the shape in the binary format file",
1523                   __FILE__, binsave, g);
1524   theCommands.Add("binrestore", "binrestore filename shape\n"
1525                   "\t\trestore the shape from the binary format file",
1526                   __FILE__, binrestore, g);
1527
1528   theCommands.Add ("removeinternals", "removeinternals shape [force flag {0/1}]"
1529                    "\n\t\t             Removes sub-shapes with internal orientation from the shape.\n"
1530                    "\n\t\t             Force flag disables the check on topological connectivity and"
1531                                        "removes all internal sub-shapes\n",
1532                   __FILE__, removeInternals, g);
1533 }
1534
1535 //=======================================================================
1536 //function : HLRMode
1537 //purpose  : 
1538 //=======================================================================
1539
1540 Standard_Boolean DBRep::HLRMode()
1541 { return withHLR; }
1542
1543 //=======================================================================
1544 //function : Rg1Mode
1545 //purpose  : 
1546 //=======================================================================
1547
1548 Standard_Boolean DBRep::Rg1Mode()
1549 { return withRg1; }
1550
1551 //=======================================================================
1552 //function : RgNMode
1553 //purpose  : 
1554 //=======================================================================
1555
1556 Standard_Boolean DBRep::RgNMode()
1557 { return withRgN; }
1558
1559 //=======================================================================
1560 //function : HidMode
1561 //purpose  : 
1562 //=======================================================================
1563
1564 Standard_Boolean DBRep::HidMode()
1565 { return withHid; }
1566
1567 //=======================================================================
1568 //function : HLRAngle
1569 //purpose  : 
1570 //=======================================================================
1571
1572 Standard_Real DBRep::HLRAngle()
1573 { return anglHLR; }
1574
1575 //=======================================================================
1576 //function : 
1577 //purpose  : save and restore shapes
1578 //=======================================================================
1579
1580 static Standard_Boolean stest(const Handle(Draw_Drawable3D)& d) 
1581 {
1582   return d->IsInstance(STANDARD_TYPE(DBRep_DrawableShape));
1583 }
1584
1585 static void ssave(const Handle(Draw_Drawable3D)&d, std::ostream& OS)
1586 {
1587   Handle(DBRep_DrawableShape) 
1588     N = Handle(DBRep_DrawableShape)::DownCast(d);
1589   BRep_Builder B;
1590   BRepTools_ShapeSet S(B);
1591   S.Add (N->Shape());
1592   Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1593   S.Write(OS, Message_ProgressIndicator::Start(aProgress));
1594   if (! aProgress.IsNull() && aProgress->UserBreak())
1595     return;
1596   S.Write(N->Shape(),OS);
1597 }
1598
1599 static Handle(Draw_Drawable3D) srestore (std::istream& IS)
1600 {
1601   BRep_Builder B;
1602   BRepTools_ShapeSet S(B);
1603   Handle(Draw_ProgressIndicator) aProgress = Draw::GetProgressBar();
1604   S.Read(IS, Message_ProgressIndicator::Start(aProgress));
1605   Handle(DBRep_DrawableShape) N;
1606   if (! aProgress.IsNull() && aProgress->UserBreak())
1607     return N;
1608   TopoDS_Shape theShape;
1609   S.Read(theShape,IS );
1610   N = new DBRep_DrawableShape(theShape,
1611                             Draw_vert,
1612                             Draw_jaune,
1613                             Draw_rouge,
1614                             Draw_bleu,
1615                             size,
1616                             nbIsos,
1617                             discret);
1618   N->DisplayTriangulation(disptriangles);
1619   N->DisplayPolygons(disppolygons);
1620   N->DisplayHLR(withHLR,withRg1,withRgN,withHid,anglHLR);
1621   
1622   return N;
1623 }
1624
1625
1626 static Draw_SaveAndRestore ssr("DBRep_DrawableShape",
1627                                stest,ssave,srestore);
1628
1629
1630 void dumps (const TopoDS_Shape& S)
1631 {
1632  BRepTools::Dump(S,std::cout);
1633 }
1634
1635 //=======================================================================
1636 //function : NbIsos
1637 //purpose  : 
1638 //=======================================================================
1639
1640 Standard_Integer DBRep::NbIsos()
1641 { return nbIsos; }
1642
1643
1644 //=======================================================================
1645 //function : Discretisation
1646 //purpose  : 
1647 //=======================================================================
1648
1649 Standard_Integer DBRep::Discretisation()
1650 { return discret; }