Revert "Fix Attribute data type not being assigned when it makes sense"

This reverts commit 1117c8670c.
This commit is contained in:
Gorgious
2021-08-25 15:18:32 +02:00
parent a91242371b
commit 93d2699155
9 changed files with 51 additions and 24 deletions
@@ -47,10 +47,6 @@ 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)
@@ -81,9 +77,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.set_value("" if new.is_null else json.dumps(classification_data[attribute.name()]))
new.string_value = "" if new.is_null else json.dumps(classification_data[attribute.name()])
else:
new.set_value("" if new.is_null else classification_data[attribute.name()])
new.string_value = "" if new.is_null else classification_data[attribute.name()]
props.active_classification_id = self.classification
return {"FINISHED"}
@@ -166,7 +162,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.set_value("" if new.is_null else reference_data[attribute.name()])
new.string_value = "" if new.is_null else reference_data[attribute.name()]
props.active_reference_id = self.reference
return {"FINISHED"}
@@ -49,7 +49,14 @@ 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
new.set_value(new.get_value_default() if new.is_null else Data.projected_crs[attribute.name()])
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()]
props.is_map_unit_null = Data.projected_crs["MapUnit"] is None
if not props.is_map_unit_null:
@@ -72,7 +79,8 @@ 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.set_value("" if new.is_null else str(Data.map_conversion[attribute.name()]))
new.data_type = "string"
new.string_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.set_value("" if new.is_null else data[attribute.name()])
new.string_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.set_value("" if new.is_null else data[attribute.name()])
new.string_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.set_value("" if new.is_null else material_set_data[attribute.name()])
new.string_value = "" if new.is_null else material_set_data[attribute.name()]
return {"FINISHED"}
def import_attributes(self, name, prop, data):
@@ -600,7 +600,14 @@ 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
new.set_value(new.get_value_default() if new.is_null else material_set_item_data[attribute.name()])
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()]
def load_profile_attributes(self, material_set_item, material_set_item_data):
self.props.material_set_item_profile_attributes.clear()
@@ -621,12 +628,18 @@ 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 == "enum":
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":
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,12 +141,18 @@ class EnablePsetEditing(bpy.types.Operator):
new.is_optional = True
new.data_type = data_type
if data_type == "enum":
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":
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,7 +176,8 @@ 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.set_value("" if new.is_null else data[attribute.name()])
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
props.active_boundary_condition = self.boundary_condition
return {"FINISHED"}
@@ -358,7 +359,8 @@ class EnableEditingStructuralAnalysisModel(bpy.types.Operator):
if data[attribute.name()]:
new.enum_value = data[attribute.name()]
else:
new.set_value("" if new.is_null else data[attribute.name()])
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
props.active_structural_analysis_model_id = self.structural_analysis_model
return {"FINISHED"}
@@ -1095,7 +1097,8 @@ 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.set_value("" if new.is_null else data[attribute.name()])
new.string_value = "" if new.is_null else data[attribute.name()]
new.data_type = "string"
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.set_value("" if new.is_null else data[attribute.name()])
new.string_value = "" if new.is_null else data[attribute.name()]
props.active_system_id = self.system
return {"FINISHED"}
@@ -248,7 +248,8 @@ class EnableEditingUnit(bpy.types.Operator):
new.name = name
new.is_null = data[name] is None
new.is_optional = False
new.set_value(json.dumps([e for e in IfcStore.get_file().by_id(data["id"]).Dimensions]))
new.data_type = "string"
new.string_value = json.dumps([e for e in IfcStore.get_file().by_id(data["id"]).Dimensions])
return True