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

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

133 {
134  int copyCount = 0;
135 
136  for( unsigned ii = 0; ; ii++ )
137  {
138  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
139 
140  if( zone == NULL ) // End of list
141  break;
142 
143  if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
144  continue;
145 
146  if( aLayer >= 0 && aLayer != zone->GetLayer() )
147  continue;
148 
149  ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
150  zoneDup->SetParent( aPcb );
151  ITEM_PICKER picker( zone, UR_CHANGED );
152  picker.SetLink( zoneDup );
153  aPickList.PushItem( picker );
154  copyCount++;
155  }
156 
157  return copyCount;
158 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
int GetNetCode() const
Function GetNetCode.
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:190
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:225
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:926

References BOARD::GetArea(), ZONE_CONTAINER::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), 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)

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

199 {
200  for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
201  {
202  UNDO_REDO_T status = aPickList.GetPickedItemStatus( kk );
203 
204  ZONE_CONTAINER* ref = (ZONE_CONTAINER*) aPickList.GetPickedItem( kk );
205 
206  for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
207  {
208  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
209 
210  if( zone == NULL )
211  {
212  /* End of list: the stored item is not found:
213  * it must be in aDeletedList:
214  * search it and restore initial values
215  * or
216  * if flagged UR_NEW: remove it definitively
217  */
218  if( status == UR_NEW )
219  {
220  delete ref;
221  ref = NULL;
222  aPickList.RemovePicker( kk );
223  kk--;
224  }
225  else
226  {
227  ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
228  aPickList.SetPickedItemStatus( UR_DELETED, kk );
229 
230  wxASSERT_MSG( zcopy != NULL,
231  wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
232 
233  *ref = *zcopy;
234 
235  // the copy was deleted; the link does not exists now.
236  aPickList.SetPickedItemLink( NULL, kk );
237  delete zcopy;
238  }
239 
240  // Remove this item from aAuxiliaryList, mainly for tests purpose
241  bool notfound = true;
242 
243  for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
244  {
245  if( ref != NULL && aAuxiliaryList.GetPickedItem( nn ) == ref )
246  {
247  aAuxiliaryList.RemovePicker( nn );
248  notfound = false;
249  break;
250  }
251  }
252 
253  if( notfound ) // happens when the new zone overlaps an existing zone
254  // and these zones are combined
255  {
256  DBG( printf(
257  "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
258  "combined with another zone\n" ) );
259  }
260  break;
261  }
262 
263  if( zone == ref ) // picked zone found
264  {
265  if( aPickList.GetPickedItemStatus( kk ) != UR_NEW )
266  {
267  ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
268 
269  if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
270  {
271  delete zcopy; // Delete copy
272  aPickList.RemovePicker( kk );
273  kk--;
274  }
275  }
276 
277  break;
278  }
279  }
280  }
281 
282  // Add new zones in main pick list, and remove pickers from Auxiliary List
283  for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
284  {
285  if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_NEW )
286  {
287  ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
288  aPickList.PushItem( picker );
289  aAuxiliaryList.RemovePicker( ii );
290  }
291  else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_DELETED )
292  {
293  delete aAuxiliaryList.GetPickedItemLink( ii );
294  aAuxiliaryList.RemovePicker( ii );
295  }
296  else
297  ii++;
298  }
299 
300  // Should not occur:
301  wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
302  wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
303 }
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
Function GetPickedItemLink.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:57
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.
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:926

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