GAL opts: move config reading into GAL_DISPLAY_OPTIONS

Move repeated GAL config reading routines into GAL_DISPLAY_OPTIONS.
THe app-level config is in here already, do the same for the
common config.

This means that the configs are loaded consistently, which fixes
the symbol-chooser preview window, which previously didn't use the
same config routine as other GAL canvases.

Future work could move these functions to free functions that
act on the public interface of GAL_DISPLAY_OPTIONS to avoid
GAL_DISPLAY_OPTIONS having to know about wxConfig and wxWindow.

Fixes: lp:1824524
* https://bugs.launchpad.net/kicad/+bug/1824524

(cherry picked from commit ab2281d26f)
This commit is contained in:
John Beard 2019-04-11 20:35:52 +01:00
parent 3edad56e6b
commit 2d43fcf9ee
8 changed files with 87 additions and 88 deletions

View File

@ -27,6 +27,7 @@
#include <config_map.h>
#include <dpi_scaling.h>
#include <pgm_base.h>
using namespace KIGFX;
@ -62,38 +63,71 @@ GAL_DISPLAY_OPTIONS::GAL_DISPLAY_OPTIONS()
{}
void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase* aCfg, const wxString& aBaseName )
void GAL_DISPLAY_OPTIONS::ReadAppConfig( wxConfigBase& aCfg, const wxString& aBaseName )
{
const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY;
long readLong; // Temp value buffer
aCfg->Read( aBaseName + GalGridStyleConfig, &readLong,
static_cast<long>( KIGFX::GRID_STYLE::DOTS ) );
aCfg.Read( baseName + GalGridStyleConfig, &readLong,
static_cast<long>( KIGFX::GRID_STYLE::DOTS ) );
m_gridStyle = UTIL::GetValFromConfig( gridStyleConfigVals, readLong );
aCfg->Read( aBaseName + GalGridLineWidthConfig, &m_gridLineWidth, 1.0 );
aCfg->Read( aBaseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 );
aCfg->Read( aBaseName + GalGridAxesEnabledConfig, &m_axesEnabled, false );
aCfg->Read( aBaseName + GalFullscreenCursorConfig, &m_fullscreenCursor, false );
aCfg->Read( aBaseName + GalForceDisplayCursorConfig, &m_forceDisplayCursor, true );
aCfg.Read( baseName + GalGridLineWidthConfig, &m_gridLineWidth, 1.0 );
aCfg.Read( baseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 );
aCfg.Read( baseName + GalGridAxesEnabledConfig, &m_axesEnabled, false );
aCfg.Read( baseName + GalFullscreenCursorConfig, &m_fullscreenCursor, false );
aCfg.Read( baseName + GalForceDisplayCursorConfig, &m_forceDisplayCursor, true );
NotifyChanged();
}
void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase* aCfg, const wxString& aBaseName )
void GAL_DISPLAY_OPTIONS::ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindow* aWindow )
{
aCfg->Write( aBaseName + GalGridStyleConfig,
int temp;
aCommonConfig.Read(
GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp;
aCommonConfig.Read(
CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp;
{
const DPI_SCALING dpi{ &aCommonConfig, aWindow };
m_scaleFactor = dpi.GetScaleFactor();
}
NotifyChanged();
}
void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase& aCommonConfig, wxConfigBase& aAppConfig,
const wxString& aBaseCfgName, wxWindow* aWindow )
{
ReadAppConfig( aAppConfig, aBaseCfgName );
ReadCommonConfig( aCommonConfig, aWindow );
}
void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName )
{
const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY;
aCfg.Write( baseName + GalGridStyleConfig,
UTIL::GetConfigForVal( gridStyleConfigVals, m_gridStyle ) );
aCfg->Write( aBaseName + GalGridLineWidthConfig, m_gridLineWidth );
aCfg->Write( aBaseName + GalGridMaxDensityConfig, m_gridMinSpacing );
aCfg->Write( aBaseName + GalGridAxesEnabledConfig, m_axesEnabled );
aCfg->Write( aBaseName + GalFullscreenCursorConfig, m_fullscreenCursor );
aCfg->Write( aBaseName + GalForceDisplayCursorConfig, m_forceDisplayCursor );
aCfg.Write( baseName + GalGridLineWidthConfig, m_gridLineWidth );
aCfg.Write( baseName + GalGridMaxDensityConfig, m_gridMinSpacing );
aCfg.Write( baseName + GalGridAxesEnabledConfig, m_axesEnabled );
aCfg.Write( baseName + GalFullscreenCursorConfig, m_fullscreenCursor );
aCfg.Write( baseName + GalForceDisplayCursorConfig, m_forceDisplayCursor );
}
void GAL_DISPLAY_OPTIONS::NotifyChanged()
{
Notify( &GAL_DISPLAY_OPTIONS_OBSERVER::OnGalDisplayOptionsChanged, *this );
}
}

View File

@ -67,7 +67,6 @@
#include <page_info.h>
#include <title_block.h>
#include <advanced_config.h>
#include <dpi_scaling.h>
/**
* Definition for enabling and disabling scroll bar setting trace output. See the
@ -295,19 +294,7 @@ void EDA_DRAW_FRAME::CommonSettingsChanged()
settings->Read( ENBL_AUTO_PAN_KEY, &option );
m_canvas->SetEnableAutoPan( option );
int tmp;
settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp;
settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp;
{
const DPI_SCALING dpi{ settings, this };
m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor();
}
m_galDisplayOptions.NotifyChanged();
m_galDisplayOptions.ReadCommonConfig( *settings, this );
}
@ -849,21 +836,7 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
m_galDisplayOptions.ReadConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY );
int temp;
cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp;
cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp;
{
const DPI_SCALING dpi{ cmnCfg, this };
m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor();
}
m_galDisplayOptions.NotifyChanged();
m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this );
}
@ -881,7 +854,7 @@ void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
if( GetScreen() )
aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
m_galDisplayOptions.WriteConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY );
m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName );
}

View File

@ -46,7 +46,6 @@
#include <math/box2.h>
#include <lockfile.h>
#include <trace_helpers.h>
#include <dpi_scaling.h>
#include <wx/clipbrd.h>
#include <fctsys.h>
@ -297,19 +296,7 @@ void EDA_DRAW_FRAME::CommonSettingsChanged()
settings->Read( ENBL_AUTO_PAN_KEY, &option );
m_canvas->SetEnableAutoPan( option );
int tmp;
settings->Read( GAL_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) tmp;
settings->Read( CAIRO_ANTIALIASING_MODE_KEY, &tmp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) tmp;
{
const DPI_SCALING dpi{ settings, this };
m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor();
}
m_galDisplayOptions.NotifyChanged();
m_galDisplayOptions.ReadCommonConfig( *settings, this );
}
@ -868,21 +855,7 @@ void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
m_galDisplayOptions.ReadConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY );
int temp;
cmnCfg->Read( GAL_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) temp;
cmnCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &temp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
m_galDisplayOptions.cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) temp;
{
const DPI_SCALING dpi{ cmnCfg, this };
m_galDisplayOptions.m_scaleFactor = dpi.GetScaleFactor();
}
m_galDisplayOptions.NotifyChanged();
m_galDisplayOptions.ReadConfig( *cmnCfg, *aCfg, baseCfgName, this );
}
@ -902,7 +875,7 @@ void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
if( GetScreen() )
aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
m_galDisplayOptions.WriteConfig( aCfg, baseCfgName + GAL_DISPLAY_OPTIONS_KEY );
m_galDisplayOptions.WriteConfig( *aCfg, baseCfgName );
}

View File

@ -738,7 +738,7 @@ void LIB_VIEW_FRAME::LoadSettings( wxConfigBase* aCfg )
SetGridColor( wtmp );
// Grid shape, etc.
GetGalDisplayOptions().ReadConfig( aCfg, symbolEditor + GAL_DISPLAY_OPTIONS_KEY );
GetGalDisplayOptions().ReadAppConfig( *aCfg, symbolEditor );
aCfg->Read( LIBLIST_WIDTH_KEY, &m_libListWidth, 150 );
aCfg->Read( CMPLIST_WIDTH_KEY, &m_cmpListWidth, 150 );

View File

@ -39,7 +39,7 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway,
{
wxString eeschemaFrameKey( SCH_EDIT_FRAME_NAME );
auto eeschemaConfig = GetNewConfig( Pgm().App().GetAppName() );
m_galDisplayOptions.ReadConfig( eeschemaConfig.get(), eeschemaFrameKey + GAL_DISPLAY_OPTIONS_KEY );
m_galDisplayOptions.ReadAppConfig( *eeschemaConfig, eeschemaFrameKey );
EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = aCanvasType;

View File

@ -28,6 +28,8 @@
class wxConfigBase;
class wxString;
class wxWindow;
namespace KIGFX
{
@ -74,8 +76,31 @@ namespace KIGFX
public:
GAL_DISPLAY_OPTIONS();
void ReadConfig ( wxConfigBase* aCfg, const wxString& aBaseName );
void WriteConfig( wxConfigBase* aCfg, const wxString& aBaseName );
/**
* Read GAL config options from applicaton-level config
* @param aCfg the application config base
* @param aBaseName the application's GAL options key prefix
*/
void ReadAppConfig( wxConfigBase& aCfg, const wxString& aBaseName );
/**
* Read GAL config options from the common config store
* @param aCommonConfig the common config store
* @param aWindow the wx parent window (used for DPI scaling)
*/
void ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindow* aWindow );
/**
* Read application and common configs
* @param aCommonConfig the common config store
* @param aCfg the application config base
* @param aBaseName the application's GAL options key prefix
* @param aWindow the wx parent window (used for DPI scaling)
*/
void ReadConfig( wxConfigBase& aCommonConfig, wxConfigBase& aAppCondfig,
const wxString& aBaseCfgName, wxWindow* aWindow );
void WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName );
void NotifyChanged();

View File

@ -395,13 +395,7 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow*
// Make and populate a new one from config
gal_opts = std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>();
gal_opts->ReadConfig( cfg, wxString( PCB_EDIT_FRAME_NAME ) + GAL_DISPLAY_OPTIONS_KEY );
commonCfg->Read( GAL_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::OPENGL_ANTIALIASING_MODE::NONE );
gal_opts->gl_antialiasing_mode = (KIGFX::OPENGL_ANTIALIASING_MODE) itemp;
commonCfg->Read( CAIRO_ANTIALIASING_MODE_KEY, &itemp, (int) KIGFX::CAIRO_ANTIALIASING_MODE::NONE );
gal_opts->cairo_antialiasing_mode = (KIGFX::CAIRO_ANTIALIASING_MODE) itemp;
gal_opts->ReadConfig( *commonCfg, *cfg, wxString( PCB_EDIT_FRAME_NAME ), aParent );
}
#ifdef __WXMAC__

View File

@ -513,7 +513,7 @@ void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
SetGridColor( wtmp );
// Grid shape, etc.
GetGalDisplayOptions().ReadConfig( aCfg, footprintEditor + GAL_DISPLAY_OPTIONS_KEY );
GetGalDisplayOptions().ReadAppConfig( *aCfg, footprintEditor );
m_configSettings.Load( aCfg ); // mainly, load the color config