KiCad PCB EDA Suite
zones_functions_for_undo_redo.cpp File Reference
#include <fctsys.h>
#include <pgm_base.h>
#include <pcb_edit_frame.h>
#include <class_board.h>
#include <class_zone.h>
#include <pcbnew.h>
#include <zones.h>
#include <zones_functions_for_undo_redo.h>

Go to the source code of this file.

Functions

int SaveCopyOfZones (PICKED_ITEMS_LIST &aPickList, BOARD *aPcb, int aNetCode, LAYER_NUM aLayer)
 Function SaveCopyOfZones creates a copy of zones having a given netcode on a given layer, and fill a pick list with pickers to handle these copies the UndoRedo status is set to UR_CHANGED for all items in list Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing. More...
 
void UpdateCopyOfZonesList (PICKED_ITEMS_LIST &aPickList, PICKED_ITEMS_LIST &aAuxiliaryList, BOARD *aPcb)
 Function UpdateCopyOfZonesList Check a pick list to remove zones identical to their copies and set the type of operation in picker (UR_DELETED, UR_CHANGED). More...
 

Function Documentation

◆ SaveCopyOfZones()

int SaveCopyOfZones ( PICKED_ITEMS_LIST aPickList,
BOARD aPcb,
int  aNetCode,
LAYER_NUM  aLayer 
)

Function SaveCopyOfZones creates a copy of zones having a given netcode on a given layer, and fill a pick list with pickers to handle these copies the UndoRedo status is set to UR_CHANGED for all items in list Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing.

Function SaveCopyOfZones creates a copy of zones having a given netcode on a given layer, and fill a pick list with pickers to handle these copies.

Parameters
aPickList= the pick list
aPcb= the Board
aNetCode= the reference netcode. if aNetCode < 0 all netcodes are used
aLayer= the layer of zones. if aLayer < 0, all layers are used
Returns
the count of saved copies

Definition at line 147 of file zones_functions_for_undo_redo.cpp.

148 {
149  int copyCount = 0;
150 
151  for( unsigned ii = 0; ; ii++ )
152  {
153  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
154 
155  if( zone == NULL ) // End of list
156  break;
157 
158  if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
159  continue;
160 
161  if( aLayer >= 0 && !zone->GetLayerSet().test( aLayer ) )
162  continue;
163 
164  ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
165  zoneDup->SetParent( aPcb );
166  ITEM_PICKER picker( nullptr, zone, UR_CHANGED );
167  picker.SetLink( zoneDup );
168  aPickList.PushItem( picker );
169  copyCount++;
170  }
171 
172  return copyCount;
173 }
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
int GetNetCode() const
Function GetNetCode.
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:312
#define NULL
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:897

References BOARD::GetArea(), ZONE_CONTAINER::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), NULL, PICKED_ITEMS_LIST::PushItem(), ITEM_PICKER::SetLink(), EDA_ITEM::SetParent(), and UR_CHANGED.

Referenced by PCB_EDIT_FRAME::Edit_Zone_Params().

◆ UpdateCopyOfZonesList()

void UpdateCopyOfZonesList ( PICKED_ITEMS_LIST aPickList,
PICKED_ITEMS_LIST aAuxiliaryList,
BOARD aPcb 
)

Function UpdateCopyOfZonesList Check a pick list to remove zones identical to their copies and set the type of operation in picker (UR_DELETED, UR_CHANGED).

Function UpdateCopyOfZonesList check a pick list to remove zones identical to their copies and set the type of operation in picker (UR_DELETED, UR_CHANGED)

If an item is deleted, the initial values are retrievered, because they can have changed during editing.

Parameters
aPickList= the main pick list
aAuxiliaryList= the list of deleted or added (new created) items after calculations
aPcb= the Board

aAuxiliaryList is a list of pickers updated by zone algorithms: This list contains zones which were added or deleted during the zones combine process aPickList :is a list of zones that can be modified (changed or deleted, or not modified) Typically, this is the list of existing zones on the layer of the edited zone, before any change.

if the picked zone is not changed, it is removed from list if the picked zone was deleted (i.e. not found in board list), the picker is modified:

its status becomes UR_DELETED the aAuxiliaryList corresponding picker is removed (if not found : set an error)

if the picked zone was flagged as UR_NEW, and was after deleted ,

perhaps combined with another zone (i.e. not found in board list): the picker is removed the zone itself if really deleted the aAuxiliaryList corresponding picker is removed (if not found : set an error) After aPickList is cleaned, the aAuxiliaryList is read All pickers flagged UR_NEW are moved to aPickList (the corresponding zones are zone that were created by the zone normalize and combine process, mainly when adding cutout areas, or creating self intersecting contours) All pickers flagged UR_DELETED are removed, and the coresponding zones actually deleted (the corresponding zones are new zone that were created by the zone normalize process, when creating self intersecting contours, and after combined with an existing zone. At the end of the update process the aAuxiliaryList must be void, because all pickers created by the combine process must have been removed (removed for new and deleted zones, or moved in aPickList.) If not an error is set.

Definition at line 211 of file zones_functions_for_undo_redo.cpp.

214 {
215  for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
216  {
217  UNDO_REDO_T status = aPickList.GetPickedItemStatus( kk );
218 
219  ZONE_CONTAINER* ref = (ZONE_CONTAINER*) aPickList.GetPickedItem( kk );
220 
221  for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
222  {
223  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
224 
225  if( zone == NULL )
226  {
227  /* End of list: the stored item is not found:
228  * it must be in aDeletedList:
229  * search it and restore initial values
230  * or
231  * if flagged UR_NEW: remove it definitively
232  */
233  if( status == UR_NEW )
234  {
235  delete ref;
236  ref = NULL;
237  aPickList.RemovePicker( kk );
238  kk--;
239  }
240  else
241  {
242  ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
243  aPickList.SetPickedItemStatus( UR_DELETED, kk );
244 
245  wxASSERT_MSG( zcopy != NULL,
246  wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
247 
248  *ref = *zcopy;
249 
250  // the copy was deleted; the link does not exists now.
251  aPickList.SetPickedItemLink( NULL, kk );
252  delete zcopy;
253  }
254 
255  // Remove this item from aAuxiliaryList, mainly for tests purpose
256  bool notfound = true;
257 
258  for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
259  {
260  if( ref != NULL && aAuxiliaryList.GetPickedItem( nn ) == ref )
261  {
262  aAuxiliaryList.RemovePicker( nn );
263  notfound = false;
264  break;
265  }
266  }
267 
268  if( notfound ) // happens when the new zone overlaps an existing zone
269  // and these zones are combined
270  {
271  DBG( printf(
272  "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
273  "combined with another zone\n" ) );
274  }
275  break;
276  }
277 
278  if( zone == ref ) // picked zone found
279  {
280  if( aPickList.GetPickedItemStatus( kk ) != UR_NEW )
281  {
282  ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
283 
284  if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
285  {
286  delete zcopy; // Delete copy
287  aPickList.RemovePicker( kk );
288  kk--;
289  }
290  }
291 
292  break;
293  }
294  }
295  }
296 
297  // Add new zones in main pick list, and remove pickers from Auxiliary List
298  for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
299  {
300  if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_NEW )
301  {
302  ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
303  aPickList.PushItem( picker );
304  aAuxiliaryList.RemovePicker( ii );
305  }
306  else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_DELETED )
307  {
308  delete aAuxiliaryList.GetPickedItemLink( ii );
309  aAuxiliaryList.RemovePicker( ii );
310  }
311  else
312  ii++;
313  }
314 
315  // Should not occur:
316  wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
317  wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
318 }
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
UNDO_REDO_T
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
unsigned GetCount() const
Function GetCount.
#define NULL
bool IsSame(const ZONE_CONTAINER &aZoneToCompare)
Function IsSame tests if 2 zones are equivalent: 2 zones are equivalent if they have same parameters ...
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
bool RemovePicker(unsigned aIdx)
Function RemovePicker removes one entry (one picker) from the list of picked items.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
Function GetItemWrapper.
bool SetPickedItemStatus(UNDO_REDO_T aStatus, unsigned aIdx)
Function SetPickedItemStatus sets the type of undo/redo operation for a given picked item.
UNDO_REDO_T GetPickedItemStatus(unsigned int aIdx) const
Function GetPickedItemStatus.
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Function SetPickedItemLink set the link associated to a given picked item.
#define DBG(x)
Definition: fctsys.h:33
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:897

References DBG, BOARD::GetArea(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetItemWrapper(), PICKED_ITEMS_LIST::GetPickedItem(), PICKED_ITEMS_LIST::GetPickedItemLink(), PICKED_ITEMS_LIST::GetPickedItemStatus(), ZONE_CONTAINER::IsSame(), NULL, PICKED_ITEMS_LIST::PushItem(), PICKED_ITEMS_LIST::RemovePicker(), PICKED_ITEMS_LIST::SetPickedItemLink(), PICKED_ITEMS_LIST::SetPickedItemStatus(), UR_DELETED, and UR_NEW.

Referenced by PCB_EDIT_FRAME::Edit_Zone_Params().