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 
40 
49 void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
50 
51 
69 };
70 
71 
81 class PARAM_CFG
82 {
83 public:
84  wxString m_Ident;
86  wxString m_Group;
87  bool m_Setup;
88 
89  // If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy.
90  // Note that values are always written to the current, non-legacy keyword.
91  wxString m_Ident_legacy;
92 
93 public:
94  PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = NULL,
95  const wxString& legacy_ident = wxEmptyString );
96  virtual ~PARAM_CFG() {}
97 
103  virtual void ReadParam( wxConfigBase* aConfig ) const {};
104 
110  virtual void SaveParam( wxConfigBase* aConfig ) const {};
111 };
112 
113 
118 class PARAM_CFG_INT : public PARAM_CFG
119 {
120 public:
121  int* m_Pt_param;
122  int m_Min, m_Max;
123  int m_Default;
124 
125 public:
126  PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0,
127  int min = std::numeric_limits<int>::min(),
128  int max = std::numeric_limits<int>::max(),
129  const wxChar* group = nullptr,
130  const wxString& legacy_ident = wxEmptyString );
131  PARAM_CFG_INT( bool Insetup, const wxString& ident, int* ptparam, int default_val = 0,
132  int min = std::numeric_limits<int>::min(),
133  int max = std::numeric_limits<int>::max(),
134  const wxChar* group = nullptr,
135  const wxString& legacy_ident = wxEmptyString );
136 
137  virtual void ReadParam( wxConfigBase* aConfig ) const override;
138  virtual void SaveParam( wxConfigBase* aConfig ) const override;
139 };
140 
149 {
150 public:
152 
153 public:
154  PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0,
155  int min = std::numeric_limits<int>::min(),
156  int max = std::numeric_limits<int>::max(),
157  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
158  const wxString& legacy_ident = wxEmptyString );
159  PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam,
160  int default_val = 0,
161  int min = std::numeric_limits<int>::min(),
162  int max = std::numeric_limits<int>::max(),
163  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
164  const wxString& legacy_ident = wxEmptyString );
165 
166  virtual void ReadParam( wxConfigBase* aConfig ) const override;
167  virtual void SaveParam( wxConfigBase* aConfig ) const override;
168 };
169 
170 
176 {
177 public:
178  double* m_Pt_param;
179  double m_Default;
180  double m_Min, m_Max;
181 
182 public:
183  PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
184  double default_val = 0.0, double min = 0.0, double max = 10000.0,
185  const wxChar* group = NULL );
186  PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
187  double default_val = 0.0, double min = 0.0, double max = 10000.0,
188  const wxChar* group = NULL );
189 
190  virtual void ReadParam( wxConfigBase* aConfig ) const override;
191  virtual void SaveParam( wxConfigBase* aConfig ) const override;
192 };
193 
194 
199 class PARAM_CFG_BOOL : public PARAM_CFG
200 {
201 public:
202  bool* m_Pt_param;
203  int m_Default;
204 
205 public:
206  PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
207  int default_val = false, const wxChar* group = NULL,
208  const wxString& legacy_ident = wxEmptyString );
209  PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
210  int default_val = false, const wxChar* group = NULL,
211  const wxString& legacy_ident = wxEmptyString );
212 
213  virtual void ReadParam( wxConfigBase* aConfig ) const override;
214  virtual void SaveParam( wxConfigBase* aConfig ) const override;
215 };
216 
217 
223 {
224 public:
225  wxString* m_Pt_param;
226  wxString m_default;
227 
228 public:
229  PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = NULL );
230 
231  PARAM_CFG_WXSTRING( bool Insetup,
232  const wxString& ident,
233  wxString* ptparam,
234  const wxString& default_val = wxEmptyString,
235  const wxChar* group = NULL );
236 
237  virtual void ReadParam( wxConfigBase* aConfig ) const override;
238  virtual void SaveParam( wxConfigBase* aConfig ) const override;
239 };
240 
241 
247 {
248 public:
249  std::set<wxString>* m_Pt_param;
250 
251 public:
252  PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam, const wxChar* group = NULL );
253 
254  PARAM_CFG_WXSTRING_SET( bool Insetup,
255  const wxString& ident,
256  std::set<wxString>* ptparam,
257  const wxChar* group = NULL );
258 
259  virtual void ReadParam( wxConfigBase* aConfig ) const override;
260  virtual void SaveParam( wxConfigBase* aConfig ) const override;
261 };
262 
263 
271 {
272 public:
273  wxString* m_Pt_param;
274 
275 public:
276  PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
277  const wxChar* group = NULL );
278  virtual void ReadParam( wxConfigBase* aConfig ) const override;
279  virtual void SaveParam( wxConfigBase* aConfig ) const override;
280 };
281 
282 
284 {
285 public:
286  wxArrayString* m_Pt_param;
287 
288 public:
289  PARAM_CFG_LIBNAME_LIST( const wxChar* ident,
290  wxArrayString* ptparam,
291  const wxChar* group = NULL );
292 
293  virtual void ReadParam( wxConfigBase* aConfig ) const override;
294  virtual void SaveParam( wxConfigBase* aConfig ) const override;
295 };
296 
297 
307 void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
308 
319 void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
320  const wxString& aGroup );
321 
330 void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
331 
342 void wxConfigLoadParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
343  const wxString& aGroup );
344 
345 
346 #endif // CONFIG_PARAMS_H_
bool m_Setup
Install or Project based parameter, true == install.
Definition: config_params.h:87
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
wxString m_Group
Group name (this is like a path in the config data)
Definition: config_params.h:86
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)
Function wxConfigSaveSetups writes aList of PARAM_CFG to save configuration values to aCfg.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
void ConfigBaseWriteDouble(wxConfigBase *aConfig, const wxString &aKey, double aValue)
Function ConfigBaseWriteDouble This is a helper function to write doubles in config We cannot use wxC...
wxString m_default
The default value of the parameter.
PARAM_CFG_WXSTRING_SET(const wxString &ident, std::set< wxString > *ptparam, const wxChar *group=NULL)
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
wxString m_Ident
Keyword in config data.
Definition: config_params.h:84
Configuration parameter - Double Precision Class.
int m_Default
The default value of the parameter.
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
void wxConfigLoadParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Function wxConfigLoadParams uses aList of PARAM_CFG to load configuration values from aCfg.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
wxString m_Ident_legacy
Definition: config_params.h:91
double * m_Pt_param
Pointer to the parameter value.
Configuration parameter - Integer Class with unit conversion.
int * m_Pt_param
Pointer to the parameter value.
Configuration parameter - PARAM_CFG_FILENAME Class Same as PARAM_CFG_WXSTRING, but stores "\" as "/".
PARAM_CFG_BOOL(const wxString &ident, bool *ptparam, int default_val=false, const wxChar *group=NULL, const wxString &legacy_ident=wxEmptyString)
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_LIBNAME_LIST(const wxChar *ident, wxArrayString *ptparam, const wxChar *group=NULL)
#define NULL
Configuration parameter - std::set<wxString>
wxArrayString * m_Pt_param
Pointer to the parameter value.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
PARAM_CFG(const wxString &ident, const paramcfg_id type, const wxChar *group=NULL, const wxString &legacy_ident=wxEmptyString)
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
Configuration parameter - Integer Class.
void wxConfigSaveParams(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
Function wxConfigSaveParams writes aList of PARAM_CFG to save configuration values to aCfg.
int m_Max
Minimum and maximum values of the param type.
Configuration parameter - Boolean Class.
virtual void ReadParam(wxConfigBase *aConfig) const
Function ReadParam reads the value of the parameter stored in aConfig.
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
virtual void SaveParam(wxConfigBase *aConfig) const
Function SaveParam saves 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:53
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
Configuration parameter - wxString Class.
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)
PARAM_CFG_WXSTRING(const wxString &ident, wxString *ptparam, const wxChar *group=NULL)
bool * m_Pt_param
Pointer to the parameter value.
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81
void wxConfigLoadSetups(wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
Function wxConfigLoadSetups uses aList of PARAM_CFG to load configuration values from aCfg.
paramcfg_id m_Type
Type of parameter.
Definition: config_params.h:85
wxString * m_Pt_param
Pointer to the parameter value.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
virtual ~PARAM_CFG()
Definition: config_params.h:96
PARAM_CFG_DOUBLE(const wxString &ident, double *ptparam, double default_val=0.0, double min=0.0, double max=10000.0, const wxChar *group=NULL)
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
virtual void ReadParam(wxConfigBase *aConfig) const override
Function ReadParam reads the value of the parameter stored in aConfig.
PARAM_CFG_FILENAME(const wxString &ident, wxString *ptparam, const wxChar *group=NULL)
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
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=NULL, double aBiu2cfgunit=1.0, const wxString &legacy_ident=wxEmptyString)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99