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 Wed, 02/17/2010 - 12:37
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.
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
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.
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);
Wed, 02/17/2010 - 12:37
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
Wed, 02/17/2010 - 18:58
thx
Wed, 02/17/2010 - 19:00
Hmm, but it doesn't work. I can only add another standard_transient as owner - maybe i will experiment wiht typecasts.
Thu, 02/18/2010 - 18:19
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
Fri, 02/19/2010 - 09:54
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
Fri, 02/19/2010 - 10:55
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
Wed, 07/02/2014 - 03:46
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