Remove Export Settings to Other Similar Zones.

The UI for it is clunky (Cancel afterwards doesn't do what
you think it might), the undo code is all hand-rolled (and
possibly buggy?), and we have the Property Inspector now
for this type of stuff.
This commit is contained in:
Jeff Young 2024-02-03 13:20:48 +00:00
parent 0890ac57dd
commit 4d49762714
10 changed files with 12 additions and 561 deletions

View File

@ -333,7 +333,6 @@ set( PCBNEW_CLASS_SRCS
tracks_cleaner.cpp
undo_redo.cpp
zone_filler.cpp
zones_functions_for_undo_redo.cpp
edit_zone_helpers.cpp
ratsnest/ratsnest.cpp

View File

@ -3,7 +3,7 @@
*
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2024 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
@ -61,20 +61,15 @@ private:
bool TransferDataFromWindow() override;
/**
* @param aUseExportableSetupOnly is true to use exportable parameters only (used to
* export this setup to other zones).
* @return bool - false if incorrect options, true if ok.
*/
bool AcceptOptions( bool aUseExportableSetupOnly = false );
bool AcceptOptions();
void OnStyleSelection( wxCommandEvent& event ) override;
void OnLayerSelection( wxDataViewEvent& event ) override;
void OnNetSortingOptionSelected( wxCommandEvent& event ) override;
void ExportSetupToOtherCopperZones( wxCommandEvent& event ) override;
void OnShowNetNameFilterChange( wxCommandEvent& event ) override;
void OnUpdateUI( wxUpdateUIEvent& ) override;
void OnButtonCancelClick( wxCommandEvent& event ) override;
void OnClose( wxCloseEvent& event ) override;
void OnNetSelectionUpdated( wxCommandEvent& event ) override;
void OnRemoveIslandsSelection( wxCommandEvent& event ) override;
@ -96,8 +91,6 @@ private:
private:
PCB_BASE_FRAME* m_Parent;
bool m_settingsExported; // settings will be written to all other zones
ZONE_SETTINGS m_settings;
ZONE_SETTINGS* m_ptr;
bool m_netSortingByPadCount;
@ -243,7 +236,6 @@ DIALOG_COPPER_ZONE::DIALOG_COPPER_ZONE( PCB_BASE_FRAME* aParent, ZONE_SETTINGS*
SetTitle( _( "Convert to Copper Zone" ) );
}
m_settingsExported = false;
m_currentlySelectedNetcode = INVALID_NET_CODE;
m_maxNetCode = INVALID_NET_CODE;
@ -415,14 +407,6 @@ void DIALOG_COPPER_ZONE::OnUpdateUI( wxUpdateUIEvent& )
}
void DIALOG_COPPER_ZONE::OnButtonCancelClick( wxCommandEvent& event )
{
// After an "Export Settings to Other Zones" cancel and close must return
// ZONE_EXPORT_VALUES instead of wxID_CANCEL.
Close( true );
}
void DIALOG_COPPER_ZONE::OnNetSelectionUpdated( wxCommandEvent& event )
{
updateCurrentNetSelection();
@ -490,14 +474,7 @@ bool DIALOG_COPPER_ZONE::TransferDataFromWindow()
}
void DIALOG_COPPER_ZONE::OnClose( wxCloseEvent& event )
{
SetReturnCode( m_settingsExported ? ZONE_EXPORT_VALUES : wxID_CANCEL );
event.Skip();
}
bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
bool DIALOG_COPPER_ZONE::AcceptOptions()
{
if( !m_clearance.Validate( 0, pcbIUScale.mmToIU( ZONE_CLEARANCE_MAX_VALUE_MM ) ) )
return false;
@ -573,10 +550,6 @@ bool DIALOG_COPPER_ZONE::AcceptOptions( bool aUseExportableSetupOnly )
m_settings.SetIslandRemovalMode( (ISLAND_REMOVAL_MODE) m_cbRemoveIslands->GetSelection() );
m_settings.SetMinIslandArea( m_islandThreshold.GetValue() );
// If we use only exportable to others zones parameters, exit here:
if( aUseExportableSetupOnly )
return true;
// Get the layer selection for this zone
int layers = 0;
@ -679,35 +652,6 @@ void DIALOG_COPPER_ZONE::loadPersistentNetSortConfigurations()
}
void DIALOG_COPPER_ZONE::ExportSetupToOtherCopperZones( wxCommandEvent& event )
{
if( !AcceptOptions( true ) )
return;
// Export settings ( but layer and netcode ) to others copper zones
BOARD* pcb = m_Parent->GetBoard();
for( ZONE* zone : pcb->Zones() )
{
// Cannot export settings from a copper zone
// to a zone keepout:
if( zone->GetIsRuleArea() )
continue;
// Export only to similar zones:
// Teardrop area -> teardrop area of same type
// copper zone -> copper zone
// Exporting current settings to a different zone type make no sense
if( m_settings.m_TeardropType != zone->GetTeardropAreaType() )
continue;
m_settings.ExportSetting( *zone, false ); // false = partial export
m_settingsExported = true;
m_Parent->OnModify();
}
}
void DIALOG_COPPER_ZONE::OnShowNetNameFilterChange( wxCommandEvent& event )
{
updateDisplayedListOfNets();

View File

@ -392,11 +392,6 @@ DIALOG_COPPER_ZONE_BASE::DIALOG_COPPER_ZONE_BASE( wxWindow* parent, wxWindowID i
wxBoxSizer* bSizerbottom;
bSizerbottom = new wxBoxSizer( wxHORIZONTAL );
m_ExportSetupButton = new wxButton( this, wxID_BUTTON_EXPORT, _("Export Settings to Other Similar Zones"), wxDefaultPosition, wxDefaultSize, 0 );
m_ExportSetupButton->SetToolTip( _("Export this zone setup (excluding layer and net selection) to other similar copper zones (teardrops or usual copper zones).") );
bSizerbottom->Add( m_ExportSetupButton, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 10 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
@ -425,7 +420,6 @@ DIALOG_COPPER_ZONE_BASE::DIALOG_COPPER_ZONE_BASE( wxWindow* parent, wxWindowID i
m_ListNetNameSelection->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnNetSelectionUpdated ), NULL, this );
m_GridStyleCtrl->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnStyleSelection ), NULL, this );
m_cbRemoveIslands->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnRemoveIslandsSelection ), NULL, this );
m_ExportSetupButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::ExportSetupToOtherCopperZones ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnButtonCancelClick ), NULL, this );
}
@ -442,7 +436,6 @@ DIALOG_COPPER_ZONE_BASE::~DIALOG_COPPER_ZONE_BASE()
m_ListNetNameSelection->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnNetSelectionUpdated ), NULL, this );
m_GridStyleCtrl->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnStyleSelection ), NULL, this );
m_cbRemoveIslands->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnRemoveIslandsSelection ), NULL, this );
m_ExportSetupButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::ExportSetupToOtherCopperZones ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COPPER_ZONE_BASE::OnButtonCancelClick ), NULL, this );
}

View File

@ -4083,81 +4083,6 @@
<property name="name">bSizerbottom</property>
<property name="orient">wxHORIZONTAL</property>
<property name="permission">none</property>
<object class="sizeritem" expanded="false">
<property name="border">10</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="false">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="drag_accept_files">0</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_BUTTON_EXPORT</property>
<property name="label">Export Settings to Other Similar Zones</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_ExportSetupButton</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip">Export this zone setup (excluding layer and net selection) to other similar copper zones (teardrops or usual copper zones).</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">ExportSetupToOtherCopperZones</event>
</object>
</object>
<object class="sizeritem" expanded="false">
<property name="border">5</property>
<property name="flag">wxALL|wxEXPAND</property>

View File

@ -29,9 +29,6 @@
#include <wx/statline.h>
#include <wx/gbsizer.h>
#include <wx/button.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
@ -55,8 +52,7 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
ID_CORNER_SMOOTHING,
ID_M_PADINZONEOPT,
wxID_ANTIPAD_SIZE,
wxID_COPPER_BRIDGE_VALUE,
wxID_BUTTON_EXPORT
wxID_COPPER_BRIDGE_VALUE
};
wxBoxSizer* m_MainBoxSizer;
@ -118,7 +114,6 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
wxStaticText* m_islandThresholdLabel;
wxTextCtrl* m_tcIslandThreshold;
wxStaticText* m_islandThresholdUnits;
wxButton* m_ExportSetupButton;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
@ -132,7 +127,6 @@ class DIALOG_COPPER_ZONE_BASE : public DIALOG_SHIM
virtual void OnNetSelectionUpdated( wxCommandEvent& event ) { event.Skip(); }
virtual void OnStyleSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void OnRemoveIslandsSelection( wxCommandEvent& event ) { event.Skip(); }
virtual void ExportSetupToOtherCopperZones( wxCommandEvent& event ) { event.Skip(); }
virtual void OnButtonCancelClick( wxCommandEvent& event ) { event.Skip(); }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
*
* Some code comes from FreePCB.
*
@ -34,21 +34,14 @@
#include <tool/actions.h>
#include <zone.h>
#include <zones.h>
#include <zones_functions_for_undo_redo.h>
#include <connectivity/connectivity_data.h>
void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone )
{
int dialogResult;
ZONE_SETTINGS zoneInfo = m_pcb->GetDesignSettings().GetDefaultZoneSettings();
PICKED_ITEMS_LIST pickedList; // zones for undo/redo command
PICKED_ITEMS_LIST deletedList; // zones that have been deleted when combined
BOARD_COMMIT commit( this );
// Save initial zones configuration, for undo/redo, before adding new zone
// note the net name and the layer can be changed, so we must save all zones
SaveCopyOfZones( pickedList, GetBoard() );
int dialogResult;
ZONE_SETTINGS zoneInfo = m_pcb->GetDesignSettings().GetDefaultZoneSettings();
BOARD_COMMIT commit( this );
if( aZone->GetIsRuleArea() )
{
@ -69,23 +62,7 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone )
}
if( dialogResult == wxID_CANCEL )
{
ClearListAndDeleteItems( &deletedList );
ClearListAndDeleteItems( &pickedList );
return;
}
m_pcb->GetDesignSettings().SetDefaultZoneSettings( zoneInfo );
OnModify();
if( dialogResult == ZONE_EXPORT_VALUES )
{
UpdateCopyOfZonesList( pickedList, deletedList, GetBoard() );
commit.Stage( pickedList );
commit.Push( _( "Modify zone properties" ) );
pickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items
return;
}
wxBusyCursor dummy;
@ -93,6 +70,8 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone )
for( ZONE* zone : GetBoard()->Zones() )
GetCanvas()->GetView()->Update( zone );
commit.Modify( aZone );
zoneInfo.ExportSetting( *aZone );
NETINFO_ITEM* net = GetBoard()->FindNet( zoneInfo.m_NetcodeSelection );
@ -100,14 +79,11 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone )
if( net ) // net == NULL should not occur
aZone->SetNetCode( net->GetNetCode() );
UpdateCopyOfZonesList( pickedList, deletedList, GetBoard() );
commit.Stage( pickedList );
m_pcb->GetDesignSettings().SetDefaultZoneSettings( zoneInfo );
// TODO: 9.0: Use title capitalization
commit.Push( _( "Modify zone properties" ), SKIP_CONNECTIVITY );
rebuildConnectivity();
pickedList.ClearItemsList(); // s_ItemsListPicker is no longer owner of picked items
}

View File

@ -593,17 +593,6 @@ public:
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const { return m_borderStyle; }
void SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE aStyle ) { m_borderStyle = aStyle; }
/**
* Test if 2 zones are equivalent.
*
* Zones are equivalent if they have same parameters and same outline info.
*
* @note Filling is not taken into account.
*
* @param aZoneToCompare is the zone to compare with "this"
*/
bool IsSame( const ZONE &aZoneToCompare );
bool HasFilledPolysForLayer( PCB_LAYER_ID aLayer ) const
{
return m_FilledPolysList.count( aLayer ) > 0;

View File

@ -40,9 +40,6 @@ struct CONVERT_SETTINGS;
#define ZONE_BORDER_HATCH_MINDIST_MM 0.1 // Minimum for ZONE_SETTINGS::m_BorderHatchPitch
#define ZONE_BORDER_HATCH_MAXDIST_MM 2.0 // Maximum for ZONE_SETTINGS::m_BorderHatchPitch
#define ZONE_EXPORT_VALUES 1004 // Copper zone dialog reports wxID_OK, wxID_CANCEL or
// ZONE_EXPORT_VALUES
/// How pads are covered by copper in zone
enum class ZONE_CONNECTION

View File

@ -1,297 +0,0 @@
/*
* 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 (C) 2007-2022 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 <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( 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;
// 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." ) );
}

View File

@ -1,69 +0,0 @@
/**
* @file zones_functions_for_undo_redo.h
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
* Copyright (C) 2007 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)
*/
#ifndef ZONES_FUNCTIONS_TO_UNDO_REDO_H
#define ZONES_FUNCTIONS_TO_UNDO_REDO_H
/**
* 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
* @param aPickList = the pick list
* @param aPcb = the Board
*/
void SaveCopyOfZones(PICKED_ITEMS_LIST & aPickList, BOARD* aPcb );
/**
* Function UpdateCopyOfZonesList
* check a pick list to remove zones identical to their copies
* and set the type of operation in picker (DELETED, CHANGED)
* @param aPickList = the main pick list
* @param aAuxiliaryList = the list of deleted or added (new created) items after calculations
* @param aPcb = the Board
*/
void UpdateCopyOfZonesList( PICKED_ITEMS_LIST& aPickList, PICKED_ITEMS_LIST& aAuxiliaryList,
BOARD* aPcb );
#endif // ZONES_FUNCTIONS_TO_UNDO_REDO_H