KiCad PCB EDA Suite
libedit_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) 2007 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <fctsys.h>
26 #include <class_drawpanel.h>
27 
28 #include <libeditframe.h>
29 #include <class_libentry.h>
30 
31 
33 {
34  LIB_PART* CopyItem;
35  PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
36 
37  CopyItem = new LIB_PART( * (LIB_PART*) ItemToCopy );
38 
39  // Clear current flags (which can be temporary set by a current edit command).
40  CopyItem->ClearStatus();
41 
42  ITEM_PICKER wrapper( CopyItem, UR_LIBEDIT );
43  lastcmd->PushItem( wrapper );
44  GetScreen()->PushCommandToUndoList( lastcmd );
45 
46  // Clear redo list, because after new save there is no redo to do.
47  GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
48 }
49 
50 
51 void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event )
52 {
53  if( GetScreen()->GetRedoCommandCount() <= 0 )
54  return;
55 
56  // Store the current part in the undo buffer
57  PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
58  LIB_PART* part = GetCurPart();
59  ITEM_PICKER wrapper( part, UR_LIBEDIT );
60  lastcmd->PushItem( wrapper );
61  GetScreen()->PushCommandToUndoList( lastcmd );
62 
63  // Load the last redo entry
64  lastcmd = GetScreen()->PopCommandFromRedoList();
65  wrapper = lastcmd->PopItem();
66  delete lastcmd;
67  part = (LIB_PART*) wrapper.GetItem();
68 
69  // Do not delete the previous part by calling SetCurPart( part )
70  // which calls delete <previous part>.
71  // <previous part> is now put in undo list and is owned by this list
72  // Just set the current part to the part which come from the redo list
73  m_my_part = part;
74 
75  if( !part )
76  return;
77 
78  if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
79  m_aliasName = part->GetName();
80 
81  m_drawItem = NULL;
84  SetShowDeMorgan( part->HasConversion() );
86  DisplayCmpDoc();
87  OnModify();
88  m_canvas->Refresh();
89 }
90 
91 
92 void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event )
93 {
94  if( GetScreen()->GetUndoCommandCount() <= 0 )
95  return;
96 
97  // Store the current part in the redo buffer
98  PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
99  LIB_PART* part = GetCurPart();
100  ITEM_PICKER wrapper( part, UR_LIBEDIT );
101  lastcmd->PushItem( wrapper );
102  GetScreen()->PushCommandToRedoList( lastcmd );
103 
104  // Load the last undo entry
105  lastcmd = GetScreen()->PopCommandFromUndoList();
106  wrapper = lastcmd->PopItem();
107  delete lastcmd;
108  part = (LIB_PART*) wrapper.GetItem();
109 
110  // Do not delete the previous part by calling SetCurPart( part ),
111  // which calls delete <previous part>.
112  // <previous part> is now put in redo list and is owned by this list.
113  // Just set the current part to the part which come from the undo list
114  m_my_part = part;
115 
116  if( !part )
117  return;
118 
119  if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
120  m_aliasName = part->GetName();
121 
122  m_drawItem = NULL;
125  SetShowDeMorgan( part->HasConversion() );
126  DisplayLibInfos();
127  DisplayCmpDoc();
128  OnModify();
129  m_canvas->Refresh();
130 }
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToUndoList add a command to undo in undo list delete the very old commands when t...
bool HasConversion() const
Test if part has more than one body conversion type (DeMorgan).
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
static LIB_ITEM * m_drawItem
Definition: libeditframe.h:92
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
bool HasAlias(const wxString &aName) const
Test if alias aName is in part alias list.
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen...
Definition: libeditframe.h:352
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
void UpdateAliasSelectList()
LIB_PART * m_my_part
a part I own, it is not in any library, but a copy could be.
Definition: libeditframe.h:54
void SetShowDeMorgan(bool show)
Definition: libeditframe.h:388
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
PopCommandFromUndoList return the last command to undo and remove it from list nothing is deleted...
void DisplayLibInfos()
Updates the main window title bar with the current library name and read only status of the library...
Definition: libedit.cpp:56
EDA_ITEM * GetItem() const
const wxString & GetName() const
Class LIB_ITEM definition.
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
PopCommandFromRedoList return the last command to undo and remove it from list nothing is deleted...
Class LIB_PART defines a library part object.
void GetComponentFromRedoList(wxCommandEvent &event)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void DisplayCmpDoc()
Display the documentation of the selected component.
Definition: libedit.cpp:449
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
void ClearStatus()
Clears the status flag all draw objects in this part.
static wxString m_aliasName
Definition: libeditframe.h:93
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Function PushCommandToRedoList add a command to redo in redo list delete the very old commands when t...
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
ITEM_PICKER PopItem()
Function PopItem.
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:555
void GetComponentFromUndoList(wxCommandEvent &event)
void UpdatePartSelectList()
Definition of class LIB_EDIT_FRAME.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Create a copy of the current component, and save it in the undo list.