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