KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pl_editor_undo_redo.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jean-Pierre Charras, jp.charras at wanadoo.fr
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
24#include <tool/tool_manager.h>
25#include <tool/actions.h>
26
27#include "pl_editor_frame.h"
29
31{
32 PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
33 DS_PROXY_UNDO_ITEM* copyItem = new DS_PROXY_UNDO_ITEM( this );
35
36 lastcmd->PushItem( wrapper );
37 PushCommandToUndoList( lastcmd );
38
39 // Clear redo list, because after new save there is no redo to do.
41}
42
43
44/* Redo the last edit:
45 * - Place the current edited layout in undo list
46 * - Get previous version of the current edited layput
47 */
49{
51
52 if ( GetRedoCommandCount() <= 0 )
53 return;
54
56 DS_PROXY_UNDO_ITEM* redoItem = static_cast<DS_PROXY_UNDO_ITEM*>( redoWrapper.GetItem() );
57 bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
58
59 PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST();
60 DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
61 ITEM_PICKER undoWrapper( GetScreen(), undoItem );
62
63 undoCmd->PushItem( undoWrapper );
64 PushCommandToUndoList( undoCmd );
65
66 selTool->ClearSelection();
67 redoItem->Restore( this, GetCanvas()->GetView() );
68 selTool->RebuildSelection();
69
70 delete redoItem;
71
72 if( pageSettingsAndTitleBlock )
73 HardRedraw(); // items based off of corners will need re-calculating
74 else
75 GetCanvas()->Refresh();
76
77 OnModify();
78}
79
80
81/* Undo the last edit:
82 * - Place the current layout in Redo list
83 * - Get previous version of the current edited layout
84 */
86{
88
89 if ( GetUndoCommandCount() <= 0 )
90 return;
91
93 DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
94 bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
95
96 PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST();
97 DS_PROXY_UNDO_ITEM* redoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
98 ITEM_PICKER redoWrapper( GetScreen(), redoItem );
99
100 redoCmd->PushItem( redoWrapper );
101 PushCommandToRedoList( redoCmd );
102
103 selTool->ClearSelection();
104 undoItem->Restore( this, GetCanvas()->GetView() );
105 selTool->RebuildSelection();
106
107 delete undoItem;
108
109 if( pageSettingsAndTitleBlock )
110 HardRedraw(); // items based off of corners will need re-calculating
111 else
112 GetCanvas()->Refresh();
113
114 OnModify();
115}
116
117
118/* Remove the last command in Undo List.
119 * Used to clean the uUndo stack after a cancel command
120 */
122{
124
125 if ( GetUndoCommandCount() <= 0 )
126 return;
127
128 ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
129 DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
130 bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
131
132 selTool->ClearSelection();
133 undoItem->Restore( this, GetCanvas()->GetView() );
134 selTool->RebuildSelection();
135
136 delete undoItem;
137
138 if( pageSettingsAndTitleBlock )
139 {
141 HardRedraw(); // items based off of corners will need re-calculating
142 }
143 else
144 GetCanvas()->Refresh();
145}
static TOOL_ACTION zoomFitScreen
Definition actions.h:138
void Restore(EDA_DRAW_FRAME *aFrame, KIGFX::VIEW *aView=nullptr)
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
virtual int GetRedoCommandCount() const
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
virtual int GetUndoCommandCount() const
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
virtual BASE_SCREEN * GetScreen() const
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
EDA_ITEM * GetItem() const
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
void OnModify() override
Must be called after a change in order to set the "modify" flag.
void GetLayoutFromRedoList()
Redo the last edit:
void GetLayoutFromUndoList()
Undo the last edit:
void RollbackFromUndo()
Apply the last command in Undo List without stacking a Redo.
void SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
void HardRedraw() override
Refresh the library tree and redraw the window.
PL_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void ClearUndoORRedoList(UNDO_REDO_LIST whichList, int aItemCount=-1) override
Remove the aItemCount of old commands from aList and delete commands, pickers and picked items if nee...
int ClearSelection(const TOOL_EVENT &aEvent)
void RebuildSelection()
Rebuild the selection from the flags in the view items.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
@ WS_PROXY_UNDO_ITEM_PLUS_T
Definition typeinfo.h:222