
Mon, 02/21/2005 - 18:17
Forums:
I've made a new MyAISObject object by deriving it from AIS_InteractiveObject and everything works fine.
Now I would like to recognize it into a list of interactive objects, but of course the IsKind() routine is only able to recognize if the object is of AIS_InteractiveObject type, not MyAISObject.
What should I do to detect the type of derived objects?
Thanks in advance.
Tue, 02/22/2005 - 23:04
Hi Fabio,
To take advantage of RTTI and safe typecast features of OCC handles you need to correctly define your type.
In your .hxx:
#include
…
DEFINE_STANDARD_HANDLE(MyAISObject, AIS_InteractiveObject)
class MyAISObject : public AIS_InteractiveObject {
…
public:
DEFINE_STANDARD_RTTI(MyAISObject)
}
In implementation .cxx:
IMPLEMENT_STANDARD_HANDLE(MyAISObject,AIS_InteractiveObject)
IMPLEMENT_STANDARD_RTTIEXT(MyAISObject,AIS_InteractiveObject)
Now you should be able to use standard RTTI and typecast:
if (anObj->IsKind (STANDARD_TYPE (MyAISObject )) {
Handle (MyAISObject) aMyObj = Handle (MyAISObject)::DownCast (anObj);
…
}
If you use WOK and CDL, it does everything for you.
Hope this helps.
Roman
Wed, 02/23/2005 - 10:53
many thanks Roman,
actually I've figured it out yesterday but forgot to self-reply:
I've seen this done on the Geometry example.
Thanks for your interest: now I know I've made it the right way.