eryar

PipeCAD - Plant Piping Design Software.
RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
posts - 603, comments - 590, trackbacks - 0, articles - 0

OpenCASCADE Extended Data Exchange - XDE

Posted on 2018-07-29 19:43 eryar 阅读(3848) 评论(0)  编辑 收藏 引用 所属分类: 2.OpenCASCADE

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;

wps_clip_image-25767

Figure 1. 导入的STEP模型

2. Extended Data Exchange(XDE)

扩展的数据交换模块可以转换附加在几何BREP体中其他信息,如颜色、图层,组装结构等,因此提高与其他CAD软件的兼容性。目前包含这些信息的文件格式有IGES和STEP。XDE通过XCAF框架来读写包含颜色、图层等信息的IGES,STEP文件。

wps_clip_image-29842

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支持装配结构的读写。如下图所示:

wps_clip_image-19676

Figure 3. 装配结构树

装配结构通过OCAF的Label/SubLabel来组织:

wps_clip_image-18828

Figure 4. 一个简单的框架模型 

类XCAFDoc_ShapeTool来管理Label中的模型属性。

6. Names

XDE支持读写IGES和STEP中的名字数据。这个关闭这个功能以减小文件。

wps_clip_image-10693

Figure 5. 模型名字

7. Colors and Layers

XDE可以读写模型的颜色数据,使用到的类有:

l 通用颜色:generic color(XCAFDoc_ColorGen)

l 曲面颜色:surface color(XCAFDoc_ColorSurf)

l 曲线颜色:curve color(XCAFDoc_ColorCurv)

wps_clip_image-4463

Figure 6. XDE颜色

8. Code Example

程序将Draw Test Harness的samples的XDE的例子模型来测试读取装配结构、颜色等信息。首先将例子模型通过命令:WriteStep D d:/rod.step来保存装配结构、颜色等数据到STEP格式。

wps_clip_image-24546

Figure 7. XDE Samples in Draw Test Harness

wps_clip_image-18659

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;
}

程序运行结果如下图所示:

wps_clip_image-8893

Figure 9. 使用XDE读取STEP装配结构、颜色、名字等

9. Conclusion

使用XDE模块支持STEP和IGES中的装配结构、颜色、名字等信息的读写,提高与其他CAD系统数据交换效果。

XDE主要使用OCAF框架来处理装配结构、属性信息,所以要使用XDE,必须理解OCAF的框架,OCAF框架也是一个基于Label的树结构。



为了方便大家在移动端也能看到我的博文和讨论交流,现已注册微信公众号,欢迎大家扫描下方二维码关注。
Shing Liu(eryar@163.com)

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理