identifying TDF_Attribute subclasses

How do I identify the class of a TDF_Attribute object read from a general OCAF document, where I don't have any prior knowledge of the document structure? I only need to deal with the attribute types built in to OCC.

I can get it's GUID easily enough, but I need to cast the handle to the appropriate underlying class? Is there a registry of TDF_Attribute types I can iterate over, to test against? Or maybe an easier method?

Roman Lygin's picture

You can exploit at least two approaches. First is based on GUIDs() (what makes it difficult for you to get it, by the way ?):

Handle(TDF_Attribute) anAttr = ...;
if (anAttr->ID() == MyAttribute::GetID()) {
Handle(MyAttribute) aMyAttr = Handle(MyAttribute)::DownCast (anAttr);

Second is based on rtti offered by Handles:

if (anAttr->IsKind (STANDARD_TYPE (MyAttribute))) {
Handle(MyAttribute) aMyAttr = Handle(MyAttribute)::DownCast (anAttr);

And of course, there is always a standard way

Handle(MyAttr) aMyAttr;
if (aLab.FindAttribute (MyAttr::GetID(), MyAttr)) {

Hope this helps.
--- - the Open CASCADE blog - CAD Exchanger, your 3D data translator

jelle's picture

I think Bryan is using pythonOCC and some of the C++ idioms can be non-intuitive to map in Python.
I think this helps a lot though ( does it Bryan? )