Is it possible to attach custom data to an AIS_InteractiveObject?

I would like to store some custom data (eg. a void* - Pointer) within an AIS_InteractiveObject. Does anyone of you know of a way to do this without instantiating a derived class?

Marco Balen's picture

Hello,

You can use the methods GetOwner,HasOwner,SetOwner of the AIS_InteractiveObject class.
Using this methods you can bind data with an AIS_InteractiveObject. Pay attention to memory leak when you erase the AIS object.

Bye

Tilman Leune's picture

thx

Tilman Leune's picture

Hmm, but it doesn't work. I can only add another standard_transient as owner - maybe i will experiment wiht typecasts.

Marco Balen's picture

Sorry,

You have to use a standard_transient derived class.

I use a class like this :

.hxx

#pragma once

#include
#include
#include
#include

// Your class has to inherit MMgt_TShared or its descendant

DEFINE_STANDARD_HANDLE(CMyData,MMgt_TShared)

class CMyData : public MMgt_TShared
{
// Declare the methods of your class here
//...
public:
CMyData(void);
CMyData(........);
~CMyData(void);

.... add your member here ....

DEFINE_STANDARD_RTTI(CMyData)
};

.cpp

#include "StdAfx.h"
#include "mydata.hxx"

IMPLEMENT_STANDARD_HANDLE(CMyData,MMgt_TShared)

IMPLEMENT_STANDARD_RTTIEXT(CMyData,MMgt_TShared)

// Define the methods of your class here
//...
CMyData::CMyData(void)
{
.... assign your memeber here ...
}

CMyData::CMyData(....)
{
.... assign your memeber here ...
}

CMyData::~CMyData(void)
{
... free your member here
}

I hope this help you

By

Tilman Leune's picture

Thanks for the clarification. I still need to wrap my head around OCC being totally Object-oriented. I will try to implement this for my case and share my results

Roman Lygin's picture

In addition to using the Owner (which can be already used when using AIS via OCAF and/or during local selection - not sure, please double-check), you can always use a separate map.

typedef NCollection_DataMap ObjectDataMap;

...

ObjectDataMap aMap;

void* aData = ...;

aMap.Bind (anAISObject, aData);

Hope this helps.
Roman

Andrey Pozdeev's picture

Hi Roman,

Thanks for this gem, quite straightforward and insanely useful:

I was able to replicate using Qt as follows:

//Register a typedef with QString
typedef NCollection_DataMap ObjectDataMap;

//store reference to your map in your documentclass
ObjectDataMap myaismap;

1- during ais object creation
//right after creation of AIS_InteractiveObject add it to map
QString keyval = QString("object Id") + QString::number(id);
myaismap.Bind(AIS_OBJ,keyval);

2- during selection:
// get current AIS from selection
myContext->InitCurrent();
Handle_AIS_InteractiveObject Current = myContext->Current() ;

//request QString stored in map
QString id = this->myaismap.Find(Current);

Regards,

Alex