KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <fctsys.h>
#include <class_drawpanel.h>
#include <class_draw_panel_gal.h>
#include <macros.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <class_board.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <class_pcb_text.h>
#include <class_pcb_target.h>
#include <class_module.h>
#include <class_dimension.h>
#include <class_zone.h>
#include <class_edge_mod.h>
#include <connectivity_data.h>
#include <tools/selection_tool.h>
#include <tool/tool_manager.h>
#include <view/view.h>

Go to the source code of this file.

Functions

static bool TestForExistingItem (BOARD *aPcb, BOARD_ITEM *aItem)
 Function TestForExistingItem test if aItem exists somewhere in lists of items This is a function used by PutDataInPreviousState to be sure an item was not deleted since an undo or redo. More...
 
static void SwapItemData (BOARD_ITEM *aItem, BOARD_ITEM *aImage)
 

Function Documentation

static void SwapItemData ( BOARD_ITEM aItem,
BOARD_ITEM aImage 
)
static

Definition at line 171 of file undo_redo.cpp.

References BOARD_ITEM::Back(), EDA_ITEM::GetList(), BOARD_ITEM::GetParent(), EDA_ITEM::GetTimeStamp(), BOARD_ITEM::Next(), EDA_ITEM::SetBack(), EDA_ITEM::SetList(), EDA_ITEM::SetNext(), EDA_ITEM::SetParent(), EDA_ITEM::SetTimeStamp(), BOARD_ITEM::SwapData(), and EDA_ITEM::Type().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

172 {
173  if( aImage == NULL )
174  return;
175 
176  wxASSERT( aItem->Type() == aImage->Type() );
177 
178  // Remark: to create images of edited items to undo, we are using Clone method
179  // which can duplication of items foe copy, but does not clone all members
180  // mainly pointers in chain and time stamp, which is set to new, unique value.
181  // So we have to use the current values of these parameters.
182 
183  EDA_ITEM* pnext = aItem->Next();
184  EDA_ITEM* pback = aItem->Back();
185  DHEAD* mylist = aItem->GetList();
186  timestamp_t timestamp = aItem->GetTimeStamp();
187  EDA_ITEM* parent = aItem->GetParent();
188 
189  aItem->SwapData( aImage );
190 
191  // Restore pointers and time stamp, to be sure they are not broken
192  aItem->SetNext( pnext );
193  aItem->SetBack( pback );
194  aItem->SetList( mylist );
195  aItem->SetTimeStamp( timestamp );
196  aItem->SetParent( parent );
197 }
DHEAD * GetList() const
Definition: base_struct.h:236
KICAD_T Type() const
Function Type()
Definition: base_struct.h:225
BOARD_ITEM_CONTAINER * GetParent() const
long timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: base_struct.h:171
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:239
Class DHEAD is only for use by template class DLIST, use that instead.
Definition: dlist.h:40
void SetList(DHEAD *aList)
Definition: base_struct.h:241
BOARD_ITEM * Next() const
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:240
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:238
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:178
BOARD_ITEM * Back() const
timestamp_t GetTimeStamp() const
Definition: base_struct.h:231
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:230
static bool TestForExistingItem ( BOARD aPcb,
BOARD_ITEM aItem 
)
static

Function TestForExistingItem test if aItem exists somewhere in lists of items This is a function used by PutDataInPreviousState to be sure an item was not deleted since an undo or redo.

This could be possible:

  • if a call to SaveCopyInUndoList was forgotten in Pcbnew
  • in zones outlines, when a change in one zone merges this zone with an other This function avoids a Pcbnew crash Before using this function to test existence of items, it must be called with aItem = NULL to prepare the list
    Parameters
    aPcb= board to test
    aItem= item to find = NULL to build the list of existing items

Definition at line 125 of file undo_redo.cpp.

References NETINFO_LIST::begin(), BOARD::Drawings(), NETINFO_LIST::end(), BOARD::GetArea(), BOARD::GetAreaCount(), BOARD::GetNetInfo(), BOARD::m_Modules, BOARD::m_Track, BOARD::m_Zone, and BOARD_ITEM::Next().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

126 {
127  static std::list<BOARD_ITEM*> itemsList;
128 
129  if( aItem == NULL ) // Build list
130  {
131  // Count items to store in itemsList:
132  BOARD_ITEM* item;
133  itemsList.clear();
134 
135  // Store items in list:
136  // Append tracks:
137  for( item = aPcb->m_Track; item != NULL; item = item->Next() )
138  itemsList.push_back( item );
139 
140  // Append modules:
141  for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
142  itemsList.push_back( item );
143 
144  // Append drawings
145  for( auto ditem : aPcb->Drawings() )
146  itemsList.push_back( ditem );
147 
148  // Append zones outlines
149  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
150  itemsList.push_back( aPcb->GetArea( ii ) );
151 
152  // Append zones segm:
153  for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
154  itemsList.push_back( item );
155 
156  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
157 
158  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
159  itemsList.push_back( *i );
160 
161  // Sort list
162  itemsList.sort();
163 
164  return false;
165  }
166 
167  // search in list:
168  return std::binary_search( itemsList.begin(), itemsList.end(), aItem );
169 }
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
BOARD_ITEM * Next() const
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:743
iterator begin() const
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
iterator end() const
DLIST< MODULE > m_Modules
Definition: class_board.h:245
DLIST< TRACK > m_Track
Definition: class_board.h:246
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251