Search code examples
c++opencascade

How to detect selection of shapes in OpenCASCADE?


I am using OPENCASCADE 3D library together with Qt. I have set up 3D display, and displayed several items of TopoDS_Shape in a window, using calls to AIS_InteractiveContext::Display method. Now I'd like to have some event processing when user picks a shape on 3D display.

I have checked documentation to AIS_InteractiveContext ( https://dev.opencascade.org/doc/refman/html/class_a_i_s___interactive_context.html ). There is a way to query items in 3D view. But it can only QUERY the selection:

  1. SelectedShape method (https://dev.opencascade.org/doc/refman/html/class_a_i_s___interactive_context.html#ac7879e85fade79a71e4f543a154763ff)
  2. IsSelected method for graphical representation
  3. Selection method

Constantly querying AIS_Interactive context for selection changes is not a way.

Is there any way to setup callback in opencascade when selection was changed?


Solution

  • No, you should react on mouse clicks or key strokes to check whether the user wants to select something.

    There is an Open CASCADE Qt sample called "Tutorial", you might want to check it. In the file ".../samples/qt/Common/src/View.cxx" you can find a sample implementation.