Using Compound .dgn Line Styles in a .dwg File (Part 1 of 2)

Andrew Markovich

April 04, 2019

Introduction

This is last series of articles about creating complex .dgn line styles in a .dwg database. We will use our knowledge about creating DGN line styles that was described in previous articles and create a final compound line style that invokes all previously created line style components. Here are the previous articles for reference:

 

 

Creating compound components

Compound line style components can be used to join two or more line style components inside a single complex line style. We can append existing stroke pattern, internal, point and other compound components inside the newly created compound component, set up offsets between them, and they will be drawn together as one single complex line style. In terms of a .dwg database, compound line style components provide similar capabilities as OdDbMline entity functionality, but DGN line styles provide many additional features.

To start working with compound components, include the header with OdDbLSCompoundComponent class declaration:


#include "DgnLS/DbLSCompoundComponent.h"

But first we need the object IDs of other existing components that we will append to our newly created compound component. Here we will use existing components described in previous articles, so we can invoke functions that already exist:


// Declare commands from previous articles.
void _CreateDgnLineStyle_Stroke_func(OdEdCommandContext* pCmdCtx);
void _CreateDgnLineStyle_Internal_func(OdEdCommandContext* pCmdCtx);
void _CreateDgnLineStyle_Point_func(OdEdCommandContext* pCmdCtx);

And simply call them to populate the stroke pattern, internal, and point components into a .dwg database:


// Create stroke, internal and point components
_CreateDgnLineStyle_Stroke_func(pCmdCtx);
_CreateDgnLineStyle_Internal_func(pCmdCtx);
_CreateDgnLineStyle_Point_func(pCmdCtx);

Calling these functions populates the following list of components into a DGN line styles dictionary:

 

image0

 

And since we did not remove test code from these functions that create OdDbLine entities with demonstration linetypes, we see three lines with different line styles in the same position:

 

image1

 

This is not a compound line style, of course. We can erase these lines; they are not required for future operations.

Now we can extract the object IDs of the previously created components:


OdDbDictionaryPtr pLsDict = ::oddbDgnLSGetComponentsDictionary(pDb, OdDb::kForRead);
OdDbObjectId strokeCompId = pLsDict->getAt(OD_T("DemoDgnLineStyleStrokeComponent"));
OdDbObjectId internalCompId = pLsDict->getAt(OD_T("DemoDgnLineStyleInternalComponent"));
OdDbObjectId pointCompId = pLsDict->getAt(OD_T("DemoDgnPointComponent"));
OdDbObjectId pointStrokeCompId = pLsDict->getAt(OD_T("DemoDgnLineStyleStrokeComponentForPointComponent"));

"DemoDgnLineStyleStrokeComponent" was created by the _CreateDgnLineStyle_Stroke_func() function call. "DemoDgnLineStyleInternalComponent" were created by the _CreateDgnLineStyle_Internal_func() function call. "DemoDgnPointComponent" and "DemoDgnLineStyleStrokeComponentForPointComponent" was created by the _CreateDgnLineStyle_Point_func() function call.

Now we can create the compound component itself. Creation of compound components is very similar to creation of other DGN line style components:


// We need GUID for DgnLS objects
OdUInt8 dgnLS_UID[16];
::oddbDgnLSInitializeImportUID(dgnLS_UID);

// Create Compound LineStyle Component
OdDbLSCompoundComponentPtr pCompComponent = OdDbLSCompoundComponent::createObject();
pCompComponent->setComponentType(kLSCompoundComponent);
pCompComponent->setComponentUID(dgnLS_UID);

After compound component creation, we can append the object IDs of the four existing line style components to it:


// Append compound component sub-components
pCompComponent->appendComponent(pointStrokeCompId);
pCompComponent->appendComponent(pointCompId);
pCompComponent->appendComponent(strokeCompId, -0.005);
pCompComponent->appendComponent(internalCompId, 0.005);

In this code we added point stroke pattern and point components without an offset. Stroke pattern and internal components were added with 0.005 offset on different sides.

Finally we can attach the created compound component to the DGN line styles dictionary:


// Add component into LineStyles dictionary
pLsDict->upgradeOpen();
pLsDict->setAt(OD_T("DemoDgnLineStyleCompoundComponent"), pCompComponent);

The code used to create a line style definition and .dwg linetype table record is very similar to code from previous articles:


// Create LineStyle Definition
  OdDbLSDefinitionPtr pLSDef = OdDbLSDefinition::createObject();
  pLSDef->setComponent(pCompComponent->objectId());
  pLSDef->setComponentUID(pCompComponent->componentUID());

  // Create Linetype Table Record
  OdDbLinetypeTableRecordPtr pLtpRec = OdDbLinetypeTableRecord::createObject();
  pLtpRec->setName(OD_T("DemoDgnLineStyleCompound"));
  pLtpRec->setComments(OD_T("Compound component"));
  OdDbObjectId lsId = OdDbLinetypeTable::cast(pDb->getLinetypeTableId().safeOpenObject(OdDb::kForWrite))->add(pLtpRec);
  // Attach LineStyle Definition to Linetype Table Record
  pLtpRec->createExtensionDictionary();
  OdDbDictionaryPtr pLtpDict = OdDbDictionary::cast(pLtpRec->extensionDictionary().openObject(OdDb::kForWrite));
  pLtpDict->setAt(::oddbDgnLSGetDefinitionKeyName(), pLSDef);

And we can populate some OdDbLine entities:


// Create three lines for LineStyle testing
  OdDbObjectId lineIds[3];
  for (int nLine = 0; nLine < 3; nLine++)
  {
    OdDbLinePtr pLine = OdDbLine::createObject();
    pLine->setDatabaseDefaults(pDb);
    pLine->setLinetype(lsId);
    pLine->setStartPoint(OdGePoint3d(1.1, 0.03 - 0.03 * nLine, 0.0));
    pLine->setEndPoint(OdGePoint3d(1.2, 0.03 - 0.03 * nLine, 0.0));
    lineIds[nLine] = OdDbBlockTableRecord::cast(pDb->getActiveLayoutBTRId().safeOpenObject(OdDb::kForWrite))->appendOdDbEntity(pLine);
  }

The final picture created by the described code looks like the following:

 

image2

 

Consider the created compound line style closer:

 

image3

 

Here we can see the internal component on the first row of the line style (offset 0.005), point and point stroke pattern components in the center, and the stroke pattern component with widths on one of the dash segments on the last row of the line style (offset -0.005). Actually, the sides of the line style components, which are added to the compound component, depend on the curve direction. In our demonstration we created a line that goes from left to right, so finally we have shown line style component order.

The next article in this series describes line style modifiers that can be applied to specific entities.