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

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

References BOARD::GetArea(), BOARD_ITEM::GetLayer(), BOARD_CONNECTED_ITEM::GetNetCode(), PICKED_ITEMS_LIST::PushItem(), ITEM_PICKER::SetLink(), EDA_ITEM::SetParent(), and UR_CHANGED.

Referenced by PCB_EDIT_FRAME::duplicateZone(), PCB_EDIT_FRAME::Edit_Zone_Params(), PCB_EDIT_FRAME::End_Zone(), PCB_EDIT_FRAME::Remove_Zone_Corner(), PCB_EDIT_FRAME::Start_Move_Zone_Corner(), PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge(), and PCB_EDIT_FRAME::Start_Move_Zone_Outlines().

138 {
139  int copyCount = 0;
140 
141  for( unsigned ii = 0; ; ii++ )
142  {
143  ZONE_CONTAINER* zone = aPcb->GetArea( ii );
144 
145  if( zone == NULL ) // End of list
146  break;
147 
148  if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
149  continue;
150 
151  if( aLayer >= 0 && aLayer != zone->GetLayer() )
152  continue;
153 
154  ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
155  zoneDup->SetParent( aPcb );
156  ITEM_PICKER picker( zone, UR_CHANGED );
157  picker.SetLink( zoneDup );
158  aPickList.PushItem( picker );
159  copyCount++;
160  }
161 
162  return copyCount;
163 }
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:78
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:227
int GetNetCode() const
Function GetNetCode.
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
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)

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 an other 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 202 of file zones_functions_for_undo_redo.cpp.

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::duplicateZone(), PCB_EDIT_FRAME::Edit_Zone_Params(), PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines(), PCB_EDIT_FRAME::End_Zone(), and PCB_EDIT_FRAME::Remove_Zone_Corner().

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