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 | |
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> |
7e785937 | 46 | #include <Message_ProgressScope.hxx> |
42cf5bc1 | 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 | |
69 | namespace { | |
70 | ||
71 | //======================================================================= | |
72 | //function : WriteShape | |
73 | //purpose : Creates a file Shape_'number' | |
74 | //======================================================================= | |
75 | void 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 | ||
87 | TCollection_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 | 102 | static 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 ); | |
7e785937 | 109 | Message_ProgressScope aPSRoot (progress->Start(), "Reading", 100); |
7fd59977 | 110 | |
111 | IGESControl_Reader Reader (XSDRAW::Session(),Standard_False); | |
bc650d41 G |
112 | Standard_Boolean aFullMode = Standard_True; |
113 | Reader.WS()->SetModeStat(aFullMode); | |
7fd59977 | 114 | if (ctl.IsNull()) |
115 | ctl=Handle(IGESControl_Controller)::DownCast(XSDRAW::Controller()); | |
116 | ||
117 | TCollection_AsciiString fnom,rnom; | |
118 | ||
119 | Standard_Boolean modfic = XSDRAW::FileAndVar | |
120 | (argv[1],argv[2],"IGESBREP",fnom,rnom); | |
121 | if (modfic) di<<" File IGES to read : "<<fnom.ToCString()<<"\n"; | |
122 | else di<<" Model taken from the session : "<<fnom.ToCString()<<"\n"; | |
123 | di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom.ToCString()<<"\n"; | |
124 | IFSelect_ReturnStatus readstat = IFSelect_RetVoid; | |
125 | ||
126 | #ifdef CHRONOMESURE | |
127 | OSD_Timer Chr; Chr.Reset(); | |
128 | IDT_SetLevel(3); | |
129 | #endif | |
130 | ||
131 | ||
132 | // Reading the file | |
7e785937 | 133 | aPSRoot.SetName("Loading"); |
134 | progress->Show(aPSRoot); | |
7fd59977 | 135 | |
136 | if (modfic) readstat = Reader.ReadFile (fnom.ToCString()); | |
137 | else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone; | |
138 | ||
7e785937 | 139 | aPSRoot.Next(20); // On average loading takes 20% |
140 | if (aPSRoot.UserBreak()) | |
141 | return 1; | |
7fd59977 | 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()); |
7e785937 | 179 | |
180 | aPSRoot.SetName("Translation"); | |
181 | progress->Show(aPSRoot); | |
7fd59977 | 182 | |
183 | if (modepri == 1) Reader.SetReadVisible (Standard_True); | |
7e785937 | 184 | Reader.TransferRoots(aPSRoot.Next(80)); |
7fd59977 | 185 | |
7e785937 | 186 | if (aPSRoot.UserBreak()) |
187 | return 1; | |
188 | ||
7fd59977 | 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 | ||
7e785937 | 254 | if (!Reader.TransferOne (nent)) |
255 | di<<"Transfer entity n0 "<<nent<<" : no result\n"; | |
7fd59977 | 256 | else { |
257 | nbs = Reader.NbShapes(); | |
91322f44 | 258 | char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nent); |
7fd59977 | 259 | di<<"Transfer entity n0 "<<nent<<" OK -> DRAW Shape: "<<shname<<"\n"; |
586db386 | 260 | di<<"Now, "<<nbs<<" Shapes produced\n"; |
7fd59977 | 261 | TopoDS_Shape sh = Reader.Shape(nbs); |
262 | DBRep::Set (shname,sh); | |
263 | } | |
264 | } | |
265 | ||
266 | else if (modepri == 4) { // Selection | |
267 | Standard_Integer answer = 1; | |
268 | Handle(TColStd_HSequenceOfTransient) list; | |
269 | ||
270 | // Selection, nommee ou via tcl. tcl : raccourcis admis | |
271 | // * donne iges-visible + xst-transferrable-roots | |
272 | // *r donne xst-model-roots (TOUTES racines) | |
273 | ||
274 | if( fromtcl && argv[3][0]=='*' && argv[3][1]=='\0' ) { | |
586db386 | 275 | di << "All Geometry Transfer\n"; |
276 | di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n"; | |
277 | di<<" To modify : command param read.iges.bspline.continuity\n"; | |
7fd59977 | 278 | Handle(XSControl_WorkSession) thesession = Reader.WS(); |
279 | thesession->ClearContext(); | |
7f56eba8 | 280 | XSDRAW::SetTransferProcess (thesession->TransferReader()->TransientProcess()); |
7e785937 | 281 | |
282 | aPSRoot.SetName("Translation"); | |
283 | progress->Show(aPSRoot); | |
7fd59977 | 284 | |
285 | Reader.SetReadVisible (Standard_True); | |
7e785937 | 286 | Reader.TransferRoots(aPSRoot.Next(80)); |
7fd59977 | 287 | |
7e785937 | 288 | if (aPSRoot.UserBreak()) |
289 | return 1; | |
290 | ||
7fd59977 | 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()); |
7e785937 | 358 | aPSRoot.SetName("Translation"); |
359 | progress->Show(aPSRoot); | |
7fd59977 | 360 | |
7e785937 | 361 | Message_ProgressScope aPS(aPSRoot.Next(80), "Root", nbl); |
362 | for (Standard_Integer ill = 1; ill <= nbl && aPS.More(); ill++) | |
363 | { | |
7fd59977 | 364 | nent = Reader.Model()->Number(list->Value(ill)); |
365 | if (nent == 0) continue; | |
7e785937 | 366 | if (!Reader.TransferOne(nent, aPS.Next())) |
367 | 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 | } | |
7e785937 | 378 | if (aPSRoot.UserBreak()) |
379 | return 1; | |
380 | di<<"Nb Shapes successfully produced : "<<nbt<<"\n"; | |
7fd59977 | 381 | answer = 0; // on ne reboucle pas |
382 | } | |
383 | } | |
384 | } | |
385 | else di<<"Unknown mode n0 "<<modepri<<"\n"; | |
386 | } | |
387 | return 0; | |
388 | } | |
389 | ||
390 | //-------------------------------------------------------------- | |
391 | // Function : testreadiges | |
392 | // | |
393 | //-------------------------------------------------------------- | |
394 | static Standard_Integer testread (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
395 | { | |
396 | if (argc != 3) | |
397 | { | |
586db386 | 398 | di << "ERROR in " << argv[0] << "Wrong Number of Arguments.\n"; |
399 | di << " Usage : " << argv[0] <<" file_name shape_name\n"; | |
7fd59977 | 400 | return 1; |
401 | } | |
402 | IGESControl_Reader Reader; | |
403 | Standard_CString filename = argv[1]; | |
404 | IFSelect_ReturnStatus readstat = Reader.ReadFile(filename); | |
405 | di<<"Status from reading IGES file "<<filename<<" : "; | |
406 | switch(readstat) { | |
586db386 | 407 | case IFSelect_RetVoid : { di<<"empty file\n"; return 1; } |
408 | case IFSelect_RetDone : { di<<"file read\n"; break; } | |
409 | case IFSelect_RetError : { di<<"file not found\n"; return 1; } | |
410 | case IFSelect_RetFail : { di<<"error during read\n"; return 1; } | |
411 | default : { di<<"failure\n"; return 1; } | |
7fd59977 | 412 | } |
413 | Reader.TransferRoots(); | |
414 | TopoDS_Shape shape = Reader.OneShape(); | |
415 | DBRep::Set(argv[2],shape); | |
416 | di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n"; | |
417 | return 0; | |
418 | } | |
419 | ||
420 | //-------------------------------------------------------------- | |
421 | // Function : brepiges | |
422 | // | |
423 | //-------------------------------------------------------------- | |
424 | ||
425 | static Standard_Integer brepiges (Draw_Interpretor& di, Standard_Integer n, const char** a) | |
426 | { | |
427 | XSDRAW::SetNorm ("IGES"); | |
428 | // ecriture dans le model d'une entite : | |
429 | // - model_AddEntity(ent) : ecriture de l`entite seule | |
430 | // - model->AddWithRefs(ent, protocol): ecriture de l`entite et eventuellement | |
431 | // . de sa matrice de transformation | |
432 | // . de ses sous-elements | |
433 | ||
434 | IGESControl_Writer ICW (Interface_Static::CVal("write.iges.unit"), | |
435 | Interface_Static::IVal("write.iges.brep.mode")); | |
436 | di<<"unit (write) : "<<Interface_Static::CVal("write.iges.unit")<<"\n"; | |
437 | di<<"mode write : "<<Interface_Static::CVal("write.iges.brep.mode")<<"\n"; | |
586db386 | 438 | di<<" To modifiy : command param\n"; |
7fd59977 | 439 | |
440 | // Mode d emploi (K4B ->) : brepiges shape [+shape][ +shape] nomfic | |
441 | // c a d tant qu il y a des + on ajoute ce qui suit | |
1d47d8d0 | 442 | const char* nomfic = NULL; |
7fd59977 | 443 | Standard_Integer npris = 0; |
444 | ||
445 | Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); | |
7e785937 | 446 | Message_ProgressScope aPSRoot (progress->Start(), "Translating", 100); |
447 | progress->Show(aPSRoot); | |
7fd59977 | 448 | |
7e785937 | 449 | Message_ProgressScope aPS(aPSRoot.Next(90), NULL, n); |
450 | for ( Standard_Integer i = 1; i < n && aPS.More(); i++) { | |
7fd59977 | 451 | const char* nomvar = a[i]; |
452 | if (a[i][0] == '+') nomvar = &(a[i])[1]; | |
2857a8ac | 453 | else if (i > 1) { nomfic = a[i]; break; } |
7fd59977 | 454 | TopoDS_Shape Shape = DBRep::Get(nomvar); |
7e785937 | 455 | if (ICW.AddShape (Shape, aPS.Next())) npris ++; |
7fd59977 | 456 | else if (ICW.AddGeom (DrawTrSurf::GetCurve (nomvar)) ) npris ++; |
457 | else if (ICW.AddGeom (DrawTrSurf::GetSurface (nomvar)) ) npris ++; | |
458 | } | |
459 | ICW.ComputeModel(); | |
460 | XSDRAW::SetModel(ICW.Model()); | |
461 | XSDRAW::SetTransferProcess (ICW.TransferProcess()); | |
462 | ||
7e785937 | 463 | if (aPSRoot.UserBreak()) |
464 | return 1; | |
465 | aPSRoot.SetName("Writing"); | |
466 | progress->Show(aPSRoot); | |
7fd59977 | 467 | |
586db386 | 468 | di<<npris<<" Shapes written, giving "<<XSDRAW::Model()->NbEntities()<<" Entities\n"; |
7fd59977 | 469 | |
2857a8ac | 470 | if ( ! nomfic ) // delayed write |
471 | { | |
586db386 | 472 | di<<" Now, to write a file, command : writeall filename\n"; |
2857a8ac | 473 | return 0; |
7fd59977 | 474 | } |
475 | ||
2857a8ac | 476 | // write file |
477 | if (! ICW.Write(nomfic)) di<<" Error: could not write file " << nomfic; | |
478 | else di<<" File " << nomfic << " written"; | |
7fd59977 | 479 | |
7fd59977 | 480 | return 0; |
481 | } | |
482 | ||
483 | //-------------------------------------------------------------- | |
484 | // Function : testwriteiges | |
485 | // | |
486 | //-------------------------------------------------------------- | |
487 | ||
488 | static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer n, const char** a) | |
489 | { | |
490 | if (n != 3) | |
491 | { | |
586db386 | 492 | di << "ERROR in " << a[0] << "Wrong Number of Arguments.\n"; |
493 | di << " Usage : " << a[0] <<" file_name shape_name\n"; | |
7fd59977 | 494 | return 1; |
495 | } | |
496 | IGESControl_Writer Writer; | |
497 | Standard_CString filename = a[1]; | |
498 | TopoDS_Shape shape = DBRep::Get(a[2]); | |
499 | Standard_Boolean ok = Writer.AddShape(shape); | |
500 | if(!ok){ | |
586db386 | 501 | di<<"Shape not add\n"; |
7fd59977 | 502 | return 1; |
503 | } | |
504 | ||
505 | if(!(Writer.Write(filename))){ | |
586db386 | 506 | di<<"Error on writing file\n"; |
7fd59977 | 507 | return 1; |
508 | } | |
586db386 | 509 | di<<"File Is Written\n"; |
7fd59977 | 510 | return 0; |
511 | } | |
512 | //-------------------------------------------------------------- | |
513 | // Function : igesparam | |
514 | // | |
515 | //-------------------------------------------------------------- | |
516 | ||
517 | ||
518 | static Standard_Integer igesparam (Draw_Interpretor& di, Standard_Integer , const char** ) | |
519 | { | |
520 | // liste des parametres | |
586db386 | 521 | di<<"List of parameters which control IGES :\n"; |
522 | 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 | 523 | di<<"unit (write) : "<<Interface_Static::CVal("write.iges.unit")<<"\n"; |
524 | di<<"mode write : "<<Interface_Static::CVal("write.iges.brep.mode")<<"\n"; | |
586db386 | 525 | di<<"spline_continuity (read) : "<<Interface_Static::IVal("read.iges.bspline.continuity")<<" (0 : no modif, 1 : C1, 2 : C2)\n"; |
526 | di<<"\n To modifier, param nom_param new_val\n"; | |
7fd59977 | 527 | return 0; |
528 | } | |
529 | ||
530 | ||
531 | //-------------------------------------------------------------- | |
532 | // Function : tplosttrim | |
533 | // | |
534 | //-------------------------------------------------------------- | |
535 | ||
536 | static Standard_Integer XSDRAWIGES_tplosttrim (Draw_Interpretor& di, Standard_Integer n, const char** a) | |
537 | { | |
538 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); | |
539 | ||
540 | // Standard_Integer narg = pilot->NbWords(); | |
541 | Standard_Integer narg = n; | |
542 | ||
7f56eba8 | 543 | const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); |
7fd59977 | 544 | TColStd_Array1OfAsciiString strarg(1, 3); |
545 | TColStd_Array1OfAsciiString typarg(1, 3); | |
546 | strarg.SetValue(1,"xst-type(CurveOnSurface)"); | |
547 | strarg.SetValue(2,"xst-type(Boundary)"); | |
548 | strarg.SetValue(3,"xst-type(Loop)"); | |
549 | typarg.SetValue(1,"IGESGeom_TrimmedSurface"); | |
550 | typarg.SetValue(2,"IGESGeom_BoundedSurface"); | |
551 | typarg.SetValue(3,"IGESSolid_Face"); | |
586db386 | 552 | if (TP.IsNull()) { di<<"No Transfer Read\n"; return 1; } |
7fd59977 | 553 | Standard_Integer nbFaces = 0, totFaces = 0 ; |
554 | Handle(IFSelect_WorkSession) WS = pilot->Session(); | |
555 | Transfer_IteratorOfProcessForTransient itrp = TP->AbnormalResult(); | |
556 | Standard_Integer k=0; | |
557 | if(narg > 1) { | |
558 | // TCollection_AsciiString Arg = pilot->Word(1); | |
559 | TCollection_AsciiString Arg(a[1]); | |
560 | for(k=1 ; k<=3;k++ ) { | |
561 | if(typarg.Value(k).Location(Arg,1,typarg.Value(k).Length()) != 0) break; | |
562 | } | |
563 | } | |
586db386 | 564 | if( k == 4) {di<< "Invalid argument\n"; return 0; } |
7fd59977 | 565 | for(Standard_Integer j = 1 ; j <= 3; j++) { |
566 | TColStd_MapOfTransient aMap; | |
567 | if(narg == 1) k=j; | |
568 | Handle(TColStd_HSequenceOfTransient) list = IFSelect_Functions::GiveList(pilot->Session(),strarg.Value(k).ToCString()); | |
569 | if (!list.IsNull()) itrp.Filter (list); | |
570 | else { | |
586db386 | 571 | di << "No untrimmed faces\n"; |
7fd59977 | 572 | return 0; |
573 | } | |
574 | for (itrp.Start(); itrp.More(); itrp.Next()) { | |
575 | Handle(Standard_Transient) ent = itrp.Starting(); | |
576 | Handle(TColStd_HSequenceOfTransient) super = WS->Sharings (ent); | |
577 | if (!super.IsNull()) { | |
578 | Standard_Integer nb = super->Length(); | |
579 | if (nb > 0) { | |
580 | for (Standard_Integer i = 1; i <= nb; i++) | |
581 | if (super->Value(i)->IsKind (typarg.Value(k).ToCString())) { | |
582 | if(aMap.Add(super->Value(i))) nbFaces++; | |
583 | } | |
584 | } | |
585 | } | |
586 | } | |
587 | if(nbFaces != 0) { | |
586db386 | 588 | if( j == 1 ) di << "Number of untrimmed faces: \n"; |
7fd59977 | 589 | switch(k){ |
590 | case 1: | |
586db386 | 591 | di << "Trimmed Surface: \n"; break; |
7fd59977 | 592 | case 2: |
586db386 | 593 | di << "Bounded Surface: \n"; break; |
7fd59977 | 594 | case 3: |
586db386 | 595 | di << "Face: \n"; break; |
7fd59977 | 596 | } |
785a9540 | 597 | |
7fd59977 | 598 | TColStd_MapIteratorOfMapOfTransient itmap; |
0ebe5b0a | 599 | Standard_SStream aTmpStream; |
7fd59977 | 600 | for(itmap.Initialize(aMap); itmap.More(); itmap.Next()) { |
0ebe5b0a | 601 | XSDRAW::Model()->Print (itmap.Key(), aTmpStream); |
602 | aTmpStream << " "; | |
7fd59977 | 603 | } |
0ebe5b0a | 604 | di << aTmpStream.str().c_str(); |
7fd59977 | 605 | di << "\n"; |
586db386 | 606 | di << "\nNumber:"<< nbFaces << "\n"; |
7fd59977 | 607 | totFaces += nbFaces; |
608 | } | |
609 | if(narg > 1) break; | |
610 | nbFaces = 0; | |
611 | } | |
612 | ||
586db386 | 613 | if(totFaces == 0) di << "No untrimmed faces\n"; |
7fd59977 | 614 | else di << "Total number :" << totFaces << "\n"; |
615 | return 0; | |
616 | } | |
617 | //------------------------------------------------------------------- | |
618 | //-------------------------------------------------------------- | |
619 | // Function : TPSTAT | |
620 | // | |
621 | //-------------------------------------------------------------- | |
622 | static Standard_Integer XSDRAWIGES_TPSTAT(Draw_Interpretor& di,Standard_Integer n, const char** a) | |
623 | { | |
624 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); | |
625 | Standard_Integer argc = n;//= pilot->NbWords(); | |
626 | const Standard_CString arg1 = a[1];//pilot->Arg(1); | |
7f56eba8 | 627 | const Handle(Transfer_TransientProcess) &TP = XSControl::Session(pilot)->TransferReader()->TransientProcess(); |
628 | IGESControl_Reader read; //(XSControl::Session(pilot),Standard_False); | |
7fd59977 | 629 | // **** tpent **** |
7fd59977 | 630 | Handle(Interface_InterfaceModel) model = TP->Model(); |
586db386 | 631 | if (model.IsNull()) {di<<"No Transfer Read\n"; return -1;} |
7fd59977 | 632 | Handle(XSControl_WorkSession) thesession = read.WS(); |
633 | thesession->SetMapReader(TP); | |
7fd59977 | 634 | Standard_Integer mod1 = 0; |
635 | if (argc > 1) { | |
636 | char a2 = arg1[1]; if (a2 == '\0') a2 = '!'; | |
637 | switch (arg1[0]) { | |
638 | case 'g' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_GeneralInfo);break; | |
639 | case 'c' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_CountByItem); break; | |
640 | case 'C' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ListByItem); break; | |
641 | case 'r' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_ResultCount);break; | |
642 | case 's' : read.PrintTransferInfo(IFSelect_FailAndWarn,IFSelect_Mapping);break; | |
643 | case '?' : mod1 = -1; break; | |
644 | default : mod1 = -2; break; | |
645 | } | |
646 | } | |
586db386 | 647 | if (mod1 < -1) di<<"Unknown Mode\n"; |
7fd59977 | 648 | if (mod1 < 0) { |
649 | di<<"Modes available :\n" | |
586db386 | 650 | <<"g : general c : checks (count) C (list)\n" |
651 | <<"r : number of CasCade resulting shapes\n" | |
652 | <<"s : mapping between IGES entities and CasCade shapes\n"; | |
7fd59977 | 653 | if (mod1 < -1) return -1; |
654 | return 0; | |
655 | } | |
656 | return 0; | |
657 | } | |
658 | ||
659 | static Standard_Integer etest(Draw_Interpretor& di, Standard_Integer argc, const char** a) | |
660 | { | |
661 | if(argc < 3) { | |
586db386 | 662 | di<<"etest igesfile shape\n"; |
7fd59977 | 663 | return 0; |
664 | } | |
665 | IGESControl_Reader aReader; | |
666 | aReader.ReadFile(a[1]); | |
667 | aReader.SetReadVisible(Standard_True); | |
668 | aReader.TransferRoots(); | |
669 | TopoDS_Shape shape = aReader.OneShape(); | |
670 | DBRep::Set(a[2],shape); | |
671 | return 0; | |
672 | } | |
673 | ||
674 | extern "C" { | |
675 | static void cleanpilot () | |
676 | { | |
677 | XSDRAW::Session()->ClearData(1); | |
678 | } | |
679 | } | |
680 | ||
681 | ||
682 | //-------------------------------------------------------------- | |
683 | // Function : Init(s) | |
684 | // | |
685 | //-------------------------------------------------------------- | |
686 | ||
687 | void XSDRAWIGES::InitSelect () | |
688 | { | |
689 | Handle(IGESSelect_Activator) igesact = new IGESSelect_Activator; | |
690 | IGESControl_Controller::Init(); | |
691 | // XSDRAW::SetNorm ("IGES"); trop tot | |
692 | XSDRAW::SetController (XSControl_Controller::Recorded("iges")); | |
693 | ||
694 | atexit (cleanpilot); | |
695 | } | |
696 | ||
697 | ||
698 | //======================================================================= | |
699 | //function : InitToBRep | |
700 | //purpose : | |
701 | //======================================================================= | |
702 | ||
703 | void XSDRAWIGES::InitToBRep (Draw_Interpretor& theCommands) | |
704 | { | |
705 | const char* g = "DE: IGES"; | |
706 | theCommands.Add("igesbrep", "igesbrep [file else already loaded model] [name DRAW]", __FILE__, igesbrep, g); | |
707 | theCommands.Add("testreadiges", "testreadiges [file else already loaded model] [name DRAW]", __FILE__, testread, g); | |
708 | theCommands.Add("igesread", "igesread [file else already loaded model] [name DRAW]", __FILE__, igesbrep, g); | |
709 | theCommands.Add("igesparam", "igesparam ->list, + name ->one param, + name val->change", __FILE__, igesparam, g); | |
710 | theCommands.Add("TPSTAT", " ", __FILE__, XSDRAWIGES_TPSTAT, g); | |
711 | theCommands.Add("tplosttrim", "number of untrimmed faces during last transfer", __FILE__, XSDRAWIGES_tplosttrim, g); | |
712 | theCommands.Add("etest", "test of eviewer", __FILE__, etest, g); | |
713 | ||
714 | } | |
715 | ||
716 | ||
717 | //======================================================================= | |
718 | //function : InitFromBRep | |
719 | //purpose : | |
720 | //======================================================================= | |
721 | ||
722 | void XSDRAWIGES::InitFromBRep (Draw_Interpretor& theCommands) | |
723 | { | |
724 | const char* g = "DE: IGES"; | |
725 | theCommands.Add("brepiges", "brepiges sh1 [+sh2 [+sh3 ..]] filename.igs", __FILE__, brepiges, g); | |
726 | theCommands.Add("testwriteiges", "testwriteiges filename.igs shape", __FILE__, testwrite, g); | |
727 | } |