How to receive notification of a selection change?

Hi, 

In my application, when a user selects an AIS_Object in the viewer, I would like to highlight a corresponding node in aTreeView gui control elsewhere in the UI. 

How can I receive notification that the user has selected (or deselected) and object in the viewer so that I can take external action (e.g. select a treeview node)?

I searched the forums for terms like 'selection notification', 'selection callback', 'selection event' but didn't find anything.

Thanks,

-Eric.

Anton Shabalin's picture

Hello,

This should be the application-side event. For example, when user clicks on the OCCT context window you should find out which object was selected and then call a callback function or emit signal.

Eric Brandt's picture

Thanks for the reply, Anton. I'm not sure I fully understand your answer.

Do you mean that in my Windows app, I should add code to the 'OnMouseLButtonUp' event/message handler on the OCCT Window to check OCCT for what the selection state of all the entities are in the scene? This seems like a lot of processing to do every time the user releases the mouse button.

Perhaps I am missing some detail of your suggestion? 

Are you aware of any sample code you could refer me to that does selection checking in this manner?

Thanks! -Eric.

Anton Shabalin's picture

Hi,

It is exactly what I mean. For example, when user clicks, you need to take current cursor position and pass it to OCCT context as follows:

occtContext->MoveTo(cursorX, cursorY, occtView);
occtContext->Select();

Or like this:

occtContext->Select(cursorX, cursorY, endpointX, endpointY, occtView);

And then you can get selected objects:

    for (occtContext->InitSelected(); occtContext->MoreSelected(); occtContext->NextSelected()) 
    {
        Handle(AIS_InteractiveObject) selected = occtContext->SelectedInteractive();
    }

And now you can call your callback function if there are selected objects

Eric Brandt's picture

Thank you! I appreciate the quick and clear response.

-Eric.