2020-05-07 16:57:14 +10:00
|
|
|
import bpy
|
|
|
|
|
import ifcopenshell
|
2021-02-23 19:19:06 +11:00
|
|
|
import blenderbim.bim.handler
|
2020-05-07 16:57:14 +10:00
|
|
|
|
2020-11-01 20:08:48 +07:00
|
|
|
|
|
|
|
|
class IfcStore:
|
|
|
|
|
path = ""
|
2020-03-30 12:47:14 +11:00
|
|
|
file = None
|
2021-01-07 10:47:50 +11:00
|
|
|
schema = None
|
2021-02-03 13:47:09 +11:00
|
|
|
id_map = {}
|
|
|
|
|
guid_map = {}
|
2021-03-15 20:32:47 +11:00
|
|
|
edited_objs = set()
|
2020-11-01 20:08:48 +07:00
|
|
|
pset_template_path = ""
|
2020-04-24 18:05:59 +10:00
|
|
|
pset_template_file = None
|
2021-04-20 12:45:20 +10:00
|
|
|
library_path = ""
|
|
|
|
|
library_file = None
|
2020-05-07 16:57:14 +10:00
|
|
|
|
2021-04-22 18:37:41 +10:00
|
|
|
@staticmethod
|
|
|
|
|
def purge():
|
|
|
|
|
IfcStore.path = ""
|
|
|
|
|
IfcStore.file = None
|
|
|
|
|
IfcStore.schema = None
|
|
|
|
|
IfcStore.id_map = {}
|
|
|
|
|
IfcStore.guid_map = {}
|
|
|
|
|
IfcStore.edited_objs = set()
|
|
|
|
|
IfcStore.pset_template_path = ""
|
|
|
|
|
IfcStore.pset_template_file = None
|
|
|
|
|
IfcStore.library_path = ""
|
|
|
|
|
IfcStore.library_file = None
|
|
|
|
|
|
2020-05-07 16:57:14 +10:00
|
|
|
@staticmethod
|
|
|
|
|
def get_file():
|
|
|
|
|
if IfcStore.file is None:
|
|
|
|
|
IfcStore.path = bpy.context.scene.BIMProperties.ifc_file
|
2020-12-30 13:50:10 +11:00
|
|
|
if IfcStore.path:
|
2021-02-03 19:15:25 +11:00
|
|
|
try:
|
|
|
|
|
IfcStore.file = ifcopenshell.open(IfcStore.path)
|
|
|
|
|
except:
|
|
|
|
|
IfcStore.file
|
2020-05-07 16:57:14 +10:00
|
|
|
return IfcStore.file
|
2021-01-07 10:47:50 +11:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get_schema():
|
|
|
|
|
if IfcStore.file is None:
|
|
|
|
|
return
|
|
|
|
|
elif IfcStore.schema is None:
|
|
|
|
|
IfcStore.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(IfcStore.file.schema)
|
|
|
|
|
return IfcStore.schema
|
2021-02-03 13:47:09 +11:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def link_element(element, obj):
|
|
|
|
|
IfcStore.id_map[element.id()] = obj
|
2021-02-06 15:14:38 +11:00
|
|
|
if hasattr(element, "GlobalId"):
|
|
|
|
|
IfcStore.guid_map[element.GlobalId] = obj
|
2021-02-03 13:47:09 +11:00
|
|
|
obj.BIMObjectProperties.ifc_definition_id = element.id()
|
2021-02-23 19:19:06 +11:00
|
|
|
blenderbim.bim.handler.subscribe_to(obj, "mode", blenderbim.bim.handler.mode_callback)
|
2021-02-23 21:15:27 +11:00
|
|
|
blenderbim.bim.handler.subscribe_to(obj, "name", blenderbim.bim.handler.name_callback)
|
2021-02-03 13:47:09 +11:00
|
|
|
|
|
|
|
|
@staticmethod
|
2021-05-12 22:20:58 +10:00
|
|
|
def unlink_element(element=None, obj=None):
|
|
|
|
|
if element is None:
|
|
|
|
|
try:
|
|
|
|
|
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if element:
|
|
|
|
|
del IfcStore.id_map[element.id()]
|
|
|
|
|
else:
|
|
|
|
|
del IfcStore.id_map[obj.BIMObjectProperties.ifc_definition_id]
|
|
|
|
|
|
|
|
|
|
if element and hasattr(element, "GlobalId"):
|
2021-02-06 15:14:38 +11:00
|
|
|
del IfcStore.guid_map[element.GlobalId]
|
2021-05-12 22:20:58 +10:00
|
|
|
|
2021-02-03 13:47:09 +11:00
|
|
|
if obj:
|
|
|
|
|
obj.BIMObjectProperties.ifc_definition_id = 0
|