Link InteractiveObject to user data structure

Hello,

I'd need to have some sort of link from an AIS_InteractiveObject (for example, after selecting on screen)
and an underlying data I store elsewhere. It would be enough to have an user integer field
usable as an array index, but I see no one.... Just the Owner field, which is a transient pointer.
Is there a way to store and retrieve some sort of index when creating an interactive object ?
I know I could create a Map, but imho searching into the map using Interactive Object as key would be
by far slower.

Max

AP's picture

sub class AIS_InteractiveObject and add the private member string called Object_Name

before displaying the object, create the custom data and store it in a map using as key the objectname you assigned to the AIS_object.

when you select, dynamic cast the selection object to your subclass of the AIS object, retreive the Object_Name and then get the custom data from the map searching by Key.

example of getting only the subclass object type from the selection

// define your subclass of AIS_Shape i.e: callit AIS_NamedObject

const Handle(AIS_InteractiveContext)& ic

Handle(TopTools_HSequenceOfShape) aSequence;
Handle(AIS_InteractiveObject) picked;
for ( ic->InitCurrent(); ic->MoreCurrent(); ic->NextCurrent() )
{
Handle(AIS_InteractiveObject) obj = ic->Current();
if ( obj->IsKind( STANDARD_TYPE( AIS_NamedObject ) ) )
{
AIS_NamedObject currentnamed = Handle_AIS_NamedObject::DownCast(obj);
QString myname = currentnamed.ObjectName;

}
}

Best,

AlexP

AP's picture

Alternatively you can map the custom data and search the map for the custom data based on the selected object key like you suggested.

Best,

AlexP

Massimo Del Fedele's picture

Hi AlexP,

thank you for answering :-)
My need is as usual to keep a database of objects and to gather "quickly" the geometry object from the
interactive one. I'm not using OCAF, btw.
I'm storing the geometry objects in an Array, accessible by index; so, it would be enough an index inside
interactive object for fast access to geometry data.
Using a map (any kind...) seems to me overkilling, as to have to subclass each interactive object just to
embed an integer index to it.
As it seems to me that there's no such a thing like "user field" inside Interactive object, I was thinking
about making a couple of Transient_Integer and Handle_Transient_Integer (if it's not already inside foundation classes....) and store it inside Owner field of interactive object.... a bit overkilling too, and
encompasses another handle de-referencing, but I guess it would do the job.
The question now is.... It's Owner field usable for this purpose, or OpenCascade make use of it in some
way that make my workaround not working ?
The idea is :
interactive->Owner() ---> geometry_index ---> geometry_data
That one would spare a search in a possibly quite big map.

Ciao

Max

Gianluca Antoniacci's picture

Ciao Massimo,

actually I'm currently using Owner field as you are suggesting, saving a TCollection_HExtendedString inside it. If I well remember, this field is used for some hilight/selectin mechanism and assigning an integer value would result in some unwanted selection of an AIS_InteractiveObject when selecting another one (it happened to me). Using a string you can easily convert it to an integer value and the other way around. 

jason jiang's picture

Hi,
If I have got an object such as Face,wire,edge,vertex ect,What is the way to transfer these object into AIS_InteractiveObject?if it is done,I want to hightlight show this object by different color.
thanks
Jason.Jiang