Hide menu
Loading...
Searching...
No Matches
Properties

Properties are meta data, which can be attached to any graph element or a sub-shape in ModelData_BRepRepresentation.

Properties are represented in the form tables encapsulated by ModelData_PropertyTable. The property table contains a list of pairs {property_name, property_value}. A property name is defined with a Unicode string (Base_UTF16String) and value can have any of the following types:

Type C++ Type Example
32 bit integer I32 25
64 bit integer I64 8589934590
float float -0.2
double double 1.34e-16
timestamp time_t 1437980561 (July 27, 2015 11:02am)
String (Ascii or Unicode) Base_UTF16String "ABC123", "© 2015"
3D point BaseGeom_Point {1.2 3.4 -5.6}
3D box BaseGeom_Box {-1.2 3.4 -5.6} {2.34 5.8 3.1}

The following example demonstrates creation and attachment of properties:

ModelData_PropertyTable aPT;
aPT.Add ("id", 25); //integer property
UTF16 aString[] = {0x00A9, 0x0032, 0x0030, 0x0031, 0x0035, 0x0000};//(c) 2015
aPT.Add ("copyright", aString); //string property
time_t aTime;
time (&aTime);
aPT.Add ("creation time", ModelData_PropertyTable::TimeType (aTime)); //timestamp property
aPart.AddProperties (aPT);
U16 UTF16
Defines a type of character when using UTF-16 encoding.
Definition: Base_TypeDef.hxx:64

Traversal over properties

The properties can be traversed with the help of visitors as demonstrated in the example below:

class PropertyTableVisitor : public ModelData_PropertyTable::Visitor
{
public:
virtual void operator() (const Base_UTF16String& theName, I32 theValue) override
{
//visiting integer property...
}
virtual void operator() (const Base_UTF16String& theName, float theValue) override
{
//visiting float property...
}
...
};
ModelData_PropertyTable aPT = aSGE.Properties();
if (aPT) {
PropertyTableVisitor aVisitor;
aPT.Accept (aVisitor);
}

ModelData_PropertyTable::VoidVisitor is a convenience class which provides empty implementation for each supported value type. Thus, it allows to only define methods for required types:

class StringItemVisitor : public ModelData_PropertyTable::VoidVisitor
{
public:
virtual void operator() (const Base_UTF16String& theName, const Base_UTF16String& theValue) override
{
//visiting string property...
}
};
aPT.Accept (StringItemVisitor());

A specific property item can be retrieved using the FindProperty() item for a required value type, for example:

Base_UTF16String aValue;
if (aPT.FindProperty ("author", aValue)) {
//found the 'author' item with string value
}

ModelData_PropertyTable::HasProperty() allows to quickly check if the property item has been registered.

Validation properties

The data model allows to attach specific properties called "validation properties". These properties allow to exchange data between CAD systems in order to verify correctness of the conversion and compare properties in the sending and receiving systems. These properties include:

  • volume;
  • surface area;
  • center of gravity;
  • bounding box.

When importing from or exporting to formats which support validation properties (e.g. STEP or JT) validation properties are converted from / to specific entities as prescribed by the format.

Validation properties are stored in the property table using reserved names. These names are used to recognize and distinguish them from user-defined properties and therefore may not be used for any other properties.

The following table describes names and expected value types for the validation properties:

Validation property Reserved name String C++ Type
Surface area ModelData_PropertyTable::SurfaceAreaPropertyName() "CADEX_SURFACE_AREA" double
Volume ModelData_PropertyTable::VolumePropertyName() "CADEX_VOLUME" double
Center of gravity ModelData_PropertyTable::CentroidPropertyName() "CADEX_CENTROID" BaseGeom_Point
Bounding box ModelData_PropertyTable::BoundingBoxPropertyName() "CADEX_BOUNDING_BOX" BaseGeom_Box

The following example demonstrates how to recognize a validation property:

class PropertyTableVisitor : public ModelData_PropertyTable::Visitor
{
public:
...
virtual void operator() (const Base_UTF16String& theName, double theValue) override
{
if (theName == ModelData_PropertyTable::VolumePropertyName()) {
//volume
} else if (theName == ModelData_PropertyTable::SurfaceAreaPropertyName()) {
//surface area
} else {
//general case
}
}
...
};

Validation properties must be specified in the model units (linear, square or cubic).

See also
Measurements.