Highlight without Select the object


I want to make a dynamic selection, where the user see the shapes highlighted when hovering them with the cursor, and after clicking on them they will be selected and shown highlighted (as in 3d CAD software).

Currently to highlight an object or parts of it, I open a localContext and set the selectionMode for it, and I use moveto() and Select() in the mouseMove event in Qt.

The problem with this approach is that it selects the object (and prevents me from selecting others), I want it just to highlight it. So I can use select() in the click() event.

Any idea?

mfregeau's picture

I'd like to do the same as well. I believe with OC 7.2 there is no more need for localContext

Benjamin Bihler's picture

I do it like this:

Handle(TPrsStd_AISPresentation)& presentation = ...

Handle(AIS_InteractiveObject)& interactiveObject = presentation->GetAIS();

                interactiveContext->HighlightStyle(), Standard_False);



mfregeau's picture

Don't you have to test if presentation->GetAIS() returns a valid object? Otherwise HilightWithColor with null object would crash..

liuhuliuhu123's picture

I use GetAIS(), it return NULL.But,why ?

mfregeau's picture

also how do you get the handle for the object your mouse is hovering over? Can you complete that line of code of yours:

"Handle(TPrsStd_AISPresentation)& presentation = ..."

mfregeau's picture

I got it to hilight on mouse hover:

First when you create the myContext, you have to specify which type of geometry would be detected (you can activate more than one):

mContext->Activate(TopAbs_FACE, Standard_False );

Then inside the mousemove event:

mContext->MoveTo(point.x,point.y,mView,Standard_False);//this is needed so the context is aware of where the mouse is

if (mContext->HasDetected() == Standard_True){

//do something with the detected shape if you want, but it will hilight anyway


mView->Redraw(); //to make sure it hilight right away

jason jiang's picture

As Hightlight the object,my question is ,if I import a step file and parse the Face,Wire,Edge,Vertext and put them into a TreeCtrl,while I click the Item of TreeCtrl,the chosed object hightlight show by different color.
Do you have any suggestion?could you give me the C++ code to do it?