A DirectShape element is a container for an external custom geometry that can be created as a result of:
BimRv SDK implements DirectShape functionality through the following classes:
OdBmDirectShapeType
is the class that provides an interface for storage of common information about DirectShape
objects of the same type:
setGeometryData()
,
setShape()
,
appendShape()
methods).
setPlanViewGeometryData()
)
setCategoryId()
method).
isValidShape()
methods).
OdBmDirectShape
is the class that implements the functionality of working with DirectShape data.
For creating a new DirectShape element, use the static method createElement()
that returns
a smart pointer to the created DirectShape element. Another way for creating a new DirectShape object
with predefined type, category and transformation matrix that defines its position is to call the
createElementInstance()
from a smart pointer returned by the createElement()
.
This method retrieves identifiers for type, category and an instance of the transformation matrix.
The type of the DirectShape element can also be specified with the setTypeId()
method.
Like the OdBmDirectShapeType
class, this class also contains methods for setting and validating geometry data:
setShape()
,
appendShape()
,
isValidGeometry()
and isValidShape()
.
For setting additional options for a DirectShape element, use the setOptions()
method.
OdBmDirectShapeOptions
is the class that allows to store and apply to a DirectShape element two options:
DirectShapeReferencingOption
enumeration(0 - NonReferenceable
, 1 - Referenceable
).
DirectShapeRoomBoundingOption
enumeration(0 - NotApplicable
, 1 - SetByParameter
).
OdBmDirectShapeDataCell
class stores metadata of the DirectShape element such as:
OdBmDirectShapeCell
class is used for storage of geometry information represented with an instance of
the OdBmGElement
class. To get geometry information, use the getGElement()
method,
to set new geometry to the element, call the setGElement()
method.
It is assumed in the code fragments below that the following variables are defined:
pDb
— A smart pointer to a BimRv database.
nodes
— An array of geometrical nodes that represents the element geometry.
The following step-by-step instruction illustrate how a simple DirectShape element can be created with a specific set of options:
OdBmDirectShape
class and add it to the database:
OdBmDirectShapePtr directShape = OdBmDirectShape::createObject();
OdBmObjectId retId = pDb->addElement(directShape);
addElement()
returns an identifier of the added object that can be used for checking the result of the operation.
If the element was successfully added to the database, assign it with a family that owns it:
OdBmGNodePtrArray nodes;
if (!retId.isNull())
{
directShape->setOwningElementId(pDb->getOwnerFamilyId());
directShape->setShape(nodes);
}
Call the setShape()
method to create shape from the array of geometrical nodes.
You can analyze the result of setting shape data through checking the value of the OdResult
data type that the method returns.
For additional illustration of the process of creating the array of geometrical nodes, please refer to the sample command "BmBrepMeshCmd"
that can be found in the TB_Commands
sample application allocated in the BimRv/Examples/TB_Commands
folder.
The _BmBrepMesh_func()
function that implements custom user command sequentally calls two functions, which are responsible for
creating geometry data:
createMeshOfGeometry()
.
createBrepOfMesh()
.
All the functions are defined in the BmBrepMeshCmd.cpp
source code file.
The following example source code illustrates creating a new DirectShape element, setting its parameters and applies graphical style to it.
Example assumes that there are two previously declared and defined variables:
OdBmDatabasePtr& pDb;
— Contains a smart pointer to a BimRv database that contains created DirectShape element.
OdInt32 nColor;
— Contains DirectShape element color value.
Besides it is assumed that a special structure, needed for encapsulated storing both category and graphical style identifiers for a new DirectShape element, is declared as well:
struct TCategoryIdAndGStyleId
{
OdBmObjectId nGStyleElem;
OdBmObjectId nCategoryElem;
};
The last prerequisite is the materialId
variable that stores the element material identifier.
The description of material element creation is omitted to make the code example simpler.
TCategoryIdAndGStyleId aElements;
aElements.nCategoryElem = pDb->addElement(OdBmCategoryElem::createObject());
aElements.nGStyleElem = pDb->addElement(OdBmGStyleElem::createObject());
OdBmObjectId oRootFamilyId = pDb->getOwnerFamilyId();
OdBmObjectId materialId;
OdGeExtents3d oBBox;
OdBmDirectShapeTypePtr pDirectShapeType = OdBmDirectShapeType::createObject();
OdBmObjectId directShapeTypeId = pDb->addElement(pDirectShapeType);
OdBmCategoryElemPtr pCategoryElem = aElements.nCategoryElem.safeOpenObject();
pCategoryElem->setOwningElementId(oRootFamilyId);
pCategoryElem->setFamId(oRootFamilyId);
// DesignOptionId. Header has -1 value but body has -4 value
pCategoryElem->setBaseDesignOptionId(pDb->getObjectId(-4));
OdBmCategoryPtr pCategory = OdBmCategory::createObject();
pCategory->setName("New_Category");
pCategory->setParentCategoryHandle(OdDbHandle(OdBm::BuiltInCategory::OST_GenericModel));
pCategory->setCategoryType(OdBm::CategoryType::Model);
pCategoryElem->setCategory(pCategory);
OdBmObjectIdArray aGStyleIds;
aGStyleIds.push_back(aElements.nGStyleElem);
pCategoryElem->setGStyleIds(aGStyleIds);
OdBmGStyleElemPtr pGStyleElem = aElements.nGStyleElem.safeOpenObject();
pGStyleElem->setOwningElementId(directShapeTypeId);
pGStyleElem->setOwnerId(directShapeTypeId);
pGStyleElem->setFamId(oRootFamilyId);
// DesignOptionId. Header has -1 value but body has -4 value
pGStyleElem->setBaseDesignOptionId(pDb->getObjectId(-4));
OdBmGStylePtr pGStyle = OdBmGStyle::createObject();
pGStyle->setPenNumber(1);
OdBmCmColor oColor;
oColor.setRGB(nColor);
pGStyle->setColor(oColor);
pGStyle->setLinePatternId(pDb->getObjectId(-3000010)); // solid line
pGStyle->setMaterialElemId(materialId);
pGStyleElem->setGStyle(pGStyle);
pGStyleElem->setGStyleType(1);
pGStyleElem->setGStyleCategoryId(aElements.nCategoryElem);
OdBmCategoryTrackingPtr pCatTracking = pDb->getAppInfo(OdBm::ManagerType::CategoryTracking);
pCatTracking->addCategoryDataItem(pDb->getObjectId(pCategory->getParentCategoryHandle()), aElements.nCategoryElem);
pGStyle = aElements.nGStyleElem.safeOpenObject();
pCatTracking->addGStyleDataItem(aElements.nCategoryElem, aElements.nGStyleElem, pGStyleElem->getGStyleType());
OdGeMatrix3d oTrf = OdGeMatrix3d::kIdentity;
oTrf.setTranslation(OdGeVector3d(-30.0, 0.0, 0.0));
OdGeExtents3d oBBoxTransformed = oBBox;
oBBoxTransformed.transformBy(oTrf);
OdBmObjectId directShapeId;
OdBmDirectShapePtr pDirectShape = OdBmDirectShape::createObject();
pDirectShape->setParam(pDb->getObjectId(OdBm::BuiltInParameter::PROJECT_ORGANIZATION_NAME), L"Open Design Alliance");
pDirectShape->setParam(pDb->getObjectId(OdBm::BuiltInParameter::IS_VISIBLE_PARAM), (OdInt32)1);
directShapeId = pDb->addElement(pDirectShape);
pDirectShape->createElementInstance(directShapeId, aElements.nCategoryElem, oTrf);
For additional information about working with DirectShape element, please see the Creating a "Dummy" Element
sample application located in the /BimRv/Examples/TB_ExCreateDummyObject
folder.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|