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 | //:k8 abv 6 Jan 98: using parameter "step.group" for writing assemblies/shapes |
15 | #include <XSDRAWSTEP.ixx> | |
16 | #include <STEPControl_Controller.hxx> | |
17 | #include <STEPControl_ActorWrite.hxx> | |
18 | #include <STEPControl_Reader.hxx> | |
19 | #include <STEPControl_Writer.hxx> | |
20 | #include <STEPControl_StepModelType.hxx> | |
21 | #include <XSDRAW.hxx> | |
22 | #include <StepSelect_Activator.hxx> | |
23 | ||
24 | #include <Draw_Appli.hxx> | |
25 | #include <Draw_Interpretor.hxx> | |
785a9540 | 26 | #include <Message.hxx> |
7fd59977 | 27 | #include <Message_Messenger.hxx> |
28 | ||
29 | #include <DBRep.hxx> | |
30 | ||
31 | #include <TCollection_HAsciiString.hxx> | |
32 | #include <Interface_Macros.hxx> | |
33 | #include <Interface_InterfaceModel.hxx> | |
34 | ||
35 | // Pour le transfert (write) | |
36 | // Pour NewModel et Write : definition de produit (temporaire ...) | |
37 | #include <Transfer_FinderProcess.hxx> | |
38 | #include <TransferBRep_ShapeMapper.hxx> | |
39 | #include <StepShape_ShapeRepresentation.hxx> | |
40 | #include <TColStd_HSequenceOfTransient.hxx> | |
41 | ||
42 | #include <XSControl_Controller.hxx> | |
43 | #include <XSControl_WorkSession.hxx> | |
44 | #include <StepData_StepModel.hxx> | |
45 | ||
46 | #include <TopoDS.hxx> | |
47 | ||
48 | // steptrans | |
49 | #include <StepToTopoDS_MakeTransformed.hxx> | |
50 | #include <StepGeom_Axis2Placement3d.hxx> | |
51 | ||
52 | #include <stdio.h> | |
53 | #include <Interface_Static.hxx> | |
54 | #include <IFSelect_SessionPilot.hxx> | |
55 | #include <STEPSelections_Counter.hxx> | |
56 | #include <STEPSelections_AssemblyExplorer.hxx> | |
57 | ||
58 | #include <Draw_ProgressIndicator.hxx> | |
59 | #include <Transfer_TransientProcess.hxx> | |
60 | ||
61 | #include <TopExp_Explorer.hxx> | |
62 | #include <XSControl_TransferWriter.hxx> | |
63 | #include <Message_ProgressSentry.hxx> | |
64 | ||
65 | ||
66 | extern "C" { | |
67 | static void cleanpilot () | |
68 | { | |
69 | XSDRAW::Session()->ClearData(1); | |
70 | } | |
71 | } | |
72 | ||
73 | ||
74 | //======================================================================= | |
75 | //function : Init | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | ||
79 | void XSDRAWSTEP::Init () | |
80 | { | |
81 | Handle(StepSelect_Activator) stepact = new StepSelect_Activator; | |
82 | if (STEPControl_Controller::Init()) // XSDRAW::SetNorm("STEP AP-214"); trop tot | |
83 | XSDRAW::SetController(XSControl_Controller::Recorded("STEP")); | |
84 | ||
85 | atexit (cleanpilot); | |
86 | } | |
87 | ||
88 | // ######## COMMANDE stepread : teste le Reader ######### | |
89 | ||
90 | //======================================================================= | |
91 | //function : stepread | |
92 | //purpose : | |
93 | //======================================================================= | |
94 | ||
95 | static Standard_Integer stepread (Draw_Interpretor& di/*theCommands*/, Standard_Integer argc, const char** argv) | |
96 | { | |
f933f9cf | 97 | if (argc < 3) { |
98 | di << "Use: stepread [file] [f or r (type of model full or reduced)]\n"; | |
99 | return 1; | |
100 | } | |
bc650d41 | 101 | // On admet le controller AP214 ou une variante |
7fd59977 | 102 | DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); |
103 | if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); | |
104 | ||
bc650d41 | 105 | |
7fd59977 | 106 | // Progress indicator |
107 | Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); | |
108 | progress->SetScale ( 0, 100, 1 ); | |
109 | progress->Show(); | |
bc650d41 | 110 | |
7fd59977 | 111 | STEPControl_Reader sr (XSDRAW::Session(),Standard_False); |
112 | TCollection_AsciiString fnom,rnom; | |
113 | Standard_Boolean modfic = XSDRAW::FileAndVar | |
114 | (argv[1],argv[2],"STEP",fnom,rnom); | |
115 | if (modfic) di<<" File STEP to read : "<<fnom.ToCString()<<"\n"; | |
116 | else di<<" Model taken from the session : "<<fnom.ToCString()<<"\n"; | |
117 | di<<" -- Names of variables BREP-DRAW prefixed by : "<<rnom.ToCString()<<"\n"; | |
118 | IFSelect_ReturnStatus readstat = IFSelect_RetVoid; | |
119 | ||
120 | progress->NewScope ( 20, "Loading" ); // On average loading takes 20% | |
121 | progress->Show(); | |
122 | ||
bc650d41 | 123 | Standard_Boolean fromtcl = Standard_False; |
45521367 | 124 | Standard_Boolean aFullMode = Standard_False; |
bc650d41 G |
125 | Standard_Integer k = 3; |
126 | if(argc > k ) | |
127 | { | |
128 | if(argv[k][0] == 'f' || argv[3][0] == 'F') | |
129 | { | |
130 | aFullMode = Standard_True; | |
131 | k++; | |
132 | } | |
133 | else if(argv[k][0] == 'r' || argv[3][0] == 'R') | |
134 | { | |
135 | aFullMode = Standard_False; | |
136 | k++; | |
137 | } | |
138 | else | |
139 | fromtcl = Standard_True; | |
140 | ||
141 | } | |
142 | if(!fromtcl) | |
143 | fromtcl = argc > k; | |
144 | if(aFullMode) | |
145 | cout<<"Full model for translation with additional info will be used \n"<<flush; | |
146 | else | |
147 | cout<<"Reduced model for translation without additional info will be used \n"<<flush; | |
148 | ||
149 | sr.WS()->SetModeStat(aFullMode); | |
150 | ||
151 | ||
7fd59977 | 152 | if (modfic) readstat = sr.ReadFile (fnom.ToCString()); |
153 | else if (XSDRAW::Session()->NbStartingEntities() > 0) readstat = IFSelect_RetDone; | |
154 | ||
155 | progress->EndScope(); | |
156 | progress->Show(); | |
157 | ||
158 | if (readstat != IFSelect_RetDone) { | |
159 | if (modfic) di<<"Could not read file "<<fnom.ToCString()<<" , abandon"<<"\n"; | |
160 | else di<<"No model loaded"<<"\n"; | |
161 | return 1; | |
162 | } | |
bc650d41 | 163 | |
7fd59977 | 164 | |
bc650d41 | 165 | // nom = "." -> fichier deja lu |
7fd59977 | 166 | Standard_Integer i, num, nbs, modepri = 1; |
167 | if (fromtcl) modepri = 4; | |
7fd59977 | 168 | while (modepri) { |
169 | num = sr.NbRootsForTransfer(); | |
170 | if (!fromtcl) { | |
171 | di<<"NbRootsForTransfer="<<num<<" :\n"; | |
172 | for (i = 1; i <= num; i ++) { | |
bc650d41 | 173 | di<<"Root."<<i<<", Ent. "; |
785a9540 | 174 | sr.Model()->Print (sr.RootForTransfer(i), Message::DefaultMessenger()); |
bc650d41 | 175 | di<<" Type:"<<sr.RootForTransfer(i)->DynamicType()->Name()<<"\n"; |
7fd59977 | 176 | } |
177 | ||
178 | cout<<"Mode (0 End, 1 root n0 1, 2 one root/n0, 3 one entity/n0, 4 Selection) : "<<flush; | |
179 | cin>>modepri; | |
180 | } | |
181 | ||
182 | if (modepri == 0) { di<<"End Reading STEP"<<"\n"; return 0; } | |
183 | if (modepri <= 2) { | |
184 | num = 1; | |
185 | if (modepri == 2) { | |
bc650d41 | 186 | cout<<"Root N0 : "<<flush; cin>>num; |
7fd59977 | 187 | } |
188 | ||
189 | progress->NewScope ( 80, "Translation" ); | |
190 | progress->Show(); | |
191 | sr.WS()->MapReader()->SetProgress ( progress ); | |
192 | ||
193 | if (!sr.TransferRoot (num)) di<<"Transfer root n0 "<<num<<" : no result"<<"\n"; | |
194 | else { | |
bc650d41 | 195 | nbs = sr.NbShapes(); |
91322f44 | 196 | char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nbs); |
bc650d41 G |
197 | di<<"Transfer root n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n"; |
198 | di<<"Now, "<<nbs<<" Shapes produced"<<"\n"; | |
199 | TopoDS_Shape sh = sr.Shape(nbs); | |
200 | DBRep::Set (shname,sh); | |
7fd59977 | 201 | } |
202 | ||
203 | sr.WS()->MapReader()->SetProgress ( 0 ); | |
204 | progress->EndScope(); | |
205 | progress->Show(); | |
206 | } | |
207 | else if (modepri == 3) { | |
208 | cout<<"Entity : "<<flush; num = XSDRAW::GetEntityNumber(); | |
209 | if (!sr.TransferOne (num)) di<<"Transfer entity n0 "<<num<<" : no result"<<"\n"; | |
210 | else { | |
bc650d41 | 211 | nbs = sr.NbShapes(); |
91322f44 | 212 | char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),num); |
bc650d41 G |
213 | di<<"Transfer entity n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n"; |
214 | di<<"Now, "<<nbs<<" Shapes produced"<<"\n"; | |
215 | TopoDS_Shape sh = sr.Shape(nbs); | |
216 | DBRep::Set (shname,sh); | |
7fd59977 | 217 | } |
218 | } | |
219 | else if (modepri == 4) { | |
bc650d41 | 220 | // char snm[100]; Standard_Integer answer = 1; |
7fd59977 | 221 | Handle(TColStd_HSequenceOfTransient) list; |
222 | ||
bc650d41 G |
223 | // Selection, nommee ou via tcl. tcl : raccourcis admis |
224 | // * donne xst-transferrable-roots | |
7fd59977 | 225 | if (fromtcl) { |
bc650d41 G |
226 | modepri = 0; // d ioffice une seule passe |
227 | if (argv[k][0] == '*' && argv[k][1] == '\0') { | |
228 | di<<"Transferrable Roots : "; | |
229 | list = XSDRAW::GetList("xst-transferrable-roots"); | |
7fd59977 | 230 | //list = new TColStd_HSequenceOfTransient; |
231 | //for(Standard_Integer j=1; j<=num; j++) | |
232 | // list->Append(sr.RootForTransfer(j)); | |
bc650d41 | 233 | } |
7fd59977 | 234 | else { |
bc650d41 G |
235 | di<<"List given by "<<argv[k]; |
236 | if (argc > k+1) di<<" "<<argv[k+1]; | |
237 | di<<" : "; | |
238 | list = XSDRAW::GetList (argv[k], ( argc > (k+1) ? argv[k+1] : 0 ) ); | |
239 | } | |
240 | if (list.IsNull()) { di<<"No list defined. Give a selection name or * for all transferrable roots"<<"\n"; continue; } | |
7fd59977 | 241 | } else { |
bc650d41 G |
242 | cout<<"Name of Selection :"<<flush; |
243 | list = XSDRAW::GetList(); | |
244 | if (list.IsNull()) { di<<"No list defined"<<"\n"; continue; } | |
7fd59977 | 245 | } |
246 | ||
247 | Standard_Integer ill, nbl = list->Length(); | |
248 | di<<"Nb entities selected : "<<nbl<<"\n"; | |
249 | if (nbl == 0) continue; | |
250 | ||
251 | progress->NewScope ( 80, "Translation" ); | |
252 | progress->Show(); | |
253 | sr.WS()->MapReader()->SetProgress ( progress ); | |
254 | ||
255 | Message_ProgressSentry PSentry ( progress, "Root", 0, nbl, 1 ); | |
256 | for (ill = 1; ill <= nbl && PSentry.More(); ill ++, PSentry.Next()) { | |
bc650d41 G |
257 | num = sr.Model()->Number(list->Value(ill)); |
258 | if (num == 0) continue; | |
259 | if (!sr.TransferOne(num)) di<<"Transfer entity n0 "<<num<<" : no result"<<"\n"; | |
260 | else { | |
261 | nbs = sr.NbShapes(); | |
91322f44 | 262 | char shname[30]; Sprintf (shname,"%s_%d",rnom.ToCString(),nbs); |
bc650d41 G |
263 | di<<"Transfer entity n0 "<<num<<" OK -> DRAW Shape: "<<shname<<"\n"; |
264 | di<<"Now, "<<nbs<<" Shapes produced"<<"\n"; | |
265 | TopoDS_Shape sh = sr.Shape(nbs); | |
266 | DBRep::Set (shname,sh); | |
267 | } | |
7fd59977 | 268 | } |
269 | sr.WS()->MapReader()->SetProgress ( 0 ); | |
270 | progress->EndScope(); | |
271 | progress->Show(); | |
272 | } | |
273 | else di<<"Unknown mode n0 "<<modepri<<"\n"; | |
274 | } | |
275 | return 0; | |
276 | } | |
277 | ||
278 | //======================================================================= | |
279 | //function : testreadstep | |
280 | //purpose : | |
281 | //======================================================================= | |
282 | static Standard_Integer testread (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
283 | { | |
284 | if (argc != 3) | |
285 | { | |
286 | di << "ERROR in " << argv[0] << "Wrong Number of Arguments."<<"\n"; | |
287 | di << " Usage : " << argv[0] <<" file_name shape_name"<< "\n"; | |
288 | return 1; | |
289 | } | |
290 | STEPControl_Reader Reader; | |
291 | Standard_CString filename = argv[1]; | |
292 | IFSelect_ReturnStatus readstat = Reader.ReadFile(filename); | |
293 | di<<"Status from reading STEP file "<<filename<<" : "; | |
294 | switch(readstat) { | |
295 | case IFSelect_RetVoid : { di<<"empty file"<<"\n"; return 1; } | |
296 | case IFSelect_RetDone : { di<<"file read"<<"\n"; break; } | |
297 | case IFSelect_RetError : { di<<"file not found"<<"\n"; return 1; } | |
298 | case IFSelect_RetFail : { di<<"error during read"<<"\n"; return 1; } | |
299 | default : { di<<"failure"<<"\n"; return 1; } | |
300 | } | |
301 | Reader.TransferRoots(); | |
302 | TopoDS_Shape shape = Reader.OneShape(); | |
303 | DBRep::Set(argv[2],shape); | |
304 | di<<"Count of shapes produced : "<<Reader.NbShapes()<<"\n"; | |
305 | return 0; | |
306 | } | |
307 | ||
7fd59977 | 308 | // ######## COMMANDE steptrans : teste les transformations ######### |
309 | //======================================================================= | |
310 | //function : steptrans | |
311 | //purpose : | |
312 | //======================================================================= | |
313 | ||
314 | static Standard_Integer steptrans (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
315 | { | |
316 | if (argc < 5) { di<<"give shape-name new-shape + entity-n0 entity-n0: AXIS2"<<"\n"; | |
317 | return 1; } | |
318 | TopoDS_Shape shape = DBRep::Get(argv[1]); | |
319 | if (shape.IsNull()) { di<<"Not a shape : "<<argv[1]<<"\n"; return 1; } | |
320 | Handle(StepGeom_Axis2Placement3d) ax1,ax2; | |
321 | Standard_Integer n1 = 0, n2 = 0; | |
322 | n1 = XSDRAW::GetEntityNumber(argv[3]); | |
323 | if (argc > 4) n2 = XSDRAW::GetEntityNumber(argv[4]); | |
324 | if (n1 > 0) ax1 = Handle(StepGeom_Axis2Placement3d)::DownCast | |
325 | (XSDRAW::Entity(n1)); | |
326 | if (n2 > 0) ax2 = Handle(StepGeom_Axis2Placement3d)::DownCast | |
327 | (XSDRAW::Entity(n2)); | |
328 | StepToTopoDS_MakeTransformed mktrans; | |
329 | if (mktrans.Compute (ax1,ax2)) { | |
330 | TopLoc_Location loc (mktrans.Transformation()); | |
331 | shape.Move (loc); | |
332 | // mktrans.Transform (shape); | |
333 | DBRep::Set (argv[2],shape); | |
334 | di<<"Transformed Shape as "<<argv[2]<<"\n"; | |
335 | } | |
336 | else di<<"No transformation computed"<<"\n"; | |
337 | return 0; | |
338 | } | |
339 | ||
340 | // ######## COMMANDE stepwrite : teste le Writer ######### | |
341 | ||
342 | //======================================================================= | |
343 | //function : stepwrite | |
344 | //purpose : | |
345 | //======================================================================= | |
346 | ||
347 | static Standard_Integer stepwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
348 | { | |
349 | // On admet le controller AP214 ou une variante | |
350 | DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); | |
351 | if (ctl.IsNull()) { | |
352 | XSDRAW::SetNorm("STEP"); | |
353 | //sln 14.01.2002 OCC51: assign new value to ctl in order to avoid exception during using one in the function | |
354 | ctl = Handle(STEPControl_Controller)::DownCast(XSDRAW::Controller()); | |
355 | } | |
356 | ||
357 | if (argc < 3) { | |
358 | di<<"Give mode[1-4] and Shape name + optional file. Mode possible"<<"\n"; | |
359 | di<<"f ou 1 : FacettedBRep s ou 2 : ShellBasedSurfaceModel\n" | |
360 | <<"m ou 3 : ManifoldSolidBrep w ou 4 : GeometricCurveSet/WireFrame"<<"\n"; | |
361 | return 1; } | |
362 | char modeshape = argv[1][0]; | |
363 | STEPControl_StepModelType mode; | |
364 | switch (modeshape) { | |
365 | case 'a' : | |
366 | case '0' : mode = STEPControl_AsIs; break; | |
367 | case 'f' : | |
368 | case '1' : mode = STEPControl_FacetedBrep; break; | |
369 | case 's' : | |
370 | case '2' : mode = STEPControl_ShellBasedSurfaceModel; break; | |
371 | case 'm' : | |
372 | case '3' : mode = STEPControl_ManifoldSolidBrep; break; | |
373 | case 'w' : | |
374 | case '4' : mode = STEPControl_GeometricCurveSet; break; | |
375 | default : di<<"1st arg = mode, incorrect [give fsmw]"<<"\n"; return 1; | |
376 | } | |
377 | ||
378 | //:k8 abv 6 Jan 98: using parameter for writing mode (assemblies/shapes) | |
379 | Handle(STEPControl_ActorWrite) ActWrite = | |
380 | Handle(STEPControl_ActorWrite)::DownCast ( ctl->ActorWrite() ); | |
381 | if ( ! ActWrite.IsNull() ) | |
382 | ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly")); | |
383 | ||
384 | TopoDS_Shape shape = DBRep::Get(argv[2]); | |
385 | STEPControl_Writer sw (XSDRAW::Session(),Standard_False); | |
386 | Handle(Interface_InterfaceModel) stepmodel = sw.Model(); | |
387 | Standard_Integer nbavant = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities()); | |
388 | ||
389 | Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); | |
390 | progress->NewScope(90,"Translating"); | |
391 | progress->Show(); | |
392 | sw.WS()->TransferWriter()->FinderProcess()->SetProgress(progress); | |
393 | ||
394 | Standard_Integer stat = sw.Transfer (shape,mode); | |
2857a8ac | 395 | if (stat == IFSelect_RetDone) |
396 | { | |
397 | di << "Translation: OK\n"; | |
398 | } | |
399 | else | |
400 | { | |
401 | di << "Error: translation failed, status = " << stat << "\n"; | |
402 | } | |
7fd59977 | 403 | |
404 | sw.WS()->TransferWriter()->FinderProcess()->SetProgress(0); | |
405 | progress->EndScope(); | |
406 | progress->Show(); | |
407 | progress->NewScope(10,"Writing"); | |
408 | progress->Show(); | |
409 | ||
410 | // Que s est-il passe | |
411 | stepmodel = sw.Model(); | |
412 | Standard_Integer nbapres = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities()); | |
413 | if (nbavant > 0) di<<"Beware : Model not empty before transferring"<<"\n"; | |
414 | if (nbapres <= nbavant) di<<"Beware : No data produced by this transfer"<<"\n"; | |
415 | if (nbapres == 0) { di<<"No data to write"<<"\n"; return 0; } | |
416 | ||
7fd59977 | 417 | if (argc <= 3) { |
2857a8ac | 418 | di<<" Now, to write a file, command : writeall filename"<<"\n"; |
419 | return 0; | |
7fd59977 | 420 | } |
7fd59977 | 421 | |
2857a8ac | 422 | const char *nomfic = argv[3]; |
7fd59977 | 423 | stat = sw.Write(nomfic); |
424 | switch (stat) { | |
2857a8ac | 425 | case IFSelect_RetVoid : di<<"Error: No file written"<<"\n"; break; |
7fd59977 | 426 | case IFSelect_RetDone : di<<"File "<<nomfic<<" written"<<"\n"; break; |
12bf87c5 | 427 | case IFSelect_RetStop : di<<"Error on writing file: no space on disk or destination is write protected"<<"\n"; break; |
2857a8ac | 428 | default : di<<"Error: File "<<nomfic<<" written with fail messages"<<"\n"; break; |
7fd59977 | 429 | } |
430 | ||
431 | progress->EndScope(); | |
432 | progress->Show(); | |
433 | ||
434 | return 0; | |
435 | } | |
436 | //======================================================================= | |
437 | //function : testwritestep | |
438 | //purpose : | |
439 | //======================================================================= | |
440 | static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv) | |
441 | { | |
442 | if (argc != 3) | |
443 | { | |
444 | di << "ERROR in " << argv[0] << "Wrong Number of Arguments."<<"\n"; | |
445 | di << " Usage : " << argv[0] <<" file_name shape_name "<< "\n"; | |
446 | return 1; | |
447 | } | |
448 | STEPControl_Writer Writer; | |
449 | Standard_CString filename = argv[1]; | |
450 | TopoDS_Shape shape = DBRep::Get(argv[2]); | |
451 | IFSelect_ReturnStatus stat = Writer.Transfer(shape,STEPControl_AsIs); | |
452 | stat = Writer.Write(filename); | |
453 | if(stat != IFSelect_RetDone){ | |
454 | di<<"Error on writing file"<<"\n"; | |
455 | return 1; | |
456 | } | |
457 | di<<"File Is Written"<<"\n"; | |
458 | return 0; | |
459 | } | |
460 | ||
461 | //======================================================================= | |
462 | //function : countexpected | |
463 | //purpose : | |
464 | //======================================================================= | |
465 | ||
466 | static Standard_Integer countexpected | |
467 | (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) | |
468 | { | |
469 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); | |
470 | Handle(IFSelect_WorkSession) WS = pilot->Session(); | |
471 | const Interface_Graph& graph = WS->Graph(); | |
472 | ||
473 | Handle(TColStd_HSequenceOfTransient) roots = WS->GiveList("xst-transferrable-roots", ""); | |
474 | STEPSelections_Counter cnt; | |
475 | ||
476 | for (Standard_Integer i =1 ; i <= roots->Length(); i++) { | |
477 | cnt.Count(graph,roots->Value(i)); | |
478 | } | |
479 | ||
480 | di<< "Instances of Faces \t: "<<cnt.NbInstancesOfFaces()<<"\n"; | |
481 | di<< "Instances of Shells\t: "<<cnt.NbInstancesOfShells()<<"\n"; | |
482 | di<< "Instances of Solids\t: "<<cnt.NbInstancesOfSolids()<<"\n"; | |
483 | di<< "Instances of Wires in GS\t: "<<cnt.NbInstancesOfWires()<<"\n"; | |
484 | di<< "Instances of Edges in GS\t: "<<cnt.NbInstancesOfEdges()<<"\n"; | |
485 | ||
486 | di<< "Source Faces \t: "<<cnt.NbSourceFaces()<<"\n"; | |
487 | di<< "Source Shells\t: "<<cnt.NbSourceShells()<<"\n"; | |
488 | di<< "Source Solids\t: "<<cnt.NbSourceSolids()<<"\n"; | |
489 | di<< "Source Wires in GS\t: "<<cnt.NbSourceWires()<<"\n"; | |
490 | di<< "Source Edges in GS\t: "<<cnt.NbSourceEdges()<<"\n"; | |
491 | ||
492 | return 1; | |
493 | } | |
494 | ||
495 | static Standard_Integer dumpassembly | |
496 | (Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char** /*argv*/) | |
497 | { | |
498 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); | |
499 | Handle(IFSelect_WorkSession) WS = pilot->Session(); | |
500 | const Interface_Graph& graph = WS->Graph(); | |
501 | ||
502 | STEPSelections_AssemblyExplorer exp(graph); | |
503 | exp.Dump(cout); | |
504 | return 0; | |
505 | } | |
506 | ||
d402d481 | 507 | static Standard_Integer stepfileunits (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
508 | { | |
509 | ||
510 | if( argc < 2) | |
511 | { | |
512 | cout<<"Error: Invalid number of parameters. Should be: getfileunits name_file"<<endl; | |
513 | return 1; | |
514 | } | |
515 | STEPControl_Reader aStepReader; | |
516 | ||
517 | IFSelect_ReturnStatus readstat = IFSelect_RetVoid; | |
518 | readstat = aStepReader.ReadFile (argv[1]); | |
519 | ||
520 | if (readstat != IFSelect_RetDone) { | |
521 | ||
522 | di<<"No model loaded"<<"\n"; | |
523 | return 1; | |
524 | } | |
525 | ||
526 | TColStd_SequenceOfAsciiString anUnitLengthNames; | |
527 | TColStd_SequenceOfAsciiString anUnitAngleNames; | |
528 | TColStd_SequenceOfAsciiString anUnitSolidAngleNames; | |
529 | aStepReader.FileUnits( anUnitLengthNames,anUnitAngleNames,anUnitSolidAngleNames); | |
530 | ||
302f96fb | 531 | Standard_Integer i =1; |
d402d481 | 532 | di<<"=====================================================\n"; |
533 | di<<"LENTH Unit"<<"\n"; | |
534 | for( ; i <= anUnitLengthNames.Length() ; i++) | |
535 | di<<anUnitLengthNames(i).ToCString()<<"\n"; | |
536 | ||
537 | di<<"=====================================================\n"; | |
538 | di<<"Angle Unit"<<"\n"; | |
539 | for( i =1 ; i <= anUnitAngleNames.Length() ; i++) | |
540 | di<<anUnitAngleNames(i).ToCString()<<"\n"; | |
541 | ||
542 | di<<"=====================================================\n"; | |
543 | di<<"Solid Angle Unit"<<"\n"; | |
544 | for( i =1 ; i <= anUnitSolidAngleNames.Length() ; i++) | |
545 | di<<anUnitSolidAngleNames(i).ToCString()<<"\n"; | |
546 | ||
547 | return 0; | |
548 | } | |
7fd59977 | 549 | // ######## COMMANDE stepwrite : teste le Writer ######### |
550 | ||
551 | void XSDRAWSTEP::InitCommands (Draw_Interpretor& theCommands) | |
552 | { | |
553 | const char* g = "DE: STEP"; // Step transfer file commands | |
554 | XSDRAWSTEP::Init(); | |
555 | XSDRAW::LoadDraw(theCommands); | |
556 | theCommands.Add("stepwrite" , "stepwrite mode[0-4 afsmw] shape", __FILE__, stepwrite, g); | |
557 | theCommands.Add("testwritestep", "testwritestep filename.stp shape", __FILE__, testwrite, g); | |
bc650d41 | 558 | theCommands.Add("stepread", "stepread [file] [f or r (type of model full or reduced)]",__FILE__, stepread, g); |
7fd59977 | 559 | theCommands.Add("testreadstep", "testreadstep [file] [name DRAW]", __FILE__, testread, g); |
560 | theCommands.Add("steptrans", "steptrans shape stepax1 stepax2", __FILE__, steptrans, g); | |
561 | theCommands.Add("countexpected","TEST", __FILE__, countexpected, g); | |
562 | theCommands.Add("dumpassembly", "TEST", __FILE__, dumpassembly, g); | |
d402d481 | 563 | theCommands.Add("stepfileunits" , "stepfileunits name_file", __FILE__, stepfileunits, g); |
7fd59977 | 564 | } |