KiCad PCB EDA Suite
config_params.cpp File Reference
#include <config_params.h>
#include <locale_io.h>
#include <gal/color4d.h>
#include <math/util.h>
#include <wx/config.h>
#include <wx/debug.h>

Go to the source code of this file.

Functions

void wxConfigLoadParams (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
 Use aList of PARAM_CFG objects to load configuration values from aCfg. More...
 
void wxConfigLoadSetups (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
 Use aList of PARAM_CFG object to load configuration values from aCfg. More...
 
void wxConfigSaveParams (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList, const wxString &aGroup)
 Write aList of PARAM_CFG objects aCfg. More...
 
void wxConfigSaveSetups (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
 Writes aList of PARAM_CFG objects to aCfg. More...
 
void ConfigBaseWriteDouble (wxConfigBase *aConfig, const wxString &aKey, double aValue)
 A helper function to write doubles in configuration file. More...
 

Function Documentation

◆ ConfigBaseWriteDouble()

void ConfigBaseWriteDouble ( wxConfigBase *  aConfig,
const wxString &  aKey,
double  aValue 
)

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.

Definition at line 118 of file config_params.cpp.

119{
120 // Use a single strategy, regardless of wx version.
121 // Want C locale float string.
122
123 LOCALE_IO toggle;
124 wxString tnumber = wxString::Format( wxT( "%.16g" ), aValue );
125
126 aConfig->Write( aKey, tnumber );
127}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format().

Referenced by PARAM_CFG_INT_WITH_SCALE::SaveParam(), and PARAM_CFG_DOUBLE::SaveParam().

◆ wxConfigLoadParams()

void wxConfigLoadParams ( wxConfigBase *  aCfg,
const std::vector< PARAM_CFG * > &  aList,
const wxString &  aGroup 
)

Use aList of PARAM_CFG objects to load configuration values from aCfg.

Only elements whose m_Setup field is false will be loaded.

Parameters
aCfgwhere to load from.
aListholds some configuration parameters, not all of which will necessarily be loaded.
aGroupindicates 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.

Definition at line 34 of file config_params.cpp.

36{
37 wxASSERT( aCfg );
38
39 for( PARAM_CFG* param : aList )
40 {
41 if( !!param->m_Group )
42 aCfg->SetPath( param->m_Group );
43 else
44 aCfg->SetPath( aGroup );
45
46 if( param->m_Setup )
47 continue;
48
49 param->ReadParam( aCfg );
50 }
51}
A base class which establishes the interface functions ReadParam and SaveParam, which are implemented...
Definition: config_params.h:82

◆ wxConfigLoadSetups()

void wxConfigLoadSetups ( wxConfigBase *  aCfg,
const std::vector< PARAM_CFG * > &  aList 
)

Use aList of PARAM_CFG object to load configuration values from aCfg.

Only elements whose m_Setup field is true will be loaded.

Parameters
aCfgwhere to load from.
aListholds some configuration parameters, not all of which will necessarily be loaded.

Definition at line 54 of file config_params.cpp.

55{
56 wxASSERT( aCfg );
57
58 for( PARAM_CFG* param : aList )
59 {
60 if( !param->m_Setup )
61 continue;
62
63 param->ReadParam( aCfg );
64 }
65}

Referenced by ADVANCED_CFG::loadSettings().

◆ wxConfigSaveParams()

void wxConfigSaveParams ( wxConfigBase *  aCfg,
const std::vector< PARAM_CFG * > &  aList,
const wxString &  aGroup 
)

Write aList of PARAM_CFG objects aCfg.

Only elements with m_Setup set false will be saved, hence the function name.

Parameters
aCfgwhere to save.
aListholds some configuration parameters, not all of which will necessarily be saved.
aGroupindicates 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.

Definition at line 68 of file config_params.cpp.

70{
71 wxASSERT( aCfg );
72
73 for( PARAM_CFG* param : aList )
74 {
75 if( !!param->m_Group )
76 aCfg->SetPath( param->m_Group );
77 else
78 aCfg->SetPath( aGroup );
79
80 if( param->m_Setup )
81 continue;
82
83 if( param->m_Type == PARAM_COMMAND_ERASE ) // Erase all data
84 {
85 if( !!param->m_Ident )
86 aCfg->DeleteGroup( param->m_Ident );
87 }
88 else
89 {
90 param->SaveParam( aCfg );
91 }
92 }
93}
@ PARAM_COMMAND_ERASE
Definition: config_params.h:63

References PARAM_COMMAND_ERASE.

◆ wxConfigSaveSetups()

void wxConfigSaveSetups ( wxConfigBase *  aCfg,
const std::vector< PARAM_CFG * > &  aList 
)

Writes aList of PARAM_CFG objects to aCfg.

Only elements with m_Setup set true will be saved, hence the function name.

Parameters
aCfgwhere to save.
aListholds some configuration parameters, not all of which will necessarily be saved.

Definition at line 96 of file config_params.cpp.

97{
98 wxASSERT( aCfg );
99
100 for( PARAM_CFG* param : aList )
101 {
102 if( !param->m_Setup )
103 continue;
104
105 if( param->m_Type == PARAM_COMMAND_ERASE ) // Erase all data
106 {
107 if( !!param->m_Ident )
108 aCfg->DeleteGroup( param->m_Ident );
109 }
110 else
111 {
112 param->SaveParam( aCfg );
113 }
114 }
115}

References PARAM_COMMAND_ERASE.