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