Lock selection

How do I lock selection while I iterate over it?

Daniel Neander's picture

if (lockSelection) {
// Do nothing because we are processing the current information.
} else {
context->Select(true);
}

Does that work for you?

Billy's picture

Would like to lock the selection while I process application events. The things is by processing application events I let the user change the selection and it gives error. I don't know which command deactivates selection in OpenCASCADE.

Daniel Neander's picture

You don't necessarily have to deactivate the selection in OCC. Simply ignore the events from the GUI while a flag is set. Have a look at this snippet derived from view.cxx in Qt sample (note untested):

bool ignoreSelection = false;

void View::mousePressEvent( QMouseEvent* e )
{
if (ignoreSelection) {
e->ignore();
return;
}
if ( e->button() == Qt::LeftButton )
onLButtonDown( ( e->buttons() | e->modifiers() ), e->pos() );
else if ( e->button() == Qt::MidButton )
onMButtonDown( e->buttons() | e->modifiers(), e->pos() );
else if ( e->button() == Qt::RightButton )
onRButtonDown( e->buttons() | e->modifiers(), e->pos() );
}

void View::mouseReleaseEvent(QMouseEvent* e)
{
if (ignoreSelection) {
e->ignore();
return;
}
if ( e->button() == Qt::LeftButton )
onLButtonUp( e->buttons(), e->pos() );
else if ( e->button() == Qt::MidButton )
onMButtonUp( e->buttons(), e->pos() );
else if( e->button() == Qt::RightButton )
onRButtonUp( e->buttons(), e->pos() );
}

void View::mouseMoveEvent(QMouseEvent* e)
{
if (ignoreSelection) {
e->ignore();
return;
}
onMouseMove( e->buttons(), e->pos() );
}

void View::enableSelection(bool state)
{
ignoreSelection = state;
}

So you would use as follows:
view->enableSelection(false);
// process your application events
view->enableSelection(true);

Good luck