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"
30
32{
33 PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
34 DS_PROXY_UNDO_ITEM* copyItem = new DS_PROXY_UNDO_ITEM( this );
36
37 lastcmd->PushItem( wrapper );
38 PushCommandToUndoList( lastcmd );
39
40 // Clear redo list, because after new save there is no redo to do.
42}
43
44
45/* Redo the last edit:
46 * - Place the current edited layout in undo list
47 * - Get previous version of the current edited layput
48 */
50{
52
53 if ( GetRedoCommandCount() <= 0 )
54 return;
55
57 DS_PROXY_UNDO_ITEM* redoItem = static_cast<DS_PROXY_UNDO_ITEM*>( redoWrapper.GetItem() );
58 bool pageSettingsAndTitleBlock = redoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
59
60 PICKED_ITEMS_LIST* undoCmd = new PICKED_ITEMS_LIST();
61 DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
62 ITEM_PICKER undoWrapper( GetScreen(), undoItem );
63
64 undoCmd->PushItem( undoWrapper );
65 PushCommandToUndoList( undoCmd );
66
67 selTool->ClearSelection();
68 redoItem->Restore( this, GetCanvas()->GetView() );
69 selTool->RebuildSelection();
70
71 delete redoItem;
72
73 if( pageSettingsAndTitleBlock )
74 HardRedraw(); // items based off of corners will need re-calculating
75 else
76 GetCanvas()->Refresh();
77
78 OnModify();
79 m_propertiesPagelayout->UpdateData();
80}
81
82
83/* Undo the last edit:
84 * - Place the current layout in Redo list
85 * - Get previous version of the current edited layout
86 */
88{
90
91 if ( GetUndoCommandCount() <= 0 )
92 return;
93
95 DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
96 bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
97
98 PICKED_ITEMS_LIST* redoCmd = new PICKED_ITEMS_LIST();
99 DS_PROXY_UNDO_ITEM* redoItem = new DS_PROXY_UNDO_ITEM( pageSettingsAndTitleBlock ? this : nullptr );
100 ITEM_PICKER redoWrapper( GetScreen(), redoItem );
101
102 redoCmd->PushItem( redoWrapper );
103 PushCommandToRedoList( redoCmd );
104
105 selTool->ClearSelection();
106 undoItem->Restore( this, GetCanvas()->GetView() );
107 selTool->RebuildSelection();
108
109 delete undoItem;
110
111 if( pageSettingsAndTitleBlock )
112 HardRedraw(); // items based off of corners will need re-calculating
113 else
114 GetCanvas()->Refresh();
115
116 OnModify();
117 m_propertiesPagelayout->UpdateData();
118}
119
120
121/* Remove the last command in Undo List.
122 * Used to clean the uUndo stack after a cancel command
123 */
125{
127
128 if ( GetUndoCommandCount() <= 0 )
129 return;
130
131 ITEM_PICKER undoWrapper = PopCommandFromUndoList()->PopItem();
132 DS_PROXY_UNDO_ITEM* undoItem = static_cast<DS_PROXY_UNDO_ITEM*>( undoWrapper.GetItem() );
133 bool pageSettingsAndTitleBlock = undoItem->Type() == WS_PROXY_UNDO_ITEM_PLUS_T;
134
135 selTool->ClearSelection();
136 undoItem->Restore( this, GetCanvas()->GetView() );
137 selTool->RebuildSelection();
138
139 delete undoItem;
140
141 if( pageSettingsAndTitleBlock )
142 {
144 HardRedraw(); // items based off of corners will need re-calculating
145 }
146 else
147 GetCanvas()->Refresh();
148
149 m_propertiesPagelayout->UpdateData();
150}
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:110
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:
PL_PROPERTIES_PANEL * m_propertiesPagelayout
The last filename chosen to be proposed to the user.
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.
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
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:221