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 ifcopenshell
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 Vector
import blenderbim.tool as tool
@@ -129,7 +129,10 @@ def add_attribute_description(attribute_blender):
if not attribute_blender.name:
return
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:
attribute_blender.description = description
@@ -128,6 +128,9 @@ class EnablePsetEditing(bpy.types.Operator):
elif metadata.data_type == "boolean":
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):
if prop_template.TemplateType in ["Q_LENGTH", "Q_AREA", "Q_VOLUME", "Q_WEIGHT", "Q_TIME"]:
return "float"
+3 -6
View File
@@ -689,9 +689,9 @@ class EditBlenderCollection(bpy.types.Operator):
class BIM_OT_show_description(bpy.types.Operator):
bl_idname = "bim.show_description"
bl_label = "Description"
ifc_class: bpy.props.StringProperty()
attr_name: bpy.props.StringProperty()
description: bpy.props.StringProperty()
url: bpy.props.StringProperty()
def invoke(self, context, event):
wm = context.window_manager
@@ -706,12 +706,9 @@ class BIM_OT_show_description(bpy.types.Operator):
wrapper = textwrap.TextWrapper(width=80)
for line in wrapper.wrap(self.description):
layout.label(text=line)
version = tool.Ifc.get_schema()
doc = ifcopenshell.util.doc.get_entity_doc(version, self.ifc_class)
url = doc.get("spec_url")
if url:
if self.url:
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url
url_op.url = self.url
@classmethod
def description(cls, context, properties):
+40 -34
View File
@@ -17,18 +17,19 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import os
import bpy
from pathlib import Path
import bpy
from bpy.types import Panel
from bpy.props import StringProperty, IntProperty, BoolProperty
from ifcopenshell.util.doc import (
get_entity_doc,
get_property_set_doc,
get_type_doc,
)
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
from blenderbim.bim.helper import IfcHeaderExtractor
from blenderbim.bim.prop import Attribute
class IFCFileSelector:
@@ -402,39 +403,44 @@ def draw_custom_context_menu(self, context):
if prop_value is None:
return
version = tool.Ifc.get_schema()
docs = {}
try:
docs = get_entity_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
layout = self.layout
if isinstance(context.button_pointer, Attribute):
print(prop, prop_name, prop_value)
description = getattr(context.button_pointer, "description", None)
ifc_class = getattr(context.button_pointer, "ifc_class", "")
if ifc_class:
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:
docs = get_type_doc(version, prop_value)
docs = get_entity_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
except (RuntimeError, AttributeError):
try:
docs = get_property_set_doc(version, prop_value)
docs = get_type_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
pass
if docs:
url = docs.get("spec_url", "")
else:
url = ""
description = getattr(context.button_pointer, "description", None)
if not url and not description:
return
layout = self.layout
layout.separator()
if 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", "")
except (RuntimeError, AttributeError):
try:
docs = get_property_set_doc(version, prop_value)
if docs is None:
raise RuntimeError
except (RuntimeError, AttributeError):
pass
if docs:
url = docs.get("spec_url", "")
if url:
layout.separator()
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url