query topods shape by name

Hi,

I want to query a TopoDS_Shape by its name. First, an IGES file is loaded with the IGESControl_Reader. As far as I have seen in the sourcecode, the sections containing the names are directory sections. Unfortunately, I can't see where I could query these directory entries or, that would be the best, how to get a shape by the name referenced in the IGES file.

So, is there a possible solution? What could I do?

Best,
Matthias

Matthias Teich's picture

You should search the forum for IGESCAFControl_Reader, there you can use layers, colors and names

mwr's picture

Thank you very much! I did and from the sourcecode I programmed the following.
It is included in a class that is derived from IGESControl_Reader.

//get shape for label
TopoDS_Shape getShape(char* shapeName)
{
const TCollection_AsciiString ascShapeName(shapeName);

const Handle(XSControl_WorkSession)& theSession = WS();
const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
const Handle(XSControl_TransferReader)& aReader = theSession->TransferReader();
const Handle(Transfer_TransientProcess)& tp = aReader->TransientProcess();

Standard_Integer nb = theModel->NbEntities();
TopoDS_Shape retShape;
for(Standard_Integer i=1; i<=nb; i++)
{
Handle(IGESData_IGESEntity) ent =
Handle(IGESData_IGESEntity)::DownCast
(theModel->Value(i));
if (ent.IsNull()) continue;
Handle(Transfer_Binder) binder = tp->Find(ent);
if (binder.IsNull()) continue;
TopoDS_Shape oneShape = TransferBRep::ShapeResult(binder);
if (oneShape.IsNull()) continue;

if (ent->HasName() && ent->NameValue()->String().IsEqual(ascShapeName))
{
retShape = oneShape;
}
}

return retShape;
}

//dump all labels
void dumpLabels()
{
const Handle(XSControl_WorkSession)& theSession = WS();
const Handle(Interface_InterfaceModel)& theModel = theSession->Model();

Standard_Integer nb = theModel->NbEntities();
for(Standard_Integer i=1; i<=nb; i++)
{
Handle(IGESData_IGESEntity) ent =
Handle(IGESData_IGESEntity)::DownCast
(theModel->Value(i));
if (ent.IsNull()) continue;

if (ent->HasName())
{
std::cout << ent->NameValue()->String().ToCString() << std::endl;
}
}
}

This seems to work quite well and just want to share this if anybody else looks for a similar solution.

Fabian Hachenberg's picture

Wow, thank you so much. With the help of your code I was able to implement the same functionality for STEP files. :)
I've created a recipe entry in the wiki for this topic. You can find it here
http://opencascade.wikidot.com/entitynames

jeholl's picture

HI: Fabian!

I have done it with your code, but it can not work for me.
Please help me write a full code can work.

Thank you very much!!
My email address is kin_lee@126.com

Onnesimus S's picture

Hi there, I followed the example and I am getting the exact count of entities here

Standard_Integer nb = theModel->NbEntities();//nb = number of entities

However a lot of these entities go null for me here

if (ent.IsNull()) continue;//or the name is null

Is there a way to correct this? I am using standard step file from opencascade installation and Version is OpenCascade 6.2.0

Ben Cain's picture

I keep getting isNull() for the transfer binder in the code above.
Handle(Transfer_Binder) binder = tp->Find(ent);

Any ideas why? Any help is greatly appreciated!

Ben Cain's picture

I was able to get the shape by name. See the thread ...
http://www.opencascade.org/org/forum/thread_27045/?forum=3