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