Problems processing selection

Hi,

I added selection processing to mouse click handler like this:

void OcctQtViewer::mousePressEvent(QMouseEvent* e) {
  QOpenGLWidget::mousePressEvent(e);
  const Graphic3d_Vec2i  aPnt(e->pos().x(), e->pos().y());
  const Aspect_VKeyFlags aFlags = qtMouseModifiers2VKeys(e->modifiers());

  if (!myView.IsNull()
    && UpdateMouseButtons(aPnt
                        , qtMouseButtons2VKeys(e->buttons())
                        , aFlags
                        , false)) {
     updateView();
     evaluateSelection();
     }
  }

and in evaluateSelection I process selection like this:

  myContext->InitSelected();
  while (myContext->MoreSelected())  {
        if (myContext->HasSelectedShape()) {
           TopoDS_Shape shape = myContext->SelectedShape();

           ...
           }
        myContext->NextSelected();
        }

Whenever I click on a shape which changes selection, myContext->MoreSelected() returns false so that no selection processing happens. I always need to click two times on the same shape to get the desired result.

What am I missing?

Kirill Gavrilov's picture

AIS_ViewController::UpdateMouseButtons() doesn't handle selection immediately; instead it queues the click event to the buffer to be processed when 3D Viewer will be redrawn next time. QOpenGLWidget::update() does the similar thing - it doesn't redraw 3D Viewer immediately, but queues the update event to be processed later.

When clicking actually happen, controller calls virtual method AIS_ViewController::OnSelectionChanged(), which you may override to process selection.

DjangoReinhard's picture

Yes, that did the trick. Thank you very much!