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

147 {
148  int copyCount = 0;
149 
150  for( unsigned ii = 0; ; ii++ )
151  {
152  ZONE* zone = aPcb->GetArea( ii );
153 
154  if( zone == NULL ) // End of list
155  break;
156 
157  if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
158  continue;
159 
160  if( aLayer >= 0 && !zone->GetLayerSet().test( aLayer ) )
161  continue;
162 
163  ZONE* zoneDup = new ZONE( *zone );
164  zoneDup->SetParent( aPcb );
165  ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
166  picker.SetLink( zoneDup );
167  aPickList.PushItem( picker );
168  copyCount++;
169  }
170 
171  return copyCount;
172 }
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.cpp:288
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:911
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:165
#define NULL
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57

References CHANGED, BOARD::GetArea(), ZONE::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNetCode(), NULL, 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 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 210 of file zones_functions_for_undo_redo.cpp.

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