Merge branch 'v0.6.0' into patch-5

This commit is contained in:
s-leger
2019-11-18 04:07:26 +01:00
committed by GitHub
5 changed files with 69 additions and 24 deletions
+16 -13
View File
@@ -54,19 +54,22 @@ class TestPurger:
def purge(self): def purge(self):
for filename in Path('features/').glob('*.feature'): for filename in Path('features/').glob('*.feature'):
with open(filename, 'r') as feature_file: with open(filename, 'r') as feature_file:
with open('{}.purged'.format(filename), 'w') as new_file: old_file = feature_file.readlines()
for line in feature_file: with open(filename, 'w') as new_file:
if 'Given the IFC file ' in line: for line in old_file:
filename = line.split('"')[1] is_purged = False
print('Loading file {} ...'.format(filename)) if 'Given the IFC file ' in line:
self.file = ifcopenshell.open(filename) filename = line.split('"')[1]
if line.strip()[0:4] == 'Then': print('Loading file {} ...'.format(filename))
words = line.strip().split() self.file = ifcopenshell.open(filename)
for word in words: if line.strip()[0:4] == 'Then':
if self.is_a_global_id(word): words = line.strip().split()
if not self.does_global_id_exist(word): for word in words:
print('Test for {} purged ...'.format(word)) if self.is_a_global_id(word):
continue if not self.does_global_id_exist(word):
print('Test for {} purged ...'.format(word))
is_purged = True
if not is_purged:
new_file.write(line) new_file.write(line)
def is_a_global_id(self, word): def is_a_global_id(self, word):
+14 -6
View File
@@ -297,6 +297,7 @@ class IfcParser():
'has_scale': obj.scale != Vector((1, 1, 1)), 'has_scale': obj.scale != Vector((1, 1, 1)),
'scale': obj.scale, 'scale': obj.scale,
'class': self.get_ifc_class(obj.name), 'class': self.get_ifc_class(obj.name),
'relating_structure': None, 'relating_structure': None,
'relating_host': None, 'relating_host': None,
'relating_qtos_key': None, 'relating_qtos_key': None,
@@ -669,10 +670,16 @@ class IfcParser():
'is_material_layer_set': True if 'IsMaterialLayerSet' in obj.keys() else False, 'is_material_layer_set': True if 'IsMaterialLayerSet' in obj.keys() else False,
'is_material_constituent_set': True if 'IsMaterialConstituentSet' in obj.keys() else False, 'is_material_constituent_set': True if 'IsMaterialConstituentSet' in obj.keys() else False,
'attributes': {'Name': slot.material.name}, 'attributes': {'Name': slot.material.name},
'layer_attributes': {key[3:]: slot.material[key] for key in 'layer_attributes': {
slot.material.keys() if key[0:3] == 'Ifc'}, key[3:]: slot.material[key]
'constituent_attributes': {key[3:]: slot.material[key] for key in for key in slot.material.keys()
slot.material.keys() if key[0:3] == 'Ifc'} if key[0:3] == 'Ifc'
},
'constituent_attributes': {
key[3:]: slot.material[key]
for key in slot.material.keys()
if key[0:3] == 'Ifc'
}
} }
return results return results
@@ -733,8 +740,8 @@ class IfcParser():
'location': obj.translation, 'location': obj.translation,
'up_axis': obj.matrix_world.to_quaternion() @ Vector((0, 0, 1)), 'up_axis': obj.matrix_world.to_quaternion() @ Vector((0, 0, 1)),
'forward_axis': obj.matrix_world.to_quaternion() @ Vector((1, 0, 0)), 'forward_axis': obj.matrix_world.to_quaternion() @ Vector((1, 0, 0)),
'psets': ['{}/{}'.format(pset.name, pset.file) for pset in 'psets': ['{}/{}'.format(pset.name, pset.file)
obj.BIMObjectProperties.psets], for pset in obj.BIMObjectProperties.psets],
'class': self.get_ifc_class(obj.name), 'class': self.get_ifc_class(obj.name),
'representations': self.get_object_representation_names(obj), 'representations': self.get_object_representation_names(obj),
'attributes': self.get_object_attributes(obj) 'attributes': self.get_object_attributes(obj)
@@ -1381,6 +1388,7 @@ class IfcExporter():
shape_representation.RepresentationType, shape_representation.RepresentationType,
[mapped_item]) [mapped_item])
def calculate_quantities(self, qto_name, obj): def calculate_quantities(self, qto_name, obj):
quantities = [] quantities = []
for index, vg in enumerate(obj.vertex_groups): for index, vg in enumerate(obj.vertex_groups):
@@ -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
+8 -5
View File
@@ -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)
@@ -224,13 +225,15 @@ class SelectAudited(bpy.types.Operator):
bl_label = 'Select Audited' bl_label = 'Select Audited'
def execute(self, context): def execute(self, context):
audited_global_ids = []
with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt') as file: with open(bpy.context.scene.BIMProperties.data_dir + 'audit.txt') as file:
for line in file: for line in file:
for object in bpy.context.visible_objects: audited_global_ids.append(line.split(' ')[3])
index = object.BIMObjectProperties.attributes.find('GlobalId') for object in bpy.context.visible_objects:
if index != -1 \ index = object.BIMObjectProperties.attributes.find('GlobalId')
and object.BIMObjectProperties.attributes[index].string_value == line.split(' ')[3]: if index != -1 \
object.select_set(True) and object.BIMObjectProperties.attributes[index].string_value in audited_global_ids:
object.select_set(True)
return {'FINISHED'} return {'FINISHED'}
class QuickProjectSetup(bpy.types.Operator): class QuickProjectSetup(bpy.types.Operator):
+5
View File
@@ -1959,6 +1959,11 @@ IfcSchema::IfcProduct::list::ptr IfcGeom::Kernel::products_represented_by(const
} }
IfcSchema::IfcRepresentationMap::list::ptr maps = representation->RepresentationMap(); IfcSchema::IfcRepresentationMap::list::ptr maps = representation->RepresentationMap();
if (products->size() && maps->size()) {
Logger::Warning("Representation used by IfcRepresentationMap and IfcProductDefinitionShape", representation);
}
if (maps->size() == 1) { if (maps->size() == 1) {
IfcSchema::IfcRepresentationMap* map = *maps->begin(); IfcSchema::IfcRepresentationMap* map = *maps->begin();
if (is_identity_transform(map->MappingOrigin())) { if (is_identity_transform(map->MappingOrigin())) {