1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras <jp.charras@wanadoo.fr>
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* These functions are relative to undo redo function, when zones are involved.
*
* When a zone outline is modified (or created) this zone, or others zones on the same layer
* and with the same netcode can change or can be deleted due to the fact overlapping zones are
* merged. Also, when a zone outline is modified by adding a cutout area, this zone can be
* converted to more than one area, if the outline is break to 2 or more outlines and therefore
* new zones are created
*
* Due to the complexity of potential changes, and the fact there are only few zones in a board,
* and a zone has only few segments outlines, the more easy way to undo redo changes is to make
* a copy of all zones that can be changed and see after zone editing or creation what zones that
* are really modified, and ones they are modified (changes, deletion or addition)
*/
#include <pcb_edit_frame.h>
#include <board.h>
#include <zone.h>
#include <zones.h>
#include <zones_functions_for_undo_redo.h>
/**
* Function IsSame
* test is 2 zones are equivalent:
* 2 zones are equivalent if they have same parameters and same outlines
* info relative to filling is not take in account
* @param aZoneToCompare = zone to compare with "this"
*/
bool ZONE::IsSame( const ZONE& aZoneToCompare )
{
// compare basic parameters:
if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
return false;
if( GetNetCode() != aZoneToCompare.GetNetCode() )
return false;
if( GetAssignedPriority() != aZoneToCompare.GetAssignedPriority() )
return false;
// Compare zone specific parameters
if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
return false;
if( GetDoNotAllowCopperPour() != aZoneToCompare.GetDoNotAllowCopperPour() )
return false;
if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
return false;
if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
return false;
if( GetDoNotAllowPads() != aZoneToCompare.GetDoNotAllowPads() )
return false;
if( GetDoNotAllowFootprints() != aZoneToCompare.GetDoNotAllowFootprints() )
return false;
if( GetRuleAreaPlacementEnabled() != aZoneToCompare.GetRuleAreaPlacementEnabled() )
return false;
if( GetRuleAreaPlacementSourceType() != aZoneToCompare.GetRuleAreaPlacementSourceType() )
return false;
if( GetRuleAreaPlacementSource() != aZoneToCompare.GetRuleAreaPlacementSource() )
return false;
if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
return false;
if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
return false;
if( m_fillMode != aZoneToCompare.GetFillMode() )
return false;
if( m_PadConnection != aZoneToCompare.m_PadConnection )
return false;
if( m_thermalReliefGap != aZoneToCompare.m_thermalReliefGap )
return false;
if( m_thermalReliefSpokeWidth != aZoneToCompare.m_thermalReliefSpokeWidth )
return false;
if( m_zoneName != aZoneToCompare.m_zoneName )
return false;
if( m_islandRemovalMode != aZoneToCompare.m_islandRemovalMode )
return false;
if( m_minIslandArea != aZoneToCompare.m_minIslandArea )
return false;
// Compare outlines
wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
wxASSERT( aZoneToCompare.Outline() );
if( Outline() != aZoneToCompare.Outline() ) // Compare vector
return false;
return true;
}
/**
* 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
* the UndoRedo status is set to CHANGED for all items in list
* Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing
* @param aPickList = the pick list
* @param aPcb = the Board
*/
void SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb )
{
for( ZONE* zone : aPcb->Zones() )
{
ZONE* zoneDup = new ZONE( *zone );
zoneDup->SetParent( aPcb );
zoneDup->SetParentGroup( nullptr );
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
picker.SetLink( zoneDup );
aPickList.PushItem( picker );
}
}
/**
* Function UpdateCopyOfZonesList
* Check a pick list to remove zones identical to their copies and set the type of operation in
* picker (DELETED, CHANGED). If an item is deleted, the initial values are retrievered,
* because they can have changed during editing.
* @param aPickList = the main pick list
* @param aAuxiliaryList = the list of deleted or added (new created) items after calculations
* @param 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 DELETED
* the aAuxiliaryList corresponding picker is removed (if not found : set an error)
* >> if the picked zone was flagged as NEWITEM, 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 NEWITEM 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 DELETED are removed, and the corresponding 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.
*/
void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList, PICKED_ITEMS_LIST& aAuxiliaryList,
BOARD* aPcb )
{
for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
{
UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
{
ZONE* zone = aPcb->GetArea( ii );
if( zone == nullptr )
{
/* End of list: the stored item is not found:
* it must be in aDeletedList:
* search it and restore initial values
* or
* if flagged NEWITEM: remove it definitively
*/
if( status == UNDO_REDO::NEWITEM )
{
delete ref;
ref = nullptr;
aPickList.RemovePicker( kk );
kk--;
}
else
{
ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
aPickList.SetPickedItemStatus( UNDO_REDO::DELETED, kk );
wxASSERT_MSG( zcopy != nullptr,
wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
ref->SwapItemData( zcopy );
// the copy was deleted; the link does not exists now.
aPickList.SetPickedItemLink( nullptr, kk );
delete zcopy;
}
// Remove this item from aAuxiliaryList, mainly for tests purpose
bool notfound = true;
for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
{
if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
{
aAuxiliaryList.RemovePicker( nn );
notfound = false;
break;
}
}
if( notfound ) // happens when the new zone overlaps an existing zone
// and these zones are combined
{
#if defined(DEBUG)
printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
"combined with another zone\n" );
fflush(nullptr);
#endif
}
break;
}
if( zone == ref ) // picked zone found
{
if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
{
ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
{
delete zcopy; // Delete copy
aPickList.RemovePicker( kk );
kk--;
}
}
break;
}
}
}
// Add new zones in main pick list, and remove pickers from Auxiliary List
for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
{
if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
{
ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
aPickList.PushItem( picker );
aAuxiliaryList.RemovePicker( ii );
}
else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::DELETED )
{
delete aAuxiliaryList.GetPickedItemLink( ii );
aAuxiliaryList.RemovePicker( ii );
}
else
{
ii++;
}
}
// Should not occur:
wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
}
|