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 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 <general.h>
29 //#include <protos.h>
30 #include <libeditframe.h>
31 #include <class_libentry.h>
32 
33 
35 {
36  LIB_PART* CopyItem;
37  PICKED_ITEMS_LIST* lastcmd;
38 
39  CopyItem = new LIB_PART( * (LIB_PART*) ItemToCopy );
40 
41  // Clear current flags (which can be temporary set by a current edit command).
42  CopyItem->ClearStatus();
43 
44  lastcmd = new PICKED_ITEMS_LIST();
45  ITEM_PICKER wrapper( CopyItem, UR_LIBEDIT );
46  lastcmd->PushItem(wrapper);
47  GetScreen()->PushCommandToUndoList( lastcmd );
48 
49  // Clear redo list, because after new save there is no redo to do.
50  GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList );
51 }
52 
53 
54 void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event )
55 {
56  if( GetScreen()->GetRedoCommandCount() <= 0 )
57  return;
58 
59  PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
60 
61  LIB_PART* part = GetCurPart();
62 
63  ITEM_PICKER wrapper( part, UR_LIBEDIT );
64 
65  lastcmd->PushItem( wrapper );
66  GetScreen()->PushCommandToUndoList( lastcmd );
67 
68  lastcmd = GetScreen()->PopCommandFromRedoList();
69 
70  wrapper = lastcmd->PopItem();
71 
72  part = (LIB_PART*) wrapper.GetItem();
73 
74  // Do not delete the previous part by calling SetCurPart( part )
75  // which calls delete <previous part>.
76  // <previous part> is now put in undo list and is owned by this list
77  // Just set the current part to the part which come from the redo list
78  m_my_part = part;
79 
80  if( !part )
81  return;
82 
83  if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
84  m_aliasName = part->GetName();
85 
86  m_drawItem = NULL;
89  SetShowDeMorgan( part->HasConversion() );
91  DisplayCmpDoc();
92  OnModify();
93  m_canvas->Refresh();
94 }
95 
96 
97 void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event )
98 {
99  if( GetScreen()->GetUndoCommandCount() <= 0 )
100  return;
101 
102  PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST();
103 
104  LIB_PART* part = GetCurPart();
105 
106  ITEM_PICKER wrapper( part, UR_LIBEDIT );
107 
108  lastcmd->PushItem( wrapper );
109  GetScreen()->PushCommandToRedoList( lastcmd );
110 
111  lastcmd = GetScreen()->PopCommandFromUndoList();
112 
113  wrapper = lastcmd->PopItem();
114 
115  part = (LIB_PART* ) wrapper.GetItem();
116 
117  // Do not delete the previous part by calling SetCurPart( part ),
118  // which calls delete <previous part>.
119  // <previous part> is now put in redo list and is owned by this list.
120  // Just set the current part to the part which come from the undo list
121  m_my_part = part;
122 
123  if( !part )
124  return;
125 
126  if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
127  m_aliasName = part->GetName();
128 
129  m_drawItem = NULL;
132  SetShowDeMorgan( part->HasConversion() );
133  DisplayLibInfos();
134  DisplayCmpDoc();
135  OnModify();
136  m_canvas->Refresh();
137 }
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
Definition: draw_panel.cpp:326
static LIB_ITEM * m_drawItem
Definition: libeditframe.h:91
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()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: libeditframe.h:369
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:53
void SetShowDeMorgan(bool show)
Definition: libeditframe.h:405
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
PopCommandFromUndoList return the last command to undo and remove it from list nothing is deleted...
void DisplayLibInfos()
Function DisplayLibInfos updates the main window title bar with the current library name and read onl...
Definition: libedit.cpp:55
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()
Function DisplayCmpDoc displays the documentation of the selected component.
Definition: libedit.cpp:464
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void ClearStatus()
Clears the status flag all draw objects in this part.
static wxString m_aliasName
Definition: libeditframe.h:92
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()
Function GetCurPart returns 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:151
ITEM_PICKER PopItem()
Function PopItem.
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Function ClearUndoORRedoList free the undo or redo list from List element Wrappers are deleted...
Definition: sch_screen.cpp:597
void GetComponentFromUndoList(wxCommandEvent &event)
void UpdatePartSelectList()
Definition of class LIB_EDIT_FRAME.
void SaveCopyInUndoList(EDA_ITEM *ItemToCopy)
Function SaveCopyInUndoList.