Raster Reference Element Feature in .dgn Files

Michael Kuzinets

June 27, 2017

A raster reference element (OdDgReferenceAttachmentHeader) is actually a non-graphical element that has no graphical element properties as level properties, etc. It can’t be selected like other elements. In fact there is a display and selection problem with it.

Beginning with Bentley® MicroStation® V8 XM format, a new element type was added: raster frame element (OdDgRasterFrame). It has no actual graphics data, so it can’t be rendered. It pairs with the raster reference element, and it is always used together with it (never used as a separate element). It provides a specific raster reference element with graphics element properties, and this is just the element that solves the display and selection problem with OdDgReferenceAttachmentHeader.

image1

The OdDgReferenceAttachmentHeader element is a type 90 with no display header and is stored with control elements. The OdDgRasterFrame element is a type 94 with a display header and is stored with graphic elements.

Only one OdDgRasterFrame element corresponds to the OdDgReferenceAttachmentHeader element. So there is one OdDgRasterFrame (type 94) for one OdDgReferenceAttachmentHeader (type 90). It is the OdDgRasterFrame element that contains all the data required to describe the raster attachment.

When an OdDgReferenceAttachmentHeader element is modified, Teigha updates and synchronizes a proper OdDgRasterFrame.

Note: You can create an OdDgReferenceAttachmentHeader element without a corresponding OdDgRasterFrame element, and the output file is valid. But in this case the application must solve the “display and selection problem” with rasters (for instance, to create a corresponding OdDgRasterFrame element as MicroStation does in such a case).

Creating an OdDgReferenceAttachmentHeader element

Create a .dgn file with a raster reference element (a file database and an environment already exists):

  • Create an OdDgRasterAttachmentHeader object.
  • Add the raster reference to the database.
  • Fill basic properties (filename, extent, orientation, etc.).
  • Create an OdDgRasterFrame object.
  • Add the frame element to the database.
  • Set a reference ID for the raster reference.
  • Fill basic frame properties (raster color mode, etc.).
// Add Raster Reference element
//
// EntityBoxes m_EntityBoxes;   //some table with number of rows and columns
// int boxRow;
// int boxColumn;
// OdDgModelPtr pModel3d;
{
// creates Raster Reference element
OdDgRasterAttachmentHeaderPtr raster = OdDgRasterAttachmentHeader::createObject();
double sx = m_EntityBoxes.getHeight() / 2.;    //some Height value
double rotation = .1;
double affinity = .03;  // some angles for demonstration

m_pModel3d->addElement(raster);  // add Raster Reference element to database

raster->setFilename(OdString( "attachUnkown.jpg"));
//some non-existent file name is set just for sample
raster->setExtent(OdGePoint2d(1., 1.));
raster->setOrientation(m_EntityBoxes.getBoxCenter(boxRow, boxColumn) - 
OdGeVector3d(sx / 3., 0., 0.),
OdGeVector3d(cos(rotation), sin(rotation), 0. ) * .01,
OdGeVector3d(-sin(rotation + affinity), cos(rotation + affinity), 0. ) * .01);

raster->setApplyRotationFlag(true);

// creates Raster Frame element
OdDgRasterFramePtr pRasterFrame = OdDgRasterFrame::createObject();

m_pModel3d->addElement(pRasterFrame);// add Raster Frame element to database

pRasterFrame->setRasterReferenceId(raster->id());
// binds Raster Reference element with the specific Raster Reference element

// sets graphic element properties…
pRasterFrame->setColorIndex(5);
pRasterFrame->setLineStyleEntryId(2);
pRasterFrame->setLineWeight(2);
pRasterFrame->setPrintableFlag(true);

pRasterFrame->setTintColorIndex(1536);
pRasterFrame->setForegroundColorIndex(1536);
pRasterFrame->setBackgroundColorIndex(2032);
pRasterFrame->setHighlightColorIndex(0);

// sets a valid file name. Raster Reference element data will be synchronized
pRasterFrame->setFileName(OdString("attach.jpg"));
OdString sFileNameRasteReferense = raster->getFilename();
OdString sFileNameRasterFrame = pRasterFrame->getFileName();
// you can compare sFileNameRasteReferense and sFileNameRasterFrame.
// They are obliged to be equal.