获取分层信息
本文介绍了如何从通用数据访问树中获取分层信息。有关通用数据访问的概述和要求,请参阅本系列的第一篇文章。
OdRxModelHierarchyTreeBase 类的 createDatabaseHierarchyTree 函数用于构建分层树结构。构建通用数据访问树有三种模式:
- 仅获取基础的树结构(这是最快的)。
- 获取基础的树结构以及一小组属性,这些属性例如用于在树中对对象进行分组和排序。
- 获取完整集合:一个树和所有节点属性的缓存。
…
// 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 产品的适用性。
| 图纸 | 图纸 (DGN) | IFC | BimNv | BimRv | |
|---|---|---|---|---|---|
| 类依赖层次结构 | + | + | + | + | - |
| 类依赖属性 | + | + | - | + | - |
图纸 图纸 (DGN) IFC BimNv BimRv 类依赖层次结构 + + + + - 类依赖属性 + + - + -
以下是获取具有完整属性集的层次结构树的示例:
OdRxModelHierarchyTreeBasePtr pHierarchyTreeBase = OdRxModelHierarchyTreeBase::createObject();
OdRxModelTreeBaseNodePtr pTree = pHierarchyTreeBase->createDatabaseHierarchyTree(pDb, true);
其中 pTree 是指向基础层次结构树的根节点的指针。
OdRxModelTreeBaseNode 对象
通用数据访问树中的每个 OdRxModelTreeBaseNode 对象都包含以下信息:
- 唯一节点标识符 (UniqueID)
- 唯一数据库标识符 (UniqueDatabaseID)
UniqueID 和 UniqueDatabaseID 用于标识树中的节点。例如,UniqueID 在 Visualize 中用于绑定 GiDrawables 节点和通用数据访问。主数据库的唯一标识符 (UniqueDatabaseID) 始终为零。嵌套数据库的唯一标识符是相应数据库对象的地址。当创建通用数据访问树时,如果节点元素位于具有分层属性“Database”的层次结构中,则会填充 UniqueDatabaseID。
重要提示:GiDrawables 和 UniqueDatabaseID 的绑定只能在一个数据库会话期间进行。否则,结果无法保证。
PropertyInfo 对象
PropertyInfo 结构包含有关节点属性的信息。每个元素包含以下信息:
- 属性名称
- 本地化属性名称
- UI 放置组
- UI 放置权重
- 属性值
- 子属性数组
创建通用数据访问树时,属性值将根据以下规则填充:
- 如果属性是对 RxObject 的引用并具有 OdRxDisplayAsAttribute,则将 OdRxDisplayAsAttribute 值作为属性值进行分配。
- 如果属性值包含在支持的类型列表中,则分配此属性的相应值。
- 在其他情况下,该值设置为 OdRxValue::toString() 返回的值。