kicad/pcbnew/zones_functions_for_undo_re...

319 lines
12 KiB
C++
Raw Normal View History

/**
* @file zones_functions_for_undo_redo.cpp
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras <jp.charras@wanadoo.fr>
2015-02-22 21:25:29 +00:00
* Copyright (C) 2007-2015 KiCad Developers, see change_log.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 <fctsys.h>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
2018-01-29 20:58:58 +00:00
#include <pcb_edit_frame.h>
#include <class_board.h>
#include <class_zone.h>
#include <pcbnew.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_CONTAINER::IsSame( const ZONE_CONTAINER& aZoneToCompare )
{
// compare basic parameters:
if( GetLayerSet() != aZoneToCompare.GetLayerSet() )
return false;
if( GetNetCode() != aZoneToCompare.GetNetCode() )
return false;
if( GetPriority() != aZoneToCompare.GetPriority() )
return false;
// Compare zone specific parameters
if( GetIsRuleArea() != aZoneToCompare.GetIsRuleArea() )
return false;
if( GetIsRuleArea() )
{
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( 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;
2012-01-29 19:29:19 +00:00
// 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
2020-08-26 18:04:32 +00:00
* 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
* @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, LAYER_NUM aLayer )
{
int copyCount = 0;
for( unsigned ii = 0; ; ii++ )
{
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
if( zone == NULL ) // End of list
break;
if( aNetCode >= 0 && aNetCode != zone->GetNetCode() )
continue;
if( aLayer >= 0 && !zone->GetLayerSet().test( aLayer ) )
continue;
ZONE_CONTAINER* zoneDup = new ZONE_CONTAINER( *zone );
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 );
aPickList.PushItem( picker );
copyCount++;
}
return copyCount;
}
/**
* Function UpdateCopyOfZonesList
* 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,
* 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
2012-08-03 15:43:15 +00:00
* 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:
2020-08-26 18:04:32 +00:00
* its status becomes DELETED
* 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):
* 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
2020-08-26 18:04:32 +00:00
* 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)
2020-08-26 18:04:32 +00:00
* All pickers flagged DELETED are removed, and the coresponding 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.
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.)
* 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++ )
{
2020-08-26 18:04:32 +00:00
UNDO_REDO status = aPickList.GetPickedItemStatus( kk );
ZONE_CONTAINER* ref = (ZONE_CONTAINER*) aPickList.GetPickedItem( kk );
for( unsigned ii = 0; ; ii++ ) // analyse the main picked list
{
ZONE_CONTAINER* zone = aPcb->GetArea( ii );
if( zone == NULL )
{
/* 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
*/
2020-08-26 18:04:32 +00:00
if( status == UNDO_REDO::NEWITEM )
{
delete ref;
2015-02-22 21:25:29 +00:00
ref = NULL;
aPickList.RemovePicker( kk );
kk--;
}
else
{
ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) aPickList.GetPickedItemLink( kk );
2020-08-26 18:04:32 +00:00
aPickList.SetPickedItemStatus( UNDO_REDO::DELETED, kk );
2015-02-22 21:25:29 +00:00
wxASSERT_MSG( zcopy != NULL,
wxT( "UpdateCopyOfZonesList() error: link = NULL" ) );
*ref = *zcopy;
// the copy was deleted; the link does not exists now.
aPickList.SetPickedItemLink( NULL, kk );
delete zcopy;
}
// Remove this item from aAuxiliaryList, mainly for tests purpose
bool notfound = true;
for( unsigned nn = 0; nn < aAuxiliaryList.GetCount(); nn++ )
{
2015-02-22 21:25:29 +00:00
if( ref != NULL && 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
{
DBG( printf(
"UpdateCopyOfZonesList(): item not found in aAuxiliaryList,"
"combined with another zone\n" ) );
}
break;
}
2015-02-22 21:25:29 +00:00
if( zone == ref ) // picked zone found
{
2020-08-26 18:04:32 +00:00
if( aPickList.GetPickedItemStatus( kk ) != UNDO_REDO::NEWITEM )
{
ZONE_CONTAINER* zcopy = (ZONE_CONTAINER*) 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(); )
{
2020-08-26 18:04:32 +00:00
if( aAuxiliaryList.GetPickedItemStatus( ii ) == UNDO_REDO::NEWITEM )
{
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 )
{
delete aAuxiliaryList.GetPickedItemLink( ii );
aAuxiliaryList.RemovePicker( ii );
}
else
ii++;
}
// Should not occur:
2015-02-22 21:25:29 +00:00
wxASSERT_MSG( aAuxiliaryList.GetCount() == 0,
wxT( "UpdateCopyOfZonesList() error: aAuxiliaryList not empty." ) );
}