From 9c591ce285db619d164b4cdc5d1e5d6b7acf80c1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 10 Sep 2020 16:11:33 +1000 Subject: [PATCH] Add support for exporting addresses to the site and building --- .../blenderbim/bim/export_ifc.py | 67 +++++++++++-------- src/ifcblenderexport/blenderbim/bim/prop.py | 4 +- src/ifcblenderexport/blenderbim/bim/ui.py | 30 +++++++++ 3 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/export_ifc.py b/src/ifcblenderexport/blenderbim/bim/export_ifc.py index 6293013958..88d75cdef0 100644 --- a/src/ifcblenderexport/blenderbim/bim/export_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/export_ifc.py @@ -349,10 +349,10 @@ class IfcParser(): 'ifc': None, 'raw': obj, 'class': self.get_ifc_class(obj.name), + 'attributes': self.get_object_attributes(obj), 'relating_structure': None, 'relating_host': None, 'relating_qtos_key': None, - 'attributes': self.get_object_attributes(obj), 'has_boundary_condition': obj.BIMObjectProperties.has_boundary_condition, 'boundary_condition_class': None, 'boundary_condition_attributes': {}, @@ -752,6 +752,11 @@ class IfcParser(): def get_addresses(self, addresses): results = [] + for address in addresses: + results.append(self.get_address(address)) + return results + + def get_address(self, address): address_data_map = { 'purpose': 'Purpose', 'description': 'Description', @@ -775,28 +780,26 @@ class IfcParser(): 'electronic_mail_addresses': 'ElectronicMailAddresses', 'messaging_ids': 'MessagingIDs', } - for address in addresses: - attributes = {} - if 'IfcPostalAddress' in address.name: - merged_data_map = {**address_data_map, **postal_data_map} - if address.address_lines: - attributes['AddressLines'] = address.address_lines.split('/') - elif 'IfcTelecomAddress' in address.name: - merged_data_map = {**address_data_map, **telecom_data_map} - for key, value in telecom_list_data_map.items(): - if getattr(address, key): - attributes[value] = getattr(address, key).split(',') - for key, value in merged_data_map.items(): + attributes = {} + if 'IfcPostalAddress' in address.name: + merged_data_map = {**address_data_map, **postal_data_map} + if address.address_lines: + attributes['AddressLines'] = address.address_lines.split('/') + elif 'IfcTelecomAddress' in address.name: + merged_data_map = {**address_data_map, **telecom_data_map} + for key, value in telecom_list_data_map.items(): if getattr(address, key): - attributes[value] = getattr(address, key) - results.append({ - 'ifc': None, - 'raw': address, - 'is_postal': 'IfcPostalAddress' in address.name, - 'is_telecom': 'IfcTelecomAddress' in address.name, - 'attributes': attributes - }) - return results + attributes[value] = getattr(address, key).split(',') + for key, value in merged_data_map.items(): + if getattr(address, key): + attributes[value] = getattr(address, key) + return { + 'ifc': None, + 'raw': address, + 'is_postal': 'IfcPostalAddress' in address.name, + 'is_telecom': 'IfcTelecomAddress' in address.name, + 'attributes': attributes + } def get_document_references(self): results = {} @@ -954,7 +957,8 @@ class IfcParser(): 'ifc': None, 'raw': obj, 'class': self.get_ifc_class(obj.name), - 'attributes': self.get_object_attributes(obj) + 'attributes': self.get_object_attributes(obj), + 'address': self.get_address(obj.BIMObjectProperties.address) } self.append_product_attributes(element, obj) self.get_product_psets_qtos(element, obj, is_pset=True) @@ -1539,12 +1543,15 @@ class IfcExporter(): def create_addresses(self, addresses): results = [] for address in addresses: - if self.schema == 'IFC2X3' and 'MessagingIDs' in address['attributes']: - del address['attributes']['MessagingIDs'] - results.append(self.file.create_entity('IfcPostalAddress' if - address['is_postal'] else 'IfcTelecomAddress', **address['attributes'])) + results.append(self.create_address(address)) return results + def create_address(self, address): + if self.schema == 'IFC2X3' and 'MessagingIDs' in address['attributes']: + del address['attributes']['MessagingIDs'] + return self.file.create_entity('IfcPostalAddress' if + address['is_postal'] else 'IfcTelecomAddress', **address['attributes']) + def create_library_information(self): information = self.ifc_parser.library_information if not information: @@ -1854,6 +1861,12 @@ class IfcExporter(): 'ObjectPlacement': placement, 'Representation': self.get_product_shape(element) }) + + if element['class'] == 'IfcSite': + element['attributes'].update({'SiteAddress': self.create_address(element['address'])}) + elif element['class'] == 'IfcBuilding': + element['attributes'].update({'BuildingAddress': self.create_address(element['address'])}) + element['ifc'] = self.file.create_entity(element['class'], **element['attributes']) related_objects.append(element['ifc']) self.create_spatial_structure_elements(node['children'], element['ifc']) diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 3731c0d6c1..9603783d6f 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -1027,7 +1027,7 @@ class PropertyTemplate(PropertyGroup): class Address(PropertyGroup): - name: StringProperty(name="Name") # Stores IfcPostalAddress or IfcTelecomAddress + name: StringProperty(name="Name", default='IfcPostalAddress') # Stores IfcPostalAddress or IfcTelecomAddress purpose: EnumProperty(items=[ ('OFFICE', 'OFFICE', 'An office address.'), ('SITE', 'SITE', 'A site address.'), @@ -1385,6 +1385,8 @@ class BIMObjectProperties(PropertyGroup): boundary_condition: PointerProperty(name='Boundary Condition', type=BoundaryCondition) structural_member_connection: PointerProperty(name='Structural Member Connection', type=bpy.types.Object) representation_contexts: CollectionProperty(name="Representation Contexts", type=Subcontext) + # Address applies to IfcSite's SiteAddress and IfcBuilding's BuildingAddress + address: PointerProperty(name='Address', type=Address) class BIMDebugProperties(PropertyGroup): diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 500fafa725..a402d56003 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -63,6 +63,9 @@ class BIM_PT_object(Panel): row = layout.row() row.prop(props, 'attributes') + if 'IfcSite/' in context.active_object.name or 'IfcBuilding/' in context.active_object.name: + self.draw_addresses_ui() + row = layout.row(align=True) row.prop(props, 'relating_type') row.operator('bim.select_similar_type', icon='RESTRICT_SELECT_OFF', text='') @@ -72,6 +75,33 @@ class BIM_PT_object(Panel): row = layout.row() row.prop(props, 'material_type') + def draw_addresses_ui(self): + layout = self.layout + layout.label(text="Address:") + address = bpy.context.active_object.BIMObjectProperties.address + row = layout.row() + row.prop(address, 'purpose') + if address.purpose == 'USERDEFINED': + row = layout.row() + row.prop(address, 'user_defined_purpose') + row = layout.row() + row.prop(address, 'description') + + row = layout.row() + row.prop(address, 'internal_location') + row = layout.row() + row.prop(address, 'address_lines') + row = layout.row() + row.prop(address, 'postal_box') + row = layout.row() + row.prop(address, 'town') + row = layout.row() + row.prop(address, 'region') + row = layout.row() + row.prop(address, 'postal_code') + row = layout.row() + row.prop(address, 'country') + class BIM_PT_object_psets(Panel): bl_label = 'IFC Object Property Sets'