KiCad PCB EDA Suite
filename_resolver.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Cirilo Bernardo <cirilo.bernardo@gmail.com>
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
29 #ifndef FILENAME_RESOLVER_H
30 #define FILENAME_RESOLVER_H
31 
32 #include <list>
33 #include <map>
34 #include <vector>
35 #include <wx/string.h>
36 
37 class PGM_BASE;
38 
40 {
41  wxString m_Alias; // alias to the base path
42  wxString m_Pathvar; // base path as stored in the config file
43  wxString m_Pathexp; // expanded base path
44  wxString m_Description; // description of the aliased path
45 };
46 
47 
56 {
57 public:
59 
66  bool Set3DConfigDir( const wxString& aConfigDir );
67 
76  bool SetProject( PROJECT* aProject, bool* flgChanged = nullptr );
77 
78  wxString GetProjectDir() const;
79 
83  void SetProgramBase( PGM_BASE* aBase );
84 
85 
90  bool UpdatePathList( const std::vector< SEARCH_PATH >& aPathList );
91 
99  wxString ResolvePath( const wxString& aFileName );
100 
108  wxString ShortenPath( const wxString& aFullPathName );
109 
117  const std::list< SEARCH_PATH >* GetPaths() const;
118 
123  bool SplitAlias( const wxString& aFileName, wxString& anAlias, wxString& aRelPath ) const;
124 
130  bool ValidateFileName( const wxString& aFileName, bool& hasAlias ) const;
131 
137  bool GetKicadPaths( std::list< wxString >& paths ) const;
138 
139 private:
148  bool createPathList( void );
149 
156  bool addPath( const SEARCH_PATH& aPath );
157 
163  bool readPathList( void );
164 
171  bool writePathList( void );
172 
177  void checkEnvVarPath( const wxString& aPath );
178 
179  wxString m_configDir; // 3D configuration directory
180  std::list<SEARCH_PATH> m_paths; // list of base paths to search from
184  wxString m_curProjDir;
185 };
186 
187 #endif // FILENAME_RESOLVER_H
std::list< SEARCH_PATH > m_paths
Container for project specific data.
Definition: project.h:62
bool readPathList(void)
Read a list of path names from a configuration file.
Container for data for KiCad programs.
Definition: pgm_base.h:91
bool UpdatePathList(const std::vector< SEARCH_PATH > &aPathList)
Clear the current path list and substitutes the given path list and update the path configuration fil...
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 a...
bool writePathList(void)
Write the current path list to a configuration file.
bool createPathList(void)
Build the path list using available information such as KICAD6_3DMODEL_DIR and the 3d_path_list confi...
bool ValidateFileName(const wxString &aFileName, bool &hasAlias) const
Returns true if the given path is a valid aliased relative path.
wxString m_Alias
bool addPath(const SEARCH_PATH &aPath)
Check that a path is valid and adds it to the search list.
wxString ShortenPath(const wxString &aFullPathName)
Produce a relative path based on the existing search directories or returns the same path if the path...
wxString m_Description
wxString m_Pathvar
const std::list< SEARCH_PATH > * GetPaths() const
Return a pointer to the internal path list; the items in:load.
wxString ResolvePath(const wxString &aFileName)
Determines the full path of the given file name.
Provide an extensible class to resolve 3D model paths.
bool SetProject(PROJECT *aProject, bool *flgChanged=nullptr)
Set the current KiCad project directory as the first entry in the model path list.
bool Set3DConfigDir(const wxString &aConfigDir)
Set the user's configuration directory for 3D models.
bool GetKicadPaths(std::list< wxString > &paths) const
Return a list of path environment variables local to KiCad.
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 ...
void SetProgramBase(PGM_BASE *aBase)
Set a pointer to the application's PGM_BASE instance used to extract the local env vars.
wxString GetProjectDir() const
wxString m_Pathexp