mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Implement nested relationships between elements
This commit is contained in:
@@ -104,6 +104,7 @@ class IfcParser():
|
|||||||
self.spatial_structure_elements = []
|
self.spatial_structure_elements = []
|
||||||
self.spatial_structure_elements_tree = []
|
self.spatial_structure_elements_tree = []
|
||||||
self.rel_contained_in_spatial_structure = {}
|
self.rel_contained_in_spatial_structure = {}
|
||||||
|
self.rel_nests = {}
|
||||||
self.rel_defines_by_type = {}
|
self.rel_defines_by_type = {}
|
||||||
self.rel_defines_by_qto = {}
|
self.rel_defines_by_qto = {}
|
||||||
self.rel_defines_by_pset = {}
|
self.rel_defines_by_pset = {}
|
||||||
@@ -195,6 +196,11 @@ class IfcParser():
|
|||||||
self.products.append(product)
|
self.products.append(product)
|
||||||
self.product_index += 1
|
self.product_index += 1
|
||||||
|
|
||||||
|
def get_product_index_from_raw_name(self, name):
|
||||||
|
for index, product in enumerate(self.products):
|
||||||
|
if product['raw'].name == name:
|
||||||
|
return index
|
||||||
|
|
||||||
def get_product(self, selected_product, metadata_override={}, attribute_override={}):
|
def get_product(self, selected_product, metadata_override={}, attribute_override={}):
|
||||||
object = selected_product['raw']
|
object = selected_product['raw']
|
||||||
product = {
|
product = {
|
||||||
@@ -212,8 +218,12 @@ class IfcParser():
|
|||||||
product['attributes'].update(attribute_override)
|
product['attributes'].update(attribute_override)
|
||||||
product.update(metadata_override)
|
product.update(metadata_override)
|
||||||
|
|
||||||
for collection in product['raw'].users_collection:
|
if product['raw'].parent:
|
||||||
self.parse_product_collection(product, collection)
|
self.rel_nests.setdefault(
|
||||||
|
self.get_product_index_from_raw_name(product['raw'].parent.name), []).append(product)
|
||||||
|
else:
|
||||||
|
for collection in product['raw'].users_collection:
|
||||||
|
self.parse_product_collection(product, collection)
|
||||||
|
|
||||||
if object.instance_type == 'COLLECTION' \
|
if object.instance_type == 'COLLECTION' \
|
||||||
and self.is_a_rel_aggregates(self.get_ifc_class(object.instance_collection.name)):
|
and self.is_a_rel_aggregates(self.get_ifc_class(object.instance_collection.name)):
|
||||||
@@ -720,6 +730,7 @@ class IfcExporter():
|
|||||||
self.relate_definitions_to_contexts()
|
self.relate_definitions_to_contexts()
|
||||||
self.relate_objects_to_objects()
|
self.relate_objects_to_objects()
|
||||||
self.relate_elements_to_spatial_structures()
|
self.relate_elements_to_spatial_structures()
|
||||||
|
self.relate_nested_elements_to_hosted_elements()
|
||||||
self.relate_objects_to_types()
|
self.relate_objects_to_types()
|
||||||
self.relate_objects_to_qtos()
|
self.relate_objects_to_qtos()
|
||||||
self.relate_objects_to_psets()
|
self.relate_objects_to_psets()
|
||||||
@@ -1222,6 +1233,13 @@ class IfcExporter():
|
|||||||
[ self.ifc_parser.products[e]['ifc'] for e in related_elements],
|
[ self.ifc_parser.products[e]['ifc'] for e in related_elements],
|
||||||
self.ifc_parser.spatial_structure_elements[relating_structure]['ifc'])
|
self.ifc_parser.spatial_structure_elements[relating_structure]['ifc'])
|
||||||
|
|
||||||
|
def relate_nested_elements_to_hosted_elements(self):
|
||||||
|
for relating_object, related_objects in self.ifc_parser.rel_nests.items():
|
||||||
|
self.file.createIfcRelNests(
|
||||||
|
ifcopenshell.guid.new(), self.owner_history, None, None,
|
||||||
|
self.ifc_parser.products[relating_object]['ifc'],
|
||||||
|
[ o['ifc'] for o in related_objects ])
|
||||||
|
|
||||||
def relate_objects_to_types(self):
|
def relate_objects_to_types(self):
|
||||||
for relating_type, related_objects in self.ifc_parser.rel_defines_by_type.items():
|
for relating_type, related_objects in self.ifc_parser.rel_defines_by_type.items():
|
||||||
self.file.createIfcRelDefinesByType(
|
self.file.createIfcRelDefinesByType(
|
||||||
|
|||||||
Reference in New Issue
Block a user