2021-01-04 15:57:12 +11:00
|
|
|
class Data:
|
|
|
|
|
products = {}
|
2021-02-21 11:24:27 +11:00
|
|
|
spatial_elements = {}
|
2021-01-04 15:57:12 +11:00
|
|
|
|
2021-02-03 17:30:19 +11:00
|
|
|
@classmethod
|
|
|
|
|
def purge(cls):
|
|
|
|
|
cls.products = {}
|
2021-02-21 11:24:27 +11:00
|
|
|
cls.spatial_elements = {}
|
2021-02-03 17:30:19 +11:00
|
|
|
|
2021-01-04 15:57:12 +11:00
|
|
|
@classmethod
|
2021-03-25 10:48:31 +11:00
|
|
|
def load(cls, file, product_id=None):
|
2021-02-21 11:24:27 +11:00
|
|
|
if product_id:
|
2021-03-25 10:48:31 +11:00
|
|
|
return cls.load_product(file, product_id)
|
|
|
|
|
cls.load_spatial_elements(file)
|
2021-02-21 11:24:27 +11:00
|
|
|
|
|
|
|
|
@classmethod
|
2021-03-25 10:48:31 +11:00
|
|
|
def load_product(cls, file, product_id):
|
2021-01-04 15:57:12 +11:00
|
|
|
if not file:
|
|
|
|
|
return
|
|
|
|
|
product = file.by_id(product_id)
|
2021-01-05 13:16:31 +11:00
|
|
|
if not hasattr(product, "ContainedInStructure"):
|
|
|
|
|
cls.products[product_id] = None
|
|
|
|
|
elif product.ContainedInStructure:
|
2021-01-04 16:23:36 +11:00
|
|
|
structure = product.ContainedInStructure[0].RelatingStructure
|
|
|
|
|
cls.products[product_id] = {"type": structure.is_a(), "Name": structure.Name, "id": int(structure.id())}
|
|
|
|
|
else:
|
|
|
|
|
cls.products[product_id] = {"type": None, "Name": None, "id": None}
|
2021-02-21 11:24:27 +11:00
|
|
|
|
|
|
|
|
@classmethod
|
2021-03-25 10:48:31 +11:00
|
|
|
def load_spatial_elements(cls, file):
|
2021-02-21 11:24:27 +11:00
|
|
|
if not file:
|
|
|
|
|
return
|
|
|
|
|
cls.spatial_elements = {}
|
|
|
|
|
ifc_class = "IfcSpatialElement"
|
|
|
|
|
if file.schema == "IFC2X3":
|
|
|
|
|
ifc_class = "IfcSpatialStructureElement"
|
|
|
|
|
for element in file.by_type(ifc_class):
|
|
|
|
|
decomposes = None
|
|
|
|
|
if element.Decomposes:
|
|
|
|
|
decomposes = element.Decomposes[0].RelatingObject.id()
|
|
|
|
|
is_decomposed_by = []
|
|
|
|
|
if element.IsDecomposedBy:
|
|
|
|
|
for rel in element.IsDecomposedBy:
|
|
|
|
|
is_decomposed_by.extend([e.id() for e in rel.RelatedObjects])
|
|
|
|
|
cls.spatial_elements[element.id()] = {
|
|
|
|
|
"Name": element.Name,
|
|
|
|
|
"LongName": element.LongName,
|
|
|
|
|
"Decomposes": decomposes,
|
2021-09-09 21:27:23 +10:00
|
|
|
"IsDecomposedBy": is_decomposed_by,
|
2021-02-21 11:24:27 +11:00
|
|
|
}
|