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