![]() |
KiCad PCB EDA Suite
|
Provide an extensible class to resolve 3D model paths. More...
#include <filename_resolver.h>
Public Member Functions | |
FILENAME_RESOLVER () | |
bool | Set3DConfigDir (const wxString &aConfigDir) |
Set the user's configuration directory for 3D models. More... | |
bool | SetProject (PROJECT *aProject, bool *flgChanged=nullptr) |
Set the current KiCad project directory as the first entry in the model path list. More... | |
wxString | GetProjectDir (void) |
void | SetProgramBase (PGM_BASE *aBase) |
Set a pointer to the application's PGM_BASE instance used to extract the local env vars. More... | |
bool | UpdatePathList (std::vector< SEARCH_PATH > &aPathList) |
Clear the current path list and substitutes the given path list and update the path configuration file on success. More... | |
wxString | ResolvePath (const wxString &aFileName) |
Determines the full path of the given file name. More... | |
wxString | ShortenPath (const wxString &aFullPathName) |
Produce a relative path based on the existing search directories or returns the same path if the path is not a superset of an existing search path. More... | |
const std::list< SEARCH_PATH > * | GetPaths (void) |
Return a pointer to the internal path list; the items in:load. More... | |
bool | SplitAlias (const wxString &aFileName, wxString &anAlias, wxString &aRelPath) |
Return true if the given name contains an alias and populates the string anAlias with the alias and aRelPath with the relative path. More... | |
bool | ValidateFileName (const wxString &aFileName, bool &hasAlias) |
Returns true if the given path is a valid aliased relative path. More... | |
bool | GetKicadPaths (std::list< wxString > &paths) |
Return a list of path environment variables local to KiCad. More... | |
Private Member Functions | |
bool | createPathList (void) |
Build the path list using available information such as KICAD6_3DMODEL_DIR and the 3d_path_list configuration file. More... | |
bool | addPath (const SEARCH_PATH &aPath) |
Check that a path is valid and adds it to the search list. More... | |
bool | readPathList (void) |
Read a list of path names from a configuration file. More... | |
bool | writePathList (void) |
Write the current path list to a configuration file. More... | |
void | checkEnvVarPath (const wxString &aPath) |
Check the ${ENV_VAR} component of a path and adds it to the resolver's path list if it is not yet in the list. More... | |
Private Attributes | |
wxString | m_configDir |
std::list< SEARCH_PATH > | m_paths |
int | m_errflags |
PGM_BASE * | m_pgm |
PROJECT * | m_project |
wxString | m_curProjDir |
Provide an extensible class to resolve 3D model paths.
Initially the legacy behavior will be implemented and an incomplete path would be checked against the project directory or the KICAD6_3DMODEL_DIR environment variable. In the future a configurable set of search paths may be specified.
Definition at line 55 of file filename_resolver.h.
FILENAME_RESOLVER::FILENAME_RESOLVER | ( | ) |
|
private |
Check that a path is valid and adds it to the search list.
aPath | is the alias set to be checked and added. |
Definition at line 426 of file filename_resolver.cpp.
References _, ExpandEnvVarSubstitutions(), SEARCH_PATH::m_Alias, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, m_project, and mutex_resolver.
Referenced by readPathList(), and UpdatePathList().
|
private |
Check the ${ENV_VAR} component of a path and adds it to the resolver's path list if it is not yet in the list.
Definition at line 674 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), SEARCH_PATH::m_Alias, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, and m_project.
Referenced by ResolvePath().
|
private |
Build the path list using available information such as KICAD6_3DMODEL_DIR and the 3d_path_list configuration file.
Definition at line 158 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), GetKicadPaths(), SEARCH_PATH::m_Alias, m_configDir, m_curProjDir, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, m_project, MASK_3D_RESOLVER, and readPathList().
Referenced by ResolvePath(), Set3DConfigDir(), SetProgramBase(), and ShortenPath().
bool FILENAME_RESOLVER::GetKicadPaths | ( | std::list< wxString > & | paths | ) |
Return a list of path environment variables local to KiCad.
This list always includes KICAD6_3DMODEL_DIR even if it is not defined locally.
Definition at line 1008 of file filename_resolver.cpp.
References PGM_BASE::GetLocalEnvVariables(), and m_pgm.
Referenced by createPathList().
const std::list< SEARCH_PATH > * FILENAME_RESOLVER::GetPaths | ( | void | ) |
Return a pointer to the internal path list; the items in:load.
The list can be used to set up the list of search paths available to a 3D file browser.
Definition at line 825 of file filename_resolver.cpp.
References m_paths.
Referenced by DIALOG_CONFIGURE_PATHS::TransferDataToWindow(), and DLG_SELECT_3DMODEL::updateDirChoiceList().
wxString FILENAME_RESOLVER::GetProjectDir | ( | void | ) |
|
private |
Read a list of path names from a configuration file.
Definition at line 503 of file filename_resolver.cpp.
References addPath(), CFGFILE_VERSION, getHollerith(), SEARCH_PATH::m_Alias, m_configDir, SEARCH_PATH::m_Description, m_paths, SEARCH_PATH::m_Pathvar, MASK_3D_RESOLVER, RESOLVER_CONFIG, and writePathList().
Referenced by createPathList().
wxString FILENAME_RESOLVER::ResolvePath | ( | const wxString & | aFileName | ) |
Determines the full path of the given file name.
In the future remote files may be supported, in which case it is best to require a full URI in which case ResolvePath should check that the URI conforms to RFC-2396 and related documents and copies aFileName into aResolvedName if the URI is valid.
Definition at line 243 of file filename_resolver.cpp.
References checkEnvVarPath(), createPathList(), ERRFLG_ALIAS, ERRFLG_ENVPATH, ERRFLG_RELPATH, ExpandEnvVarSubstitutions(), m_errflags, m_paths, m_project, mutex_resolver, SplitAlias(), and tracePathsAndFiles.
Referenced by export_vrml_footprint(), idf_export_footprint(), and S3D_CACHE::load().
bool FILENAME_RESOLVER::Set3DConfigDir | ( | const wxString & | aConfigDir | ) |
Set the user's configuration directory for 3D models.
aConfigDir |
Definition at line 61 of file filename_resolver.cpp.
References createPathList(), ExpandEnvVarSubstitutions(), m_configDir, and m_project.
Referenced by S3D_CACHE::Set3DConfigDir().
void FILENAME_RESOLVER::SetProgramBase | ( | PGM_BASE * | aBase | ) |
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
Definition at line 145 of file filename_resolver.cpp.
References createPathList(), m_paths, and m_pgm.
Referenced by S3D_CACHE::SetProgramBase().
bool FILENAME_RESOLVER::SetProject | ( | PROJECT * | aProject, |
bool * | flgChanged = nullptr |
||
) |
Set the current KiCad project directory as the first entry in the model path list.
[in] | aProjDir | current project directory |
[out] | flgChanged | optional, set to true if directory was changed |
true | success |
false | failure |
Definition at line 80 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), PROJECT::GetProjectPath(), SEARCH_PATH::m_Alias, m_curProjDir, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, m_project, and MASK_3D_RESOLVER.
Referenced by S3D_CACHE::SetProject().
wxString FILENAME_RESOLVER::ShortenPath | ( | const wxString & | aFullPathName | ) |
Produce a relative path based on the existing search directories or returns the same path if the path is not a superset of an existing search path.
aFullPathName | is an absolute path to shorten. |
Definition at line 734 of file filename_resolver.cpp.
References createPathList(), ExpandEnvVarSubstitutions(), m_paths, m_project, and mutex_resolver.
Referenced by DLG_SELECT_3DMODEL::TransferDataFromWindow().
bool FILENAME_RESOLVER::SplitAlias | ( | const wxString & | aFileName, |
wxString & | anAlias, | ||
wxString & | aRelPath | ||
) |
Return true if the given name contains an alias and populates the string anAlias with the alias and aRelPath with the relative path.
Definition at line 831 of file filename_resolver.cpp.
Referenced by DIALOG_FOOTPRINT_FP_EDITOR::OnAdd3DModel(), DIALOG_FOOTPRINT_PROPERTIES::OnAdd3DModel(), ResolvePath(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), and DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow().
bool FILENAME_RESOLVER::UpdatePathList | ( | std::vector< SEARCH_PATH > & | aPathList | ) |
Clear the current path list and substitutes the given path list and update the path configuration file on success.
Definition at line 227 of file filename_resolver.cpp.
References addPath(), m_paths, and writePathList().
Referenced by DIALOG_CONFIGURE_PATHS::TransferDataFromWindow().
bool FILENAME_RESOLVER::ValidateFileName | ( | const wxString & | aFileName, |
bool & | hasAlias | ||
) |
Returns true if the given path is a valid aliased relative path.
If the path contains an alias then hasAlias is set true.
Definition at line 950 of file filename_resolver.cpp.
Referenced by DIALOG_FOOTPRINT_FP_EDITOR::On3DModelCellChanged(), and DIALOG_FOOTPRINT_PROPERTIES::On3DModelCellChanged().
|
private |
Write the current path list to a configuration file.
Definition at line 606 of file filename_resolver.cpp.
References _, CFGFILE_VERSION, m_configDir, m_paths, MASK_3D_RESOLVER, and RESOLVER_CONFIG.
Referenced by readPathList(), and UpdatePathList().
|
private |
Definition at line 179 of file filename_resolver.h.
Referenced by createPathList(), readPathList(), Set3DConfigDir(), and writePathList().
|
private |
Definition at line 184 of file filename_resolver.h.
Referenced by createPathList(), GetProjectDir(), and SetProject().
|
private |
Definition at line 181 of file filename_resolver.h.
Referenced by FILENAME_RESOLVER(), and ResolvePath().
|
private |
Definition at line 180 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), GetPaths(), readPathList(), ResolvePath(), SetProgramBase(), SetProject(), ShortenPath(), UpdatePathList(), and writePathList().
|
private |
Definition at line 182 of file filename_resolver.h.
Referenced by GetKicadPaths(), and SetProgramBase().
|
private |
Definition at line 183 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), ResolvePath(), Set3DConfigDir(), SetProject(), and ShortenPath().