mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
IfcStore cache - small refactor and doc-strings
This commit is contained in:
@@ -125,15 +125,25 @@ class IfcStore:
|
|||||||
IfcStore.path = os.path.abspath(os.path.join(bpy.path.abspath("//"), IfcStore.path))
|
IfcStore.path = os.path.abspath(os.path.join(bpy.path.abspath("//"), IfcStore.path))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cache() -> ifcopenshell.geom.serializers.hdf5 | None:
|
def generate_cache_path() -> str:
|
||||||
if IfcStore.cache is None and IfcStore.path:
|
"""Generate cache path based on the active file and it's path."""
|
||||||
prefs = tool.Blender.get_addon_preferences()
|
assert IfcStore.file
|
||||||
assert IfcStore.file
|
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
||||||
|
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
||||||
|
prefs = tool.Blender.get_addon_preferences()
|
||||||
|
cache_path = os.path.join(prefs.cache_dir, f"{ifc_hash}.h5")
|
||||||
|
return cache_path
|
||||||
|
|
||||||
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
@staticmethod
|
||||||
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
def get_cache() -> ifcopenshell.geom.serializers.hdf5 | None:
|
||||||
os.makedirs(prefs.cache_dir, exist_ok=True)
|
"""Get existing cache for the current file or create a new one.
|
||||||
IfcStore.cache_path = os.path.join(prefs.cache_dir, f"{ifc_hash}.h5")
|
|
||||||
|
.h5 cache name reflects IFC filepath and it's current header's timestamp.
|
||||||
|
"""
|
||||||
|
if IfcStore.cache is None and IfcStore.path:
|
||||||
|
cache_path = IfcStore.generate_cache_path()
|
||||||
|
os.makedirs(os.path.dirname(cache_path), exist_ok=True)
|
||||||
|
IfcStore.cache_path = cache_path
|
||||||
cache_path = Path(IfcStore.cache_path)
|
cache_path = Path(IfcStore.cache_path)
|
||||||
cache_settings = ifcopenshell.geom.settings()
|
cache_settings = ifcopenshell.geom.settings()
|
||||||
serializer_settings = ifcopenshell.geom.serializer_settings()
|
serializer_settings = ifcopenshell.geom.serializer_settings()
|
||||||
@@ -167,14 +177,11 @@ class IfcStore:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_cache() -> None:
|
def update_cache() -> None:
|
||||||
|
"""Update cache filename after timestamp was updated."""
|
||||||
if not IfcStore.cache:
|
if not IfcStore.cache:
|
||||||
return
|
return
|
||||||
assert IfcStore.cache_path
|
assert IfcStore.cache_path
|
||||||
assert IfcStore.file
|
new_cache_path = IfcStore.generate_cache_path()
|
||||||
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
|
||||||
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
|
||||||
prefs = tool.Blender.get_addon_preferences()
|
|
||||||
new_cache_path = os.path.join(prefs.cache_dir, f"{ifc_hash}.h5")
|
|
||||||
IfcStore.cache = None
|
IfcStore.cache = None
|
||||||
try:
|
try:
|
||||||
shutil.move(IfcStore.cache_path, new_cache_path)
|
shutil.move(IfcStore.cache_path, new_cache_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user