From 05a120f09f104400303c867d8d412ea46df7b8fe Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 20 Sep 2017 10:53:58 +0200 Subject: [PATCH] Unified {Load,Save]CanvasTypeSetting in EDA_DRAW_FRAME --- common/draw_frame.cpp | 43 ++++++++++++++++++++++++++-- gerbview/events_called_functions.cpp | 2 +- gerbview/gerbview_frame.cpp | 42 +-------------------------- gerbview/gerbview_frame.h | 16 ----------- include/draw_frame.h | 14 +++++++++ include/wxBasePcbFrame.h | 13 --------- pcbnew/basepcbframe.cpp | 40 +------------------------- pcbnew/pcbframe.cpp | 2 +- 8 files changed, 59 insertions(+), 113 deletions(-) diff --git a/common/draw_frame.cpp b/common/draw_frame.cpp index 5a8bdc175a..d559a8423a 100644 --- a/common/draw_frame.cpp +++ b/common/draw_frame.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,6 @@ #include #include #include -#include #include #include #include @@ -76,6 +74,9 @@ static const wxString LastGridSizeIdKeyword( wxT( "_LastGridSize" ) ); /// GAL Display Options static const wxString GalDisplayOptionsKeyword( wxT( "GalDisplayOptions" ) ); +const wxChar EDA_DRAW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" ); + + ///@} /** @@ -1169,6 +1170,44 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable ) m_galCanvasActive = aEnable; } + +EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::loadCanvasTypeSetting() const +{ + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; + wxConfigBase* cfg = Kiface().KifaceSettings(); + + if( cfg ) + canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY, + EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ); + + if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE + || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) + { + assert( false ); + canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; + } + + return canvasType; +} + + +bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) +{ + if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE + || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) + { + assert( false ); + return false; + } + + wxConfigBase* cfg = Kiface().KifaceSettings(); + + if( cfg ) + return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType ); + + return false; +} + //-----< BASE_SCREEN API moved here >-------------------------------------------- wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp index d8c4ffaee0..f7a9cb21b1 100644 --- a/gerbview/events_called_functions.cpp +++ b/gerbview/events_called_functions.cpp @@ -563,7 +563,7 @@ void GERBVIEW_FRAME::SwitchCanvas( wxCommandEvent& aEvent ) break; } - SaveCanvasTypeSetting( canvasType ); + saveCanvasTypeSetting( canvasType ); UseGalCanvas( use_gal ); wxUpdateUIEvent e; OnUpdateSwitchCanvas( e ); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index d3b86032f3..c28893b93a 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -64,8 +64,6 @@ static const wxString cfgShowDCodes( wxT( "ShowDCodesOpt" ) ); static const wxString cfgShowNegativeObjects( wxT( "ShowNegativeObjectsOpt" ) ); static const wxString cfgShowBorderAndTitleBlock( wxT( "ShowBorderAndTitleBlock" ) ); -const wxChar GERBVIEW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" ); - // Colors for layers and items COLORS_DESIGN_SETTINGS g_ColorsSettings( FRAME_GERBER ); @@ -211,7 +209,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ): Zoom_Automatique( false ); // Gives a default zoom value UpdateTitleAndInfo(); - EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = LoadCanvasTypeSetting(); + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = loadCanvasTypeSetting(); if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ) { @@ -1095,44 +1093,6 @@ void GERBVIEW_FRAME::UseGalCanvas( bool aEnable ) } -EDA_DRAW_PANEL_GAL::GAL_TYPE GERBVIEW_FRAME::LoadCanvasTypeSetting() const -{ - EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; - wxConfigBase* cfg = Kiface().KifaceSettings(); - - if( cfg ) - canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY, - EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ); - - if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE - || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) - { - assert( false ); - canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; - } - - return canvasType; -} - - -bool GERBVIEW_FRAME::SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) -{ - if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE - || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) - { - assert( false ); - return false; - } - - wxConfigBase* cfg = Kiface().KifaceSettings(); - - if( cfg ) - return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType ); - - return false; -} - - void GERBVIEW_FRAME::setupTools() { // Create the manager and dispatcher & route draw panel events to the dispatcher diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 34394c57a6..d35ea8f1ec 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -41,7 +41,6 @@ #include #include #include -#include #include extern COLORS_DESIGN_SETTINGS g_ColorsSettings; @@ -749,21 +748,6 @@ public: */ void OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent ); - /** - * Function LoadCanvasTypeSetting() - * Returns the canvas type stored in the application settings. - */ - EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting() const; - - /** - * Function SaveCanvasTypeSetting() - * Stores the canvas type in the application settings. - */ - bool SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ); - - ///> Key in KifaceSettings to store the canvas type. - static const wxChar CANVAS_TYPE_KEY[]; - DECLARE_EVENT_TABLE() }; diff --git a/include/draw_frame.h b/include/draw_frame.h index f7fb6ed023..6c17ffd30e 100644 --- a/include/draw_frame.h +++ b/include/draw_frame.h @@ -31,6 +31,7 @@ #include #include #include +#include class wxSingleInstanceChecker; class EDA_HOTKEY; @@ -170,6 +171,19 @@ protected: */ bool isBusy() const; + /** + * Returns the canvas type stored in the application settings. + */ + EDA_DRAW_PANEL_GAL::GAL_TYPE loadCanvasTypeSetting() const; + + /** + * Stores the canvas type in the application settings. + */ + bool saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ); + + ///> Key in KifaceSettings to store the canvas type. + static const wxChar CANVAS_TYPE_KEY[]; + public: EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h index 3bd799dfb9..a3695ae961 100644 --- a/include/wxBasePcbFrame.h +++ b/include/wxBasePcbFrame.h @@ -41,7 +41,6 @@ #include #include #include -#include #include @@ -694,18 +693,6 @@ public: */ void OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent ); - /** - * Function LoadCanvasTypeSetting() - * Returns the canvas type stored in the application settings. - */ - EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting() const; - - /** - * Function SaveCanvasTypeSetting() - * Stores the canvas type in the application settings. - */ - bool SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ); - PCB_GENERAL_SETTINGS& Settings() { return m_configSettings; diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 7c0cb0304f..2cff66e00c 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -958,7 +958,7 @@ void PCB_BASE_FRAME::SwitchCanvas( wxCommandEvent& aEvent ) break; } - SaveCanvasTypeSetting( canvasType ); + saveCanvasTypeSetting( canvasType ); UseGalCanvas( use_gal ); } @@ -1001,44 +1001,6 @@ void PCB_BASE_FRAME::UseGalCanvas( bool aEnable ) } -EDA_DRAW_PANEL_GAL::GAL_TYPE PCB_BASE_FRAME::LoadCanvasTypeSetting() const -{ - EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; - wxConfigBase* cfg = Kiface().KifaceSettings(); - - if( cfg ) - canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY, - EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ); - - if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE - || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) - { - assert( false ); - canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; - } - - return canvasType; -} - - -bool PCB_BASE_FRAME::SaveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) -{ - if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE - || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST ) - { - assert( false ); - return false; - } - - wxConfigBase* cfg = Kiface().KifaceSettings(); - - if( cfg ) - return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType ); - - return false; -} - - void PCB_BASE_FRAME::OnUpdateSwitchCanvas( wxUpdateUIEvent& aEvent ) { wxMenuBar* menuBar = GetMenuBar(); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8f6a557699..c0b7f0fb14 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -468,7 +468,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : Zoom_Automatique( false ); - EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = LoadCanvasTypeSetting(); + EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = loadCanvasTypeSetting(); if( canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ) {