KiCad PCB EDA Suite
env_vars.cpp File Reference
#include <env_vars.h>
#include <map>
#include <common.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 28 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 111 of file env_vars.cpp.

112 {
113  OPT<double> opt_value;
114 
115  wxString env;
116  if( wxGetEnv( aEnvVarName, &env ) )
117  {
118  double value;
119  if( env.ToDouble( &value ) )
120  {
121  opt_value = value;
122  }
123  }
124 
125  return opt_value;
126 }
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 129 of file env_vars.cpp.

130 {
131  OPT<wxString> opt_value;
132 
133  wxString env;
134  if( wxGetEnv( aEnvVarName, &env ) )
135  {
136  opt_value = env;
137  }
138 
139  return opt_value;
140 }
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 61 of file env_vars.cpp.

62 {
63  return predefined_env_vars;
64 }
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:37

References predefined_env_vars.

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().

◆ initialiseEnvVarHelp()

void initialiseEnvVarHelp ( STRING_MAP aMap)

Definition at line 67 of file env_vars.cpp.

68 {
69  // Set up dynamically, as we want to be able to use _() translations,
70  // which can't be done statically
71  aMap["KISYSMOD"] =
72  _( "The base path of locally installed system "
73  "footprint libraries (.pretty folders).");
74  aMap["KISYS3DMOD"] =
75  _( "The base path of system footprint 3D shapes (.3Dshapes folders).");
76  aMap["KICAD_SYMBOL_DIR"] =
77  _( "The base path of the locally installed symbol libraries.");
78  aMap["KIGITHUB"] =
79  _( "Used by KiCad to define the URL of the repository "
80  "of the official KiCad footprint libraries.");
81  aMap["KICAD_TEMPLATE_DIR"] =
82  _( "A directory containing project templates installed with KiCad.");
83  aMap["KICAD_USER_TEMPLATE_DIR"] =
84  _( "Optional. Can be defined if you want to create your own project "
85  "templates folder.");
86  aMap["KIPRJMOD"] =
87  _("Internally defined by KiCad (cannot be edited) and is set "
88  "to the absolute path of the currently loaded project file. This environment "
89  "variable can be used to define files and paths relative to the currently loaded "
90  "project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
91  "folder containing a project specific footprint library named footprints.pretty." );
92 
93  // Deprecated vars
94  aMap["KICAD_PTEMPLATES"] =
95  _( "Deprecated version of KICAD_TEMPLATE_DIR.");
96 }
#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 49 of file env_vars.cpp.

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

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 99 of file env_vars.cpp.

100 {
101  static STRING_MAP env_var_help_text;
102 
103  if( env_var_help_text.size() == 0 )
104  initialiseEnvVarHelp( env_var_help_text );
105 
106  return env_var_help_text[aEnvVar];
107 }
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:28
void initialiseEnvVarHelp(STRING_MAP &aMap)
Definition: env_vars.cpp:67

References initialiseEnvVarHelp().

Referenced by DIALOG_CONFIGURE_PATHS::OnHelp().

Variable Documentation

◆ predefined_env_vars

const ENV_VAR_LIST predefined_env_vars
static
Initial value:
= {
"KIPRJMOD",
"KICAD_SYMBOL_DIR",
"KISYS3DMOD",
"KISYSMOD",
"KIGITHUB",
"KICAD_TEMPLATE_DIR",
"KICAD_USER_TEMPLATE_DIR",
"KICAD_PTEMPLATES",
}

Definition at line 37 of file env_vars.cpp.

Referenced by GetPredefinedEnvVars(), and IsEnvVarImmutable().