• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

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

            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

            Feedback

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2012-11-07 09:33 by 力為
            最好不用這個組件

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2012-11-07 12:27 by occ
            @力為
            為什么不能使用這個組件?說說原因吧

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2012-11-07 17:23 by eryar
            @力為
            我想如果對樹形結構的數據的操作進行撤消與重做的話,這種框架還是值得參考的吧?

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2012-11-19 23:05 by aslan
            如果說沒有仔細研究該部分,或者沒有自己認為更加好的解決方法,還是建議采用OCAF,不需要人云亦云。

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2012-11-20 18:15 by eryar
            @aslan
            是啊。
            OCAF也是別人的勞動成果啊!

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2013-10-22 09:19 by 力為
            @eryar
            1. 繁瑣
            最最開始的時候用OCAF,簡單的描述沒什么問題。需要保存的數據多的時候,有很多體力活。每次都遍歷樹,使用不方便。
            2. 臃腫
            用GUID標識,Undo/Redo保存的數據太多,耗費內存。

            簡單的應用用不上,復雜的應用使用起來不方便。我們都是按照自己的需求自己實現的。

            # re: OpenCASCADE Application Framework Data Framework Services  回復  更多評論   

            2013-10-22 19:48 by eryar
            @力為
            贊同,
            不過我正在寫的一個小程序正好用上了,
            :-)
            97精品久久天干天天天按摩| 久久人与动人物a级毛片| 久久精品国产AV一区二区三区| 九九精品久久久久久噜噜| 伊人热热久久原色播放www| 97精品依人久久久大香线蕉97| 国内精品久久久久伊人av| 国产女人aaa级久久久级| 热99RE久久精品这里都是精品免费| 日产精品99久久久久久| 久久久久亚洲AV无码专区桃色| 亚洲AV成人无码久久精品老人| 久久国产美女免费观看精品| 亚洲中文字幕无码久久精品1| 国产精品热久久毛片| 色欲综合久久躁天天躁蜜桃| 国产精品无码久久久久| 久久AV高清无码| 久久亚洲国产精品成人AV秋霞| 99精品久久久久久久婷婷| 久久这里只有精品18| 亚洲国产成人久久综合一区77| 国产香蕉97碰碰久久人人| 无码精品久久久久久人妻中字 | 好属妞这里只有精品久久| 久久午夜福利电影| 精品国产青草久久久久福利| 9久久9久久精品| 99久久久精品免费观看国产| 久久久久亚洲av无码专区| 亚洲精品国产字幕久久不卡| 91麻豆国产精品91久久久| 中文字幕无码久久精品青草| 久久久久亚洲AV成人网人人网站 | 国产精品九九久久免费视频| 99麻豆久久久国产精品免费| 99久久精品国内| 久久精品一区二区| 99久久国产主播综合精品| 亚洲国产成人久久综合一| 亚洲国产成人久久精品影视 |