Learning Open CASCADE: Reading STEP Model Files into XDE

Click the above “Mechanical and Electronic Engineering Technology” to follow us

1. Introduction to XDE Component

The XDE (Extended Data Exchange) component of Open CASCADE is a key tool that allows users to extend the range of data exchange by converting additional data attached to geometric BREP (Boundary Representation) data, thus enhancing interoperability with external software.
First, XDE supports various data types, including colors, layers, assembly descriptions, and validation properties (such as center of gravity, etc.). This data is stored alongside shapes in XCAF documents, providing users with a comprehensive data management environment. Additionally, XDE also offers read and write tools, enabling users to easily read and write XCAF-supported data from IGES and STEP files.
In terms of assembly handling, XDE has significant advantages. It uses OCAF (Open CASCADE Application Framework) to store assembly structures and attributes, allowing for the retrieval of each layer’s TopoDS representation in the assembly structure tree. By separating shape definitions and their locations, XDE supports assemblies, making the handling of multi-level assemblies more flexible. This means users can more conveniently manage and operate complex assembly structures.
Moreover, XDE also allows users to add new data types based on existing tools to meet specific application needs. This flexibility enables XDE to adapt to different data exchange scenarios, providing users with a wider range of data processing options.
2. Steps to Read STEP Model Files into XDE
Here is a basic step-by-step guide to read STEP model files into XDE:
Initialize the XDE Environment: First, you need to initialize the XDE environment. This usually involves creating or obtaining a TDocStd_Document object, which is the basic container for handling documents in XDE.
Read the STEP Model File: Use relevant classes from the Open CASCADE library, such as XCAFDoc, to read the STEP model file. This involves opening the file, parsing its contents, and storing the parsed data structure in the TDocStd_Document object.
Process Shapes and Attributes: After reading the STEP file, you need to process the shape and attribute information in the file. Open CASCADE provides a rich API to handle this data, including querying shapes, setting, and getting attributes, etc.
Attach Data to XDE: Once you have processed the shapes and attributes from the STEP file, you can attach this data to XDE. This usually involves using the API provided by XDE to create and manage shapes, add attributes, set hierarchical structures, etc.
Validation and Verification: After attaching data to XDE, it is recommended to perform validation and verification to ensure the data is correct and meets your application requirements.
Further Operations: Once the data is successfully loaded into XDE, you can perform various operations such as editing shapes, modifying attributes, performing analyses, or exporting to other formats.

3. Example

void COCCmfcMDIDoc::ReadSTEP(){    // Create document  Handle(TDocStd_Document) doc;  XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF", doc);   // Load file (.step)  STEPCAFControl_Reader myReader;  myReader.ReadFile("hezi.STEP");  myReader.SetColorMode(true);  myReader.SetNameMode(true);  myReader.SetLayerMode(true);   myReader.Transfer(doc);   TDF_Label mainLabel = doc->Main();  // To get the node considered as an assembly from the XDE structure, you can use the node's Label (shape)  Handle(XCAFDoc_ShapeTool) myShapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel);  // Query, edit, or initialize the document to handle XCAF colors (OCCT no longer uses this method to render models)  Handle(XCAFDoc_ColorTool) myColors = XCAFDoc_DocumentTool::ColorTool(mainLabel);  TDF_LabelSequence FreeShape;  myShapeTool->GetFreeShapes(FreeShape);// Use GetFreeShapes to solve assembly and component display issues  //myShapeTool->GetShapes(FreeShape);  // Get names corresponding to assemblies and components (not applicable)  int Roots = FreeShape.Length();  for (int index = 1; index <= Roots; index++)  {    TDF_Label label = FreeShape.Value(index);     // Use XCAFPrs_AISObject to display    Handle(XCAFPrs_AISObject) displayedShape = new XCAFPrs_AISObject(label);    myAISContext->Display(displayedShape, true);   }}
Learning Open CASCADE: Reading STEP Model Files into XDE

Want to learn more

Quickly scan the code to follow

Leave a Comment