Selection with Qt Opencascade

I notice that with Qt Opencascade you can select Shapes. I have been trying to change it by adding filters so it will only select Faces or Edges when set to the correct mode, but so far I have had no luck at getting it to select anything but whole solid shapes. My current attempt have been trying to follow the examples given in Visualization tutorial (around page 42). Here is a piece of it for a plane:

Handle(StdSelect_FaceFilter) Fil2= new StdSelect_FaceFilter(StdSelect_Plane);
myContext->AddFilter(Fil2);

So any help with selection or selecting in different modes would be very helpful. Thanks.

Torsten Sadowski's picture

Hi Robert,

try this:

void SelectTool::setLocalContext(TopAbs_ShapeEnum which)
{
if (stWs->activeWindow())
{
Handle(AIS_InteractiveContext) ctx =
((MDIWindow*)stWs->activeWindow())->getDocument()->getCo
ntext();
if (ctx)
{
ctx->CloseAllContexts();
if (which != TopAbs_SHAPE)
{
ctx->OpenLocalContext();
ctx->ActivateStandardMode(which);
}
}
}
}

maninred's picture

I'm sorry, can I get some explanation behind your code, I'm a little lost.

Torsten Sadowski's picture

Hi Robert,

void SelectTool::setLocalContext(TopAbs_ShapeEnum which)
{
if (stWs->activeWindow())
{
Handle(AIS_InteractiveContext) ctx =
((MDIWindow*)stWs->activeWindow())->getDocument()->getCo
ntext();

This is only to get the AIS_InteractiveContext of the active ImportExportSample window

if (ctx)

If I have the context

{
ctx->CloseAllContexts();

I close all local contexts. This prevents opening more than one local context and gives me the default behaviour of selecting shapes.

if (which != TopAbs_SHAPE)

If I want to select something special

{
ctx->OpenLocalContext();

I open a local context

ctx->ActivateStandardMode(which);

And set its selection mode to the entity I want to select:
TopAbs_VERTEX, _EDGE, _WIRE, _FACE, _SHELL, _SOLID, _COMPSOLID, _COMPOUND

}
}
}
}

Cheers, Torsten