KiCad PCB EDA Suite
env_vars.cpp File Reference
#include <env_vars.h>
#include <map>
#include <wx/translation.h>
#include <wx/utils.h>

Go to the source code of this file.

Typedefs

using STRING_MAP = std::map< wxString, wxString >
 

Functions

bool IsEnvVarImmutable (const wxString &aEnvVar)
 Determine if an environment variable is "predefined", i.e. More...
 
const ENV_VAR_LISTGetPredefinedEnvVars ()
 Get the list of pre-defined environment variables. More...
 
void initialiseEnvVarHelp (STRING_MAP &aMap)
 
wxString LookUpEnvVarHelp (const wxString &aEnvVar)
 Look up long-form help text for a given environment variable. More...
 
template<>
OPT< double > GetEnvVar (const wxString &aEnvVarName)
 Get an environment variable as a specific type, if set correctly. More...
 
template<>
OPT< wxString > GetEnvVar (const wxString &aEnvVarName)
 Get an environment variable as a specific type, if set correctly. More...
 

Variables

static const ENV_VAR_LIST predefined_env_vars
 

Typedef Documentation

◆ STRING_MAP

using STRING_MAP = std::map<wxString, wxString>

Definition at line 27 of file env_vars.cpp.

Function Documentation

◆ GetEnvVar() [1/2]

template<>
OPT<double> GetEnvVar ( const wxString &  aEnvVarName)

Get an environment variable as a specific type, if set correctly.

Get a double from an environment variable, if set.

Get a string environment variable, if it is set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable, otherwise empty.

Definition at line 116 of file env_vars.cpp.

117 {
118  OPT<double> opt_value;
119 
120  wxString env;
121  if( wxGetEnv( aEnvVarName, &env ) )
122  {
123  double value;
124  if( env.ToDouble( &value ) )
125  {
126  opt_value = value;
127  }
128  }
129 
130  return opt_value;
131 }
boost::optional< T > OPT
Definition: optional.h:7

◆ GetEnvVar() [2/2]

template<>
OPT<wxString> GetEnvVar ( const wxString &  aEnvVarName)

Get an environment variable as a specific type, if set correctly.

Get a double from an environment variable, if set.

Get a string environment variable, if it is set.

Parameters
aEnvVarNamethe name of the environment variable
Returns
an OPT containing the value, if set and parseable, otherwise empty.

Definition at line 134 of file env_vars.cpp.

135 {
136  OPT<wxString> opt_value;
137 
138  wxString env;
139  if( wxGetEnv( aEnvVarName, &env ) )
140  {
141  opt_value = env;
142  }
143 
144  return opt_value;
145 }
boost::optional< T > OPT
Definition: optional.h:7

◆ GetPredefinedEnvVars()

const ENV_VAR_LIST& GetPredefinedEnvVars ( )

Get the list of pre-defined environment variables.

Definition at line 59 of file env_vars.cpp.

60 {
61  return predefined_env_vars;
62 }
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:36

References predefined_env_vars.

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().

◆ initialiseEnvVarHelp()

void initialiseEnvVarHelp ( STRING_MAP aMap)

Definition at line 65 of file env_vars.cpp.

66 {
67  // Set up dynamically, as we want to be able to use _() translations,
68  // which can't be done statically
69  aMap["KICAD6_FOOTPRINT_DIR"] =
70  _( "The base path of locally installed system "
71  "footprint libraries (.pretty folders).");
72  aMap["KICAD6_3DMODEL_DIR"] =
73  _( "The base path of system footprint 3D shapes (.3Dshapes folders).");
74  aMap["KICAD6_SYMBOL_DIR"] =
75  _( "The base path of the locally installed symbol libraries.");
76  aMap["KICAD6_TEMPLATE_DIR"] =
77  _( "A directory containing project templates installed with KiCad.");
78  aMap["KICAD_USER_TEMPLATE_DIR"] =
79  _( "Optional. Can be defined if you want to create your own project "
80  "templates folder.");
81  aMap["KIPRJMOD"] =
82  _("Internally defined by KiCad (cannot be edited) and is set "
83  "to the absolute path of the currently loaded project file. This environment "
84  "variable can be used to define files and paths relative to the currently loaded "
85  "project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
86  "folder containing a project specific footprint library named footprints.pretty." );
87  aMap["KICAD6_SCRIPTING_DIR"] =
88  _( "A directory containing system-wide scripts installed with KiCad" );
89  aMap["KICAD6_USER_SCRIPTING_DIR"] =
90  _( "A directory containing user-specific scripts installed with KiCad" );
91 
92  // Deprecated vars
93  aMap["KICAD_PTEMPLATES"] =
94  _( "Deprecated version of KICAD_TEMPLATE_DIR.");
95  aMap["KISYS3DMOD"] =
96  _( "Deprecated version of KICAD6_3DMODEL_DIR." );
97  aMap["KISYSMOD"] =
98  _( "Deprecated version of KICAD6_FOOTPRINT_DIR." );
99  aMap["KICAD_SYMBOL_DIR"] =
100  _( "Deprecated version of KICAD_SYMBOL_DIR.");
101 }
#define _(s)
Definition: 3d_actions.cpp:33

References _.

Referenced by LookUpEnvVarHelp().

◆ IsEnvVarImmutable()

bool IsEnvVarImmutable ( const wxString &  aEnvVar)

Determine if an environment variable is "predefined", i.e.

if the name of the variable is special to KiCad, and isn't just a user-specified substitution name.

Parameters
aEnvVarthe variable to check
Returns
true if predefined

Definition at line 47 of file env_vars.cpp.

48 {
49  for( const auto& s: predefined_env_vars )
50  {
51  if( s == aEnvVar )
52  return true;
53  }
54 
55  return false;
56 }
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:36

References predefined_env_vars.

Referenced by DIALOG_CONFIGURE_PATHS::AppendEnvVar(), and DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar().

◆ LookUpEnvVarHelp()

wxString LookUpEnvVarHelp ( const wxString &  aEnvVar)

Look up long-form help text for a given environment variable.

This is intended for use in more verbose help resources (as opposed to tooltip text)

Parameters
aEnvVarThe variable to look up
Returns
A string with help for that variable. Empty if no help available for this variable.

Definition at line 104 of file env_vars.cpp.

105 {
106  static STRING_MAP env_var_help_text;
107 
108  if( env_var_help_text.size() == 0 )
109  initialiseEnvVarHelp( env_var_help_text );
110 
111  return env_var_help_text[aEnvVar];
112 }
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:27
void initialiseEnvVarHelp(STRING_MAP &aMap)
Definition: env_vars.cpp:65

References initialiseEnvVarHelp().

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().

Variable Documentation

◆ predefined_env_vars

const ENV_VAR_LIST predefined_env_vars
static
Initial value:
= {
"KIPRJMOD",
"KICAD6_SYMBOL_DIR",
"KICAD6_3DMODEL_DIR",
"KICAD6_FOOTPRINT_DIR",
"KICAD6_TEMPLATE_DIR",
"KICAD_USER_TEMPLATE_DIR",
"KICAD_PTEMPLATES",
}

Definition at line 36 of file env_vars.cpp.

Referenced by GetPredefinedEnvVars(), and IsEnvVarImmutable().