From 48d058a32a9f960de781193b043fe6d9cf7009eb Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 27 Jun 2024 11:49:00 +1000 Subject: [PATCH] Fix #4921. When upgrading to IFC4X3, preprocess the file to remove deprecated style assignments --- .../blenderbim/bim/module/georeference/data.py | 2 ++ src/blenderbim/blenderbim/tool/patch.py | 3 --- .../ifcopenshell/util/schema.py | 15 +++++++++++++++ src/ifcpatch/ifcpatch/recipes/Migrate.py | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/georeference/data.py b/src/blenderbim/blenderbim/bim/module/georeference/data.py index a13ee0625c..c0c9080dcc 100644 --- a/src/blenderbim/blenderbim/bim/module/georeference/data.py +++ b/src/blenderbim/blenderbim/bim/module/georeference/data.py @@ -48,6 +48,8 @@ class GeoreferenceData: @classmethod def coordinate_operation_class(cls): + if tool.Ifc.get_schema() == "IFC2X3": + return [] declaration = tool.Ifc.schema().declaration_by_name("IfcCoordinateOperation") declarations = ifcopenshell.util.schema.get_subtypes(declaration) names = [d.name() for d in declarations] diff --git a/src/blenderbim/blenderbim/tool/patch.py b/src/blenderbim/blenderbim/tool/patch.py index 7ec3edd55b..beb348eb0b 100644 --- a/src/blenderbim/blenderbim/tool/patch.py +++ b/src/blenderbim/blenderbim/tool/patch.py @@ -16,11 +16,9 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . -import os import bpy import ifcopenshell import blenderbim.core.tool -import blenderbim.tool as tool try: import ifcpatch @@ -31,6 +29,5 @@ except: class Patch(blenderbim.core.tool.Patch): @classmethod def run_migrate_patch(cls, infile, outfile, schema): - log = os.path.join(bpy.context.scene.BIMProperties.data_dir, "process.log") output = ifcpatch.execute({"input": infile, "file": ifcopenshell.open(infile), "recipe": "Migrate", "arguments": [schema]}) ifcpatch.write(output, outfile) diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 77cbbb1ee1..59015cbddd 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -223,6 +223,21 @@ class Migrator: "User": None, } + def preprocess(self, old_file, new_file): + if old_file.schema == "IFC4" and new_file.schema == "IFC4X3": + # In IFC4 -> IFC4X3, IfcPresentationStyleAssignment is deprecated + to_delete = set() + for assignment in old_file.by_type("IfcPresentationStyleAssignment"): + for styled_item in old_file.get_inverse(assignment): + if not styled_item.is_a("IfcStyledItem"): + continue + styled_item.Styles = [ + s for s in styled_item.Styles if s.is_a("IfcPresentationStyle") + ] + list(assignment.Styles) + to_delete.add(assignment) + for element in to_delete: + old_file.remove(element) + def migrate( self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file ) -> ifcopenshell.entity_instance: diff --git a/src/ifcpatch/ifcpatch/recipes/Migrate.py b/src/ifcpatch/ifcpatch/recipes/Migrate.py index 8a4c6768cd..ff5ed28e5e 100644 --- a/src/ifcpatch/ifcpatch/recipes/Migrate.py +++ b/src/ifcpatch/ifcpatch/recipes/Migrate.py @@ -46,6 +46,7 @@ class Patcher: def patch(self): self.file_patched = ifcopenshell.file(schema=self.schema) migrator = ifcopenshell.util.schema.Migrator() + migrator.preprocess(self.file, self.file_patched) for element in self.file: new_element = migrator.migrate(element, self.file_patched) print("Migrating", element)