Entities are objects that have a graphical representation, for example, lines, circles, text, etc. All entities are owned by blocks, which are represented in the database by OdDbBlockTableRecord objects.
The OdDbEntity class, which is the base class for all entities, is derived from the OdRxObject class and implements the smart pointer mechanism. To create an entity object of a specific class, call the createObject() method of the corresponding entity class and get a smart pointer for the object. For example, to create a line entity:
OdDbLinePtr pLine = OdDbLine::createObject();
Then use the created smart pointer object for performing operations with the entity.
Since all entities in the database belong to blocks, the created entity object must be appended to a block table record by the appendOdDbEntity() method of the corresponding OdDbBlockRecord object. It can be the Model Space or Paper Space blocks or another block. For example, to add a line to the Btr block:
pBtr->appendOdDbEntity(pLine);
After the entity object is added to the block table record, you can use it as a database object and use all methods and properties available for this entity.
The OdDbEntity class is the base class for all entities which defines the set of properties which are common for all entity types, such as:
These properties can be accessed by corresponding methods: color()/setColor(), layer()/setLayer(), linetype()/setLinetype(), and so on.
Some properties (color, linetype etc) can be applied for every entity that belongs to a specific block or resides in a specific layer; in this case use the ByBlock and ByLayer property values.
For example, if car body geometry defined in a block has the ByBlock color, a color of the referenced block reference is used and the same block can be used to represent cars of different colors. For entities residing in layout blocks (no corresponding block reference), default values are used. For example, color 7 is used for the ByBlock color.
If an entity property has the ByLayer value, the property from the layer is used. However, layer "0" is a special case. It is the "default" layer. If an entity is inside a non-Layout block, then layer "0" means "use block reference layer."
Besides common properties, each specific entity class has a set of properties which are specific for a particular entity type. For example, for a OdDbCircle object you can access center, radius, and other properties which define a circle.
The following example sets properties for the circle entity:
/***********************************************/
/* Sets the center of the circle. */
/***********************************************/
pCircle->setCenter(OdGePoint3d(2.0,0,0));
/***********************************************/
/* Sets the radius of the circle. */
/***********************************************/
pCircle->setRadius(2.0);
/***********************************************/
/* Sets the layer that circle belongs to. */
/***********************************************/
pCircle->setLayer(layerId, true);
/***********************************************/
/* Sets a circle color to the ByBlock value. */
/***********************************************/
pCircle->setColorIndex(OdCmColor::kACIbyBlock);
/***********************************************/
/* Sets a circle linetype to the ByLayer value.*/
/***********************************************/
pCircle->setLinetype(pDb->getLinetypeByLayerId());
The OdDbEntity class also provides a set of methods for determining and modifying entity objects.
For example, you can apply 3D transformations to an entity using the transformBy() method:
OdResult OdDbEntity::transformBy(const OdGeMatrix3d& xfm);
The transformations are defined by a transformation matrix, xfm. For example, the following line translates the entity by the specified offset:
pEnt->transformBy(OdGeMatrix3d::translation(offset));
If you need to create a modified copy of the entity, use the getTransformedCopy() method.
The explode() method breaks a complex entity into a set of simpler entities. For example, a multiline can be exploded into simple lines, a region into separate curves, and so on:
OdResult OdDbEntity::explode(OdRxObjectPtrArray& entitySet) const;
The method fills the entitySet array with a set of single entities without modifying the source entity. For example, to explode a multiline:
OdRxObjectPtrArray entitySet;
OdResult result = pMline->explode(entitySet);
See Creating Entities topic to get an example of creating entities.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|