From 90d5509046ca0c67bda542b7561dc3ea1f9083e4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 7 Nov 2024 10:37:10 +0500 Subject: [PATCH] Add min 0 value to IFC props in UI Basically it won't allow setting values below 0 by accident (especially important for representation item props as it may lead to a crash). 1) IfcPositiveLengthMeasure will affect bunch of props like Depth in IfcExtrudedAreaSolid. 2) IfcNonNegativeLengthMeasure will affect MaterialLayer and some profiles attributes. --- src/bonsai/bonsai/bim/helper.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index a719fac65d..6b94bd5335 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -176,18 +176,23 @@ def import_attribute( if data[new.name]: new.enum_value = data[new.name] add_attribute_description(new, data) - add_attribute_min_max(new) + add_attribute_min_max(attribute, new) ATTRIBUTE_MIN_MAX_CONSTRAINTS = {"IfcMaterialLayer": {"Priority": {"value_min": 0, "value_max": 100}}} -def add_attribute_min_max(attribute_blender: bonsai.bim.prop.Attribute) -> None: +def add_attribute_min_max(attribute: W.attribute, attribute_blender: bonsai.bim.prop.Attribute) -> None: if attribute_blender.ifc_class in ATTRIBUTE_MIN_MAX_CONSTRAINTS: constraints = ATTRIBUTE_MIN_MAX_CONSTRAINTS[attribute_blender.ifc_class].get(attribute_blender.name, {}) for constraint, value in constraints.items(): setattr(attribute_blender, constraint, value) setattr(attribute_blender, constraint + "_constraint", True) + attribute_type = attribute.type_of_attribute() + + if attribute_type._is("IfcPositiveLengthMeasure") or attribute_type._is("IfcNonNegativeLengthMeasure"): + attribute_blender.value_min = 0.0 + attribute_blender.value_min_constraint = True def add_attribute_enum_items_descriptions(