How to judge whether a topo-shape is independent(no parent)?

Hi All,
Now, I want to judge a specified shape whether it has parent. Such as shape A(type:TopoDS_Vertex) has no parent B(type:TopoDS_Edge). My code like this:
TopoDS_Shape topoShape;
....
switch(topoShape.ShapeType())
{
case TopAbs_VERTEX:
{
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(topoShape, TopAbs_VERTEX, TopAbs_EDGE, M);
const TopTools_ListOfShape& listOfShapes = M.FindFromKey(topoShape);
if(listOfShapes.IsEmpty())
return true;
}
break;
case TopAbs_EDGE:
{
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(topoShape, TopAbs_EDGE, TopAbs_WIRE, M);
const TopTools_ListOfShape& listOfShapes = M.FindFromKey(topoShape);
if(listOfShapes.IsEmpty())
return true;
}
break;
case TopAbs_WIRE:
{
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(topoShape, TopAbs_WIRE, TopAbs_FACE, M);
const TopTools_ListOfShape& listOfShapes = M.FindFromKey(topoShape);
if(listOfShapes.IsEmpty())
return true;
}
break;
case TopAbs_FACE:
{
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(topoShape, TopAbs_FACE, TopAbs_SHELL, M);
const TopTools_ListOfShape& listOfShapes = M.FindFromKey(topoShape);
if(listOfShapes.IsEmpty())
return true;
}
break;
....
return false;

I've tried some samples, but it always return "true".
Any suggestion is welcome.
Thanks in advance.

Cauchy Ding's picture

I've solved it. It seems as the the "topoShape" in "TopExp::MapShapesAndAncestors(topoShape..." should be set to the root shape of the model
.