:orphan:

##########
DGN Reader
##########

.. rst-class:: format-title-block

+------------------------------------------------------------------------------+
|                               **DGN**                                        |
+-----------------------------------------+------------------------------------+
| **File Extension**                      | DGN                                |
+-----------------------------------------+------------------------------------+
| **Supported Versions**                  | 7, 8                               |
+-----------------------------------------+------------------------------------+
| **Platforms**                           | |wy| |ly| |my| |an| |in|           |
+-----------------------------------------+------------------------------------+
| **Tessellation**                        | |t_green| Supported (computed)     |
+-----------------------------------------+------------------------------------+
| :ref:`dgn_brep`                         | |t_green| Generated from file      |
+-----------------------------------------+------------------------------------+
| **PMI**                                 | |c_grey| Unsupported by format     |
+-----------------------------------------+------------------------------------+

The DGN (Design) format is a prominent file format used primarily for computer-aided 
design (CAD) and building information modeling (BIM) applications.
Developed and maintained by Bentley Systems, DGN files are extensively employed in 
various industries, including architecture, engineering, construction, and geospatial.

The file extensions of DGN files that you can expect to be loaded by HOOPS Exchange include:

* `.DGN`

How to Import from DGN
======================

Reading ``DGN`` files follows the same pattern as other formats: configure load parameters, 
then call the standard load function.

To load a DGN file, use :cpp:func:`A3DAsmModelFileLoadFromFile`.
The :cpp:struct:`A3DParamsLoadData` structure is used to customize the loading behavior:

.. code-block:: c

   A3DAsmModelFile* pModelFile = 0;

   A3DRWParamsLoadData sReadParam = A3D_MAKE_DATA(A3DRWParamsLoadData);
   sReadParam.m_sGeneral.m_bReadSolids = true;

   // ... set other A3DRWParamsLoadData fields as necessary

   A3DAsmModelFileLoadFromFile("path/to/file.dgn", &sReadParam, &pModelFile);

See :doc:`/guide/basic_operations/load_model` for more about loading model files.

.. _dgn_brep:

Boundary Representation (B-rep)
===============================

The DGN format does not store geometry as meshes or as boundary representations (B-rep).
Instead, it stores definitions of shapes, such as extrusions, revolutions, and B-spline surfaces.
These definitions describe how to build the geometry, not the final set of faces and edges.

To use this data as a B-rep model, the definitions must be evaluated.
HOOPS Exchange reads these definitions, computes the resulting geometry, and converts it into a B-rep with faces, edges, and topology suitable for downstream use.

Levels
======

HOOPS Exchange provides support of items visibility based on the level they are attached to:

* In the DGN format, each item is attached to a level. 
* In the PRC structure generated by HOOPS Exchange, it creates a separate layer for each level, assigning a layer id that corresponds to the level number. 
* We set the layer id of each :struct:`A3DRiRepresentationItem` or :struct:`A3DAsmProductOccurrence` to match the level number of its counterpart in the DGN file. 

To manage layer visibility and control the visibility of different layers, a filter is applied on the root :struct:`A3DAsmProductOccurrence`. 
This is based on the ``GlobalDisplay`` and ``GlobalFreeze`` settings of the respective level in the DGN file.

Limitations
===========

* Topology is not supported for revolutions, except for cones and cylinders.
* Multilines, notes, texts, fonts, and dimensions are not supported.
* Levels

   * Levels are fully supported only for V8 files; they are not for V7 files.
   * Only the ``GlobalDisplay`` and ``GlobalFreeze`` settings are supported for controlling level visibility. The ViewDisplay setting is not handled.
   * Level numbers greater than 65,535 are not supported. These levels will not be assigned to any :struct:`A3DRiRepresentationItem` or :struct:`A3DAsmProductOccurrence`, and will not be included in the default filter layer list.
   * Changes to color, style, transparency, or material based on level are not yet supported.
* iModel files, with a *.i.dgn* extension, are not supported.
* UV mapping, color, and normal redefinitions are not supported for meshes.
* Reference files that are not in DGN format (such as DWG, IFC, ...) are not supported.
