DiscussionsIssue archiveVisualization and 3D Viewer

Archived discussion

Handle(AIS_InteractiveContext) occtContext->NbSelected()

Visualization and 3D ViewerMon, 05/09/2022 - 03:232 replies

Browse this forum
QuestionAuthor
void MainWindow::mousePressEvent(QMouseEvent *e)
{
    qDebug() << occtContext->NbSelected();
}

qDebug() will only show NbSelected() for one selection before the last one. It seems to have a delay.

Does anyone know, what might it be ?

Thanks in advance,

Author

Discussion

2 archived replies

Posts are displayed in their archived order.

01Commenter-1

Your code snippet just prints some information on a mouse press event. If there no other code around performing actual selection, then selection should be always 0.

02Author

Thanks for your answer. You're absolutely right, there isn't enough information to support my last question. Sorry for that.
So, it goes like this ...

1. I create a shape, a cylinder for instance:

gp_Ax2 axes(gp_Pnt(0,0,0),gp_Dir(0,1,0));
double r = 50;
double h = 60;
double angle = M_PI*1.0;
TopoDS_Shape topo_cylinder = BRepPrimAPI_MakeCylinder(axes, r, h, angle);
ais_cylinder = new AIS_Shape(topo_cylinder);
myContext->Display(ais_cylinder, true);
myContext->SetDisplayMode(AIS_Shaded,true);
myView->FitAll();

2. Activate decomposition of shapes and apply filters:

const int aSubShapeSelMode = AIS_Shape::SelectionMode (TopAbs_FACE);
myContext->Activate (ais_cylinder, aSubShapeSelMode, false);

Handle(StdSelect_FaceFilter) aFil1 = new StdSelect_FaceFilter (StdSelect_AnyFace);
Handle(StdSelect_EdgeFilter) aFil2 = new StdSelect_EdgeFilter (StdSelect_AnyEdge);
myContext->AddFilter (aFil1);
myContext->AddFilter (aFil2);

3. In the mouse handle method with (QMouseEvent *e):

const Graphic3d_Vec2i aPnt (e->pos().x(), e->pos().y());

myContext->MoveTo(aPnt.x(), aPnt.y(), myView, true);

myContext->SelectDetected (AIS_SelectionScheme_Add);

qDebug() << myContext->HasDetected();

qDebug() << myContext->MainSelector()->NbPicked();

Finally, during a run, the first qDebug() shows false, and the other shows 0. It does not matter how many times I click the mouse over the cylinder shape.