How to get the name of a part in an IGES file?

Hi,everyone!

I want to get the assembly information on the upper left side of the CAD assistant (shown in the uploaded picture).

But Now, I can only get the node information of the parent(like "a   (0) "in the picture).

I want to get the following 8 compounds;

In my program, I add judgment statements code:

ShapeTool->IsComponent(rootLabel);
ShapeTool->IsAssembly(rootLabel);

to judge whether the current label is main part or node, but the results are all sub-part or simple shape.This makes me very confusion.

this is my part source codes;

Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
Handle(TDocStd_Document) anXdeDoc;
anXdeApp->NewDocument(TCollection_ExtendedString("BinXCAF"), anXdeDoc);
IGESCAFControl_Reader aReader;
IFSelect_ReturnStatus stat = aReader.ReadFile("D:\\Project\\modelFile\\IGES\\Product1.igs");
if (!aReader.Transfer(anXdeDoc)) {
		std::cout << "error" << endl;
	}

	//Initialize an XDE Document (Shapes)==>GetRootsFromDocument
	Handle(XCAFDoc_ShapeTool) ShapeTool = XCAFDoc_DocumentTool::ShapeTool(anXdeDoc->Main());
	TDF_LabelSequence rootLabels;
	ShapeTool->GetShapes(rootLabels);
	int a = 0;

	Standard_Integer rootLabelCount = rootLabels.Length();
	for (Standard_Integer rootLabelIndex = 1; rootLabelIndex <= rootLabelCount; ++rootLabelIndex)
	{
		TDF_Label rootLabel = rootLabels.Value(rootLabelIndex);
		if (ShapeTool->IsComponent(rootLabel)) { 
			cout << "main part"<< endl;
		}
		else {
			cout << "sub-part" << endl;
		}
		TCollection_AsciiString Name(' ');
		if (ShapeTool->IsAssembly(rootLabel)) {
			cout << "node" << endl;
		}
		else {
			cout << "simple shape" << endl;
		}
		Handle(TDataStd_Name) nameAttr;
        //GetChildFromDocument
		if (rootLabel.FindAttribute(TDataStd_Name::GetID(), nameAttr))
		{
			Name += nameAttr->Get();
			cout << "Name" << Name << endl;
			TDF_LabelSequence components;
			cout << ShapeTool->GetComponents(rootLabel, components, Standard_False) << endl;
			if (ShapeTool->GetComponents(rootLabel, components, Standard_False))
			{
				Standard_Integer componentCount = components.Length();
				for (Standard_Integer compIndex = 1; compIndex <= componentCount; ++compIndex)
				{
					TDF_Label componentLabel = components.Value(compIndex);
					TDF_Label shapeLabel;
					if (!ShapeTool->GetReferredShape(componentLabel, shapeLabel))
					{
						shapeLabel = componentLabel;
					}
					Handle(TDataStd_Name) shapeNameAttr;
					if (shapeLabel.FindAttribute(TDataStd_Name::GetID(), shapeNameAttr))
					{
						Name += shapeNameAttr->Get();
					}
					else
					{
						Name += L"[Unnamed]";
					}
				}
			}
		}
		TDF_Label Label = rootLabel;
	}

Thank you all for any replies and suggestions!

Best regards.

sunlin0oo's picture

In other words, how do I read the assembly information about IGES;

I know that the assembly information will be processed through the IGESCAFControl_Reader class and XDE document, but I can't get the complete assembly information.

This is the website information I refer to, I deal with it according to the prompts, but without success;

https://dev.opencascade.org/doc/overview/html/occt_user_guides__xde.html

The assembly content corresponding to this Product.iges file corresponds to the picture content in the theme.

Thank you all for any replies and suggestions!

Best regards.

Attachments: 
Dmitrii Pasukhin's picture

Hello, I guess this quasting about general usage of XCAF tree.

I recomended to look into :XCAFPrs_DocumentExplorer

This clase iterate throught document and by Next(), Current(), More() and getting values from Current you will have the same result with CAD Assistent.

Best regareds, Dmitrii.

sunlin0oo's picture

Thank you for your reply and advice, Dmitrii!

In the STEP file, I have used this method for processing, and I have traversed the same result as CAD Assistant.

	for (XCAFPrs_DocumentExplorer aDocExp(anXdeDoc,XCAFPrs_DocumentExplorerFlags_None);aDocExp.More(); aDocExp.Next())
	{
		a++;
		const XCAFPrs_DocumentNode& aNode = aDocExp.Current();
		if (ShapeTool->IsComponent(aNode.Label)) {
			cout << "main part" << endl;
		}
		else {
			cout << "sub-part" << endl;
		}
		TCollection_AsciiString Name(' ');
		if (ShapeTool->IsAssembly(aNode.Label)) {
			cout << "node" << endl;
		}
		else {
			cout << "simple shape" << endl;
		}
		TCollection_AsciiString aName(aDocExp.CurrentDepth() * 2, ' ');
		Handle(TDataStd_Name) aNodeName;
		if (aNode.RefLabel.FindAttribute(TDataStd_Name::GetID(), aNodeName)
			|| aNode.Label.FindAttribute(TDataStd_Name::GetID(), aNodeName))
		{
			aName += aNodeName->Get();
		}
		cout << aName << " [id: " << aNode.Id << "]\n";
	}

But in IGES, I can't traverse to the assembly with child nodes. If there are only nodes, it is possible.

Best regareds, Sun.