mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 03:05:33 +00:00
Fix floating precision artifacts when displaying float values in the Attributes panel
Minor fixes on previous commit
This commit is contained in:
@@ -254,6 +254,20 @@ def export_attributes(
|
|||||||
ENUM_ITEMS_DATA = Union[bpy.types.PropertyGroup, bpy.types.ID, bpy.types.Operator, bpy.types.OperatorProperties]
|
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(
|
def prop_with_search(
|
||||||
layout: bpy.types.UILayout,
|
layout: bpy.types.UILayout,
|
||||||
data: ENUM_ITEMS_DATA,
|
data: ENUM_ITEMS_DATA,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import bonsai.bim.helper
|
|||||||
from bpy.types import Panel
|
from bpy.types import Panel
|
||||||
from bonsai.bim.ifc import IfcStore
|
from bonsai.bim.ifc import IfcStore
|
||||||
from bonsai.bim.module.attribute.data import AttributesData
|
from bonsai.bim.module.attribute.data import AttributesData
|
||||||
|
import bonsai.tool as tool
|
||||||
|
|
||||||
|
|
||||||
def draw_ui(context, layout, attributes):
|
def draw_ui(context, layout, attributes):
|
||||||
@@ -43,8 +44,8 @@ def draw_ui(context, layout, attributes):
|
|||||||
for attribute in attributes:
|
for attribute in attributes:
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.label(text=attribute["name"])
|
row.label(text=attribute["name"])
|
||||||
# row.label(text=attribute["value"])
|
value = bonsai.bim.helper.get_display_value(attribute["value"])
|
||||||
op = row.operator("bim.select_similar", text=attribute["value"], icon="NONE", emboss=False)
|
op = row.operator("bim.select_similar", text=value, icon="NONE", emboss=False)
|
||||||
op.key = attribute["name"]
|
op.key = attribute["name"]
|
||||||
|
|
||||||
# TODO: reimplement, see #1222
|
# TODO: reimplement, see #1222
|
||||||
@@ -62,11 +63,7 @@ class BIM_PT_object_attributes(Panel):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if not context.active_object:
|
return tool.Ifc.get_entity(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)
|
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
if not AttributesData.is_loaded:
|
if not AttributesData.is_loaded:
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ class CancelEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Cancel Editing Door on Selected Objects"
|
bl_label = "Cancel Editing Door on Selected Objects"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
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)
|
element = tool.Ifc.get_entity(obj)
|
||||||
if not tool.Blender.Modifier.is_door(element):
|
if not tool.Blender.Modifier.is_door(element):
|
||||||
return
|
return
|
||||||
@@ -652,19 +652,22 @@ class EnableEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Enable Editing Door on Selected Objects"
|
bl_label = "Enable Editing Door on Selected Objects"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
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):
|
def _execute(self, context):
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
props = obj.BIMDoorProperties
|
self.edit_door_on_obj(obj)
|
||||||
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
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user