From cfa99168369b881e3a0a024decfc8896bae86745 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 23 Apr 2018 11:17:28 +0200 Subject: [PATCH] Prevent issuing a print command before the previous one is finished Fixes: lp:1765965 * https://bugs.launchpad.net/kicad/+bug/1765965 --- .../dialogs/dialog_print_using_printer.cpp | 6 ++- .../dialogs/dialog_print_using_printer.cpp | 6 +++ include/enabler.h | 54 +++++++++++++++++++ pcbnew/dialogs/dialog_print_for_modedit.cpp | 5 ++ pcbnew/dialogs/dialog_print_using_printer.cpp | 4 ++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 include/enabler.h diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index 7ddad85554..ec7ccd3dfe 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -38,7 +38,7 @@ #include #include - +#include /** @@ -300,6 +300,10 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) wxPrinter printer( &printDialogData ); SCH_PRINTOUT printout( parent, _( "Print Schematic" ) ); + // Disable 'Print' button to prevent issuing another print + // command before the previous one is finished (causes problems on Windows) + ENABLER printBtnDisable( *m_buttonPrint, false ); + if( !printer.Print( this, &printout, true ) ) { if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) diff --git a/gerbview/dialogs/dialog_print_using_printer.cpp b/gerbview/dialogs/dialog_print_using_printer.cpp index 0109cf07eb..cd3a025bed 100644 --- a/gerbview/dialogs/dialog_print_using_printer.cpp +++ b/gerbview/dialogs/dialog_print_using_printer.cpp @@ -37,6 +37,8 @@ #include #include +#include + ///@{ /// \ingroup config @@ -403,6 +405,10 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) wxString title = _( "Print" ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_Parent, title ); + // Disable 'Print' button to prevent issuing another print + // command before the previous one is finished (causes problems on Windows) + ENABLER printBtnDisable( *m_buttonPrint, false ); + if( !printer.Print( this, &printout, true ) ) { if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) diff --git a/include/enabler.h b/include/enabler.h new file mode 100644 index 0000000000..5d022d27a5 --- /dev/null +++ b/include/enabler.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2018 CERN + * Author: Maciej Suminski + * + * 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 3 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, see . + */ + +#ifndef ENABLER_H +#define ENABLER_H + +#include + +/** + * Simple class to automatically enable/disable widgets. + * + * As long as an ENABLER object exists, the handled widget will be kept in the requested state. + */ +class ENABLER +{ +public: + /** + * Constructor. + * + * @param aObject is the object to be temporarily enabled or disabled. + * @param aState is the requested temporary state (true for enabled, false for disabled). + */ + ENABLER( wxWindow& aObject, bool aState ) + : m_object( aObject ), m_state( aState ) + { + m_object.Enable( m_state ); + } + + ~ENABLER() + { + m_object.Enable( !m_state ); + } + +private: + wxWindow& m_object; + bool m_state; +}; + +#endif /* ENABLER_H */ diff --git a/pcbnew/dialogs/dialog_print_for_modedit.cpp b/pcbnew/dialogs/dialog_print_for_modedit.cpp index 6de6eeae8d..a349f7992a 100644 --- a/pcbnew/dialogs/dialog_print_for_modedit.cpp +++ b/pcbnew/dialogs/dialog_print_for_modedit.cpp @@ -35,6 +35,7 @@ #include #include +#include static double s_scaleList[] = { 0, 0.5, 0.7, 1.0, 1.4, 2.0, 3.0, 4.0, 8.0, 16.0 }; @@ -234,6 +235,10 @@ void DIALOG_PRINT_FOR_MODEDIT::OnPrintButtonClick( wxCommandEvent& event ) BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, _( "Print Footprint" ) ); + // Disable 'Print' button to prevent issuing another print + // command before the previous one is finished (causes problems on Windows) + ENABLER printBtnDisable( *m_buttonPrint, false ); + if( !printer.Print( this, &printout, true ) ) { if( wxPrinter::GetLastError() == wxPRINTER_ERROR ) diff --git a/pcbnew/dialogs/dialog_print_using_printer.cpp b/pcbnew/dialogs/dialog_print_using_printer.cpp index f05464b9eb..1410fb5074 100644 --- a/pcbnew/dialogs/dialog_print_using_printer.cpp +++ b/pcbnew/dialogs/dialog_print_using_printer.cpp @@ -39,6 +39,7 @@ #include #include +#include #define PEN_WIDTH_MAX_VALUE ( KiROUND( 5 * IU_PER_MM ) ) @@ -494,6 +495,9 @@ void DIALOG_PRINT_USING_PRINTER::OnPrintButtonClick( wxCommandEvent& event ) wxString title = _( "Print" ); BOARD_PRINTOUT_CONTROLLER printout( s_Parameters, m_parent, title ); + // Disable 'Print' button to prevent issuing another print + // command before the previous one is finished (causes problems on Windows) + ENABLER printBtnDisable( *m_buttonPrint, false ); if( !printer.Print( this, &printout, true ) ) {