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