mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
Numerical Attribute validation callback (#2562)
* Numerical attributes can now be clamped * #2545 : IfcMaterialLayer Priority is now clamped between 0 and 100 * Run black
This commit is contained in:
@@ -109,6 +109,17 @@ def import_attribute(attribute, props, data, callback=None):
|
|||||||
if data[new.name]:
|
if data[new.name]:
|
||||||
new.enum_value = data[new.name]
|
new.enum_value = data[new.name]
|
||||||
add_attribute_description(new)
|
add_attribute_description(new)
|
||||||
|
add_attribute_min_max(new)
|
||||||
|
|
||||||
|
|
||||||
|
ATTRIBUTE_MIN_MAX_CONSTRAINTS = {"IfcMaterialLayer": {"Priority": {"value_min": 0, "value_max": 100}}}
|
||||||
|
|
||||||
|
|
||||||
|
def add_attribute_min_max(attribute_blender):
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
def add_attribute_enum_items_descriptions(attribute_blender, enum_items):
|
def add_attribute_enum_items_descriptions(attribute_blender, enum_items):
|
||||||
|
|||||||
@@ -626,6 +626,7 @@ class EnableEditingMaterialSetItem(bpy.types.Operator):
|
|||||||
elif data_type == "boolean":
|
elif data_type == "boolean":
|
||||||
new.bool_value = False if new.is_null else material_set_item_data[attribute.name()]
|
new.bool_value = False if new.is_null else material_set_item_data[attribute.name()]
|
||||||
blenderbim.bim.helper.add_attribute_description(new)
|
blenderbim.bim.helper.add_attribute_description(new)
|
||||||
|
blenderbim.bim.helper.add_attribute_min_max(new)
|
||||||
|
|
||||||
|
|
||||||
class DisableEditingMaterialSetItem(bpy.types.Operator):
|
class DisableEditingMaterialSetItem(bpy.types.Operator):
|
||||||
|
|||||||
@@ -195,6 +195,23 @@ def update_attribute_value(self, context):
|
|||||||
self.is_null = False
|
self.is_null = False
|
||||||
|
|
||||||
|
|
||||||
|
def get_numerical_value(self):
|
||||||
|
value_attr = self.get_value_name()
|
||||||
|
if value_attr == "int_value":
|
||||||
|
return int(self.get(value_attr) or 0)
|
||||||
|
elif value_attr == "float_value":
|
||||||
|
return float(self.get(value_attr) or 0)
|
||||||
|
|
||||||
|
|
||||||
|
def set_numerical_value(self, new_value):
|
||||||
|
value_attr = self.get_value_name()
|
||||||
|
if new_value < self.value_min:
|
||||||
|
new_value = self.value_min
|
||||||
|
elif new_value > self.value_max:
|
||||||
|
new_value = self.value_max
|
||||||
|
self[value_attr] = new_value
|
||||||
|
|
||||||
|
|
||||||
class Attribute(PropertyGroup):
|
class Attribute(PropertyGroup):
|
||||||
tooltip = "`Right Click > IFC Description` to read the attribute description and online documentation"
|
tooltip = "`Right Click > IFC Description` to read the attribute description and online documentation"
|
||||||
name: StringProperty(name="Name")
|
name: StringProperty(name="Name")
|
||||||
@@ -203,8 +220,20 @@ class Attribute(PropertyGroup):
|
|||||||
data_type: StringProperty(name="Data Type")
|
data_type: StringProperty(name="Data Type")
|
||||||
string_value: StringProperty(name="Value", update=update_attribute_value, description=tooltip)
|
string_value: StringProperty(name="Value", update=update_attribute_value, description=tooltip)
|
||||||
bool_value: BoolProperty(name="Value", update=update_attribute_value, description=tooltip)
|
bool_value: BoolProperty(name="Value", update=update_attribute_value, description=tooltip)
|
||||||
int_value: IntProperty(name="Value", update=update_attribute_value, description=tooltip)
|
int_value: IntProperty(
|
||||||
float_value: FloatProperty(name="Value", update=update_attribute_value, description=tooltip)
|
name="Value",
|
||||||
|
description=tooltip,
|
||||||
|
update=update_attribute_value,
|
||||||
|
get=get_numerical_value,
|
||||||
|
set=set_numerical_value,
|
||||||
|
)
|
||||||
|
float_value: FloatProperty(
|
||||||
|
name="Value",
|
||||||
|
description=tooltip,
|
||||||
|
update=update_attribute_value,
|
||||||
|
get=get_numerical_value,
|
||||||
|
set=set_numerical_value,
|
||||||
|
)
|
||||||
enum_items: StringProperty(name="Value")
|
enum_items: StringProperty(name="Value")
|
||||||
enum_descriptions: CollectionProperty(type=StrProperty)
|
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)
|
||||||
@@ -213,6 +242,8 @@ class Attribute(PropertyGroup):
|
|||||||
is_uri: BoolProperty(name="Is Uri", default=False)
|
is_uri: BoolProperty(name="Is Uri", default=False)
|
||||||
is_selected: BoolProperty(name="Is Selected", default=False)
|
is_selected: BoolProperty(name="Is Selected", default=False)
|
||||||
has_calculator: BoolProperty(name="Has Calculator", default=False)
|
has_calculator: BoolProperty(name="Has Calculator", default=False)
|
||||||
|
value_min: FloatProperty(default=-10e20, description="This is used to validate int_value and float_value")
|
||||||
|
value_max: FloatProperty(default=10e20, description="This is used to validate int_value and float_value")
|
||||||
|
|
||||||
def get_value(self):
|
def get_value(self):
|
||||||
if self.is_optional and self.is_null:
|
if self.is_optional and self.is_null:
|
||||||
|
|||||||
Reference in New Issue
Block a user