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 ) {}
57
void PL_EDITOR_FRAME::SaveCopyInUndoList()
59
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
60
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
61
pglayout.SaveInString( copyItem->m_Layout );
63
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
64
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
65
lastcmd->PushItem(wrapper);
66
GetScreen()->PushCommandToUndoList( lastcmd );
68
// Clear redo list, because after new save there is no redo to do.
69
GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
73
/* Redo the last edition:
74
* - Place the current edited layout in undo list
75
* - Get previous version of the current edited layput
77
void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event )
79
if ( GetScreen()->GetRedoCommandCount() <= 0 )
82
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
83
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
84
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
85
pglayout.SaveInString( copyItem->m_Layout );
87
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
89
lastcmd->PushItem( wrapper );
90
GetScreen()->PushCommandToUndoList( lastcmd );
92
lastcmd = GetScreen()->PopCommandFromRedoList();
94
wrapper = lastcmd->PopItem();
95
copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();
96
pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) );
105
/* Undo the last edition:
106
* - Place the current layout in Redo list
107
* - Get previous version of the current edited layout
109
void PL_EDITOR_FRAME::GetLayoutFromUndoList( wxCommandEvent& event )
111
if ( GetScreen()->GetUndoCommandCount() <= 0 )
114
PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
115
PL_ITEM_LAYOUT* copyItem = new PL_ITEM_LAYOUT;
116
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
117
pglayout.SaveInString( copyItem->m_Layout );
119
ITEM_PICKER wrapper( copyItem, UR_LIBEDIT );
120
lastcmd->PushItem( wrapper );
121
GetScreen()->PushCommandToRedoList( lastcmd );
123
lastcmd = GetScreen()->PopCommandFromUndoList();
125
wrapper = lastcmd->PopItem();
126
copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();
127
pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) );
135
/* Remove the last command in Undo List.
136
* Used to clean the uUndo stack after a cancel command
138
void PL_EDITOR_FRAME::RemoveLastCommandInUndoList()
140
if ( GetScreen()->GetUndoCommandCount() <= 0 )
143
PICKED_ITEMS_LIST* lastcmd = GetScreen()->PopCommandFromUndoList();
145
ITEM_PICKER wrapper = lastcmd->PopItem();
146
PL_ITEM_LAYOUT* copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem();