diff --git a/zxlive/commands.py b/zxlive/commands.py index a898a73d..e8553ef8 100644 --- a/zxlive/commands.py +++ b/zxlive/commands.py @@ -423,6 +423,10 @@ class GoToRewriteStep(SetGraph): def __init__(self, graph_view: GraphView, step_view: QListView, old_step: int, step: int) -> None: proof_model = step_view.model() assert isinstance(proof_model, ProofModel) + + # Save any vertex rearrangements to the proof step + proof_model.set_graph(old_step, graph_view.graph_scene.g) + SetGraph.__init__(self, graph_view, proof_model.get_graph(step)) self.step_view = step_view self.step = step @@ -445,20 +449,3 @@ def undo(self) -> None: self.step_view.selectionModel().blockSignals(False) self.step_view.update(idx) super().undo() - - -@dataclass -class MoveNodeInStep(MoveNode): - step_view: QListView - - def redo(self) -> None: - super().redo() - model = self.step_view.model() - assert isinstance(model, ProofModel) - model.set_graph(self.step_view.currentIndex().row(), self.g) - - def undo(self) -> None: - super().undo() - model = self.step_view.model() - assert isinstance(model, ProofModel) - model.set_graph(self.step_view.currentIndex().row(), self.g) diff --git a/zxlive/proof_panel.py b/zxlive/proof_panel.py index f0ec1b6a..e962670b 100644 --- a/zxlive/proof_panel.py +++ b/zxlive/proof_panel.py @@ -18,7 +18,7 @@ from . import animations as anims from .base_panel import BasePanel, ToolbarSection -from .commands import AddRewriteStep, GoToRewriteStep, MoveNodeInStep, UndoableChange +from .commands import AddRewriteStep, GoToRewriteStep, MoveNode, UndoableChange from .common import (ET, VT, GraphT, get_data, pos_from_view, pos_to_view, colors) from .dialogs import show_error_msg @@ -156,7 +156,7 @@ def parse_selection(self) -> tuple[list[VT], list[ET]]: return selection, list(edges) def _vert_moved(self, vs: list[tuple[VT, float, float]]) -> None: - cmd = MoveNodeInStep(self.graph_view, vs, self.step_view) + cmd = MoveNode(self.graph_view, vs) self.undo_stack.push(cmd) def _selection_clicked(self) -> None: diff --git a/zxlive/rewrite_data.py b/zxlive/rewrite_data.py index 76de351e..01cf7b48 100644 --- a/zxlive/rewrite_data.py +++ b/zxlive/rewrite_data.py @@ -94,6 +94,19 @@ def _extract_circuit(graph: GraphT, matches: list) -> GraphT: return extract_circuit(graph).to_graph() +# The OCM action simply saves the current graph without modifying anything. +# This can be used to make repositioning the vertices an explicit proof step. +def ocm_rule(_graph: GraphT, _matches: list) -> pyzx.rules.RewriteOutputType[ET, VT]: + return ({}, [], [], True) + +ocm_action: RewriteData = { + "text": "OCM", + "tooltip": "Saves the graph with the current vertex positions", + "matcher": const_true, + "rule": ocm_rule, + "type": MATCHES_VERTICES, +} + simplifications: dict[str, RewriteData] = { 'bialg_simp': { "text": "bialgebra", @@ -239,6 +252,7 @@ def _extract_circuit(graph: GraphT, matches: list) -> GraphT: action_groups = { "Basic rules": {key: operations[key] for key in rules_basic}, + "OCM": ocm_action, "Custom rules": {}, "Graph-like rules": rewrites_graph_theoretic, "ZXW rules": {key: operations[key] for key in rules_zxw},