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數(shù)據(jù)交換模塊可以通過讀寫CAD模型數(shù)據(jù)的方式與其他CAD系統(tǒng)進(jìn)行交互。標(biāo)準(zhǔn)數(shù)據(jù)交換(Standardized Data Exchange)的接口可以查詢和檢查輸入文件,轉(zhuǎn)換文件中的CAD模型,正確性檢查。目前開源部分支持的文件格式有:
l STEP(AP203:Mechanical Design;AP214:Automotive Design)
l IGES(5.3版本)
l VRML和STL;

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

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

Figure 3. 裝配結(jié)構(gòu)樹
裝配結(jié)構(gòu)通過OCAF的Label/SubLabel來(lái)組織:

Figure 4. 一個(gè)簡(jiǎn)單的框架模型
類XCAFDoc_ShapeTool來(lái)管理Label中的模型屬性。
6. Names
XDE支持讀寫IGES和STEP中的名字?jǐn)?shù)據(jù)。這個(gè)關(guān)閉這個(gè)功能以減小文件。

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

Figure 6. XDE顏色
8. Code Example
程序?qū)raw Test Harness的samples的XDE的例子模型來(lái)測(cè)試讀取裝配結(jié)構(gòu)、顏色等信息。首先將例子模型通過命令:WriteStep D d:/rod.step來(lái)保存裝配結(jié)構(gòu)、顏色等數(shù)據(jù)到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;
}
程序運(yùn)行結(jié)果如下圖所示:

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