0026809: Visualization, TKOpenGl - handle point arrays with per-vertex color within...
[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>
62#include <XSDRAW.hxx>
63#include <XSDRAW_Commands.hxx>
64#include <XSDRAWIGES.hxx>
7fd59977 65
42cf5bc1 66#include <stdio.h>
67// #include <IGESData_IGESWriter.hxx>
68// pour igeslist
7fd59977 69//#include <GeometryTest.hxx> essai CKY 4-AUT-1998
70//#include <BRepTest.hxx> essai CKY 4-AUT-1998
71//#include <MeshTest.hxx> essai CKY 4-AUT-1998
7fd59977 72// Init functions
7fd59977 73// + tplosttrim
7fd59977 74//--------------------------------------------------------------
75// Function : igesbrep
7fd59977 76//--------------------------------------------------------------
7fd59977 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) {
586db386 119 if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon\n";
120 else di<<"No model loaded\n";
7fd59977 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;
91322f44 139 modepri = Draw::Atoi(str);
7fd59977 140 }
141
142 if (modepri == 0) { //fin
586db386 143 di << "Bye and good luck! \n";
7fd59977 144 break;
145 }
146
147 else if (modepri <= 2) { // 1 : Visible Roots, 2 : All Roots
586db386 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";
7fd59977 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;
91322f44 174 answer = Draw::Atoi(str_a);
7fd59977 175 }
176 if ( answer == 0) continue;
177 if ( answer == 1 || answer == 3) {
178 TopoDS_Shape shape = Reader.OneShape();
179 // save the shape
586db386 180 if (shape.IsNull()) { di<<"No Shape produced\n"; continue; }
7fd59977 181 char fname[110];
91322f44 182 Sprintf(fname, "%s", rnom.ToCString());
7fd59977 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();
586db386 192 di<<" ** Skip\n";
7fd59977 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);
586db386 203 if (shape.IsNull()) { di<<"No Shape produced\n"; continue; }
7fd59977 204 char fname[110];
91322f44 205 Sprintf(fname, "%s_%d", rnom.ToCString(),inum);
7fd59977 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();
586db386 215 di<<" ** Skip\n";
7fd59977 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
586db386 229 if (!Reader.TransferOne (nent)) di<<"Transfer entity n0 "<<nent<<" : no result\n";
7fd59977 230 else {
231 nbs = Reader.NbShapes();
91322f44 232 char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nent);
7fd59977 233 di<<"Transfer entity n0 "<<nent<<" OK -> DRAW Shape: "<<shname<<"\n";
586db386 234 di<<"Now, "<<nbs<<" Shapes produced\n";
7fd59977 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' ) {
586db386 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";
7fd59977 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];
91322f44 270 Sprintf(fname, "%s", rnom.ToCString());
7fd59977 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();
586db386 279 di<<" ** Skip\n";
7fd59977 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()) {
586db386 298 di<<"No list defined. Give a selection name or * for all visible transferrable roots\n";
7fd59977 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;
91322f44 318 answer = Draw::Atoi(str_answer);
7fd59977 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;
586db386 342 if (!Reader.TransferOne(nent)) di<<"Transfer entity n0 "<<nent<<" : no result\n";
7fd59977 343 else {
344 nbs = Reader.NbShapes();
91322f44 345 char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nbs);
7fd59977 346 di<<"Transfer entity n0 "<<nent<<" OK -> DRAW Shape: "<<shname<<"\n";
586db386 347 di<<"Now, "<<nbs<<" Shapes produced\n";
7fd59977 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 {
586db386 374 di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n";
375 di << " Usage : " << argv[0] <<" file_name shape_name\n";
7fd59977 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) {
586db386 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; }
7fd59977 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";
586db386 414 di<<" To modifiy : command param\n";
7fd59977 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
1d47d8d0 418 const char* nomfic = NULL;
7fd59977 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];
2857a8ac 429 else if (i > 1) { nomfic = a[i]; break; }
7fd59977 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
586db386 445 di<<npris<<" Shapes written, giving "<<XSDRAW::Model()->NbEntities()<<" Entities\n";
7fd59977 446
2857a8ac 447 if ( ! nomfic ) // delayed write
448 {
586db386 449 di<<" Now, to write a file, command : writeall filename\n";
2857a8ac 450 return 0;
7fd59977 451 }
452
2857a8ac 453 // write file
454 if (! ICW.Write(nomfic)) di<<" Error: could not write file " << nomfic;
455 else di<<" File " << nomfic << " written";
7fd59977 456
457 progress->EndScope();
458 progress->Show();
459
460 return 0;
461}
462
463//--------------------------------------------------------------
464// Function : testwriteiges
465//
466//--------------------------------------------------------------
467
468static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer n, const char** a)
469{
470 if (n != 3)
471 {
586db386 472 di << "ERROR in " << a[0] << "Wrong Number of Arguments.\n";
473 di << " Usage : " << a[0] <<" file_name shape_name\n";
7fd59977 474 return 1;
475 }
476 IGESControl_Writer Writer;
477 Standard_CString filename = a[1];
478 TopoDS_Shape shape = DBRep::Get(a[2]);
479 Standard_Boolean ok = Writer.AddShape(shape);
480 if(!ok){
586db386 481 di<<"Shape not add\n";
7fd59977 482 return 1;
483 }
484
485 if(!(Writer.Write(filename))){
586db386 486 di<<"Error on writing file\n";
7fd59977 487 return 1;
488 }
586db386 489 di<<"File Is Written\n";
7fd59977 490 return 0;
491}
492//--------------------------------------------------------------
493// Function : igesparam
494//
495//--------------------------------------------------------------
496
497
498static Standard_Integer igesparam (Draw_Interpretor& di, Standard_Integer , const char** )
499{
500// liste des parametres
586db386 501 di<<"List of parameters which control IGES :\n";
502 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 503 di<<"unit (write) : "<<Interface_Static::CVal("write.iges.unit")<<"\n";
504 di<<"mode write : "<<Interface_Static::CVal("write.iges.brep.mode")<<"\n";
586db386 505 di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n";
506 di<<"\n To modifier, param nom_param new_val\n";
7fd59977 507 return 0;
508}
509
510
511//--------------------------------------------------------------
512// Function : tplosttrim
513//
514//--------------------------------------------------------------
515
516static Standard_Integer XSDRAWIGES_tplosttrim (Draw_Interpretor& di, Standard_Integer n, const char** a)
517{
518 Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
519
520// Standard_Integer narg = pilot->NbWords();
521 Standard_Integer narg = n;
522
523 Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->MapReader();
524 TColStd_Array1OfAsciiString strarg(1, 3);
525 TColStd_Array1OfAsciiString typarg(1, 3);
526 strarg.SetValue(1,"xst-type(CurveOnSurface)");
527 strarg.SetValue(2,"xst-type(Boundary)");
528 strarg.SetValue(3,"xst-type(Loop)");
529 typarg.SetValue(1,"IGESGeom_TrimmedSurface");
530 typarg.SetValue(2,"IGESGeom_BoundedSurface");
531 typarg.SetValue(3,"IGESSolid_Face");
586db386 532 if (TP.IsNull()) { di<<"No Transfer Read\n"; return 1; }
7fd59977 533 Standard_Integer nbFaces = 0, totFaces = 0 ;
534 Handle(IFSelect_WorkSession) WS = pilot->Session();
535 Transfer_IteratorOfProcessForTransient itrp = TP->AbnormalResult();
536 Standard_Integer k=0;
537 if(narg > 1) {
538// TCollection_AsciiString Arg = pilot->Word(1);
539 TCollection_AsciiString Arg(a[1]);
540 for(k=1 ; k<=3;k++ ) {
541 if(typarg.Value(k).Location(Arg,1,typarg.Value(k).Length()) != 0) break;
542 }
543 }
586db386 544 if( k == 4) {di<< "Invalid argument\n"; return 0; }
7fd59977 545 for(Standard_Integer j = 1 ; j <= 3; j++) {
546 TColStd_MapOfTransient aMap;
547 if(narg == 1) k=j;
548 Handle(TColStd_HSequenceOfTransient) list = IFSelect_Functions::GiveList(pilot->Session(),strarg.Value(k).ToCString());
549 if (!list.IsNull()) itrp.Filter (list);
550 else {
586db386 551 di << "No untrimmed faces\n";
7fd59977 552 return 0;
553 }
554 for (itrp.Start(); itrp.More(); itrp.Next()) {
555 Handle(Standard_Transient) ent = itrp.Starting();
556 Handle(TColStd_HSequenceOfTransient) super = WS->Sharings (ent);
557 if (!super.IsNull()) {
558 Standard_Integer nb = super->Length();
559 if (nb > 0) {
560 for (Standard_Integer i = 1; i <= nb; i++)
561 if (super->Value(i)->IsKind (typarg.Value(k).ToCString())) {
562 if(aMap.Add(super->Value(i))) nbFaces++;
563 }
564 }
565 }
566 }
567 if(nbFaces != 0) {
586db386 568 if( j == 1 ) di << "Number of untrimmed faces: \n";
7fd59977 569 switch(k){
570 case 1:
586db386 571 di << "Trimmed Surface: \n"; break;
7fd59977 572 case 2:
586db386 573 di << "Bounded Surface: \n"; break;
7fd59977 574 case 3:
586db386 575 di << "Face: \n"; break;
7fd59977 576 }
785a9540 577
7fd59977 578 TColStd_MapIteratorOfMapOfTransient itmap;
579 for(itmap.Initialize(aMap); itmap.More(); itmap.Next()) {
785a9540 580 XSDRAW::Model()->Print (itmap.Key(), Message::DefaultMessenger());
581 di << " ";
7fd59977 582 }
583 di << "\n";
586db386 584 di << "\nNumber:"<< nbFaces << "\n";
7fd59977 585 totFaces += nbFaces;
586 }
587 if(narg > 1) break;
588 nbFaces = 0;
589 }
590
586db386 591 if(totFaces == 0) di << "No untrimmed faces\n";
7fd59977 592 else di << "Total number :" << totFaces << "\n";
593 return 0;
594}
595//-------------------------------------------------------------------
596//--------------------------------------------------------------
597// Function : TPSTAT
598//
599//--------------------------------------------------------------
600static Standard_Integer XSDRAWIGES_TPSTAT(Draw_Interpretor& di,Standard_Integer n, const char** a)
601{
602 Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot();
603 Standard_Integer argc = n;//= pilot->NbWords();
604 const Standard_CString arg1 = a[1];//pilot->Arg(1);
605 //IGESControl_Reader read; //(XSControl::Session(pilot),Standard_False);
606 Handle(Transfer_TransientProcess) TP= XSControl::Session(pilot)->MapReader();
607 IGESControl_Reader read; //(XSControl::Session(pilot),Standard_False);
608 //read.SetTransientProcess(TP);
609// **** tpent ****
586db386 610// if (TP.IsNull()) { di<<"No Transfer Read\n"; return IFSelect_RetError;}
7fd59977 611 Handle(Interface_InterfaceModel) model = TP->Model();
612 //Handle(Interface_InterfaceModel) model = read.Model();
586db386 613 if (model.IsNull()) {di<<"No Transfer Read\n"; return -1;}
7fd59977 614 //DeclareAndCast(IGESData_IGESModel,modelig,model);
615 // read.SetModel(modelig);
616 Handle(XSControl_WorkSession) thesession = read.WS();
617 thesession->SetMapReader(TP);
618 //read.SetModel(model);
619 Standard_Integer mod1 = 0;
620 if (argc > 1) {
621 char a2 = arg1[1]; if (a2 == '\0') a2 = '!';
622 switch (arg1[0]) {
623 case 'g' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_GeneralInfo);break;
624 case 'c' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_CountByItem); break;
625 case 'C' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ListByItem); break;
626 case 'r' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ResultCount);break;
627 case 's' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_Mapping);break;
628 case '?' : mod1 = -1; break;
629 default : mod1 = -2; break;
630 }
631 }
586db386 632 if (mod1 < -1) di<<"Unknown Mode\n";
7fd59977 633 if (mod1 < 0) {
634 di<<"Modes available :\n"
586db386 635 <<"g : general c : checks (count) C (list)\n"
636 <<"r : number of CasCade resulting shapes\n"
637 <<"s : mapping between IGES entities and CasCade shapes\n";
7fd59977 638 if (mod1 < -1) return -1;
639 return 0;
640 }
641 return 0;
642}
643
644static Standard_Integer etest(Draw_Interpretor& di, Standard_Integer argc, const char** a)
645{
646 if(argc < 3) {
586db386 647 di<<"etest igesfile shape\n";
7fd59977 648 return 0;
649 }
650 IGESControl_Reader aReader;
651 aReader.ReadFile(a[1]);
652 aReader.SetReadVisible(Standard_True);
653 aReader.TransferRoots();
654 TopoDS_Shape shape = aReader.OneShape();
655 DBRep::Set(a[2],shape);
656 return 0;
657}
658
659extern "C" {
660static void cleanpilot ()
661{
662 XSDRAW::Session()->ClearData(1);
663}
664}
665
666
667//--------------------------------------------------------------
668// Function : Init(s)
669//
670//--------------------------------------------------------------
671
672void XSDRAWIGES::InitSelect ()
673{
674 Handle(IGESSelect_Activator) igesact = new IGESSelect_Activator;
675 IGESControl_Controller::Init();
676// XSDRAW::SetNorm ("IGES"); trop tot
677 XSDRAW::SetController (XSControl_Controller::Recorded("iges"));
678
679 atexit (cleanpilot);
680}
681
682
683//=======================================================================
684//function : InitToBRep
685//purpose :
686//=======================================================================
687
688void XSDRAWIGES::InitToBRep (Draw_Interpretor& theCommands)
689{
690 const char* g = "DE: IGES";
691 theCommands.Add("igesbrep", "igesbrep [file else already loaded model] [name DRAW]", __FILE__, igesbrep, g);
692 theCommands.Add("testreadiges", "testreadiges [file else already loaded model] [name DRAW]", __FILE__, testread, g);
693 theCommands.Add("igesread", "igesread [file else already loaded model] [name DRAW]", __FILE__, igesbrep, g);
694 theCommands.Add("igesparam", "igesparam ->list, + name ->one param, + name val->change", __FILE__, igesparam, g);
695 theCommands.Add("TPSTAT", " ", __FILE__, XSDRAWIGES_TPSTAT, g);
696 theCommands.Add("tplosttrim", "number of untrimmed faces during last transfer", __FILE__, XSDRAWIGES_tplosttrim, g);
697 theCommands.Add("etest", "test of eviewer", __FILE__, etest, g);
698
699}
700
701
702//=======================================================================
703//function : InitFromBRep
704//purpose :
705//=======================================================================
706
707void XSDRAWIGES::InitFromBRep (Draw_Interpretor& theCommands)
708{
709 const char* g = "DE: IGES";
710 theCommands.Add("brepiges", "brepiges sh1 [+sh2 [+sh3 ..]] filename.igs", __FILE__, brepiges, g);
711 theCommands.Add("testwriteiges", "testwriteiges filename.igs shape", __FILE__, testwrite, g);
712}