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 () const |
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 (const 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, const wxString &aWorkingPath) |
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 () const |
Return a pointer to the internal path list; the items in:load. More... | |
bool | SplitAlias (const wxString &aFileName, wxString &anAlias, wxString &aRelPath) const |
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) const |
Returns true if the given path is a valid aliased relative path. More... | |
bool | GetKicadPaths (std::list< wxString > &paths) const |
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 KICAD7_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... | |
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 KICAD7_3DMODEL_DIR environment variable. In the future a configurable set of search paths may be specified.
Definition at line 56 of file filename_resolver.h.
FILENAME_RESOLVER::FILENAME_RESOLVER | ( | ) |
Definition at line 51 of file filename_resolver.cpp.
References m_errflags.
|
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 417 of file filename_resolver.cpp.
References _, DisplayErrorMessage(), ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, SEARCH_PATH::m_Alias, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, m_project, mutex_resolver, and path.
Referenced by 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 496 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, 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 KICAD7_3DMODEL_DIR and the 3d_path_list configuration file.
Definition at line 156 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, GetKicadPaths(), SEARCH_PATH::m_Alias, m_curProjDir, SEARCH_PATH::m_Pathexp, m_paths, SEARCH_PATH::m_Pathvar, m_project, and MASK_3D_RESOLVER.
Referenced by ResolvePath(), Set3DConfigDir(), SetProgramBase(), and ShortenPath().
bool FILENAME_RESOLVER::GetKicadPaths | ( | std::list< wxString > & | paths | ) | const |
Return a list of path environment variables local to KiCad.
This list always includes KICAD7_3DMODEL_DIR even if it is not defined locally.
Definition at line 774 of file filename_resolver.cpp.
References PGM_BASE::GetLocalEnvVariables(), and m_pgm.
Referenced by createPathList().
const std::list< SEARCH_PATH > * FILENAME_RESOLVER::GetPaths | ( | ) | const |
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 647 of file filename_resolver.cpp.
References m_paths.
Referenced by DIALOG_SELECT_3DMODEL::updateDirChoiceList().
wxString FILENAME_RESOLVER::GetProjectDir | ( | ) | const |
Definition at line 137 of file filename_resolver.cpp.
References m_curProjDir.
wxString FILENAME_RESOLVER::ResolvePath | ( | const wxString & | aFileName, |
const wxString & | aWorkingPath | ||
) |
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.
aFileName | The configured file path to resolve |
aWorkingPath | The current working path for relative path resolutions |
Definition at line 243 of file filename_resolver.cpp.
References checkEnvVarPath(), createPathList(), ERRFLG_ALIAS, ERRFLG_ENVPATH, ERRFLG_RELPATH, ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, m_errflags, m_paths, m_project, mutex_resolver, path, SplitAlias(), and tracePathsAndFiles.
Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint(), idf_export_footprint(), S3D_CACHE::load(), and PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().
bool FILENAME_RESOLVER::Set3DConfigDir | ( | const wxString & | aConfigDir | ) |
Set the user's configuration directory for 3D models.
aConfigDir |
Definition at line 59 of file filename_resolver.cpp.
References createPathList(), ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, 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 143 of file filename_resolver.cpp.
References createPathList(), m_paths, and m_pgm.
Referenced by PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), and 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 78 of file filename_resolver.cpp.
References ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, 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 556 of file filename_resolver.cpp.
References createPathList(), ExpandEnvVarSubstitutions(), m_paths, m_project, and mutex_resolver.
Referenced by DIALOG_SELECT_3DMODEL::TransferDataFromWindow().
bool FILENAME_RESOLVER::SplitAlias | ( | const wxString & | aFileName, |
wxString & | anAlias, | ||
wxString & | aRelPath | ||
) | const |
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 653 of file filename_resolver.cpp.
Referenced by ResolvePath().
bool FILENAME_RESOLVER::UpdatePathList | ( | const 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 229 of file filename_resolver.cpp.
bool FILENAME_RESOLVER::ValidateFileName | ( | const wxString & | aFileName, |
bool & | hasAlias | ||
) | const |
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 679 of file filename_resolver.cpp.
Referenced by PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().
|
private |
Definition at line 168 of file filename_resolver.h.
Referenced by Set3DConfigDir().
|
private |
Definition at line 173 of file filename_resolver.h.
Referenced by createPathList(), GetProjectDir(), and SetProject().
|
private |
Definition at line 170 of file filename_resolver.h.
Referenced by FILENAME_RESOLVER(), and ResolvePath().
|
private |
Definition at line 169 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), GetPaths(), ResolvePath(), SetProgramBase(), SetProject(), ShortenPath(), and UpdatePathList().
|
private |
Definition at line 171 of file filename_resolver.h.
Referenced by GetKicadPaths(), and SetProgramBase().
|
private |
Definition at line 172 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), ResolvePath(), Set3DConfigDir(), SetProject(), and ShortenPath().