2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file zones_functions_for_undo_redo.cpp
|
|
|
|
*/
|
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
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
|
2011-09-30 18:15:37 +00:00
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
* 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
|
|
|
|
* This is 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 edition or creation what zones that are really modified,
|
|
|
|
* and ones they are modified (changes, deletion or addition)
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <wxPcbStruct.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_zone.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#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"
|
|
|
|
*/
|
|
|
|
bool ZONE_CONTAINER::IsSame( const ZONE_CONTAINER& aZoneToCompare )
|
|
|
|
{
|
|
|
|
// compare basic parameters:
|
|
|
|
if( GetLayer() != aZoneToCompare.GetLayer() )
|
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( m_Netname != aZoneToCompare.m_Netname )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Compare zone specfic parameters
|
|
|
|
if( m_ZoneClearance != aZoneToCompare.m_ZoneClearance )
|
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( m_ZoneMinThickness != aZoneToCompare.m_ZoneMinThickness )
|
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( m_FillMode != aZoneToCompare.m_FillMode )
|
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( m_ArcToSegmentsCount != aZoneToCompare.m_ArcToSegmentsCount )
|
|
|
|
return false;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-02-24 23:23:46 +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
|
|
|
|
2011-11-30 21:15:56 +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
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
if( m_ThermalReliefCopperBridge != aZoneToCompare.m_ThermalReliefCopperBridge )
|
2009-08-23 15:22:44 +00:00
|
|
|
return false;
|
|
|
|
|
2012-01-29 19:29:19 +00:00
|
|
|
if( GetPriority() != aZoneToCompare.GetPriority() )
|
|
|
|
return false;
|
|
|
|
|
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
|
2009-08-23 15:22:44 +00:00
|
|
|
wxASSERT( aZoneToCompare.m_Poly );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
if( m_Poly->corner != aZoneToCompare.m_Poly->corner ) // 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
|
|
|
|
* the UndoRedo status is set to UR_CHANGED for all items in list
|
|
|
|
* Later, UpdateCopyOfZonesList will change and update these pickers after a zone edition
|
|
|
|
* @param aPickList = the pick list
|
|
|
|
* @param aPcb = the Board
|
|
|
|
* @param aNetCode = the reference netcode. if aNetCode < 0 all netcodes are used
|
|
|
|
* @param aLayer = the layer of zones. if aLayer < 0, all layers are used
|
|
|
|
* @return the count of saved copies
|
|
|
|
*/
|
|
|
|
int SaveCopyOfZones( PICKED_ITEMS_LIST& aPickList, BOARD* aPcb, int aNetCode, int aLayer )
|
|
|
|
{
|
|
|
|
int copyCount = 0;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ; ii++ )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( zone == NULL ) // End of list
|
|
|
|
break;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( aNetCode >= 0 && aNetCode != zone->GetNet() )
|
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( aLayer >= 0 && aLayer != zone->GetLayer() )
|
|
|
|
continue;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-14 19:50:32 +00:00
|
|
|
ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
|
|
|
|
zoneDup->SetParent( aPcb );
|
2012-02-05 13:02:46 +00:00
|
|
|
ITEM_PICKER picker( zone, UR_CHANGED );
|
|
|
|
picker.SetLink( zoneDup );
|
2009-08-23 15:22:44 +00:00
|
|
|
aPickList.PushItem( picker );
|
|
|
|
copyCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return copyCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function UpdateCopyOfZonesList
|
2009-08-23 15:22:44 +00:00
|
|
|
* 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 in edition
|
|
|
|
* @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:
|
|
|
|
* In this list are put zone taht were added or deleted during the zone combine process
|
|
|
|
* aPickList :is a list of zone that can be modified (changed or deleted, or not modified)
|
|
|
|
* >> if the picked zone is not changed, it is removed from list
|
|
|
|
* >> if the picked zone was deleted (i.e. not found in boad 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 deleted (i.e. not found in boad 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 combine process, mainly when adding cutaout areas)
|
|
|
|
* 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++ )
|
|
|
|
{
|
2011-04-05 14:46:51 +00:00
|
|
|
UNDO_REDO_T status = aPickList.GetPickedItemStatus( kk );
|
2009-08-23 15:22:44 +00:00
|
|
|
|
|
|
|
ZONE_CONTAINER* ref = (ZONE_CONTAINER*) 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
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( zone == NULL )
|
|
|
|
{
|
|
|
|
/* End of list: the stored item is not found:
|
|
|
|
* it must be in aDeletedList:
|
|
|
|
* search it and restore initial values
|
|
|
|
* or
|
|
|
|
* if flagged UR_NEW: remove it definitively
|
|
|
|
*/
|
|
|
|
if( status == UR_NEW )
|
|
|
|
{
|
|
|
|
delete ref;
|
|
|
|
aPickList.RemovePicker( kk );
|
|
|
|
kk--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
|
|
|
|
aPickList.SetPickedItemStatus( UR_DELETED, kk );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
if( zcopy )
|
|
|
|
ref->Copy( zcopy );
|
|
|
|
else
|
|
|
|
wxMessageBox( wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
|
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.
|
|
|
|
aPickList.SetPickedItemLink( NULL, 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++ )
|
|
|
|
{
|
|
|
|
if( aAuxiliaryList.GetPickedItem( nn ) == ref )
|
|
|
|
{
|
|
|
|
aAuxiliaryList.RemovePicker( nn );
|
|
|
|
notfound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( notfound )
|
2011-09-23 13:57:12 +00:00
|
|
|
wxMessageBox( wxT( "UpdateCopyOfZonesList() error: item not found in aAuxiliaryList" ) );
|
|
|
|
|
2009-08-23 15:22:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( zone == ref ) // picked zone found
|
|
|
|
{
|
|
|
|
if( aPickList.GetPickedItemStatus( kk ) != UR_NEW )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) 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
|
|
|
|
for( unsigned ii = 0; ii < aAuxiliaryList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
if( aAuxiliaryList.GetPickedItemStatus( ii ) == UR_NEW )
|
|
|
|
{
|
|
|
|
ITEM_PICKER picker = aAuxiliaryList.GetItemWrapper( ii );
|
|
|
|
aPickList.PushItem( picker );
|
|
|
|
aAuxiliaryList.RemovePicker( ii );
|
|
|
|
ii--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should not occur:
|
|
|
|
if( aAuxiliaryList.GetCount()> 0 )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2011-09-23 13:57:12 +00:00
|
|
|
msg.Printf( wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not void: %d item left (status %d)" ),
|
|
|
|
aAuxiliaryList.GetCount(), aAuxiliaryList.GetPickedItemStatus( 0 ) );
|
2009-08-23 15:22:44 +00:00
|
|
|
wxMessageBox( msg );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
while( aAuxiliaryList.GetCount() > 0 )
|
2009-08-23 15:22:44 +00:00
|
|
|
{
|
|
|
|
delete aAuxiliaryList.GetPickedItemLink( 0 );
|
|
|
|
aAuxiliaryList.RemovePicker( 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|