Fix Attribute data type not being assigned when it makes sense

This commit is contained in:
Gorgious
2021-08-25 14:02:49 +02:00
parent 7585ab11d0
commit 1117c8670c
9 changed files with 24 additions and 51 deletions
@@ -47,6 +47,10 @@ class AddClassification(bpy.types.Operator):
bl_label = "Add Classification"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return getClassifications(context.scene.BIMClassificationProperties, context)
def execute(self, context):
return IfcStore.execute_ifc_operator(self, context)
@@ -77,9 +81,9 @@ class EnableEditingClassification(bpy.types.Operator):
new.is_null = classification_data[attribute.name()] is None
new.is_optional = attribute.optional()
if attribute.name() == "ReferenceTokens":
new.string_value = "" if new.is_null else json.dumps(classification_data[attribute.name()])
new.set_value("" if new.is_null else json.dumps(classification_data[attribute.name()]))
else:
new.string_value = "" if new.is_null else classification_data[attribute.name()]
new.set_value("" if new.is_null else classification_data[attribute.name()])
props.active_classification_id = self.classification
return {"FINISHED"}
@@ -162,7 +166,7 @@ class EnableEditingClassificationReference(bpy.types.Operator):
new.name = attribute.name()
new.is_null = reference_data[attribute.name()] is None
new.is_optional = attribute.optional()
new.string_value = "" if new.is_null else reference_data[attribute.name()]
new.set_value("" if new.is_null else reference_data[attribute.name()])
props.active_reference_id = self.reference
return {"FINISHED"}
@@ -49,14 +49,7 @@ class EnableEditingGeoreferencing(bpy.types.Operator):
new.is_null = Data.projected_crs[attribute.name()] is None
new.is_optional = attribute.optional()
new.data_type = data_type
if data_type == "string":
new.string_value = "" if new.is_null else Data.projected_crs[attribute.name()]
elif data_type == "float":
new.float_value = 0.0 if new.is_null else Data.projected_crs[attribute.name()]
elif data_type == "integer":
new.int_value = 0 if new.is_null else Data.projected_crs[attribute.name()]
elif data_type == "boolean":
new.bool_value = False if new.is_null else Data.projected_crs[attribute.name()]
new.set_value(new.get_value_default() if new.is_null else Data.projected_crs[attribute.name()])
props.is_map_unit_null = Data.projected_crs["MapUnit"] is None
if not props.is_map_unit_null:
@@ -79,8 +72,7 @@ class EnableEditingGeoreferencing(bpy.types.Operator):
new.is_null = Data.map_conversion[attribute.name()] is None
new.is_optional = attribute.optional()
# Enforce a string data type to prevent data loss in single-precision Blender props
new.data_type = "string"
new.string_value = "" if new.is_null else str(Data.map_conversion[attribute.name()])
new.set_value("" if new.is_null else str(Data.map_conversion[attribute.name()]))
props.has_true_north = bool(Data.true_north)
if Data.true_north:
@@ -130,7 +130,7 @@ class EnableEditingGroup(bpy.types.Operator):
new.name = attribute.name()
new.is_null = data[attribute.name()] is None
new.is_optional = attribute.optional()
new.string_value = "" if new.is_null else data[attribute.name()]
new.set_value("" if new.is_null else data[attribute.name()])
props.active_group_id = self.group
return {"FINISHED"}
@@ -73,7 +73,7 @@ class EnableEditingLayer(bpy.types.Operator):
new.name = attribute.name()
new.is_null = data[attribute.name()] is None
new.is_optional = attribute.optional()
new.string_value = "" if new.is_null else data[attribute.name()]
new.set_value("" if new.is_null else data[attribute.name()])
props.active_layer_id = self.layer
return {"FINISHED"}
@@ -444,7 +444,7 @@ class EnableEditingAssignedMaterial(bpy.types.Operator):
new = props.material_set_attributes.add()
new.name = attribute.name()
new.is_null = material_set_data[attribute.name()] is None
new.string_value = "" if new.is_null else material_set_data[attribute.name()]
new.set_value("" if new.is_null else material_set_data[attribute.name()])
return {"FINISHED"}
def import_attributes(self, name, prop, data):
@@ -600,14 +600,7 @@ class EnableEditingMaterialSetItem(bpy.types.Operator):
new.name = attribute.name()
new.is_null = material_set_item_data[attribute.name()] is None
new.data_type = data_type
if data_type == "string":
new.string_value = "" if new.is_null else material_set_item_data[attribute.name()]
elif data_type == "float":
new.float_value = 0.0 if new.is_null else material_set_item_data[attribute.name()]
elif data_type == "integer":
new.int_value = 0 if new.is_null else material_set_item_data[attribute.name()]
elif data_type == "boolean":
new.bool_value = False if new.is_null else material_set_item_data[attribute.name()]
new.set_value(new.get_value_default() if new.is_null else material_set_item_data[attribute.name()])
def load_profile_attributes(self, material_set_item, material_set_item_data):
self.props.material_set_item_profile_attributes.clear()
@@ -628,18 +621,12 @@ class EnableEditingMaterialSetItem(bpy.types.Operator):
new.is_null = profile_data[attribute.name()] is None
new.is_optional = attribute.optional()
new.data_type = data_type
if data_type == "string":
new.string_value = "" if new.is_null else profile_data[attribute.name()]
elif data_type == "float":
new.float_value = 0.0 if new.is_null else profile_data[attribute.name()]
elif data_type == "integer":
new.int_value = 0 if new.is_null else profile_data[attribute.name()]
elif data_type == "boolean":
new.bool_value = False if new.is_null else profile_data[attribute.name()]
elif data_type == "enum":
if data_type == "enum":
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
if profile_data[attribute.name()]:
new.enum_value = profile_data[attribute.name()]
else:
new.set_value(new.get_value_default() if new.is_null else profile_data[attribute.name()])
# Force null to be false if the attribute is mandatory because when we first assign a profile, all of
# its fields are null (which is illegal).
@@ -141,18 +141,12 @@ class EnablePsetEditing(bpy.types.Operator):
new.is_optional = True
new.data_type = data_type
if data_type == "string":
new.string_value = "" if new.is_null else data[prop_template.Name]
elif data_type == "integer":
new.int_value = 0 if new.is_null else data[prop_template.Name]
elif data_type == "float":
new.float_value = 0.0 if new.is_null else data[prop_template.Name]
elif data_type == "boolean":
new.bool_value = False if new.is_null else data[prop_template.Name]
elif data_type == "enum":
if data_type == "enum":
new.enum_items = json.dumps(enum_items)
if data.get(prop_template.Name):
new.enum_value = data[prop_template.Name]
else:
new.set_value(new.get_value_default() if new.is_null else data[prop_template.Name])
def load_from_pset_data(self, pset_data):
for prop_id in pset_data["Properties"]:
@@ -176,8 +176,7 @@ class EnableEditingStructuralBoundaryCondition(bpy.types.Operator):
new.data_type = "float"
new.enum_value = [i for i in enum_items if i != "IfcBoolean"][0]
elif data_type == "string":
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
new.set_value("" if new.is_null else data[attribute.name()])
props.active_boundary_condition = self.boundary_condition
return {"FINISHED"}
@@ -359,8 +358,7 @@ class EnableEditingStructuralAnalysisModel(bpy.types.Operator):
if data[attribute.name()]:
new.enum_value = data[attribute.name()]
else:
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
new.set_value("" if new.is_null else data[attribute.name()])
props.active_structural_analysis_model_id = self.structural_analysis_model
return {"FINISHED"}
@@ -1097,8 +1095,7 @@ class EnableEditingBoundaryCondition(bpy.types.Operator):
new.data_type = "float"
new.enum_value = [i for i in enum_items if i != "IfcBoolean"][0]
elif data_type == "string":
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
new.set_value("" if new.is_null else data[attribute.name()])
props.active_boundary_condition_id = self.boundary_condition
return {"FINISHED"}
@@ -130,7 +130,7 @@ class EnableEditingSystem(bpy.types.Operator):
new.name = attribute.name()
new.is_null = data[attribute.name()] is None
new.is_optional = attribute.optional()
new.string_value = "" if new.is_null else data[attribute.name()]
new.set_value("" if new.is_null else data[attribute.name()])
props.active_system_id = self.system
return {"FINISHED"}
@@ -248,8 +248,7 @@ class EnableEditingUnit(bpy.types.Operator):
new.name = name
new.is_null = data[name] is None
new.is_optional = False
new.data_type = "string"
new.string_value = json.dumps([e for e in IfcStore.get_file().by_id(data["id"]).Dimensions])
new.set_value(json.dumps([e for e in IfcStore.get_file().by_id(data["id"]).Dimensions]))
return True