CAD Data Exchange with Open CASCADE

Overview

Like any other geometric modeling kernel, Open CASCADE has internal data representation. On the lower level this representation includes geometry and topology (represented with Geom, Geom2d and TopoDS packages). This level is used in modeling algorithms (such as fillets or Boolean operations). On a higher level OCC provides OCAF (Open CASCADE Application Framework) and XDE (eXtended Data Exchange, which is OCAF-based) components to represent meta-data (such as attributes) and structures (e.g. assemblies).

Using native file formats and API of OCC

OCC shapes (TopoDS_Shape) can be saved in (and read from) an external file with the help of BRepTools::Write(), ::Read() API. By convention, the files bear the ".brep" file name extension.

TopoDS_Shape aShape = ...;
BRepTools::Write (aShape, "myfile.brep");

Thus, using .brep files is the most straightforward way to exchange data with Open CASCADE-based applications, as long as topology and geometry is enough. Bear in mind though that ".brep" is a text file format, so saving to it may lead to precision loss (as significant digits may get truncated).

For OCAF or XDE-based applications the way is using their respective persistence mechanism (through TDocStd_Application::SaveAs(), ::Open()). There are no strict conventions on the file extensions, although when the framework uses an XML file format the ".xml" extension is typically used.

When using direct API is possible (e.g. when integrating Open CASCADE-based app with some SDK), using direct API (TopoDS_Shape and TDocStd_Document) provides truly seamless integration as data resides fully in memory and no interim files are used. Of course, underlying OCC versions must match (be equal).

Using neutral file format converters included into OCC

OCC includes a few converters to exchange data with neutral 3D formats. This list includes STEP, IGES, STL, and VRML.

STEPControl_Reader aReader;
IFSelect_ReturnStatus status = aReader.ReadFile ("myfile.stp");
if (status != IFSelect_RetDone) {
     return false;
}
 
aReader.TransferRoots();
TopoDS_Shape aShape = aReader.OneShape();

When using data in a native ".brep" file format is impossible then you may resort to using one of the above formats. When exchanging precise geometry (B-Rep), STEP would be the best choice. IGES would be much less recommended (primarily due to often missing connectivitiy between faces and thus no solid representations).

VRML, STL or any other mesh formats may only work as an output format for visualization. Reading a mesh into B-Rep (TopoDS_Shape) is essentially pointless.

Using commercial components promoted by OPEN CASCADE SAS company

In addition to select free formats included into the free OCC library itself, the OPEN CASCADE SAS company distributes commercial components to work with other neutral formats.
The list includes: ACIS, DXF, Parasolid.

Using CAD Exchanger SDK to exchange data with Open CASCADE

CAD Exchanger is a product family focused on CAD data exchange and visualization. The project was started by Roman Lygin (his articles are cited on this wiki) in 2009 and grew into sustainable business over time.

CAD Exchanger supports numerous CAD formats far exceeding the list available in free part of OCC or in commercial add-ons. In particular, the list includes native formats of CAD systems, such as Dassault Systemes' CATIA and SOLIDWORKS, Siemens NX, PTC Creo, DWG. The SDK has both direct API support with OCC (both via TopoDS_Shape or OCAF/XDE) and ".brep" file support.

The blog post "How to import SOLIDWORKS (or Parasolid, JT, NX, Creo) files into Open CASCADE" explains how to import and export CAD data to/from OCC-based apps.

cadex::SLD_Reader aReader;
cadex::ModelData_Model aModel;
if (!aReader.ReadFile ("myfile.sldprt") || !aReader.Transfer (aModel)) {
    return false;
}
TopoDS_Shape aShape = cadex::ModelData_ShapeConverter::Convert (aModel);

Similar to above, conversion to XDE-based applications is provided:

Handle(TDocStd_Document) aDoc = ...;
cadex::ModelXDE_Converter::Convert (aModel, aDoc);
model_cadex-and-draw-56d776055334d7420e679c93b15ed22e.webp