From 41619ebbe25f34a9e2e05207ae5f04f2d04f3fe3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 14 Aug 2021 21:05:21 +0100 Subject: [PATCH] Decouple PROGRESS_REPORTER interface from implementations. --- common/CMakeLists.txt | 3 +- common/widgets/footprint_select_widget.cpp | 2 +- common/widgets/progress_reporter_base.cpp | 141 +++++++++++++ common/widgets/progress_reporter_base.h | 127 +++++++++++ ...reporter.cpp => wx_progress_reporters.cpp} | 118 +---------- cvpcb/cvpcb_mainframe.cpp | 2 +- eeschema/dialogs/dialog_erc.cpp | 4 +- eeschema/dialogs/dialog_erc.h | 6 +- eeschema/files-io.cpp | 2 +- .../sch_plugins/eagle/sch_eagle_plugin.cpp | 2 +- .../sch_plugins/kicad/sch_sexpr_parser.cpp | 2 +- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 2 +- .../sch_plugins/legacy/sch_legacy_plugin.cpp | 2 +- eeschema/symbol_async_loader.cpp | 2 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 2 +- .../symbol_editor/symbol_library_manager.cpp | 2 +- eeschema/symbol_tree_model_adapter.cpp | 3 +- gerbview/files.cpp | 2 +- include/progress_reporter.h | 112 ++++++++++ include/widgets/progress_reporter.h | 198 ------------------ include/widgets/wx_progress_reporters.h | 99 +++++++++ pagelayout_editor/tools/pl_point_editor.cpp | 2 +- pcbnew/autorouter/ar_autoplacer.cpp | 2 +- pcbnew/autorouter/autoplace_tool.cpp | 2 +- pcbnew/connectivity/connectivity_algo.cpp | 2 +- pcbnew/dialogs/dialog_board_setup.cpp | 2 +- pcbnew/dialogs/dialog_drc.cpp | 6 +- pcbnew/dialogs/dialog_drc.h | 4 +- pcbnew/drc/drc_engine.cpp | 2 +- pcbnew/edit_zone_helpers.cpp | 7 +- pcbnew/files.cpp | 2 +- pcbnew/footprint_edit_frame.cpp | 2 +- pcbnew/footprint_info_impl.cpp | 2 +- pcbnew/load_select_footprint.cpp | 2 +- pcbnew/plugins/altium/altium_pcb.cpp | 2 +- pcbnew/plugins/eagle/eagle_plugin.cpp | 2 +- pcbnew/plugins/fabmaster/fabmaster_plugin.cpp | 2 +- pcbnew/plugins/fabmaster/import_fabmaster.cpp | 2 +- pcbnew/plugins/kicad/kicad_plugin.cpp | 2 +- pcbnew/plugins/kicad/pcb_parser.cpp | 2 +- pcbnew/plugins/legacy/legacy_plugin.cpp | 2 +- pcbnew/tools/drc_tool.cpp | 2 +- pcbnew/tools/pcb_control.cpp | 2 +- pcbnew/tools/pcb_point_editor.cpp | 2 +- pcbnew/tools/zone_filler_tool.cpp | 38 ++-- pcbnew/zone_filler.cpp | 10 +- pcbnew/zone_filler.h | 9 +- qa/drc_proto/drc_proto.cpp | 2 +- qa/drc_proto/drc_proto.h | 6 +- 49 files changed, 567 insertions(+), 388 deletions(-) create mode 100644 common/widgets/progress_reporter_base.cpp create mode 100644 common/widgets/progress_reporter_base.h rename common/widgets/{progress_reporter.cpp => wx_progress_reporters.cpp} (59%) create mode 100644 include/progress_reporter.h delete mode 100644 include/widgets/progress_reporter.h create mode 100644 include/widgets/wx_progress_reporters.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 808c7caf53..0353f40836 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -229,7 +229,7 @@ set( COMMON_WIDGET_SRCS widgets/msgpanel.cpp widgets/number_badge.cpp widgets/paged_dialog.cpp - widgets/progress_reporter.cpp + widgets/progress_reporter_base.cpp widgets/split_button.cpp widgets/stepped_slider.cpp widgets/text_ctrl_eval.cpp @@ -241,6 +241,7 @@ set( COMMON_WIDGET_SRCS widgets/wx_busy_indicator.cpp widgets/wx_ellipsized_static_text.cpp widgets/wx_grid.cpp + widgets/wx_progress_reporters.cpp ) set( COMMON_DRAWING_SHEET_SRCS diff --git a/common/widgets/footprint_select_widget.cpp b/common/widgets/footprint_select_widget.cpp index de096e9647..f000288bc5 100644 --- a/common/widgets/footprint_select_widget.cpp +++ b/common/widgets/footprint_select_widget.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include diff --git a/common/widgets/progress_reporter_base.cpp b/common/widgets/progress_reporter_base.cpp new file mode 100644 index 0000000000..a4103846fc --- /dev/null +++ b/common/widgets/progress_reporter_base.cpp @@ -0,0 +1,141 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * Author: Tomasz Wlostowski + * + * 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 + +PROGRESS_REPORTER_BASE::PROGRESS_REPORTER_BASE( int aNumPhases ) : + PROGRESS_REPORTER(), + m_msgChanged( false ), + m_phase( 0 ), + m_numPhases( aNumPhases ), + m_progress( 0 ), + m_maxProgress( 1000 ), + m_cancelled( false ) +{ +} + + +void PROGRESS_REPORTER_BASE::BeginPhase( int aPhase ) +{ + m_phase.store( aPhase ); + m_progress.store( 0 ); +} + + +void PROGRESS_REPORTER_BASE::AdvancePhase() +{ + m_phase.fetch_add( 1 ); + m_progress.store( 0 ); +} + + +void PROGRESS_REPORTER_BASE::AdvancePhase( const wxString& aMessage ) +{ + AdvancePhase(); + Report( aMessage ); +} + + +void PROGRESS_REPORTER_BASE::Report( const wxString& aMessage ) +{ + std::lock_guard guard( m_mutex ); + m_rptMessage = aMessage; + m_msgChanged = true; +} + + +void PROGRESS_REPORTER_BASE::SetMaxProgress( int aMaxProgress ) +{ + m_maxProgress.store( aMaxProgress ); +} + + +void PROGRESS_REPORTER_BASE::SetCurrentProgress( double aProgress ) +{ + m_maxProgress.store( 1000 ); + m_progress.store( (int) ( aProgress * 1000.0 ) ); +} + + +void PROGRESS_REPORTER_BASE::AdvanceProgress() +{ + m_progress.fetch_add( 1 ); +} + + +void PROGRESS_REPORTER_BASE::SetNumPhases( int aNumPhases ) +{ + m_numPhases = aNumPhases; +} + + +void PROGRESS_REPORTER_BASE::AddPhases( int aNumPhases ) +{ + m_numPhases += aNumPhases; +} + + +int PROGRESS_REPORTER_BASE::currentProgress() const +{ + double current = ( 1.0 / (double) m_numPhases ) * + ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) ); + + return (int)( current * 1000 ); +} + + +bool PROGRESS_REPORTER_BASE::KeepRefreshing( bool aWait ) +{ + if( aWait ) + { + while( m_progress.load() < m_maxProgress && m_maxProgress > 0 ) + { + if( !updateUI() ) + { + m_cancelled.store( true ); + return false; + } + + wxMilliSleep( 20 ); + } + + return true; + } + else + { + if( !updateUI() ) + { + m_cancelled.store( true ); + return false; + } + + return true; + } +} + + diff --git a/common/widgets/progress_reporter_base.h b/common/widgets/progress_reporter_base.h new file mode 100644 index 0000000000..f7fd54b48b --- /dev/null +++ b/common/widgets/progress_reporter_base.h @@ -0,0 +1,127 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * Author: Tomasz Wlostowski + * + * 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 + */ + +#ifndef GENERIC_PROGRESS_REPORTER_H +#define GENERIC_PROGRESS_REPORTER_H + +#include +#include +#include + +/** + * This implements all the tricky bits for thread safety, but the GUI is left to derived classes. + */ +class PROGRESS_REPORTER_BASE : public PROGRESS_REPORTER +{ +public: + + PROGRESS_REPORTER_BASE( int aNumPhases ); + PROGRESS_REPORTER_BASE( const PROGRESS_REPORTER_BASE& ) = delete; + + virtual ~PROGRESS_REPORTER_BASE() + { + } + + /** + * Set the number of phases. + */ + void SetNumPhases( int aNumPhases ) override; + void AddPhases( int aNumPhases ) override; + + /** + * Initialize the \a aPhase virtual zone of the dialog progress bar. + */ + virtual void BeginPhase( int aPhase ) override; + + /** + * Use the next available virtual zone of the dialog progress bar. + */ + virtual void AdvancePhase() override; + + /** + * Use the next available virtual zone of the dialog progress bar and updates the message. + */ + virtual void AdvancePhase( const wxString& aMessage ) override; + + /** + * Display \a aMessage in the progress bar dialog. + */ + virtual void Report( const wxString& aMessage ) override; + + /** + * Set the progress value to aProgress (0..1). + */ + virtual void SetCurrentProgress( double aProgress ) override; + + /** + * Fix the value that gives the 100 percent progress bar length + * (inside the current virtual zone). + */ + void SetMaxProgress( int aMaxProgress ) override; + + /** + * Increment the progress bar length (inside the current virtual zone). + */ + void AdvanceProgress() override; + + /** + * Update the UI dialog. + * + * @warning This should only be called from the main thread. + * + * @return false if the user clicked Cancel. + */ + bool KeepRefreshing( bool aWait = false ) override; + + /** + * Change the title displayed on the window caption. + * + * Has meaning only for some reporters. Does nothing for others. + * + * @warning This should only be called from the main thread. + */ + void SetTitle( const wxString& aTitle ) override { } + + bool IsCancelled() const override { return m_cancelled; } + +protected: + int currentProgress() const; + + virtual bool updateUI() = 0; + + wxString m_rptMessage; + bool m_msgChanged; // true after change in m_rptMessage + + mutable std::mutex m_mutex; + std::atomic_int m_phase; + std::atomic_int m_numPhases; + std::atomic_int m_progress; + std::atomic_int m_maxProgress; + std::atomic_bool m_cancelled; +}; + + +#endif diff --git a/common/widgets/progress_reporter.cpp b/common/widgets/wx_progress_reporters.cpp similarity index 59% rename from common/widgets/progress_reporter.cpp rename to common/widgets/wx_progress_reporters.cpp index 41c779352a..a14620a703 100644 --- a/common/widgets/progress_reporter.cpp +++ b/common/widgets/wx_progress_reporters.cpp @@ -24,124 +24,16 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include #include #include - -PROGRESS_REPORTER::PROGRESS_REPORTER( int aNumPhases ) : - m_msgChanged( false ), - m_phase( 0 ), - m_numPhases( aNumPhases ), - m_progress( 0 ), - m_maxProgress( 1000 ), - m_cancelled( false ) -{ -} - - -void PROGRESS_REPORTER::BeginPhase( int aPhase ) -{ - m_phase.store( aPhase ); - m_progress.store( 0 ); -} - - -void PROGRESS_REPORTER::AdvancePhase() -{ - m_phase.fetch_add( 1 ); - m_progress.store( 0 ); -} - - -void PROGRESS_REPORTER::AdvancePhase( const wxString& aMessage ) -{ - AdvancePhase(); - Report( aMessage ); -} - - -void PROGRESS_REPORTER::Report( const wxString& aMessage ) -{ - std::lock_guard guard( m_mutex ); - m_rptMessage = aMessage; - m_msgChanged = true; -} - - -void PROGRESS_REPORTER::SetMaxProgress( int aMaxProgress ) -{ - m_maxProgress.store( aMaxProgress ); -} - -void PROGRESS_REPORTER::SetCurrentProgress( double aProgress ) -{ - m_maxProgress.store( 1000 ); - m_progress.store( (int) ( aProgress * 1000.0 ) ); -} - - -void PROGRESS_REPORTER::AdvanceProgress() -{ - m_progress.fetch_add( 1 ); -} - - -void PROGRESS_REPORTER::SetNumPhases( int aNumPhases ) -{ - m_numPhases = aNumPhases; -} - - -void PROGRESS_REPORTER::AddPhases( int aNumPhases ) -{ - m_numPhases += aNumPhases; -} - - -int PROGRESS_REPORTER::currentProgress() const -{ - double current = ( 1.0 / (double) m_numPhases ) * - ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) ); - - return (int)( current * 1000 ); -} - - -bool PROGRESS_REPORTER::KeepRefreshing( bool aWait ) -{ - if( aWait ) - { - while( m_progress.load() < m_maxProgress && m_maxProgress > 0 ) - { - if( !updateUI() ) - { - m_cancelled.store( true ); - return false; - } - - wxMilliSleep( 20 ); - } - - return true; - } - else - { - if( !updateUI() ) - { - m_cancelled.store( true ); - return false; - } - - return true; - } -} +#include WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases, bool aCanAbort, bool aReserveSpaceForMessage ) : - PROGRESS_REPORTER( aNumPhases ), - wxProgressDialog( aTitle, ( aReserveSpaceForMessage ? wxT( " " ) : wxT( "" ) ), 1, aParent, + PROGRESS_REPORTER_BASE( aNumPhases ), + wxProgressDialog( aTitle, ( aReserveSpaceForMessage ? wxT( " " ) : wxT( "" ) ), 1, aParent, // wxPD_APP_MODAL | // Don't use; messes up OSX when called from // quasi-modal dialog wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin @@ -151,7 +43,7 @@ WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& a wxPD_ELAPSED_TIME ) #if wxCHECK_VERSION( 3, 1, 0 ) , - m_appProgressIndicator( aParent ) + m_appProgressIndicator( aParent ) #endif { #if wxCHECK_VERSION( 3, 1, 0 ) @@ -196,7 +88,7 @@ bool WX_PROGRESS_REPORTER::updateUI() GAUGE_PROGRESS_REPORTER::GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases ) : - PROGRESS_REPORTER( aNumPhases ), + PROGRESS_REPORTER_BASE( aNumPhases ), wxGauge( aParent, wxID_ANY, 1000, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL, wxDefaultValidator, wxGaugeNameStr ) { diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index d94cc4aa80..4aefa92d34 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 956d326ab2..735aee1ba5 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -54,7 +54,7 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : DIALOG_ERC_BASE( parent ), - PROGRESS_REPORTER( 1 ), + PROGRESS_REPORTER_BASE( 1 ), m_parent( parent ), m_running( false ), m_ercRun( false ), @@ -143,7 +143,7 @@ bool DIALOG_ERC::updateUI() void DIALOG_ERC::AdvancePhase( const wxString& aMessage ) { // Will also call Report( aMessage ): - PROGRESS_REPORTER::AdvancePhase( aMessage ); + PROGRESS_REPORTER_BASE::AdvancePhase( aMessage ); SetCurrentProgress( 0.0 ); } diff --git a/eeschema/dialogs/dialog_erc.h b/eeschema/dialogs/dialog_erc.h index a0160f6a08..47afc2b496 100644 --- a/eeschema/dialogs/dialog_erc.h +++ b/eeschema/dialogs/dialog_erc.h @@ -30,17 +30,17 @@ #include // For PINTYPE_COUNT definition #include -#include +#include #include -class DIALOG_ERC : public DIALOG_ERC_BASE, PROGRESS_REPORTER +class DIALOG_ERC : public DIALOG_ERC_BASE, PROGRESS_REPORTER_BASE { public: DIALOG_ERC( SCH_EDIT_FRAME* parent ); ~DIALOG_ERC(); - // PROGRESS_REPORTER calls + // PROGRESS_REPORTER_BASE calls bool updateUI() override; void AdvancePhase( const wxString& aMessage ) override; void Report( const wxString& aMessage ) override; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 5c12db06ff..d14ef4aca3 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -61,7 +61,7 @@ #include #include #include // For ::ResolvePossibleSymlinks -#include +#include bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) { diff --git a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp index 22c0ee3d19..23f1ac837c 100644 --- a/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp +++ b/eeschema/sch_plugins/eagle/sch_eagle_plugin.cpp @@ -61,7 +61,7 @@ #include #include #include -#include +#include // Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp index c1aeadddf6..569d768d9f 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_parser.cpp @@ -55,7 +55,7 @@ #include #include #include -#include +#include using namespace TSCHEMATIC_T; diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index 8df05f1cc1..fcf9dd6ca3 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -61,7 +61,7 @@ #include #include #include // for ::ResolvePossibleSymlinks() -#include +#include using namespace TSCHEMATIC_T; diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index eea9fd08f6..45e4e6c590 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/eeschema/symbol_async_loader.cpp b/eeschema/symbol_async_loader.cpp index f8c5360cbf..2f1720d876 100644 --- a/eeschema/symbol_async_loader.cpp +++ b/eeschema/symbol_async_loader.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include SYMBOL_ASYNC_LOADER::SYMBOL_ASYNC_LOADER( const std::vector& aNicknames, diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index cb102a535a..9bbf6ca70a 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -67,7 +67,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index 52a567299a..9690dcce39 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/eeschema/symbol_tree_model_adapter.cpp b/eeschema/symbol_tree_model_adapter.cpp index 5876c8cb0c..5d47d124be 100644 --- a/eeschema/symbol_tree_model_adapter.cpp +++ b/eeschema/symbol_tree_model_adapter.cpp @@ -22,8 +22,7 @@ #include #include #include -#include - +#include #include #include #include diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 5f1b1e0b1d..0abac6ebd2 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include "widgets/gerbview_layer_widget.h" // HTML Messages used more than one time: diff --git a/include/progress_reporter.h b/include/progress_reporter.h new file mode 100644 index 0000000000..73db3b4ab3 --- /dev/null +++ b/include/progress_reporter.h @@ -0,0 +1,112 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * Author: Tomasz Wlostowski + * + * 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 + */ + +#ifndef PROGRESS_REPORTER_H +#define PROGRESS_REPORTER_H + +/** + * A progress reporter interface for use in multi-threaded environments. The various advancement + * and message methods can be called from sub-threads. The KeepRefreshing method *MUST* be called + * only from the main thread (primarily a MSW requirement, which won't allow access to UI objects + * allocated from a separate thread). + */ +class PROGRESS_REPORTER +{ +public: + + PROGRESS_REPORTER() + { } + + PROGRESS_REPORTER( const PROGRESS_REPORTER& ) = delete; + + virtual ~PROGRESS_REPORTER() + { } + + /** + * Set the number of phases. + */ + virtual void SetNumPhases( int aNumPhases ) = 0; + virtual void AddPhases( int aNumPhases ) = 0; + + /** + * Initialize the \a aPhase virtual zone of the dialog progress bar. + */ + virtual void BeginPhase( int aPhase ) = 0; + + /** + * Use the next available virtual zone of the dialog progress bar. + */ + virtual void AdvancePhase() = 0; + + /** + * Use the next available virtual zone of the dialog progress bar and updates the message. + */ + virtual void AdvancePhase( const wxString& aMessage ) = 0; + + /** + * Display \a aMessage in the progress bar dialog. + */ + virtual void Report( const wxString& aMessage ) = 0; + + /** + * Set the progress value to aProgress (0..1). + */ + virtual void SetCurrentProgress( double aProgress ) = 0; + + /** + * Fix the value that gives the 100 percent progress bar length + * (inside the current virtual zone). + */ + virtual void SetMaxProgress( int aMaxProgress ) = 0; + + /** + * Increment the progress bar length (inside the current virtual zone). + */ + virtual void AdvanceProgress() = 0; + + /** + * Update the UI (if any). + * + * @warning This should only be called from the main thread. + * + * @return false if the user cancelled. + */ + virtual bool KeepRefreshing( bool aWait = false ) = 0; + + /** + * Change the title displayed on the window caption. + * + * Has meaning only for some reporters. Does nothing for others. + * + * @warning This should only be called from the main thread. + */ + virtual void SetTitle( const wxString& aTitle ) = 0; + + virtual bool IsCancelled() const = 0; +}; + + +#endif diff --git a/include/widgets/progress_reporter.h b/include/widgets/progress_reporter.h deleted file mode 100644 index 0e993c8492..0000000000 --- a/include/widgets/progress_reporter.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2017 CERN - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. - * - * Author: Tomasz Wlostowski - * - * 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 - */ - -#ifndef __PROGRESS_REPORTER -#define __PROGRESS_REPORTER - -#include -#include - -#include -#include -#if wxCHECK_VERSION( 3, 1, 0 ) -#include -#endif - -/** - * A progress reporter for use in multi-threaded environments. The various advancement - * and message methods can be called from sub-threads. The KeepRefreshing method *MUST* - * be called only from the main thread (primarily a MSW requirement, which won't allow - * access to UI objects allocated from a separate thread). - */ -class PROGRESS_REPORTER -{ -public: - - PROGRESS_REPORTER( int aNumPhases ); - PROGRESS_REPORTER( const PROGRESS_REPORTER& ) = delete; - - virtual ~PROGRESS_REPORTER() - { - } - - /** - * Set the number of phases. - */ - void SetNumPhases( int aNumPhases ); - void AddPhases( int aNumPhases ); - - /** - * Initialize the \a aPhase virtual zone of the dialog progress bar. - */ - virtual void BeginPhase( int aPhase ); - - /** - * Use the next available virtual zone of the dialog progress bar. - */ - virtual void AdvancePhase(); - - /** - * Use the next available virtual zone of the dialog progress bar and updates - * the message. - */ - virtual void AdvancePhase( const wxString& aMessage ); - - /** - * Display \a aMessage in the progress bar dialog. - */ - virtual void Report( const wxString& aMessage ); - - /** - * Set the progress value to aProgress (0..1). - */ - virtual void SetCurrentProgress( double aProgress ); - - /** - * Fix the value that gives the 100 percent progress bar length - * (inside the current virtual zone). - */ - void SetMaxProgress( int aMaxProgress ); - - /** - * Increment the progress bar length (inside the current virtual zone). - */ - void AdvanceProgress(); - - /** - * Update the UI dialog. - * - * @warning This should only be called from the main thread. - * - * @return false if the user clicked Cancel. - */ - bool KeepRefreshing( bool aWait = false ); - - /** - * Change the title displayed on the window caption. - * - * Has meaning only for some reporters. Does nothing for others. - * - * @warning This should only be called from the main thread. - */ - virtual void SetTitle( const wxString& aTitle ) {} - - bool IsCancelled() const { return m_cancelled.load(); } - -protected: - - int currentProgress() const; - - virtual bool updateUI() = 0; - - wxString m_rptMessage; - bool m_msgChanged; // true after change in m_rptMessage - // the dialog needs perhaps a resize - mutable std::mutex m_mutex; - std::atomic_int m_phase; - std::atomic_int m_numPhases; - std::atomic_int m_progress; - std::atomic_int m_maxProgress; - std::atomic_bool m_cancelled; -}; - -/** -* Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting -* back of work status. -* -* @see PROGRESS_REPORTER. -*/ -class WX_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxProgressDialog -{ -public: - /** - * The #PROGRESS_REPORTER will stay on top of \a aParent. - * - * The style is wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME. - * - * @param aParent is the wxDialog of Frame that manage this. - * @param aTitle is the dialog progress title - * @param aNumPhases is the number of "virtual sections" of the progress bar - * aNumPhases = 1 is the usual progress bar - * aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width - * of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index - * @param aCanAbort is true if the abort button should be shown - * @param aReserveSpaceForMessage will ensure that the dialog is laid out for status messages, - * preventing layout issues on Windows when reporting a message after the initial layout - */ - WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases, - bool aCanAbort = true, bool aReserveSpaceForMessage = true ); - ~WX_PROGRESS_REPORTER(); - - /** - * Change the title displayed on the window caption. - */ - virtual void SetTitle( const wxString& aTitle ) override - { - wxProgressDialog::SetTitle( aTitle ); - } - -private: -#if wxCHECK_VERSION( 3, 1, 0 ) - wxAppProgressIndicator m_appProgressIndicator; -#endif - - virtual bool updateUI() override; -}; - - -class GAUGE_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxGauge -{ -public: - /** - * @param aParent is the parent of the wxGauge control - * @param aNumPhases is the number of "virtual sections" of the progress bar - * aNumPhases = 1 is the usual progress bar - * aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width - * of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index - */ - GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases ); - -private: - - bool updateUI() override; -}; - -#endif diff --git a/include/widgets/wx_progress_reporters.h b/include/widgets/wx_progress_reporters.h new file mode 100644 index 0000000000..074347a687 --- /dev/null +++ b/include/widgets/wx_progress_reporters.h @@ -0,0 +1,99 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2017 CERN + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * Author: Tomasz Wlostowski + * + * 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 + */ + +#ifndef WX_PROGRESS_REPORTERS_H +#define WX_PROGRESS_REPORTERS_H + +#include +#include +#if wxCHECK_VERSION( 3, 1, 0 ) +#include +#endif + +#include + +/** + * Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting + * back of work status. + * + * @see PROGRESS_REPORTER. + */ +class WX_PROGRESS_REPORTER : public PROGRESS_REPORTER_BASE, public wxProgressDialog +{ +public: + /** + * The #PROGRESS_REPORTER will stay on top of \a aParent. + * + * The style is wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME. + * + * @param aParent is the wxDialog of Frame that manage this. + * @param aTitle is the dialog progress title + * @param aNumPhases is the number of "virtual sections" of the progress bar + * aNumPhases = 1 is the usual progress bar + * aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width + * of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index + * @param aCanAbort is true if the abort button should be shown + * @param aReserveSpaceForMessage will ensure that the dialog is laid out for status messages, + * preventing layout issues on Windows when reporting a message after the initial layout + */ + WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases, + bool aCanAbort = true, bool aReserveSpaceForMessage = true ); + ~WX_PROGRESS_REPORTER(); + + /** + * Change the title displayed on the window caption. + */ + void SetTitle( const wxString& aTitle ) override + { + wxProgressDialog::SetTitle( aTitle ); + } + +private: +#if wxCHECK_VERSION( 3, 1, 0 ) + wxAppProgressIndicator m_appProgressIndicator; +#endif + + bool updateUI() override; +}; + + +class GAUGE_PROGRESS_REPORTER : public PROGRESS_REPORTER_BASE, public wxGauge +{ +public: + /** + * @param aParent is the parent of the wxGauge control + * @param aNumPhases is the number of "virtual sections" of the progress bar + * aNumPhases = 1 is the usual progress bar + * aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width + * of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index + */ + GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases ); + +private: + bool updateUI() override; +}; + +#endif diff --git a/pagelayout_editor/tools/pl_point_editor.cpp b/pagelayout_editor/tools/pl_point_editor.cpp index 4e9fdd1be9..83a08d3f7a 100644 --- a/pagelayout_editor/tools/pl_point_editor.cpp +++ b/pagelayout_editor/tools/pl_point_editor.cpp @@ -36,7 +36,7 @@ using namespace std::placeholders; #include #include #include -#include +#include #include "pl_editor_frame.h" #include "pl_editor_id.h" diff --git a/pcbnew/autorouter/ar_autoplacer.cpp b/pcbnew/autorouter/ar_autoplacer.cpp index d86917d378..9c8b9fcbb9 100644 --- a/pcbnew/autorouter/ar_autoplacer.cpp +++ b/pcbnew/autorouter/ar_autoplacer.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include "ar_autoplacer.h" #include "ar_matrix.h" diff --git a/pcbnew/autorouter/autoplace_tool.cpp b/pcbnew/autorouter/autoplace_tool.cpp index 55d86cf418..6dc07338d5 100644 --- a/pcbnew/autorouter/autoplace_tool.cpp +++ b/pcbnew/autorouter/autoplace_tool.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "ar_autoplacer.h" #include "autoplace_tool.h" diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp index f0d80e79da..5325ef51db 100644 --- a/pcbnew/connectivity/connectivity_algo.cpp +++ b/pcbnew/connectivity/connectivity_algo.cpp @@ -25,7 +25,7 @@ */ #include -#include +#include #include #include diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index f4b159646e..aaf822cc6d 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include "dialog_board_setup.h" diff --git a/pcbnew/dialogs/dialog_drc.cpp b/pcbnew/dialogs/dialog_drc.cpp index ed781982de..316bcc21f3 100644 --- a/pcbnew/dialogs/dialog_drc.cpp +++ b/pcbnew/dialogs/dialog_drc.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ DIALOG_DRC::DIALOG_DRC( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent ) : DIALOG_DRC_BASE( aParent ), - PROGRESS_REPORTER( 1 ), + PROGRESS_REPORTER_BASE( 1 ), m_running( false ), m_cancelled( false ), m_drcRun( false ), @@ -167,7 +167,7 @@ bool DIALOG_DRC::updateUI() void DIALOG_DRC::AdvancePhase( const wxString& aMessage ) { - PROGRESS_REPORTER::AdvancePhase( aMessage ); + PROGRESS_REPORTER_BASE::AdvancePhase( aMessage ); SetCurrentProgress( 0.0 ); m_messages->Report( aMessage ); diff --git a/pcbnew/dialogs/dialog_drc.h b/pcbnew/dialogs/dialog_drc.h index 729716e888..75f09fb843 100644 --- a/pcbnew/dialogs/dialog_drc.h +++ b/pcbnew/dialogs/dialog_drc.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include class BOARD_DESIGN_SETTINGS; @@ -41,7 +41,7 @@ class BOARD_DESIGN_SETTINGS; #define DIALOG_DRC_WINDOW_NAME "DialogDrcWindowName" class -DIALOG_DRC: public DIALOG_DRC_BASE, PROGRESS_REPORTER +DIALOG_DRC: public DIALOG_DRC_BASE, PROGRESS_REPORTER_BASE { public: /// Constructors diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index c029c727bb..d219838f89 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -24,7 +24,7 @@ */ #include -#include +#include #include #include #include diff --git a/pcbnew/edit_zone_helpers.cpp b/pcbnew/edit_zone_helpers.cpp index c197356309..ab9c472cc8 100644 --- a/pcbnew/edit_zone_helpers.cpp +++ b/pcbnew/edit_zone_helpers.cpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include @@ -136,7 +136,10 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE* aZone ) ZONE_FILLER filler( GetBoard(), &commit ); wxString title = wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() ); - filler.InstallNewProgressReporter( this, title, 4 ); + + std::unique_ptr reporter; + reporter = std::make_unique( this, title, 4 ); + filler.SetProgressReporter( reporter.get() ); if( !filler.Fill( zones_to_refill ) ) { diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 20d701ebae..a88141d8dd 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index e77d59daac..4a6b2ec89e 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -75,7 +75,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index e4e6b317ce..f3e9fef433 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/load_select_footprint.cpp b/pcbnew/load_select_footprint.cpp index 10868cfc73..d893c1d729 100644 --- a/pcbnew/load_select_footprint.cpp +++ b/pcbnew/load_select_footprint.cpp @@ -47,7 +47,7 @@ using namespace std::placeholders; #include #include #include -#include +#include #include #include "fp_tree_model_adapter.h" diff --git a/pcbnew/plugins/altium/altium_pcb.cpp b/pcbnew/plugins/altium/altium_pcb.cpp index c9c7045d7b..69961b54bc 100644 --- a/pcbnew/plugins/altium/altium_pcb.cpp +++ b/pcbnew/plugins/altium/altium_pcb.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include void ParseAltiumPcb( BOARD* aBoard, const wxString& aFileName, PROGRESS_REPORTER* aProgressReporter, diff --git a/pcbnew/plugins/eagle/eagle_plugin.cpp b/pcbnew/plugins/eagle/eagle_plugin.cpp index 4eda9535be..5b7693a0d7 100644 --- a/pcbnew/plugins/eagle/eagle_plugin.cpp +++ b/pcbnew/plugins/eagle/eagle_plugin.cpp @@ -67,7 +67,7 @@ Load() TODO's #include #include #include // for KiROUND -#include +#include #include #include diff --git a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp index d6e425acef..98ec115ab5 100644 --- a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp +++ b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp @@ -29,7 +29,7 @@ #include "fabmaster_plugin.h" #include -#include +#include #include #include diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.cpp b/pcbnew/plugins/fabmaster/import_fabmaster.cpp index a4695a8ea8..0507e1b968 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.cpp +++ b/pcbnew/plugins/fabmaster/import_fabmaster.cpp @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include #include diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index 03c8e275be..946f895a8c 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index e35132fa21..a112f708ca 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -57,7 +57,7 @@ #include // KiROUND, Clamp #include #include -#include +#include using namespace PCB_KEYS_T; diff --git a/pcbnew/plugins/legacy/legacy_plugin.cpp b/pcbnew/plugins/legacy/legacy_plugin.cpp index 0ad9a8f86a..5093bbcc03 100644 --- a/pcbnew/plugins/legacy/legacy_plugin.cpp +++ b/pcbnew/plugins/legacy/legacy_plugin.cpp @@ -88,7 +88,7 @@ #include #include #include // for KiROUND -#include +#include typedef LEGACY_PLUGIN::BIU BIU; diff --git a/pcbnew/tools/drc_tool.cpp b/pcbnew/tools/drc_tool.cpp index ce083b09f5..b6b46a86f6 100644 --- a/pcbnew/tools/drc_tool.cpp +++ b/pcbnew/tools/drc_tool.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 948e944ade..d6c1020d76 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include #include diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index b880c7e296..09e900f3e5 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -45,7 +45,7 @@ using namespace std::placeholders; #include #include #include -#include +#include // Few constants to avoid using bare numbers for point indices diff --git a/pcbnew/tools/zone_filler_tool.cpp b/pcbnew/tools/zone_filler_tool.cpp index 3be0e99d64..8e6ef6fe4e 100644 --- a/pcbnew/tools/zone_filler_tool.cpp +++ b/pcbnew/tools/zone_filler_tool.cpp @@ -28,8 +28,9 @@ #include #include #include -#include +#include #include +#include #include #include #include @@ -67,14 +68,19 @@ void ZONE_FILLER_TOOL::CheckAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aRep for( ZONE* zone : board()->Zones() ) toFill.push_back(zone); - BOARD_COMMIT commit( this ); - - ZONE_FILLER filler( frame()->GetBoard(), &commit ); + BOARD_COMMIT commit( this ); + std::unique_ptr reporter; + ZONE_FILLER filler( frame()->GetBoard(), &commit ); if( aReporter ) + { filler.SetProgressReporter( aReporter ); + } else - filler.InstallNewProgressReporter( aCaller, _( "Checking Zones" ), 4 ); + { + reporter = std::make_unique( aCaller, _( "Checking Zones" ), 4 ); + filler.SetProgressReporter( reporter.get() ); + } std::lock_guard lock( board()->GetConnectivity()->GetLock() ); @@ -103,7 +109,6 @@ void ZONE_FILLER_TOOL::singleShotRefocus( wxIdleEvent& ) void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aReporter ) { PCB_EDIT_FRAME* frame = getEditFrame(); - BOARD_COMMIT commit( this ); std::vector toFill; if( m_fillInProgress ) @@ -116,7 +121,9 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aRepo board()->IncrementTimeStamp(); // Clear caches - ZONE_FILLER filler( board(), &commit ); + BOARD_COMMIT commit( this ); + std::unique_ptr reporter; + ZONE_FILLER filler( board(), &commit ); if( !board()->GetDesignSettings().m_DRCEngine->RulesValid() ) { @@ -139,9 +146,14 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aRepo } if( aReporter ) + { filler.SetProgressReporter( aReporter ); + } else - filler.InstallNewProgressReporter( aCaller, _( "Fill All Zones" ), 3 ); + { + reporter = std::make_unique( aCaller, _( "Fill All Zones" ), 3 ); + filler.SetProgressReporter( reporter.get() ); + } std::lock_guard lock( board()->GetConnectivity()->GetLock() ); @@ -179,8 +191,6 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) std::vector toFill; - BOARD_COMMIT commit( this ); - if( ZONE* passedZone = aEvent.Parameter() ) { toFill.push_back( passedZone ); @@ -194,8 +204,12 @@ int ZONE_FILLER_TOOL::ZoneFill( const TOOL_EVENT& aEvent ) } } - ZONE_FILLER filler( board(), &commit ); - filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 ); + BOARD_COMMIT commit( this ); + std::unique_ptr reporter; + ZONE_FILLER filler( board(), &commit ); + + reporter = std::make_unique( frame(), _( "Fill Zone" ), 4 ); + filler.SetProgressReporter( reporter.get() ); std::lock_guard lock( board()->GetConnectivity()->GetLock() ); diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index 44cfc07d55..a09925da56 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include #include @@ -69,14 +69,6 @@ ZONE_FILLER::~ZONE_FILLER() } -void ZONE_FILLER::InstallNewProgressReporter( wxWindow* aParent, const wxString& aTitle, - int aNumPhases ) -{ - m_uniqueReporter = std::make_unique( aParent, aTitle, aNumPhases ); - SetProgressReporter( m_uniqueReporter.get() ); -} - - void ZONE_FILLER::SetProgressReporter( PROGRESS_REPORTER* aReporter ) { m_progressReporter = aReporter; diff --git a/pcbnew/zone_filler.h b/pcbnew/zone_filler.h index 174396e326..3683126e0f 100644 --- a/pcbnew/zone_filler.h +++ b/pcbnew/zone_filler.h @@ -23,13 +23,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef __ZONE_FILLER_H -#define __ZONE_FILLER_H +#ifndef ZONE_FILLER_H +#define ZONE_FILLER_H #include #include -class WX_PROGRESS_REPORTER; +class PROGRESS_REPORTER; class BOARD; class COMMIT; class SHAPE_POLY_SET; @@ -43,7 +43,6 @@ public: ~ZONE_FILLER(); void SetProgressReporter( PROGRESS_REPORTER* aReporter ); - void InstallNewProgressReporter( wxWindow* aParent, const wxString& aTitle, int aNumPhases ); /** * Fills the given list of zones. Invalidates connectivity - it is up to the caller to obtain @@ -127,8 +126,6 @@ private: COMMIT* m_commit; PROGRESS_REPORTER* m_progressReporter; - std::unique_ptr m_uniqueReporter; - int m_maxError; int m_worstClearance; diff --git a/qa/drc_proto/drc_proto.cpp b/qa/drc_proto/drc_proto.cpp index 0db2eff6c6..2e9ff08a98 100644 --- a/qa/drc_proto/drc_proto.cpp +++ b/qa/drc_proto/drc_proto.cpp @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include diff --git a/qa/drc_proto/drc_proto.h b/qa/drc_proto/drc_proto.h index fe9701193c..67b30d75d2 100644 --- a/qa/drc_proto/drc_proto.h +++ b/qa/drc_proto/drc_proto.h @@ -26,7 +26,7 @@ #include -#include +#include #include #include #include @@ -94,11 +94,11 @@ private: std::mutex m_lock; }; -class CONSOLE_PROGRESS_REPORTER : public PROGRESS_REPORTER +class CONSOLE_PROGRESS_REPORTER : public PROGRESS_REPORTER_BASE { public: CONSOLE_PROGRESS_REPORTER( CONSOLE_LOG* log ) : - PROGRESS_REPORTER( 0 ), + PROGRESS_REPORTER_BASE( 0 ), m_log( log ) {}; ~CONSOLE_PROGRESS_REPORTER() {};