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-2011 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 
34 #include <wx/confbase.h>
35 #include <wx/fileconf.h>
36 #include <boost/ptr_container/ptr_vector.hpp>
37 #include <gal/color4d.h>
38 #include <limits>
39 
40 using KIGFX::COLOR4D;
41 
43 #define GROUP_PCB wxT( "/pcbnew" )
44 #define GROUP_SCH wxT( "/eeschema" )
45 #define GROUP_SCH_EDIT wxT( "/schematic_editor" )
46 #define GROUP_PCB_LIBS wxT( "/pcbnew/libraries" )
49 #define GROUP_SCH_LIBS wxT( "/eeschema/libraries" )
51 
52 #define GROUP_CVP wxT("/cvpcb")
53 #define GROUP_CVP_EQU wxT("/cvpcb/equfiles")
54 
55 
56 #define CONFIG_VERSION 1
57 
58 
67 void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
68 
69 
87 };
88 
89 
99 class PARAM_CFG
100 {
101 public:
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 public:
112  PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = NULL,
113  const wxString& legacy_ident = wxEmptyString );
114  virtual ~PARAM_CFG() {}
115 
121  virtual void ReadParam( wxConfigBase* aConfig ) const {};
122 
128  virtual void SaveParam( wxConfigBase* aConfig ) const {};
129 };
130 
131 
136 class PARAM_CFG_INT : public PARAM_CFG
137 {
138 public:
139  int* m_Pt_param;
140  int m_Min, m_Max;
141  int m_Default;
142 
143 public:
144  PARAM_CFG_INT( const wxString& ident, int* ptparam, int default_val = 0,
145  int min = std::numeric_limits<int>::min(),
146  int max = std::numeric_limits<int>::max(),
147  const wxChar* group = nullptr,
148  const wxString& legacy_ident = wxEmptyString );
149  PARAM_CFG_INT( bool Insetup, const wxString& ident, int* ptparam, int default_val = 0,
150  int min = std::numeric_limits<int>::min(),
151  int max = std::numeric_limits<int>::max(),
152  const wxChar* group = nullptr,
153  const wxString& legacy_ident = wxEmptyString );
154 
155  virtual void ReadParam( wxConfigBase* aConfig ) const override;
156  virtual void SaveParam( wxConfigBase* aConfig ) const override;
157 };
158 
167 {
168 public:
170 
171 public:
172  PARAM_CFG_INT_WITH_SCALE( const wxString& ident, int* ptparam, int default_val = 0,
173  int min = std::numeric_limits<int>::min(),
174  int max = std::numeric_limits<int>::max(),
175  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
176  const wxString& legacy_ident = wxEmptyString );
177  PARAM_CFG_INT_WITH_SCALE( bool insetup, const wxString& ident, int* ptparam,
178  int default_val = 0,
179  int min = std::numeric_limits<int>::min(),
180  int max = std::numeric_limits<int>::max(),
181  const wxChar* group = NULL, double aBiu2cfgunit = 1.0,
182  const wxString& legacy_ident = wxEmptyString );
183 
184  virtual void ReadParam( wxConfigBase* aConfig ) const override;
185  virtual void SaveParam( wxConfigBase* aConfig ) const override;
186 };
187 
188 
194 {
195 public:
198 
199 public:
200  PARAM_CFG_SETCOLOR( const wxString& ident, COLOR4D* ptparam,
201  COLOR4D default_val, const wxChar* group = NULL );
202  PARAM_CFG_SETCOLOR( bool Insetup, const wxString& ident, COLOR4D* ptparam,
203  COLOR4D default_val, const wxChar* group = NULL );
204 
205  virtual void ReadParam( wxConfigBase* aConfig ) const override;
206  virtual void SaveParam( wxConfigBase* aConfig ) const override;
207 };
208 
209 
215 {
216 public:
217  double* m_Pt_param;
218  double m_Default;
219  double m_Min, m_Max;
220 
221 public:
222  PARAM_CFG_DOUBLE( const wxString& ident, double* ptparam,
223  double default_val = 0.0, double min = 0.0, double max = 10000.0,
224  const wxChar* group = NULL );
225  PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
226  double default_val = 0.0, double min = 0.0, double max = 10000.0,
227  const wxChar* group = NULL );
228 
229  virtual void ReadParam( wxConfigBase* aConfig ) const override;
230  virtual void SaveParam( wxConfigBase* aConfig ) const override;
231 };
232 
233 
238 class PARAM_CFG_BOOL : public PARAM_CFG
239 {
240 public:
241  bool* m_Pt_param;
242  int m_Default;
243 
244 public:
245  PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
246  int default_val = false, const wxChar* group = NULL,
247  const wxString& legacy_ident = wxEmptyString );
248  PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
249  int default_val = false, const wxChar* group = NULL,
250  const wxString& legacy_ident = wxEmptyString );
251 
252  virtual void ReadParam( wxConfigBase* aConfig ) const override;
253  virtual void SaveParam( wxConfigBase* aConfig ) const override;
254 };
255 
256 
262 {
263 public:
264  wxString* m_Pt_param;
265  wxString m_default;
266 
267 public:
268  PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = NULL );
269 
270  PARAM_CFG_WXSTRING( bool Insetup,
271  const wxString& ident,
272  wxString* ptparam,
273  const wxString& default_val = wxEmptyString,
274  const wxChar* group = NULL );
275 
276  virtual void ReadParam( wxConfigBase* aConfig ) const override;
277  virtual void SaveParam( wxConfigBase* aConfig ) const override;
278 };
279 
280 
288 {
289 public:
290  wxString* m_Pt_param;
291 
292 public:
293  PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
294  const wxChar* group = NULL );
295  virtual void ReadParam( wxConfigBase* aConfig ) const override;
296  virtual void SaveParam( wxConfigBase* aConfig ) const override;
297 };
298 
299 
301 {
302 public:
303  wxArrayString* m_Pt_param;
304 
305 public:
306  PARAM_CFG_LIBNAME_LIST( const wxChar* ident,
307  wxArrayString* ptparam,
308  const wxChar* group = NULL );
309 
310  virtual void ReadParam( wxConfigBase* aConfig ) const override;
311  virtual void SaveParam( wxConfigBase* aConfig ) const override;
312 };
313 
314 
324 void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
325 
336 void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
337  const wxString& aGroup );
338 
347 void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
348 
359 void wxConfigLoadParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
360  const wxString& aGroup );
361 
362 
363 #endif // CONFIG_PARAMS_H_
bool m_Setup
Install or Project based parameter, true == install.
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)
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.
COLOR4D * m_Pt_param
Pointer to the parameter value.
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.
virtual void ReadParam(wxConfigBase *aConfig) const override
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.
wxString m_Ident
Keyword in config data.
Configuration parameter - Double Precision Class.
int m_Default
The default value of the parameter.
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.
wxString m_Ident_legacy
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
PARAM_CFG_LIBNAME_LIST(const wxChar *ident, wxArrayString *ptparam, const wxChar *group=NULL)
#define NULL
wxArrayString * m_Pt_param
Pointer to the parameter value.
Configuration parameter - SetColor Class.
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:71
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.
COLOR4D m_Default
The default value of the parameter.
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:99
virtual void SaveParam(wxConfigBase *aConfig) const override
Function SaveParam saves the value of the parameter stored in aConfig.
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.
wxString * m_Pt_param
Pointer to the parameter value.
PARAM_CFG_SETCOLOR(const wxString &ident, COLOR4D *ptparam, COLOR4D default_val, const wxChar *group=NULL)
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:39