Plotting signals in besim

This commit is contained in:
2026-08-02 11:22:28 +02:00
parent 2128fb00b4
commit 756a621ab1
7 changed files with 391 additions and 1 deletions

View File

@@ -0,0 +1,79 @@
from __future__ import annotations
from collections.abc import Callable
from PySide6.QtGui import QUndoCommand
from bedit_gui.simulation_models import SimulationPlotTab, SimulationRoot
ChangedCallback = Callable[[int], None]
class AddSimulationPlotTabCommand(QUndoCommand):
def __init__(self, root: SimulationRoot, tab: SimulationPlotTab, index: int, changed: ChangedCallback) -> None:
super().__init__("Add plot")
self.root = root
self.tab = tab
self.index = index
self.changed = changed
def redo(self) -> None:
self.root.plot_tabs.insert(self.index, self.tab)
self.changed(self.index)
def undo(self) -> None:
self.root.plot_tabs.pop(self.index)
self.changed(max(0, self.index - 1))
class RemoveSimulationPlotTabCommand(QUndoCommand):
def __init__(self, root: SimulationRoot, index: int, changed: ChangedCallback) -> None:
super().__init__("Remove plot")
self.root = root
self.index = index
self.tab = root.plot_tabs[index]
self.changed = changed
def redo(self) -> None:
self.root.plot_tabs.pop(self.index)
self.changed(min(self.index, len(self.root.plot_tabs) - 1))
def undo(self) -> None:
self.root.plot_tabs.insert(self.index, self.tab)
self.changed(self.index)
class RenameSimulationPlotTabCommand(QUndoCommand):
def __init__(self, root: SimulationRoot, index: int, name: str, changed: ChangedCallback) -> None:
super().__init__("Rename plot")
self.root = root
self.index = index
self.old_name = root.plot_tabs[index].name
self.name = name
self.changed = changed
def redo(self) -> None:
self.root.plot_tabs[self.index].name = self.name
self.changed(self.index)
def undo(self) -> None:
self.root.plot_tabs[self.index].name = self.old_name
self.changed(self.index)
class ChangeSimulationPlotSignalsCommand(QUndoCommand):
def __init__(self, root: SimulationRoot, index: int, signals: list[str], changed: ChangedCallback) -> None:
super().__init__("Change plotted signals")
self.root = root
self.index = index
self.old_signals = list(root.plot_tabs[index].signals)
self.signals = list(signals)
self.changed = changed
def redo(self) -> None:
self.root.plot_tabs[self.index].signals = list(self.signals)
self.changed(self.index)
def undo(self) -> None:
self.root.plot_tabs[self.index].signals = list(self.old_signals)
self.changed(self.index)