In a database, layers are stored as layer table records in the layer table. By default the layer table contains one record, layer 0. To create a new layer, create a new OdDbLayerTableRecord object and put it in the OdDbLayerTable object. Note that the layer name must be set before it's added to the layer table.
OdDbLayerTablePtr pLayers = pDb->getLayerTableId().safeOpenObject(OdDb::kForWrite);
OdDbLayerTableRecordPtr pLayer = OdDbLayerTableRecord::createObject();
pLayer->setName("My Layer");
OdDbObjectId layerId = pLayers->add(pLayer);
The OdDbLayerTableRecord class provides methods for accessing a set of layer properties that affect the display of their associated entities. Here is the list with examples of properties and methods to access them:
void OdDbLayerTableRecord::setIsOff(bool off);
bool OdDbLayerTableRecord::isOff() const;
void OdDbLayerTableRecord::setIsFrozen(bool frozen);
bool OdDbLayerTableRecord::isFrozen() const;
void OdDbLayerTableRecord::setIsLocked(bool locked);
bool OdDbLayerTableRecord::isLocked() const;
Each layer also controls the properties of entities on that layer that are set to the ByLayer value. When an entity is drawn, it can use the linetype, lineweight, material, color, and transparency of the associated layer table record.
OdCmColor OdDbLayerTableRecord::color() const;
void OdDbLayerTableRecord::setColor(const OdCmColor &color);
void OdDbLayerTableRecord::setLinetypeObjectId(OdDbObjectId linetypeId);
OdDbObjectId OdDbLayerTableRecord::linetypeObjectId() const;
For iterating through layer table records, the mechanism of iterators is used (see also Accessing Database Objects). Use OdDbSymbolTableIterator objects for bidirectional traversing between records within the layer table. For example, to get information about each layer (where pLayers is a smart pointer for the Layer Table object).
The following function illustrates how to access records from the layer table and get information about each layer.
void dumpLayers(OdDbDatabase* pDb)
{
/**********************************************************************/
/* Get a SmartPointer to the LayerTable */
/**********************************************************************/
OdDbLayerTablePtr pTable = pDb->getLayerTableId().safeOpenObject();
/**********************************************************************/
/* Get a SmartPointer to a new SymbolTableIterator */
/**********************************************************************/
OdDbSymbolTableIteratorPtr pIter = pLayers->newIterator();
/**********************************************************************/
/* Step through the LayerTable */
/**********************************************************************/
for (pIter->start(); !pIter->done(); pIter->step())
{
/********************************************************************/
/* Open the LayerTableRecord for Reading */
/********************************************************************/
OdDbLayerTableRecordPtr pRecord = pIter->getRecordId().safeOpenObject();
/********************************************************************/
/* Dump the LayerTableRecord */
/********************************************************************/
printf("Name: %ls\n", toString(pRecord->getName()).c_str());
printf("On: %ls\n", toString(!pRecord->isOff()).c_str());
printf("Locked: %ls\n", toString(pRecord->isLocked()).c_str());
printf("Color: %ls\n", toString(pRecord->color()).c_str());
printf("Linetype: %ls\n", toString(pRecord->linetypeObjectId()).c_str());
printf("\n");
}
}
See Creating Layers topic to get an example of creating layers procedure.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|