I just needed to solve the same problem. Here is the solution that I came up with. It requires that you have an open local context. When first displaying an AIS_InteractiveObject in a local context, use the aSelectionMode input argument (the third input argument) of the AIS_InteractiveContext::Display(...) method to disable selection (0 is the default value and -1 disables selection).
ais_context->OpenLocalContext();
ais_context_->Display(ais_object_one,0, -1); // selection disabled for ais_object_one
ais_context_->Display(ais_object_two,0, 0); // selection enabled for ais_object_two
The above method only works if the AIS_InteractiveObject is not currently being displayed in the current local context. If it is already being displayed, the following code will work to disable selection and redisplay the AIS_InteractiveObject (this may not be the best way to accomplish this but it works).
ais_context_->Remove(ais_object_one); // need to remove ais object first if it is already being displayed
ais_context_->Display(ais_object_one,0, -1); // redisplay ais object, this time disabling selection
ais_context_->Redisplay(ais_object_one); // call to Redisplay(...) necessary to make ais object visible again
It's not intuitive to me why, in the second example, the call to Redisplay(...) is needed but the AIS_InteractiveObject ends up being invisible if I don't include it.
Here's the documentation for the relevant AIS_InteractiveContext::Display(...) method:
Standard_EXPORT void Display (const Handle(AIS_InteractiveObject)&anIobj, const Standard_Integer amode, const Standard_Integer aSelectionMode, const Standard_Boolean updateviewer=Standard_True, const Standard_Boolean allowdecomposition=Standard_True)
Controls the choice between the using the display
and selection modes of open local context which you
have defined and activating those available by default.
If no Local Context is opened. and the Interactive
Object aniobj has no display mode of its own, the
default display mode, 0, is used. Likewise, if aniobj
has no selection mode of its own, the default one, 0, is used.
If a local context is open and if updateviewer equals
Standard_False, the presentation of the Interactive
Object activates the selection mode; the object is
displayed but no viewer will be updated.
If aSelectionMode equals -1, anIobj will not be
activated: it will be displayed but will not be selectable.
Use this if you want to view the object in open local
context without selection. Note: This option is only
available in Local Context.
If allowDecomposition equals true, anIObj can have
subshapes detected by selection mechanisms. anIObj
must be able to give a shape selection modes which
fit the AIS_Shape selection modes:
- vertices: 1
- edges: 2
- wires: 3.
Hope this helps!
Regards,
Mike