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 (std::function< void(EDA_ITEM *)> aItemDeleter)
 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 133 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 ( std::function< void(EDA_ITEM *)>  aItemDeleter)

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 while( GetCount() > 0 )
120 {
121 ITEM_PICKER wrapper = PopItem();
122
123 if( wrapper.GetItem() == nullptr ) // No more items in list.
124 break;
125
126 // The Link is an undo construct; it is always owned by the undo/redo container
127 if( wrapper.GetLink() )
128 aItemDeleter( wrapper.GetLink() );
129
130 if( wrapper.GetFlags() & UR_TRANSIENT )
131 {
132 aItemDeleter( wrapper.GetItem() );
133 }
134 else if( wrapper.GetStatus() == UNDO_REDO::DELETED )
135 {
136 // This should really be replaced with UR_TRANSIENT, but currently many clients
137 // (eeschema in particular) abuse this to achieve non-undo-related deletions.
138 aItemDeleter( wrapper.GetItem() );
139 }
140 }
141}
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 271 of file undo_redo_container.cpp.

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

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 144 of file undo_redo_container.cpp.

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

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 155 of file undo_redo_container.cpp.

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

References m_ItemsList.

Referenced by 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 173 of file undo_redo_container.cpp.

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

References m_ItemsList.

Referenced by 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 182 of file undo_redo_container.cpp.

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

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 191 of file undo_redo_container.cpp.

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

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 164 of file undo_redo_container.cpp.

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

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 261 of file undo_redo_container.cpp.

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

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 277 of file undo_redo_container.cpp.

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

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 224 of file undo_redo_container.cpp.

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

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 200 of file undo_redo_container.cpp.

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

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 212 of file undo_redo_container.cpp.

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

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 237 of file undo_redo_container.cpp.

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

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 249 of file undo_redo_container.cpp.

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

References m_ItemsList.

Member Data Documentation

◆ m_ItemsList


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