From ee5c4018239c6638ee781e822724f52d9f7851f4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 26 Jul 2024 11:45:44 +0500 Subject: [PATCH] bsdd - expose bsdd props descriptions to ui Example - https://imgur.com/a/xUUeuF5 --- .../blenderbim/bim/module/bsdd/operator.py | 10 +++++++--- src/blenderbim/blenderbim/core/bsdd.py | 8 ++++---- src/blenderbim/blenderbim/tool/bsdd.py | 15 ++++++++++++++- src/bsdd/bsdd.py | 2 ++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/bsdd/operator.py b/src/blenderbim/blenderbim/bim/module/bsdd/operator.py index 81a41261a4..42963e756c 100644 --- a/src/blenderbim/blenderbim/bim/module/bsdd/operator.py +++ b/src/blenderbim/blenderbim/bim/module/bsdd/operator.py @@ -60,10 +60,14 @@ class SearchBSDDClass(bpy.types.Operator): class GetBSDDClassificationProperties(bpy.types.Operator): bl_idname = "bim.get_bsdd_classification_properties" bl_label = "Search bSDD Class Properties" - bl_description = "Search for bSDD class properties for the currently selected class" + bl_description = ( + "Search for bSDD class properties for the currently selected class. All non-IFC properties are skipped" + ) bl_options = {"REGISTER", "UNDO"} def execute(self, context): - properties_found = core.get_class_properties(bsdd.Client(), tool.Bsdd) - self.report({"INFO"}, f"{properties_found} properties found for the active classification.") + pset_data = core.get_class_properties(bsdd.Client(), tool.Bsdd) + psets_found = len(pset_data) + props_found = sum(len(pset) for pset in pset_data.values()) + self.report({"INFO"}, f"{psets_found} psets found ({props_found} props) for the active classification.") return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/core/bsdd.py b/src/blenderbim/blenderbim/core/bsdd.py index b15b2cf539..b18eae23c5 100644 --- a/src/blenderbim/blenderbim/core/bsdd.py +++ b/src/blenderbim/blenderbim/core/bsdd.py @@ -17,7 +17,7 @@ # along with BlenderBIM Add-on. If not, see . from __future__ import annotations -from typing import TYPE_CHECKING, Optional +from typing import TYPE_CHECKING, Optional, Any if TYPE_CHECKING: import bpy @@ -26,14 +26,14 @@ if TYPE_CHECKING: import blenderbim.tool as tool -def get_class_properties(client: bsdd.Client, bsdd: tool.Bsdd) -> int: +def get_class_properties(client: bsdd.Client, bsdd: tool.Bsdd) -> dict[str, dict[str, Any]]: bsdd.clear_class_psets() data = bsdd.get_active_class_data(client) pset_dict = bsdd.get_property_dict(data) if pset_dict is None: - return 0 + return {} bsdd.create_class_psets(pset_dict) - return len(pset_dict) + return pset_dict def load_bsdd(client: bsdd.Client, bsdd: tool.Bsdd) -> None: diff --git a/src/blenderbim/blenderbim/tool/bsdd.py b/src/blenderbim/blenderbim/tool/bsdd.py index 5b07d76288..40c74a706b 100644 --- a/src/blenderbim/blenderbim/tool/bsdd.py +++ b/src/blenderbim/blenderbim/tool/bsdd.py @@ -38,6 +38,8 @@ class Bsdd(blenderbim.core.tool.Bsdd): new2.data_type = "enum" else: new2.data_type = data_type_map[data["data_type"]] + new2.description = data["description"] + new2.ifc_class = data["ifc_class"] @classmethod def create_classes(cls, class_dict: list[bsdd.ClassSearchResponseClassContractV1]) -> None: @@ -89,6 +91,10 @@ class Bsdd(blenderbim.core.tool.Bsdd): if not properties: return None + ifc_class = class_data.get("relatedIfcEntityNames") or "" + if ifc_class: + ifc_class = ifc_class[0] + psets = {} for prop in properties: if prop.get("propertyDictionaryName") != "IFC": @@ -105,7 +111,14 @@ class Bsdd(blenderbim.core.tool.Bsdd): possible_values = prop.get("allowedValues", []) or [] possible_values = [v["value"] for v in possible_values] - psets[pset][prop["name"]] = {"data_type": prop["dataType"], "possible_values": possible_values} + description = prop.get("description", "") + + psets[pset][prop["name"]] = { + "data_type": prop["dataType"], + "possible_values": possible_values, + "description": description, + "ifc_class": ifc_class, + } return psets @classmethod diff --git a/src/bsdd/bsdd.py b/src/bsdd/bsdd.py index 6effc6b5c2..583c816e28 100644 --- a/src/bsdd/bsdd.py +++ b/src/bsdd/bsdd.py @@ -31,6 +31,8 @@ __version__ = version = "0.0.0" Status = Literal["Preview", "Active", "Inactive"] ClassTypes = Literal["Class", "GroupOfProperties", "AlternativeUse", "Material"] +# NOTE: Some values in TypedDicts are actually not guaranteed to be provided +# and should be typed with NotRequired. class DictionaryContractV1(TypedDict): uri: str