为了读取步骤文件中的所有形状,我已经成功使用STEPControl_reader提取了所有形状。 现在,我想找到一种方法(OCAF / XDE?)来提取包含另一个形状包含的形状的树视图。
谁能提供一些使用OCAF或XDE在步骤文件中提取这些信息的示例的指针。 我很难理解正式文件,因为它缺少示例。
编辑: 通过使用Mayo项目: 您可以使用XdeDocumentItem :: XdeDocumentItem(...)构造函数并递归创建节点。
XdeDocumentItem::XdeDocumentItem(const Handle_TDocStd_Document &doc)
: m_cafDoc(doc),
m_shapeTool(XCAFDoc_DocumentTool::ShapeTool(doc->Main())),
m_colorTool(XCAFDoc_DocumentTool::ColorTool(doc->Main())){
this->rebuildAssemblyTree();}
rebuildAssemblyTree方法如下:
for (const TDF_Label& rootLabel : this->topLevelFreeShapes())
this->deepBuildAssemblyTree(0, rootLabel);
答案 0 :(得分:0)
您可以使用类 XCAFPrs_DocumentExplorer 进行OCCT 7.4.0+中的类似堆栈的遍历,并使用以下代码片段(基于 XDisplay Draw Harness命令)进行遍历。递归函数调用:
//! Handle document root shapes.
int traverseDocument (const Handle(TDocStd_Document)& theDoc)
{
TDF_LabelSequence aLabels;
XCAFDoc_DocumentTool::ShapeTool (theDoc->Main())->GetFreeShapes (aLabels);
for (TDF_LabelSequence::Iterator aLabIter (myLabels); aLabIter.More(); aLabIter.Next())
{
const TDF_Label& aLabel = aLabIter.Value();
if (traverseLabel (aLabel, "", TopLoc_Location()) == 1)
{
return 1;
}
}
return 0;
}
//! Handle single label.
int traverseLabel (const TDF_Label& theLabel,
const TCollection_AsciiString& theNamePrefix,
const TopLoc_Location& theLoc)
{
TCollection_AsciiString aName;
{
Handle(TDataStd_Name) aNodeName;
if (theLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
{
aName = aNodeName->Get(); // instance name
}
if (aName.IsEmpty())
{
TDF_Label aRefLabel;
if (XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel)
&& aRefLabel.FindAttribute (TDataStd_Name::GetID(), aNodeName))
{
aName = aNodeName->Get(); // product name
}
}
}
aName = theNamePrefix + aName;
TDF_Label aRefLabel = theLabel;
XCAFDoc_ShapeTool::GetReferredShape (theLabel, aRefLabel);
if (XCAFDoc_ShapeTool::IsAssembly (aRefLabel))
{
aName += "/";
const TopLoc_Location aLoc = theLoc * XCAFDoc_ShapeTool::GetLocation (theLabel);
for (TDF_ChildIterator aChildIter (aRefLabel); aChildIter.More(); aChildIter.Next())
{
if (traverseLabel (aChildIter.Value(), aName, aLoc) == 1)
{
return 1;
}
}
return 0;
}
std::cout << aName << " ";
return 0;
}