Prioritize existing data types for templates props for safety

Noticed working on #5596 and #5708 a few issue when pset template is changing the prop types.

E.g. prop had string data type and now template suggests that it should be a float.
Previously, it might error trying to cast a string to a float. Now it will show a float until user will set it to null, then next time it will be loaded from the template data type.

Another example - prop was a string and now it's a boolean. Previously, it would be cast to boolean implicitly. E.g. "test" -> bool("test") -> True. And if user wouldn't be paying attention then enabling pset editing and saving it would make them lose "test" value.

Now - https://imgchest.com/p/na7ke99wb78
Before - https://imgchest.com/p/5xy23rr3z4l
This commit is contained in:
Andrej730
2024-11-07 14:56:51 +05:00
parent 3ad713d5c6
commit 832ad6d318
3 changed files with 27 additions and 7 deletions
@@ -411,14 +411,14 @@ class Usecase:
raise TypeError(f"'{self.settings['pset']}' is not a valid pset")
def get_primary_measure_type(self, name, old_value=None, new_value=None):
if old_value:
return old_value.is_a()
if self.pset_template:
for prop_template in self.pset_template.HasPropertyTemplates:
if prop_template.Name != name:
continue
return prop_template.PrimaryMeasureType or "IfcLabel"
if old_value:
return old_value.is_a()
elif new_value and hasattr(new_value, "is_a"):
if new_value and hasattr(new_value, "is_a"):
return new_value.is_a()
elif new_value is not None:
if isinstance(new_value, str):
@@ -394,6 +394,7 @@ def get_properties(
"id": prop.id(),
"class": prop.is_a(),
"value": results[prop_name],
"value_type": v.is_a() if v else None,
}
elif ifc_class == "IfcPropertyEnumeratedValue":
# 2 IfcPropertyEnumeratedValue.EnumerationValues