Store grid settings for GAL.

This commit is contained in:
Maciej Suminski 2016-05-02 16:15:25 +02:00
parent ed0b95d710
commit 09d2d5367a
2 changed files with 81 additions and 8 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -23,12 +23,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <wx/wx.h> #include <draw_frame.h>
#include <wx/frame.h> #include <kiface_i.h>
#include <wx/window.h>
#include <wx/event.h>
#include <wx/colour.h>
#include <wx/filename.h>
#include <confirm.h> #include <confirm.h>
#include <class_draw_panel_gal.h> #include <class_draw_panel_gal.h>
@ -108,11 +104,17 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_drawing = false; m_drawing = false;
m_drawingEnabled = false; m_drawingEnabled = false;
Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this ); Connect( wxEVT_TIMER, wxTimerEventHandler( EDA_DRAW_PANEL_GAL::onRefreshTimer ), NULL, this );
m_edaFrame = dynamic_cast<EDA_DRAW_FRAME*>( aParentWindow );
LoadGalSettings();
} }
EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL() EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL()
{ {
SaveGalSettings();
delete m_painter; delete m_painter;
delete m_viewControls; delete m_viewControls;
delete m_view; delete m_view;
@ -347,6 +349,8 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
result = false; result = false;
} }
SaveGalSettings();
assert( new_gal ); assert( new_gal );
delete m_gal; delete m_gal;
m_gal = new_gal; m_gal = new_gal;
@ -361,11 +365,49 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType )
m_view->SetGAL( m_gal ); m_view->SetGAL( m_gal );
m_backend = aGalType; m_backend = aGalType;
LoadGalSettings();
return result; 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 ) void EDA_DRAW_PANEL_GAL::onEvent( wxEvent& aEvent )
{ {
if( m_lostFocus ) if( m_lostFocus )
@ -419,3 +461,5 @@ void EDA_DRAW_PANEL_GAL::onRefreshTimer( wxTimerEvent& aEvent )
wxPaintEvent redrawEvent; wxPaintEvent redrawEvent;
wxPostEvent( this, redrawEvent ); wxPostEvent( this, redrawEvent );
} }
const wxChar EDA_DRAW_PANEL_GAL::GRID_STYLE_CFG[] = wxT( "GridStyle" );

View File

@ -1,8 +1,9 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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 <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -37,6 +38,7 @@
#include <msgpanel.h> #include <msgpanel.h>
class BOARD; class BOARD;
class EDA_DRAW_FRAME;
class TOOL_DISPATCHER; class TOOL_DISPATCHER;
namespace KIGFX namespace KIGFX
@ -165,6 +167,27 @@ public:
*/ */
double GetLegacyZoom() const; 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: protected:
void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onPaint( wxPaintEvent& WXUNUSED( aEvent ) );
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
@ -178,6 +201,9 @@ protected:
/// Pointer to the parent window /// Pointer to the parent window
wxWindow* m_parent; wxWindow* m_parent;
/// Parent EDA_DRAW_FRAME (if available)
EDA_DRAW_FRAME* m_edaFrame;
/// Last timestamp when the panel was refreshed /// Last timestamp when the panel was refreshed
wxLongLong m_lastRefresh; 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 /// 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. /// for cases when the panel loses keyboard focus, so it does not react to hotkeys anymore.
bool m_lostFocus; bool m_lostFocus;
/// Grid style setting string
static const wxChar GRID_STYLE_CFG[];
}; };
#endif #endif