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

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

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

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

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