KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <fctsys.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/connectivity_data.h>
#include <tool/tool_manager.h>
#include <tool/actions.h>
#include <tools/selection_tool.h>
#include <tools/pcbnew_control.h>
#include <tools/pcb_editor_control.h>
#include <view/view.h>
#include <ws_proxy_undo_item.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

◆ SwapItemData()

static void SwapItemData ( BOARD_ITEM aItem,
BOARD_ITEM aImage 
)
static

Definition at line 160 of file undo_redo.cpp.

161 {
162  if( aImage == NULL )
163  return;
164 
165  wxASSERT( aItem->Type() == aImage->Type() );
166 
167  // Remark: to create images of edited items to undo, we are using Clone method
168  // which can duplication of items foe copy, but does not clone all members
169  // mainly pointers in chain and time stamp, which is set to new, unique value.
170  // So we have to use the current values of these parameters.
171 
172  timestamp_t timestamp = aItem->GetTimeStamp();
173  EDA_ITEM* parent = aItem->GetParent();
174 
175  aItem->SwapData( aImage );
176 
177  // Restore pointers and time stamp, to be sure they are not broken
178  aItem->SetTimeStamp( timestamp );
179  aItem->SetParent( parent );
180 }
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:225
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215

References BOARD_ITEM::GetParent(), EDA_ITEM::GetTimeStamp(), EDA_ITEM::SetParent(), EDA_ITEM::SetTimeStamp(), BOARD_ITEM::SwapData(), and EDA_ITEM::Type().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

◆ TestForExistingItem()

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

121 {
122  for( auto item : aPcb->Tracks() )
123  {
124  if( aItem == static_cast<BOARD_ITEM*>( item ) )
125  return true;
126  }
127 
128  // Append modules:
129  for( auto item : aPcb->Modules() )
130  {
131  if( aItem == static_cast<BOARD_ITEM*>( item ) )
132  return true;
133  }
134 
135  // Append drawings
136  for( auto item : aPcb->Drawings() )
137  {
138  if( aItem == static_cast<BOARD_ITEM*>( item ) )
139  return true;
140  }
141 
142  // Append zones outlines
143  for( auto item : aPcb->Zones() )
144  {
145  if( aItem == static_cast<BOARD_ITEM*>( item ) )
146  return true;
147  }
148 
149  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
150 
151  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
152  {
153  if( aItem == static_cast<BOARD_ITEM*>( *i ) )
154  return true;
155  }
156 
157  return false;
158 }
iterator end() const
Definition: netinfo.h:531
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:480
MODULES & Modules()
Definition: class_board.h:227
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:409
iterator begin() const
Definition: netinfo.h:526
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:738
ZONE_CONTAINERS & Zones()
Definition: class_board.h:241
size_t i
Definition: json11.cpp:649
DRAWINGS & Drawings()
Definition: class_board.h:236
TRACKS & Tracks()
Definition: class_board.h:218

References NETINFO_LIST::begin(), BOARD::Drawings(), NETINFO_LIST::end(), BOARD::GetNetInfo(), i, BOARD::Modules(), BOARD::Tracks(), and BOARD::Zones().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().