From 250d958ebb2b9c7409110948275c488383c1cde7 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 25 May 2018 18:33:00 +0200 Subject: [PATCH] Plot dialog: fix broken dialog management. Previously, the dialog was created only once, with the current board setup and the current units selection. Therefore, after changes in board or units, the dialog was really broken. Now, the dialog is recreated when the plot command is run. --- pcbnew/dialogs/dialog_plot.cpp | 62 ++++++++++++++--------------- pcbnew/dialogs/dialog_plot.h | 4 ++ pcbnew/dialogs/dialog_plot_base.cpp | 6 ++- pcbnew/dialogs/dialog_plot_base.fbp | 1 - pcbnew/dialogs/dialog_plot_base.h | 6 ++- pcbnew/pcb_edit_frame.cpp | 15 ++++--- pcbnew/pcb_edit_frame.h | 2 - 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/pcbnew/dialogs/dialog_plot.cpp b/pcbnew/dialogs/dialog_plot.cpp index 8f5734d218..9ad3169a14 100644 --- a/pcbnew/dialogs/dialog_plot.cpp +++ b/pcbnew/dialogs/dialog_plot.cpp @@ -5,7 +5,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-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 @@ -48,6 +48,8 @@ DIALOG_PLOT::DIALOG_PLOT( PCB_EDIT_FRAME* aParent ) : DIALOG_PLOT_BASE( aParent ), m_parent( aParent ) { + SetName( DLG_WINDOW_NAME ); + m_userUnits = g_UserUnit; m_config = Kiface().KifaceSettings(); m_plotOpts = aParent->GetPlotSettings(); init_Dialog(); @@ -118,23 +120,24 @@ void DIALOG_PLOT::init_Dialog() break; } - msg = StringFromValue( g_UserUnit, board->GetDesignSettings().m_SolderMaskMargin, true ); + msg = StringFromValue( m_userUnits, board->GetDesignSettings().m_SolderMaskMargin, true ); m_SolderMaskMarginCurrValue->SetLabel( msg ); - msg = StringFromValue( g_UserUnit, board->GetDesignSettings().m_SolderMaskMinWidth, true ); + msg = StringFromValue( m_userUnits, board->GetDesignSettings().m_SolderMaskMinWidth, true ); m_SolderMaskMinWidthCurrValue->SetLabel( msg ); - // Set units and value for HPGL pen size (this param in in mils). - AddUnitSymbol( *m_textPenSize, g_UserUnit ); - msg = StringFromValue( g_UserUnit, - m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS ); - m_HPGLPenSizeOpt->AppendText( msg ); + // Set units and value for HPGL pen size (this param is in mils). + AddUnitSymbol( *m_textPenSize, m_userUnits ); - AddUnitSymbol( *m_textDefaultPenSize, g_UserUnit ); - msg = StringFromValue( g_UserUnit, m_plotOpts.GetLineWidth() ); - m_linesWidth->AppendText( msg ); + msg = StringFromValue( m_userUnits, + m_plotOpts.GetHPGLPenDiameter() * IU_PER_MILS ); + m_HPGLPenSizeOpt->SetValue( msg ); + + AddUnitSymbol( *m_textDefaultPenSize, m_userUnits ); + msg = StringFromValue( m_userUnits, m_plotOpts.GetLineWidth() ); + m_linesWidth->SetValue( msg ); // Set units for PS global width correction. - AddUnitSymbol( *m_textPSFineAdjustWidth, g_UserUnit ); + AddUnitSymbol( *m_textPSFineAdjustWidth, m_userUnits ); // Test for a reasonable scale value. Set to 1 if problem if( m_XScaleAdjust < PLOT_MIN_SCALE || m_YScaleAdjust < PLOT_MIN_SCALE @@ -145,14 +148,14 @@ void DIALOG_PLOT::init_Dialog() m_fineAdjustXscaleOpt->AppendText( msg ); msg.Printf( wxT( "%f" ), m_YScaleAdjust ); - m_fineAdjustYscaleOpt->AppendText( msg ); + m_fineAdjustYscaleOpt->SetValue( msg ); // Test for a reasonable PS width correction value. Set to 0 if problem. if( m_PSWidthAdjust < m_widthAdjustMinValue || m_PSWidthAdjust > m_widthAdjustMaxValue ) m_PSWidthAdjust = 0.; - msg.Printf( wxT( "%f" ), To_User_Unit( g_UserUnit, m_PSWidthAdjust ) ); - m_PSFineAdjustWidthOpt->AppendText( msg ); + msg.Printf( wxT( "%f" ), To_User_Unit( m_userUnits, m_PSWidthAdjust ) ); + m_PSFineAdjustWidthOpt->SetValue( msg ); m_plotPSNegativeOpt->SetValue( m_plotOpts.GetNegative() ); m_forcePSA4OutputOpt->SetValue( m_plotOpts.GetA4Output() ); @@ -249,21 +252,18 @@ void DIALOG_PLOT::reInitDialog() m_useAuxOriginCheckBox->SetValue( m_plotOpts.GetUseAuxOrigin() ); } + void DIALOG_PLOT::OnQuit( wxCommandEvent& event ) { - // Put a wxID_CANCEL event through the dialog infrastrucutre - event.SetId( wxID_CANCEL ); event.Skip(); + + Destroy(); } void DIALOG_PLOT::OnClose( wxCloseEvent& event ) { - applyPlotSettings(); - - // Put an wxID_OK event through the dialog infrastrucutre - event.SetId( wxID_OK ); - event.Skip(); + Destroy(); } @@ -632,11 +632,11 @@ void DIALOG_PLOT::applyPlotSettings() // read HPLG pen size (this param is stored in mils) wxString msg = m_HPGLPenSizeOpt->GetValue(); - int tmp = ValueFromString( g_UserUnit, msg ) / IU_PER_MILS; + int tmp = ValueFromString( m_userUnits, msg ) / IU_PER_MILS; if( !tempOptions.SetHPGLPenDiameter( tmp ) ) { - msg = StringFromValue( g_UserUnit, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS ); + msg = StringFromValue( m_userUnits, tempOptions.GetHPGLPenDiameter() * IU_PER_MILS ); m_HPGLPenSizeOpt->SetValue( msg ); msg.Printf( _( "HPGL pen size constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); @@ -644,11 +644,11 @@ void DIALOG_PLOT::applyPlotSettings() // Default linewidth msg = m_linesWidth->GetValue(); - tmp = ValueFromString( g_UserUnit, msg ); + tmp = ValueFromString( m_userUnits, msg ); if( !tempOptions.SetLineWidth( tmp ) ) { - msg = StringFromValue( g_UserUnit, tempOptions.GetLineWidth() ); + msg = StringFromValue( m_userUnits, tempOptions.GetLineWidth() ); m_linesWidth->SetValue( msg ); msg.Printf( _( "Default line width constrained." ) ); reporter.Report( msg, REPORTER::RPT_INFO ); @@ -687,18 +687,18 @@ void DIALOG_PLOT::applyPlotSettings() // PS Width correction msg = m_PSFineAdjustWidthOpt->GetValue(); - int itmp = ValueFromString( g_UserUnit, msg ); + int itmp = ValueFromString( m_userUnits, msg ); if( !setInt( &m_PSWidthAdjust, itmp, m_widthAdjustMinValue, m_widthAdjustMaxValue ) ) { - msg = StringFromValue( g_UserUnit, m_PSWidthAdjust ); + msg = StringFromValue( m_userUnits, m_PSWidthAdjust ); m_PSFineAdjustWidthOpt->SetValue( msg ); msg.Printf( _( "Width correction constrained. " "The reasonable width correction value must be in a range of " " [%+f; %+f] (%s) for current design rules." ), - To_User_Unit( g_UserUnit, m_widthAdjustMinValue ), - To_User_Unit( g_UserUnit, m_widthAdjustMaxValue ), - ( g_UserUnit == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) ); + To_User_Unit( m_userUnits, m_widthAdjustMinValue ), + To_User_Unit( m_userUnits, m_widthAdjustMaxValue ), + ( m_userUnits == INCHES ) ? wxT( "\"" ) : wxT( "mm" ) ); reporter.Report( msg, REPORTER::RPT_WARNING ); } diff --git a/pcbnew/dialogs/dialog_plot.h b/pcbnew/dialogs/dialog_plot.h index 7a695e5c7b..6965be2769 100644 --- a/pcbnew/dialogs/dialog_plot.h +++ b/pcbnew/dialogs/dialog_plot.h @@ -29,6 +29,9 @@ #include #include +// the plot dialog window name, used by wxWidgets +#define DLG_WINDOW_NAME "plot_dialog-window" + /** * Class DIALOG_PLOT is the dialog to set the plot options, and create plot files * in various formats. @@ -40,6 +43,7 @@ public: private: PCB_EDIT_FRAME* m_parent; + EDA_UNITS_T m_userUnits; // units used when creating the dialog wxConfigBase* m_config; LSEQ m_layerList; // List to hold CheckListBox layer numbers double m_XScaleAdjust; // X scale factor adjust to compensate diff --git a/pcbnew/dialogs/dialog_plot_base.cpp b/pcbnew/dialogs/dialog_plot_base.cpp index 9e02dd567b..b93482ec45 100644 --- a/pcbnew/dialogs/dialog_plot_base.cpp +++ b/pcbnew/dialogs/dialog_plot_base.cpp @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 20 2018) +// C++ code generated with wxFormBuilder (version Aug 4 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO *NOT* EDIT THIS FILE! +// PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #include "wx_html_report_panel.h" @@ -429,6 +429,7 @@ DIALOG_PLOT_BASE::DIALOG_PLOT_BASE( wxWindow* parent, wxWindowID id, const wxStr this->Centre( wxBOTH ); // Connect Events + this->Connect( wxEVT_ACTIVATE, wxActivateEventHandler( DIALOG_PLOT_BASE::onActivate ) ); this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_PLOT_BASE::OnClose ) ); this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_PLOT_BASE::OnInitDialog ) ); this->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( DIALOG_PLOT_BASE::OnRightClick ) ); @@ -452,6 +453,7 @@ DIALOG_PLOT_BASE::DIALOG_PLOT_BASE( wxWindow* parent, wxWindowID id, const wxStr DIALOG_PLOT_BASE::~DIALOG_PLOT_BASE() { // Disconnect Events + this->Disconnect( wxEVT_ACTIVATE, wxActivateEventHandler( DIALOG_PLOT_BASE::onActivate ) ); this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_PLOT_BASE::OnClose ) ); this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_PLOT_BASE::OnInitDialog ) ); this->Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( DIALOG_PLOT_BASE::OnRightClick ) ); diff --git a/pcbnew/dialogs/dialog_plot_base.fbp b/pcbnew/dialogs/dialog_plot_base.fbp index 8111446f64..10a646879e 100644 --- a/pcbnew/dialogs/dialog_plot_base.fbp +++ b/pcbnew/dialogs/dialog_plot_base.fbp @@ -14,7 +14,6 @@ dialog_plot_base 1000 none - 1 Dialog_Plot_base diff --git a/pcbnew/dialogs/dialog_plot_base.h b/pcbnew/dialogs/dialog_plot_base.h index 5a6ce1925d..e4e9c79fcd 100644 --- a/pcbnew/dialogs/dialog_plot_base.h +++ b/pcbnew/dialogs/dialog_plot_base.h @@ -1,8 +1,8 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Apr 20 2018) +// C++ code generated with wxFormBuilder (version Aug 4 2017) // http://www.wxformbuilder.org/ // -// PLEASE DO *NOT* EDIT THIS FILE! +// PLEASE DO "NOT" EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// #ifndef __DIALOG_PLOT_BASE_H__ @@ -11,6 +11,7 @@ #include #include #include +class DIALOG_SHIM; class WX_HTML_REPORT_PANEL; #include "dialog_shim.h" @@ -122,6 +123,7 @@ class DIALOG_PLOT_BASE : public DIALOG_SHIM wxMenu* m_popMenu; // Virtual event handlers, overide them in your derived class + virtual void onActivate( wxActivateEvent& event ) { event.Skip(); } virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnInitDialog( wxInitDialogEvent& event ) { event.Skip(); } virtual void OnRightClick( wxMouseEvent& event ) { event.Skip(); } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 95c878d3d6..0a51319f7d 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2013 Wayne Stambaugh * Copyright (C) 2013-2018 KiCad Developers, see AUTHORS.txt for contributors. @@ -352,7 +352,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas() ); m_drc = new DRC( this ); // these 2 objects point to each other - m_plotDialog = nullptr; wxIcon icon; icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) ); @@ -535,7 +534,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : PCB_EDIT_FRAME::~PCB_EDIT_FRAME() { delete m_drc; - delete m_plotDialog; } @@ -1183,10 +1181,15 @@ void PCB_EDIT_FRAME::OnSwitchCanvas( wxCommandEvent& aEvent ) void PCB_EDIT_FRAME::ToPlotter( wxCommandEvent& event ) { - if( !m_plotDialog ) - m_plotDialog = new DIALOG_PLOT( this ); + // Force rebuild the dialog if currently open because the old dialog can be not up to date + // if the board (or units) has changed + wxWindow* dlg = wxWindow::FindWindowByName( DLG_WINDOW_NAME ); - m_plotDialog->Show( true ); + if( dlg ) + dlg->Destroy(); + + dlg = new DIALOG_PLOT( this ); + dlg->Show( true ); } diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index db5935465d..0e1fa87860 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -90,8 +90,6 @@ protected: DRC* m_drc; ///< the DRC controller, see drc.cpp - DIALOG_PLOT* m_plotDialog; - PARAM_CFG_ARRAY m_configParams; ///< List of Pcbnew configuration settings. wxString m_lastNetListRead; ///< Last net list read with relative path.