KiCad PCB EDA Suite
Loading...
Searching...
No Matches
env_paths.h File Reference

Helper functions to substitute paths with environmental variables. More...

#include <wx/string.h>
#include <settings/environment.h>
#include <kicommon.h>

Go to the source code of this file.

Functions

wxString KICOMMON_API NormalizePath (const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const PROJECT *aProject)
 Normalize a file path to an environmental variable, if possible.
 
wxString KICOMMON_API NormalizePath (const wxFileName &aFilePath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath)
 Normalize a file path to an environmental variable, if possible.
 
wxString KICOMMON_API MakeRelativePath (const wxString &aPath, const wxString &aBaseDir)
 Express an absolute path relative to a base directory, stepping out with ".." when needed.
 
wxString KICOMMON_API NormalizePathForProject (const wxString &aPath, const ENV_VAR_MAP *aEnvVars, const wxString &aProjectPath, bool aAllowParentDirs)
 Choose how to store a path the user picked for a project.
 
wxString KICOMMON_API ResolveFile (const wxString &aFileName, const ENV_VAR_MAP *aEnvVars, const PROJECT *aProject)
 Search the default paths trying to find one with the requested file.
 

Detailed Description

Helper functions to substitute paths with environmental variables.

Definition in file env_paths.h.

Function Documentation

◆ MakeRelativePath()

wxString KICOMMON_API MakeRelativePath ( const wxString & aPath,
const wxString & aBaseDir )

Express an absolute path relative to a base directory, stepping out with ".." when needed.

The result always uses '/' separators so a path stored in a shared file works on every platform.

Parameters
aPathis the absolute file or directory path to convert.
aBaseDiris the absolute directory the result is relative to.
Returns
the relative path, "." when aPath is aBaseDir itself, or aPath unchanged when it has no relative form (relative input, empty base or a different volume).

Definition at line 152 of file env_paths.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), NormalizePathForProject(), and DIALOG_DESTINATION::onOutputPathBrowseClicked().

◆ NormalizePath() [1/2]

wxString KICOMMON_API NormalizePath ( const wxFileName & aFilePath,
const ENV_VAR_MAP * aEnvVars,
const PROJECT * aProject )

Normalize a file path to an environmental variable, if possible.

Parameters
aFilePathis the full file path (path and file name) to be normalized.
aEnvVarsis an optional map of environmental variables to try substitution with.
aProjectis an optional project, to normalize the file path to the project path.
Returns
Normalized full file path (path and file name) if succeeded or the input path if the path could not be normalized.

Definition at line 142 of file env_paths.cpp.

References PROJECT::GetProjectPath(), and NormalizePath().

◆ NormalizePath() [2/2]

wxString KICOMMON_API NormalizePath ( const wxFileName & aFilePath,
const ENV_VAR_MAP * aEnvVars,
const wxString & aProjectPath )

Normalize a file path to an environmental variable, if possible.

Parameters
aFilePathis the full file path (path and file name) to be normalized.
aEnvVarsis an optional map of environmental variables to try substitution with.
aProjectPathis an optional string to normalize the file path to the project path.
Returns
Normalized full file path (path and file name) if succeeded or the input path if the path could not be normalized.

Definition at line 73 of file env_paths.cpp.

References normalizeAbsolutePaths(), and PROJECT_VAR_NAME.

Referenced by DESIGN_BLOCK_PANE::AddDesignBlockLibrary(), PCB_BASE_EDIT_FRAME::AddLibrary(), SYMBOL_LIBRARY_MANAGER::addLibrary(), SYMBOL_EDIT_FRAME::addLibTableEntry(), PANEL_SYM_LIB_TABLE::appendLibraryRow(), BOOST_AUTO_TEST_CASE(), PANEL_DESIGN_BLOCK_LIB_TABLE::browseLibrariesHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), NormalizePath(), NormalizePathForProject(), TEXT_BUTTON_FILE_BROWSER::OnButtonClick(), PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), PANEL_DESIGN_BLOCK_LIB_TABLE::onMigrateLibraries(), PANEL_FP_LIB_TABLE::onMigrateLibraries(), and SYMBOL_EDIT_FRAME::replaceLibTableEntry().

◆ NormalizePathForProject()

wxString KICOMMON_API NormalizePathForProject ( const wxString & aPath,
const ENV_VAR_MAP * aEnvVars,
const wxString & aProjectPath,
bool aAllowParentDirs )

Choose how to store a path the user picked for a project.

A path inside the project is always made relative to it. Otherwise an environment variable substitution is preferred, then a path climbing out of the project with ".." when aAllowParentDirs is set, and finally the absolute path.

Parameters
aPathis the absolute file or directory path to store.
aEnvVarsis an optional map of environment variables to try substitution with.
aProjectPathis the absolute project directory, or empty when there is no project.
aAllowParentDirspermits a relative path that leaves the project directory.

Definition at line 170 of file env_paths.cpp.

References MakeRelativePath(), and NormalizePath().

Referenced by BOOST_AUTO_TEST_CASE(), DIALOG_DESTINATION::onOutputPathBrowseClicked(), and DIALOG_PAGES_SETTINGS::OnWksFileSelection().

◆ ResolveFile()

wxString KICOMMON_API ResolveFile ( const wxString & aFileName,
const ENV_VAR_MAP * aEnvVars,
const PROJECT * aProject )

Search the default paths trying to find one with the requested file.

Parameters
aFileNameis the name of the searched file. It might be a relative path.
aEnvVarsis an optional map of environmental variables that can contain paths.
aProjectis an optional project, to check the project path.
Returns
Full path (path and file name) if the file was found in one of the paths, otherwise an empty string.

Definition at line 207 of file env_paths.cpp.

References createFilePath(), and PROJECT::GetProjectPath().

Referenced by NETLIST_EXPORTER_SPICE::writeInclude().