2
* @file pl_editor_undo_redo.cpp
3
* @brief page layout editor: undo and redo functions
7
* This program source code file is part of KiCad, a free EDA CAD application.
9
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
10
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
12
* This program is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, you may find one here:
24
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25
* or you may search the http://www.gnu.org website for the version 2 license,
26
* or you may write to the Free Software Foundation, Inc.,
27
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31
#include <class_drawpanel.h>
33
#include <worksheet_shape_builder.h>
35
#include <pl_editor_frame.h>
37
/* Note: the Undo/redo commands use a "brute" method:
38
* the full page layout is converted to a S expression, and saved as string.
39
* When a previous version is needed, the old string is parsed,
40
* and the description replaces the current desc, just like reading a new file
42
* This is not optimal from the memory point of view, but:
43
* - the descriptions are never very long (max few thousand of bytes)
44
* - this is very easy to code
47
// A helper class used in undo/redo commad:
48
class PL_ITEM_LAYOUT: public EDA_ITEM
54
PL_ITEM_LAYOUT() : EDA_ITEM( TYPE_PL_EDITOR_LAYOUT ) {}
56
// Required to keep compiler happy on debug builds.
58
virtual void Show( int nestLevel, std::ostream& os ) const {}
62
void PL_EDITOR_FRAME::SaveCopyInUndoList()
64
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
65
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
66
pglayout.SaveInString( copyItem->m_Layout );
68
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
69
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
70
lastcmd->PushItem(wrapper);
71
GetScreen()->PushCommandToUndoList( lastcmd );
73
// Clear redo list, because after new save there is no redo to do.
74
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
78
/* Redo the last edition:
79
* - Place the current edited layout in undo list
80
* - Get previous version of the current edited layput
82
void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event )
84
if ( GetScreen()->GetRedoCommandCount() <= 0 )
87
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
88
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
89
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
90
pglayout.SaveInString( copyItem->m_Layout );
92
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
94
lastcmd->PushItem( wrapper );
95
GetScreen()->PushCommandToUndoList( lastcmd );
97
lastcmd = GetScreen()->PopCommandFromRedoList();
99
wrapper = lastcmd->PopItem();
100
copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();
101
pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) );
110
/* Undo the last edition:
111
* - Place the current layout in Redo list
112
* - Get previous version of the current edited layout
114
void PL_EDITOR_FRAME::GetLayoutFromUndoList( wxCommandEvent& event )
116
if ( GetScreen()->GetUndoCommandCount() <= 0 )
119
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
120
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
121
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
122
pglayout.SaveInString( copyItem->m_Layout );
124
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
125
lastcmd->PushItem( wrapper );
126
GetScreen()->PushCommandToRedoList( lastcmd );
128
lastcmd = GetScreen()->PopCommandFromUndoList();
130
wrapper = lastcmd->PopItem();
131
copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();
132
pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) );
140
/* Remove the last command in Undo List.
141
* Used to clean the uUndo stack after a cancel command
143
void PL_EDITOR_FRAME::RemoveLastCommandInUndoList()
145
if ( GetScreen()->GetUndoCommandCount() <= 0 )
148
PICKED_ITEMS_LIST* lastcmd = GetScreen()->PopCommandFromUndoList();
150
ITEM_PICKER wrapper = lastcmd->PopItem();
151
PL_ITEM_LAYOUT* copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();