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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25
26/* These functions are relative to undo redo function, when zones are involved.
27 *
28 * When a zone outline is modified (or created) this zone, or others zones on the same layer
29 * and with the same netcode can change or can be deleted due to the fact overlapping zones are
30 * merged. Also, when a zone outline is modified by adding a cutout area, this zone can be
31 * converted to more than one area, if the outline is break to 2 or more outlines and therefore
32 * new zones are created
33 *
34 * Due to the complexity of potential changes, and the fact there are only few zones in a board,
35 * and a zone has only few segments outlines, the more easy way to undo redo changes is to make
36 * a copy of all zones that can be changed and see after zone editing or creation what zones that
37 * are really modified, and ones they are modified (changes, deletion or addition)
38 */
39
40#include <pcb_edit_frame.h>
41
42#include <board.h>
43#include <zone.h>
44#include <zones.h>
45#include <zones_functions_for_undo_redo.h>
46
54bool ZONE::IsSame( const ZONE& aZoneToCompare )
55{
56 // compare basic parameters:
57 if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
58 return false;
59
60 if( GetNetCode() != aZoneToCompare.GetNetCode() )
61 return false;
62
63 if( GetAssignedPriority() != aZoneToCompare.GetAssignedPriority() )
64 return false;
65
66 // Compare zone specific parameters
67 if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
68 return false;
69
70 if( GetDoNotAllowZoneFills() != aZoneToCompare.GetDoNotAllowZoneFills() )
71 return false;
72
73 if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
74 return false;
75
76 if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
77 return false;
78
79 if( GetDoNotAllowPads() != aZoneToCompare.GetDoNotAllowPads() )
80 return false;
81
82 if( GetDoNotAllowFootprints() != aZoneToCompare.GetDoNotAllowFootprints() )
83 return false;
84
85 if( GetPlacementAreaEnabled() != aZoneToCompare.GetPlacementAreaEnabled() )
86 return false;
87
89 return false;
90
91 if( GetPlacementAreaSource() != aZoneToCompare.GetPlacementAreaSource() )
92 return false;
93
94 if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
95 return false;
96
97 if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
98 return false;
99
100 if( m_fillMode != aZoneToCompare.GetFillMode() )
101 return false;
102
103 if( m_thievingSettings != aZoneToCompare.GetThievingSettings() )
104 return false;
105
106 if( m_PadConnection != aZoneToCompare.m_PadConnection )
107 return false;
108
109 if( m_thermalReliefGap != aZoneToCompare.m_thermalReliefGap )
110 return false;
111
113 return false;
114
115 if( m_zoneName != aZoneToCompare.m_zoneName )
116 return false;
117
118 if( m_islandRemovalMode != aZoneToCompare.m_islandRemovalMode )
119 return false;
120
121 if( m_minIslandArea != aZoneToCompare.m_minIslandArea )
122 return false;
123
124
125 // Compare outlines
126 wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
127 wxASSERT( aZoneToCompare.Outline() );
128
129 if( Outline() != aZoneToCompare.Outline() ) // Compare vector
130 return false;
131
132 return true;
133}
134
135
145void SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb )
146{
147 for( ZONE* zone : aPcb->Zones() )
148 {
149 ZONE* zoneDup = new ZONE( *zone );
150 zoneDup->SetParent( aPcb );
151 zoneDup->SetParentGroup( nullptr );
152
153 ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
154 picker.SetLink( zoneDup );
155 aPickList.PushItem( picker );
156 }
157}
158
159
196 BOARD* aPcb )
197{
198 for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
199 {
200 UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
201
202 ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
203
204 for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
205 {
206 ZONE* zone = aPcb->GetArea( ii );
207
208 if( zone == nullptr )
209 {
210 /* End of list: the stored item is not found:
211 * it must be in aDeletedList:
212 * search it and restore initial values
213 * or
214 * if flagged NEWITEM: remove it definitively
215 */
216 if( status == UNDO_REDO::NEWITEM )
217 {
218 delete ref;
219 ref = nullptr;
220 aPickList.RemovePicker( kk );
221 kk--;
222 }
223 else
224 {
225 ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
227
228 wxASSERT_MSG( zcopy != nullptr,
229 wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
230
231 ref->SwapItemData( zcopy );
232
233 // the copy was deleted; the link does not exists now.
234 aPickList.SetPickedItemLink( nullptr, kk );
235 delete zcopy;
236 }
237
238 // Remove this item from aAuxiliaryList, mainly for tests purpose
239 bool notfound = true;
240
241 for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
242 {
243 if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
244 {
245 aAuxiliaryList.RemovePicker( nn );
246 notfound = false;
247 break;
248 }
249 }
250
251 if( notfound ) // happens when the new zone overlaps an existing zone
252 // and these zones are combined
253 {
254#if defined(DEBUG)
255 printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
256 "combined with another zone\n" );
257 fflush(nullptr);
258#endif
259 }
260
261 break;
262 }
263
264 if( zone == ref ) // picked zone found
265 {
266 if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
267 {
268 ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
269
270 if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
271 {
272 delete zcopy; // Delete copy
273 aPickList.RemovePicker( kk );
274 kk--;
275 }
276 }
277
278 break;
279 }
280 }
281 }
282
283 // Add new zones in main pick list, and remove pickers from Auxiliary List
284 for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
285 {
286 if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
287 {
288 ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
289 aPickList.PushItem( picker );
290 aAuxiliaryList.RemovePicker( ii );
291 }
292 else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::DELETED )
293 {
294 delete aAuxiliaryList.GetPickedItemLink( ii );
295 aAuxiliaryList.RemovePicker( ii );
296 }
297 else
298 {
299 ii++;
300 }
301 }
302
303 // Should not occur:
304 wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
305 wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
306}
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:323
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition board.h:1205
const ZONES & Zones() const
Definition board.h:368
virtual void SetParentGroup(EDA_GROUP *aGroup)
Definition eda_item.h:117
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
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:74
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition zone.h:802
const THIEVING_SETTINGS & GetThievingSettings() const
Definition zone.h:355
bool GetDoNotAllowVias() const
Definition zone.h:813
ZONE_FILL_MODE m_fillMode
Definition zone.h:984
THIEVING_SETTINGS m_thievingSettings
Definition zone.h:997
int m_ZoneMinThickness
Definition zone.h:960
int m_thermalReliefSpokeWidth
Definition zone.h:982
wxString GetPlacementAreaSource() const
Definition zone.h:807
wxString m_zoneName
An optional unique name for this zone, used for identifying it in DRC checking.
Definition zone.h:918
bool GetDoNotAllowPads() const
Definition zone.h:815
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
Definition zone.h:809
bool GetDoNotAllowTracks() const
Definition zone.h:814
SHAPE_POLY_SET * Outline()
Definition zone.h:422
SHAPE_POLY_SET * m_Poly
Outline of the zone.
Definition zone.h:913
int m_ZoneClearance
Definition zone.h:959
int GetMinThickness() const
Definition zone.h:319
bool GetPlacementAreaEnabled() const
Definition zone.h:804
bool GetDoNotAllowFootprints() const
Definition zone.h:816
ZONE_FILL_MODE GetFillMode() const
Definition zone.h:242
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition zone.h:137
ISLAND_REMOVAL_MODE m_islandRemovalMode
Definition zone.h:963
bool GetDoNotAllowZoneFills() const
Definition zone.h:812
int m_thermalReliefGap
Definition zone.h:981
ZONE_CONNECTION m_PadConnection
Definition zone.h:958
unsigned GetAssignedPriority() const
Definition zone.h:126
long long int m_minIslandArea
When island removal mode is set to AREA, islands below this area will be removed.
Definition zone.h:969
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,...