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 <pcb_edit_frame.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 <origin_viewitem.h>
#include <connectivity_data.h>
#include <tools/selection_tool.h>
#include <tools/pcbnew_control.h>
#include <tools/pcb_editor_control.h>
#include <tool/tool_manager.h>
#include <view/view.h>

Go to the source code of this file.


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,

Definition at line 174 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().

175 {
176  if( aImage == NULL )
177  return;
179  wxASSERT( aItem->Type() == aImage->Type() );
181  // Remark: to create images of edited items to undo, we are using Clone method
182  // which can duplication of items foe copy, but does not clone all members
183  // mainly pointers in chain and time stamp, which is set to new, unique value.
184  // So we have to use the current values of these parameters.
186  EDA_ITEM* pnext = aItem->Next();
187  EDA_ITEM* pback = aItem->Back();
188  DHEAD* mylist = aItem->GetList();
189  timestamp_t timestamp = aItem->GetTimeStamp();
190  EDA_ITEM* parent = aItem->GetParent();
192  aItem->SwapData( aImage );
194  // Restore pointers and time stamp, to be sure they are not broken
195  aItem->SetNext( pnext );
196  aItem->SetBack( pback );
197  aItem->SetList( mylist );
198  aItem->SetTimeStamp( timestamp );
199  aItem->SetParent( parent );
200 }
DHEAD * GetList() const
Definition: base_struct.h:238
KICAD_T Type() const
Function Type()
Definition: base_struct.h:227
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:173
void SetBack(EDA_ITEM *aBack)
Definition: base_struct.h:241
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:243
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:242
void SetNext(EDA_ITEM *aNext)
Definition: base_struct.h:240
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:180
BOARD_ITEM * Back() const
timestamp_t GetTimeStamp() const
Definition: base_struct.h:233
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:232
static bool TestForExistingItem ( BOARD aPcb,

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
    aPcb= board to test
    aItem= item to find = NULL to build the list of existing items

Definition at line 128 of file undo_redo.cpp.

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

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

129 {
130  static std::list<BOARD_ITEM*> itemsList;
132  if( aItem == NULL ) // Build list
133  {
134  // Count items to store in itemsList:
135  BOARD_ITEM* item;
136  itemsList.clear();
138  // Store items in list:
139  // Append tracks:
140  for( item = aPcb->m_Track; item != NULL; item = item->Next() )
141  itemsList.push_back( item );
143  // Append modules:
144  for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
145  itemsList.push_back( item );
147  // Append drawings
148  for( auto ditem : aPcb->Drawings() )
149  itemsList.push_back( ditem );
151  // Append zones outlines
152  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
153  itemsList.push_back( aPcb->GetArea( ii ) );
155  // Append zones segm:
156  for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
157  itemsList.push_back( item );
159  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
161  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
162  itemsList.push_back( *i );
164  // Sort list
165  itemsList.sort();
167  return false;
168  }
170  // search in list:
171  return std::binary_search( itemsList.begin(), itemsList.end(), aItem );
172 }
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:478
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
Definition: class_board.h:247
BOARD_ITEM * Next() const
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:407
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
Definition: class_board.h:743
iterator begin() const
Definition: netinfo.h:524
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
Definition: netinfo.h:529
DLIST< MODULE > m_Modules
Definition: class_board.h:245
size_t i
Definition: json11.cpp:597
DLIST< TRACK > m_Track
Definition: class_board.h:246
Definition: class_board.h:251