How to select shape from viewer?

Hello, everyone! I have a question now. I want to select edge or face, then save the attribute of them. But when I use the code below, selectedShape is Null.
TopoDS_Shape selectedShape = m_context->SelectedShape();
TopAbs_ShapeEnum objectType = selectedShape.ShapeType();
if (objectType == TopAbs_VERTEX)
{
std::cout }
else if (objectType == TopAbs_EDGE)
{
std::cout }
else if (objectType == TopAbs_FACE)
{
std::cout }

When I use another code below, the shapetype is Compound when I choose edge or face.
Handle(AIS_InteractiveObject) detectedObject = m_context->DetectedInteractive();
Handle(AIS_Shape) aisShape = Handle(AIS_Shape)::DownCast(detectedObject);
TopoDS_Shape selectedShape = aisShape->Shape();

I want to use DetectedShape() , but it was deprecated. Sad!

gkv311 n's picture

Please use code tags to insert code snippets on the forum to make it readable.