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 <page_layout/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 157 of file undo_redo.cpp.

158 {
159  if( aImage == NULL )
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 == aItem->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:164
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:523
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:168
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:161

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

114 {
115  for( 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:458
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:407
ZONES & Zones()
Definition: board.h:292
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:306
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:735
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:326
iterator begin() const
Definition: netinfo.h:453
FOOTPRINTS & Footprints()
Definition: board.h:286
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
DRAWINGS & Drawings()
Definition: board.h:289
TRACKS & Tracks()
Definition: board.h:283
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().