Simulation settings window
This commit is contained in:
@@ -14,8 +14,9 @@ from bedit_gui.commands.port_commands import AddPortCommand, ChangePortCommand,
|
||||
from bedit_gui.commands.param_commands import AddParamCommand, ChangeParamCommand, RemoveParamCommand
|
||||
from bedit_gui.commands.rename_component_command import RenameComponentCommand
|
||||
from bedit_gui.commands.rename_document_command import RenameDocumentCommand
|
||||
from bedit_gui.commands.simulation_database_command import ChangeSimulationDatabaseCommand
|
||||
from bedit_gui.commands.component_command import AddEmptyEquationComponent, AddEmptyGraphComponent, DeleteComponent, PasteComponents
|
||||
from bedit_gui.models import Icon, IconDatabase
|
||||
from bedit_gui.models import Icon, IconDatabase, SimulationDatabase
|
||||
from bedit_gui.services import document_files
|
||||
|
||||
|
||||
@@ -27,6 +28,7 @@ class Document(QObject):
|
||||
modified_changed = Signal(bool)
|
||||
icon_changed = Signal(object, object)
|
||||
equation_text_changed = Signal(object, str)
|
||||
simulation_database_changed = Signal(object)
|
||||
|
||||
def __init__(self, parent: QObject | None = None) -> None:
|
||||
super().__init__(parent)
|
||||
@@ -122,6 +124,44 @@ class Document(QObject):
|
||||
def change_icon(self, component_id: ComponentID, icon: Icon) -> None:
|
||||
self.undo_stack.push(ChangeIconCommand(self, component_id, icon))
|
||||
|
||||
def stored_simulation_database(self) -> SimulationDatabase | None:
|
||||
database = self._simulation_database(False)
|
||||
return deepcopy(database) if database is not None else None
|
||||
|
||||
def simulation_database(self) -> SimulationDatabase:
|
||||
return self.stored_simulation_database() or SimulationDatabase()
|
||||
|
||||
def change_simulation_database(self, database: SimulationDatabase) -> None:
|
||||
if database != self.stored_simulation_database():
|
||||
self.undo_stack.push(ChangeSimulationDatabaseCommand(self, database))
|
||||
|
||||
def _set_simulation_database(self, database: SimulationDatabase | None) -> None:
|
||||
if database is None:
|
||||
if self.model.metadata is not None:
|
||||
self.model.metadata.pop("simulation_database", None)
|
||||
else:
|
||||
if self.model.metadata is None:
|
||||
self.model.metadata = {}
|
||||
self.model.metadata["simulation_database"] = deepcopy(database)
|
||||
self.simulation_database_changed.emit(self.stored_simulation_database())
|
||||
|
||||
def _simulation_database(self, create: bool) -> SimulationDatabase | None:
|
||||
metadata = self.model.metadata
|
||||
value = metadata.get("simulation_database") if metadata is not None else None
|
||||
if isinstance(value, dict):
|
||||
value = SimulationDatabase.from_data(value)
|
||||
metadata["simulation_database"] = value
|
||||
if isinstance(value, SimulationDatabase):
|
||||
return value
|
||||
if not create:
|
||||
return None
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
self.model.metadata = metadata
|
||||
database = SimulationDatabase()
|
||||
metadata["simulation_database"] = database
|
||||
return database
|
||||
|
||||
def _set_component_icon(self, component_id: ComponentID, icon: Icon | None) -> None:
|
||||
if icon is None:
|
||||
database = self._icon_database(False)
|
||||
|
||||
Reference in New Issue
Block a user