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

Go to the source code of this file.

Functions

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. More...
 
void wxConfigLoadSetups (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
 Function wxConfigLoadSetups uses aList of PARAM_CFG to load configuration values from aCfg. More...
 
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. More...
 
void wxConfigSaveSetups (wxConfigBase *aCfg, const std::vector< PARAM_CFG * > &aList)
 Function wxConfigSaveSetups writes aList of PARAM_CFG to save configuration values to aCfg. More...
 
void ConfigBaseWriteDouble (wxConfigBase *aConfig, const wxString &aKey, double aValue)
 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. More...
 

Function Documentation

◆ ConfigBaseWriteDouble()

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

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.

Definition at line 119 of file config_params.cpp.

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

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 
)

Function wxConfigLoadParams uses aList of PARAM_CFG 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 35 of file config_params.cpp.

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

◆ wxConfigLoadSetups()

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

Function wxConfigLoadSetups uses aList of PARAM_CFG 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 55 of file config_params.cpp.

56 {
57  wxASSERT( aCfg );
58 
59  for( PARAM_CFG* param : aList )
60  {
61  if( !param->m_Setup )
62  continue;
63 
64  param->ReadParam( aCfg );
65  }
66 }
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81

Referenced by ADVANCED_CFG::loadSettings().

◆ wxConfigSaveParams()

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.

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 69 of file config_params.cpp.

71 {
72  wxASSERT( aCfg );
73 
74  for( PARAM_CFG* param : aList )
75  {
76  if( !!param->m_Group )
77  aCfg->SetPath( param->m_Group );
78  else
79  aCfg->SetPath( aGroup );
80 
81  if( param->m_Setup )
82  continue;
83 
84  if( param->m_Type == PARAM_COMMAND_ERASE ) // Erase all data
85  {
86  if( !!param->m_Ident )
87  aCfg->DeleteGroup( param->m_Ident );
88  }
89  else
90  {
91  param->SaveParam( aCfg );
92  }
93  }
94 }
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81

References PARAM_COMMAND_ERASE.

◆ wxConfigSaveSetups()

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

Function wxConfigSaveSetups writes aList of PARAM_CFG to save configuration values 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 97 of file config_params.cpp.

98 {
99  wxASSERT( aCfg );
100 
101  for( PARAM_CFG* param : aList )
102  {
103  if( !param->m_Setup )
104  continue;
105 
106  if( param->m_Type == PARAM_COMMAND_ERASE ) // Erase all data
107  {
108  if( !!param->m_Ident )
109  aCfg->DeleteGroup( param->m_Ident );
110  }
111  else
112  {
113  param->SaveParam( aCfg );
114  }
115  }
116 }
PARAM_CFG is a base class which establishes the interface functions ReadParam and SaveParam,...
Definition: config_params.h:81

References PARAM_COMMAND_ERASE.