KiCad PCB EDA Suite
config_params.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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
5  * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef CONFIG_PARAMS_H_
27 #define CONFIG_PARAMS_H_
28 
29 #include <set>
30 #include <limits>
31 
32 #include <wx/confbase.h>
33 #include <wx/fileconf.h>
34 #include <boost/ptr_container/ptr_vector.hpp>
35 #include <gal/color4d.h>
36 
37 using KIGFX::COLOR4D;
38 
39 
50 void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
51 
52 
70 };
71 
72 
81 class PARAM_CFG
82 {
83 public:
84  PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = nullptr,
85  const wxString& legacy_ident = wxEmptyString );
86  virtual ~PARAM_CFG() {}
87 
93  virtual void ReadParam( wxConfigBase* aConfig ) const {};
94 
100  virtual void SaveParam( wxConfigBase* aConfig ) const {};
101 
102  wxString m_Ident;
104  wxString m_Group;
105  bool m_Setup;
106 
107  // If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy.
108  // Note that values are always written to the current, non-legacy keyword.
109  wxString m_Ident_legacy;
110 };
111 
112 
116 class PARAM_CFG_INT : public PARAM_CFG
117 {
118 public:
119  PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0,
120  int min = std::numeric_limits<int>::min(),
121  int max = std::numeric_limits<int>::max(),
122  const wxChar* group = nullptr,
123  const wxString& legacy_ident = wxEmptyString );
124  PARAM_CFG_INT( bool Insetup, const wxString& ident, int* ptparam, int default_val = 0,
125  int min = std::numeric_limits<int>::min(),
126  int max = std::numeric_limits<int>::max(),
127  const wxChar* group = nullptr,
128  const wxString& legacy_ident = wxEmptyString );
129 
130  virtual void ReadParam( wxConfigBase* aConfig ) const override;
131  virtual void SaveParam( wxConfigBase* aConfig ) const override;
132 
133  int* m_Pt_param;
134  int m_Min, m_Max;
135  int m_Default;
136 };
137 
145 {
146 public:
147  PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0,
148  int min = std::numeric_limits<int>::min(),
149  int max = std::numeric_limits<int>::max(),
150  const wxChar* group = nullptr, double aBiu2cfgunit = 1.0,
151  const wxString& legacy_ident = wxEmptyString );
152  PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam,
153  int default_val = 0,
154  int min = std::numeric_limits<int>::min(),
155  int max = std::numeric_limits<int>::max(),
156  const wxChar* group = nullptr, double aBiu2cfgunit = 1.0,
157  const wxString& legacy_ident = wxEmptyString );
158 
159  virtual void ReadParam( wxConfigBase* aConfig ) const override;
160  virtual void SaveParam( wxConfigBase* aConfig ) const override;
161 
162 public:
164 };
165 
166 
171 {
172 public:
173  PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
174  double default_val = 0.0, double min = 0.0, double max = 10000.0,
175  const wxChar* group = nullptr );
176  PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
177  double default_val = 0.0, double min = 0.0, double max = 10000.0,
178  const wxChar* group = nullptr );
179 
180  virtual void ReadParam( wxConfigBase* aConfig ) const override;
181  virtual void SaveParam( wxConfigBase* aConfig ) const override;
182 
183  double* m_Pt_param;
184  double m_Default;
185  double m_Min, m_Max;
186 };
187 
188 
192 class PARAM_CFG_BOOL : public PARAM_CFG
193 {
194 public:
195  PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
196  int default_val = false, const wxChar* group = nullptr,
197  const wxString& legacy_ident = wxEmptyString );
198  PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
199  int default_val = false, const wxChar* group = nullptr,
200  const wxString& legacy_ident = wxEmptyString );
201 
202  virtual void ReadParam( wxConfigBase* aConfig ) const override;
203  virtual void SaveParam( wxConfigBase* aConfig ) const override;
204 
205  bool* m_Pt_param;
206  int m_Default;
207 };
208 
209 
214 {
215 public:
216  PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = nullptr );
217 
218  PARAM_CFG_WXSTRING( bool Insetup,
219  const wxString& ident,
220  wxString* ptparam,
221  const wxString& default_val = wxEmptyString,
222  const wxChar* group = nullptr );
223 
224  virtual void ReadParam( wxConfigBase* aConfig ) const override;
225  virtual void SaveParam( wxConfigBase* aConfig ) const override;
226 
227  wxString* m_Pt_param;
228  wxString m_default;
229 };
230 
231 
237 {
238 public:
239  PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam,
240  const wxChar* group = nullptr );
241 
242  PARAM_CFG_WXSTRING_SET( bool Insetup,
243  const wxString& ident,
244  std::set<wxString>* ptparam,
245  const wxChar* group = nullptr );
246 
247  virtual void ReadParam( wxConfigBase* aConfig ) const override;
248  virtual void SaveParam( wxConfigBase* aConfig ) const override;
249 
250  std::set<wxString>* m_Pt_param;
251 };
252 
253 
260 {
261 public:
262  PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
263  const wxChar* group = nullptr );
264  virtual void ReadParam( wxConfigBase* aConfig ) const override;
265  virtual void SaveParam( wxConfigBase* aConfig ) const override;
266 
267  wxString* m_Pt_param;
268 };
269 
270 
272 {
273 public:
274  wxArrayString* m_Pt_param;
275 
276 public:
277  PARAM_CFG_LIBNAME_LIST( const wxChar* ident, wxArrayString* ptparam,
278  const wxChar* group = nullptr );
279 
280  virtual void ReadParam( wxConfigBase* aConfig ) const override;
281  virtual void SaveParam( wxConfigBase* aConfig ) const override;
282 };
283 
284 
293 void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
294 
305 void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
306  const wxString& aGroup );
307 
316 void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
317 
327 void wxConfigLoadParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
328  const wxString& aGroup );
329 
330 
331 #endif // CONFIG_PARAMS_H_
PARAM_CFG_DOUBLE(const wxString &ident, double *ptparam, double default_val=0.0, double min=0.0, double max=10000.0, const wxChar *group=nullptr)
bool m_Setup
Install or Project based parameter, true == install.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
PARAM_CFG_WXSTRING_SET(const wxString &ident, std::set< wxString > *ptparam, const wxChar *group=nullptr)
wxString m_Group
Group name (this is like a path in the config data)
int m_Default
The default value of the parameter.
wxString * m_Pt_param
Pointer to the parameter value.
void wxConfigSaveSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Writes aList of PARAM_CFG objects to aCfg.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
void ConfigBaseWriteDouble(wxConfigBase *aConfig, const wxString &aKey, double aValue)
A helper function to write doubles in configuration file.
wxString m_default
The default value of the parameter.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
wxString m_Ident
Keyword in config data.
Configuration object for double precision floating point numbers.
int m_Default
The default value of the parameter.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
void wxConfigLoadParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Use aList of PARAM_CFG objects to load configuration values from aCfg.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
wxString m_Ident_legacy
double * m_Pt_param
Pointer to the parameter value.
Configuration for integers with unit conversion.
int * m_Pt_param
Pointer to the parameter value.
PARAM_CFG(const wxString &ident, const paramcfg_id type, const wxChar *group=nullptr, const wxString &legacy_ident=wxEmptyString)
Configuration object for a file name object.
double m_BIU_to_cfgunit
the factor to convert the saved value in internal value
std::set< wxString > * m_Pt_param
Pointer to the parameter value.
PARAM_CFG_INT_WITH_SCALE(const wxString &ident, int *ptparam, int default_val=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), const wxChar *group=nullptr, double aBiu2cfgunit=1.0, const wxString &legacy_ident=wxEmptyString)
Configuration object for a set of wxString objects.
wxArrayString * m_Pt_param
Pointer to the parameter value.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
Configuration object for integers.
void wxConfigSaveParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Write aList of PARAM_CFG objects aCfg.
int m_Max
Minimum and maximum values of the param type.
Configuration object for booleans.
virtual void ReadParam(wxConfigBase *aConfig) const
Read the value of the parameter stored in aConfig.
Definition: config_params.h:93
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
virtual void SaveParam(wxConfigBase *aConfig) const
Save the value of the parameter stored in aConfig.
double m_Max
Minimum and maximum values of the param type.
paramcfg_id
Type of parameter in the configuration file.
Definition: config_params.h:54
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
Configuration object for wxString objects.
double m_Default
The default value of the parameter.
PARAM_CFG_INT(const wxString &ident, int *ptparam, int default_val=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), const wxChar *group=nullptr, const wxString &legacy_ident=wxEmptyString)
bool * m_Pt_param
Pointer to the parameter value.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
PARAM_CFG_BOOL(const wxString &ident, bool *ptparam, int default_val=false, const wxChar *group=nullptr, const wxString &legacy_ident=wxEmptyString)
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
Definition: config_params.h:81
void wxConfigLoadSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Use aList of PARAM_CFG object to load configuration values from aCfg.
PARAM_CFG_LIBNAME_LIST(const wxChar *ident, wxArrayString *ptparam, const wxChar *group=nullptr)
paramcfg_id m_Type
Type of parameter.
wxString * m_Pt_param
Pointer to the parameter value.
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
virtual ~PARAM_CFG()
Definition: config_params.h:86
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
PARAM_CFG_WXSTRING(const wxString &ident, wxString *ptparam, const wxChar *group=nullptr)
virtual void ReadParam(wxConfigBase *aConfig) const override
Read the value of the parameter stored in aConfig.
virtual void SaveParam(wxConfigBase *aConfig) const override
Save the value of the parameter stored in aConfig.
PARAM_CFG_FILENAME(const wxString &ident, wxString *ptparam, const wxChar *group=nullptr)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103