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