A line is a parametric entity that specifies a straight segment in world space. The OdDbLine class is a line object that represents the interface for accessing a line entity and manipulating its properties. The OdDbLinePtr class is the typified smart pointer to an instance of the line entity and is used for storing and passing references to the line object.
To create an instance of the line object, use the createObject() method of the OdDbLine class that is the static pseudo-constructor. For example:
OdDbLinePtr pLine = OdDbLine::createObject();
The pseudo-constructor initializes the properties of a new instance using default values. After creating, the new instance must be added in model space, paper space, or a block using the appendOdDbEntity() method. The database associates the object ID with the line instance. In examples, the pDb variable stores a pointer to the database object. For example:
// Add in the block
OdDbBlockTablePtr pBlocks = pDb->getBlockTableId().safeOpenObject(OdDb::kForRead);
OdDbBlockTableRecordPtr pBlock = pBlocks->getAt(L"BLOCK", OdDb::kForWrite)
OdDbObjectId idLine = pBlock->appendOdDbEntity(pLine);
// Add in the model space
OdDbBlockTableRecordPtr pModel = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite);
pModel->appendOdDbEntity(pLine);
// Add in the paper space
OdDbBlockTableRecordPtr pPaper = pDb->getPaperSpaceId().safeOpenObject(OdDb::kForWrite);
pPaper->appendOdDbEntity(pLine);
The OdDbLine class is derived from the OdDbCurve class and inherits the common properties of parametric curves. The OdDbCurve class is derived from the OdDbEntity class, therefore the OdDbLine class also inherits the general properties of entities. A pointer to a line object can be converted to an entity object or a curve object. For example:
OdDbEntityPtr pEntity = pLine;
OdDbCurvePtr pCurve = pLine;
The line object has the AcDbLine class name. To verify an instance, use the isKindOf() and desc() methods. For example:
// Accurate comparing
if(pEntity->isA() == OdDbLine::desc())
odPrintConsoleString(L"\nEntity is the line");
// Check on belonging
if(pEntity->isKindOf(OdDbLine::desc()))
odPrintConsoleString(L"\nEntity is derived from the line object");
Example of Working with the Line Object
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|