365tuwe

main.cpp

Aug 14th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include <TopoDS_Shape.hxx>
  4. #include <TCollection_AsciiString.hxx>
  5. #include <TCollection_HAsciiString.hxx>
  6. #include <XSControl_WorkSession.hxx>
  7. #include <Interface_InterfaceModel.hxx>
  8. #include <XSControl_TransferReader.hxx>
  9. #include <Transfer_TransientProcess.hxx>
  10. #include <StepRepr_Representation.hxx>
  11. #include <StepRepr_RepresentationItem.hxx>
  12. #include <TransferBRep.hxx>
  13. #include <STEPControl_Reader.hxx>
  14.  
  15.  
  16. TopoDS_Shape getShape(STEPControl_Reader &reader, char* shapeName) {
  17.     const TCollection_AsciiString ascShapeName(shapeName);
  18.  
  19.     const Handle(XSControl_WorkSession)& theSession = reader.WS();
  20.     const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
  21.     const Handle(XSControl_TransferReader)& aReader = theSession->TransferReader();
  22.     const Handle(Transfer_TransientProcess)& tp = aReader->TransientProcess();
  23.  
  24.     Standard_Integer nb = theModel->NbEntities();
  25.     TopoDS_Shape retShape;
  26.     for(Standard_Integer i=1; i<=nb; i++) {
  27.         Handle(StepRepr_Representation) ent = Handle(StepRepr_Representation)::DownCast(theModel->Value(i));
  28.  
  29.         if (ent.IsNull()) continue;
  30.         Handle(Transfer_Binder) binder = tp->Find(ent);
  31.         if (binder.IsNull()) continue;
  32.         TopoDS_Shape oneShape = TransferBRep::ShapeResult(binder);
  33.         if (oneShape.IsNull()) continue;
  34.  
  35.         if (ent->Name().IsNull())
  36.             continue;
  37.  
  38.         if(ent->Name()->String().IsEqual(ascShapeName))
  39.         {
  40.             retShape = oneShape;
  41.         }
  42.     }
  43.  
  44.     return retShape;
  45. }
  46.  
  47.  
  48. //dump all labels
  49. void dumpLabels(STEPControl_Reader &reader) {
  50.     const Handle(XSControl_WorkSession)& theSession = reader.WS();
  51.     const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
  52.  
  53.     Standard_Integer nb = theModel->NbEntities();
  54.     std::cout << "number of entities: " << nb << endl;
  55.     for(Standard_Integer i=1; i<=nb; i++) {
  56.         Handle(StepRepr_Representation) ent = Handle(StepRepr_Representation)::DownCast(theModel->Value(i));
  57.         if (ent.IsNull()) {
  58.             cout << "ent is null" << endl;
  59.             continue;
  60.         }
  61.         if (ent->Name().IsNull()) {
  62.             cout << "ent is not null but does not have a name" << endl;
  63.             continue;
  64.         }
  65.         std::cout << "dumpLabels: " << ent->Name()->ToCString() << std::endl;
  66.     }
  67. }
  68.  
  69.  
  70. int main() {
  71.     STEPControl_Reader reader;
  72.     reader.ReadFile("MJ_3PSA_B2B_AFT_S-PLATE_SOURCE_lan04_2013-06-18.stp");
  73.     dumpLabels(reader);
  74.     //TopoDS_Shape sh = getShape(reader, "CP3");
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment