mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 11:18:18 +00:00
Show descriptions for attributes in right click context menu
This is hacky, looking for a solution to get tooltips on hover over field
This commit is contained in:
@@ -95,6 +95,7 @@ classes = [
|
|||||||
operator.SelectURIAttribute,
|
operator.SelectURIAttribute,
|
||||||
operator.EditBlenderCollection,
|
operator.EditBlenderCollection,
|
||||||
operator.BIM_OT_open_webbrowser,
|
operator.BIM_OT_open_webbrowser,
|
||||||
|
operator.BIM_OT_show_description,
|
||||||
prop.StrProperty,
|
prop.StrProperty,
|
||||||
operator.BIM_OT_enum_property_search, # /!\ Register AFTER prop.StrProperty
|
operator.BIM_OT_enum_property_search, # /!\ Register AFTER prop.StrProperty
|
||||||
prop.ObjProperty,
|
prop.ObjProperty,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import ifcopenshell.util.attribute
|
|||||||
from mathutils import geometry
|
from mathutils import geometry
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
from blenderbim.bim.prop import get_attribute_description, get_predefined_type_description
|
||||||
|
|
||||||
|
|
||||||
def draw_attributes(props, layout, copy_operator=None):
|
def draw_attributes(props, layout, copy_operator=None):
|
||||||
@@ -100,9 +101,20 @@ def import_attribute(attribute, props, data, callback=None):
|
|||||||
elif data_type == "float":
|
elif data_type == "float":
|
||||||
new.float_value = 0.0 if new.is_null else data[attribute.name()]
|
new.float_value = 0.0 if new.is_null else data[attribute.name()]
|
||||||
elif data_type == "enum":
|
elif data_type == "enum":
|
||||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
enum_items = ifcopenshell.util.attribute.get_enum_items(attribute)
|
||||||
|
new.enum_items = json.dumps(enum_items)
|
||||||
|
new.enum_descriptions.clear()
|
||||||
|
if isinstance(enum_items, dict):
|
||||||
|
enum_items = enum_items.keys()
|
||||||
|
for enum_item in enum_items:
|
||||||
|
new_enum_description = new.enum_descriptions.add()
|
||||||
|
# TODO this only supports predefined type enums. Add support for other types of enums ?
|
||||||
|
new_enum_description.name = get_predefined_type_description(data["type"], enum_item) or ""
|
||||||
if data[attribute.name()]:
|
if data[attribute.name()]:
|
||||||
new.enum_value = data[attribute.name()]
|
new.enum_value = data[attribute.name()]
|
||||||
|
description = get_attribute_description(data["type"], attribute.name())
|
||||||
|
if description:
|
||||||
|
new.description = description
|
||||||
|
|
||||||
|
|
||||||
def export_attributes(props, callback=None):
|
def export_attributes(props, callback=None):
|
||||||
|
|||||||
@@ -683,3 +683,16 @@ class EditBlenderCollection(bpy.types.Operator):
|
|||||||
else:
|
else:
|
||||||
getattr(context.bim_prop_group, self.collection).remove(self.index)
|
getattr(context.bim_prop_group, self.collection).remove(self.index)
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class BIM_OT_show_description(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.show_description"
|
||||||
|
bl_label = "Description"
|
||||||
|
description: bpy.props.StringProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def description(cls, context, properties):
|
||||||
|
return properties.description
|
||||||
|
|||||||
@@ -128,10 +128,26 @@ def get_predefined_type_description(entity, predefined_type):
|
|||||||
return get_predefined_type_doc(schema, entity, predefined_type)
|
return get_predefined_type_doc(schema, entity, predefined_type)
|
||||||
|
|
||||||
|
|
||||||
|
HARDCODED_ATTRIBUTE_DESCRIPTIONS = {
|
||||||
|
"GlobalId": "Unique Entity Identifier",
|
||||||
|
"Name": "TODO",
|
||||||
|
"Description": "TODO",
|
||||||
|
"PredefinedType": "TODO",
|
||||||
|
"ObjectType": "TODO",
|
||||||
|
"Tag": "TODO",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_attribute_description(entity, attribute):
|
def get_attribute_description(entity, attribute):
|
||||||
schema = tool.Ifc.get_schema()
|
doc = HARDCODED_ATTRIBUTE_DESCRIPTIONS.get(attribute, None)
|
||||||
if schema is not None:
|
if doc is None:
|
||||||
return get_attribute_doc(schema, entity, attribute)
|
schema = tool.Ifc.get_schema()
|
||||||
|
if schema is not None:
|
||||||
|
try:
|
||||||
|
doc = get_attribute_doc(schema, entity, attribute)
|
||||||
|
except KeyError: # This entity doesn't have any attribute or doesn't implement this attribute
|
||||||
|
pass
|
||||||
|
return doc
|
||||||
|
|
||||||
|
|
||||||
def get_property_set_docs(pset):
|
def get_property_set_docs(pset):
|
||||||
@@ -174,6 +190,10 @@ def get_attribute_enum_values(prop, context):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
items = [
|
||||||
|
(identifier, name, prop.enum_descriptions[i].name) for i, (identifier, name, _) in enumerate(items)
|
||||||
|
]
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
@@ -238,12 +258,14 @@ def update_attribute_value(self, context):
|
|||||||
|
|
||||||
class Attribute(PropertyGroup):
|
class Attribute(PropertyGroup):
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
|
description: StringProperty(name="Description")
|
||||||
data_type: StringProperty(name="Data Type")
|
data_type: StringProperty(name="Data Type")
|
||||||
string_value: StringProperty(name="Value", update=update_attribute_value)
|
string_value: StringProperty(name="Value", update=update_attribute_value)
|
||||||
bool_value: BoolProperty(name="Value", update=update_attribute_value)
|
bool_value: BoolProperty(name="Value", update=update_attribute_value)
|
||||||
int_value: IntProperty(name="Value", update=update_attribute_value)
|
int_value: IntProperty(name="Value", update=update_attribute_value)
|
||||||
float_value: FloatProperty(name="Value", update=update_attribute_value)
|
float_value: FloatProperty(name="Value", update=update_attribute_value)
|
||||||
enum_items: StringProperty(name="Value")
|
enum_items: StringProperty(name="Value")
|
||||||
|
enum_descriptions: CollectionProperty(type=StrProperty)
|
||||||
enum_value: EnumProperty(items=get_attribute_enum_values, name="Value", update=update_attribute_value)
|
enum_value: EnumProperty(items=get_attribute_enum_values, name="Value", update=update_attribute_value)
|
||||||
is_null: BoolProperty(name="Is Null")
|
is_null: BoolProperty(name="Is Null")
|
||||||
is_optional: BoolProperty(name="Is Optional")
|
is_optional: BoolProperty(name="Is Optional")
|
||||||
|
|||||||
@@ -394,8 +394,17 @@ def draw_custom_context_menu(self, context):
|
|||||||
url = get_ifc_entity_doc_url(prop_value)
|
url = get_ifc_entity_doc_url(prop_value)
|
||||||
if not bool(url):
|
if not bool(url):
|
||||||
url = get_property_set_doc_url(prop_value)
|
url = get_property_set_doc_url(prop_value)
|
||||||
|
|
||||||
|
description = getattr(context.button_pointer, "description", None)
|
||||||
|
if not url and not description:
|
||||||
|
return
|
||||||
|
layout = self.layout
|
||||||
|
layout.separator()
|
||||||
if url:
|
if url:
|
||||||
layout = self.layout
|
|
||||||
layout.separator()
|
|
||||||
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 = url
|
||||||
|
if description:
|
||||||
|
op_description = layout.operator(
|
||||||
|
"bim.show_description", text="Hover for Description", icon="INFO", emboss=False
|
||||||
|
)
|
||||||
|
op_description.description = description
|
||||||
|
|||||||
Reference in New Issue
Block a user