forked from KiCad/kicad-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_params.h
331 lines (278 loc) · 12 KB
/
config_params.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, [email protected]
* Copyright (C) 2008-2011 Wayne Stambaugh <[email protected]>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef CONFIG_PARAMS_H_
#define CONFIG_PARAMS_H_
#include <set>
#include <limits>
#include <wx/confbase.h>
#include <wx/fileconf.h>
#include <boost/ptr_container/ptr_vector.hpp>
#include <gal/color4d.h>
using KIGFX::COLOR4D;
/**
* A helper function to write doubles in configuration file.
*
* We cannot use wxConfigBase->Write for a double, because this function uses a format with
* very few digits in mantissa and truncation issues are frequent. We use here a better
* floating format.
*
* @note Everything in this file is deprecated, it only remains because advanced_config depends on
* it for the moment.
*/
void ConfigBaseWriteDouble( wxConfigBase* aConfig, const wxString& aKey, double aValue );
/** Type of parameter in the configuration file */
enum paramcfg_id {
PARAM_INT,
PARAM_INT_WITH_SCALE,
PARAM_DOUBLE,
PARAM_BOOL,
PARAM_LIBNAME_LIST,
PARAM_WXSTRING,
PARAM_WXSTRING_SET,
PARAM_FILENAME,
PARAM_COMMAND_ERASE,
PARAM_LAYERS,
PARAM_TRACKWIDTHS,
PARAM_VIADIMENSIONS,
PARAM_DIFFPAIRDIMENSIONS,
PARAM_NETCLASSES,
PARAM_SEVERITIES
};
/**
* A base class which establishes the interface functions ReadParam and SaveParam,
* which are implemented by a number of derived classes, and these function's
* doxygen comments are inherited also.
*
* See kicad.odt or kicad.pdf, chapter 2 :
* "Installation and configuration/Initialization of the default config".
*/
class PARAM_CFG
{
public:
PARAM_CFG( const wxString& ident, const paramcfg_id type, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString );
virtual ~PARAM_CFG() {}
/**
* Read the value of the parameter stored in \a aConfig.
*
* @param aConfig the wxConfigBase that holds the parameter.
*/
virtual void ReadParam( wxConfigBase* aConfig ) const {};
/**
* Save the value of the parameter stored in \a aConfig.
*
* @param aConfig the wxConfigBase that can store the parameter.
*/
virtual void SaveParam( wxConfigBase* aConfig ) const {};
wxString m_Ident; ///< Keyword in config data
paramcfg_id m_Type; ///< Type of parameter
wxString m_Group; ///< Group name (this is like a path in the config data)
bool m_Setup; ///< Install or Project based parameter, true == install
// If the m_Ident keyword isn't found, fall back and read values from m_Ident_legacy.
// Note that values are always written to the current, non-legacy keyword.
wxString m_Ident_legacy;
};
/**
* Configuration object for integers.
*/
class PARAM_CFG_INT : public PARAM_CFG
{
public:
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_INT( bool Insetup, 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 );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
int* m_Pt_param; ///< Pointer to the parameter value
int m_Min, m_Max; ///< Minimum and maximum values of the param type
int m_Default; ///< The default value of the parameter
};
/**
* Configuration for integers with unit conversion.
*
* Mainly used to store an integer value in millimeters (or inches) and retrieve it in
* internal units. The stored value is a floating number.
*/
class PARAM_CFG_INT_WITH_SCALE : public PARAM_CFG_INT
{
public:
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 );
PARAM_CFG_INT_WITH_SCALE( bool insetup, 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 );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
public:
double m_BIU_to_cfgunit; ///< the factor to convert the saved value in internal value
};
/**
* Configuration object for double precision floating point numbers.
*/
class PARAM_CFG_DOUBLE : public PARAM_CFG
{
public:
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 );
PARAM_CFG_DOUBLE( bool Insetup, const wxString& ident, double* ptparam,
double default_val = 0.0, double min = 0.0, double max = 10000.0,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
double* m_Pt_param; ///< Pointer to the parameter value
double m_Default; ///< The default value of the parameter
double m_Min, m_Max; ///< Minimum and maximum values of the param type
};
/**
* Configuration object for booleans.
*/
class PARAM_CFG_BOOL : public PARAM_CFG
{
public:
PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
int default_val = false, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString );
PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
int default_val = false, const wxChar* group = nullptr,
const wxString& legacy_ident = wxEmptyString );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
bool* m_Pt_param; ///< Pointer to the parameter value
int m_Default; ///< The default value of the parameter
};
/**
* Configuration object for wxString objects.
*/
class PARAM_CFG_WXSTRING : public PARAM_CFG
{
public:
PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = nullptr );
PARAM_CFG_WXSTRING( bool Insetup,
const wxString& ident,
wxString* ptparam,
const wxString& default_val = wxEmptyString,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
wxString* m_Pt_param; ///< Pointer to the parameter value
wxString m_default; ///< The default value of the parameter
};
/**
* Configuration object for a set of wxString objects.
*
*/
class PARAM_CFG_WXSTRING_SET : public PARAM_CFG
{
public:
PARAM_CFG_WXSTRING_SET( const wxString& ident, std::set<wxString>* ptparam,
const wxChar* group = nullptr );
PARAM_CFG_WXSTRING_SET( bool Insetup,
const wxString& ident,
std::set<wxString>* ptparam,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
std::set<wxString>* m_Pt_param; ///< Pointer to the parameter value
};
/**
* Configuration object for a file name object.
*
* Same as #PARAM_CFG_WXSTRING but stores "\" as "/" and replace "/" by "\" under Windows.
*/
class PARAM_CFG_FILENAME : public PARAM_CFG
{
public:
PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
wxString* m_Pt_param; ///< Pointer to the parameter value
};
class PARAM_CFG_LIBNAME_LIST : public PARAM_CFG
{
public:
wxArrayString* m_Pt_param; ///< Pointer to the parameter value
public:
PARAM_CFG_LIBNAME_LIST( const wxChar* ident, wxArrayString* ptparam,
const wxChar* group = nullptr );
virtual void ReadParam( wxConfigBase* aConfig ) const override;
virtual void SaveParam( wxConfigBase* aConfig ) const override;
};
/**
* Writes @a aList of #PARAM_CFG objects to @a aCfg.
*
* Only elements with m_Setup set true will be saved, hence the function name.
*
* @param aCfg where to save.
* @param aList holds some configuration parameters, not all of which will necessarily be saved.
*/
void wxConfigSaveSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
/**
* Write @a aList of #PARAM_CFG objects @a aCfg.
*
* Only elements with m_Setup set false will be saved, hence the function name.
*
* @param aCfg where to save.
* @param aList holds some configuration parameters, not all of which will necessarily be saved.
* @param aGroup indicates in which group the value should be saved, unless the PARAM_CFG provides
* its own group, in which case it will take precedence. aGroup may be empty.
*/
void wxConfigSaveParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
const wxString& aGroup );
/**
* Use @a aList of #PARAM_CFG object to load configuration values from @a aCfg.
*
* Only elements whose m_Setup field is true will be loaded.
*
* @param aCfg where to load from.
* @param aList holds some configuration parameters, not all of which will necessarily be loaded.
*/
void wxConfigLoadSetups( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList );
/**
* Use @a aList of #PARAM_CFG objects to load configuration values from @a aCfg.
* Only elements whose m_Setup field is false will be loaded.
*
* @param aCfg where to load from.
* @param aList holds some configuration parameters, not all of which will necessarily be loaded.
* @param aGroup indicates in which group the value should be saved, unless the PARAM_CFG provides
* its own group, in which case it will take precedence. aGroup may be empty.
*/
void wxConfigLoadParams( wxConfigBase* aCfg, const std::vector<PARAM_CFG*>& aList,
const wxString& aGroup );
#endif // CONFIG_PARAMS_H_