mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-29 03:37:21 +00:00
Specifying an IFC diff now does an incremental import
This commit is contained in:
@@ -68,6 +68,7 @@ class MaterialCreator():
|
|||||||
class IfcImporter():
|
class IfcImporter():
|
||||||
def __init__(self, ifc_import_settings):
|
def __init__(self, ifc_import_settings):
|
||||||
self.ifc_import_settings = ifc_import_settings
|
self.ifc_import_settings = ifc_import_settings
|
||||||
|
self.diff = None
|
||||||
self.file = None
|
self.file = None
|
||||||
self.settings = ifcopenshell.geom.settings()
|
self.settings = ifcopenshell.geom.settings()
|
||||||
if self.ifc_import_settings.should_import_curves:
|
if self.ifc_import_settings.should_import_curves:
|
||||||
@@ -83,14 +84,22 @@ class IfcImporter():
|
|||||||
self.material_creator = MaterialCreator()
|
self.material_creator = MaterialCreator()
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
|
self.load_diff()
|
||||||
self.load_file()
|
self.load_file()
|
||||||
self.calculate_unit_scale()
|
self.calculate_unit_scale()
|
||||||
self.create_project()
|
self.create_project()
|
||||||
self.create_spatial_hierarchy()
|
self.create_spatial_hierarchy()
|
||||||
|
self.purge_diff()
|
||||||
elements = self.file.by_type('IfcElement') + self.file.by_type('IfcSpace')
|
elements = self.file.by_type('IfcElement') + self.file.by_type('IfcSpace')
|
||||||
for element in elements:
|
for element in elements:
|
||||||
self.create_object(element)
|
self.create_object(element)
|
||||||
|
|
||||||
|
def load_diff(self):
|
||||||
|
if not self.ifc_import_settings.diff_file:
|
||||||
|
return
|
||||||
|
with open(self.ifc_import_settings.diff_file, 'r') as file:
|
||||||
|
self.diff = json.load(file)
|
||||||
|
|
||||||
def load_file(self):
|
def load_file(self):
|
||||||
print('loading file {}'.format(self.ifc_import_settings.input_file))
|
print('loading file {}'.format(self.ifc_import_settings.input_file))
|
||||||
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
|
self.file = ifcopenshell.open(self.ifc_import_settings.input_file)
|
||||||
@@ -140,7 +149,23 @@ class IfcImporter():
|
|||||||
def get_name(self, element):
|
def get_name(self, element):
|
||||||
return '{}/{}'.format(element.is_a(), element.Name)
|
return '{}/{}'.format(element.is_a(), element.Name)
|
||||||
|
|
||||||
|
def purge_diff(self):
|
||||||
|
objects_to_purge = []
|
||||||
|
for obj in bpy.data.objects:
|
||||||
|
if 'GlobalId' not in obj.BIMObjectProperties.attributes:
|
||||||
|
continue
|
||||||
|
global_id = obj.BIMObjectProperties.attributes['GlobalId'].string_value
|
||||||
|
if global_id in self.diff['deleted'] \
|
||||||
|
or global_id in self.diff['changed'].keys():
|
||||||
|
objects_to_purge.append(obj)
|
||||||
|
bpy.ops.object.delete({'selected_objects': objects_to_purge})
|
||||||
|
|
||||||
def create_object(self, element):
|
def create_object(self, element):
|
||||||
|
if self.diff:
|
||||||
|
if element.GlobalId not in self.diff['added'] \
|
||||||
|
and element.GlobalId not in self.diff['changed'].keys():
|
||||||
|
return
|
||||||
|
|
||||||
print('Creating object {}'.format(element))
|
print('Creating object {}'.format(element))
|
||||||
self.time = time.time()
|
self.time = time.time()
|
||||||
if element.is_a('IfcOpeningElement'):
|
if element.is_a('IfcOpeningElement'):
|
||||||
@@ -305,3 +330,4 @@ class IfcImportSettings:
|
|||||||
self.input_file = None
|
self.input_file = None
|
||||||
self.should_ignore_site_coordinates = False
|
self.should_ignore_site_coordinates = False
|
||||||
self.should_import_curves = False
|
self.should_import_curves = False
|
||||||
|
self.diff_file = None
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class ImportIFC(bpy.types.Operator, ImportHelper):
|
|||||||
ifc_import_settings.logger = logging.getLogger('ImportIFC')
|
ifc_import_settings.logger = logging.getLogger('ImportIFC')
|
||||||
ifc_import_settings.logger.info('Starting import')
|
ifc_import_settings.logger.info('Starting import')
|
||||||
ifc_import_settings.input_file = self.filepath
|
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_site_coordinates = bpy.context.scene.BIMProperties.import_should_ignore_site_coordinates
|
||||||
ifc_import_settings.should_import_curves = bpy.context.scene.BIMProperties.import_should_import_curves
|
ifc_import_settings.should_import_curves = bpy.context.scene.BIMProperties.import_should_import_curves
|
||||||
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
ifc_importer = import_ifc.IfcImporter(ifc_import_settings)
|
||||||
|
|||||||
Reference in New Issue
Block a user