0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / XSDRAWIGES / XSDRAWIGES.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //gka 06.01.99 S3767 new function TPSTAT (first version)
15 //pdn 11.01.99 putting "return" statement for compilation on NT
16
17 #include <BRepTools.hxx>
18 #include <DBRep.hxx>
19 #include <Draw_Appli.hxx>
20 #include <Draw_ProgressIndicator.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <Geom_Curve.hxx>
23 #include <Geom_Surface.hxx>
24 #include <IFSelect_Functions.hxx>
25 #include <IFSelect_SessionPilot.hxx>
26 #include <IGESControl_Controller.hxx>
27 #include <IGESControl_Reader.hxx>
28 #include <IGESControl_Writer.hxx>
29 #include <IGESData.hxx>
30 #include <IGESData_BasicEditor.hxx>
31 #include <IGESData_IGESEntity.hxx>
32 #include <IGESData_IGESModel.hxx>
33 #include <IGESData_Protocol.hxx>
34 #include <IGESSelect_Activator.hxx>
35 #include <IGESToBRep.hxx>
36 #include <IGESToBRep_Actor.hxx>
37 #include <IGESToBRep_Reader.hxx>
38 #include <Interface_Check.hxx>
39 #include <Interface_CheckIterator.hxx>
40 #include <Interface_CheckTool.hxx>
41 #include <Interface_InterfaceModel.hxx>
42 #include <Interface_Macros.hxx>
43 #include <Interface_Static.hxx>
44 #include <Message.hxx>
45 #include <Message_Messenger.hxx>
46 #include <Message_ProgressSentry.hxx>
47 #include <Standard_ErrorHandler.hxx>
48 #include <Standard_Failure.hxx>
49 #include <TCollection_AsciiString.hxx>
50 #include <TCollection_HAsciiString.hxx>
51 #include <TColStd_HSequenceOfTransient.hxx>
52 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
53 #include <TColStd_MapOfTransient.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopoDS.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <Transfer_FinderProcess.hxx>
58 #include <Transfer_IteratorOfProcessForTransient.hxx>
59 #include <Transfer_TransferOutput.hxx>
60 #include <Transfer_TransientProcess.hxx>
61 #include <XSControl.hxx>
62 #include <XSControl_WorkSession.hxx>
63 #include <XSControl_TransferReader.hxx>
64 #include <XSDRAW.hxx>
65 #include <XSDRAWIGES.hxx>
66
67 #include <stdio.h>
68
69 namespace {
70
71   //=======================================================================
72 //function : WriteShape
73 //purpose  : Creates a file Shape_'number'
74 //=======================================================================
75 void WriteShape(const TopoDS_Shape& shape, const Standard_Integer number)
76 {
77   char fname[110];
78   sprintf(fname, "Shape_%d",number);
79   std::ofstream f(fname,std::ios::out);
80   std::cout << "Output file name : " << fname << std::endl;
81   f << "DBRep_DrawableShape\n";
82   
83   BRepTools::Write(shape, f);
84   f.close();
85 }
86
87 TCollection_AsciiString XSDRAW_CommandPart
88   (Standard_Integer argc, const char** argv, const Standard_Integer argf)
89 {
90   TCollection_AsciiString res;
91   for (Standard_Integer i = argf; i < argc; i ++) {
92     if (i > argf) res.AssignCat(" ");
93     res.AssignCat (argv[i]);
94   }
95   return res;
96 }
97 }
98
99 //--------------------------------------------------------------
100 // Function : igesbrep
101 //--------------------------------------------------------------
102 static Standard_Integer igesbrep (Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
103 {
104   DeclareAndCast(IGESControl_Controller,ctl,XSDRAW::Controller());
105   if (ctl.IsNull()) XSDRAW::SetNorm("IGES");
106
107   // Progress indicator
108   Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
109   progress->SetScale ( 0, 100, 1 );
110   progress->Show();
111  
112   IGESControl_Reader Reader (XSDRAW::Session(),Standard_False);
113   Standard_Boolean aFullMode = Standard_True;
114   Reader.WS()->SetModeStat(aFullMode);
115   if (ctl.IsNull())
116     ctl=Handle(IGESControl_Controller)::DownCast(XSDRAW::Controller());
117
118   TCollection_AsciiString fnom,rnom;
119
120   Standard_Boolean modfic = XSDRAW::FileAndVar
121     (argv[1],argv[2],"IGESBREP",fnom,rnom);
122   if (modfic) di<<" File IGES to read : "<<fnom.ToCString()<<"\n";
123   else        di<<" Model taken from the session : "<<fnom.ToCString()<<"\n";
124   di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom.ToCString()<<"\n";
125   IFSelect_ReturnStatus readstat = IFSelect_RetVoid;
126
127 #ifdef CHRONOMESURE
128   OSD_Timer Chr; Chr.Reset();
129   IDT_SetLevel(3);
130 #endif
131
132
133 // Reading the file
134   progress->NewScope ( 20, "Loading" ); // On average loading takes 20% 
135   progress->Show();
136
137   if (modfic) readstat = Reader.ReadFile (fnom.ToCString());
138   else  if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone;
139
140   progress->EndScope();
141   progress->Show();
142
143   if (readstat != IFSelect_RetDone) {
144     if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon\n";
145     else di<<"No model loaded\n";
146     return 1;
147   }
148 // Choice of treatment
149   Standard_Boolean fromtcl = (argc > 3);
150   Standard_Integer modepri = 1, nent, nbs;
151   if (fromtcl) modepri = 4;
152
153   while (modepri) {
154     //Roots for transfer are defined before setting mode ALL or OnlyVisible - gka 
155     //mode OnlyVisible does not work.
156     // nent = Reader.NbRootsForTransfer();
157     if (!fromtcl) {
158       std::cout<<"Mode (0 End, 1 Visible Roots, 2 All Roots, 3 Only One Entity, 4 Selection) :"<<std::flush;
159       modepri = -1;
160       
161 // amv 26.09.2003 : this is used to avoid error of enter's simbol        
162       char str[80];                                                             
163       std::cin>>str;                                                                 
164       modepri = Draw::Atoi(str);   
165     }
166
167     if (modepri == 0) {  //fin
168       di << "Bye and good luck! \n";
169       break;
170     } 
171
172     else if (modepri <= 2) {  // 1 : Visible Roots, 2 : All Roots
173       di << "All Geometry Transfer\n";
174       di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n";
175       di<<"  To modify : command  param read.iges.bspline.continuity\n";
176       Handle(XSControl_WorkSession) thesession = Reader.WS();
177       thesession->ClearContext();
178       XSDRAW::SetTransferProcess (thesession->TransferReader()->TransientProcess());
179       progress->NewScope ( 80, "Translation" );
180       progress->Show();
181       thesession->TransferReader()->TransientProcess()->SetProgress ( progress );
182       
183       if (modepri == 1) Reader.SetReadVisible (Standard_True);
184       Reader.TransferRoots();
185       
186       thesession->TransferReader()->TransientProcess()->SetProgress ( 0 );
187       progress->EndScope();
188       progress->Show();
189       // result in only one shape for all the roots
190       //        or in one shape for one root.
191       di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n";
192       Standard_Integer answer = 1;
193       if (Reader.NbShapes() > 1) {
194         std::cout << " pass(0)  one shape for all (1)\n or one shape per root (2)\n + WriteBRep (one for all : 3) (one per root : 4) : " << std::flush;
195         answer = -1;
196         //amv 26.09.2003                                                        
197         char str_a[80];                                                         
198         std::cin >> str_a;                                                           
199         answer = Draw::Atoi(str_a);    
200       }
201       if ( answer == 0) continue;
202       if ( answer == 1 || answer == 3) {
203         TopoDS_Shape shape = Reader.OneShape();
204         // save the shape
205         if (shape.IsNull()) { di<<"No Shape produced\n"; continue; }
206         char fname[110];
207         Sprintf(fname, "%s", rnom.ToCString());
208         di << "Saving shape in variable Draw : " << fname << "\n";
209         if (answer == 3) WriteShape (shape,1);
210         try {
211           OCC_CATCH_SIGNALS
212           DBRep::Set(fname,shape);
213         }
214         catch(Standard_Failure const& anException) {
215           di << "** Exception : ";
216           di << anException.GetMessageString();
217           di<<" ** Skip\n";
218           di << "Saving shape in variable Draw : " << fname << "\n";
219           WriteShape (shape,1);
220         }
221       }
222         
223       else if (answer == 2 || answer == 4) {
224         Standard_Integer numshape = Reader.NbShapes();
225         for (Standard_Integer inum = 1; inum <= numshape; inum++) {
226           // save all the shapes
227           TopoDS_Shape shape = Reader.Shape(inum);
228           if (shape.IsNull()) { di<<"No Shape produced\n"; continue; }
229           char fname[110];
230           Sprintf(fname, "%s_%d", rnom.ToCString(),inum);
231           di << "Saving shape in variable Draw : " << fname << "\n";
232           if (answer == 4) WriteShape (shape,inum);
233           try {
234             OCC_CATCH_SIGNALS
235             DBRep::Set(fname,shape);
236           }
237           catch(Standard_Failure const& anException) {
238             di << "** Exception : ";
239             di << anException.GetMessageString();
240             di<<" ** Skip\n";
241           }
242         }
243       }
244       else return 0;
245     }
246
247     else if (modepri == 3) {  // One Entity
248       std::cout << "Only One Entity"<<std::endl;
249       std::cout<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)"<<std::endl;
250       std::cout<<"  To modify : command  param read.iges.bspline.continuity"<<std::endl;
251       std::cout << " give the number of the Entity : " << std::flush;
252       nent = XSDRAW::GetEntityNumber();
253
254       if (!Reader.TransferOne (nent)) di<<"Transfer entity n0 "<<nent<<" : no result\n";
255       else {
256         nbs = Reader.NbShapes();
257         char shname[30];  Sprintf (shname,"%s_%d",rnom.ToCString(),nent);
258         di<<"Transfer entity n0 "<<nent<<" OK  -> DRAW Shape: "<<shname<<"\n";
259         di<<"Now, "<<nbs<<" Shapes produced\n";
260         TopoDS_Shape sh = Reader.Shape(nbs);
261         DBRep::Set (shname,sh);
262       }
263     }
264
265     else if (modepri == 4) {   // Selection
266       Standard_Integer answer = 1;
267       Handle(TColStd_HSequenceOfTransient)  list;
268
269 //  Selection, nommee ou via tcl. tcl : raccourcis admis
270 //   * donne iges-visible + xst-transferrable-roots
271 //   *r donne xst-model-roots (TOUTES racines)
272
273       if( fromtcl && argv[3][0]=='*' && argv[3][1]=='\0' ) {         
274         di << "All Geometry Transfer\n";
275         di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n";
276         di<<"  To modify : command  param read.iges.bspline.continuity\n";
277         Handle(XSControl_WorkSession) thesession = Reader.WS();
278         thesession->ClearContext();
279         XSDRAW::SetTransferProcess (thesession->TransferReader()->TransientProcess());
280         progress->NewScope ( 80, "Translation" );
281         progress->Show();
282         thesession->TransferReader()->TransientProcess()->SetProgress ( progress );
283       
284         Reader.SetReadVisible (Standard_True);
285         Reader.TransferRoots();
286       
287         thesession->TransferReader()->TransientProcess()->SetProgress ( 0 );
288         progress->EndScope();
289         progress->Show();
290         
291         // result in only one shape for all the roots
292         TopoDS_Shape shape = Reader.OneShape();
293         // save the shape
294         char fname[110];
295         Sprintf(fname, "%s", rnom.ToCString());
296         di << "Saving shape in variable Draw : " << fname << "\n";
297         try {
298           OCC_CATCH_SIGNALS
299           DBRep::Set(fname,shape);
300         }
301         catch(Standard_Failure const& anException) {
302           di << "** Exception : ";
303           di << anException.GetMessageString();
304           di<<" ** Skip\n";
305           di << "Saving shape in variable Draw : " << fname << "\n";
306           WriteShape (shape,1);
307         }                                                                             
308         return 0;
309       }
310    
311       if(fromtcl) {
312         modepri = 0;    // d office, une seule passe
313         if (argv[3][0] == '*' && argv[3][1] == 'r' && argv[3][2] == '\0') {
314           di<<"All Roots : ";
315           list = XSDRAW::GetList ("xst-model-roots");
316         }
317         else {
318           TCollection_AsciiString compart = XSDRAW_CommandPart (argc,argv,3);
319           di<<"List given by "<<compart.ToCString()<<" : ";
320           list = XSDRAW::GetList (compart.ToCString());
321         }
322         if (list.IsNull()) {
323           di<<"No list defined. Give a selection name or * for all visible transferrable roots\n";
324           continue;
325         }
326       }
327       else {
328         std::cout<<"Name of Selection :"<<std::flush;
329         list = XSDRAW::GetList();
330         if (list.IsNull()) { std::cout<<"No list defined"<<std::endl; continue; }
331       }
332
333       Standard_Integer nbl = list->Length();
334       di<<"Nb entities selected : "<<nbl<<"\n";
335       if (nbl == 0) continue;
336       while (answer) {
337         if (!fromtcl) {
338           std::cout<<"Choice: 0 abandon  1 transfer all  2 with confirmation  3 list n0s ents :"<<std::flush;
339           answer = -1;
340           // anv 26.09.2003                                                     
341           char str_answer[80];                                                  
342           std::cin>>str_answer;                                                      
343           answer = Draw::Atoi(str_answer);    
344         }
345         if (answer <= 0 || answer > 3) continue;
346         if (answer == 3) {
347           for (Standard_Integer ill = 1; ill <= nbl; ill ++) {
348             Handle(Standard_Transient) ent = list->Value(ill);
349             di<<"  ";// model->Print(ent,di);
350           }
351           di<<"\n";
352         }
353         if (answer == 1 || answer == 2) {
354           Standard_Integer nbt = 0;
355           Handle(XSControl_WorkSession) thesession = Reader.WS();
356         
357           XSDRAW::SetTransferProcess (thesession->TransferReader()->TransientProcess());
358           progress->NewScope ( 80, "Translation" );
359           progress->Show();
360           thesession->TransferReader()->TransientProcess()->SetProgress ( progress );
361
362           Message_ProgressSentry PSentry ( progress, "Root", 0, nbl, 1 );
363           for (Standard_Integer ill = 1; ill <= nbl && PSentry.More(); ill ++, PSentry.Next()) {
364           
365             nent = Reader.Model()->Number(list->Value(ill));
366             if (nent == 0) continue;
367             if (!Reader.TransferOne(nent)) di<<"Transfer entity n0 "<<nent<<" : no result\n";
368             else {
369               nbs = Reader.NbShapes();
370               char shname[30];  Sprintf (shname,"%s_%d",rnom.ToCString(),nbs);
371               di<<"Transfer entity n0 "<<nent<<" OK  -> DRAW Shape: "<<shname<<"\n";
372               di<<"Now, "<<nbs<<" Shapes produced\n";
373               TopoDS_Shape sh = Reader.Shape(nbs);
374               DBRep::Set (shname,sh);
375               nbt++;
376             }
377           }
378           thesession->TransferReader()->TransientProcess()->SetProgress ( 0 );
379           progress->EndScope();
380           progress->Show();
381           di<<"Nb Shapes successfully produced : "<<nbt<<"\n";
382           answer = 0;  // on ne reboucle pas
383         }
384       }
385     }
386     else di<<"Unknown mode n0 "<<modepri<<"\n";
387   }
388   return 0;
389 }
390
391 //--------------------------------------------------------------
392 // Function : testreadiges
393 //
394 //--------------------------------------------------------------
395 static Standard_Integer testread (Draw_Interpretor& di, Standard_Integer argc, const char** argv) 
396 {
397   if (argc != 3)                                                                                      
398     {                                                                                             
399       di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n";                     
400       di << " Usage : " << argv[0] <<" file_name shape_name\n";                          
401       return 1;                                                                                 
402     }  
403   IGESControl_Reader Reader;
404   Standard_CString filename = argv[1];
405   IFSelect_ReturnStatus readstat =  Reader.ReadFile(filename);
406   di<<"Status from reading IGES file "<<filename<<" : ";  
407   switch(readstat) {                                                              
408     case IFSelect_RetVoid  : { di<<"empty file\n"; return 1; }            
409     case IFSelect_RetDone  : { di<<"file read\n";    break; }             
410     case IFSelect_RetError : { di<<"file not found\n";   return 1; }      
411     case IFSelect_RetFail  : { di<<"error during read\n";  return 1; }    
412     default  :  { di<<"failure\n";   return 1; }                          
413   }       
414   Reader.TransferRoots();
415   TopoDS_Shape shape = Reader.OneShape();
416   DBRep::Set(argv[2],shape); 
417   di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n";
418   return 0;  
419 }
420  
421 //--------------------------------------------------------------
422 // Function : brepiges
423 //
424 //--------------------------------------------------------------
425
426 static Standard_Integer brepiges (Draw_Interpretor& di, Standard_Integer n, const char** a) 
427 {
428   XSDRAW::SetNorm ("IGES");
429   // ecriture dans le model d'une entite :
430   //    -  model_AddEntity(ent)             : ecriture de l`entite seule
431   //    -  model->AddWithRefs(ent, protocol): ecriture de l`entite et eventuellement 
432   //                                          . de sa matrice de transformation 
433   //                                          . de ses sous-elements
434
435   IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"),
436                           Interface_Static::IVal("write.iges.brep.mode"));
437   di<<"unit (write) : "<<Interface_Static::CVal("write.iges.unit")<<"\n";
438   di<<"mode  write  : "<<Interface_Static::CVal("write.iges.brep.mode")<<"\n";
439   di<<"  To modifiy : command  param\n";
440
441 //  Mode d emploi (K4B ->) : brepiges shape [+shape][ +shape] nomfic
442 //   c a d tant qu il y a des + on ajoute ce qui suit
443   const char* nomfic = NULL;
444   Standard_Integer npris = 0;
445
446   Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 );
447   progress->NewScope(90,"Translating");
448   progress->Show();
449   ICW.TransferProcess()->SetProgress(progress);
450
451   for ( Standard_Integer i = 1; i < n; i++) {
452     const char* nomvar = a[i];
453     if (a[i][0] == '+') nomvar = &(a[i])[1];
454     else if (i > 1)  {  nomfic = a[i];  break;  }
455     TopoDS_Shape Shape = DBRep::Get(nomvar);
456     if      (ICW.AddShape (Shape)) npris ++;
457     else if (ICW.AddGeom (DrawTrSurf::GetCurve   (nomvar)) ) npris ++;
458     else if (ICW.AddGeom (DrawTrSurf::GetSurface (nomvar)) ) npris ++;
459   }
460   ICW.ComputeModel();
461   XSDRAW::SetModel(ICW.Model());
462   XSDRAW::SetTransferProcess (ICW.TransferProcess());
463     
464   ICW.TransferProcess()->SetProgress(0);
465   progress->EndScope();
466   progress->Show();
467   progress->NewScope(10,"Writing");
468   progress->Show();
469
470   di<<npris<<" Shapes written, giving "<<XSDRAW::Model()->NbEntities()<<" Entities\n";
471
472   if ( ! nomfic ) // delayed write
473   {
474     di<<" Now, to write a file, command : writeall filename\n";
475     return 0;
476   }
477
478   // write file
479   if (! ICW.Write(nomfic)) di<<" Error: could not write file " << nomfic;
480   else                     di<<" File " << nomfic << " written";
481
482   progress->EndScope();
483   progress->Show();
484
485   return 0;
486 }
487
488 //--------------------------------------------------------------
489 // Function : testwriteiges
490 //
491 //--------------------------------------------------------------
492
493 static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer n, const char** a) 
494 {
495   if (n != 3)                                                                                      
496     {                                                                                             
497       di << "ERROR in " << a[0] << "Wrong Number of Arguments.\n";                     
498       di << " Usage : " << a[0] <<" file_name shape_name\n";                          
499       return 1;                                                                                 
500     }
501   IGESControl_Writer Writer;
502   Standard_CString filename = a[1];
503   TopoDS_Shape shape = DBRep::Get(a[2]); 
504   Standard_Boolean ok = Writer.AddShape(shape);
505   if(!ok){
506     di<<"Shape not add\n";
507     return 1;
508   }
509   
510   if(!(Writer.Write(filename))){
511     di<<"Error on writing file\n";
512     return 1;
513   }
514   di<<"File Is Written\n"; 
515   return 0;
516 }
517 //--------------------------------------------------------------
518 // Function : igesparam
519 //
520 //--------------------------------------------------------------
521
522
523 static Standard_Integer igesparam (Draw_Interpretor& di, Standard_Integer , const char** ) 
524 {
525 //  liste des parametres
526   di<<"List of parameters which control IGES :\n";
527   di<<"  unit : write.iges.unit\n  mode write : write.iges.brep.mode\n  spline_continuity (read) : read.iges.bspline.continuity\nSee definition by  defparam, read/edit value by  param\n";
528   di<<"unit (write) : "<<Interface_Static::CVal("write.iges.unit")<<"\n";
529   di<<"mode  write  : "<<Interface_Static::CVal("write.iges.brep.mode")<<"\n";
530   di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n";
531   di<<"\n To modifier, param nom_param new_val\n";
532   return 0;
533 }
534
535
536 //--------------------------------------------------------------
537 // Function : tplosttrim
538 //
539 //--------------------------------------------------------------
540
541 static Standard_Integer XSDRAWIGES_tplosttrim (Draw_Interpretor& di, Standard_Integer n, const char** a) 
542 {
543   Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
544
545 //  Standard_Integer narg = pilot->NbWords();
546   Standard_Integer narg = n;
547
548   const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
549   TColStd_Array1OfAsciiString strarg(1, 3);
550   TColStd_Array1OfAsciiString typarg(1, 3);
551   strarg.SetValue(1,"xst-type(CurveOnSurface)");
552   strarg.SetValue(2,"xst-type(Boundary)");
553   strarg.SetValue(3,"xst-type(Loop)");
554   typarg.SetValue(1,"IGESGeom_TrimmedSurface");
555   typarg.SetValue(2,"IGESGeom_BoundedSurface");
556   typarg.SetValue(3,"IGESSolid_Face");
557   if (TP.IsNull()) { di<<"No Transfer Read\n"; return 1; }
558   Standard_Integer nbFaces = 0, totFaces = 0 ;
559   Handle(IFSelect_WorkSession) WS = pilot->Session(); 
560   Transfer_IteratorOfProcessForTransient itrp = TP->AbnormalResult(); 
561   Standard_Integer k=0;
562   if(narg > 1) {
563 //    TCollection_AsciiString Arg = pilot->Word(1);
564     TCollection_AsciiString Arg(a[1]);
565     for(k=1 ; k<=3;k++ ) {
566       if(typarg.Value(k).Location(Arg,1,typarg.Value(k).Length()) != 0) break;
567     }
568   }   
569   if( k == 4) {di<< "Invalid argument\n"; return 0; }
570   for(Standard_Integer j = 1 ; j <= 3; j++) {
571     TColStd_MapOfTransient aMap;
572     if(narg == 1) k=j;
573     Handle(TColStd_HSequenceOfTransient) list = IFSelect_Functions::GiveList(pilot->Session(),strarg.Value(k).ToCString());
574     if (!list.IsNull()) itrp.Filter (list);
575     else {
576       di << "No untrimmed faces\n";
577       return 0;
578     }
579     for (itrp.Start(); itrp.More(); itrp.Next()) {
580       Handle(Standard_Transient) ent = itrp.Starting();
581       Handle(TColStd_HSequenceOfTransient) super = WS->Sharings (ent);
582       if (!super.IsNull()) {
583         Standard_Integer nb = super->Length();
584         if (nb > 0) {
585             for (Standard_Integer i = 1; i <= nb; i++)
586               if (super->Value(i)->IsKind (typarg.Value(k).ToCString())) {
587                 if(aMap.Add(super->Value(i))) nbFaces++;
588               }
589         }
590       }
591     }
592     if(nbFaces != 0) {
593       if( j == 1 ) di << "Number of untrimmed faces: \n";
594       switch(k){
595       case 1:  
596         di << "Trimmed Surface: \n"; break;
597       case 2:
598         di << "Bounded Surface: \n"; break;
599       case 3:
600         di << "Face: \n"; break;
601       }
602
603       TColStd_MapIteratorOfMapOfTransient itmap;
604       Standard_SStream aTmpStream;
605       for(itmap.Initialize(aMap); itmap.More(); itmap.Next()) {
606         XSDRAW::Model()->Print (itmap.Key(), aTmpStream);
607         aTmpStream << "  ";
608       }
609       di << aTmpStream.str().c_str();
610       di << "\n";
611       di << "\nNumber:"<< nbFaces << "\n";
612       totFaces += nbFaces;
613     }
614     if(narg > 1) break;
615     nbFaces = 0;
616   }
617   
618   if(totFaces == 0) di << "No untrimmed faces\n";
619   else              di << "Total number :" << totFaces << "\n";
620   return 0;
621 }
622 //-------------------------------------------------------------------
623 //--------------------------------------------------------------
624 // Function : TPSTAT
625 //
626 //--------------------------------------------------------------
627 static Standard_Integer XSDRAWIGES_TPSTAT(Draw_Interpretor& di,Standard_Integer n, const char** a)
628 {
629   Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
630   Standard_Integer argc = n;//= pilot->NbWords();
631   const Standard_CString arg1 = a[1];//pilot->Arg(1);
632   const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess();
633   IGESControl_Reader read; //(XSControl::Session(pilot),Standard_False);
634 //        ****    tpent        ****
635   Handle(Interface_InterfaceModel) model = TP->Model();
636   if (model.IsNull()) {di<<"No Transfer Read\n"; return -1;}
637   Handle(XSControl_WorkSession) thesession = read.WS();
638   thesession->SetMapReader(TP);
639   Standard_Integer mod1 = 0;
640   if (argc > 1) {
641     char a2 = arg1[1]; if (a2 == '\0') a2 = '!';
642     switch (arg1[0]) {
643     case 'g' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_GeneralInfo);break;
644     case 'c' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_CountByItem); break;
645     case 'C' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ListByItem); break;
646     case 'r' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ResultCount);break;
647     case 's' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_Mapping);break;
648     case '?' : mod1 = -1; break;
649     default  : mod1 = -2; break;
650     }
651   }
652   if (mod1 < -1) di<<"Unknown Mode\n";
653   if (mod1 < 0) {
654     di<<"Modes available :\n"
655       <<"g : general    c : checks (count)  C (list)\n"
656       <<"r : number of CasCade resulting shapes\n"
657       <<"s : mapping between IGES entities and CasCade shapes\n";
658     if (mod1 < -1) return -1;
659     return 0;
660   }
661   return 0;
662 }
663
664 static Standard_Integer etest(Draw_Interpretor& di, Standard_Integer argc, const char** a)
665 {
666   if(argc < 3) {
667     di<<"etest igesfile shape\n";
668     return 0;
669   }
670   IGESControl_Reader aReader;
671   aReader.ReadFile(a[1]);
672   aReader.SetReadVisible(Standard_True);
673   aReader.TransferRoots();
674   TopoDS_Shape shape = aReader.OneShape();
675   DBRep::Set(a[2],shape);
676   return 0;
677 }
678
679 extern "C" {
680 static void cleanpilot ()
681 {
682   XSDRAW::Session()->ClearData(1);
683 }
684 }
685
686
687 //--------------------------------------------------------------
688 // Function : Init(s)
689 //
690 //--------------------------------------------------------------
691
692 void  XSDRAWIGES::InitSelect ()
693 {
694   Handle(IGESSelect_Activator)    igesact = new IGESSelect_Activator;
695   IGESControl_Controller::Init();
696 //  XSDRAW::SetNorm ("IGES");  trop tot
697   XSDRAW::SetController (XSControl_Controller::Recorded("iges"));
698   
699   atexit (cleanpilot);
700 }
701
702
703 //=======================================================================
704 //function : InitToBRep
705 //purpose  : 
706 //=======================================================================
707
708 void  XSDRAWIGES::InitToBRep (Draw_Interpretor& theCommands)
709 {
710   const char* g = "DE: IGES";
711   theCommands.Add("igesbrep",     "igesbrep [file else already loaded model] [name DRAW]",     __FILE__, igesbrep,              g);
712   theCommands.Add("testreadiges", "testreadiges [file else already loaded model] [name DRAW]", __FILE__, testread,              g);
713   theCommands.Add("igesread",     "igesread [file else already loaded model] [name DRAW]",     __FILE__, igesbrep,              g);
714   theCommands.Add("igesparam",    "igesparam ->list, + name ->one param, + name val->change",  __FILE__, igesparam,             g);
715   theCommands.Add("TPSTAT",       " ",                                                         __FILE__, XSDRAWIGES_TPSTAT,     g);
716   theCommands.Add("tplosttrim",   "number of untrimmed faces during last transfer",            __FILE__, XSDRAWIGES_tplosttrim, g);
717   theCommands.Add("etest",        "test of eviewer",                                           __FILE__, etest,                 g);
718
719 }
720
721
722 //=======================================================================
723 //function : InitFromBRep
724 //purpose  : 
725 //=======================================================================
726
727 void  XSDRAWIGES::InitFromBRep (Draw_Interpretor& theCommands)
728 {
729   const char* g = "DE: IGES";
730   theCommands.Add("brepiges",      "brepiges sh1 [+sh2 [+sh3 ..]] filename.igs", __FILE__, brepiges,  g);
731   theCommands.Add("testwriteiges", "testwriteiges filename.igs shape",           __FILE__, testwrite, g);
732 }