Pset nominal values now show their description on right click

This commit is contained in:
Gorgious
2022-10-31 19:09:58 +01:00
parent 90369bf7f7
commit 7eefb3f62f
4 changed files with 51 additions and 42 deletions
+5 -2
View File
@@ -23,7 +23,7 @@ import math
import zipfile import zipfile
import ifcopenshell import ifcopenshell
import ifcopenshell.util.attribute import ifcopenshell.util.attribute
from ifcopenshell.util.doc import get_attribute_doc, get_predefined_type_doc from ifcopenshell.util.doc import get_attribute_doc, get_predefined_type_doc, get_property_doc
from mathutils import geometry from mathutils import geometry
from mathutils import Vector from mathutils import Vector
import blenderbim.tool as tool import blenderbim.tool as tool
@@ -129,7 +129,10 @@ def add_attribute_description(attribute_blender):
if not attribute_blender.name: if not attribute_blender.name:
return return
version = tool.Ifc.get_schema() version = tool.Ifc.get_schema()
description = get_attribute_doc(version, attribute_blender.ifc_class, attribute_blender.name) try:
description = get_attribute_doc(version, attribute_blender.ifc_class, attribute_blender.name)
except RuntimeError: # It's not an Entity Attribute. Let's try a Property Set attribute.
description = get_property_doc(version, attribute_blender.ifc_class, attribute_blender.name).get("description")
if description: if description:
attribute_blender.description = description attribute_blender.description = description
@@ -128,6 +128,9 @@ class EnablePsetEditing(bpy.types.Operator):
elif metadata.data_type == "boolean": elif metadata.data_type == "boolean":
metadata.bool_value = False if metadata.is_null else data[prop_template.Name] metadata.bool_value = False if metadata.is_null else data[prop_template.Name]
metadata.ifc_class = pset_template.Name
blenderbim.bim.helper.add_attribute_description(metadata)
def get_data_type(self, prop_template): def get_data_type(self, prop_template):
if prop_template.TemplateType in ["Q_LENGTH", "Q_AREA", "Q_VOLUME", "Q_WEIGHT", "Q_TIME"]: if prop_template.TemplateType in ["Q_LENGTH", "Q_AREA", "Q_VOLUME", "Q_WEIGHT", "Q_TIME"]:
return "float" return "float"
+3 -6
View File
@@ -689,9 +689,9 @@ class EditBlenderCollection(bpy.types.Operator):
class BIM_OT_show_description(bpy.types.Operator): class BIM_OT_show_description(bpy.types.Operator):
bl_idname = "bim.show_description" bl_idname = "bim.show_description"
bl_label = "Description" bl_label = "Description"
ifc_class: bpy.props.StringProperty()
attr_name: bpy.props.StringProperty() attr_name: bpy.props.StringProperty()
description: bpy.props.StringProperty() description: bpy.props.StringProperty()
url: bpy.props.StringProperty()
def invoke(self, context, event): def invoke(self, context, event):
wm = context.window_manager wm = context.window_manager
@@ -706,12 +706,9 @@ class BIM_OT_show_description(bpy.types.Operator):
wrapper = textwrap.TextWrapper(width=80) wrapper = textwrap.TextWrapper(width=80)
for line in wrapper.wrap(self.description): for line in wrapper.wrap(self.description):
layout.label(text=line) layout.label(text=line)
version = tool.Ifc.get_schema() if self.url:
doc = ifcopenshell.util.doc.get_entity_doc(version, self.ifc_class)
url = doc.get("spec_url")
if url:
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation") url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url url_op.url = self.url
@classmethod @classmethod
def description(cls, context, properties): def description(cls, context, properties):
+39 -33
View File
@@ -17,18 +17,19 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>. # along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os import os
import bpy
from pathlib import Path from pathlib import Path
import bpy
from bpy.types import Panel
from bpy.props import StringProperty, IntProperty, BoolProperty
from ifcopenshell.util.doc import ( from ifcopenshell.util.doc import (
get_entity_doc, get_entity_doc,
get_property_set_doc, get_property_set_doc,
get_type_doc, get_type_doc,
) )
from . import ifc from . import ifc
from bpy.types import Panel
from bpy.props import StringProperty, IntProperty, BoolProperty
from blenderbim.bim.helper import IfcHeaderExtractor
import blenderbim.tool as tool import blenderbim.tool as tool
from blenderbim.bim.helper import IfcHeaderExtractor
from blenderbim.bim.prop import Attribute
class IFCFileSelector: class IFCFileSelector:
@@ -402,39 +403,44 @@ def draw_custom_context_menu(self, context):
if prop_value is None: if prop_value is None:
return return
version = tool.Ifc.get_schema() version = tool.Ifc.get_schema()
layout = self.layout
docs = {} if isinstance(context.button_pointer, Attribute):
try: print(prop, prop_name, prop_value)
docs = get_entity_doc(version, prop_value) description = getattr(context.button_pointer, "description", None)
if docs is None: ifc_class = getattr(context.button_pointer, "ifc_class", "")
raise RuntimeError if ifc_class:
except RuntimeError: try:
url = get_entity_doc(version, context.button_pointer.ifc_class).get("spec_url", "")
except RuntimeError: # It's not an Entity Attribute. Let's try a Property Set attribute.
url = get_property_set_doc(version, context.button_pointer.ifc_class).get("spec_url", "")
if description:
layout.separator()
op_description = layout.operator("bim.show_description", text="IFC Description", icon="INFO")
op_description.attr_name = getattr(context.button_pointer, "name", "")
op_description.description = description
op_description.url = url
else:
# Ugly but we can't know which type of data is under the cursor so we test everything until it clicks
try: try:
docs = get_type_doc(version, prop_value) docs = get_entity_doc(version, prop_value)
if docs is None: if docs is None:
raise RuntimeError raise RuntimeError
except RuntimeError: except (RuntimeError, AttributeError):
try: try:
docs = get_property_set_doc(version, prop_value) docs = get_type_doc(version, prop_value)
if docs is None: if docs is None:
raise RuntimeError raise RuntimeError
except RuntimeError: except (RuntimeError, AttributeError):
pass try:
if docs: docs = get_property_set_doc(version, prop_value)
url = docs.get("spec_url", "") if docs is None:
else: raise RuntimeError
url = "" except (RuntimeError, AttributeError):
pass
description = getattr(context.button_pointer, "description", None) if docs:
if not url and not description: url = docs.get("spec_url", "")
return if url:
layout = self.layout layout.separator()
layout.separator() url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
if url: url_op.url = url
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url
if description:
op_description = layout.operator("bim.show_description", text="IFC Description", icon="INFO")
op_description.description = description
op_description.ifc_class = getattr(context.button_pointer, "ifc_class", "")
op_description.attr_name = getattr(context.button_pointer, "name", "")