Please tell me how to read STEP files using

Forums: 

Please tell me how to read STEP files using STEPCAFControl_Reader and display them on the screen.
I'm a beginner.

Dmitrii Pasukhin's picture

Hello.
Please take a look into documentation:

step · Open-Cascade-SAS/OCCT Wiki or de_wrapper · Open-Cascade-SAS/OCCT Wiki or xde · Open-Cascade-SAS/OCCT Wiki

https://github.com/Open-Cascade-SAS/OCCT/wiki/visualization#examples-cre...

  Handle(DE_Wrapper) aSession = DE_Wrapper::GlobalWrapper();
  TCollection_AsciiString aPathToFile = "example.stp";
Handle(TDocStd_Document) aDoc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication(); 
BinXCAFDrivers::DefineFormat (anApp);
XmlXCAFDrivers::DefineFormat (anApp);
anApp->NewDocument ("BinXCAF", aDoc);
  if (!aSession->Read(aPathToFile, aDoc))
  {
    Message::SendFail() << "Error: Can't read file";
  }

Best regards, Dmitrii

kim young Woong's picture

So, is it possible to read it in Mesh and export it in Step? If so, please tell me how
Code :
myXdeDoc = new TDocStd_Document("MDTV-XCAF");
STEPCAFControl_Reader reader;
reader.ReadFile(toAsciiString(fileName).ToCString());
reader.SetMatMode(true);
if (reader.Transfer(myXdeDoc)) {
std::cout << "Translate successful\n";
}
else {
std::cout << "Translate failed\n";
}
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(myXdeDoc->Main());
NCollection_IndexedDataMap<TCollection_AsciiString, Handle(TDataStd_NamedData)> aNameDataMap; // Container to keep label's entry and its metadata
for (TDF_ChildIterator anIter(aShapeTool->Label(), Standard_True); anIter.More(); anIter.Next())
{
const TDF_Label& aLabel = anIter.Value();
TCollection_AsciiString anEntry;
TDF_Tool::Entry(aLabel, anEntry);
Handle(TDataStd_NamedData) aNamedData = aShapeTool->GetNamedProperties(aLabel);
if (!aNamedData.IsNull())
{
aNameDataMap.Add(anEntry, aNamedData);
}
Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject(aLabel);
myAISContext()->Display(aPrs, AIS_WireFrame, 1, false);

}
myView()->FitAll(0.01, false);

Dmitrii Pasukhin's picture

In your case after Display model automatically meshed. But you can mesh manually:

// Usually STP file going with BRep (geometry)
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc.Main());
TopoDS_Shape aShape = aShapeTool->GetOneShape();

// Setting up meshing parameters
IMeshTools_Parameters aMeshParameters;
aMeshParameters.InParallel = true;
aMeshParameters.Deflection = 0.01;
// .. other parameters
BRepMesh_IncrementalMesh aMesher (aShape, aMeshParameters);
aMesher.Perform();

Export is the same as import.

TCollection_AsciiString anOutStep = "as1-oc-214-mat.stp";
STEPCAFControl_Writer aStepWriter;
if (!aStepWriter.Perform(aDoc, anOutStep))
{
    // Do something
}

Best regardsm Dmitrii.

kim young Woong's picture

Thank you for your reply.
have a good day

gkv311 n's picture

Here you may also find another introduction article with code sample displaying XCAF shape.

kim young Woong's picture

Thank you for your reply.