KiCad PCB EDA Suite
undo_redo.cpp File Reference
#include <functional>
#include <fctsys.h>
#include <class_drawpanel.h>
#include <class_draw_panel_gal.h>
#include <macros.h>
#include <pcbnew.h>
#include <wxPcbStruct.h>
#include <class_board.h>
#include <class_track.h>
#include <class_drawsegment.h>
#include <class_pcb_text.h>
#include <class_mire.h>
#include <class_module.h>
#include <class_dimension.h>
#include <class_zone.h>
#include <class_edge_mod.h>
#include <connectivity.h>
#include <tools/selection_tool.h>
#include <tool/tool_manager.h>
#include <view/view.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...
 

Function Documentation

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

References NETINFO_LIST::begin(), BOARD::Drawings(), NETINFO_LIST::end(), BOARD::GetArea(), BOARD::GetAreaCount(), BOARD::GetNetInfo(), BOARD::m_Modules, BOARD::m_Track, BOARD::m_Zone, and BOARD_ITEM::Next().

Referenced by PCB_BASE_EDIT_FRAME::PutDataInPreviousState().

126 {
127  static std::list<BOARD_ITEM*> itemsList;
128 
129  if( aItem == NULL ) // Build list
130  {
131  // Count items to store in itemsList:
132  BOARD_ITEM* item;
133  itemsList.clear();
134 
135  // Store items in list:
136  // Append tracks:
137  for( item = aPcb->m_Track; item != NULL; item = item->Next() )
138  itemsList.push_back( item );
139 
140  // Append modules:
141  for( item = aPcb->m_Modules; item != NULL; item = item->Next() )
142  itemsList.push_back( item );
143 
144  // Append drawings
145  for( auto ditem : aPcb->Drawings() )
146  itemsList.push_back( ditem );
147 
148  // Append zones outlines
149  for( int ii = 0; ii < aPcb->GetAreaCount(); ii++ )
150  itemsList.push_back( aPcb->GetArea( ii ) );
151 
152  // Append zones segm:
153  for( item = aPcb->m_Zone; item != NULL; item = item->Next() )
154  itemsList.push_back( item );
155 
156  NETINFO_LIST& netInfo = aPcb->GetNetInfo();
157 
158  for( NETINFO_LIST::iterator i = netInfo.begin(); i != netInfo.end(); ++i )
159  itemsList.push_back( *i );
160 
161  // Sort list
162  itemsList.sort();
163 
164  return false;
165  }
166 
167  // search in list:
168  return std::binary_search( itemsList.begin(), itemsList.end(), aItem );
169 }
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
BOARD_ITEM * Next() const
Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1025
NETINFO_LIST & GetNetInfo()
Definition: class_board.h:757
iterator begin() const
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:996
iterator end() const
DLIST< MODULE > m_Modules
Definition: class_board.h:245
DLIST< TRACK > m_Track
Definition: class_board.h:246
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251