KiCad PCB EDA Suite
gal_display_options.cpp
Go to the documentation of this file.
1 /*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23 
25 
26 #include <wx/config.h>
27 #include <wx/log.h>
28 
29 #include <config_map.h>
30 #include <dpi_scaling.h>
31 #include <pgm_base.h>
32 
33 using namespace KIGFX;
34 
35 /*
36  * Config option strings
37  */
38 static const wxString GalGridStyleConfig( "GridStyle" );
39 static const wxString GalGridLineWidthConfig( "GridLineWidth" );
40 static const wxString GalGridMaxDensityConfig( "GridMaxDensity" );
41 static const wxString GalGridAxesEnabledConfig( "GridAxesEnabled" );
42 static const wxString GalFullscreenCursorConfig( "CursorFullscreen" );
43 static const wxString GalForceDisplayCursorConfig( "ForceDisplayCursor" );
44 
45 
47 {
51 };
52 
53 
61 static const wxChar* traceGalDispOpts = wxT( "KICAD_GAL_DISPLAY_OPTIONS" );
62 
63 
65  : gl_antialiasing_mode( OPENGL_ANTIALIASING_MODE::NONE ),
66  cairo_antialiasing_mode( CAIRO_ANTIALIASING_MODE::NONE ),
67  m_gridStyle( GRID_STYLE::DOTS ),
68  m_gridLineWidth( 1.0 ),
69  m_gridMinSpacing( 10.0 ),
70  m_axesEnabled( false ),
71  m_fullscreenCursor( false ),
72  m_forceDisplayCursor( false ),
73  m_scaleFactor( DPI_SCALING::GetDefaultScaleFactor() )
74 {}
75 
76 
77 void GAL_DISPLAY_OPTIONS::ReadAppConfig( wxConfigBase& aCfg, const wxString& aBaseName )
78 {
79  const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY;
80 
81  wxLogTrace( traceGalDispOpts, "Reading options with base name '%s'", baseName );
82 
83  long readLong; // Temp value buffer
84 
85  aCfg.Read( baseName + GalGridStyleConfig, &readLong,
86  static_cast<long>( KIGFX::GRID_STYLE::DOTS ) );
88 
89  aCfg.Read( baseName + GalGridLineWidthConfig, &m_gridLineWidth, 1.0 );
90  aCfg.Read( baseName + GalGridMaxDensityConfig, &m_gridMinSpacing, 10 );
91  aCfg.Read( baseName + GalGridAxesEnabledConfig, &m_axesEnabled, false );
92  aCfg.Read( baseName + GalFullscreenCursorConfig, &m_fullscreenCursor, false );
93  aCfg.Read( baseName + GalForceDisplayCursorConfig, &m_forceDisplayCursor, true );
94 
95  NotifyChanged();
96 }
97 
98 
99 void GAL_DISPLAY_OPTIONS::ReadCommonConfig( wxConfigBase& aCommonConfig, wxWindow* aWindow )
100 {
101  wxLogTrace( traceGalDispOpts, "Reading common config" );
102 
103  int temp;
104  aCommonConfig.Read(
107 
108  aCommonConfig.Read(
111 
112  {
113  const DPI_SCALING dpi{ &aCommonConfig, aWindow };
114  m_scaleFactor = dpi.GetScaleFactor();
115  }
116 
117  NotifyChanged();
118 }
119 
120 
121 void GAL_DISPLAY_OPTIONS::ReadConfig( wxConfigBase& aCommonConfig, wxConfigBase& aAppConfig,
122  const wxString& aBaseCfgName, wxWindow* aWindow )
123 {
124  wxLogTrace( traceGalDispOpts, "Reading common and app config (%s)", aBaseCfgName );
125 
126  ReadAppConfig( aAppConfig, aBaseCfgName );
127 
128  ReadCommonConfig( aCommonConfig, aWindow );
129 }
130 
131 
132 void GAL_DISPLAY_OPTIONS::WriteConfig( wxConfigBase& aCfg, const wxString& aBaseName )
133 {
134  const wxString baseName = aBaseName + GAL_DISPLAY_OPTIONS_KEY;
135 
136  wxLogTrace( traceGalDispOpts, "Writing app config (%s)", baseName );
137 
138  aCfg.Write( baseName + GalGridStyleConfig,
140 
141  aCfg.Write( baseName + GalGridLineWidthConfig, m_gridLineWidth );
142  aCfg.Write( baseName + GalGridMaxDensityConfig, m_gridMinSpacing );
143  aCfg.Write( baseName + GalGridAxesEnabledConfig, m_axesEnabled );
144  aCfg.Write( baseName + GalFullscreenCursorConfig, m_fullscreenCursor );
145  aCfg.Write( baseName + GalForceDisplayCursorConfig, m_forceDisplayCursor );
146 }
147 
148 
150 {
151  wxLogTrace( traceGalDispOpts, "Change notification" );
152 
154 }
Use lines for the grid.
GRID_STYLE
GRID_STYLE: Type definition of the grid style.
static const wxString GalGridAxesEnabledConfig("GridAxesEnabled")
static const wxString GalGridLineWidthConfig("GridLineWidth")
static const wxString GalGridStyleConfig("GridStyle")
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:131
static const wxString GalForceDisplayCursorConfig("ForceDisplayCursor")
KIGFX::GRID_STYLE m_gridStyle
The grid style to draw the grid in
void ReadCommonConfig(wxConfigBase &aCommonConfig, wxWindow *aWindow)
Read GAL config options from the common config store.
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleConfigVals
static const wxChar * traceGalDispOpts
Flag to enable GAL_DISPLAY_OPTIONS logging.
bool m_forceDisplayCursor
Force cursor display
double m_gridMinSpacing
Minimum pixel distance between displayed grid lines
void Notify(void(GAL_DISPLAY_OPTIONS_OBSERVER ::*Ptr)(Args1...), Args2 &&... aArgs)
Function Notify Notifies event to all subscribed observers.
Definition: observable.h:183
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
void ReadConfig(wxConfigBase &aCommonConfig, wxConfigBase &aAppCondfig, const wxString &aBaseCfgName, wxWindow *aWindow)
Read application and common configs.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:35
bool m_axesEnabled
Whether or not to draw the coordinate system axes
CAIRO_ANTIALIASING_MODE cairo_antialiasing_mode
#define GAL_DISPLAY_OPTIONS_KEY
Definition: pgm_base.h:54
void WriteConfig(wxConfigBase &aCfg, const wxString &aBaseName)
static const wxString GalGridMaxDensityConfig("GridMaxDensity")
static CFG_NATIVE_VAL< MAP > GetValFromConfig(const MAP &aMap, long aConf)
Get the native value corresponding to the config value (read from file or UI, probably) and find it i...
Definition: config_map.h:96
void ReadAppConfig(wxConfigBase &aCfg, const wxString &aBaseName)
Read GAL config options from applicaton-level config.
Use dots for the grid.
Use small cross instead of dots for the grid.
static const wxString GalFullscreenCursorConfig("CursorFullscreen")
#define GAL_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:55
see class PGM_BASE
virtual void OnGalDisplayOptionsChanged(const GAL_DISPLAY_OPTIONS &)=0
double m_scaleFactor
The pixel scale factor (>1 for hi-DPI scaled displays)
double m_gridLineWidth
Thickness to render grid lines/dots
#define CAIRO_ANTIALIASING_MODE_KEY
Definition: pgm_base.h:56
std::vector< std::pair< T, long > > CFG_MAP
A config value table is a list of native values (usually enums) to a different set of values,...
Definition: config_map.h:49
bool m_fullscreenCursor
Fullscreen crosshair or small cross
static long GetConfigForVal(const MAP &aMap, CFG_NATIVE_VAL< MAP > aVal)
Get the mapped config value (the one to write to file, or use in an index) from the given native (pro...
Definition: config_map.h:69