proper modelica text model editing
This commit is contained in:
@@ -181,6 +181,7 @@ class MainWindow(QMainWindow):
|
||||
)
|
||||
self.ui.actionGraphParameters.triggered.connect(self.show_graph_parameters)
|
||||
self.ui.actionCompose.triggered.connect(self.compose_active_graph)
|
||||
self.ui.actionExportModel.triggered.connect(self.export_model)
|
||||
self.ui.actionSimulationWindow.triggered.connect(self.show_simulation_window)
|
||||
self.ui.actionRunSimulation.triggered.connect(self.run_simulation)
|
||||
self.document_controller.undo_stack.canUndoChanged.connect(self.ui.actionUndo.setEnabled)
|
||||
@@ -261,6 +262,35 @@ class MainWindow(QMainWindow):
|
||||
self.log.error("Composition failed: %s", error)
|
||||
QMessageBox.warning(self, "Cannot compose", str(error))
|
||||
|
||||
@Slot()
|
||||
def export_model(self) -> None:
|
||||
try:
|
||||
model_name, source = self.document_controller.compose_active_graph_source()
|
||||
except ValueError as error:
|
||||
self.log.error("Model export composition failed: %s", error)
|
||||
QMessageBox.warning(self, "Cannot Export Model", str(error))
|
||||
return
|
||||
file_name, _selected_filter = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
"Export OpenModelica Model",
|
||||
f"{model_name}.mo",
|
||||
"Modelica Models (*.mo);;All Files (*)",
|
||||
)
|
||||
if not file_name:
|
||||
return
|
||||
path = Path(file_name)
|
||||
if not path.suffix:
|
||||
path = path.with_suffix(".mo")
|
||||
temporary_path = path.with_suffix(path.suffix + ".tmp")
|
||||
try:
|
||||
temporary_path.write_text(source, encoding="utf-8")
|
||||
temporary_path.replace(path)
|
||||
except OSError as error:
|
||||
self.log.error("Could not export model %s: %s", path, error)
|
||||
QMessageBox.critical(self, "Cannot Export Model", str(error))
|
||||
return
|
||||
self.log.info("Exported OpenModelica model to %s", path)
|
||||
|
||||
@Slot()
|
||||
def show_simulation_window(self) -> None:
|
||||
self._simulation_window.show()
|
||||
@@ -307,6 +337,7 @@ class MainWindow(QMainWindow):
|
||||
self.ui.actionSimulationSettings.setEnabled(False)
|
||||
self.ui.actionGraphParameters.setEnabled(False)
|
||||
self.ui.actionCompose.setEnabled(False)
|
||||
self.ui.actionExportModel.setEnabled(False)
|
||||
self.ui.actionRunSimulation.setEnabled(False)
|
||||
self._update_edit_actions()
|
||||
return
|
||||
@@ -318,6 +349,7 @@ class MainWindow(QMainWindow):
|
||||
self.ui.actionSimulationSettings.setEnabled(is_graph)
|
||||
self.ui.actionGraphParameters.setEnabled(is_graph)
|
||||
self.ui.actionCompose.setEnabled(is_graph)
|
||||
self.ui.actionExportModel.setEnabled(is_graph)
|
||||
self.ui.actionRunSimulation.setEnabled(is_graph)
|
||||
self.ui.workspaceModeLabel.setText("Graph" if is_graph else "Text")
|
||||
self.ui.workspaceStack.setCurrentWidget(
|
||||
@@ -505,6 +537,8 @@ class MainWindow(QMainWindow):
|
||||
if component is None:
|
||||
return
|
||||
self.ui.textDefinitionEditor.set_definition(
|
||||
component.source.get("declarations", ""),
|
||||
component.source.get("initialEquations", ""),
|
||||
component.source.get("equations", ""),
|
||||
component.inputs,
|
||||
component.outputs,
|
||||
@@ -522,7 +556,8 @@ class MainWindow(QMainWindow):
|
||||
answer = QMessageBox.question(
|
||||
self,
|
||||
"Apply text component changes?",
|
||||
"The text component has unapplied equation, port, or parameter changes.",
|
||||
"The text component has unapplied declaration, initial-equation, "
|
||||
"equation, port, or parameter changes.",
|
||||
QMessageBox.StandardButton.Apply
|
||||
| QMessageBox.StandardButton.Discard
|
||||
| QMessageBox.StandardButton.Cancel,
|
||||
@@ -540,6 +575,8 @@ class MainWindow(QMainWindow):
|
||||
self.document_controller.replace_active_text_definition(
|
||||
inputs,
|
||||
outputs,
|
||||
self.ui.textDefinitionEditor.declarations,
|
||||
self.ui.textDefinitionEditor.initial_equations,
|
||||
self.ui.textDefinitionEditor.equations,
|
||||
self.ui.textDefinitionEditor.parameters,
|
||||
)
|
||||
@@ -672,6 +709,8 @@ class MainWindow(QMainWindow):
|
||||
if scene is not None:
|
||||
scene.update()
|
||||
self.ui.graphView.viewport().update()
|
||||
self.ui.textDefinitionEditor.ui.declarationsEdit.reload_highlighting()
|
||||
self.ui.textDefinitionEditor.ui.initialEquationsEdit.reload_highlighting()
|
||||
self.ui.textDefinitionEditor.ui.equationsEdit.reload_highlighting()
|
||||
|
||||
def _document_opened_changed(self, opened: bool) -> None:
|
||||
|
||||
Reference in New Issue
Block a user