KiCad PCB EDA Suite
3d_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  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
33 #ifndef FILENAME_RESOLVER_3D_H
34 #define FILENAME_RESOLVER_3D_H
35 
36 #include <list>
37 #include <map>
38 #include <vector>
39 #include <wx/string.h>
40 #include "str_rsort.h"
41 
42 class PGM_BASE;
43 
44 struct S3D_ALIAS
45 {
46  wxString m_alias; // alias to the base path
47  wxString m_pathvar; // base path as stored in the config file
48  wxString m_pathexp; // expanded base path
49  wxString m_description; // description of the aliased path
50 };
51 
53 {
54 private:
55  wxString m_ConfigDir; // 3D configuration directory
56  std::list< S3D_ALIAS > m_Paths; // list of base paths to search from
59  wxString m_curProjDir;
60 
70  bool createPathList( void );
71 
79  bool addPath( const S3D_ALIAS& aPath );
80 
88  bool readPathList( void );
89 
97  bool writePathList( void );
98 
105  void checkEnvVarPath( const wxString& aPath );
106 
107 public:
109 
118  bool Set3DConfigDir( const wxString& aConfigDir );
119 
129  bool SetProjectDir( const wxString& aProjDir, bool* flgChanged = NULL );
130  wxString GetProjectDir( void );
131 
137  void SetProgramBase( PGM_BASE* aBase );
138 
139 
145  bool UpdatePathList( std::vector< S3D_ALIAS >& aPathList );
146 
155  wxString ResolvePath( const wxString& aFileName );
156 
166  wxString ShortenPath( const wxString& aFullPathName );
167 
177  const std::list< S3D_ALIAS >* GetPaths( void );
178 
185  bool SplitAlias( const wxString& aFileName, wxString& anAlias, wxString& aRelPath );
186 
192  bool ValidateFileName( const wxString& aFileName, bool& hasAlias );
193 
200  bool GetKicadPaths( std::list< wxString >& paths );
201 };
202 
203 #endif // FILENAME_RESOLVER_3D_H
wxString m_pathvar
bool createPathList(void)
Function createPathList builds the path list using available information such as KISYS3DMOD and the 3...
Class PGM_BASE keeps program (whole process) data for KiCad programs.
Definition: pgm_base.h:107
provides a wxString sorting functino which works from the end of the string towards the beginning ...
bool readPathList(void)
Function readPathList reads a list of path names from a configuration file.
std::list< S3D_ALIAS > m_Paths
wxString m_pathexp
void SetProgramBase(PGM_BASE *aBase)
Function SetProgramBase sets a pointer to the application's PGM_BASE instance; the pointer is used to...
bool ValidateFileName(const wxString &aFileName, bool &hasAlias)
Function ValidateName returns true if the given path is a valid aliased relative path.
wxString ShortenPath(const wxString &aFullPathName)
Function ShortenPath produces a relative path based on the existing search directories or returns the...
bool SplitAlias(const wxString &aFileName, wxString &anAlias, wxString &aRelPath)
Function SplitAlias returns true if the given name contains an alias and populates the string anAlias...
wxString m_description
void checkEnvVarPath(const wxString &aPath)
Function checkEnvVarPath checks the ${ENV_VAR} component of a path and adds it to the resolver's path...
bool UpdatePathList(std::vector< S3D_ALIAS > &aPathList)
Function UpdatePathList clears the current path list and substitutes the given path list...
const std::list< S3D_ALIAS > * GetPaths(void)
Function GetPaths returns a pointer to the internal path list; the items in:load. ...
bool addPath(const S3D_ALIAS &aPath)
Function addPath checks that a path is valid and adds it to the search list.
bool SetProjectDir(const wxString &aProjDir, bool *flgChanged=NULL)
Function SetProjectDir sets the current KiCad project directory as the first entry in the model path ...
bool writePathList(void)
Function writePathList writes the current path list to a configuration file.
wxString ResolvePath(const wxString &aFileName)
Function ResolvePath determines the full path of the given file name.
bool GetKicadPaths(std::list< wxString > &paths)
Function GetKicadPaths returns a list of path environment variables local to Kicad; this list always ...
bool Set3DConfigDir(const wxString &aConfigDir)
Function Set3DConfigDir sets the user's configuration directory for 3D models.