階層情報の取得
この記事では、共通データアクセスツリーから階層情報を取得する方法について説明します。共通データアクセスの概要と要件については、このシリーズの最初の記事を参照してください。
OdRxModelHierarchyTreeBaseクラスのcreateDatabaseHierarchyTree関数は、階層ツリー構造を構築するために使用されます。共通データアクセスツリーを構築するには、3つのモードがあります。
- ベースのツリー構造のみを取得する(これが最も高速です)。
- ベースのツリー構造と、例えばツリー内のオブジェクトをグループ化およびソートするために使用される少数のプロパティセットを取得する。
- 完全なセットを取得する:ツリーとすべてのノードプロパティのキャッシュ。
…
// pDb - Pointer to the source database object.
// create_properties_cache - Flag to create cache of properties. Default value is true.
// class_dependent_hierarchy - Flag to optimize the creation of a hierarchical tree. It can only be set to true if the properties of database objects with a hierarchical attribute are statically dependent on the object type. Default value is false.
// class_dependent_property - Flag to optimize cache creation. It can be set to true only if all properties of database objects are statically dependent on the object type. Default value is false.
// Returns a smart pointer to the root node of the hierarchical tree.
virtual OdRxModelTreeBaseNodePtr createDatabaseHierarchyTree(const OdRxObject* pDb, const bool create_properties_cache = true,
const bool class_dependent_hierarchy = false, const bool class_dependent_property = false);
// pDb - Pointer to the source database object.
// collected_properties - A pointer to a set of property names that will be added to the cache. If NULL, all properties will be cached.
// class_dependent_hierarchy - Flag to optimize the creation of a hierarchical tree. It can only be set to true if the properties of database objects with a hierarchical attribute are statically dependent on the object type. Default value is false.
// class_dependent_property - Flag to optimize cache creation. It can be set to true only if all properties of database objects are statically dependent on the object type. Default value is false.
// Returns a smart pointer to the root node of the hierarchical tree.
virtual OdRxModelTreeBaseNodePtr createDatabaseHierarchyTree(const OdRxObject* pDb, const std::set<OdString>* collected_properties,
const bool class_dependent_hierarchy = false, const bool class_dependent_property = false);
パラメータ class_dependent_hierarchy および class_dependent_property は、階層データの取得パフォーマンスを最適化するために使用されます。これらのフラグは、次の場合にのみメソッドのパフォーマンスを最適化できます。
- class_dependent_hierarchy フラグ — 階層属性を含むプロパティがオブジェクト型に静的に依存している場合。
- class_dependent_property フラグ — オブジェクトのすべてのプロパティがオブジェクト型に静的に依存している場合。
それ以外の場合、結果は予測できません。
次の表は、さまざまな ODA 製品におけるフラグの適用性を示しています。
| Drawings | Drawings (DGN) | IFC | BimNv | BimRv | |
|---|---|---|---|---|---|
| class_dependent_hierarchy | + | + | + | + | - |
| class_dependent_property | + | + | - | + | - |
Drawings Drawings (DGN) IFC BimNv BimRv class_dependent_hierarchy + + + + - class_dependent_property + + - + -
プロパティの完全なセットを持つ階層ツリーを取得する例を次に示します。
OdRxModelHierarchyTreeBasePtr pHierarchyTreeBase = OdRxModelHierarchyTreeBase::createObject();
OdRxModelTreeBaseNodePtr pTree = pHierarchyTreeBase->createDatabaseHierarchyTree(pDb, true);
ここで、pTree はベースの階層ツリーのルートノードへのポインタです。
OdRxModelTreeBaseNode オブジェクト
Common Data Access ツリー内の各 OdRxModelTreeBaseNode オブジェクトには、次の情報が含まれています。
- 一意のノード識別子 (UniqueID)
- 一意のデータベース識別子 (UniqueDatabaseID)
UniqueID と UniqueDatabaseID は、ツリー内のノードを識別するために使用されます。たとえば、UniqueID は Visualize で GiDrawables ノードと Common Data Access をバインドするために使用されます。メインデータベースの一意の識別子 (UniqueDatabaseID) は常にゼロです。ネストされたデータベースの一意の識別子は、対応するデータベースオブジェクトのアドレスです。UniqueDatabaseID は、Common Data Access ツリーを作成するときに、ノード要素が階層属性「Database」を持つ階層にある場合に設定されます。
重要: GiDrawables と UniqueDatabaseID のバインドは、1つのデータベースセッション中のみ可能です。それ以外の場合、結果は保証されません。
PropertyInfo オブジェクト
PropertyInfo 構造体には、ノードプロパティに関する情報が含まれています。各要素には次の情報が含まれています。
- プロパティ名
- ローカライズされたプロパティ名
- UI配置グループ
- UI配置ウェイト
- プロパティ値
- サブプロパティの配列
Common Data Access ツリーを作成する際、プロパティ値は次のルールを使用して入力されます。
- プロパティがRxObjectへの参照であり、OdRxDisplayAsAttributeを持つ場合、OdRxDisplayAsAttributeの値がプロパティ値として割り当てられます。
- プロパティ値がサポートされている型のリストに含まれている場合、このプロパティの対応する値が割り当てられます。
- その他の場合、値はOdRxValue::toString()によって返される値に設定されます。