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
 
STATUS_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 (STATUS_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 134 of file undo_redo_container.h.

Constructor & Destructor Documentation

◆ PICKED_ITEMS_LIST()

PICKED_ITEMS_LIST::PICKED_ITEMS_LIST ( )

Definition at line 61 of file undo_redo_container.cpp.

62 {
63 }

◆ ~PICKED_ITEMS_LIST()

PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST ( )

Definition at line 65 of file undo_redo_container.cpp.

66 {
67 }

Member Function Documentation

◆ ClearItemsList()

void PICKED_ITEMS_LIST::ClearItemsList ( )

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

Definition at line 114 of file undo_redo_container.cpp.

115 {
116  m_ItemsList.clear();
117 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

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

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

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

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

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

◆ ContainsItem()

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

Definition at line 90 of file undo_redo_container.cpp.

91 {
92  for( const ITEM_PICKER& picker : m_ItemsList )
93  {
94  if( picker.GetItem() == aItem )
95  return true;
96  }
97 
98  return false;
99 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

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

275 {
276  m_ItemsList = aSource.m_ItemsList; // Vector's copy
277 }
std::vector< ITEM_PICKER > m_ItemsList

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

103 {
104  for( size_t i = 0; i < m_ItemsList.size(); i++ )
105  {
106  if( m_ItemsList[i].GetItem() == aItem )
107  return i;
108  }
109 
110  return -1;
111 }
std::vector< ITEM_PICKER > m_ItemsList

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

148 {
149  ITEM_PICKER picker;
150 
151  if( aIdx < m_ItemsList.size() )
152  picker = m_ItemsList[aIdx];
153 
154  return picker;
155 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

Referenced by PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), SCH_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 158 of file undo_redo_container.cpp.

159 {
160  if( aIdx < m_ItemsList.size() )
161  return m_ItemsList[aIdx].GetItem();
162 
163  return NULL;
164 }
std::vector< ITEM_PICKER > m_ItemsList
#define NULL

References m_ItemsList, and NULL.

Referenced by PCB_EDIT_FRAME::Edit_Zone_Params(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), SCH_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 176 of file undo_redo_container.cpp.

177 {
178  if( aIdx < m_ItemsList.size() )
179  return m_ItemsList[aIdx].GetLink();
180 
181  return NULL;
182 }
std::vector< ITEM_PICKER > m_ItemsList
#define NULL

References m_ItemsList, and NULL.

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), SCH_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 185 of file undo_redo_container.cpp.

186 {
187  if( aIdx < m_ItemsList.size() )
188  return m_ItemsList[aIdx].GetStatus();
189 
190  return UNDO_REDO::UNSPECIFIED;
191 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList, and UNSPECIFIED.

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

◆ GetPickerFlags()

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

195 {
196  if( aIdx < m_ItemsList.size() )
197  return m_ItemsList[aIdx].GetFlags();
198 
199  return 0;
200 }
std::vector< ITEM_PICKER > m_ItemsList

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 sceen.
Parameters
aIdxIndex of the picked item in the picked list.

Definition at line 167 of file undo_redo_container.cpp.

168 {
169  if( aIdx < m_ItemsList.size() )
170  return m_ItemsList[aIdx].GetScreen();
171 
172  return NULL;
173 }
std::vector< ITEM_PICKER > m_ItemsList
#define NULL

References m_ItemsList, and NULL.

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

77 {
78  ITEM_PICKER item;
79 
80  if( m_ItemsList.size() != 0 )
81  {
82  item = m_ItemsList.back();
83  m_ItemsList.pop_back();
84  }
85 
86  return item;
87 }
std::vector< ITEM_PICKER > m_ItemsList

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

265 {
266  if( aIdx >= m_ItemsList.size() )
267  return false;
268 
269  m_ItemsList.erase( m_ItemsList.begin() + aIdx );
270  return true;
271 }
std::vector< ITEM_PICKER > m_ItemsList

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

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

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

204 {
205  if( aIdx < m_ItemsList.size() )
206  {
207  m_ItemsList[aIdx].SetItem( aItem );
208  return true;
209  }
210 
211  return false;
212 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState().

◆ SetPickedItem() [2/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 227 of file undo_redo_container.cpp.

228 {
229  if( aIdx < m_ItemsList.size() )
230  {
231  m_ItemsList[aIdx].SetItem( aItem );
232  m_ItemsList[aIdx].SetStatus( aStatus );
233  return true;
234  }
235 
236  return false;
237 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

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

216 {
217  if( aIdx < m_ItemsList.size() )
218  {
219  m_ItemsList[aIdx].SetLink( aLink );
220  return true;
221  }
222 
223  return false;
224 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState(), PCB_BASE_EDIT_FRAME::SaveCopyInUndoList(), SCH_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 240 of file undo_redo_container.cpp.

241 {
242  if( aIdx < m_ItemsList.size() )
243  {
244  m_ItemsList[aIdx].SetStatus( aStatus );
245  return true;
246  }
247 
248  return false;
249 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

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

◆ SetPickerFlags()

bool PICKED_ITEMS_LIST::SetPickerFlags ( STATUS_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 252 of file undo_redo_container.cpp.

253 {
254  if( aIdx < m_ItemsList.size() )
255  {
256  m_ItemsList[aIdx].SetFlags( aFlags );
257  return true;
258  }
259 
260  return false;
261 }
std::vector< ITEM_PICKER > m_ItemsList

References m_ItemsList.

Member Data Documentation

◆ m_ItemsList


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