KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <fctsys.h>
#include <macros.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 <origin_viewitem.h>
#include <connectivity/connectivity_data.h>
#include <pcbnew_settings.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 <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 156 of file undo_redo.cpp.

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

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

117 {
118  for( auto item : aPcb->Tracks() )
119  {
120  if( aItem == static_cast<BOARD_ITEM*>( item ) )
121  return true;
122  }
123 
124  // Append modules:
125  for( auto item : aPcb->Modules() )
126  {
127  if( aItem == static_cast<BOARD_ITEM*>( item ) )
128  return true;
129  }
130 
131  // Append drawings
132  for( auto item : aPcb->Drawings() )
133  {
134  if( aItem == static_cast<BOARD_ITEM*>( item ) )
135  return true;
136  }
137 
138  // Append zones outlines
139  for( auto item : aPcb->Zones() )
140  {
141  if( aItem == static_cast<BOARD_ITEM*>( item ) )
142  return true;
143  }
144 
145  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
146 
147  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
148  {
149  if( aItem == static_cast<BOARD_ITEM*>( *i ) )
150  return true;
151  }
152 
153  return false;
154 }
iterator end() const
Definition: netinfo.h:554
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:503
const NETINFO_LIST & GetNetInfo() const
Definition: class_board.h:741
MODULES & Modules()
Definition: class_board.h:266
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:422
iterator begin() const
Definition: netinfo.h:549
ZONE_CONTAINERS & Zones()
Definition: class_board.h:280
DRAWINGS & Drawings()
Definition: class_board.h:275
TRACKS & Tracks()
Definition: class_board.h:257

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

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().