The non-COM properties mechanism provides access to object properties at runtime for reading and modification in end-user applications. Unlike the legacy mechanism that uses COM technology, the non-COM properties mechanism is cross-platform. It is recommended for use in newly developed objects, although the legacy mechanism also remains supported by the ODA platform.
From the user's point of view, a property is a value associated with an object that is accessible by name at runtime.
The non-COM properties mechanism is an extension of the ODA Kernel runtime system. This mechanism allows you to describe properties of objects in a platform-independent way in order to make them accessible from end-user applications.
The non-COM properties mechanism is represented by the following set of classes and structures:
OdRxPropertyBase
OdRxProperty
OdRxMethod
OdRxValue
OdRxValueType
OdRxAttribute
OdRxFacetProvider structure
OdRxClass (Facet)
The implementation of the non-COM properties mechanism is located in the RxProperties module.
To list properties of a given object, use an iterator. To get an iterator for
object properties, call the
OdRxMemberQueryEngine::theEngine()->newMemberIterator()
method.
Each member returned by the iterator can be either
an OdRxPropertyBase
or OdRxMethod
object.
odrxDynamicLinker()->loadModule(RxPropertiesModuleName);
OdRxMemberPtr testCat = OdRxCategory::createObject(L"test", OdRxCategory::rootCategory());
OdRxMemberIteratorPtr pIterator = OdRxMemberQueryEngine::theEngine()->newMemberIterator(testCat);
while (!pIterator->done())
{
OdRxMemberPtr pMember = pIterator->current();
...
pIterator->next();
}
You can also find a known property by its name using the
OdRxMemberQueryEngine::find()
function.
OdRxMemberPtr pMember = pIterator->find(L"ClassName");
The OdRxValue
class is an instance of the
OdRxValueType
metaclass and is registered in the class
dictionary. The metaclass can contain information about the type such as the
enumeration members list for enumerated types. All common C++ types such as
int
and double
are registered automatically. You can
register your own types.
For more information about the variant type system, see the following header files:
Kernel/Include/RxValueType.h
Kernel/Include/RxValueTypeUtil.h
The OdRxProperty
object is a single value property object, and it
returns OdRxValue
via the getValue()
method.
OdRxValue
is a generic variant type; it can contain any C++ type
if the corresponding metaclass was declared. The contained C++ type is accessed
with a free template function rxvalue_cast<>()
.
OdRxValue value;
if (eOk == OdRxPropertyPtr(pMember)->getValue(testCat, value))
{
OdString s = *rxvalue_cast< OdString >(&value);
}
The value of the property can be set via the setValue()
method.
OdRxPropertyPtr pProperty = OdRxMemberQueryEngine::theEngine()->find(testCat, L"LocalizedName");
pProperty->setValue(testCat, OdRxValue(L"Category"));
There are also several collection types for properties, like
OdRxCollectionProperty
,
OdRxIndexedProperty
, OdRxDictionaryProperty
, etc.
(see RxProperty.h
for details).
To get values from collection properties, use the value iterator instead of
the getValue()
method.
OdDbBlockTablePtr bt = pDb->getBlockTableId().safeOpenObject();
OdRxCollectionPropertyPtr pCollectionProperty = OdRxMemberQueryEngine::theEngine()->find(bt, L"Items");
OdRxValueIteratorPtr pIterator = pCollectionProperty->newValueIterator(bt);
while (!pIterator->done())
{
OdRxValue value = pIterator->current();
...
pIterator->next();
}
Additional information about a property can be provided by the attributes
attached to it (OdRxMember::attributes
).
Attributes usage and interpretation is up to the end-user application.
Attributes are identified by the type; there can be only one attribute attached of a
given type.
Code sample below illustrates how to add attributes to the property of an
dbTable
object that determines the flow direction of table
elements.
OdRxMemberPtr pProperty = OdRxMember::createObject();
pProperty->attributes().add(OdRxDescriptionAttribute::createObject(L"Determines the direction that parts of the table flow."));
pProperty->attributes().add(OdRxCOMAttribute::createObject(L"TableBreakFlowDirection"));
See the list of existing attribute types in RxAttribute.h
.
There are several ways to provide non-COM properties for the class:
OdRxMemberCollectionConstructorPtr
parameter for the
newOdRxClass()
class registration function.
odrxSetMemberConstructor()
global function.
OdRxMemberQueryEngine::addFacetProvider()
function to set the
interface to extend a class with additional methods or properties.
For examples of Drawings SDK object properties, see header files in
Drawing/Extensions/DbProperties
.
odrxSetMemberConstructor Function
OdRxMemberQueryEngine::addFacetProvider Function
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|