KiCad PCB EDA Suite
Loading...
Searching...
No Matches
zones_functions_for_undo_redo.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2009 Jean-Pierre Charras <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22/* These functions are relative to undo redo function, when zones are involved.
23 *
24 * When a zone outline is modified (or created) this zone, or others zones on the same layer
25 * and with the same netcode can change or can be deleted due to the fact overlapping zones are
26 * merged. Also, when a zone outline is modified by adding a cutout area, this zone can be
27 * converted to more than one area, if the outline is break to 2 or more outlines and therefore
28 * new zones are created
29 *
30 * Due to the complexity of potential changes, and the fact there are only few zones in a board,
31 * and a zone has only few segments outlines, the more easy way to undo redo changes is to make
32 * a copy of all zones that can be changed and see after zone editing or creation what zones that
33 * are really modified, and ones they are modified (changes, deletion or addition)
34 */
35
36#include <pcb_edit_frame.h>
37
38#include <board.h>
39#include <zone.h>
40#include <zones.h>
41#include <zones_functions_for_undo_redo.h>
42
50bool ZONE::IsSame( const ZONE& aZoneToCompare )
51{
52 // compare basic parameters:
53 if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
54 return false;
55
56 if( GetNetCode() != aZoneToCompare.GetNetCode() )
57 return false;
58
59 if( GetAssignedPriority() != aZoneToCompare.GetAssignedPriority() )
60 return false;
61
62 // Compare zone specific parameters
63 if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
64 return false;
65
66 if( GetDoNotAllowZoneFills() != aZoneToCompare.GetDoNotAllowZoneFills() )
67 return false;
68
69 if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
70 return false;
71
72 if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
73 return false;
74
75 if( GetDoNotAllowPads() != aZoneToCompare.GetDoNotAllowPads() )
76 return false;
77
78 if( GetDoNotAllowFootprints() != aZoneToCompare.GetDoNotAllowFootprints() )
79 return false;
80
81 if( GetPlacementAreaEnabled() != aZoneToCompare.GetPlacementAreaEnabled() )
82 return false;
83
85 return false;
86
87 if( GetPlacementAreaSource() != aZoneToCompare.GetPlacementAreaSource() )
88 return false;
89
90 if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
91 return false;
92
93 if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
94 return false;
95
96 if( m_fillMode != aZoneToCompare.GetFillMode() )
97 return false;
98
99 if( m_thievingSettings != aZoneToCompare.GetThievingSettings() )
100 return false;
101
102 if( m_PadConnection != aZoneToCompare.m_PadConnection )
103 return false;
104
105 if( m_thermalReliefGap != aZoneToCompare.m_thermalReliefGap )
106 return false;
107
109 return false;
110
111 if( m_zoneName != aZoneToCompare.m_zoneName )
112 return false;
113
114 if( m_islandRemovalMode != aZoneToCompare.m_islandRemovalMode )
115 return false;
116
117 if( m_minIslandArea != aZoneToCompare.m_minIslandArea )
118 return false;
119
120
121 // Compare outlines
122 wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
123 wxASSERT( aZoneToCompare.Outline() );
124
125 if( Outline() != aZoneToCompare.Outline() ) // Compare vector
126 return false;
127
128 return true;
129}
130
131
141void SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb )
142{
143 for( ZONE* zone : aPcb->Zones() )
144 {
145 ZONE* zoneDup = new ZONE( *zone );
146 zoneDup->SetParent( aPcb );
147 zoneDup->SetParentGroup( nullptr );
148
149 ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
150 picker.SetLink( zoneDup );
151 aPickList.PushItem( picker );
152 }
153}
154
155
192 BOARD* aPcb )
193{
194 for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
195 {
196 UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
197
198 ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
199
200 for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
201 {
202 ZONE* zone = aPcb->GetArea( ii );
203
204 if( zone == nullptr )
205 {
206 /* End of list: the stored item is not found:
207 * it must be in aDeletedList:
208 * search it and restore initial values
209 * or
210 * if flagged NEWITEM: remove it definitively
211 */
212 if( status == UNDO_REDO::NEWITEM )
213 {
214 delete ref;
215 ref = nullptr;
216 aPickList.RemovePicker( kk );
217 kk--;
218 }
219 else
220 {
221 ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
223
224 wxASSERT_MSG( zcopy != nullptr,
225 wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
226
227 ref->SwapItemData( zcopy );
228
229 // the copy was deleted; the link does not exists now.
230 aPickList.SetPickedItemLink( nullptr, kk );
231 delete zcopy;
232 }
233
234 // Remove this item from aAuxiliaryList, mainly for tests purpose
235 bool notfound = true;
236
237 for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
238 {
239 if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
240 {
241 aAuxiliaryList.RemovePicker( nn );
242 notfound = false;
243 break;
244 }
245 }
246
247 if( notfound ) // happens when the new zone overlaps an existing zone
248 // and these zones are combined
249 {
250#if defined(DEBUG)
251 printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
252 "combined with another zone\n" );
253 fflush(nullptr);
254#endif
255 }
256
257 break;
258 }
259
260 if( zone == ref ) // picked zone found
261 {
262 if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
263 {
264 ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
265
266 if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
267 {
268 delete zcopy; // Delete copy
269 aPickList.RemovePicker( kk );
270 kk--;
271 }
272 }
273
274 break;
275 }
276 }
277 }
278
279 // Add new zones in main pick list, and remove pickers from Auxiliary List
280 for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
281 {
282 if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
283 {
284 ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
285 aPickList.PushItem( picker );
286 aAuxiliaryList.RemovePicker( ii );
287 }
288 else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::DELETED )
289 {
290 delete aAuxiliaryList.GetPickedItemLink( ii );
291 aAuxiliaryList.RemovePicker( ii );
292 }
293 else
294 {
295 ii++;
296 }
297 }
298
299 // Should not occur:
300 wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
301 wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
302}
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition board.h:1287
const ZONES & Zones() const
Definition board.h:424
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition eda_item.h:113
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
void SetLink(EDA_ITEM *aItem)
A holder to handle information on schematic or board items.
bool SetPickedItemStatus(UNDO_REDO aStatus, unsigned aIdx)
Set the type of undo/redo operation for a given picked item.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
UNDO_REDO GetPickedItemStatus(unsigned int aIdx) const
EDA_ITEM * GetPickedItemLink(unsigned int aIdx) const
bool RemovePicker(unsigned aIdx)
Remove one entry (one picker) from the list of picked items.
const ITEM_PICKER & GetItemWrapper(unsigned int aIdx) const
unsigned GetCount() const
bool SetPickedItemLink(EDA_ITEM *aLink, unsigned aIdx)
Set the link associated to a given picked item.
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:811
const THIEVING_SETTINGS & GetThievingSettings() const
Definition zone.h:351
bool GetDoNotAllowVias() const
Definition zone.h:822
ZONE_FILL_MODE m_fillMode
Definition zone.h:993
THIEVING_SETTINGS m_thievingSettings
Definition zone.h:1006
int m_ZoneMinThickness
Definition zone.h:969
int m_thermalReliefSpokeWidth
Definition zone.h:991
wxString GetPlacementAreaSource() const
Definition zone.h:816
wxString m_zoneName
An optional unique name for this zone, used for identifying it in DRC checking.
Definition zone.h:927
bool GetDoNotAllowPads() const
Definition zone.h:824
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
Definition zone.h:818
bool GetDoNotAllowTracks() const
Definition zone.h:823
SHAPE_POLY_SET * Outline()
Definition zone.h:418
SHAPE_POLY_SET * m_Poly
Outline of the zone.
Definition zone.h:922
int m_ZoneClearance
Definition zone.h:968
int GetMinThickness() const
Definition zone.h:315
bool GetPlacementAreaEnabled() const
Definition zone.h:813
bool GetDoNotAllowFootprints() const
Definition zone.h:825
ZONE_FILL_MODE GetFillMode() const
Definition zone.h:238
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:133
ISLAND_REMOVAL_MODE m_islandRemovalMode
Definition zone.h:972
bool GetDoNotAllowZoneFills() const
Definition zone.h:821
int m_thermalReliefGap
Definition zone.h:990
ZONE_CONNECTION m_PadConnection
Definition zone.h:967
unsigned GetAssignedPriority() const
Definition zone.h:122
long long int m_minIslandArea
When island removal mode is set to AREA, islands below this area will be removed.
Definition zone.h:978
UNDO_REDO
Undo Redo considerations: Basically we have 3 cases New item Deleted item Modified item there is also...
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 th...
void SaveCopyOfZones(PICKED_ITEMS_LIST &aPickList, BOARD *aPcb)
Function SaveCopyOfZones creates a copy of zones having a given netcode on a given layer,...