dgnlib
Classes | Macros | Typedefs | Functions
dgnlib.h File Reference
#include "cpl_conv.h"

Go to the source code of this file.

Classes

struct  DGNPoint
 
struct  DGNElementInfo
 
struct  DGNElemCore
 
struct  DGNElemMultiPoint
 
struct  DGNElemArc
 
struct  DGNElemText
 
struct  DGNElemComplexHeader
 
struct  DGNElemColorTable
 
struct  DGNViewInfo
 
struct  DGNElemTCB
 
struct  DGNElemCellHeader
 
struct  DGNElemCellLibrary
 
struct  DGNElemSharedCellDefn
 
union  tagValueUnion
 
struct  DGNElemTagValue
 
struct  _DGNTagDef
 
struct  DGNElemTagSet
 
struct  DGNElemCone
 
struct  DGNElemTextNode
 
struct  DGNElemBSplineSurfaceHeader
 
struct  DGNElemBSplineCurveHeader
 
struct  DGNElemBSplineSurfaceBoundary
 
struct  DGNElemKnotWeight
 

Macros

#define CPLE_DGN_ERROR_BASE
 
#define CPLE_ElementTooBig   CPLE_DGN_ERROR_BASE+1
 
#define DGNTT_STRING   1
 
#define DGNTT_INTEGER   3
 
#define DGNTT_FLOAT   4
 
#define DGNST_CORE   1
 
#define DGNST_MULTIPOINT   2
 
#define DGNST_COLORTABLE   3
 
#define DGNST_TCB   4
 
#define DGNST_ARC   5
 
#define DGNST_TEXT   6
 
#define DGNST_COMPLEX_HEADER   7
 
#define DGNST_CELL_HEADER   8
 
#define DGNST_TAG_VALUE   9
 
#define DGNST_TAG_SET   10
 
#define DGNST_CELL_LIBRARY   11
 
#define DGNST_CONE   12
 
#define DGNST_TEXT_NODE   13
 
#define DGNST_BSPLINE_SURFACE_HEADER   14
 
#define DGNST_BSPLINE_CURVE_HEADER   15
 
#define DGNST_BSPLINE_SURFACE_BOUNDARY   16
 
#define DGNST_KNOT_WEIGHT   17
 
#define DGNST_SHARED_CELL_DEFN   18
 
#define DGNT_CELL_LIBRARY   1
 
#define DGNT_CELL_HEADER   2
 
#define DGNT_LINE   3
 
#define DGNT_LINE_STRING   4
 
#define DGNT_GROUP_DATA   5
 
#define DGNT_SHAPE   6
 
#define DGNT_TEXT_NODE   7
 
#define DGNT_DIGITIZER_SETUP   8
 
#define DGNT_TCB   9
 
#define DGNT_LEVEL_SYMBOLOGY   10
 
#define DGNT_CURVE   11
 
#define DGNT_COMPLEX_CHAIN_HEADER   12
 
#define DGNT_COMPLEX_SHAPE_HEADER   14
 
#define DGNT_ELLIPSE   15
 
#define DGNT_ARC   16
 
#define DGNT_TEXT   17
 
#define DGNT_3DSURFACE_HEADER   18
 
#define DGNT_3DSOLID_HEADER   19
 
#define DGNT_BSPLINE_POLE   21
 
#define DGNT_POINT_STRING   22
 
#define DGNT_BSPLINE_SURFACE_HEADER   24
 
#define DGNT_BSPLINE_SURFACE_BOUNDARY   25
 
#define DGNT_BSPLINE_KNOT   26
 
#define DGNT_BSPLINE_CURVE_HEADER   27
 
#define DGNT_BSPLINE_WEIGHT_FACTOR   28
 
#define DGNT_CONE   23
 
#define DGNT_SHARED_CELL_DEFN   34
 
#define DGNT_SHARED_CELL_ELEM   35
 
#define DGNT_TAG_VALUE   37
 
#define DGNT_APPLICATION_ELEM   66
 
#define DGNS_SOLID   0
 
#define DGNS_DOTTED   1
 
#define DGNS_MEDIUM_DASH   2
 
#define DGNS_LONG_DASH   3
 
#define DGNS_DOT_DASH   4
 
#define DGNS_SHORT_DASH   5
 
#define DGNS_DASH_DOUBLE_DOT   6
 
#define DGNS_LONG_DASH_SHORT_DASH   7
 
#define DGNSUT_SURFACE_OF_PROJECTION   0
 
#define DGNSUT_BOUNDED_PLANE   1
 
#define DGNSUT_BOUNDED_PLANE2   2
 
#define DGNSUT_RIGHT_CIRCULAR_CYLINDER   3
 
#define DGNSUT_RIGHT_CIRCULAR_CONE   4
 
#define DGNSUT_TABULATED_CYLINDER   5
 
#define DGNSUT_TABULATED_CONE   6
 
#define DGNSUT_CONVOLUTE   7
 
#define DGNSUT_SURFACE_OF_REVOLUTION   8
 
#define DGNSUT_WARPED_SURFACE   9
 
#define DGNSOT_VOLUME_OF_PROJECTION   0
 
#define DGNSOT_VOLUME_OF_REVOLUTION   1
 
#define DGNSOT_BOUNDED_VOLUME   2
 
#define DGNC_PRIMARY   0
 
#define DGNC_PATTERN_COMPONENT   1
 
#define DGNC_CONSTRUCTION_ELEMENT   2
 
#define DGNC_DIMENSION_ELEMENT   3
 
#define DGNC_PRIMARY_RULE_ELEMENT   4
 
#define DGNC_LINEAR_PATTERNED_ELEMENT   5
 
#define DGNC_CONSTRUCTION_RULE_ELEMENT   6
 
#define DGN_GDL_COLOR_TABLE   1
 
#define DGN_GDL_NAMED_VIEW   3
 
#define DGN_GDL_REF_FILE   9
 
#define DGNPF_HOLE   0x8000
 
#define DGNPF_SNAPPABLE   0x4000
 
#define DGNPF_PLANAR   0x2000
 
#define DGNPF_ORIENTATION   0x1000
 
#define DGNPF_ATTRIBUTES   0x0800
 
#define DGNPF_MODIFIED   0x0400
 
#define DGNPF_NEW   0x0200
 
#define DGNPF_LOCKED   0x0100
 
#define DGNPF_CLASS   0x000f
 
#define DGNEIF_DELETED   0x01
 
#define DGNEIF_COMPLEX   0x02
 
#define DGNJ_LEFT_TOP   0
 
#define DGNJ_LEFT_CENTER   1
 
#define DGNJ_LEFT_BOTTOM   2
 
#define DGNJ_LEFTMARGIN_TOP   3 /* text node header only */
 
#define DGNJ_LEFTMARGIN_CENTER   4 /* text node header only */
 
#define DGNJ_LEFTMARGIN_BOTTOM   5 /* text node header only */
 
#define DGNJ_CENTER_TOP   6
 
#define DGNJ_CENTER_CENTER   7
 
#define DGNJ_CENTER_BOTTOM   8
 
#define DGNJ_RIGHTMARGIN_TOP   9 /* text node header only */
 
#define DGNJ_RIGHTMARGIN_CENTER   10 /* text node header only */
 
#define DGNJ_RIGHTMARGIN_BOTTOM   11 /* text node header only */
 
#define DGNJ_RIGHT_TOP   12
 
#define DGNJ_RIGHT_CENTER   13
 
#define DGNJ_RIGHT_BOTTOM   14
 
#define DGNO_CAPTURE_RAW_DATA   0x01
 
#define DGNLT_DMRS   0x0000
 
#define DGNLT_INFORMIX   0x3848
 
#define DGNLT_ODBC   0x5e62
 
#define DGNLT_ORACLE   0x6091
 
#define DGNLT_RIS   0x71FB
 
#define DGNLT_SYBASE   0x4f58
 
#define DGNLT_XBASE   0x1971
 
#define DGNLT_SHAPE_FILL   0x0041
 
#define DGNLT_ASSOC_ID   0x7D2F
 
#define DGNCF_USE_SEED_UNITS   0x01
 
#define DGNCF_USE_SEED_ORIGIN   0x02
 
#define DGNCF_COPY_SEED_FILE_COLOR_TABLE   0x04
 
#define DGNCF_COPY_WHOLE_SEED_FILE   0x08
 
#define DGNBSC_CURVE_DISPLAY   0x10
 
#define DGNBSC_POLY_DISPLAY   0x20
 
#define DGNBSC_RATIONAL   0x40
 
#define DGNBSC_CLOSED   0x80
 
#define DGNBSS_ARC_SPACING   0x40
 
#define DGNBSS_CLOSED   0x80
 

Typedefs

typedef struct _DGNTagDef DGNTagDef
 
typedef void * DGNHandle
 

Functions

DGNHandle CPL_DLL DGNOpen (const char *, int)
 
void CPL_DLL DGNSetOptions (DGNHandle, int)
 
int CPL_DLL DGNTestOpen (GByte *, int)
 
const DGNElementInfo CPL_DLL * DGNGetElementIndex (DGNHandle, int *)
 
int CPL_DLL DGNGetExtents (DGNHandle, double *)
 
int CPL_DLL DGNGetDimension (DGNHandle)
 
DGNElemCore CPL_DLL * DGNReadElement (DGNHandle)
 
void CPL_DLL DGNFreeElement (DGNHandle, DGNElemCore *)
 
void CPL_DLL DGNRewind (DGNHandle)
 
int CPL_DLL DGNGotoElement (DGNHandle, int)
 
void CPL_DLL DGNClose (DGNHandle)
 
int CPL_DLL DGNLoadTCB (DGNHandle)
 
int CPL_DLL DGNLookupColor (DGNHandle, int, int *, int *, int *)
 
int CPL_DLL DGNGetShapeFillInfo (DGNHandle, DGNElemCore *, int *)
 
int CPL_DLL DGNGetAssocID (DGNHandle, DGNElemCore *)
 
int CPL_DLL DGNGetElementExtents (DGNHandle, DGNElemCore *, DGNPoint *, DGNPoint *)
 
void CPL_DLL DGNDumpElement (DGNHandle, DGNElemCore *, FILE *)
 
const char CPL_DLL * DGNTypeToName (int)
 
void CPL_DLL DGNRotationToQuaternion (double, int *)
 
void CPL_DLL DGNQuaternionToMatrix (int *, float *)
 
int CPL_DLL DGNStrokeArc (DGNHandle, DGNElemArc *, int, DGNPoint *)
 
int CPL_DLL DGNStrokeCurve (DGNHandle, DGNElemMultiPoint *, int, DGNPoint *)
 
void CPL_DLL DGNSetSpatialFilter (DGNHandle hDGN, double dfXMin, double dfYMin, double dfXMax, double dfYMax)
 
int CPL_DLL DGNGetAttrLinkSize (DGNHandle, DGNElemCore *, int)
 
unsigned char CPL_DLL * DGNGetLinkage (DGNHandle hDGN, DGNElemCore *psElement, int iIndex, int *pnLinkageType, int *pnEntityNum, int *pnMSLink, int *pnLinkSize)
 
int CPL_DLL DGNWriteElement (DGNHandle, DGNElemCore *)
 
int CPL_DLL DGNResizeElement (DGNHandle, DGNElemCore *, int)
 
DGNHandle CPL_DLL DGNCreate (const char *pszNewFilename, const char *pszSeedFile, int nCreationFlags, double dfOriginX, double dfOriginY, double dfOriginZ, int nMasterUnitPerSubUnit, int nUORPerSubUnit, const char *pszMasterUnits, const char *pszSubUnits)
 
DGNElemCore CPL_DLL * DGNCloneElement (DGNHandle hDGNSrc, DGNHandle hDGNDst, DGNElemCore *psSrcElement)
 
int CPL_DLL DGNUpdateElemCore (DGNHandle hDGN, DGNElemCore *psElement, int nLevel, int nGraphicGroup, int nColor, int nWeight, int nStyle)
 
int CPL_DLL DGNUpdateElemCoreExtended (DGNHandle hDGN, DGNElemCore *psElement)
 
DGNElemCore CPL_DLL * DGNCreateMultiPointElem (DGNHandle hDGN, int nType, int nPointCount, DGNPoint *pasVertices)
 
DGNElemCore CPL_DLL * DGNCreateArcElem2D (DGNHandle hDGN, int nType, double dfOriginX, double dfOriginY, double dfPrimaryAxis, double dfSecondaryAxis, double dfRotation, double dfStartAngle, double dfSweepAngle)
 
DGNElemCore CPL_DLL * DGNCreateArcElem (DGNHandle hDGN, int nType, double dfOriginX, double dfOriginY, double dfOriginZ, double dfPrimaryAxis, double dfSecondaryAxis, double dfStartAngle, double dfSweepAngle, double dfRotation, int *panQuaternion)
 
DGNElemCore CPL_DLL * DGNCreateConeElem (DGNHandle hDGN, double center_1X, double center_1Y, double center_1Z, double radius_1, double center_2X, double center_2Y, double center_2Z, double radius_2, int *panQuaternion)
 
DGNElemCore CPL_DLL * DGNCreateTextElem (DGNHandle hDGN, const char *pszText, int nFontId, int nJustification, double dfLengthMult, double dfHeightMult, double dfRotation, int *panQuaternion, double dfOriginX, double dfOriginY, double dfOriginZ)
 
DGNElemCore CPL_DLL * DGNCreateColorTableElem (DGNHandle hDGN, int nScreenFlag, GByte abyColorInfo[256][3])
 
DGNElemCore CPL_DLL * DGNCreateComplexHeaderElem (DGNHandle hDGN, int nType, int nTotLength, int nNumElems)
 
DGNElemCore CPL_DLL * DGNCreateComplexHeaderFromGroup (DGNHandle hDGN, int nType, int nNumElems, DGNElemCore **papsElems)
 
DGNElemCore CPL_DLL * DGNCreateSolidHeaderElem (DGNHandle hDGN, int nType, int nSurfType, int nBoundElems, int nTotLength, int nNumElems)
 
DGNElemCore CPL_DLL * DGNCreateSolidHeaderFromGroup (DGNHandle hDGN, int nType, int nSurfType, int nBoundElems, int nNumElems, DGNElemCore **papsElems)
 
DGNElemCore CPL_DLL * DGNCreateCellHeaderElem (DGNHandle hDGN, int nTotLength, const char *pszName, short nClass, short *panLevels, DGNPoint *psRangeLow, DGNPoint *psRangeHigh, DGNPoint *psOrigin, double dfXScale, double dfYScale, double dfRotation)
 
DGNElemCore CPL_DLL * DGNCreateCellHeaderFromGroup (DGNHandle hDGN, const char *pszName, short nClass, short *panLevels, int nNumElems, DGNElemCore **papsElems, DGNPoint *psOrigin, double dfXScale, double dfYScale, double dfRotation)
 
int CPL_DLL DGNAddMSLink (DGNHandle hDGN, DGNElemCore *psElement, int nLinkageType, int nEntityNum, int nMSLink)
 
int CPL_DLL DGNAddRawAttrLink (DGNHandle hDGN, DGNElemCore *psElement, int nLinkSize, unsigned char *pabyRawLinkData)
 
int CPL_DLL DGNAddShapeFillInfo (DGNHandle hDGN, DGNElemCore *psElement, int nColor)
 
int CPL_DLL DGNElemTypeHasDispHdr (int nElemType)
 

Detailed Description

Definitions of public structures and API of DGN Library.

Macro Definition Documentation

◆ DGNST_ARC

#define DGNST_ARC   5

DGNElemCore style: Element uses DGNElemArc structure

◆ DGNST_BSPLINE_CURVE_HEADER

#define DGNST_BSPLINE_CURVE_HEADER   15

DGNElemCore style: Element uses DGNElemBSplineCurveHeader structure

◆ DGNST_BSPLINE_SURFACE_BOUNDARY

#define DGNST_BSPLINE_SURFACE_BOUNDARY   16

DGNElemCore style: Element uses DGNElemBSplineSurfaceBoundary structure

◆ DGNST_BSPLINE_SURFACE_HEADER

#define DGNST_BSPLINE_SURFACE_HEADER   14

DGNElemCore style: Element uses DGNElemBSplineSurfaceHeader structure

◆ DGNST_CELL_HEADER

#define DGNST_CELL_HEADER   8

DGNElemCore style: Element uses DGNElemCellHeader structure

◆ DGNST_CELL_LIBRARY

#define DGNST_CELL_LIBRARY   11

DGNElemCore style: Element uses DGNElemCellLibrary structure

◆ DGNST_COLORTABLE

#define DGNST_COLORTABLE   3

DGNElemCore style: Element uses DGNElemColorTable structure

◆ DGNST_COMPLEX_HEADER

#define DGNST_COMPLEX_HEADER   7

DGNElemCore style: Element uses DGNElemComplexHeader structure

◆ DGNST_CONE

#define DGNST_CONE   12

DGNElemCore style: Element uses DGNElemCone structure

◆ DGNST_CORE

#define DGNST_CORE   1

DGNElemCore style: Element uses DGNElemCore structure

◆ DGNST_KNOT_WEIGHT

#define DGNST_KNOT_WEIGHT   17

DGNElemCore style: Element uses DGNElemKnotWeight structure

◆ DGNST_MULTIPOINT

#define DGNST_MULTIPOINT   2

DGNElemCore style: Element uses DGNElemMultiPoint structure

◆ DGNST_SHARED_CELL_DEFN

#define DGNST_SHARED_CELL_DEFN   18

DGNElemCore style: Element uses DGNElemSharedCellDefn structure

◆ DGNST_TAG_SET

#define DGNST_TAG_SET   10

DGNElemCore style: Element uses DGNElemTagSet structure

◆ DGNST_TAG_VALUE

#define DGNST_TAG_VALUE   9

DGNElemCore style: Element uses DGNElemTagValue structure

◆ DGNST_TCB

#define DGNST_TCB   4

DGNElemCore style: Element uses DGNElemTCB structure

◆ DGNST_TEXT

#define DGNST_TEXT   6

DGNElemCore style: Element uses DGNElemText structure

◆ DGNST_TEXT_NODE

#define DGNST_TEXT_NODE   13

DGNElemCore style: Element uses DGNElemTextNode structure

Typedef Documentation

◆ DGNHandle

typedef void* DGNHandle

Opaque handle representing DGN file, used with DGN API.

◆ DGNTagDef

typedef struct _DGNTagDef DGNTagDef

Tag definition.

Structure holding definition of one tag within a DGNTagSet.

Function Documentation

◆ DGNAddMSLink()

int CPL_DLL DGNAddMSLink ( DGNHandle  hDGN,
DGNElemCore psElement,
int  nLinkageType,
int  nEntityNum,
int  nMSLink 
)

Add a database link to element.

The target element must already have raw_data loaded, and it will be resized (see DGNResizeElement()) as needed for the new attribute data. Note that the element is not written to disk immediate. Use DGNWriteElement() for that.

Parameters
hDGNthe file to which the element corresponds.
psElementthe element being updated.
nLinkageTypelink type (DGNLT_*). Usually one of DGNLT_DMRS, DGNLT_INFORMIX, DGNLT_ODBC, DGNLT_ORACLE, DGNLT_RIS, DGNLT_SYBASE, or DGNLT_XBASE.
nEntityNumindicator of the table referenced on target database.
nMSLinkindicator of the record referenced on target table.
Returns
-1 on failure, or the link index.

◆ DGNAddRawAttrLink()

int CPL_DLL DGNAddRawAttrLink ( DGNHandle  hDGN,
DGNElemCore psElement,
int  nLinkSize,
unsigned char *  pabyRawLinkData 
)

Add a raw attribute linkage to element.

Given a raw data buffer, append it to this element as an attribute linkage without trying to interpret the linkage data.

The target element must already have raw_data loaded, and it will be resized (see DGNResizeElement()) as needed for the new attribute data. Note that the element is not written to disk immediate. Use DGNWriteElement() for that.

This function will take care of updating the "totlength" field of complex chain or shape headers to account for the extra attribute space consumed in the header element.

Parameters
hDGNthe file to which the element corresponds.
psElementthe element being updated.
nLinkSizethe size of the linkage in bytes.
pabyRawLinkDatathe raw linkage data (nLinkSize bytes worth).
Returns
-1 on failure, or the link index.

◆ DGNAddShapeFillInfo()

int CPL_DLL DGNAddShapeFillInfo ( DGNHandle  hDGN,
DGNElemCore psElement,
int  nColor 
)

Add a shape fill attribute linkage.

The target element must already have raw_data loaded, and it will be resized (see DGNResizeElement()) as needed for the new attribute data. Note that the element is not written to disk immediate. Use DGNWriteElement() for that.

Parameters
hDGNthe file to which the element corresponds.
psElementthe element being updated.
nColorfill color (color index from palette).
Returns
-1 on failure, or the link index.

◆ DGNClose()

void CPL_DLL DGNClose ( DGNHandle  hDGN)

Close DGN file.

Parameters
hDGNHandle from DGNOpen() for file to close.

◆ DGNCreate()

DGNHandle CPL_DLL DGNCreate ( const char *  pszNewFilename,
const char *  pszSeedFile,
int  nCreationFlags,
double  dfOriginX,
double  dfOriginY,
double  dfOriginZ,
int  nSubUnitsPerMasterUnit,
int  nUORPerSubUnit,
const char *  pszMasterUnits,
const char *  pszSubUnits 
)

Create new DGN file.

This function will create a new DGN file based on the provided seed file, and return a handle on which elements may be read and written.

The following creation flags may be passed:

  • DGNCF_USE_SEED_UNITS: The master and subunit resolutions and names from the seed file will be used in the new file. The nMasterUnitPerSubUnit, nUORPerSubUnit, pszMasterUnits, and pszSubUnits arguments will be ignored.
  • DGNCF_USE_SEED_ORIGIN: The origin from the seed file will be used and the X, Y and Z origin passed into the call will be ignored.
  • DGNCF_COPY_SEED_FILE_COLOR_TABLE: Should the first color table occurring in the seed file also be copied?
  • DGNCF_COPY_WHOLE_SEED_FILE: By default only the first three elements (TCB, Digitizer Setup and Level Symbology) are copied from the seed file. If this flag is provided the entire seed file is copied verbatim (with the TCB origin and units possibly updated).
Parameters
pszNewFilenamethe filename to create. If it already exists it will be overwritten.
pszSeedFilethe seed file to copy header from.
nCreationFlagsAn ORing of DGNCF_* flags that are to take effect.
dfOriginXthe X origin for the file.
dfOriginYthe Y origin for the file.
dfOriginZthe Z origin for the file.
nSubUnitsPerMasterUnitthe number of subunits in one master unit.
nUORPerSubUnitthe number of UOR (units of resolution) per subunit.
pszMasterUnitsthe name of the master units (2 characters).
pszSubUnitsthe name of the subunits (2 characters).

◆ DGNCreateArcElem()

DGNElemCore CPL_DLL* DGNCreateArcElem ( DGNHandle  hDGN,
int  nType,
double  dfOriginX,
double  dfOriginY,
double  dfOriginZ,
double  dfPrimaryAxis,
double  dfSecondaryAxis,
double  dfStartAngle,
double  dfSweepAngle,
double  dfRotation,
int *  panQuaternion 
)

Create Arc or Ellipse element.

Create a new 2D or 3D arc or ellipse element. The start angle, and sweep angle are ignored for DGNT_ELLIPSE but used for DGNT_ARC.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

Parameters
hDGNthe DGN file on which the element will eventually be written.
nTypeeither DGNT_ELLIPSE or DGNT_ARC to select element type.
dfOriginXthe origin (center of rotation) of the arc (X).
dfOriginYthe origin (center of rotation) of the arc (Y).
dfOriginZthe origin (center of rotation) of the arc (Y).
dfPrimaryAxisthe length of the primary axis.
dfSecondaryAxisthe length of the secondary axis.
dfStartAnglestart angle, degrees counterclockwise of primary axis.
dfSweepAnglesweep angle, degrees
dfRotationCounterclockwise rotation in degrees.
panQuaternion3D orientation quaternion (NULL to use rotation).
Returns
the new element (DGNElemArc) or NULL on failure.

◆ DGNCreateCellHeaderElem()

DGNElemCore CPL_DLL* DGNCreateCellHeaderElem ( DGNHandle  hDGN,
int  nTotLength,
const char *  pszName,
short  nClass,
short *  panLevels,
DGNPoint psRangeLow,
DGNPoint psRangeHigh,
DGNPoint psOrigin,
double  dfXScale,
double  dfYScale,
double  dfRotation 
)

Create cell header.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

Generally speaking the function DGNCreateCellHeaderFromGroup() should be used instead of this function.

Parameters
hDGNthe file handle on which the element is to be written.
nTotLengthtotal length of cell in words not including the 38 bytes of the cell header that occur before the totlength indicator.
nClassthe class value for the cell.
panLevelsan array of shorts holding the bit mask of levels in effect for this cell. This array should contain 4 shorts (64 bits).
psRangeLowthe cell diagonal origin in original cell file coordinates.
psRangeHighthe cell diagonal top left corner in original cell file coordinates.
psOriginthe origin of the cell in output file coordinates.
dfXScalethe amount of scaling applied in the X dimension in mapping from cell file coordinates to output file coordinates.
dfYScalethe amount of scaling applied in the Y dimension in mapping from cell file coordinates to output file coordinates.
dfRotationthe amount of rotation (degrees counterclockwise) in mapping from cell coordinates to output file coordinates.
Returns
the new element (DGNElemCellHeader) or NULL on failure.

◆ DGNCreateCellHeaderFromGroup()

DGNElemCore CPL_DLL* DGNCreateCellHeaderFromGroup ( DGNHandle  hDGN,
const char *  pszName,
short  nClass,
short *  panLevels,
int  nNumElems,
DGNElemCore **  papsElems,
DGNPoint psOrigin,
double  dfXScale,
double  dfYScale,
double  dfRotation 
)

Create cell header from a group of elements.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

This function will compute the total length, bounding box, and diagonal range values from the set of provided elements. Note that the proper diagonal range values will only be written if 1.0 is used for the x and y scale values, and 0.0 for the rotation. Use of other values will result in incorrect scaling handles being presented to the user in Microstation when they select the element.

Parameters
hDGNthe file handle on which the element is to be written.
nClassthe class value for the cell.
panLevelsan array of shorts holding the bit mask of levels in effect for this cell. This array should contain 4 shorts (64 bits). This array would normally be passed in as NULL, and the function will build a mask from the passed list of elements.
psOriginthe origin of the cell in output file coordinates.
dfXScalethe amount of scaling applied in the X dimension in mapping from cell file coordinates to output file coordinates.
dfYScalethe amount of scaling applied in the Y dimension in mapping from cell file coordinates to output file coordinates.
dfRotationthe amount of rotation (degrees counterclockwise) in mapping from cell coordinates to output file coordinates.
Returns
the new element (DGNElemCellHeader) or NULL on failure.

◆ DGNCreateColorTableElem()

DGNElemCore CPL_DLL* DGNCreateColorTableElem ( DGNHandle  hDGN,
int  nScreenFlag,
GByte  abyColorInfo[256][3] 
)

Create color table element.

Creates a color table element with the indicated color table.

Note that color table elements are actually of type DGNT_GROUP_DATA(5) and always on level 1. Do not alter the level with DGNUpdateElemCore() or the element will essentially be corrupt.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

Parameters
hDGNthe file to which the element will eventually be written.
nScreenFlagthe screen to which the color table applies (0 = left, 1 = right).
abyColorInfoarray of 256 color entries. The first is the background color.
Returns
the new element (DGNElemColorTable) or NULL on failure.

◆ DGNCreateComplexHeaderElem()

DGNElemCore CPL_DLL* DGNCreateComplexHeaderElem ( DGNHandle  hDGN,
int  nType,
int  nTotLength,
int  nNumElems 
)

Create complex chain/shape header.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

The nTotLength is the sum of the size of all elements in the complex group plus 5. The DGNCreateComplexHeaderFromGroup() can be used to build a complex element from the members more conveniently.

Parameters
hDGNthe file on which the element will be written.
nTypeDGNT_COMPLEX_CHAIN_HEADER or DGNT_COMPLEX_SHAPE_HEADER. depending on whether the list is open or closed (last point equal to last) or if the object represents a surface or a solid.
nTotLengththe value of the totlength field in the element.
nNumElemsthe number of elements in the complex group not including the header element.
Returns
the new element (DGNElemComplexHeader) or NULL on failure.

◆ DGNCreateComplexHeaderFromGroup()

DGNElemCore CPL_DLL* DGNCreateComplexHeaderFromGroup ( DGNHandle  hDGN,
int  nType,
int  nNumElems,
DGNElemCore **  papsElems 
)

Create complex chain/shape header.

This function is similar to DGNCreateComplexHeaderElem(), but it takes care of computing the total size of the set of elements being written, and collecting the bounding extents. It also takes care of some other convenience issues, like marking all the member elements as complex, and setting the level based on the level of the member elements.

Parameters
hDGNthe file on which the element will be written.
nTypeDGNT_COMPLEX_CHAIN_HEADER or DGNT_COMPLEX_SHAPE_HEADER. depending on whether the list is open or closed (last point equal to last) or if the object represents a surface or a solid.
nNumElemsthe number of elements in the complex group not including the header element.
papsElemsarray of pointers to nNumElems elements in the complex group. Some updates may be made to these elements.
Returns
the new element (DGNElemComplexHeader) or NULL on failure.

◆ DGNCreateConeElem()

DGNElemCore CPL_DLL* DGNCreateConeElem ( DGNHandle  hDGN,
double  dfCenter_1X,
double  dfCenter_1Y,
double  dfCenter_1Z,
double  dfRadius_1,
double  dfCenter_2X,
double  dfCenter_2Y,
double  dfCenter_2Z,
double  dfRadius_2,
int *  panQuaternion 
)

Create Cone element.

Create a new 3D cone element.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

Parameters
hDGNthe DGN file on which the element will eventually be written.
dfCenter_1Xthe center of the first bounding circle (X).
dfCenter_1Ythe center of the first bounding circle (Y).
dfCenter_1Zthe center of the first bounding circle (Z).
dfRadius_1the radius of the first bounding circle.
dfCenter_2Xthe center of the second bounding circle (X).
dfCenter_2Ythe center of the second bounding circle (Y).
dfCenter_2Zthe center of the second bounding circle (Z).
dfRadius_2the radius of the second bounding circle.
panQuaternion3D orientation quaternion (NULL for default orientation - circles parallel to the X-Y plane).
Returns
the new element (DGNElemCone) or NULL on failure.

◆ DGNCreateMultiPointElem()

DGNElemCore CPL_DLL* DGNCreateMultiPointElem ( DGNHandle  hDGN,
int  nType,
int  nPointCount,
DGNPoint pasVertices 
)

Create new multi-point element.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

NOTE: There are restrictions on the nPointCount for some elements. For instance, DGNT_LINE can only have 2 points. Maximum element size precludes very large numbers of points.

Parameters
hDGNthe file on which the element will eventually be written.
nTypethe type of the element to be created. It must be one of DGNT_LINE, DGNT_LINE_STRING, DGNT_SHAPE, DGNT_CURVE or DGNT_BSPLINE_POLE.
nPointCountthe number of points in the pasVertices list.
pasVerticesthe list of points to be written.
Returns
the new element (a DGNElemMultiPoint structure) or NULL on failure.

◆ DGNCreateSolidHeaderElem()

DGNElemCore CPL_DLL* DGNCreateSolidHeaderElem ( DGNHandle  hDGN,
int  nType,
int  nSurfType,
int  nBoundElems,
int  nTotLength,
int  nNumElems 
)

Create 3D solid/surface.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

The nTotLength is the sum of the size of all elements in the solid group plus 6. The DGNCreateSolidHeaderFromGroup() can be used to build a solid element from the members more conveniently.

Parameters
hDGNthe file on which the element will be written.
nTypeDGNT_3DSURFACE_HEADER or DGNT_3DSOLID_HEADER.
nSurfTypethe surface/solid type, one of DGNSUT_* or DGNSOT_*.
nBoundElemsthe number of elements in each boundary.
nTotLengththe value of the totlength field in the element.
nNumElemsthe number of elements in the solid not including the header element.
Returns
the new element (DGNElemComplexHeader) or NULL on failure.

◆ DGNCreateSolidHeaderFromGroup()

DGNElemCore CPL_DLL* DGNCreateSolidHeaderFromGroup ( DGNHandle  hDGN,
int  nType,
int  nSurfType,
int  nBoundElems,
int  nNumElems,
DGNElemCore **  papsElems 
)

Create 3D solid/surface header.

This function is similar to DGNCreateSolidHeaderElem(), but it takes care of computing the total size of the set of elements being written, and collecting the bounding extents. It also takes care of some other convenience issues, like marking all the member elements as complex, and setting the level based on the level of the member elements.

Parameters
hDGNthe file on which the element will be written.
nTypeDGNT_3DSURFACE_HEADER or DGNT_3DSOLID_HEADER.
nSurfTypethe surface/solid type, one of DGNSUT_* or DGNSOT_*.
nBoundElemsthe number of boundary elements.
nNumElemsthe number of elements in the solid not including the header element.
papsElemsarray of pointers to nNumElems elements in the solid. Some updates may be made to these elements.
Returns
the new element (DGNElemComplexHeader) or NULL on failure.

◆ DGNCreateTextElem()

DGNElemCore CPL_DLL* DGNCreateTextElem ( DGNHandle  hDGN,
const char *  pszText,
int  nFontId,
int  nJustification,
double  dfLengthMult,
double  dfHeightMult,
double  dfRotation,
int *  panQuaternion,
double  dfOriginX,
double  dfOriginY,
double  dfOriginZ 
)

Create text element.

The newly created element will still need to be written to file using DGNWriteElement(). Also the level and other core values will be defaulted. Use DGNUpdateElemCore() on the element before writing to set these values.

Parameters
hDGNthe file on which the element will eventually be written.
pszTextthe string of text.
nFontIdmicrostation font id for the text. 1 may be used as default.
nJustificationtext justification. One of DGNJ_LEFT_TOP, DGNJ_LEFT_CENTER, DGNJ_LEFT_BOTTOM, DGNJ_CENTER_TOP, DGNJ_CENTER_CENTER, DGNJ_CENTER_BOTTOM, DGNJ_RIGHT_TOP, DGNJ_RIGHT_CENTER, DGNJ_RIGHT_BOTTOM.
dfLengthMultcharacter width in master units.
dfHeightMultcharacter height in master units.
dfRotationCounterclockwise text rotation in degrees.
panQuaternion3D orientation quaternion (NULL to use rotation).
dfOriginXText origin (X).
dfOriginYText origin (Y).
dfOriginZText origin (Z).
Returns
the new element (DGNElemText) or NULL on failure.

◆ DGNDumpElement()

void CPL_DLL DGNDumpElement ( DGNHandle  hDGN,
DGNElemCore psElement,
FILE *  fp 
)

Emit textual report of an element.

This function exists primarily for debugging, and will produce a textual report about any element type to the designated file.

Parameters
hDGNthe file from which the element originated.
psElementthe element to report on.
fpthe file (such as stdout) to report the element information to.

◆ DGNElemTypeHasDispHdr()

int CPL_DLL DGNElemTypeHasDispHdr ( int  nElemType)

Does element type have display header.

Parameters
nElemTypeelement type (0-63) to test.
Returns
TRUE if elements of passed in type have a display header after the core element header, or FALSE otherwise.

◆ DGNGetAssocID()

int CPL_DLL DGNGetAssocID ( DGNHandle  hDGN,
DGNElemCore psElem 
)

Fetch association id for an element.

This method will check if an element has an association id, and if so returns it, otherwise returning -1. Association ids are kept as a user attribute linkage where present.

Parameters
hDGNthe file.
psElemthe element.
Returns
The id or -1 on failure.

◆ DGNGetDimension()

int CPL_DLL DGNGetDimension ( DGNHandle  hDGN)

Return 2D/3D dimension of file.

Return 2 or 3 depending on the dimension value of the provided file.

◆ DGNGetElementExtents()

int CPL_DLL DGNGetElementExtents ( DGNHandle  hDGN,
DGNElemCore psElement,
DGNPoint psMin,
DGNPoint psMax 
)

Fetch extents of an element.

This function will return the extents of the passed element if possible. The extents are extracted from the element header if it contains them, and transformed into master georeferenced format. Some element types do not have extents at all and will fail.

This call will also fail if the extents raw data for the element is not available. This will occur if it was not the most recently read element, and if the raw_data field is not loaded.

Parameters
hDGNthe handle of the file to read from.
psElementthe element to extract extents from.
psMinstructure loaded with X, Y and Z minimum values for the extent.
psMaxstructure loaded with X, Y and Z maximum values for the extent.
Returns
TRUE on success of FALSE if extracting extents fails.

◆ DGNGetElementIndex()

const DGNElementInfo CPL_DLL* DGNGetElementIndex ( DGNHandle  hDGN,
int *  pnElementCount 
)

Fetch element index.

This function will return an array with brief information about every element in a DGN file. It requires one pass through the entire file to generate (this is not repeated on subsequent calls).

The returned array of DGNElementInfo structures contain the level, type, stype, and other flags for each element in the file. This can facilitate application level code representing the number of elements of various types efficiently.

Note that while building the index requires one pass through the whole file, it does not generally request much processing for each element.

Parameters
hDGNthe file to get an index for.
pnElementCountthe integer to put the total element count into.
Returns
a pointer to an internal array of DGNElementInfo structures (there will be *pnElementCount entries in the array), or NULL on failure. The returned array should not be modified or freed, and will last only as long as the DGN file remains open.

◆ DGNGetExtents()

int CPL_DLL DGNGetExtents ( DGNHandle  hDGN,
double *  padfExtents 
)

Fetch overall file extents.

The extents are collected for each element while building an index, so if an index has not already been built, it will be built when DGNGetExtents() is called.

The Z min/max values are generally meaningless (0 and 0xffffffff in uor space).

Parameters
hDGNthe file to get extents for.
padfExtentspointer to an array of six doubles into which are loaded the values xmin, ymin, zmin, xmax, ymax, and zmax.
Returns
TRUE on success or FALSE on failure.

◆ DGNGetLinkage()

unsigned char CPL_DLL* DGNGetLinkage ( DGNHandle  hDGN,
DGNElemCore psElement,
int  iIndex,
int *  pnLinkageType,
int *  pnEntityNum,
int *  pnMSLink,
int *  pnLength 
)

Returns requested linkage raw data.

A pointer to the raw data for the requested attribute linkage is returned as well as (potentially) various information about the linkage including the linkage type, database entity number and MSLink value, and the length of the raw linkage data in bytes.

If the requested linkage (iIndex) does not exist a value of zero is returned.

The entity number is (loosely speaking) the index of the table within the current database to which the MSLINK value will refer. The entity number should be used to lookup the table name in the MSCATALOG table. The MSLINK value is the key value for the record in the target table.

Parameters
hDGNthe file from which the element originated.
psElementthe element to report on.
iIndexthe zero based index of the linkage to fetch.
pnLinkageTypevariable to return linkage type. This may be one of the predefined DGNLT_ values or a different value. This pointer may be NULL.
pnEntityNumvariable to return the entity number in or NULL if not required.
pnMSLinkvariable to return the MSLINK value in, or NULL if not required.
pnLengthvariable to returned the linkage size in bytes or NULL.
Returns
pointer to raw internal linkage data. This data should not be altered or freed. NULL returned on failure.

◆ DGNGetShapeFillInfo()

int CPL_DLL DGNGetShapeFillInfo ( DGNHandle  hDGN,
DGNElemCore psElem,
int *  pnColor 
)

Fetch fill color for a shape.

This method will check for a 0x0041 user attribute linkaged with fill color information for the element. If found the function returns TRUE, and places the fill color in *pnColor, otherwise FALSE is returned and *pnColor is not updated.

Parameters
hDGNthe file.
psElemthe element.
pnColorthe location to return the fill color.
Returns
TRUE on success or FALSE on failure.

◆ DGNGotoElement()

int CPL_DLL DGNGotoElement ( DGNHandle  hDGN,
int  element_id 
)

Seek to indicated element.

Changes what element will be read on the next call to DGNReadElement(). Note that this function requires and index, and one will be built if not already available.

Parameters
hDGNthe file to affect.
element_idthe element to seek to. These values are sequentially ordered starting at zero for the first element.
Returns
returns TRUE on success or FALSE on failure.

◆ DGNLoadTCB()

int CPL_DLL DGNLoadTCB ( DGNHandle  hDGN)

Load TCB if not already loaded.

This function will load the TCB element if it is not already loaded. It is used primarily to ensure the TCB is loaded before doing any operations that require TCB values (like creating new elements).

Returns
FALSE on failure or TRUE on success.

◆ DGNLookupColor()

int CPL_DLL DGNLookupColor ( DGNHandle  hDGN,
int  color_index,
int *  red,
int *  green,
int *  blue 
)

Translate color index into RGB values.

If no color table has yet been encountered in the file a hard-coded "default" color table will be used. This seems to be what Microstation uses as a color table when there isn't one in a DGN file but I am not absolutely convinced it is appropriate.

Parameters
hDGNthe file.
color_indexthe color index to lookup.
redlocation to put red component.
greenlocation to put green component.
bluelocation to put blue component.
Returns
TRUE on success or FALSE on failure. May fail if color_index is out of range.

◆ DGNOpen()

DGNHandle CPL_DLL DGNOpen ( const char *  pszFilename,
int  bUpdate 
)

Open a DGN file.

The file is opened, and minimally verified to ensure it is a DGN (ISFF) file. If the file cannot be opened for read access an error with code CPLE_OpenFailed with be reported via CPLError() and NULL returned. If the file header does not appear to be a DGN file, an error with code CPLE_AppDefined will be reported via CPLError(), and NULL returned.

If successful a handle for further access is returned. This should be closed with DGNClose() when no longer needed.

DGNOpen() does not scan the file on open, and should be very fast even for large files.

Parameters
pszFilenamename of file to try opening.
bUpdateshould the file be opened with read+update (r+) mode?
Returns
handle to use for further access to file using DGN API, or NULL if open fails.

◆ DGNReadElement()

DGNElemCore CPL_DLL* DGNReadElement ( DGNHandle  hDGN)

Read a DGN element.

This function will return the next element in the file, starting with the first. It is affected by DGNGotoElement() calls.

The element is read into a structure which includes the DGNElemCore structure. It is expected that applications will inspect the stype field of the returned DGNElemCore and use it to cast the pointer to the appropriate element structure type such as DGNElemMultiPoint.

Parameters
hDGNthe handle of the file to read from.
Returns
pointer to element structure, or NULL on EOF or processing error. The structure should be freed with DGNFreeElement() when no longer needed.

◆ DGNResizeElement()

int CPL_DLL DGNResizeElement ( DGNHandle  hDGN,
DGNElemCore psElement,
int  nNewSize 
)

Resize an existing element.

If the new size is the same as the old nothing happens.

Otherwise, the old element in the file is marked as deleted, and the DGNElemCore.offset and element_id are set to -1 indicating that the element should be written to the end of file when next written by DGNWriteElement(). The internal raw data buffer is updated to the new size.

Only elements with "raw_data" loaded may be moved.

In normal use the DGNResizeElement() call would be called on a previously loaded element, and afterwards the raw_data would be updated before calling DGNWriteElement(). If DGNWriteElement() isn't called after DGNResizeElement() then the element will be lost having been marked as deleted in it's old position but never written at the new location.

Parameters
hDGNthe DGN file on which the element lives.
psElementthe element to alter.
nNewSizethe desired new size of the element in bytes. Must be a multiple of 2.
Returns
TRUE on success, or FALSE on error.

◆ DGNRewind()

void CPL_DLL DGNRewind ( DGNHandle  hDGN)

Rewind element reading.

Rewind the indicated DGN file, so the next element read with DGNReadElement() will be the first. Does not require indexing like the more general DGNReadElement() function.

Parameters
hDGNhandle to file.

◆ DGNSetOptions()

void CPL_DLL DGNSetOptions ( DGNHandle  hDGN,
int  nOptions 
)

Set file access options.

Sets a flag affecting how the file is accessed. Currently there is only one support flag:

DGNO_CAPTURE_RAW_DATA: If this is enabled (it is off by default), then the raw binary data associated with elements will be kept in the raw_data field within the DGNElemCore when they are read. This is required if the application needs to interpret the raw data itself. It is also necessary if the element is to be written back to this file, or another file using DGNWriteElement(). Off by default (to conserve memory).

Parameters
hDGNhandle to file returned by DGNOpen().
nOptionsORed option flags.

◆ DGNSetSpatialFilter()

void CPL_DLL DGNSetSpatialFilter ( DGNHandle  hDGN,
double  dfXMin,
double  dfYMin,
double  dfXMax,
double  dfYMax 
)

Set rectangle for which features are desired.

If a spatial filter is set with this function, DGNReadElement() will only return spatial elements (elements with a known bounding box) and only those elements for which this bounding box overlaps the requested region.

If all four values (dfXMin, dfXMax, dfYMin and dfYMax) are zero, the spatial filter is disabled. Note that installing a spatial filter won't reduce the amount of data read from disk. All elements are still scanned, but the amount of processing work for elements outside the spatial filter is minimized.

Parameters
hDGNHandle from DGNOpen() for file to update.
dfXMinminimum x coordinate for extents (georeferenced coordinates).
dfYMinminimum y coordinate for extents (georeferenced coordinates).
dfXMaxmaximum x coordinate for extents (georeferenced coordinates).
dfYMaxmaximum y coordinate for extents (georeferenced coordinates).

◆ DGNTestOpen()

int CPL_DLL DGNTestOpen ( GByte *  pabyHeader,
int  nByteCount 
)

Test if header is DGN.

Parameters
pabyHeaderblock of header data from beginning of file.
nByteCountnumber of bytes in pabyHeader.
Returns
TRUE if the header appears to be from a DGN file, otherwise FALSE.

◆ DGNTypeToName()

const char CPL_DLL* DGNTypeToName ( int  nType)

Convert type to name.

Returns a human readable name for an element type such as DGNT_LINE.

Parameters
nTypethe DGNT_* type code to translate.
Returns
a pointer to an internal string with the translation. This string should not be modified or freed.

◆ DGNUpdateElemCore()

int CPL_DLL DGNUpdateElemCore ( DGNHandle  hDGN,
DGNElemCore psElement,
int  nLevel,
int  nGraphicGroup,
int  nColor,
int  nWeight,
int  nStyle 
)

Change element core values.

The indicated values in the element are updated in the structure, as well as in the raw data. The updated element is not written to disk. That must be done with DGNWriteElement(). The element must have raw_data loaded.

Parameters
hDGNthe file on which the element belongs.
psElementthe element to modify.
nLevelthe new level value.
nGraphicGroupthe new graphic group value.
nColorthe new color index.
nWeightthe new element weight.
nStylethe new style value for the element.
Returns
Returns TRUE on success or FALSE on failure.

◆ DGNWriteElement()

int CPL_DLL DGNWriteElement ( DGNHandle  hDGN,
DGNElemCore psElement 
)

Write element to file.

Only elements with "raw_data" loaded may be written. This should include elements created with the various DGNCreate*() functions, and those read from the file with the DGNO_CAPTURE_RAW_DATA flag turned on with DGNSetOptions().

The passed element is written to the indicated file. If the DGNElemCore.offset field is -1 then the element is written at the end of the file (and offset/element are reset properly) otherwise the element is written back to the location indicated by DGNElemCore.offset.

If the element is added at the end of the file, and if an element index has already been built, it will be updated to reference the new element.

This function takes care of ensuring that the end-of-file marker is maintained after the last element.

Parameters
hDGNthe file to write the element to.
psElementthe element to write.
Returns
TRUE on success or FALSE in case of failure.