KiCad PCB EDA Suite
env_vars.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <env_vars.h>
21 
22 #include <map>
23 
24 #include <common.h>
25 
26 using STRING_MAP = std::map<wxString, wxString>;
27 
28 /*
29  * List of pre-defined environment variables
30  *
31  * TODO - Instead of defining these values here,
32  * extract them from elsewhere in the program
33  * (where they are originally defined)
34  */
36  "KIPRJMOD",
37  "KICAD_SYMBOL_DIR",
38  "KISYS3DMOD",
39  "KISYSMOD",
40  "KIGITHUB",
41  "KICAD_TEMPLATE_DIR",
42  "KICAD_USER_TEMPLATE_DIR",
43  "KICAD_PTEMPLATES",
44 };
45 
46 
47 bool IsEnvVarImmutable( const wxString& aEnvVar )
48 {
49  for( const auto& s: predefined_env_vars )
50  {
51  if( s == aEnvVar )
52  return true;
53  }
54 
55  return false;
56 }
57 
58 
60 {
61  return predefined_env_vars;
62 }
63 
64 
66 {
67  // Set up dynamically, as we want to be able to use _() translations,
68  // which can't be done statically
69  aMap["KISYSMOD"] =
70  _( "The base path of locally installed system "
71  "footprint libraries (.pretty folders).");
72  aMap["KISYS3DMOD"] =
73  _( "The base path of system footprint 3D shapes (.3Dshapes folders).");
74  aMap["KICAD_SYMBOL_DIR"] =
75  _( "The base path of the locally installed symbol libraries.");
76  aMap["KIGITHUB"] =
77  _( "Used by KiCad to define the URL of the repository "
78  "of the official KiCad footprint libraries.");
79  aMap["KICAD_TEMPLATE_DIR"] =
80  _( "A directory containing project templates installed with KiCad.");
81  aMap["KICAD_USER_TEMPLATE_DIR"] =
82  _( "Optional. Can be defined if you want to create your own project "
83  "templates folder.");
84  aMap["KIPRJMOD"] =
85  _("Internally defined by KiCad (cannot be edited) and is set "
86  "to the absolute path of the currently loaded project file. This environment "
87  "variable can be used to define files and paths relative to the currently loaded "
88  "project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
89  "folder containing a project specific footprint library named footprints.pretty." );
90 
91  // Deprecated vars
92  aMap["KICAD_PTEMPLATES"] =
93  _( "Deprecated version of KICAD_TEMPLATE_DIR.");
94 }
95 
96 
97 wxString LookUpEnvVarHelp( const wxString& aEnvVar )
98 {
99  static STRING_MAP env_var_help_text;
100 
101  if( env_var_help_text.size() == 0 )
102  initialiseEnvVarHelp( env_var_help_text );
103 
104  return env_var_help_text[aEnvVar];
105 }
bool IsEnvVarImmutable(const wxString &aEnvVar)
Determine if an environment variable is "predefined", i.e.
Definition: env_vars.cpp:47
const ENV_VAR_LIST & GetPredefinedEnvVars()
Get the list of pre-defined environment variables.
Definition: env_vars.cpp:59
std::vector< wxString > ENV_VAR_LIST
Definition: env_vars.h:31
static const ENV_VAR_LIST predefined_env_vars
Definition: env_vars.cpp:35
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:26
wxString LookUpEnvVarHelp(const wxString &aEnvVar)
Look up long-form help text for a given environment variable.
Definition: env_vars.cpp:97
void initialiseEnvVarHelp(STRING_MAP &aMap)
Definition: env_vars.cpp:65
The common library.
Functions to provide helpful hints about what environment vars do.