Added run button and parameter dialog
This commit is contained in:
@@ -18,6 +18,7 @@ from bedit.core.serializer import DocumentSerializer
|
||||
from bedit.core.simulation import Simulation
|
||||
from bedit.gui.controllers.document import DocumentController
|
||||
from bedit.gui.dialogs.component_options import ComponentOptionsDialog
|
||||
from bedit.gui.dialogs.graph_parameters import GraphParametersDialog
|
||||
from bedit.gui.dialogs.item_options import ItemOptionsDialog
|
||||
from bedit.gui.models.library_repository import LibraryRepository
|
||||
from bedit.gui.models.library_tree import (
|
||||
@@ -55,7 +56,9 @@ class MainWindow(QMainWindow):
|
||||
self._applying_text_definition = False
|
||||
|
||||
self.libraries = LibraryRepository(self)
|
||||
self.simulation = Simulation()
|
||||
self.simulation = Simulation(
|
||||
openmodelica_path=SettingsDialog.openmodelica_path(self.settings)
|
||||
)
|
||||
self.document_controller = DocumentController(self, simulation=self.simulation)
|
||||
self.library_tree_model = LibraryTreeModel(
|
||||
self.libraries,
|
||||
@@ -162,7 +165,9 @@ class MainWindow(QMainWindow):
|
||||
self.ui.actionSimulationSettings.triggered.connect(
|
||||
self.show_simulation_settings
|
||||
)
|
||||
self.ui.actionGraphParameters.triggered.connect(self.show_graph_parameters)
|
||||
self.ui.actionCompile.triggered.connect(self.compile_active_graph)
|
||||
self.ui.actionRunSimulation.triggered.connect(self.run_simulation)
|
||||
self.document_controller.undo_stack.canUndoChanged.connect(self.ui.actionUndo.setEnabled)
|
||||
self.document_controller.undo_stack.canRedoChanged.connect(self.ui.actionRedo.setEnabled)
|
||||
self.document_controller.modifiedChanged.connect(lambda _modified: self._update_title())
|
||||
@@ -218,6 +223,21 @@ class MainWindow(QMainWindow):
|
||||
if dialog.exec() == dialog.DialogCode.Accepted:
|
||||
self.document_controller.edit_simulation_settings(dialog.settings)
|
||||
|
||||
@Slot()
|
||||
def show_graph_parameters(self) -> None:
|
||||
component = self.document_controller.active_component
|
||||
if component is None or component.implementation_kind != "graph":
|
||||
return
|
||||
dialog = GraphParametersDialog(component, self)
|
||||
if dialog.exec() == dialog.DialogCode.Accepted:
|
||||
try:
|
||||
self.document_controller.edit_graph_parameter_values(
|
||||
component.id, dialog.parameter_values
|
||||
)
|
||||
except ValueError as error:
|
||||
self.log.error("Could not change graph parameters: %s", error)
|
||||
QMessageBox.warning(self, "Cannot change graph parameters", str(error))
|
||||
|
||||
@Slot()
|
||||
def compile_active_graph(self) -> None:
|
||||
try:
|
||||
@@ -226,6 +246,14 @@ class MainWindow(QMainWindow):
|
||||
self.log.error("Compile failed: %s", error)
|
||||
QMessageBox.warning(self, "Cannot compile", str(error))
|
||||
|
||||
@Slot()
|
||||
def run_simulation(self) -> None:
|
||||
try:
|
||||
self.document_controller.run_simulation()
|
||||
except Exception as error:
|
||||
self.log.exception("Simulation run failed")
|
||||
QMessageBox.warning(self, "Cannot run simulation", str(error))
|
||||
|
||||
def _restore_window_geometry(self) -> None:
|
||||
geometry = self.settings.value("window/geometry")
|
||||
if geometry is not None:
|
||||
@@ -252,7 +280,9 @@ class MainWindow(QMainWindow):
|
||||
self.ui.workspaceStack.setCurrentWidget(self.ui.emptyPage)
|
||||
self._set_graph_controls_visible(False)
|
||||
self.ui.actionSimulationSettings.setEnabled(False)
|
||||
self.ui.actionGraphParameters.setEnabled(False)
|
||||
self.ui.actionCompile.setEnabled(False)
|
||||
self.ui.actionRunSimulation.setEnabled(False)
|
||||
self._update_edit_actions()
|
||||
return
|
||||
self.ui.graphBreadcrumbLabel.setText(" › ".join(self.document_controller.breadcrumb()))
|
||||
@@ -261,7 +291,9 @@ class MainWindow(QMainWindow):
|
||||
)
|
||||
is_graph = component.implementation_kind == "graph"
|
||||
self.ui.actionSimulationSettings.setEnabled(is_graph)
|
||||
self.ui.actionGraphParameters.setEnabled(is_graph)
|
||||
self.ui.actionCompile.setEnabled(is_graph)
|
||||
self.ui.actionRunSimulation.setEnabled(is_graph)
|
||||
self.ui.workspaceModeLabel.setText("Graph" if is_graph else "Text")
|
||||
self.ui.workspaceStack.setCurrentWidget(
|
||||
self.ui.graphPage if is_graph else self.ui.textPage
|
||||
@@ -483,8 +515,14 @@ class MainWindow(QMainWindow):
|
||||
dialog = SettingsDialog(self)
|
||||
dialog.settingsChanged.connect(self.reload_libraries)
|
||||
dialog.settingsChanged.connect(self.refresh_editor_settings)
|
||||
dialog.settingsChanged.connect(self.refresh_simulation_preferences)
|
||||
dialog.exec()
|
||||
|
||||
def refresh_simulation_preferences(self) -> None:
|
||||
self.simulation.openmodelica_path = SettingsDialog.openmodelica_path(
|
||||
self.settings
|
||||
)
|
||||
|
||||
def refresh_editor_settings(self) -> None:
|
||||
scene = self.ui.graphView.scene()
|
||||
if scene is not None:
|
||||
|
||||
Reference in New Issue
Block a user