2009-08-23 15:22:44 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2009-08-23 15:22:44 +00:00
|
|
|
*
|
2012-07-14 16:27:25 +00:00
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras <jp.charras@wanadoo.fr>
|
2022-10-21 17:41:21 +00:00
|
|
|
* Copyright (C) 2007-2022 KiCad Developers, see change_log.txt for contributors.
|
2009-08-23 15:22:44 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2018-06-22 13:05:11 +00:00
|
|
|
*
|
2009-08-23 15:22:44 +00:00
|
|
|
* When a zone outline is modified (or created) this zone, or others zones on the same layer
|
2018-06-22 13:05:11 +00:00
|
|
|
* 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
|
2009-08-23 15:22:44 +00:00
|
|
|
*
|
2018-06-22 13:05:11 +00:00
|
|
|
* 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)
|
2009-08-23 15:22:44 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <zones.h>
|
|
|
|
#include <zones_functions_for_undo_redo.h>
|
2009-08-23 15:22:44 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function IsSame
|
2009-08-23 15:22:44 +00:00
|
|
|
* 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"
|
|
|
|
*/
|
2020-11-11 23:05:59 +00:00
|
|
|
bool ZONE::IsSame( const ZONE& aZoneToCompare )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
// compare basic parameters:
|
2020-07-01 02:21:59 +00:00
|
|
|
if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( GetNetCode() != aZoneToCompare.GetNetCode() )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
|
|
|
|
2022-03-01 14:53:35 +00:00
|
|
|
if( GetAssignedPriority() != aZoneToCompare.GetAssignedPriority() )
|
2012-07-13 18:55:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compare zone specific parameters
|
2020-09-21 23:32:07 +00:00
|
|
|
if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
|
2012-07-13 18:55:29 +00:00
|
|
|
return false;
|
|
|
|
|
2020-09-21 23:32:07 +00:00
|
|
|
if( GetIsRuleArea() )
|
2012-07-13 18:55:29 +00:00
|
|
|
{
|
2012-07-14 16:27:25 +00:00
|
|
|
if( GetDoNotAllowCopperPour() != aZoneToCompare.GetDoNotAllowCopperPour() )
|
2012-07-13 18:55:29 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetDoNotAllowVias() != aZoneToCompare.GetDoNotAllowVias() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetDoNotAllowTracks() != aZoneToCompare.GetDoNotAllowTracks() )
|
|
|
|
return false;
|
2020-05-07 00:30:46 +00:00
|
|
|
|
|
|
|
if( GetDoNotAllowPads() != aZoneToCompare.GetDoNotAllowPads() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( GetDoNotAllowFootprints() != aZoneToCompare.GetDoNotAllowFootprints() )
|
|
|
|
return false;
|
2012-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 16:27:25 +00:00
|
|
|
if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2013-03-18 19:36:07 +00:00
|
|
|
if( m_ZoneMinThickness != aZoneToCompare.GetMinThickness() )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
if( m_fillMode != aZoneToCompare.GetFillMode() )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-07-14 16:27:25 +00:00
|
|
|
if( m_PadConnection != aZoneToCompare.m_PadConnection )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
if( m_thermalReliefGap != aZoneToCompare.m_thermalReliefGap )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-09-17 13:14:45 +00:00
|
|
|
if( m_thermalReliefSpokeWidth != aZoneToCompare.m_thermalReliefSpokeWidth )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
|
|
|
|
2020-07-01 02:21:59 +00:00
|
|
|
if( m_zoneName != aZoneToCompare.m_zoneName )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_islandRemovalMode != aZoneToCompare.m_islandRemovalMode )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( m_minIslandArea != aZoneToCompare.m_minIslandArea )
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 19:29:19 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
// Compare outlines
|
2011-09-23 13:57:12 +00:00
|
|
|
wxASSERT( m_Poly ); // m_Poly == NULL Should never happen
|
2013-03-20 14:50:12 +00:00
|
|
|
wxASSERT( aZoneToCompare.Outline() );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
if( Outline() != aZoneToCompare.Outline() ) // Compare vector
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function SaveCopyOfZones
|
2009-08-23 15:22:44 +00:00
|
|
|
* creates a copy of zones having a given netcode on a given layer,
|
|
|
|
* and fill a pick list with pickers to handle these copies
|
2020-08-26 18:04:32 +00:00
|
|
|
* the UndoRedo status is set to CHANGED for all items in list
|
2018-06-22 13:05:11 +00:00
|
|
|
* Later, UpdateCopyOfZonesList will change and update these pickers after a zone editing
|
2009-08-23 15:22:44 +00:00
|
|
|
* @param aPickList = the pick list
|
|
|
|
* @param aPcb = the Board
|
|
|
|
*/
|
2022-10-21 17:41:21 +00:00
|
|
|
void SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
2022-10-21 17:41:21 +00:00
|
|
|
for( ZONE* zone : aPcb->Zones() )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zoneDup = new ZONE( *zone );
|
2012-01-14 19:50:32 +00:00
|
|
|
zoneDup->SetParent( aPcb );
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
|
2012-02-05 13:02:46 +00:00
|
|
|
picker.SetLink( zoneDup );
|
2009-08-23 15:22:44 +00:00
|
|
|
aPickList.PushItem( picker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function UpdateCopyOfZonesList
|
2018-06-22 13:05:11 +00:00
|
|
|
* Check a pick list to remove zones identical to their copies and set the type of operation in
|
2020-08-26 18:04:32 +00:00
|
|
|
* picker (DELETED, CHANGED). If an item is deleted, the initial values are retrievered,
|
2018-06-22 13:05:11 +00:00
|
|
|
* because they can have changed during editing.
|
2009-08-23 15:22:44 +00:00
|
|
|
* @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:
|
2012-08-04 09:43:27 +00:00
|
|
|
* This list contains zones which were added or deleted during the zones combine process
|
2012-08-03 15:43:15 +00:00
|
|
|
* aPickList :is a list of zones that can be modified (changed or deleted, or not modified)
|
2012-08-04 09:43:27 +00:00
|
|
|
* Typically, this is the list of existing zones on the layer of the edited zone,
|
|
|
|
* before any change.
|
2009-08-23 15:22:44 +00:00
|
|
|
* >> if the picked zone is not changed, it is removed from list
|
2012-08-04 09:43:27 +00:00
|
|
|
* >> if the picked zone was deleted (i.e. not found in board list), the picker is modified:
|
2020-08-26 18:04:32 +00:00
|
|
|
* its status becomes DELETED
|
2012-08-04 09:43:27 +00:00
|
|
|
* the aAuxiliaryList corresponding picker is removed (if not found : set an error)
|
2020-08-26 18:04:32 +00:00
|
|
|
* >> if the picked zone was flagged as NEWITEM, and was after deleted ,
|
2018-04-08 10:28:59 +00:00
|
|
|
* perhaps combined with another zone (i.e. not found in board list):
|
2012-08-04 09:43:27 +00:00
|
|
|
* the picker is removed
|
|
|
|
* the zone itself if really deleted
|
|
|
|
* the aAuxiliaryList corresponding picker is removed (if not found : set an error)
|
2009-08-23 15:22:44 +00:00
|
|
|
* After aPickList is cleaned, the aAuxiliaryList is read
|
2020-08-26 18:04:32 +00:00
|
|
|
* All pickers flagged NEWITEM are moved to aPickList
|
2012-08-04 09:43:27 +00:00
|
|
|
* (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)
|
2021-06-09 19:32:58 +00:00
|
|
|
* All pickers flagged DELETED are removed, and the corresponding zones actually deleted
|
2012-08-04 09:43:27 +00:00
|
|
|
* (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.
|
2012-08-03 15:43:15 +00:00
|
|
|
* 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.)
|
2009-08-23 15:22:44 +00:00
|
|
|
* If not an error is set.
|
|
|
|
*/
|
2022-10-21 17:41:21 +00:00
|
|
|
void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList, PICKED_ITEMS_LIST& aAuxiliaryList,
|
|
|
|
BOARD* aPcb )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
for( unsigned kk = 0; kk < aPickList.GetCount(); kk++ )
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
|
2009-08-23 15:22:44 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* ref = (ZONE*) aPickList.GetPickedItem( kk );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = aPcb->GetArea( ii );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
if( zone == nullptr )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
/* End of list: the stored item is not found:
|
|
|
|
* it must be in aDeletedList:
|
|
|
|
* search it and restore initial values
|
|
|
|
* or
|
2020-08-26 18:04:32 +00:00
|
|
|
* if flagged NEWITEM: remove it definitively
|
2009-08-23 15:22:44 +00:00
|
|
|
*/
|
2020-08-26 18:04:32 +00:00
|
|
|
if( status == UNDO_REDO::NEWITEM )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
delete ref;
|
2021-04-22 21:20:34 +00:00
|
|
|
ref = nullptr;
|
2009-08-23 15:22:44 +00:00
|
|
|
aPickList.RemovePicker( kk );
|
|
|
|
kk--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
|
2020-08-26 18:04:32 +00:00
|
|
|
aPickList.SetPickedItemStatus( UNDO_REDO::DELETED, kk );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2021-04-22 21:20:34 +00:00
|
|
|
wxASSERT_MSG( zcopy != nullptr,
|
2015-02-22 21:25:29 +00:00
|
|
|
wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
|
|
|
|
|
2016-05-31 08:27:52 +00:00
|
|
|
*ref = *zcopy;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
// the copy was deleted; the link does not exists now.
|
2021-04-22 21:20:34 +00:00
|
|
|
aPickList.SetPickedItemLink( nullptr, kk );
|
2009-08-23 15:22:44 +00:00
|
|
|
delete zcopy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove this item from aAuxiliaryList, mainly for tests purpose
|
|
|
|
bool notfound = true;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
|
|
|
|
{
|
2021-04-22 21:20:34 +00:00
|
|
|
if( ref != nullptr && aAuxiliaryList.GetPickedItem( nn ) == ref )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
aAuxiliaryList.RemovePicker( nn );
|
|
|
|
notfound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-10 19:10:10 +00:00
|
|
|
if( notfound ) // happens when the new zone overlaps an existing zone
|
|
|
|
// and these zones are combined
|
|
|
|
{
|
2022-10-21 17:41:21 +00:00
|
|
|
#if defined(DEBUG)
|
2020-10-01 08:52:03 +00:00
|
|
|
printf( "UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
|
|
|
|
"combined with another zone\n" );
|
2021-04-22 21:20:34 +00:00
|
|
|
fflush(nullptr);
|
2022-10-21 17:41:21 +00:00
|
|
|
#endif
|
2015-05-10 19:10:10 +00:00
|
|
|
}
|
2022-10-21 17:41:21 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-22 21:25:29 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( zone == ref ) // picked zone found
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zcopy = (ZONE*) aPickList.GetPickedItemLink( kk );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( zone->IsSame( *zcopy ) ) // Remove picked, because no changes
|
|
|
|
{
|
|
|
|
delete zcopy; // Delete copy
|
|
|
|
aPickList.RemovePicker( kk );
|
|
|
|
kk--;
|
|
|
|
}
|
|
|
|
}
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add new zones in main pick list, and remove pickers from Auxiliary List
|
2012-08-04 09:43:27 +00:00
|
|
|
for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
|
|
|
|
aPickList.PushItem( picker );
|
|
|
|
aAuxiliaryList.RemovePicker( ii );
|
|
|
|
}
|
2020-08-26 18:04:32 +00:00
|
|
|
else if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::DELETED )
|
2012-08-04 09:43:27 +00:00
|
|
|
{
|
|
|
|
delete aAuxiliaryList.GetPickedItemLink( ii );
|
|
|
|
aAuxiliaryList.RemovePicker( ii );
|
|
|
|
}
|
|
|
|
else
|
2022-10-21 17:41:21 +00:00
|
|
|
{
|
2012-08-04 09:43:27 +00:00
|
|
|
ii++;
|
2022-10-21 17:41:21 +00:00
|
|
|
}
|
2009-08-23 15:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should not occur:
|
2015-02-22 21:25:29 +00:00
|
|
|
wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
|
|
|
|
wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
|
2009-08-23 15:22:44 +00:00
|
|
|
}
|