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 /*
41  * NOTE: Everything in this file is deprecated, it only remains because advanced_config depends on
42  * it for the moment.
43  */
44 
53 void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
54 
55 
73 };
74 
75 
85 class PARAM_CFG
86 {
87 public:
88  wxString m_Ident;
90  wxString m_Group;
91  bool m_Setup;
92 
93  // If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy.
94  // Note that values are always written to the current, non-legacy keyword.
95  wxString m_Ident_legacy;
96 
97 public:
98  PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = NULL,
99  const wxString& legacy_ident = wxEmptyString );
100  virtual ~PARAM_CFG() {}
101 
107  virtual void ReadParam( wxConfigBase* aConfig ) const {};
108 
114  virtual void SaveParam( wxConfigBase* aConfig ) const {};
115 };
116 
117 
122 class PARAM_CFG_INT : public PARAM_CFG
123 {
124 public:
125  int* m_Pt_param;
126  int m_Min, m_Max;
127  int m_Default;
128 
129 public:
130  PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0,
131  int min = std::numeric_limits<int>::min(),
132  int max = std::numeric_limits<int>::max(),
133  const wxChar* group = nullptr,
134  const wxString& legacy_ident = wxEmptyString );
135  PARAM_CFG_INT( bool Insetup, const wxString& ident, int* ptparam, int default_val = 0,
136  int min = std::numeric_limits<int>::min(),
137  int max = std::numeric_limits<int>::max(),
138  const wxChar* group = nullptr,
139  const wxString& legacy_ident = wxEmptyString );
140 
141  virtual void ReadParam( wxConfigBase* aConfig ) const override;
142  virtual void SaveParam( wxConfigBase* aConfig ) const override;
143 };
144 
153 {
154 public:
156 
157 public:
158  PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0,
159  int min = std::numeric_limits<int>::min(),
160  int max = std::numeric_limits<int>::max(),
161  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
162  const wxString& legacy_ident = wxEmptyString );
163  PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam,
164  int default_val = 0,
165  int min = std::numeric_limits<int>::min(),
166  int max = std::numeric_limits<int>::max(),
167  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
168  const wxString& legacy_ident = wxEmptyString );
169 
170  virtual void ReadParam( wxConfigBase* aConfig ) const override;
171  virtual void SaveParam( wxConfigBase* aConfig ) const override;
172 };
173 
174 
180 {
181 public:
182  double* m_Pt_param;
183  double m_Default;
184  double m_Min, m_Max;
185 
186 public:
187  PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
188  double default_val = 0.0, double min = 0.0, double max = 10000.0,
189  const wxChar* group = NULL );
190  PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
191  double default_val = 0.0, double min = 0.0, double max = 10000.0,
192  const wxChar* group = NULL );
193 
194  virtual void ReadParam( wxConfigBase* aConfig ) const override;
195  virtual void SaveParam( wxConfigBase* aConfig ) const override;
196 };
197 
198 
203 class PARAM_CFG_BOOL : public PARAM_CFG
204 {
205 public:
206  bool* m_Pt_param;
207  int m_Default;
208 
209 public:
210  PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
211  int default_val = false, const wxChar* group = NULL,
212  const wxString& legacy_ident = wxEmptyString );
213  PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
214  int default_val = false, const wxChar* group = NULL,
215  const wxString& legacy_ident = wxEmptyString );
216 
217  virtual void ReadParam( wxConfigBase* aConfig ) const override;
218  virtual void SaveParam( wxConfigBase* aConfig ) const override;
219 };
220 
221 
227 {
228 public:
229  wxString* m_Pt_param;
230  wxString m_default;
231 
232 public:
233  PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = NULL );
234 
235  PARAM_CFG_WXSTRING( bool Insetup,
236  const wxString& ident,
237  wxString* ptparam,
238  const wxString& default_val = wxEmptyString,
239  const wxChar* group = NULL );
240 
241  virtual void ReadParam( wxConfigBase* aConfig ) const override;
242  virtual void SaveParam( wxConfigBase* aConfig ) const override;
243 };
244 
245 
251 {
252 public:
253  std::set<wxString>* m_Pt_param;
254 
255 public:
256  PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam, const wxChar* group = NULL );
257 
258  PARAM_CFG_WXSTRING_SET( bool Insetup,
259  const wxString& ident,
260  std::set<wxString>* ptparam,
261  const wxChar* group = NULL );
262 
263  virtual void ReadParam( wxConfigBase* aConfig ) const override;
264  virtual void SaveParam( wxConfigBase* aConfig ) const override;
265 };
266 
267 
275 {
276 public:
277  wxString* m_Pt_param;
278 
279 public:
280  PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
281  const wxChar* group = NULL );
282  virtual void ReadParam( wxConfigBase* aConfig ) const override;
283  virtual void SaveParam( wxConfigBase* aConfig ) const override;
284 };
285 
286 
288 {
289 public:
290  wxArrayString* m_Pt_param;
291 
292 public:
293  PARAM_CFG_LIBNAME_LIST( const wxChar* ident,
294  wxArrayString* ptparam,
295  const wxChar* group = NULL );
296 
297  virtual void ReadParam( wxConfigBase* aConfig ) const override;
298  virtual void SaveParam( wxConfigBase* aConfig ) const override;
299 };
300 
301 
311 void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
312 
323 void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
324  const wxString& aGroup );
325 
334 void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
335 
346 void wxConfigLoadParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
347  const wxString& aGroup );
348 
349 
350 #endif // CONFIG_PARAMS_H_
bool m_Setup
Install or Project based parameter, true == install.
Definition: config_params.h:91
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:90
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:88
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:95
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:57
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:85
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:89
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()
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:100