| 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 | |
| 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 | { |
| 101 | // On admet le controller AP214 ou une variante |
| 102 | DeclareAndCast(STEPControl_Controller,ctl,XSDRAW::Controller()); |
| 103 | if (ctl.IsNull()) XSDRAW::SetNorm("STEP"); |
| 104 | |
| 105 | |
| 106 | // Progress indicator |
| 107 | Handle(Draw_ProgressIndicator) progress = new Draw_ProgressIndicator ( di, 1 ); |
| 108 | progress->SetScale ( 0, 100, 1 ); |
| 109 | progress->Show(); |
| 110 | |
| 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 | |
| 123 | Standard_Boolean fromtcl = Standard_False; |
| 124 | Standard_Boolean aFullMode = Standard_False; |
| 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 | |
| 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 | } |
| 163 | |
| 164 | |
| 165 | // nom = "." -> fichier deja lu |
| 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 ++) { |
| 175 | di<<"Root."<<i<<", Ent. "; |
| 176 | sr.Model()->Print(sr.RootForTransfer(i),aDIMessenger); |
| 177 | di<<" Type:"<<sr.RootForTransfer(i)->DynamicType()->Name()<<"\n"; |
| 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) { |
| 188 | cout<<"Root N0 : "<<flush; cin>>num; |
| 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 { |
| 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); |
| 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 { |
| 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); |
| 219 | } |
| 220 | } |
| 221 | else if (modepri == 4) { |
| 222 | // char snm[100]; Standard_Integer answer = 1; |
| 223 | Handle(TColStd_HSequenceOfTransient) list; |
| 224 | |
| 225 | // Selection, nommee ou via tcl. tcl : raccourcis admis |
| 226 | // * donne xst-transferrable-roots |
| 227 | if (fromtcl) { |
| 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"); |
| 232 | //list = new TColStd_HSequenceOfTransient; |
| 233 | //for(Standard_Integer j=1; j<=num; j++) |
| 234 | // list->Append(sr.RootForTransfer(j)); |
| 235 | } |
| 236 | else { |
| 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; } |
| 243 | } else { |
| 244 | cout<<"Name of Selection :"<<flush; |
| 245 | list = XSDRAW::GetList(); |
| 246 | if (list.IsNull()) { di<<"No list defined"<<"\n"; continue; } |
| 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()) { |
| 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 | } |
| 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 | if (stat == IFSelect_RetDone) |
| 439 | { |
| 440 | di << "Translation: OK\n"; |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | di << "Error: translation failed, status = " << stat << "\n"; |
| 445 | } |
| 446 | |
| 447 | sw.WS()->TransferWriter()->FinderProcess()->SetProgress(0); |
| 448 | progress->EndScope(); |
| 449 | progress->Show(); |
| 450 | progress->NewScope(10,"Writing"); |
| 451 | progress->Show(); |
| 452 | |
| 453 | // Que s est-il passe |
| 454 | stepmodel = sw.Model(); |
| 455 | Standard_Integer nbapres = (stepmodel.IsNull() ? 0 : stepmodel->NbEntities()); |
| 456 | if (nbavant > 0) di<<"Beware : Model not empty before transferring"<<"\n"; |
| 457 | if (nbapres <= nbavant) di<<"Beware : No data produced by this transfer"<<"\n"; |
| 458 | if (nbapres == 0) { di<<"No data to write"<<"\n"; return 0; } |
| 459 | |
| 460 | if (argc <= 3) { |
| 461 | di<<" Now, to write a file, command : writeall filename"<<"\n"; |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | const char *nomfic = argv[3]; |
| 466 | stat = sw.Write(nomfic); |
| 467 | switch (stat) { |
| 468 | case IFSelect_RetVoid : di<<"Error: No file written"<<"\n"; break; |
| 469 | case IFSelect_RetDone : di<<"File "<<nomfic<<" written"<<"\n"; break; |
| 470 | case IFSelect_RetStop : di<<"Error on writing file: no space on disk or destination is write protected"<<"\n"; break; |
| 471 | default : di<<"Error: File "<<nomfic<<" written with fail messages"<<"\n"; break; |
| 472 | } |
| 473 | |
| 474 | progress->EndScope(); |
| 475 | progress->Show(); |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | //======================================================================= |
| 480 | //function : testwritestep |
| 481 | //purpose : |
| 482 | //======================================================================= |
| 483 | static Standard_Integer testwrite (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 484 | { |
| 485 | if (argc != 3) |
| 486 | { |
| 487 | di << "ERROR in " << argv[0] << "Wrong Number of Arguments."<<"\n"; |
| 488 | di << " Usage : " << argv[0] <<" file_name shape_name "<< "\n"; |
| 489 | return 1; |
| 490 | } |
| 491 | STEPControl_Writer Writer; |
| 492 | Standard_CString filename = argv[1]; |
| 493 | TopoDS_Shape shape = DBRep::Get(argv[2]); |
| 494 | IFSelect_ReturnStatus stat = Writer.Transfer(shape,STEPControl_AsIs); |
| 495 | stat = Writer.Write(filename); |
| 496 | if(stat != IFSelect_RetDone){ |
| 497 | di<<"Error on writing file"<<"\n"; |
| 498 | return 1; |
| 499 | } |
| 500 | di<<"File Is Written"<<"\n"; |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | //======================================================================= |
| 505 | //function : countexpected |
| 506 | //purpose : |
| 507 | //======================================================================= |
| 508 | |
| 509 | static Standard_Integer countexpected |
| 510 | (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) |
| 511 | { |
| 512 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); |
| 513 | Handle(IFSelect_WorkSession) WS = pilot->Session(); |
| 514 | const Interface_Graph& graph = WS->Graph(); |
| 515 | |
| 516 | Handle(TColStd_HSequenceOfTransient) roots = WS->GiveList("xst-transferrable-roots", ""); |
| 517 | STEPSelections_Counter cnt; |
| 518 | |
| 519 | for (Standard_Integer i =1 ; i <= roots->Length(); i++) { |
| 520 | cnt.Count(graph,roots->Value(i)); |
| 521 | } |
| 522 | |
| 523 | di<< "Instances of Faces \t: "<<cnt.NbInstancesOfFaces()<<"\n"; |
| 524 | di<< "Instances of Shells\t: "<<cnt.NbInstancesOfShells()<<"\n"; |
| 525 | di<< "Instances of Solids\t: "<<cnt.NbInstancesOfSolids()<<"\n"; |
| 526 | di<< "Instances of Wires in GS\t: "<<cnt.NbInstancesOfWires()<<"\n"; |
| 527 | di<< "Instances of Edges in GS\t: "<<cnt.NbInstancesOfEdges()<<"\n"; |
| 528 | |
| 529 | di<< "Source Faces \t: "<<cnt.NbSourceFaces()<<"\n"; |
| 530 | di<< "Source Shells\t: "<<cnt.NbSourceShells()<<"\n"; |
| 531 | di<< "Source Solids\t: "<<cnt.NbSourceSolids()<<"\n"; |
| 532 | di<< "Source Wires in GS\t: "<<cnt.NbSourceWires()<<"\n"; |
| 533 | di<< "Source Edges in GS\t: "<<cnt.NbSourceEdges()<<"\n"; |
| 534 | |
| 535 | return 1; |
| 536 | } |
| 537 | |
| 538 | static Standard_Integer dumpassembly |
| 539 | (Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char** /*argv*/) |
| 540 | { |
| 541 | Handle(IFSelect_SessionPilot) pilot = XSDRAW::Pilot(); |
| 542 | Handle(IFSelect_WorkSession) WS = pilot->Session(); |
| 543 | const Interface_Graph& graph = WS->Graph(); |
| 544 | |
| 545 | STEPSelections_AssemblyExplorer exp(graph); |
| 546 | exp.Dump(cout); |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | static Standard_Integer stepfileunits (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
| 551 | { |
| 552 | |
| 553 | if( argc < 2) |
| 554 | { |
| 555 | cout<<"Error: Invalid number of parameters. Should be: getfileunits name_file"<<endl; |
| 556 | return 1; |
| 557 | } |
| 558 | STEPControl_Reader aStepReader; |
| 559 | |
| 560 | IFSelect_ReturnStatus readstat = IFSelect_RetVoid; |
| 561 | readstat = aStepReader.ReadFile (argv[1]); |
| 562 | |
| 563 | if (readstat != IFSelect_RetDone) { |
| 564 | |
| 565 | di<<"No model loaded"<<"\n"; |
| 566 | return 1; |
| 567 | } |
| 568 | |
| 569 | TColStd_SequenceOfAsciiString anUnitLengthNames; |
| 570 | TColStd_SequenceOfAsciiString anUnitAngleNames; |
| 571 | TColStd_SequenceOfAsciiString anUnitSolidAngleNames; |
| 572 | aStepReader.FileUnits( anUnitLengthNames,anUnitAngleNames,anUnitSolidAngleNames); |
| 573 | |
| 574 | Standard_Integer i =1; |
| 575 | di<<"=====================================================\n"; |
| 576 | di<<"LENTH Unit"<<"\n"; |
| 577 | for( ; i <= anUnitLengthNames.Length() ; i++) |
| 578 | di<<anUnitLengthNames(i).ToCString()<<"\n"; |
| 579 | |
| 580 | di<<"=====================================================\n"; |
| 581 | di<<"Angle Unit"<<"\n"; |
| 582 | for( i =1 ; i <= anUnitAngleNames.Length() ; i++) |
| 583 | di<<anUnitAngleNames(i).ToCString()<<"\n"; |
| 584 | |
| 585 | di<<"=====================================================\n"; |
| 586 | di<<"Solid Angle Unit"<<"\n"; |
| 587 | for( i =1 ; i <= anUnitSolidAngleNames.Length() ; i++) |
| 588 | di<<anUnitSolidAngleNames(i).ToCString()<<"\n"; |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | // ######## COMMANDE stepwrite : teste le Writer ######### |
| 593 | |
| 594 | void XSDRAWSTEP::InitCommands (Draw_Interpretor& theCommands) |
| 595 | { |
| 596 | const char* g = "DE: STEP"; // Step transfer file commands |
| 597 | XSDRAWSTEP::Init(); |
| 598 | XSDRAW::LoadDraw(theCommands); |
| 599 | theCommands.Add("stepwrite" , "stepwrite mode[0-4 afsmw] shape", __FILE__, stepwrite, g); |
| 600 | theCommands.Add("testwritestep", "testwritestep filename.stp shape", __FILE__, testwrite, g); |
| 601 | theCommands.Add("stepread", "stepread [file] [f or r (type of model full or reduced)]",__FILE__, stepread, g); |
| 602 | theCommands.Add("testreadstep", "testreadstep [file] [name DRAW]", __FILE__, testread, g); |
| 603 | theCommands.Add("steptrans", "steptrans shape stepax1 stepax2", __FILE__, steptrans, g); |
| 604 | theCommands.Add("countexpected","TEST", __FILE__, countexpected, g); |
| 605 | theCommands.Add("dumpassembly", "TEST", __FILE__, dumpassembly, g); |
| 606 | theCommands.Add("readstep", "readstep [file]", __FILE__, readstep, g); |
| 607 | theCommands.Add("stepfileunits" , "stepfileunits name_file", __FILE__, stepfileunits, g); |
| 608 | } |