Persistence

Save/Load round-trip for Tech and Shape collections.

Replaces the binary’s BSAVE / BLOAD / SAVE / LOAD / CAT / BCAT commands using a portable JSON format that round- trips losslessly through Python.

Schema (top-level keys are optional, all others must be present):

{
  "version": 1,
  "tech": { ... },          // Tech, schema below
  "shapes": [ ... ]         // list of Shape dicts
}

The Tech and Shape sub-schemas are derived directly from their dataclass fields. The serializer drops empty extra dicts to keep files readable.

reasitic.persistence.shape_to_dict(shape)[source]

Serialize a Shape to a JSON-friendly dict.

Parameters:

shape (Shape)

Return type:

dict[str, Any]

reasitic.persistence.shape_from_dict(d)[source]

Inverse of shape_to_dict().

Parameters:

d (dict[str, Any])

Return type:

Shape

reasitic.persistence.tech_to_dict(tech)[source]

Serialise a Tech to a JSON-friendly dict.

Parameters:

tech (Tech)

Return type:

dict[str, Any]

reasitic.persistence.tech_from_dict(d)[source]

Inverse of tech_to_dict().

Parameters:

d (dict[str, Any])

Return type:

Tech

reasitic.persistence.save_session(path, *, tech=None, shapes=None, viewport=None)[source]

Save a session (tech + named shapes + optional viewport) to JSON.

Parameters:
Return type:

None

reasitic.persistence.load_session(path)[source]

Load a session JSON file. Returns (tech, shapes_by_name).

Use load_viewport() to also read the optional viewport block.

Parameters:

path (str | Path)

Return type:

tuple[Tech | None, dict[str, Shape]]

reasitic.persistence.load_viewport(path)[source]

Read the optional viewport block from a session file.

Returns an empty dict if no viewport is recorded (older files).

Parameters:

path (str | Path)

Return type:

dict[str, float]