diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index ffe526f241..78da642800 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -291,7 +291,6 @@ set( PCBNEW_CLASS_SRCS undo_redo.cpp zone_filler.cpp zones_by_polygon.cpp - zones_by_polygon_fill_functions.cpp zones_functions_for_undo_redo.cpp zones_test_and_combine_areas.cpp diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index d4798681ba..ae984151f7 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -30,13 +30,15 @@ #include #include #include -#include +#include #include #include #include #include #include +#include #include +#include DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) : @@ -221,7 +223,6 @@ void DIALOG_PLOT::OnRightClick( wxMouseEvent& event ) // Select or deselect groups of layers in the layers list: -#include void DIALOG_PLOT::OnPopUpLayers( wxCommandEvent& event ) { // Build a list of layers for usual fabrication: @@ -740,7 +741,7 @@ void DIALOG_PLOT::Plot( wxCommandEvent& event ) } if( m_zoneFillCheck->GetValue() ) - m_parent->Check_All_Zones( this ); + m_parent->GetToolManager()->GetTool()->CheckAllZones( this ); m_plotOpts.SetAutoScale( false ); m_plotOpts.SetScale( 1 ); diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 705f5f7f4c..f88d02703d 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -863,20 +863,6 @@ public: bool aUseNetclassValue ); - // zone handling - - /** - * Function Fill_All_Zones - */ - void Fill_All_Zones(); - - /** - * Function Check_All_Zones - * Checks for out-of-date fills and fills them if requested by the user. - * @param aActiveWindow - */ - void Check_All_Zones( wxWindow* aActiveWindow ); - /** * Function Edit_Zone_Params * Edit params (layer, clearance, ...) for a zone outline diff --git a/pcbnew/tools/drc.cpp b/pcbnew/tools/drc.cpp index c134d6fbe0..b8a575b1f8 100644 --- a/pcbnew/tools/drc.cpp +++ b/pcbnew/tools/drc.cpp @@ -57,7 +57,7 @@ #include #include - +#include "zone_filler_tool.h" DRC::DRC() : PCB_TOOL_BASE( "pcbnew.DRCTool" ) @@ -393,14 +393,14 @@ void DRC::RunTests( wxTextCtrl* aMessages ) if( aMessages ) aMessages->AppendText( _( "Refilling all zones...\n" ) ); - m_pcbEditorFrame->Fill_All_Zones(); + m_toolMgr->GetTool()->FillAllZones( caller ); } else { if( aMessages ) aMessages->AppendText( _( "Checking zone fills...\n" ) ); - m_pcbEditorFrame->Check_All_Zones( caller ); + m_toolMgr->GetTool()->CheckAllZones( caller ); } // test track and via clearances to other tracks, pads, and vias diff --git a/pcbnew/tools/zone_filler_tool.cpp b/pcbnew/tools/zone_filler_tool.cpp index e7e4fc8a0e..a969fcc520 100644 --- a/pcbnew/tools/zone_filler_tool.cpp +++ b/pcbnew/tools/zone_filler_tool.cpp @@ -24,13 +24,9 @@ */ #include #include -#include - #include -#include #include #include - #include #include #include @@ -55,7 +51,60 @@ void ZONE_FILLER_TOOL::Reset( RESET_REASON aReason ) { } -// Zone actions + +void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller ) +{ + if( !getEditFrame()->m_ZoneFillsDirty ) + return; + + std::vector toFill; + + for( auto zone : board()->Zones() ) + toFill.push_back(zone); + + BOARD_COMMIT commit( this ); + + ZONE_FILLER filler( frame()->GetBoard(), &commit ); + filler.SetProgressReporter( std::make_unique( aCaller, + _( "Checking Zones" ), + 4 ) ); + + if( filler.Fill( toFill, true ) ) + { + getEditFrame()->m_ZoneFillsDirty = false; + canvas()->Refresh(); + } +} + + +void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller ) +{ + std::vector toFill; + + BOARD_COMMIT commit( this ); + + for( auto zone : board()->Zones() ) + toFill.push_back(zone); + + ZONE_FILLER filler( board(), &commit ); + filler.SetProgressReporter( std::make_unique( aCaller, + _( "Fill All Zones" ), + 4 ) ); + + if( filler.Fill( toFill ) ) + getEditFrame()->m_ZoneFillsDirty = false; + + canvas()->Refresh(); + + // wxWidgets has keyboard focus issues after the progress reporter. Re-setting the focus + // does not fix them; moving the mouse does. Here we warp the mouse to its existing location + // (which will bring it back inside the window if it was outside). While sometimes mildly + // annoying, it does fix the more-often annoying loss of keybard focus. + VECTOR2D cursor = getViewControls()->GetRawCursorPosition( false ); + getViewControls()->SetCursorPosition( cursor, true, true ); +} + + int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) { std::vector toFill; @@ -77,36 +126,19 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) } ZONE_FILLER filler( board(), &commit ); - filler.SetProgressReporter( - std::make_unique( frame(), _( "Fill Zone" ), 4 ) ); + filler.SetProgressReporter( std::make_unique( frame(), + _( "Fill Zone" ), + 4 ) ); filler.Fill( toFill ); canvas()->Refresh(); - return 0; } int ZONE_FILLER_TOOL::ZoneFillAll( const TOOL_EVENT& aEvent ) { - std::vector toFill; - - BOARD_COMMIT commit( this ); - - for( auto zone : board()->Zones() ) - { - toFill.push_back(zone); - } - - ZONE_FILLER filler( board(), &commit ); - filler.SetProgressReporter( - std::make_unique( frame(), _( "Fill All Zones" ), 4 ) ); - - if( filler.Fill( toFill ) ) - getEditFrame()->m_ZoneFillsDirty = false; - - canvas()->Refresh(); - + FillAllZones( frame() ); return 0; } diff --git a/pcbnew/tools/zone_filler_tool.h b/pcbnew/tools/zone_filler_tool.h index a76006a460..4431c65b82 100644 --- a/pcbnew/tools/zone_filler_tool.h +++ b/pcbnew/tools/zone_filler_tool.h @@ -44,7 +44,9 @@ public: /// @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ) override; - // Zone actions + void CheckAllZones( wxWindow* aCaller ); + void FillAllZones( wxWindow* aCaller ); + int ZoneFill( const TOOL_EVENT& aEvent ); int ZoneFillAll( const TOOL_EVENT& aEvent ); int ZoneUnfill( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/zones_by_polygon_fill_functions.cpp b/pcbnew/zones_by_polygon_fill_functions.cpp deleted file mode 100644 index af20b06319..0000000000 --- a/pcbnew/zones_by_polygon_fill_functions.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * @file zones_by_polygon_fill_functions.cpp - */ - -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2009 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 2018 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 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -void PCB_EDIT_FRAME::Fill_All_Zones() -{ - auto toolMgr = GetToolManager(); - toolMgr->RunAction( PCB_ACTIONS::zoneFillAll, true ); -} - - -void PCB_EDIT_FRAME::Check_All_Zones( wxWindow* aActiveWindow ) -{ - if( !m_ZoneFillsDirty ) - return; - - std::vector toFill; - - for( auto zone : GetBoard()->Zones() ) - toFill.push_back(zone); - - BOARD_COMMIT commit( this ); - - std::unique_ptr progressReporter( - new WX_PROGRESS_REPORTER( aActiveWindow, _( "Checking Zones" ), 4 ) ); - - ZONE_FILLER filler( GetBoard(), &commit ); - filler.SetProgressReporter( progressReporter.get() ); - - if( filler.Fill( toFill, true ) ) - { - m_ZoneFillsDirty = false; - GetCanvas()->ForceRefresh(); - } -}