@@ -19,6 +19,38 @@ class LazyLoadSessionError(Exception):
1919 pass
2020
2121
22+ # Sessiondir
23+ # - tolerance.json
24+ # - version(s).json
25+ # - states
26+ # -- <state identifier>
27+ # --- scene.json
28+ # --- settings.json
29+ # --- data
30+ # ---- <key>.json
31+ # ---- <key>.json
32+ # ---- <key>.json
33+ # ---- <key>.json
34+ #
35+ # Recording a state
36+ # 1. dump current state to active record
37+ # 2. copy active record to record with different name
38+ # 3. add record name to history
39+ # 4. remove all records forward from active (no more redo possible, only undo)
40+ #
41+ # Undo
42+ # 1. dump current state to active record
43+ # 2. set active record to current - 1, if possible
44+ # 3. clear data dict
45+ # 4. load scene (link scene object items to matching data items based on guid)
46+ #
47+ # Redo
48+ # 1. dump current state to active record
49+ # 2. set active record to current + 1, if possible
50+ # 3. clear data dict
51+ # 4. load scene (link scene object items to matching data items based on guid)
52+
53+
2254class LazyLoadSession :
2355 """Class representing a data session that can be identified by its name.
2456
@@ -41,7 +73,6 @@ class LazyLoadSession:
4173
4274 """
4375
44- # _instances = {}
4576 _instance = None
4677
4778 _name : str
@@ -297,10 +328,10 @@ def create_dirs(self) -> None:
297328 None
298329
299330 """
300- self .sessiondir .mkdir (exist_ok = True )
301- self .tempdir .mkdir (exist_ok = True )
302- self .recordsdir .mkdir (exist_ok = True )
303- self .datadir .mkdir (exist_ok = True )
331+ self .sessiondir .mkdir (exist_ok = True , parents = True )
332+ self .tempdir .mkdir (exist_ok = True , parents = True )
333+ self .recordsdir .mkdir (exist_ok = True , parents = True )
334+ self .datadir .mkdir (exist_ok = True , parents = True )
304335
305336 # =============================================================================
306337 # Tolerance
@@ -458,12 +489,40 @@ def setdefault(self, key: str, factory: Callable) -> Any:
458489 self .set (key , factory ())
459490 return self .get (key )
460491
492+ def delete (self , key : str ) -> None :
493+ """Delete a data item from storage.
494+
495+ Parameters
496+ ----------
497+ key : str
498+ The name of the item.
499+
500+ Returns
501+ -------
502+ None
503+
504+ """
505+ if key in self .data :
506+ del self .data [key ]
507+
508+ filepath = self .datadir / f"{ key } .json"
509+ if filepath .exists ():
510+ filepath .unlink ()
511+
512+ filepath = self .datadir / f"{ key } .obj"
513+ if filepath .exists ():
514+ filepath .unlink ()
515+
516+ filepath = self .datadir / f"{ key } .stp"
517+ if filepath .exists ():
518+ filepath .unlink ()
519+
461520 # =============================================================================
462521 # Complete state
463522 # =============================================================================
464523
465524 def dump (self , sessiondir : Optional [Union [str , pathlib .Path ]] = None ) -> None :
466- """Dump the data of the current session into a session directory.
525+ """Dump the data of the current session into the session directory.
467526
468527 Parameters
469528 ----------
@@ -482,6 +541,11 @@ def dump(self, sessiondir: Optional[Union[str, pathlib.Path]] = None) -> None:
482541 sessiondir = pathlib .Path (sessiondir )
483542
484543 self .dump_history ()
544+ # self.dump_scene()
545+ # self.dump_settings()
546+ # self.dump_tolerance()
547+ # self.dump_version()
548+ # self.dump_data()
485549
486550 compas .json_dump (self .scene , self .scenefile )
487551 compas .json_dump (self .settings .model_dump (), self .settingsfile )
0 commit comments