summaryrefslogtreecommitdiff
path: root/include/config_params.h
blob: 16cd089baba61a981c31ab62147f89e00a0d2144 (plain)
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#ifndef CONFIG_PARAMS_H_
#define CONFIG_PARAMS_H_
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
 * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2011 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
 */

/**
 * The common library
 * @file config_params.h
 */

#include <wx/confbase.h>
#include <wx/fileconf.h>
#include <boost/ptr_container/ptr_vector.hpp>
#include <colors.h>
#include <limits>

/// Names of sub sections where to store project info in *.pro project config files
#define GROUP_PCB           wxT( "/pcbnew" )            /// parameters for Pcbnew/Modedit
#define GROUP_SCH           wxT( "/eeschema" )          /// library list and lib paths list
#define GROUP_SCH_EDITOR    wxT( "/schematic_editor" )  /// parameters for schematic editor
                                                        /// (and few for component editor).
                                                        /// Does not store libs list
#define GROUP_PCB_LIBS      wxT( "/pcbnew/libraries" )  /// PCB library list, should be removed soon
                                                        /// (Now in fp lib tables)
#define GROUP_SCH_LIBS      wxT( "/eeschema/libraries" )    /// library list section

#define GROUP_CVP           wxT("/cvpcb")
#define GROUP_CVP_EQU       wxT("/cvpcb/equfiles")


#define CONFIG_VERSION      1


/**
 * Function ConfigBaseWriteDouble
 * This is a helper function to write doubles in config
 * 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.
 */
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_SETCOLOR,
    PARAM_DOUBLE,
    PARAM_BOOL,
    PARAM_LIBNAME_LIST,
    PARAM_WXSTRING,
    PARAM_FILENAME,
    PARAM_COMMAND_ERASE,
    PARAM_FIELDNAME_LIST
};


/**
 * Class PARAM_CFG_BASE
 * is 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.
 * <p>
 * See kicad.odt or kicad.pdf, chapter 2 :
 * "Installation and configuration/Initialization of the default config".
 */
class PARAM_CFG_BASE
{
public:
    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

public:
    PARAM_CFG_BASE( const wxString& ident, const paramcfg_id type,
                const wxChar* group = NULL );
    virtual ~PARAM_CFG_BASE() {}

    /**
     * Function ReadParam
     * reads the value of the parameter stored in aConfig
     * @param aConfig = the wxConfigBase that holds the parameter
     */
    virtual void ReadParam( wxConfigBase* aConfig ) const {};

    /**
     * Function SaveParam
     * saves the value of the parameter stored in aConfig
     * @param aConfig = the wxConfigBase that can store the parameter
     */
    virtual void SaveParam( wxConfigBase* aConfig ) const {};
};


/**
 * Configuration parameter - Integer Class
 *
 */
class PARAM_CFG_INT      : public PARAM_CFG_BASE
{
public:
    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

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 = NULL );
    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 = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};

/**
 * Configuration parameter - Integer Class
 * 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:
    double  m_BIU_to_cfgunit;   ///<  the factor to convert the saved value in internal value

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 = NULL,
                       double aBiu2cfgunit = 1.0);
    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 = NULL,
                   double aBiu2cfgunit = 1.0 );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/**
 * Configuration parameter - SetColor Class
 *
 */
class PARAM_CFG_SETCOLOR : public PARAM_CFG_BASE
{
public:
    EDA_COLOR_T* m_Pt_param;    ///<  Pointer to the parameter value
    EDA_COLOR_T  m_Default;     ///<  The default value of the parameter

public:
    PARAM_CFG_SETCOLOR( const wxString& ident, EDA_COLOR_T* ptparam,
                        EDA_COLOR_T default_val, const wxChar* group = NULL );
    PARAM_CFG_SETCOLOR( bool Insetup, const wxString& ident, EDA_COLOR_T* ptparam,
                        EDA_COLOR_T default_val, const wxChar* group = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/**
 * Configuration parameter - Double Precision Class
 *
 */
class PARAM_CFG_DOUBLE   : public PARAM_CFG_BASE
{
public:
    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

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 = NULL );
    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 = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/**
 * Configuration parameter - Boolean Class
 *
 */
class PARAM_CFG_BOOL     : public PARAM_CFG_BASE
{
public:
    bool* m_Pt_param;       ///<  Pointer to the parameter value
    int   m_Default;        ///<  The default value of the parameter

public:
    PARAM_CFG_BOOL( const wxString& ident, bool* ptparam,
                        int default_val = false, const wxChar* group = NULL );
    PARAM_CFG_BOOL( bool Insetup, const wxString& ident, bool* ptparam,
                    int default_val = false, const wxChar* group = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/**
 * Configuration parameter - wxString Class
 *
 */
class PARAM_CFG_WXSTRING : public PARAM_CFG_BASE
{
public:
    wxString* m_Pt_param;       ///<  Pointer to the parameter value
    wxString  m_default;        ///<  The default value of the parameter

public:
    PARAM_CFG_WXSTRING( const wxString& ident, wxString* ptparam, const wxChar* group = NULL );

    PARAM_CFG_WXSTRING( bool            Insetup,
                        const wxString& ident,
                        wxString*       ptparam,
                        const wxString& default_val = wxEmptyString,
                        const wxChar* group = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/**
 * Configuration parameter - PARAM_CFG_FILENAME Class
 * Same as PARAM_CFG_WXSTRING, but stores "\" as "/".
 * and replace "/" by "\" under Windows.
 * Used to store paths and filenames in config files
 */
class PARAM_CFG_FILENAME     : public PARAM_CFG_BASE
{
public:
    wxString* m_Pt_param;    ///<  Pointer to the parameter value

public:
    PARAM_CFG_FILENAME( const wxString& ident, wxString* ptparam,
            const wxChar* group = NULL );
    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


class PARAM_CFG_LIBNAME_LIST : public PARAM_CFG_BASE
{
public:
    wxArrayString* m_Pt_param;     ///<  Pointer to the parameter value

public:
    PARAM_CFG_LIBNAME_LIST( const wxChar*  ident,
                                wxArrayString* ptparam,
                                const wxChar*  group = NULL );

    virtual void ReadParam( wxConfigBase* aConfig ) const;
    virtual void SaveParam( wxConfigBase* aConfig ) const;
};


/** A list of parameters type */
//typedef boost::ptr_vector<PARAM_CFG_BASE> PARAM_CFG_ARRAY;
class  PARAM_CFG_ARRAY : public boost::ptr_vector<PARAM_CFG_BASE>
{
};


/**
 * Function wxConfigSaveSetups
 * writes @a aList of PARAM_CFG_ARRAY elements to save configuration values
 * 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 PARAM_CFG_ARRAY& aList );

/**
 * Function wxConfigSaveParams
 * writes @a aList of PARAM_CFG_ARRAY elements to save configuration values
 * to @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_ARRAY element provides its own group, in which case it will
 *  take precedence.  aGroup may be empty.
 */
void wxConfigSaveParams( wxConfigBase* aCfg,
            const PARAM_CFG_ARRAY& aList, const wxString& aGroup );

/**
 * Function wxConfigLoadSetups
 * uses @a aList of PARAM_CFG_ARRAY elements 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 PARAM_CFG_ARRAY& aList );

/**
 * Function wxConfigLoadParams
 * uses @a aList of PARAM_CFG_ARRAY elements 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_ARRAY element provides its own group, in which case it will
 *  take precedence.  aGroup may be empty.
 */
void wxConfigLoadParams( wxConfigBase* aCfg,
        const PARAM_CFG_ARRAY& aList, const wxString& aGroup );


#endif  // CONFIG_PARAMS_H_