-
Notifications
You must be signed in to change notification settings - Fork 0
App as state machine ‐ concept of Regimes and ProcessingContext
The application operates using Regimes, which define the current state of the application and control which actions and UI elements are available, particularly on the Viewer page.
The regimes and their states are managed within RegimeProvider.ts. The Viewer component primarily reacts to these states. The existing regimes are: idling, staging, restoring, and viewing.
- This is the empty, initial default state of the application.
- When the viewer is cleared (e.g., via a "Clear Viewer" action), the application returns to the
idlingregime. - In this state, all advanced functionalities (such as exporting data or creating views) are hidden or disabled.
- This regime acts as an intermediate bridge between external pages (like the
Homepage) and theViewerpage. - The concept here is that a file has been loaded into memory, but the
Viewercomponent itself must take responsibility for rendering it. - To achieve this, the
Viewercomponent utilizes auseEffecthook that listens for thestagingregime. Once triggered, it begins processing the data and preparing it for display.
- This is the primary active state. The
useEffectmentioned in thestagingregime loads the file into the viewer, extracts the necessary views, and saves the state tree and source URL into the regime context. - It also handles deconstructed assets, saving them as
FileDataobjects with relative paths. - Once this processing is complete, the application automatically switches to the viewing regime. Most editor operations and user interactions are available and defined within this state.
- If the user navigates away from the
Viewerpage while in theviewingstate, the application must store the current workspace to allow for a seamless return. - The
restoringregime contains all the attributes of theviewingregime, but packs additional session-dependent data (like plugin snapshots). - When the
Viewerand Molstar are initialized, the system first checks if the current regime isrestoring. If so, it passes the saved session data to theinitMolstarfunction to reconstruct the workspace. - Once restored, a dedicated
useEffectsets the views and transitions the application back to theviewingregime.
The useFileManagement.tsx hooks are designed to handle loading and deconstructing files (transitioning the application from any state to staging, and then to viewing). When using the useRegime hook, you will typically only need to read the regime property to check the current state. The Viewer component manages the specialized restoring procedure internally.
Background data processing operates independently of the UI Regimes. Data processing is managed entirely by the ProcessingProvider.tsx. To trigger these processes, you typically use hooks from useFileManagement.tsx, such as the handleFile method.
This architectural separation allows users to continue interacting with the application (e.g., in the viewing regime) while heavy tasks run in the background.
Here is the step-by-step lifecycle of processing a file and moving it into the viewer:
-
Initiation: The user selects a file (e.g., a
.mapfile). The current UI regime might be set to idling. -
API Call: The
handleFilemethod is invoked. This triggers an API call to a server-side procedure to begin processing the file. - Asset Generation: Upon successful processing, the server returns an array containing the absolute file paths of the newly created local assets.
-
MVS Index Creation: The client proceeds to create a default
multipleMVS structure. This includes an index file (.mvsj) that utilizes relative paths to reference the newly created assets. (Note: These relative paths can be customized in the Settings, e.g., changing from./to./volumes/). -
Bundling: The index file and local assets are bundled into a
.mvsxarchive and exported to a temporary directory. This design supports future functionality, allowing users to choose whether to use local files or external URLs for each snapshot. -
Transition to Staging: The UI regime is updated to staging, and a
FileDataobject containing the bundled MVS data is passed into the context. -
Deconstruction & Viewing: The
useEffectinsideViewer.tsxdetects the staging regime. It loads the bundled data into the viewer, extracts the views, and unpacks the local assets as aFileDataarray alongside the state tree and source URL. Finally, the regime is switched to viewing, populating the state with all extracted data. - Immediate Export (Optional): If the user decides to export the data immediately without making any changes in the viewer, the system can efficiently reuse the saved temporary archive.
- Session Cleanup: At the end of the session, the temporary local archive and extracted assets are cleared to free up space.