diff --git a/src/blenderbim/blenderbim/bim/__init__.py b/src/blenderbim/blenderbim/bim/__init__.py index 177e0a1e5d..822a2738fd 100644 --- a/src/blenderbim/blenderbim/bim/__init__.py +++ b/src/blenderbim/blenderbim/bim/__init__.py @@ -131,7 +131,6 @@ classes = [ prop.GlobalId, prop.BIMObjectProperties, prop.BIMCollectionProperties, - prop.BIMMaterialProperties, prop.BIMMeshProperties, prop.BIMFacet, prop.BIMFilterGroup, @@ -224,7 +223,6 @@ def register(): bpy.types.Screen.BIMTabProperties = bpy.props.PointerProperty(type=prop.BIMTabProperties) bpy.types.Collection.BIMCollectionProperties = bpy.props.PointerProperty(type=prop.BIMCollectionProperties) bpy.types.Object.BIMObjectProperties = bpy.props.PointerProperty(type=prop.BIMObjectProperties) - bpy.types.Material.BIMMaterialProperties = bpy.props.PointerProperty(type=prop.BIMMaterialProperties) bpy.types.Mesh.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties) bpy.types.Curve.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties) bpy.types.Camera.BIMMeshProperties = bpy.props.PointerProperty(type=prop.BIMMeshProperties) @@ -283,7 +281,6 @@ def unregister(): del bpy.types.Scene.BIMProperties del bpy.types.Collection.BIMCollectionProperties del bpy.types.Object.BIMObjectProperties - del bpy.types.Material.BIMMaterialProperties del bpy.types.Mesh.BIMMeshProperties del bpy.types.Curve.BIMMeshProperties del bpy.types.Camera.BIMMeshProperties diff --git a/src/blenderbim/blenderbim/bim/handler.py b/src/blenderbim/blenderbim/bim/handler.py index f232bd6b74..709c216da3 100644 --- a/src/blenderbim/blenderbim/bim/handler.py +++ b/src/blenderbim/blenderbim/bim/handler.py @@ -51,8 +51,8 @@ def name_callback(obj, data): return if isinstance(obj, bpy.types.Material): - if obj.BIMMaterialProperties.ifc_style_id: - IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id).Name = obj.name + if ifc_definition_id := obj.BIMStyleProperties.ifc_definition_id: + IfcStore.get_file().by_id(ifc_definition_id).Name = obj.name refresh_ui_data() return diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index 399402fe07..eff273b1b6 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -219,7 +219,7 @@ class IfcStore: IfcStore.commit_link_element(data) return else: # bpy.types.Material - ifc_definition_id = obj.BIMMaterialProperties.ifc_style_id + ifc_definition_id = obj.BIMStyleProperties.ifc_definition_id try: element = IfcStore.get_file().by_id(ifc_definition_id) except RuntimeError: @@ -248,7 +248,7 @@ class IfcStore: IfcStore.guid_map[element.GlobalId] = obj if element.is_a("IfcSurfaceStyle"): - obj.BIMMaterialProperties.ifc_style_id = element.id() + obj.BIMStyleProperties.ifc_definition_id = element.id() else: obj.BIMObjectProperties.ifc_definition_id = element.id() @@ -358,8 +358,8 @@ class IfcStore: @staticmethod def purge_blender_ifc_data(obj: IFC_CONNECTED_TYPE) -> None: if isinstance(obj, bpy.types.Material): - obj.BIMMaterialProperties.ifc_style_id = 0 - else: + obj.BIMStyleProperties.ifc_definition_id = 0 + else: # bpy.types.Object obj.BIMObjectProperties.ifc_definition_id = 0 @staticmethod diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index dc0747c974..4ca0957663 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -77,8 +77,8 @@ class MaterialCreator: def load_existing_materials(self) -> None: for material in bpy.data.materials: - if material.BIMMaterialProperties.ifc_style_id: - self.styles[material.BIMMaterialProperties.ifc_style_id] = material + if ifc_definition_id := material.BIMStyleProperties.ifc_definition_id: + self.styles[ifc_definition_id] = material def get_ifc_coordinate(self, material: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]: """Get IfcTextureCoordinate""" @@ -1231,7 +1231,7 @@ class IfcImporter: self.link_element(style, blender_material) - blender_material.BIMMaterialProperties.ifc_style_id = style.id() + blender_material.BIMStyleProperties.ifc_definition_id = style.id() self.material_creator.styles[style.id()] = blender_material style_elements = tool.Style.get_style_elements(blender_material) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 3c590b9e35..506ea8f510 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -2750,7 +2750,7 @@ class AddReferenceImage(bpy.types.Operator, Operator): obj.material_slots[0].material = material bpy.ops.bim.add_style() - style = ifc_file.by_id(material.BIMMaterialProperties.ifc_style_id) + style = ifc_file.by_id(material.BIMStyleProperties.ifc_definition_id) tool.Style.assign_style_to_object(style, obj) # TODO: IfcSurfaceStyleRendering is unnecessary here, added it only because diff --git a/src/blenderbim/blenderbim/bim/module/style/data.py b/src/blenderbim/blenderbim/bim/module/style/data.py index 8e0d7571b9..7bcb05482b 100644 --- a/src/blenderbim/blenderbim/bim/module/style/data.py +++ b/src/blenderbim/blenderbim/bim/module/style/data.py @@ -98,8 +98,8 @@ class BlenderMaterialStyleData: material = obj.active_material if not material: return False - props = material.BIMMaterialProperties - style_id = props.ifc_style_id + props = material.BIMStyleProperties + style_id = props.ifc_definition_id style = tool.Ifc.get_entity_by_id(style_id) if not style: return False diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index be470861be..314d767218 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -118,7 +118,7 @@ class UnlinkStyle(bpy.types.Operator, tool.Ifc.Operator): # Don't check blender_material and style_id as this operator is only called from UI. assert isinstance(self.blender_material, str) # Type checker. material = bpy.data.materials[self.blender_material] - style_id = material.BIMMaterialProperties.ifc_style_id + style_id = material.BIMStyleProperties.ifc_definition_id style = tool.Ifc.get_entity_by_id(style_id) # Material is linked to a style from a different project. @@ -235,7 +235,7 @@ class UpdateCurrentStyle(bpy.types.Operator): for obj in context.selected_objects: for mat in obj.data.materials: - if mat and mat.BIMMaterialProperties.ifc_style_id != 0: + if mat and mat.BIMStyleProperties.ifc_definition_id != 0: mat.BIMStyleProperties.active_style_type = current_style_type return {"FINISHED"} @@ -902,7 +902,7 @@ class SaveUVToStyle(bpy.types.Operator, tool.Ifc.Operator): obj = context.active_object # find active style item - style_id = material.BIMMaterialProperties.ifc_style_id + style_id = material.BIMStyleProperties.ifc_definition_id style = ifc_file.by_id(style_id) def get_active_representation_items(): diff --git a/src/blenderbim/blenderbim/bim/module/style/prop.py b/src/blenderbim/blenderbim/bim/module/style/prop.py index 9ff98c7327..687f52f2a2 100644 --- a/src/blenderbim/blenderbim/bim/module/style/prop.py +++ b/src/blenderbim/blenderbim/bim/module/style/prop.py @@ -74,7 +74,7 @@ STYLE_TYPES = [ def update_shading_styles(self, context): for mat in bpy.data.materials: - if mat.BIMMaterialProperties.ifc_style_id == 0: + if mat.BIMStyleProperties.ifc_definition_id == 0: continue tool.Style.change_current_style_type(mat, self.active_style_type) @@ -290,6 +290,7 @@ def update_shading_style(self, context): class BIMStyleProperties(PropertyGroup): + ifc_definition_id: IntProperty(name="IFC Definition ID") # TODO: remove, as attributes already moved to styles ui attributes: CollectionProperty(name="Attributes", type=Attribute) is_editing: BoolProperty(name="Is Editing") diff --git a/src/blenderbim/blenderbim/bim/module/style/ui.py b/src/blenderbim/blenderbim/bim/module/style/ui.py index 0403a55954..9bcb3353ba 100644 --- a/src/blenderbim/blenderbim/bim/module/style/ui.py +++ b/src/blenderbim/blenderbim/bim/module/style/ui.py @@ -299,7 +299,7 @@ class BIM_PT_style(Panel): @classmethod def poll(cls, context): - return bool(tool.Ifc.get() and (material := context.material) and material.BIMMaterialProperties.ifc_style_id) + return bool(tool.Ifc.get() and (material := context.material) and material.BIMStyleProperties.ifc_definition_id) def draw(self, context): # NOTE: this UI is needed only to indicate whether blender material is linked to IFC @@ -309,7 +309,7 @@ class BIM_PT_style(Panel): BlenderMaterialStyleData.load() material = context.material - style_id = material.BIMMaterialProperties.ifc_style_id + style_id = material.BIMStyleProperties.ifc_definition_id row = self.layout.row(align=True) if style_id and not BlenderMaterialStyleData.data["is_linked_to_style"]: diff --git a/src/blenderbim/blenderbim/bim/prop.py b/src/blenderbim/blenderbim/bim/prop.py index 13b7f82078..b94dc4ef68 100644 --- a/src/blenderbim/blenderbim/bim/prop.py +++ b/src/blenderbim/blenderbim/bim/prop.py @@ -441,12 +441,6 @@ class BIMObjectProperties(PropertyGroup): rotation_checksum: StringProperty(name="Rotation Checksum") -class BIMMaterialProperties(PropertyGroup): - # In Blender, a material object can map to an IFC material, IFC surface style, or both - ifc_style_id: IntProperty(name="IFC Style ID") - shading_checksum: StringProperty(name="Shading Checksum") - - class BIMMeshProperties(PropertyGroup): ifc_definition_id: IntProperty(name="IFC Definition ID") ifc_boolean_id: IntProperty(name="IFC Boolean ID") diff --git a/src/blenderbim/blenderbim/tool/geometry.py b/src/blenderbim/blenderbim/tool/geometry.py index b12cc9a750..7dab0f6609 100644 --- a/src/blenderbim/blenderbim/tool/geometry.py +++ b/src/blenderbim/blenderbim/tool/geometry.py @@ -448,7 +448,7 @@ class Geometry(blenderbim.core.tool.Geometry): @classmethod def get_object_materials_without_styles(cls, obj: bpy.types.Object) -> list[bpy.types.Material]: return [ - s.material for s in obj.material_slots if s.material and not s.material.BIMMaterialProperties.ifc_style_id + s.material for s in obj.material_slots if s.material and not s.material.BIMStyleProperties.ifc_definition_id ] @classmethod diff --git a/src/blenderbim/blenderbim/tool/style.py b/src/blenderbim/blenderbim/tool/style.py index f32003793d..40c5936ab4 100644 --- a/src/blenderbim/blenderbim/tool/style.py +++ b/src/blenderbim/blenderbim/tool/style.py @@ -109,13 +109,13 @@ class Style(blenderbim.core.tool.Style): @classmethod def get_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]: - """Get linked IFC style based on material's BIMMaterialProperties.ifc_style_id. + """Get linked IFC style based on material's BIMStyleProperties.ifc_definition_id. Return None if material is not linked to IFC or it's linked to non-existent element. """ - if obj.BIMMaterialProperties.ifc_style_id: + if ifc_definition_id := obj.BIMStyleProperties.ifc_definition_id: try: - return tool.Ifc.get().by_id(obj.BIMMaterialProperties.ifc_style_id) + return tool.Ifc.get().by_id(ifc_definition_id) except: return @@ -124,9 +124,9 @@ class Style(blenderbim.core.tool.Style): cls, blender_material_or_style: Union[bpy.types.Material, ifcopenshell.entity_instance] ) -> dict[str, ifcopenshell.entity_instance]: if isinstance(blender_material_or_style, bpy.types.Material): - if not blender_material_or_style.BIMMaterialProperties.ifc_style_id: + if not (ifc_definition_id := blender_material_or_style.BIMStyleProperties.ifc_definition_id): return {} - style = tool.Ifc.get().by_id(blender_material_or_style.BIMMaterialProperties.ifc_style_id) + style = tool.Ifc.get().by_id(ifc_definition_id) else: style = blender_material_or_style style_elements = {} @@ -443,16 +443,16 @@ class Style(blenderbim.core.tool.Style): @classmethod def get_surface_shading_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]: - if obj.BIMMaterialProperties.ifc_style_id: - style = tool.Ifc.get().by_id(obj.BIMMaterialProperties.ifc_style_id) + if ifc_definition_id := obj.BIMStyleProperties.ifc_definition_id: + style = tool.Ifc.get().by_id(ifc_definition_id) items = [s for s in style.Styles if s.is_a() == "IfcSurfaceStyleShading"] if items: return items[0] @classmethod def get_surface_texture_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]: - if obj.BIMMaterialProperties.ifc_style_id: - style = tool.Ifc.get().by_id(obj.BIMMaterialProperties.ifc_style_id) + if ifc_definition_id := obj.BIMStyleProperties.ifc_definition_id: + style = tool.Ifc.get().by_id(ifc_definition_id) items = [s for s in style.Styles if s.is_a("IfcSurfaceStyleWithTextures")] if items: return items[0] diff --git a/src/blenderbim/test/bim/test_feature.py b/src/blenderbim/test/bim/test_feature.py index db98726a17..edce9c9c3b 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -576,14 +576,14 @@ def the_material_name_is_not_an_ifc_material(name): @then(parsers.parse('the material "{name}" is an IFC style')) def the_material_name_is_an_ifc_style(name): obj = the_material_name_exists(name) - ifc_definition_id = obj.BIMMaterialProperties.ifc_style_id + ifc_definition_id = obj.BIMStyleProperties.ifc_definition_id assert ifc_definition_id != 0, f"The material {obj} has a style ID of {ifc_definition_id}" @then(parsers.parse('the material "{name}" is not an IFC style')) def the_material_name_is_not_an_ifc_style(name): obj = the_material_name_exists(name) - ifc_definition_id = obj.BIMMaterialProperties.ifc_style_id + ifc_definition_id = obj.BIMStyleProperties.ifc_definition_id assert ifc_definition_id == 0, f"The material {obj} has a style ID of {ifc_definition_id}" diff --git a/src/blenderbim/test/tool/test_drawing.py b/src/blenderbim/test/tool/test_drawing.py index 0e6c27f53d..86d6233f0a 100644 --- a/src/blenderbim/test/tool/test_drawing.py +++ b/src/blenderbim/test/tool/test_drawing.py @@ -866,9 +866,9 @@ class TestAddReferenceImage(NewFile): material = obj.active_material assert material.name == "image" - assert material.BIMMaterialProperties.ifc_style_id != 0 + assert material.BIMStyleProperties.ifc_definition_id != 0 - style = ifc_file.by_id(material.BIMMaterialProperties.ifc_style_id) + style = ifc_file.by_id(material.BIMStyleProperties.ifc_definition_id) styled_items = set(tool.Style.get_styled_items(style)) representation_items = set(tool.Geometry.get_active_representation(obj).Items) assert styled_items == representation_items diff --git a/src/blenderbim/test/tool/test_geometry.py b/src/blenderbim/test/tool/test_geometry.py index 0837fe50a3..098843d17f 100644 --- a/src/blenderbim/test/tool/test_geometry.py +++ b/src/blenderbim/test/tool/test_geometry.py @@ -110,7 +110,7 @@ class TestGetObjectMaterialsWithoutStyles(NewFile): material1 = bpy.data.materials.new("Material") material2 = bpy.data.materials.new("Material") material3 = bpy.data.materials.new("Material") - material3.BIMMaterialProperties.ifc_style_id = 1 + material3.BIMStyleProperties.ifc_definition_id = 1 obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh")) obj.data.materials.append(material1) obj.data.materials.append(material2) @@ -237,7 +237,7 @@ class TestImportRepresentation(NewFile): tool.Ifc.set(ifc) obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh")) material = bpy.data.materials.new("Material") - material.BIMMaterialProperties.ifc_style_id = 101 + material.BIMStyleProperties.ifc_definition_id = 101 element = ifc.by_type("IfcWall")[0] tool.Ifc.link(element, obj) representation = element.Representation.Representations[0] @@ -343,7 +343,7 @@ class TestRecordObjectMaterials(NewFile): tool.Ifc.set(ifc) style = ifc.createIfcSurfaceStyle() material = bpy.data.materials.new("Material") - material.BIMMaterialProperties.ifc_style_id = style.id() + material.BIMStyleProperties.ifc_definition_id = style.id() obj.data.materials.append(material) subject.record_object_materials(obj) assert obj.data.BIMMeshProperties.material_checksum == str([style.id()]) diff --git a/src/blenderbim/test/tool/test_model.py b/src/blenderbim/test/tool/test_model.py index 48fd4c459c..430d405c1d 100644 --- a/src/blenderbim/test/tool/test_model.py +++ b/src/blenderbim/test/tool/test_model.py @@ -448,7 +448,7 @@ class TestUsingArrays(NewFile): class TestApplyIfcMaterialChanges(NewFile): def get_used_styles(self, obj: bpy.types.Object) -> set[ifcopenshell.entity_instance]: ifc_file = tool.Ifc.get() - return {ifc_file.by_id(s.material.BIMMaterialProperties.ifc_style_id) for s in obj.material_slots if s.material} + return {ifc_file.by_id(s.material.BIMStyleProperties.ifc_definition_id) for s in obj.material_slots if s.material} def get_mesh(self, obj: bpy.types.Object) -> bpy.types.Mesh: mesh = obj.data diff --git a/src/blenderbim/test/tool/test_style.py b/src/blenderbim/test/tool/test_style.py index a474a0e13c..d1a5b2a54a 100644 --- a/src/blenderbim/test/tool/test_style.py +++ b/src/blenderbim/test/tool/test_style.py @@ -125,12 +125,12 @@ class TestGetStyle(NewFile): tool.Ifc.set(ifcopenshell.file()) style = tool.Ifc.get().createIfcSurfaceStyle() obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = style.id() + obj.BIMStyleProperties.ifc_definition_id = style.id() assert subject.get_style(obj) == style def test_getting_nothing_for_a_broken_link_style(self): obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = 1 + obj.BIMStyleProperties.ifc_definition_id = 1 assert subject.get_style(obj) == None @@ -322,7 +322,7 @@ class TestGetSurfaceRenderingStyle(NewFile): style_item = tool.Ifc.get().createIfcSurfaceStyleRendering() style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item]) obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = style.id() + obj.BIMStyleProperties.ifc_definition_id = style.id() assert subject.get_surface_rendering_style(obj) == style_item @@ -361,7 +361,7 @@ class TestGetSurfaceShadingStyle(NewFile): style_item = tool.Ifc.get().createIfcSurfaceStyleShading() style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item]) obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = style.id() + obj.BIMStyleProperties.ifc_definition_id = style.id() assert subject.get_surface_shading_style(obj) == style_item def test_do_not_get_rendering_styles(self): @@ -369,7 +369,7 @@ class TestGetSurfaceShadingStyle(NewFile): style_item = tool.Ifc.get().createIfcSurfaceStyleRendering() style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item]) obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = style.id() + obj.BIMStyleProperties.ifc_definition_id = style.id() assert subject.get_surface_shading_style(obj) is None @@ -379,7 +379,7 @@ class TestGetSurfaceTextureStyle(NewFile): style_item = tool.Ifc.get().createIfcSurfaceStyleWithTextures() style = tool.Ifc.get().createIfcSurfaceStyle(Styles=[style_item]) obj = bpy.data.materials.new("Material") - obj.BIMMaterialProperties.ifc_style_id = style.id() + obj.BIMStyleProperties.ifc_definition_id = style.id() assert subject.get_surface_texture_style(obj) == style_item