KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <board.h>
#include <pcb_track.h>
#include <pcb_group.h>
#include <pcb_target.h>
#include <footprint.h>
#include <pad.h>
#include <pcb_dimension.h>
#include <origin_viewitem.h>
#include <connectivity/connectivity_data.h>
#include <pcbnew_settings.h>
#include <tool/tool_manager.h>
#include <tool/actions.h>
#include <tools/pcb_selection_tool.h>
#include <tools/pcb_control.h>
#include <tools/board_editor_control.h>
#include <drawing_sheet/ds_proxy_undo_item.h>
#include <wx/msgdlg.h>

Go to the source code of this file.

Functions

static bool TestForExistingItem (BOARD *aPcb, BOARD_ITEM *aItem)
 Test if aItem exists somewhere in undo/redo lists of items. 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 157 of file undo_redo.cpp.

158 {
159  if( aImage == nullptr )
160  return;
161 
162  wxASSERT( aItem->Type() == aImage->Type() );
163 
164  // Remark: to create images of edited items to undo, we are using Clone method
165  // which does not do a deep copy.
166  // So we have to use the current values of these parameters.
167 
168  wxASSERT( aItem->m_Uuid == aImage->m_Uuid );
169 
170  EDA_ITEM* parent = aItem->GetParent();
171 
172  aItem->SwapData( aImage );
173 
174  // Restore pointers to be sure they are not broken
175  aItem->SetParent( parent );
176 }
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
virtual void SwapData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Definition: board_item.cpp:151
const KIID m_Uuid
Definition: eda_item.h:475
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:166
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113

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

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

◆ TestForExistingItem()

static bool TestForExistingItem ( BOARD aPcb,
BOARD_ITEM aItem 
)
static

Test if aItem exists somewhere in undo/redo lists of items.

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 Before using this function to test existence of items, it must be called with aItem = NULL to prepare the list.
Parameters
aPcbis the board to test.
aItemis the item to find or NULL to build the list of existing items.

Definition at line 113 of file undo_redo.cpp.

114 {
115  for( PCB_TRACK* item : aPcb->Tracks() )
116  {
117  if( aItem == static_cast<BOARD_ITEM*>( item ) )
118  return true;
119  }
120 
121  for( FOOTPRINT* item : aPcb->Footprints() )
122  {
123  if( aItem == static_cast<BOARD_ITEM*>( item ) )
124  return true;
125  }
126 
127  for( BOARD_ITEM* item : aPcb->Drawings() )
128  {
129  if( aItem == static_cast<BOARD_ITEM*>( item ) )
130  return true;
131  }
132 
133  for( ZONE* item : aPcb->Zones() )
134  {
135  if( aItem == static_cast<BOARD_ITEM*>( item ) )
136  return true;
137  }
138 
139  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
140 
141  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
142  {
143  if( aItem == static_cast<BOARD_ITEM*>( *i ) )
144  return true;
145  }
146 
147  for( PCB_GROUP* item : aPcb->Groups() )
148  {
149  if( aItem == static_cast<BOARD_ITEM*>( item ) )
150  return true;
151  }
152 
153  return false;
154 }
iterator end() const
Definition: netinfo.h:441
ZONES & Zones()
Definition: board.h:239
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:253
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:684
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:315
iterator begin() const
Definition: netinfo.h:436
FOOTPRINTS & Footprints()
Definition: board.h:233
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
DRAWINGS & Drawings()
Definition: board.h:236
TRACKS & Tracks()
Definition: board.h:230

References NETINFO_LIST::begin(), BOARD::Drawings(), NETINFO_LIST::end(), BOARD::Footprints(), BOARD::GetNetInfo(), BOARD::Groups(), BOARD::Tracks(), and BOARD::Zones().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().