Turning OFF Selection of AIS_InteractiveObject or AIS_Point

Hello, colleagues! How can i temporarily switch off the selection of AIS_Point (or any other AIS_InteractiveObject derivation)? I've tried with AIS_InteractiveObject::SetSelectionPriority(-1) just to find that this method is not used anywhere in OCAS6.2. The selection priority is simply not taken in account anywhere. One solution is to override ComputeSelection but maybe there's a better solution?

Regards to everybody working with this sofisticated wonder - OpenCASCADE! :)

Michael Greminger's picture

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_->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!


Michael Greminger's picture

I knew there had to be a better way to disable selection for an already displayed ais object and I just found it! Use the AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)&anIObj) method to disable selection for an already displayed AIS_InteractiveObject. This approach works with or without an open local context. Similarly, use the AIS_InteractiveContext::Activate(...) method to enable selection for an AIS_InteractiveObject.


Svetlozar Kostadinov's picture

Thank You very much, Michael! I appreciate your help! I've tried your advice to use Activate/Deactivate and it is absolutely fine. If you like, we may collaborate and if you have any problems with OCAS, you're wellcome to write me a e-mail (svr start.bg). We are developing a simple 2D/3D-modelling application and maybe our help could be useful to you.

Sv. Kostadinov