zoukankan      html  css  js  c++  java
  • OpenCASCADE Application Framework Data Framework Services

    OpenCASCADE Application Framework Data Framework Services

    eryar@163.com

    一、概述Overview

    OpenCASCADE的数据框架对来自不同程序的数据提供了统一的处理环境。这就简化了数据交换、修改,也保证了数据统一性、稳定性。实现方法需要用到以下部分:

    u 标号Tha tag

    u 标签The label

    u 属性The attribute

    Contents of a document

    Figure 1. Contents of a document

    如上图所示,框架树的第一个标签(label)是根标签(root)。每个标签(label)有个以整数表示的标号(tag)。由当前标签的标号到根标签的标号,可以得到一个惟一的标号列表,如:0:1:2:1

    每个标签(label)可以一些属性(attribute),这些属性可以包含数据。每个属性由GUID来区分。标签最重要的性质是其入口只是数据框架的一个地址。

    二、标号The Tag

    一个标号Tag就是一个整数,它用两种方式标示了一个label

    u 相对标示法 Relative identification:一个标签的标号只与其父标签有关系。如对于一个指定的标签,可能由四个子标签组成,其标号分别为2718100。使用相对标示方法,在设置属性时有安全的范围。

    u 绝对标示法 Absolute identification:一个标签在数据框架中位置由无歧义的、从根标签的标号到当前标签的标号用冒号表示的标号列表(list of tags)来表示。

    不管采用哪种方法,都要注意的是这些标号的值没什么实际的意义。只是用来确定每个标签在树结构的位置,都是为了使用文档支持Undo/Redo的功能。

    创建标号Tag的两种方式:

    u Random delivery 随机创建;

    u User-defined delivery 用户自定义创建;

    正如字面所说,随机创建标号时,标号是由系统随机生成。用户自定义创建标号时,标号的值是创建标号函数的参数。

    1. 随机创建标号法生成子标签 Creating child labels using random delivery of tags

    使用TDF_TagSource::NewChild来添加标签。如下代码所示,函数NewChild的参数level2也是一个TDF_Label

    2. 用户自定义创建标号法生成子标签 Creation of a child label by user delivery from a tag

    创建子标签的另一种方式就是用户自定义创建。即在指定标号创建标签。可以使用TDF_Label::FindChildTDF_Label::Tag来获得指定标号的子标签。

    如上代码所示,3是需要查找的标签的标号,Standard_False用来表示若查找不到指定标号时是否创建子标签。

    三、标签The Label

    标号(Tag)给了标签(Label)一个唯一的地址。数据框架中的标签是包含属性,绑定数据的容器。数据框架的本质是一个标签树,如下图所示:

    数据框架中的标签不能被删除,因此,当文档打开后已经的数据框架结构不能被删除。

    1. 创建标签 Label creation

    可以在任意层次创建标签,也可以找到标签在数据框架中的深度(Depth)。TDF_Label提供上述功能。

    2. 创建子标签 Creating child labels

    在数据框架中指定标签上创建子标签使用TDF_Label::FindChild。如下所示:

    当把FindChilde的第二个参数设为Standard_True时,就确保了查找不到指定标号的标签时会创建一个标签。如下所示:

    3. 访问子标签 Retrieving child labels

    可以使用遍历器来访问当前标签的第一层的子标签。如下所示:

    也可以访问当前标签的所有子标签,如下所示:

    使用TDF_Tool::Entry可以得到当前标签的入口字符串,如下所示:

    4. 访问父标签

    访问当前标签的父标签:

    四、属性The Attribute

    标签本身不包含任何数据。所有数据,不管什么类型,程序的非程序的数据都是保存在属性中。属性是绑定在标签上,且属性可以是任意类型的数据。OCAF提供许多直接可以使用的属性如:整数、实数、轴、平面。也有用于拓朴、功能、可视化的属性。每种类型的属性由GUID来标识。这样做的好处就是所有类型的属性都以相同的方式处理。可以创建新的实例,访问、绑定到标签和从标签上删除等。

    1.访问标签的属性

    使用函数TDF_Label::FindAttribute来访问标签的属性。如下例所示,

    2.使用GUID来标识属性 Identifying an attribute using a GUID

    可以创建一个属性对象并得到其GUID。如下例所示,创建了一个整数属性,通过方法ID来得到GUID

    3. 将属性绑定到标签 Attaching an attribute to a label

    使用函数TDF_Label::Add来将属性绑定到标签。重复绑定相同GUID的属性到一个标签会出现错误。TDF_Attribute::Label可以得到绑定属性的标签。如下所示:

    4. 测试标签绑定状态 Testing the attachment to a label

    可以使用函数TDF_Attribute::IsA来检验属性是否已经绑定到标签上,函数的参数是属性的GUID。在下例所示,是检测当前标签是否有整数属性,然后得出这个标签属性的数量。函数TDF_Tool::HasAttribute用来检测标签是否绑定的有属性,函数TDF_Tool::NbAttributes返回标签绑定属性的数量。

    5. 删除标签的属性 Removing an attribute from a label

    若要将属性从标签中删除,可以使用TDF_Label::Forget,函数参数为属性的GUID。若要删除标签所有属性,使用函数TDF_Label::ForgetAll

    6. 特定属性的创建 Specific attribute creation

    见《Application Framework User's Guide》。

    五、示例程序 Sample Code

      1: //------------------------------------------------------------------------------
    
      2: //	Copyright (c) 2012 eryar All Rights Reserved.
    
      3: //
    
      4: //		File    : Main.cpp
    
      5: //		Author  : eryar@163.com
    
      6: //		Date    : 2012-11-4 21:25
    
      7: //		Version : 0.1v
    
      8: //
    
      9: //	Description : OpenCASCADE Application Framework sample code.
    
     10: //
    
     11: //==============================================================================
    
     12: 
    
     13: #include <iostream>
    
     14: using namespace std;
    
     15: 
    
     16: #include <TDF_Tool.hxx>
    
     17: #include <TDF_ChildIterator.hxx>
    
     18: #include <TDataStd_Integer.hxx>
    
     19: #include <TDocStd_Document.hxx>
    
     20: 
    
     21: // Use Toolkit: TKLCAF
    
     22: #pragma comment(lib, "TKernel.lib")
    
     23: #pragma comment(lib, "TKLCAF.lib")
    
     24: 
    
     25: int main(int argc, char* argv[])
    
     26: {
    
     27:     TCollection_AsciiString entry;
    
     28: 
    
     29:     Handle_TDocStd_Document myDF    = new TDocStd_Document("myDocument");
    
     30: 
    
     31:     // Main label and root label of the data framework.
    
     32:     TDF_Label   mainLabel   = myDF->Main();
    
     33:     TDF_Label   root        = mainLabel.Root();
    
     34: 
    
     35:     cout<<"Main label :";
    
     36:     mainLabel.EntryDump(cout);
    
     37: 
    
     38:     cout<<endl<<"Root label :";
    
     39:     root.EntryDump(cout);
    
     40: 
    
     41:     // Create a label with tag 10 at Root.
    
     42:     TDF_Label   myLabel    = root.FindChild(10);
    
     43: 
    
     44:     cout<<endl<<"Entry of the new label :";
    
     45:     myLabel.EntryDump(cout);
    
     46: 
    
     47:     // Retrieving child labels.
    
     48:     cout<<endl<<"Retrieving child labels: "<<endl;
    
     49:     for (TDF_ChildIterator it(root); it.More(); it.Next())
    
     50:     {
    
     51:         it.Value().EntryDump(cout);
    
     52:         cout<<endl;
    
     53:     }
    
     54: 
    
     55:     // Attaching an attribute to a label.
    
     56:     Handle_TDataStd_Integer INT = new TDataStd_Integer;
    
     57:     myLabel.AddAttribute(INT);
    
     58: 
    
     59:     // Testing of attribute attachment.
    
     60:     if (myLabel.IsAttribute(INT->GetID()))
    
     61:     {
    
     62:         cout<<"The attribute is attached to the label."<<endl;
    
     63:     }
    
     64:     else
    
     65:     {
    
     66:         cout<<"The attribute is not attached to the label."<<endl;
    
     67:     }
    
     68: 
    
     69:     // Removing an attribute from a label.
    
     70:     myLabel.ForgetAttribute(INT->GetID());
    
     71: 
    
     72:     // Testing of attribute attachment.
    
     73:     if (myLabel.IsAttribute(INT->GetID()))
    
     74:     {
    
     75:         cout<<"The attribute is attached to the label."<<endl;
    
     76:     }
    
     77:     else
    
     78:     {
    
     79:         cout<<"The attribute is not attached to the label."<<endl;
    
     80:     }
    
     81: 
    
     82:     return 0;
    
     83: }

    输出结果如下所示:

      1: Main label :0:1
    
      2: Root label :0:
    
      3: Entry of the new label :0:10
    
      4: Retrieving child labels:
    
      5: 0:1
    
      6: 0:10
    
      7: The attribute is attached to the label.
    
      8: The attribute is not attached to the label.
    
      9: Press any key to continue . . .

    eryar@163.com

    2012-11-06

  • 相关阅读:
    网络流相关题目
    【洛谷P3119】[USACO15JAN]草鉴定Grass Cownoisseur
    【洛谷八连测R6】yanQval-透明的星尘
    【洛谷八连测R6】yanQval-分离丧失的既视感
    【洛谷八连测R6】yanQval-不可逆的重启动
    【洛谷P2700】逐个击破
    【洛谷八连测R5】whzzt-Confidence
    【洛谷八连测R5】whzzt-Warmth
    【洛谷八连测R5】whzzt-Conscience
    【NOIP模拟赛】
  • 原文地址:https://www.cnblogs.com/opencascade/p/3519592.html
Copyright © 2011-2022 走看看