KiCad PCB EDA Suite
PICKED_ITEMS_LIST Class Reference

A holder to handle information on schematic or board items. More...

#include <undo_redo_container.h>

Public Member Functions

 PICKED_ITEMS_LIST ()
 
 ~PICKED_ITEMS_LIST ()
 
void PushItem (const ITEM_PICKER &aItem)
 Push aItem to the top of the list. More...
 
ITEM_PICKER PopItem ()
 
bool ContainsItem (const EDA_ITEM *aItem) const
 
int FindItem (const EDA_ITEM *aItem) const
 
void ClearItemsList ()
 Delete only the list of pickers NOT the picked data itself. More...
 
void ClearListAndDeleteItems ()
 Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to the type of undo/redo command recorded. More...
 
unsigned GetCount () const
 
void ReversePickersListOrder ()
 Reverse the order of pickers stored in this list. More...
 
ITEM_PICKER GetItemWrapper (unsigned int aIdx) const
 
EDA_ITEMGetPickedItem (unsigned int aIdx) const
 
BASE_SCREENGetScreenForItem (unsigned int aIdx) const
 
EDA_ITEMGetPickedItemLink (unsigned int aIdx) const
 
UNDO_REDO GetPickedItemStatus (unsigned int aIdx) const
 
EDA_ITEM_FLAGS GetPickerFlags (unsigned aIdx) const
 Return the value of the picker flag. More...
 
bool SetPickedItem (EDA_ITEM *aItem, unsigned aIdx)
 
bool SetPickedItem (EDA_ITEM *aItem, UNDO_REDO aStatus, unsigned aIdx)
 
bool SetPickedItemLink (EDA_ITEM *aLink, unsigned aIdx)
 Set the link associated to a given picked item. More...
 
bool SetPickedItemStatus (UNDO_REDO aStatus, unsigned aIdx)
 Set the type of undo/redo operation for a given picked item. More...
 
bool SetPickerFlags (EDA_ITEM_FLAGS aFlags, unsigned aIdx)
 Set the flags of the picker (usually to the picked item m_flags value). More...
 
bool RemovePicker (unsigned aIdx)
 Remove one entry (one picker) from the list of picked items. More...
 
void CopyList (const PICKED_ITEMS_LIST &aSource)
 Copy all data from aSource to the list. More...
 

Private Attributes

std::vector< ITEM_PICKERm_ItemsList
 

Detailed Description

A holder to handle information on schematic or board items.

The information held is a pointer on each item, and the command made.

Definition at line 132 of file undo_redo_container.h.

Constructor & Destructor Documentation

◆ PICKED_ITEMS_LIST()

PICKED_ITEMS_LIST::PICKED_ITEMS_LIST ( )

Definition at line 57 of file undo_redo_container.cpp.

58{
59}

◆ ~PICKED_ITEMS_LIST()

PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST ( )

Definition at line 62 of file undo_redo_container.cpp.

63{
64}

Member Function Documentation

◆ ClearItemsList()

void PICKED_ITEMS_LIST::ClearItemsList ( )

Delete only the list of pickers NOT the picked data itself.

Definition at line 111 of file undo_redo_container.cpp.

112{
113 m_ItemsList.clear();
114}
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

Referenced by PCB_EDIT_FRAME::Edit_Zone_Params(), PCB_BASE_FRAME::PlaceFootprint(), and PCB_EDIT_FRAME::RunActionPlugin().

◆ ClearListAndDeleteItems()

void PICKED_ITEMS_LIST::ClearListAndDeleteItems ( )

Delete the list of pickers AND the data pointed by #m_PickedItem or #m_PickedItemLink according to the type of undo/redo command recorded.

Definition at line 117 of file undo_redo_container.cpp.

118{
119 // Delete items is they are not flagged NEWITEM, or if this is a block operation
120 while( GetCount() > 0 )
121 {
122 ITEM_PICKER wrapper = PopItem();
123
124 if( wrapper.GetItem() == nullptr ) // No more items in list.
125 break;
126
127 // The Link is an undo construct; it is always owned by the undo/redo container
128 if( wrapper.GetLink() )
129 delete wrapper.GetLink();
130
131 if( wrapper.GetFlags() & UR_TRANSIENT )
132 {
133 delete wrapper.GetItem();
134 }
135 else if( wrapper.GetStatus() == UNDO_REDO::DELETED )
136 {
137 // This should really be replaced with UR_TRANSIENT, but currently many clients
138 // (eeschema in particular) abuse this to achieve non-undo-related deletions.
139 delete wrapper.GetItem();
140 }
141 }
142}
EDA_ITEM * GetItem() const
EDA_ITEM * GetLink() const
EDA_ITEM_FLAGS GetFlags() const
UNDO_REDO GetStatus() const
unsigned GetCount() const
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack

References DELETED, GetCount(), ITEM_PICKER::GetFlags(), ITEM_PICKER::GetItem(), ITEM_PICKER::GetLink(), ITEM_PICKER::GetStatus(), PopItem(), and UR_TRANSIENT.

Referenced by PCB_BASE_EDIT_FRAME::ClearListAndDeleteItems(), SCH_EDIT_FRAME::ClearUndoORRedoList(), SYMBOL_EDIT_FRAME::ClearUndoORRedoList(), and PL_EDITOR_FRAME::ClearUndoORRedoList().

◆ ContainsItem()

bool PICKED_ITEMS_LIST::ContainsItem ( const EDA_ITEM aItem) const
Returns
True if aItem is found in the pick list.

Definition at line 87 of file undo_redo_container.cpp.

88{
89 for( const ITEM_PICKER& picker : m_ItemsList )
90 {
91 if( picker.GetItem() == aItem )
92 return true;
93 }
94
95 return false;
96}

References m_ItemsList.

Referenced by PCB_EDIT_FRAME::RunActionPlugin().

◆ CopyList()

void PICKED_ITEMS_LIST::CopyList ( const PICKED_ITEMS_LIST aSource)

Copy all data from aSource to the list.

Items picked are not copied. just pointer in them are copied.

Parameters
aSourceThe list of items to copy to the list.

Definition at line 272 of file undo_redo_container.cpp.

273{
274 m_ItemsList = aSource.m_ItemsList; // Vector's copy
275}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::SaveCopyInUndoList().

◆ FindItem()

int PICKED_ITEMS_LIST::FindItem ( const EDA_ITEM aItem) const
Returns
Index of the searched item. If the item is not stored in the list, negative value is returned.

Definition at line 99 of file undo_redo_container.cpp.

100{
101 for( size_t i = 0; i < m_ItemsList.size(); i++ )
102 {
103 if( m_ItemsList[i].GetItem() == aItem )
104 return i;
105 }
106
107 return -1;
108}

References m_ItemsList.

Referenced by DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::processItem().

◆ GetCount()

◆ GetItemWrapper()

ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper ( unsigned int  aIdx) const
Returns
The picker of a picked item.
Parameters
aIdxIndex of the picker in the picked list if this picker does not exist, a picker is returned, with its members set to 0 or NULL.

Definition at line 145 of file undo_redo_container.cpp.

146{
147 ITEM_PICKER picker;
148
149 if( aIdx < m_ItemsList.size() )
150 picker = m_ItemsList[aIdx];
151
152 return picker;
153}

References m_ItemsList.

Referenced by PCB_EDIT_FRAME::RunActionPlugin(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), and UpdateCopyOfZonesList().

◆ GetPickedItem()

EDA_ITEM * PICKED_ITEMS_LIST::GetPickedItem ( unsigned int  aIdx) const
Returns
A pointer to the picked item.
Parameters
aIdxIndex of the picked item in the picked list.

Definition at line 156 of file undo_redo_container.cpp.

157{
158 if( aIdx < m_ItemsList.size() )
159 return m_ItemsList[aIdx].GetItem();
160
161 return nullptr;
162}

References m_ItemsList.

Referenced by PCB_BASE_EDIT_FRAME::ClearListAndDeleteItems(), SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), PCB_EDIT_FRAME::RunActionPlugin(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), COMMIT::Stage(), and UpdateCopyOfZonesList().

◆ GetPickedItemLink()

EDA_ITEM * PICKED_ITEMS_LIST::GetPickedItemLink ( unsigned int  aIdx) const
Returns
link of the picked item, or null if does not exist.
Parameters
aIdxIndex of the picked item in the picked list.

Definition at line 174 of file undo_redo_container.cpp.

175{
176 if( aIdx < m_ItemsList.size() )
177 return m_ItemsList[aIdx].GetLink();
178
179 return nullptr;
180}

References m_ItemsList.

Referenced by PCB_BASE_EDIT_FRAME::ClearListAndDeleteItems(), SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), COMMIT::Stage(), and UpdateCopyOfZonesList().

◆ GetPickedItemStatus()

UNDO_REDO PICKED_ITEMS_LIST::GetPickedItemStatus ( unsigned int  aIdx) const
Returns
The type of undo/redo operation associated to the picked item, or UNSPECIFIED if does not exist.
Parameters
aIdxIndex of the picked item in the picked list.

Definition at line 183 of file undo_redo_container.cpp.

184{
185 if( aIdx < m_ItemsList.size() )
186 return m_ItemsList[aIdx].GetStatus();
187
189}

References m_ItemsList, and UNSPECIFIED.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), COMMIT::Stage(), and UpdateCopyOfZonesList().

◆ GetPickerFlags()

EDA_ITEM_FLAGS PICKED_ITEMS_LIST::GetPickerFlags ( unsigned  aIdx) const

Return the value of the picker flag.

Parameters
aIdxIndex of the picker in the picked list.
Returns
The value stored in the picker, if the picker exists, or 0 if does not exist.

Definition at line 192 of file undo_redo_container.cpp.

193{
194 if( aIdx < m_ItemsList.size() )
195 return m_ItemsList[aIdx].GetFlags();
196
197 return 0;
198}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState().

◆ GetScreenForItem()

BASE_SCREEN * PICKED_ITEMS_LIST::GetScreenForItem ( unsigned int  aIdx) const
Returns
A pointer to the picked item's screen.
Parameters
aIdxIndex of the picked item in the picked list.

Definition at line 165 of file undo_redo_container.cpp.

166{
167 if( aIdx < m_ItemsList.size() )
168 return m_ItemsList[aIdx].GetScreen();
169
170 return nullptr;
171}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState().

◆ PopItem()

ITEM_PICKER PICKED_ITEMS_LIST::PopItem ( )
Returns
The picker removed from the top of the list.

Definition at line 73 of file undo_redo_container.cpp.

74{
75 ITEM_PICKER item;
76
77 if( m_ItemsList.size() != 0 )
78 {
79 item = m_ItemsList.back();
80 m_ItemsList.pop_back();
81 }
82
83 return item;
84}

References m_ItemsList.

Referenced by ClearListAndDeleteItems(), PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), SYMBOL_EDIT_FRAME::GetSymbolFromRedoList(), SYMBOL_EDIT_FRAME::GetSymbolFromUndoList(), PL_EDITOR_FRAME::RollbackFromUndo(), and SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo().

◆ PushItem()

◆ RemovePicker()

bool PICKED_ITEMS_LIST::RemovePicker ( unsigned  aIdx)

Remove one entry (one picker) from the list of picked items.

Parameters
aIdxIndex of the picker in the picked list.
Returns
True if ok or false if did not exist.

Definition at line 262 of file undo_redo_container.cpp.

263{
264 if( aIdx >= m_ItemsList.size() )
265 return false;
266
267 m_ItemsList.erase( m_ItemsList.begin() + aIdx );
268 return true;
269}

References m_ItemsList.

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), and UpdateCopyOfZonesList().

◆ ReversePickersListOrder()

void PICKED_ITEMS_LIST::ReversePickersListOrder ( )

Reverse the order of pickers stored in this list.

This is useful when pop a list from Undo to Redo (and vice-versa) because sometimes undo (or redo) a command needs to keep the order of successive changes. Obviously, undo and redo are in reverse order

Definition at line 278 of file undo_redo_container.cpp.

279{
280 std::vector <ITEM_PICKER> tmp;
281
282 while( !m_ItemsList.empty() )
283 {
284 tmp.push_back( m_ItemsList.back() );
285 m_ItemsList.pop_back();
286 }
287
288 m_ItemsList.swap( tmp );
289}

References m_ItemsList.

Referenced by SCH_EDITOR_CONTROL::Redo(), PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList(), PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList(), and SCH_EDITOR_CONTROL::Undo().

◆ SetPickedItem() [1/2]

bool PICKED_ITEMS_LIST::SetPickedItem ( EDA_ITEM aItem,
UNDO_REDO  aStatus,
unsigned  aIdx 
)
Parameters
aItemA pointer to the item to pick.
aStatusThe type of undo/redo operation associated to the item to pick.
aIdxIndex of the picker in the picked list.
Returns
True if the picker exists or false if does not exist.

Definition at line 225 of file undo_redo_container.cpp.

226{
227 if( aIdx < m_ItemsList.size() )
228 {
229 m_ItemsList[aIdx].SetItem( aItem );
230 m_ItemsList[aIdx].SetStatus( aStatus );
231 return true;
232 }
233
234 return false;
235}

References m_ItemsList.

◆ SetPickedItem() [2/2]

bool PICKED_ITEMS_LIST::SetPickedItem ( EDA_ITEM aItem,
unsigned  aIdx 
)
Parameters
aItemA pointer to the item to pick.
aIdxIndex of the picker in the picked list.
Returns
True if the picker exists or false if does not exist.

Definition at line 201 of file undo_redo_container.cpp.

202{
203 if( aIdx < m_ItemsList.size() )
204 {
205 m_ItemsList[aIdx].SetItem( aItem );
206 return true;
207 }
208
209 return false;
210}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState().

◆ SetPickedItemLink()

bool PICKED_ITEMS_LIST::SetPickedItemLink ( EDA_ITEM aLink,
unsigned  aIdx 
)

Set the link associated to a given picked item.

Parameters
aLinkis the link to the item associated to the picked item.
aIdxis index of the picker in the picked list.
Returns
true if the picker exists, or false if does not exist.

Definition at line 213 of file undo_redo_container.cpp.

214{
215 if( aIdx < m_ItemsList.size() )
216 {
217 m_ItemsList[aIdx].SetLink( aLink );
218 return true;
219 }
220
221 return false;
222}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), and UpdateCopyOfZonesList().

◆ SetPickedItemStatus()

bool PICKED_ITEMS_LIST::SetPickedItemStatus ( UNDO_REDO  aStatus,
unsigned  aIdx 
)

Set the type of undo/redo operation for a given picked item.

Parameters
aStatusThe type of undo/redo operation associated to the picked item
aIdxIndex of the picker in the picked list
Returns
True if the picker exists or false if does not exist

Definition at line 238 of file undo_redo_container.cpp.

239{
240 if( aIdx < m_ItemsList.size() )
241 {
242 m_ItemsList[aIdx].SetStatus( aStatus );
243 return true;
244 }
245
246 return false;
247}

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::SaveCopyInUndoList(), PCB_BASE_EDIT_FRAME::saveCopyInUndoList(), and UpdateCopyOfZonesList().

◆ SetPickerFlags()

bool PICKED_ITEMS_LIST::SetPickerFlags ( EDA_ITEM_FLAGS  aFlags,
unsigned  aIdx 
)

Set the flags of the picker (usually to the picked item m_flags value).

Parameters
aFlagsThe flag value to save in picker.
aIdxIndex of the picker in the picked list.
Returns
True if the picker exists or false if does not exist.

Definition at line 250 of file undo_redo_container.cpp.

251{
252 if( aIdx < m_ItemsList.size() )
253 {
254 m_ItemsList[aIdx].SetFlags( aFlags );
255 return true;
256 }
257
258 return false;
259}

References m_ItemsList.

Member Data Documentation

◆ m_ItemsList


The documentation for this class was generated from the following files: