How to get the selected subshapes

Hello

I can change the selection mode and select subshapes, but how do I get the selected subshapes, e.g. faces or vertices?

I've tried this approach below, but now I'm stuck.

Any help much appreciated :)

int previousSelMode = 0;
void SetSelectionMode(int selectionMode)
{
myAISContext()->CloseAllContexts();
myAISContext()->OpenLocalContext(Standard_False);
//myAISContext()->OpenLocalContext();
switch (selectionMode)
{
case 0:
myAISContext()->ActivateStandardMode(TopAbs_SOLID);
break;
case 1:
myAISContext()->ActivateStandardMode(TopAbs_VERTEX);
break;
case 2:
myAISContext()->ActivateStandardMode(TopAbs_EDGE);
break;
case 3:
myAISContext()->ActivateStandardMode(TopAbs_WIRE);
break;
case 4:
myAISContext()->ActivateStandardMode(TopAbs_FACE);
break;
case 5:
myAISContext()->ActivateStandardMode(TopAbs_SHELL);
break;
case 6:
myAISContext()->ActivateStandardMode(TopAbs_SOLID);
break;
case 7:
myAISContext()->ActivateStandardMode(TopAbs_COMPSOLID);
break;
case 8:
myAISContext()->ActivateStandardMode(TopAbs_COMPOUND);
break;
}

AIS_ListOfInteractive objects;
myAISContext()->DisplayedObjects (objects);
AIS_ListIteratorOfListOfInteractive iobject (objects);
while (iobject.More ())
{
myAISContext()->Deactivate(iobject.Value(), previousSelMode);
myAISContext()->Activate(iobject.Value(), selectionMode);

myAISContext()->SetHilightColor(Quantity_NameOfColor::Quantity_NOC_WHITE);
myAISContext()->SetTransparency(iobject.Value(), 0.3);
//myAISContext()->Redisplay(iobject.Value());

myAISContext()->Display(iobject.Value(), 1, -1, Standard_True, Standard_True);
Handle(StdSelect_FaceFilter) Fil1 = new StdSelect_FaceFilter(StdSelect_Revol);
Handle(StdSelect_FaceFilter) Fil2 = new StdSelect_FaceFilter(StdSelect_Plane);
myAISContext()->AddFilter(Fil1);
myAISContext()->AddFilter(Fil2);

iobject.Next ();
}
previousSelMode = selectionMode;
}

void Select(void)
{
if (!myAISContext().IsNull())
{
AIS_StatusOfPick s = myAISContext()->Select();
}
}

NativeWrapper^ GetSelectedShape()
{
NativeWrapper ^f;
if (!myAISContext().IsNull())
{
for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
{
if (myAISContext()->HasSelectedShape())
{
const TopoDS_Shape& shape = myAISContext()->SelectedShape();
TopoDS_Shape* retVal = new TopoDS_Shape(shape);
f = gcnew NativeWrapper(retVal);
}
else
{
Handle_AIS_InteractiveObject aniobj = myAISContext()->Interactive();
// to be able to use the picked interactive object

}
}
}
return f;
}
Henrik Rune Jakobsen's picture

Never mind. Figured it out. :)

Here, just in case some one else can get some help out of it:

NativeWrapper^ GetSelectedShape()
{
NativeWrapper ^f;
for (myAISContext()->InitSelected(); myAISContext()->MoreSelected(); myAISContext()->NextSelected())
{
TopoDS_Shape shape = myAISContext()->SelectedShape();
switch (currentSelectionMode)
{
case NativeType::Shape:
{
TopoDS_Shape* retVal = new TopoDS_Shape(shape);
f = gcnew NativeWrapper(retVal);
break;
}
case NativeType::Vertex:
{
TopoDS_Vertex vtx = TopoDS::Vertex(shape);
TopoDS_Vertex* retVal = new TopoDS_Vertex(vtx);
f = gcnew NativeWrapper(NativeType::Vertex, retVal);
break;
}
case NativeType::Edge:
{
TopoDS_Edge o = TopoDS::Edge(shape);
TopoDS_Edge* retVal = new TopoDS_Edge(o);
f = gcnew NativeWrapper(NativeType::Edge, retVal);
break;
}
case NativeType::Wire:
{
TopoDS_Wire o = TopoDS::Wire(shape);
TopoDS_Wire* retVal = new TopoDS_Wire(o);
f = gcnew NativeWrapper(NativeType::Wire, retVal);
break;
}
case NativeType::Face:
{
TopoDS_Face o = TopoDS::Face(shape);
TopoDS_Face* retVal = new TopoDS_Face(o);
f = gcnew NativeWrapper(NativeType::Face, retVal);
break;
}
case NativeType::Shell:
{
TopoDS_Shell o = TopoDS::Shell(shape);
TopoDS_Shell* retVal = new TopoDS_Shell(o);
f = gcnew NativeWrapper(NativeType::Shell, retVal);
break;
}
case NativeType::Solid:
{
TopoDS_Solid o = TopoDS::Solid(shape);
TopoDS_Solid* retVal = new TopoDS_Solid(o);
f = gcnew NativeWrapper(NativeType::Solid, retVal);
break;
}
case NativeType::Compsolids:
{
TopoDS_CompSolid o = TopoDS::CompSolid(shape);
TopoDS_CompSolid* retVal = new TopoDS_CompSolid(o);
f = gcnew NativeWrapper(NativeType::Compsolids, retVal);
break;
}
case NativeType::Compound:
{
TopoDS_Compound o = TopoDS::Compound(shape);
TopoDS_Compound* retVal = new TopoDS_Compound(o);
f = gcnew NativeWrapper(NativeType::Compound, retVal);
break;
}
}
}
return f;
}

Lei Lu's picture

Dear Henrik

What is the meaning of ^
NativeWrapper^ GetSelectedShape()
{
NativeWrapper ^f;

jarsigan vickneswaran's picture

can anyone help to select face from shape?

Hugues Delorme's picture

Hello,

You have to use AIS_InteractiveContext::AddOrRemoveSelected(const Handle_SelectMgr_EntityOwner&) for that.

First thing is to find the entity owner for the face you want to select. All entity owners can be retrieved with AIS_InteractiveContext::EntityOwners().

For a TopoDS_Face, the entity owner is of type StdSelect_BRepOwner.

Have a look how this is done in my Mayo project, function GuiDocument::toggleItemSelected(const ApplicationItem&) in file gui_document.cpp :

        https://github.com/fougue/mayo/blob/develop/src/gui_document.cpp#L153