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