Resulable besim handof so recompiling model does not give second besim window
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QObject, Signal, Qt
|
||||
@@ -39,8 +40,9 @@ class SimulationFileController(QObject):
|
||||
self.runtime_changed.emit()
|
||||
logger.info("Created new simulation")
|
||||
|
||||
def open(self, path: str | Path, *, component: str | None = None, simulation: str | None = None, backed_by_file: bool = True, compiled_model: CompiledModel | None = None) -> None:
|
||||
def open(self, path: str | Path, *, component: str | None = None, simulation: str | None = None, backed_by_file: bool = True, compiled_model: CompiledModel | None = None, preserve_plots: bool = False) -> None:
|
||||
file_path = Path(path)
|
||||
plot_tabs = deepcopy(self.root.plot_tabs) if preserve_plots and self.root is not None else None
|
||||
try:
|
||||
if file_path.suffix.lower() == ".bes" or simulation_files.is_simulation_json(file_path):
|
||||
self.root = simulation_files.load(file_path)
|
||||
@@ -52,11 +54,20 @@ class SimulationFileController(QObject):
|
||||
except (OSError, RuntimeError, TypeError, ValueError):
|
||||
logger.exception("Could not open simulation %s", file_path)
|
||||
raise
|
||||
if preserve_plots and self.root is not None:
|
||||
if plot_tabs is not None:
|
||||
self.root.plot_tabs = plot_tabs
|
||||
self.root.current_end_time = self.root.settings.start_time
|
||||
self.root.results.clear()
|
||||
self._log_compilation()
|
||||
self._update_window()
|
||||
self.runtime_changed.emit()
|
||||
logger.info("Opened simulation: %s", file_path)
|
||||
|
||||
def open_handoff(self, path: str | Path, compiled_model: CompiledModel) -> None:
|
||||
self.open(path, backed_by_file=False, compiled_model=compiled_model, preserve_plots=True)
|
||||
logger.info("Accepted simulation handoff and reset to time %s", self.root.current_end_time if self.root is not None else "unknown")
|
||||
|
||||
def open_dialog(self) -> None:
|
||||
filename, _ = QFileDialog.getOpenFileName(self.window, "Open Simulation", "", "Simulation and BEdit files (*.bes *.beb *.json)")
|
||||
if not filename:
|
||||
|
||||
Reference in New Issue
Block a user