KiCad PCB EDA Suite
config_params.cpp File Reference
#include <colors.h>
#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 120 of file config_params.cpp.

121 {
122  // Use a single strategy, regardless of wx version.
123  // Want C locale float string.
124 
125  LOCALE_IO toggle;
126  wxString tnumber = wxString::Format( wxT( "%.16g" ), aValue );
127 
128  aConfig->Write( aKey, tnumber );
129 }
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: common.h:214
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 36 of file config_params.cpp.

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

Referenced by PROJECT::ConfigLoad(), DIALOG_SCHEMATIC_SETUP::OnAuxiliaryAction(), and DIALOG_BOARD_SETUP::OnAuxiliaryAction().

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

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

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

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

References PARAM_COMMAND_ERASE.

Referenced by PROJECT::ConfigSave().

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

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

References PARAM_COMMAND_ERASE.