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. | |
bool | SetProject (PROJECT *aProject, bool *flgChanged=nullptr) |
Set the current KiCad project directory as the first entry in the model path list. | |
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. | |
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. | |
wxString | ResolvePath (const wxString &aFileName, const wxString &aWorkingPath, const EMBEDDED_FILES *aFiles) |
Determines the full path of the given file name. | |
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. | |
const std::list< SEARCH_PATH > * | GetPaths () const |
Return a pointer to the internal path list; the items in:load. | |
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. | |
bool | ValidateFileName (const wxString &aFileName, bool &hasAlias) const |
Returns true if the given path is a valid aliased relative path. | |
bool | GetKicadPaths (std::list< wxString > &paths) const |
Return a list of path environment variables local to KiCad. | |
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. | |
bool | addPath (const SEARCH_PATH &aPath) |
Check that a path is valid and adds it to the search list. | |
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. | |
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 57 of file filename_resolver.h.
FILENAME_RESOLVER::FILENAME_RESOLVER | ( | ) |
Definition at line 54 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 448 of file filename_resolver.cpp.
References _, DisplayErrorMessage(), ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, ENV_VAR::GetVersionedEnvVarName(), 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 530 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 159 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 820 of file filename_resolver.cpp.
References PGM_BASE::GetLocalEnvVariables(), ENV_VAR::GetVersionedEnvVarName(), 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 681 of file filename_resolver.cpp.
References m_paths.
Referenced by DIALOG_SELECT_3DMODEL::updateDirChoiceList().
wxString FILENAME_RESOLVER::GetProjectDir | ( | ) | const |
Definition at line 140 of file filename_resolver.cpp.
References m_curProjDir.
wxString FILENAME_RESOLVER::ResolvePath | ( | const wxString & | aFileName, |
const wxString & | aWorkingPath, | ||
const EMBEDDED_FILES * | aFiles | ||
) |
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 |
aFiles | The embedded files object to use for embedded file resolution |
Definition at line 246 of file filename_resolver.cpp.
References checkEnvVarPath(), createPathList(), ERRFLG_ALIAS, ERRFLG_ENVPATH, ERRFLG_RELPATH, ExpandEnvVarSubstitutions(), FN_NORMALIZE_FLAGS, EMBEDDED_FILES::GetTemporaryFileName(), ENV_VAR::GetVersionedEnvVarName(), FILEEXT::KiCadUriPrefix, m_errflags, m_paths, m_project, mutex_resolver, path, SplitAlias(), and tracePathsAndFiles.
Referenced by EXPORTER_PCB_VRML::ExportVrmlFootprint(), idf_export_footprint(), EESCHEMA_JOBS_HANDLER::InitRenderSettings(), S3D_CACHE::load(), LoadBoard(), SCH_EDIT_FRAME::LoadDrawingSheet(), PCB_EDIT_FRAME::LoadDrawingSheet(), PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet(), DIALOG_PAGES_SETTINGS::SavePageSettings(), SCH_EDIT_FRAME::saveProjectSettings(), 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 62 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 146 of file filename_resolver.cpp.
References createPathList(), m_paths, and m_pgm.
Referenced by DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS(), EESCHEMA_JOBS_HANDLER::InitRenderSettings(), LoadBoard(), SCH_EDIT_FRAME::LoadDrawingSheet(), PCB_EDIT_FRAME::LoadDrawingSheet(), PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet(), PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL(), SCH_EDIT_FRAME::saveProjectSettings(), 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 81 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 DIALOG_PAGES_SETTINGS::DIALOG_PAGES_SETTINGS(), EESCHEMA_JOBS_HANDLER::InitRenderSettings(), LoadBoard(), SCH_EDIT_FRAME::LoadDrawingSheet(), PCB_EDIT_FRAME::LoadDrawingSheet(), PCBNEW_JOBS_HANDLER::loadOverrideDrawingSheet(), SCH_EDIT_FRAME::saveProjectSettings(), and 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 590 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 687 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 232 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 713 of file filename_resolver.cpp.
References FILEEXT::KiCadUriPrefix.
Referenced by PANEL_FP_PROPERTIES_3D_MODEL::validateModelExists().
|
private |
Definition at line 171 of file filename_resolver.h.
Referenced by Set3DConfigDir().
|
private |
Definition at line 176 of file filename_resolver.h.
Referenced by createPathList(), GetProjectDir(), and SetProject().
|
private |
Definition at line 173 of file filename_resolver.h.
Referenced by FILENAME_RESOLVER(), and ResolvePath().
|
private |
Definition at line 172 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), GetPaths(), ResolvePath(), SetProgramBase(), SetProject(), ShortenPath(), and UpdatePathList().
|
private |
Definition at line 174 of file filename_resolver.h.
Referenced by GetKicadPaths(), and SetProgramBase().
|
private |
Definition at line 175 of file filename_resolver.h.
Referenced by addPath(), checkEnvVarPath(), createPathList(), ResolvePath(), Set3DConfigDir(), SetProject(), and ShortenPath().