Import classifications, as well as the hierarchy tree which can be browsed

This commit is contained in:
Dion Moult
2020-04-30 17:03:01 +10:00
parent 38167af916
commit ce00b3d5f8
3 changed files with 48 additions and 15 deletions
@@ -223,6 +223,7 @@ class IfcImporter():
self.auto_set_workarounds()
self.calculate_unit_scale()
self.create_project()
self.create_classifications()
self.create_spatial_hierarchy()
self.purge_diff()
self.create_type_products()
@@ -742,6 +743,40 @@ class IfcImporter():
self.project['blender'].objects.link(obj)
del self.added_data[self.project['ifc'].GlobalId]
def create_classifications(self):
for classification in self.file.by_type('IfcClassification'):
data = bpy.context.scene.BIMProperties.classifications.add()
data_map = {
'name': 'Name', 'source': 'Source',
'edition': 'Edition', 'edition_date': 'EditionDate',
'description': 'Description', 'location': 'Location',
'reference_tokens': 'ReferenceTokens'
}
for key, value in data_map.items():
if getattr(classification, value):
setattr(data, key, str(getattr(classification, value)))
classification_file = ifcopenshell.file(schema=self.file.wrapped_data.schema)
references = [classification]
while references:
entities_to_add = references
references = self.get_classification_references(references)
classification_file.add(classification)
for entity in entities_to_add:
classification_file.add(entity)
classification_filename = '{}-{}.ifc'.format(
Path(os.path.basename(self.ifc_import_settings.input_file)).stem, classification.Name)
classification_file.write(os.path.join(
bpy.context.scene.BIMProperties.schema_dir, 'classifications', classification_filename))
destination = os.path.join(bpy.context.scene.BIMProperties.schema_dir,
'classifications', '{}-{}.ifc')
def get_classification_references(self, references):
results = []
for reference in references:
results.extend(self.file.get_inverse(reference))
return results
def create_spatial_hierarchy(self):
if self.project['ifc'].IsDecomposedBy:
for rel_aggregate in self.project['ifc'].IsDecomposedBy:
@@ -1263,13 +1263,15 @@ class AddClassification(bpy.types.Operator):
if context.scene.BIMProperties.classification in schema.ifc.classifications:
data = schema.ifc.classifications[context.scene.BIMProperties.classification]
classification = context.scene.BIMProperties.classifications.add()
classification.source = data.Source
classification.edition = data.Edition
classification.edition_date = data.EditionDate
classification.name = data.Name
classification.description = data.Description
classification.location = data.Location
classification.reference_tokens = str(data.ReferenceTokens)
data_map = {
'name': 'Name', 'source': 'Source',
'edition': 'Edition', 'edition_date': 'EditionDate',
'description': 'Description', 'location': 'Location',
'reference_tokens': 'ReferenceTokens'
}
for key, value in data_map.items():
if getattr(data, value):
setattr(classification, key, str(getattr(data, value)))
return {'FINISHED'}
@@ -31,10 +31,6 @@ class IfcSchema():
self.property_files.append(ifcopenshell.open(os.path.join(self.schema_dir, 'Pset_IFC4_ADD2.ifc')))
self.classification_files = {}
classification_paths = Path(self.schema_dir).glob('classifications/*.ifc')
for path in classification_paths:
self.classification_files[os.path.basename(path).split('.')[0]] = ifcopenshell.open(path)
self.psets = {}
self.qtos = {}
self.applicable_psets = {}
@@ -64,11 +60,11 @@ class IfcSchema():
entity = prop.ApplicableEntity if prop.ApplicableEntity else 'IfcRoot'
self.applicable_psets.setdefault(entity, []).append(prop.Name)
for filename, classification_file in self.classification_files.items():
classification = classification_file.by_type('IfcClassification')[0]
self.classifications[filename] = classification
def load_classification(self, filename):
if filename not in self.classifications:
classification_path = os.path.join(self.schema_dir, 'classifications', '{}.ifc'.format(filename))
self.classification_files[filename] = ifcopenshell.open(classification_path)
self.classifications[filename] = self.classification_files[filename].by_type('IfcClassification')[0]
classification = self.classifications[filename]
return {
'name': '',