diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 641c7bc225..a70a94e0e6 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013-2015 CERN + * Copyright (C) 2013-2016 CERN * @author Tomasz Wlostowski * @author Maciej Suminski * @@ -23,12 +23,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include -#include -#include -#include -#include +#include +#include #include #include @@ -108,11 +104,17 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_drawing = false; m_drawingEnabled = false; Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); + + m_edaFrame = dynamic_cast( aParentWindow ); + + LoadGalSettings(); } EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() { + SaveGalSettings(); + delete m_painter; delete m_viewControls; delete m_view; @@ -347,6 +349,8 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) result = false; } + SaveGalSettings(); + assert( new_gal ); delete m_gal; m_gal = new_gal; @@ -361,11 +365,49 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) m_view->SetGAL( m_gal ); m_backend = aGalType; + LoadGalSettings(); return result; } +bool EDA_DRAW_PANEL_GAL::SaveGalSettings() +{ + if( !m_edaFrame ) + return false; + + wxConfigBase* cfg = Kiface().KifaceSettings(); + wxString baseCfgName = m_edaFrame->GetName(); + + if( !cfg ) + return false; + + if( !cfg->Write( baseCfgName + GRID_STYLE_CFG, (long) GetGAL()->GetGridStyle() ) ) + return false; + + return true; +} + + +bool EDA_DRAW_PANEL_GAL::LoadGalSettings() +{ + if( !m_edaFrame ) + return false; + + wxConfigBase* cfg = Kiface().KifaceSettings(); + wxString baseCfgName = m_edaFrame->GetName(); + + if( !cfg ) + return false; + + long gridStyle; + cfg->Read( baseCfgName + GRID_STYLE_CFG, &gridStyle, (long) KIGFX::GRID_STYLE::GRID_STYLE_DOTS ); + GetGAL()->SetGridStyle( (KIGFX::GRID_STYLE) gridStyle ); + + return true; +} + + void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent ) { if( m_lostFocus ) @@ -419,3 +461,5 @@ void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent ) wxPaintEvent redrawEvent; wxPostEvent( this, redrawEvent ); } + +const wxChar EDA_DRAW_PANEL_GAL::GRID_STYLE_CFG[] = wxT( "GridStyle" ); diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index cc52294132..31c4c54aec 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -1,8 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2013-2014 CERN + * Copyright (C) 2013-2016 CERN * @author Tomasz Wlostowski + * @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 @@ -37,6 +38,7 @@ #include class BOARD; +class EDA_DRAW_FRAME; class TOOL_DISPATCHER; namespace KIGFX @@ -165,6 +167,27 @@ public: */ double GetLegacyZoom() const; + /** + * Function GetParentEDAFrame() + * Returns parent EDA_DRAW_FRAME, if available or NULL otherwise. + */ + EDA_DRAW_FRAME* GetParentEDAFrame() const + { + return m_edaFrame; + } + + /** + * Function SaveGalSettings() + * Stores GAL related settings in the configuration storage. + */ + virtual bool SaveGalSettings(); + + /** + * Function LoadGalSettings() + * Loads GAL related settings from the configuration storage. + */ + virtual bool LoadGalSettings(); + protected: void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onSize( wxSizeEvent& aEvent ); @@ -178,6 +201,9 @@ protected: /// Pointer to the parent window wxWindow* m_parent; + /// Parent EDA_DRAW_FRAME (if available) + EDA_DRAW_FRAME* m_edaFrame; + /// Last timestamp when the panel was refreshed wxLongLong m_lastRefresh; @@ -214,6 +240,9 @@ protected: /// Flag to indicate that focus should be regained on the next mouse event. It is a workaround /// for cases when the panel loses keyboard focus, so it does not react to hotkeys anymore. bool m_lostFocus; + + /// Grid style setting string + static const wxChar GRID_STYLE_CFG[]; }; #endif