From 9e67b05df9acd50a0e66372fc7a6bef379d40311 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 22 Jan 2020 21:43:18 +1100 Subject: [PATCH] Add workaround for importing wrongly geolocated Revit buildings. --- src/ifcblenderexport/blenderbim/import_ifc.py | 47 +++++++++++++------ src/ifcblenderexport/blenderbim/operator.py | 1 + src/ifcblenderexport/blenderbim/prop.py | 1 + src/ifcblenderexport/blenderbim/ui.py | 2 + 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/import_ifc.py b/src/ifcblenderexport/blenderbim/import_ifc.py index 314e791c04..d7bcf38b2f 100644 --- a/src/ifcblenderexport/blenderbim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/import_ifc.py @@ -160,11 +160,13 @@ class IfcImporter(): return if applications[0].ApplicationIdentifier == 'Revit': self.ifc_import_settings.should_treat_styled_item_as_material = True - if self.is_site_far_away(): + if self.is_ifc_class_far_away('IfcSite'): self.ifc_import_settings.should_ignore_site_coordinates = True + if self.is_ifc_class_far_away('IfcBuilding'): + self.ifc_import_settings.should_ignore_building_coordinates = True - def is_site_far_away(self): - for site in self.file.by_type('IfcSite'): + def is_ifc_class_far_away(self, ifc_class): + for site in self.file.by_type(ifc_class): if not site.ObjectPlacement \ or not site.ObjectPlacement.RelativePlacement \ or not site.ObjectPlacement.RelativePlacement.Location: @@ -177,18 +179,34 @@ class IfcImporter(): return True def patch_ifc(self): + project = self.file.by_type('IfcProject')[0] if self.ifc_import_settings.should_ignore_site_coordinates: - project = self.file.by_type('IfcProject')[0] - rel_aggregates = project.IsDecomposedBy - for rel_aggregate in rel_aggregates: - for site in rel_aggregate.RelatedObjects: - if not site.is_a('IfcSite'): - continue - site.ObjectPlacement.RelativePlacement.Location.Coordinates = (0., 0., 0.) - if site.ObjectPlacement.RelativePlacement.Axis: - site.ObjectPlacement.RelativePlacement.Axis.DirectionRatios = (0., 0., 1.) - if site.ObjectPlacement.RelativePlacement.RefDirection: - site.ObjectPlacement.RelativePlacement.RefDirection.DirectionRatios = (1., 0., 0.) + sites = self.find_decomposed_ifc_class(project, 'IfcSite') + for site in sites: + self.patch_placement_to_origin(site) + if self.ifc_import_settings.should_ignore_building_coordinates: + buildings = self.find_decomposed_ifc_class(project, 'IfcBuilding') + for building in buildings: + self.patch_placement_to_origin(building) + + def find_decomposed_ifc_class(self, element, ifc_class): + results = [] + rel_aggregates = element.IsDecomposedBy + if not rel_aggregates: + return results + for rel_aggregate in rel_aggregates: + for part in rel_aggregate.RelatedObjects: + if part.is_a(ifc_class): + results.append(part) + results.extend(self.find_decomposed_ifc_class(part, ifc_class)) + return results + + def patch_placement_to_origin(self, element): + element.ObjectPlacement.RelativePlacement.Location.Coordinates = (0., 0., 0.) + if element.ObjectPlacement.RelativePlacement.Axis: + element.ObjectPlacement.RelativePlacement.Axis.DirectionRatios = (0., 0., 1.) + if element.ObjectPlacement.RelativePlacement.RefDirection: + element.ObjectPlacement.RelativePlacement.RefDirection.DirectionRatios = (1., 0., 0.) def create_products_legacy(self): elements = self.file.by_type('IfcElement') + self.file.by_type('IfcSpace') @@ -526,6 +544,7 @@ class IfcImportSettings: self.input_file = None self.should_auto_set_workarounds = True self.should_ignore_site_coordinates = False + self.should_ignore_building_coordinates = False self.should_import_curves = False self.should_treat_styled_item_as_material = False self.should_use_cpu_multiprocessing = False diff --git a/src/ifcblenderexport/blenderbim/operator.py b/src/ifcblenderexport/blenderbim/operator.py index 78efa1ee78..d7dcd38736 100644 --- a/src/ifcblenderexport/blenderbim/operator.py +++ b/src/ifcblenderexport/blenderbim/operator.py @@ -78,6 +78,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper): ifc_import_settings.input_file = self.filepath ifc_import_settings.diff_file = bpy.context.scene.BIMProperties.diff_json_file ifc_import_settings.should_ignore_site_coordinates = bpy.context.scene.BIMProperties.import_should_ignore_site_coordinates + ifc_import_settings.should_ignore_building_coordinates = bpy.context.scene.BIMProperties.import_should_ignore_building_coordinates ifc_import_settings.should_import_curves = bpy.context.scene.BIMProperties.import_should_import_curves ifc_import_settings.should_auto_set_workarounds = bpy.context.scene.BIMProperties.import_should_auto_set_workarounds ifc_import_settings.should_treat_styled_item_as_material = bpy.context.scene.BIMProperties.import_should_treat_styled_item_as_material diff --git a/src/ifcblenderexport/blenderbim/prop.py b/src/ifcblenderexport/blenderbim/prop.py index affd3452c9..bedc1667e6 100644 --- a/src/ifcblenderexport/blenderbim/prop.py +++ b/src/ifcblenderexport/blenderbim/prop.py @@ -330,6 +330,7 @@ class BIMProperties(PropertyGroup): export_should_export_all_materials_as_styled_items: BoolProperty(name="Export All Materials as Styled Items", default=False) export_should_use_presentation_style_assignment: BoolProperty(name="Export with Presentation Style Assignment", default=False) import_should_ignore_site_coordinates: BoolProperty(name="Import Ignoring Site Coordinates", default=False) + import_should_ignore_building_coordinates: BoolProperty(name="Import Ignoring Building Coordinates", default=False) import_should_import_curves: BoolProperty(name="Import Curves", default=False) import_should_auto_set_workarounds: BoolProperty(name="Automatically Set Vendor Workarounds", default=True) import_should_treat_styled_item_as_material: BoolProperty(name="Import Treating Styled Item as Material", default=False) diff --git a/src/ifcblenderexport/blenderbim/ui.py b/src/ifcblenderexport/blenderbim/ui.py index fa32f02ca0..869b2aa21a 100644 --- a/src/ifcblenderexport/blenderbim/ui.py +++ b/src/ifcblenderexport/blenderbim/ui.py @@ -596,4 +596,6 @@ class BIM_PT_mvd(Panel): row = layout.row() row.prop(bim_properties, "import_should_ignore_site_coordinates") row = layout.row() + row.prop(bim_properties, "import_should_ignore_building_coordinates") + row = layout.row() row.prop(bim_properties, "import_should_treat_styled_item_as_material")