Which shape is the selection?

I created two shape,named ashape1 and ashape2.
Now I select one,for example:
Now I have some problems:
Is the selection the ashape1 or the ashape2?

Rob Bachrach's picture

Current() returns an AIS_InteractiveObject. So, you need to downcast it to an AIS_Shape and get the original shape from it:

aIO = MyAisContext->Current();
aAS = Handle(AIS_Shape)::DownCast(aIO);
aShape = aAS->Shape();

Miguel Costa's picture


If you want to see if aShape (that you got using Rob code) is either one of your ashape1 or ashape2, you'll need the function
IsEqual() (member of TopoDS_Shape)
//The shape selected is ashape1
else if(aShape.IsEqual(ashape2))
//The shape selected is ashape2

If you have an OpenLocalContext
i.e. myAIS_InteractiveContext->OpenLocalContext(),
you may also use myAIS_InteractiveContext->SelectedShape(), which return a TopoDS_Shape.

I hope this answer your question.