KiCad PCB EDA Suite
Loading...
Searching...
No Matches
FILENAME_RESOLVER Class Reference

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_PATHm_paths
 
int m_errflags
 
PGM_BASEm_pgm
 
PROJECTm_project
 
wxString m_curProjDir
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FILENAME_RESOLVER()

FILENAME_RESOLVER::FILENAME_RESOLVER ( )

Definition at line 54 of file filename_resolver.cpp.

References m_errflags.

Member Function Documentation

◆ addPath()

bool FILENAME_RESOLVER::addPath ( const SEARCH_PATH aPath)
private

Check that a path is valid and adds it to the search list.

Parameters
aPathis the alias set to be checked and added.
Returns
true if aPath is valid.

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().

◆ checkEnvVarPath()

void FILENAME_RESOLVER::checkEnvVarPath ( const wxString &  aPath)
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().

◆ createPathList()

bool FILENAME_RESOLVER::createPathList ( void  )
private

Build the path list using available information such as KICAD7_3DMODEL_DIR and the 3d_path_list configuration file.

Warning
Invalid paths are silently discarded and removed from the configuration file.
Returns
true if at least one valid path was found.

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().

◆ GetKicadPaths()

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().

◆ GetPaths()

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.

Returns
pointer to the internal path list.

Definition at line 681 of file filename_resolver.cpp.

References m_paths.

Referenced by DIALOG_SELECT_3DMODEL::updateDirChoiceList().

◆ GetProjectDir()

wxString FILENAME_RESOLVER::GetProjectDir ( ) const

Definition at line 140 of file filename_resolver.cpp.

References m_curProjDir.

◆ ResolvePath()

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.

Parameters
aFileNameThe configured file path to resolve
aWorkingPathThe current working path for relative path resolutions
aFilesThe 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().

◆ Set3DConfigDir()

bool FILENAME_RESOLVER::Set3DConfigDir ( const wxString &  aConfigDir)

Set the user's configuration directory for 3D models.

Parameters
aConfigDir
Returns
true if the call succeeds (directory exists).

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().

◆ SetProgramBase()

◆ SetProject()

bool FILENAME_RESOLVER::SetProject ( PROJECT aProject,
bool *  flgChanged = nullptr 
)

Set the current KiCad project directory as the first entry in the model path list.

Parameters
[in]aProjDircurrent project directory
[out]flgChangedoptional, set to true if directory was changed
Return values
truesuccess
falsefailure

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().

◆ ShortenPath()

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.

Parameters
aFullPathNameis an absolute path to shorten.
Returns
the shortened path or aFullPathName.

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().

◆ SplitAlias()

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().

◆ UpdatePathList()

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.

References addPath(), m_paths, and path.

◆ ValidateFileName()

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().

Member Data Documentation

◆ m_configDir

wxString FILENAME_RESOLVER::m_configDir
private

Definition at line 171 of file filename_resolver.h.

Referenced by Set3DConfigDir().

◆ m_curProjDir

wxString FILENAME_RESOLVER::m_curProjDir
private

Definition at line 176 of file filename_resolver.h.

Referenced by createPathList(), GetProjectDir(), and SetProject().

◆ m_errflags

int FILENAME_RESOLVER::m_errflags
private

Definition at line 173 of file filename_resolver.h.

Referenced by FILENAME_RESOLVER(), and ResolvePath().

◆ m_paths

std::list<SEARCH_PATH> FILENAME_RESOLVER::m_paths
private

◆ m_pgm

PGM_BASE* FILENAME_RESOLVER::m_pgm
private

Definition at line 174 of file filename_resolver.h.

Referenced by GetKicadPaths(), and SetProgramBase().

◆ m_project

PROJECT* FILENAME_RESOLVER::m_project
private

The documentation for this class was generated from the following files: