1、 读取step文件
void COCCDemoDoc::OnButtonImportStep2()
{
CString szFilter = _T("step(*.stp;*.step)|*.stp;*.step||");
CFileDialog fileDlg(true, _T("step"), 0, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
CString strFilePath;
if (IDOK == fileDlg.DoModal())
{
CString strFilePath = fileDlg.GetPathName();
CString szExt = fileDlg.GetFileExt();
szExt.MakeLower();
if (szExt != _T("stp") && szExt != _T("step"))
{
AfxMessageBox(_T("非step文件,请重新选择!"));
return;
}
TCollection_AsciiString aFileName((const wchar_t*)strFilePath);
STEPCAFControl_Reader aStepReader;
aStepReader.SetColorMode(true);
aStepReader.SetNameMode(true);
if (aStepReader.ReadFile(aFileName.ToCString()) != IFSelect_RetDone)
{
AfxMessageBox(_T("读取文件失败!"));
return ;
}
if (aStepReader.Transfer(m_OCCDoc) == FALSE)
{
AfxMessageBox(_T("转换文件失败!"));
return ;
}
TDF_Label RootLabel = m_OCCDoc->Main();
if (RootLabel.IsNull())
{
AfxMessageBox(_T("标签为空!"));
return;
}
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(RootLabel);
TDF_LabelSequence theShapeLSecond;
aShapeTool->GetFreeShapes(theShapeLSecond);
for (TDF_LabelSequence::Iterator aSecondIter(theShapeLSecond); aSecondIter.More(); aSecondIter.Next())
{
const TDF_Label& aSecondLabel = aSecondIter.Value();
Handle(XCAFPrs_AISObject) aPrs = new XCAFPrs_AISObject(aSecondLabel);
m_AISContext->Display(aPrs, false);
}
m_AISContext->UpdateCurrentViewer();
}
}
2、效果如图
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/7f8c2a5233b44b348c18e66769d8c5c1.png)