Fix floating precision artifacts when displaying float values in the Attributes panel

Minor fixes on previous commit
This commit is contained in:
Gorgious56
2025-01-08 10:28:27 +01:00
parent 519e667464
commit 5c3f0f0df9
3 changed files with 33 additions and 19 deletions
+14
View File
@@ -254,6 +254,20 @@ def export_attributes(
ENUM_ITEMS_DATA = Union[bpy.types.PropertyGroup, bpy.types.ID, bpy.types.Operator, bpy.types.OperatorProperties]
def get_display_value(value: str, float_decimal_precision: int = 6) -> str:
"""
This will get rid of the floating point precision artifacts in float values stored as a string
"""
try:
digits = len(value.split(".")[1])
value = float(value)
if digits > 6: # Maximal decimal float precision
value = round(value, float_decimal_precision)
except (ValueError, IndexError): # Not castable to a float or no decimal places (eg integer)
pass
return str(value)
def prop_with_search(
layout: bpy.types.UILayout,
data: ENUM_ITEMS_DATA,
+4 -7
View File
@@ -20,6 +20,7 @@ import bonsai.bim.helper
from bpy.types import Panel
from bonsai.bim.ifc import IfcStore
from bonsai.bim.module.attribute.data import AttributesData
import bonsai.tool as tool
def draw_ui(context, layout, attributes):
@@ -43,8 +44,8 @@ def draw_ui(context, layout, attributes):
for attribute in attributes:
row = layout.row(align=True)
row.label(text=attribute["name"])
# row.label(text=attribute["value"])
op = row.operator("bim.select_similar", text=attribute["value"], icon="NONE", emboss=False)
value = bonsai.bim.helper.get_display_value(attribute["value"])
op = row.operator("bim.select_similar", text=value, icon="NONE", emboss=False)
op.key = attribute["name"]
# TODO: reimplement, see #1222
@@ -62,11 +63,7 @@ class BIM_PT_object_attributes(Panel):
@classmethod
def poll(cls, context):
if not context.active_object:
return False
if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id):
return False
return bool(context.active_object.BIMObjectProperties.ifc_definition_id)
return tool.Ifc.get_entity(context.active_object)
def draw(self, context):
if not AttributesData.is_loaded:
+15 -12
View File
@@ -584,7 +584,7 @@ class CancelEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Cancel Editing Door on Selected Objects"
bl_options = {"REGISTER", "UNDO"}
def cancel_editing_door_on_object(self, obj, element):
def cancel_editing_door_on_object(self, obj):
element = tool.Ifc.get_entity(obj)
if not tool.Blender.Modifier.is_door(element):
return
@@ -652,19 +652,22 @@ class EnableEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Enable Editing Door on Selected Objects"
bl_options = {"REGISTER", "UNDO"}
def edit_door_on_obj(self, obj):
element = tool.Ifc.get_entity(obj)
if not tool.Blender.Modifier.is_door(element):
return
props = obj.BIMDoorProperties
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Door", "Data"))
data.update(data.pop("lining_properties"))
data.update(data.pop("panel_properties"))
# required since we could load pset from .ifc and BIMDoorProperties won't be set
props.set_props_kwargs_from_ifc_data(data)
props.is_editing = True
def _execute(self, context):
for obj in context.selected_objects:
props = obj.BIMDoorProperties
element = tool.Ifc.get_entity(obj)
if not tool.Blender.Modifier.is_door(element):
continue
data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Door", "Data"))
data.update(data.pop("lining_properties"))
data.update(data.pop("panel_properties"))
# required since we could load pset from .ifc and BIMDoorProperties won't be set
props.set_props_kwargs_from_ifc_data(data)
props.is_editing = True
self.edit_door_on_obj(obj)
return {"FINISHED"}