KiCad PCB EDA Suite
zones_functions_for_undo_redo.h File Reference

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. 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 (DELETED, 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.

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

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 145 of file zones_functions_for_undo_redo.cpp.

146 {
147  int copyCount = 0;
148 
149  for( unsigned ii = 0; ; ii++ )
150  {
151  ZONE* zone = aPcb->GetArea( ii );
152 
153  if( zone == nullptr ) // End of list
154  break;
155 
156  if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
157  continue;
158 
159  if( aLayer >= 0 && !zone->GetLayerSet().test( aLayer ) )
160  continue;
161 
162  ZONE* zoneDup = new ZONE( *zone );
163  zoneDup->SetParent( aPcb );
164  ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
165  picker.SetLink( zoneDup );
166  aPickList.PushItem( picker );
167  copyCount++;
168  }
169 
170  return copyCount;
171 }
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:295
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition: board.h:829
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
Handle a list of polygons defining a copper zone.
Definition: zone.h:56

References CHANGED, BOARD::GetArea(), ZONE::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), PICKED_ITEMS_LIST::PushItem(), ITEM_PICKER::SetLink(), and EDA_ITEM::SetParent().

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 (DELETED, CHANGED)

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

Function UpdateCopyOfZonesList check a pick list to remove zones identical to their copies and set the type of operation in picker (DELETED, 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 DELETED the aAuxiliaryList corresponding picker is removed (if not found : set an error)

if the picked zone was flagged as NEWITEM, 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 NEWITEM 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 DELETED are removed, and the corresponding 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 209 of file zones_functions_for_undo_redo.cpp.

212 {
213  for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
214  {
215  UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
216 
217  ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
218 
219  for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
220  {
221  ZONE* zone = aPcb->GetArea( ii );
222 
223  if( zone == nullptr )
224  {
225  /* End of list: the stored item is not found:
226  * it must be in aDeletedList:
227  * search it and restore initial values
228  * or
229  * if flagged NEWITEM: remove it definitively
230  */
231  if( status == UNDO_REDO::NEWITEM )
232  {
233  delete ref;
234  ref = nullptr;
235  aPickList.RemovePicker( kk );
236  kk--;
237  }
238  else
239  {
240  ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
241  aPickList.SetPickedItemStatus( UNDO_REDO::DELETED, kk );
242 
243  wxASSERT_MSG( zcopy != nullptr,
244  wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
245 
246  *ref = *zcopy;
247 
248  // the copy was deleted; the link does not exists now.
249  aPickList.SetPickedItemLink( nullptr, kk );
250  delete zcopy;
251  }
252 
253  // Remove this item from aAuxiliaryList, mainly for tests purpose
254  bool notfound = true;
255 
256  for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
257  {
258  if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
259  {
260  aAuxiliaryList.RemovePicker( nn );
261  notfound = false;
262  break;
263  }
264  }
265 
266  if( notfound ) // happens when the new zone overlaps an existing zone
267  // and these zones are combined
268  {
269  #if defined(DEBUG)
270  printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
271  "combined with another zone\n" );
272  fflush(nullptr);
273  #endif
274  }
275  break;
276  }
277 
278  if( zone == ref ) // picked zone found
279  {
280  if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
281  {
282  ZONE* zcopy = (ZONE*) 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 ) == UNDO_REDO::NEWITEM )
301  {
302  ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
303  aPickList.PushItem( picker );
304  aAuxiliaryList.RemovePicker( ii );
305  }
306  else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::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
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
bool IsSame(const ZONE &aZoneToCompare)
Test if 2 zones are equivalent.
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition: board.h:829
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
unsigned GetCount() const
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
bool RemovePicker(unsigned aIdx)
Remove one entry (one picker) from the list of picked items.
ITEM_PICKER GetItemWrapper(unsigned int aIdx) const
bool SetPickedItemStatus(UNDO_REDO aStatus, unsigned aIdx)
Set the type of undo/redo operation for a given picked item.
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Set the link associated to a given picked item.
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const

References DELETED, BOARD::GetArea(), PICKED_ITEMS_LIST::GetCount(), PICKED_ITEMS_LIST::GetItemWrapper(), PICKED_ITEMS_LIST::GetPickedItem(), PICKED_ITEMS_LIST::GetPickedItemLink(), PICKED_ITEMS_LIST::GetPickedItemStatus(), ZONE::IsSame(), NEWITEM, PICKED_ITEMS_LIST::PushItem(), PICKED_ITEMS_LIST::RemovePicker(), PICKED_ITEMS_LIST::SetPickedItemLink(), and PICKED_ITEMS_LIST::SetPickedItemStatus().

Referenced by PCB_EDIT_FRAME::Edit_Zone_Params().