@ -20,6 +20,7 @@
# include <build_version.h>
# include <env_vars.h>
# include <settings/environment.h>
# include <core/kicad_algo.h>
# include <map>
@ -27,15 +28,13 @@
# include <wx/translation.h>
# include <wx/utils.h>
using STRING_MAP = std : : map < wxString , wxString > ;
/**
* List of pre - defined environment variables .
*
* @ todo Instead of defining these values here , extract them from elsewhere in the program
* ( where they are originally defined ) .
*/
static const ENV_VAR : : ENV_VAR_LIST predefinedEnvVars = {
static const std : : vector < wxString > predefinedEnvVars = {
wxS ( " KIPRJMOD " ) ,
ENV_VAR : : GetVersionedEnvVarName ( wxS ( " SYMBOL_DIR " ) ) ,
ENV_VAR : : GetVersionedEnvVarName ( wxS ( " 3DMODEL_DIR " ) ) ,
@ -65,12 +64,22 @@ bool ENV_VAR::IsEnvVarImmutable( const wxString& aEnvVar )
}
const ENV_VAR : : ENV_VAR_LIST & ENV_VAR : : GetPredefinedEnvVars ( )
const std : : vector < wxString > & ENV_VAR : : GetPredefinedEnvVars ( )
{
return predefinedEnvVars ;
}
void ENV_VAR : : GetEnvVarAutocompleteTokens ( wxArrayString * aVars )
{
for ( const wxString & var : ENV_VAR : : GetPredefinedEnvVars ( ) )
{
if ( ! alg : : contains ( * aVars , var ) )
aVars - > push_back ( var ) ;
}
}
wxString ENV_VAR : : GetVersionedEnvVarName ( const wxString & aBaseName )
{
int version = 0 ;
@ -100,43 +109,46 @@ std::optional<wxString> ENV_VAR::GetVersionedEnvVarValue( const ENV_VAR_MAP& aMa
}
static void initialiseEnvVarHelp ( STRING_MAP & aMap )
static void initialiseEnvVarHelp ( std : : map < wxString , wxString > & aMap )
{
// Set up dynamically, as we want to be able to use _() translations,
// which can't be done statically
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " FOOTPRINT_DIR " ) ) ] =
_ ( " The base path of locally installed system "
" footprint libraries (.pretty folders). " ) ;
_ ( " The base path of locally installed system footprint libraries (.pretty folders). " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " 3DMODEL_DIR " ) ) ] =
_ ( " The base path of system footprint 3D shapes (.3Dshapes folders). " ) ;
_ ( " The base path of system footprint 3D shapes (.3Dshapes folders). " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " SYMBOL_DIR " ) ) ] =
_ ( " The base path of the locally installed symbol libraries. " ) ;
_ ( " The base path of the locally installed symbol libraries. " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " TEMPLATE_DIR " ) ) ] =
_ ( " A directory containing project templates installed with KiCad. " ) ;
_ ( " A directory containing project templates installed with KiCad. " ) ;
aMap [ wxS ( " KICAD_USER_TEMPLATE_DIR " ) ] =
_ ( " Optional. Can be defined if you want to create your own project "
" templates folder. " ) ;
_ ( " Optional. Can be defined if you want to create your own project templates folder. " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " 3RD_PARTY " ) ) ] =
_ ( " A directory containing 3rd party plugins, libraries and other "
" downloadable content. " ) ;
_ ( " A directory containing 3rd party plugins, libraries and other downloadable content. " ) ;
aMap [ wxS ( " KIPRJMOD " ) ] =
_ ( " Internally defined by KiCad (cannot be edited) and is set "
" to the absolute path of the currently loaded project file. This environment "
" variable can be used to define files and paths relative to the currently loaded "
" project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be defined as a "
" folder containing a project specific footprint library named footprints.pretty. " ) ;
_ ( " Internally defined by KiCad (cannot be edited) and is set to the absolute path of the currently "
" loaded project file. This environment variable can be used to define files and paths relative "
" to the currently loaded project. For instance, ${KIPRJMOD}/libs/footprints.pretty can be "
" defined as a folder containing a project specific footprint library named footprints.pretty. " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " SCRIPTING_DIR " ) ) ] =
_ ( " A directory containing system-wide scripts installed with KiCad " ) ;
_ ( " A directory containing system-wide scripts installed with KiCad. " ) ;
aMap [ ENV_VAR : : GetVersionedEnvVarName ( wxS ( " USER_SCRIPTING_DIR " ) ) ] =
_ ( " A directory containing user-specific scripts installed with KiCad " ) ;
_ ( " A directory containing user-specific scripts installed with KiCad. " ) ;
// Deprecated vars
# define DEP( var ) wxString::Format( _( "Deprecated version of %s." ), var )
aMap [ wxS ( " KICAD_PTEMPLATES " ) ] =
DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " TEMPLATE_DIR " ) ) ) ;
aMap [ wxS ( " KISYS3DMOD " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " 3DMODEL_DIR " ) ) ) ;
aMap [ wxS ( " KISYSMOD " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " FOOTPRINT_DIR " ) ) ) ;
aMap [ wxS ( " KICAD_PTEMPLATES " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " TEMPLATE_DIR " ) ) ) ;
aMap [ wxS ( " KISYS3DMOD " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " 3DMODEL_DIR " ) ) ) ;
aMap [ wxS ( " KISYSMOD " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " FOOTPRINT_DIR " ) ) ) ;
aMap [ wxS ( " KICAD_SYMBOL_DIR " ) ] = DEP ( ENV_VAR : : GetVersionedEnvVarName ( wxS ( " SYMBOL_DIR " ) ) ) ;
# undef DEP
@ -145,7 +157,7 @@ static void initialiseEnvVarHelp( STRING_MAP& aMap )
wxString ENV_VAR : : LookUpEnvVarHelp ( const wxString & aEnvVar )
{
static STRING_MAP envVarHelpText ;
static std : : map < wxString , wxString > envVarHelpText ;
if ( envVarHelpText . size ( ) = = 0 )
initialiseEnvVarHelp ( envVarHelpText ) ;
@ -175,13 +187,10 @@ template<>
std : : optional < wxString > ENV_VAR : : GetEnvVar ( const wxString & aEnvVarName )
{
std : : optional < wxString > optValue ;
wxString env ;
wxString env ;
if ( wxGetEnv ( aEnvVarName , & env ) )
{
optValue = env ;
}
return optValue ;
}