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