OpenCASCADE Extended Data Exchange - XDE
eryar@163.com
Abstract. OpenCASCADE Data Exchange allows developing OCCT-Based applications that can interact with other CAD systems by writing and reading CAD models to and from external data. The exchanges run smoothly regardless of the quality of external data or requirements to its internal representation, for example to the data types, accepted geometric inaccuracies, etc. Data Exchange is organized in a modular way as a set of interfaces that comply with various CAD formats: IGES, STEP, STL, VRML, etc. The interfaces allow software based on OCCT to exchange data with various CAD/PDM software packages, maintaining a good level of interoperability. Extended Data Exchange allows translating additional attributes attached to geometric data(colors, layers, names, materials, etc.)
Key Words. DataExchange, STEP, IGES, XDE, OCAF,
1. Introduction
OpenCASCADE的DataExchange數據交換模塊可以通過讀寫CAD模型數據的方式與其他CAD系統進行交互。標準數據交換(Standardized Data Exchange)的接口可以查詢和檢查輸入文件,轉換文件中的CAD模型,正確性檢查。目前開源部分支持的文件格式有:
l STEP(AP203:Mechanical Design;AP214:Automotive Design)
l IGES(5.3版本)
l VRML和STL;

Figure 1. 導入的STEP模型
2. Extended Data Exchange(XDE)
擴展的數據交換模塊可以轉換附加在幾何BREP體中其他信息,如顏色、圖層,組裝結構等,因此提高與其他CAD軟件的兼容性。目前包含這些信息的文件格式有IGES和STEP。XDE通過XCAF框架來讀寫包含顏色、圖層等信息的IGES,STEP文件。

Figure 2. 使用XDE導入的模型
3. XDE Basic Terms
為了更好的理解XDE,定義了幾個關鍵術語:
l Shape:單獨的模型,不屬于任何裝配結構(a standalone shape, which does not belong to the assembly structure);
l Instance:其他模型的一個實例化,位置信息可以相同,也可以不同(a replication of another shape with a location that can be the same location or different one);
l Assembly:裝配結構;
4. XDE Organization
XDE的基礎是XCAF,XCAF是一個基于OCAF(Open CASCADE Technology Application Framework)框架的框架,可用于處理裝配信息和其他屬性數據。XDE使用OCAF來存儲裝配結構和屬性,所以可以得到裝配結構樹的每層TopoDS表示。
5. Assemblies
XDE支持裝配結構的讀寫。如下圖所示:

Figure 3. 裝配結構樹
裝配結構通過OCAF的Label/SubLabel來組織:

Figure 4. 一個簡單的框架模型
類XCAFDoc_ShapeTool來管理Label中的模型屬性。
6. Names
XDE支持讀寫IGES和STEP中的名字數據。這個關閉這個功能以減小文件。

Figure 5. 模型名字
7. Colors and Layers
XDE可以讀寫模型的顏色數據,使用到的類有:
l 通用顏色:generic color(XCAFDoc_ColorGen)
l 曲面顏色:surface color(XCAFDoc_ColorSurf)
l 曲線顏色:curve color(XCAFDoc_ColorCurv)

Figure 6. XDE顏色
8. Code Example
程序將Draw Test Harness的samples的XDE的例子模型來測試讀取裝配結構、顏色等信息。首先將例子模型通過命令:WriteStep D d:/rod.step來保存裝配結構、顏色等數據到STEP格式。

Figure 7. XDE Samples in Draw Test Harness

Figure 8. Shapes with assembly and color info
使用XDE讀取STEP文件代碼示例如下:
Handle(XCAFDoc_ColorTool) aColorTool;
Handle(XCAFDoc_ShapeTool) aShapeTool;
void visit(const TDF_Label& theLabel)
{
theLabel.EntryDump(std::cout);
Handle(TDataStd_Name) aName;
if (theLabel.FindAttribute(TDataStd_Name::GetID(), aName))
{
std::cout << " Name: " << aName->Get() << std::endl;
}
if (aColorTool->IsSet(theLabel, XCAFDoc_ColorGen))
{
Quantity_Color aColor;
aColorTool->GetColor(theLabel, aColor);
std::cout << " Color: " << Quantity_Color::StringName(aColor.Name()) << std::endl;
}
if (aShapeTool->IsShape(theLabel))
{
TopoDS_Shape aShape;
aShapeTool->GetShape(theLabel, aShape);
}
for (TDF_ChildIterator c(theLabel); c.More(); c.Next())
{
visit(c.Value());
}
}
void readStepXde(const std::string& theStepName)
{
Handle(TDocStd_Document) aDoc;
Handle(XCAFApp_Application) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", aDoc);
STEPCAFControl_Reader aStepReader;
aStepReader.SetColorMode(true);
aStepReader.SetNameMode(true);
aStepReader.ReadFile(theStepName.c_str());
aStepReader.Transfer(aDoc);
TDF_Label aRootLabel = aDoc->Main();
aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aRootLabel);
aColorTool = XCAFDoc_DocumentTool::ColorTool(aRootLabel);
visit(aRootLabel);
}
int main(int argc, char *argv[])
{
readStepXde("D:/rod.STEP");
return 0;
}
程序運行結果如下圖所示:

Figure 9. 使用XDE讀取STEP裝配結構、顏色、名字等
9. Conclusion
使用XDE模塊支持STEP和IGES中的裝配結構、顏色、名字等信息的讀寫,提高與其他CAD系統數據交換效果。
XDE主要使用OCAF框架來處理裝配結構、屬性信息,所以要使用XDE,必須理解OCAF的框架,OCAF框架也是一個基于Label的樹結構。
為了方便大家在移動端也能看到我的博文和討論交流,現已注冊微信公眾號,歡迎大家掃描下方二維碼關注。
