Added run button and parameter dialog

This commit is contained in:
2026-07-20 18:46:59 +02:00
parent 4cfe7c3a0e
commit 38e3d7aae9
16 changed files with 587 additions and 72 deletions

View File

@@ -150,6 +150,19 @@ class EditSimulationSettingsCommand(QUndoCommand):
self.controller._set_simulation_settings(self.owner_id, self.old)
class EditGraphParametersCommand(QUndoCommand):
def __init__(self, controller, old: dict, new: dict) -> None:
super().__init__("Edit graph parameters")
self.controller = controller
self.old, self.new = old, new
def redo(self) -> None:
self.controller._set_graph_parameters(self.new)
def undo(self) -> None:
self.controller._set_graph_parameters(self.old)
class DeleteAnnotationsCommand(QUndoCommand):
def __init__(self, controller, owner_id: str, annotations: dict[str, Annotation]) -> None:
super().__init__("Delete annotations")

View File

@@ -13,6 +13,7 @@ from bedit.gui.controllers.commands import (
DeleteSelectionCommand,
DeleteAnnotationsCommand,
EditGraphItemCommand,
EditGraphParametersCommand,
EditSimulationSettingsCommand,
EditTextDefinitionCommand,
EditComponentAppearanceCommand,
@@ -393,12 +394,45 @@ class DocumentController(QObject):
EditSimulationSettingsCommand(self, component.id, old, new)
)
def edit_graph_parameter_values(
self, root_id: str, values: dict[str, dict[str, str]]
) -> None:
root = self.document.find_component(root_id) if self.document else None
if root is None:
return
subtree_ids = {component.id for component in self._component_subtree(root)}
if not set(values) <= subtree_ids:
raise ValueError("Parameter changes contain a component outside the active graph")
old: dict[str, list[dict]] = {}
new: dict[str, list[dict]] = {}
for component_id, parameter_values in values.items():
component = self.document.find_component(component_id)
known_ids = {parameter.id for parameter in component.parameters}
if not set(parameter_values) <= known_ids:
raise ValueError(f"Component {component.name!r} contains an unknown parameter")
updated = deepcopy(component.parameters)
for parameter in updated:
if parameter.id in parameter_values:
parameter.value = parameter_values[parameter.id]
old[component_id] = [parameter.to_dict() for parameter in component.parameters]
new[component_id] = [parameter.to_dict() for parameter in updated]
if old != new:
self.undo_stack.push(EditGraphParametersCommand(self, old, new))
def compile_active_graph(self) -> None:
component = self.active_component
if component is None or component.implementation_kind != "graph":
raise ValueError("Open a graph component before compiling")
self.simulation.compile(component.to_dict())
def run_simulation(self) -> None:
component = self.active_component
if component is None or component.implementation_kind != "graph":
raise ValueError("Open a graph component before running a simulation")
self.simulation.run_simulation()
def set_route_waypoints(self, item_kind: str, item_id: str, waypoints: list[QPointF]) -> None:
item = (
self.active_graph.connections
@@ -1082,6 +1116,22 @@ class DocumentController(QObject):
owner.graph.simulation_settings = deepcopy(settings)
self.documentReset.emit()
def _set_graph_parameters(self, values: dict[str, list[dict]]) -> None:
if self.document is None:
return
changed_text_components: list[str] = []
for component_id, parameters in values.items():
component = self.document.find_component(component_id)
if component is None:
continue
component.parameters = [Parameter.from_dict(item) for item in parameters]
if component.implementation_kind == "text":
changed_text_components.append(component_id)
self.document.validate()
self.documentReset.emit()
for component_id in changed_text_components:
self.textDefinitionChanged.emit(component_id)
def _replace_component(self, old_id: str, replacement: Component) -> None:
if self.document is None:
return