KiCad PCB EDA Suite
settings.h
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) 2015 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #ifndef __SETTINGS_H
27 #define __SETTINGS_H
28 
29 #include <wx/confbase.h>
30 #include <config_params.h>
31 
32 
38 class SETTINGS
39 {
40  public:
42  {}
43 
44  virtual ~SETTINGS()
45  {}
46 
50  void SetConfigPrefix( const wxString& aPrefix )
51  {
52  m_prefix = aPrefix;
53  }
54 
57  const wxString& GetConfigPrefix()
58  {
59  return m_prefix;
60  }
61 
62  virtual void Load( wxConfigBase *aConfig );
63  virtual void Save( wxConfigBase *aConfig );
64 
65  #if 0
66  template<class T>
67  T Get( const wxString& aName, T aDefaultValue ) const
68  {
69  wxConfigBase* config = getConfigBase();
70 
71  if( !config )
72  return aDefaultValue;
73 
74  T tmp = aDefaultValue;
75 
76  config->Read( getKeyName( aName ), &tmp );
77  return tmp;
78  }
79 
80  template<class T>
81  void Set( const wxString& aName, const T &aValue )
82  {
83  wxConfigBase* config = getConfigBase();
84 
85  if( !config )
86  return;
87 
88  config->Write( getKeyName( aName ), aValue );
89  }
90  #endif
91 
92 
93  void Add( const wxString& name, int* aPtr, int aDefaultValue )
94  {
95  m_params.push_back( new PARAM_CFG_INT ( m_prefix+name, aPtr, aDefaultValue ) );
96  }
97 
98  void Add( const wxString& name, bool* aPtr, bool aDefaultValue )
99  {
100  m_params.push_back( new PARAM_CFG_BOOL ( m_prefix+name, aPtr, aDefaultValue ) );
101  }
102 
103  void Add( const wxString& name, KIGFX::COLOR4D* aPtr, KIGFX::COLOR4D aDefaultValue )
104  {
105  m_params.push_back( new PARAM_CFG_SETCOLOR ( m_prefix+name, aPtr, aDefaultValue ) );
106  }
107 
108  void Add( const wxString& name, KIGFX::COLOR4D* aPtr, EDA_COLOR_T aDefaultValue )
109  {
110  m_params.push_back( new PARAM_CFG_SETCOLOR ( m_prefix+name, aPtr, aDefaultValue ) );
111  }
112 
113 
114  protected:
115 
116  virtual wxString getKeyName( const wxString& aEntryName ) const
117  {
118  return aEntryName;
119  }
120 
121  private:
122  wxString m_prefix;
124 };
125 
126 
127 
128 #endif
A list of parameters type.
EDA_COLOR_T
NOTE: EDA_COLOR_T is deprecated and is kept around for compatibility with legacy canvas.
Definition: colors.h:42
Class TOOL_SETTINGS.
Definition: settings.h:38
void Add(const wxString &name, bool *aPtr, bool aDefaultValue)
Definition: settings.h:98
const wxString & GetConfigPrefix()
Definition: settings.h:57
virtual void Save(wxConfigBase *aConfig)
Definition: settings.cpp:39
virtual wxString getKeyName(const wxString &aEntryName) const
Definition: settings.h:116
The common library.
virtual void Load(wxConfigBase *aConfig)
Definition: settings.cpp:26
PARAM_CFG_ARRAY m_params
Definition: settings.h:123
void Add(const wxString &name, KIGFX::COLOR4D *aPtr, KIGFX::COLOR4D aDefaultValue)
Definition: settings.h:103
void Add(const wxString &name, int *aPtr, int aDefaultValue)
Definition: settings.h:93
void Add(const wxString &name, KIGFX::COLOR4D *aPtr, EDA_COLOR_T aDefaultValue)
Definition: settings.h:108
Configuration parameter - SetColor Class.
SETTINGS()
Definition: settings.h:41
wxString m_prefix
Definition: settings.h:122
Configuration parameter - Integer Class.
Configuration parameter - Boolean Class.
const char * name
Definition: DXF_plotter.cpp:61
virtual ~SETTINGS()
Definition: settings.h:44
void SetConfigPrefix(const wxString &aPrefix)
Set a prefix that will be prepent to the keywords when adding a setting in list.
Definition: settings.h:50
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39