Open Cascade to DXF Translator

Leverage the LibreCAD DXF library to convert Open Cascade 3D geometry into industry-standard DXF files

IMDAS demo

OccDxfConv

.​

Open CASCADE Technology (OCCT) is the only open-source full-scale 3D geometry library widely used for 3D modeling (CAD).​

DXF (Drawing Exchange Format) is a widely used format for representing CAD data. Open Cascade, an open-source CAD library, provides robust tools for handling 3D geometry and exporting it to various formats.

Many CAD applications require interoperability with DXF files. While Open Cascade provides export capabilities for standard formats like STEP and IGES, direct DXF export is not built-in. This project aims to fill that gap by implementing a custom DXF writer known as OccDxfConv.

2D Projections in Open Cascade

.​

HLRBRep_Algo and HLRBRep_PolyAlgo are two algorithms provided in Open Cascade to compute projections of a 3D model. These algorithms operate on a shape and remove or indicate edges hidden by faces. For a given projection, they calculate a set of lines characteristic of the object being represented. They are also used in conjunction with extraction utilities, which reconstruct a new, simplified shape from a selection of the results of the calculation. This new shape is made up of edges, which represent the shape visualized in the projection.

  • Loading Shapes in OCC

To pass a TopoDS_Shape to an HLRBRep_Algo object, use HLRBRep_Algo::Add. With an HLRBRep_PolyAlgo object, use HLRBRep_PolyAlgo::Load. If you wish to add several shapes, use Add or Load.

  • Setting view parameters

HLRBRep_Algo::Projector and HLRBRep_PolyAlgo::Projector set a projector object which defines the parameters of the view. This object is an HLRAlgo_Projector.

  • Computing the projections

HLRBRep_PolyAlgo::Update launches the calculation of outlines of the shape visualized by the HLRBRep_PolyAlgo framework.

In the case of HLRBRep_Algo, use HLRBRep_Algo::Update. With this algorithm, you must also call the method HLRBRep_Algo::Hide to calculate visible and hidden lines of the shape to be visualized. With an HLRBRep_PolyAlgo object, visible and hidden lines are computed by HLRBRep_PolyHLRToShape.

  • Extracting edges

The classes HLRBRep_HLRToShape and HLRBRep_PolyHLRToShape present a range of extraction filters for an HLRBRep_Algo object and an HLRBRep_PolyAlgo object, respectively. They highlight the type of edge from the results calculated by the algorithm on a shape. With both extraction classes, you can highlight the following types of output:

  • visible/hidden sharp edges;

  • visible/hidden smooth edges;

  • visible/hidden sewn edges;

  • visible/hidden outline edges.

Occ 3D To 2D

DXF Format

DXF files follow a structured format with sections such as HEADER, TABLES, BLOCKS, and ENTITIES. The translator focuses on the ENTITIES section, where geometry is written in DXF syntax.

The approach includes:

OccDxfConv Program Structure

The translator extracts geometric entities from the Open Cascade model.

The key steps include:

Implementation Details

Setting Up the Open Cascade Environment (v 7.5)

To develop the translator, the following tools and dependencies were used:

OCC DXF Viewer

A simple 3D/2D viewer developed in VC++.

COCCViewerView class is derived from CView and AIS_ViewController to display 3D models. External 3D models are imported using the STEP translator available in Open Cascade.

OCC2DView class is derived from COCCViewerView to display 2D shapes extracted using projection algorithms.

OCC DXF Viewer Screenshot

 

Imported 3D models are converted to 2D views using projection algorithms and displayed in the viewer using a special class AIS2DShape derived from AIS_InteractiveObject class, which takes the 3D model and computes the 2D projection of the model based on the orientation of the model.

 

OCC DXF Viewer Screenshot

 

COccDxfConv class is the main work horse where the open cascade entities are converted in to DXF entities. 

OCC DXF Viewer Screenshot

 

OccDxfConv translator is also capable of reading points, lines and polylines and create geometry in open cascade which can be converted to TopoDS_Shape for visualization.

OCC DXF Viewer Screenshot

 

This OccDxfConv DXF translator provides a direct DXF export feature. The implementation allows for seamless CAD data exchange, making it useful for various engineering applications.

By developing this translator, we bridge the gap between Open Cascade and DXF-based workflows, enabling better CAD interoperability in C++ applications.