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