KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <board.h>
#include <track.h>
#include <pcb_target.h>
#include <footprint.h>
#include <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>

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

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

References BOARD_ITEM::GetParent(), EDA_ITEM::m_Uuid, NULL, 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

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

Definition at line 111 of file undo_redo.cpp.

112 {
113  for( TRACK* item : aPcb->Tracks() )
114  {
115  if( aItem == static_cast<BOARD_ITEM*>( item ) )
116  return true;
117  }
118 
119  for( FOOTPRINT* item : aPcb->Footprints() )
120  {
121  if( aItem == static_cast<BOARD_ITEM*>( item ) )
122  return true;
123  }
124 
125  for( BOARD_ITEM* item : aPcb->Drawings() )
126  {
127  if( aItem == static_cast<BOARD_ITEM*>( item ) )
128  return true;
129  }
130 
131  for( ZONE* item : aPcb->Zones() )
132  {
133  if( aItem == static_cast<BOARD_ITEM*>( item ) )
134  return true;
135  }
136 
137  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
138 
139  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
140  {
141  if( aItem == static_cast<BOARD_ITEM*>( *i ) )
142  return true;
143  }
144 
145  for( PCB_GROUP* item : aPcb->Groups() )
146  {
147  if( aItem == static_cast<BOARD_ITEM*>( item ) )
148  return true;
149  }
150 
151  return false;
152 }
iterator end() const
Definition: netinfo.h:441
ZONES & Zones()
Definition: board.h:309
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:323
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:752
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:303
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
DRAWINGS & Drawings()
Definition: board.h:306
TRACKS & Tracks()
Definition: board.h:300
Definition: track.h:83

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().