KiCad PCB EDA Suite
PATHS Class Reference

Helper class to centralize the paths used throughout kicad. More...

#include <paths.h>

Static Public Member Functions

static wxString GetUserScriptingPath ()
 Gets the user path for python scripts. More...
 
static wxString GetUserTemplatesPath ()
 Gets the user path for custom templates. More...
 
static wxString GetUserPluginsPath ()
 Gets the user path for plugins. More...
 
static wxString GetUserPlugins3DPath ()
 Gets the user path for 3d viewer plugin. More...
 
static wxString GetDefaultUserProjectsPath ()
 Gets the default path we point users to create projects. More...
 
static wxString GetDefaultUserSymbolsPath ()
 Gets the default path we point users to create projects. More...
 
static wxString GetDefaultUserFootprintsPath ()
 Gets the default path we point users to create projects. More...
 
static wxString GetDefaultUser3DModelsPath ()
 Gets the default path we point users to create projects. More...
 
static wxString GetStockDataPath (bool aRespectRunFromBuildDir=true)
 Gets the stock (install) data path, which is the base path for things like scripting, etc. More...
 
static wxString GetStockEDALibraryPath ()
 Gets the stock (install) EDA library data path, which is the base path for templates, schematic symbols, footprints, and 3D models. More...
 
static wxString GetStockScriptingPath ()
 Gets the stock (install) scripting path. More...
 
static wxString GetStockPluginsPath ()
 Gets the stock (install) plugins path. More...
 
static wxString GetStockPlugins3DPath ()
 Gets the stock (install) 3d viewer pluginspath. More...
 
static wxString GetUserCachePath ()
 Gets the stock (install) 3d viewer pluginspath. More...
 
static wxString GetDocumentationPath ()
 Gets the documentation path, which is the base path for help files. More...
 
static bool EnsurePathExists (const wxString &aPath)
 Attempts to create a given path if it does not exist. More...
 
static void EnsureUserPathsExist ()
 Ensures/creates user default paths. More...
 

Private Member Functions

 PATHS ()
 

Static Private Member Functions

static void getUserDocumentPath (wxFileName &aPath)
 Gets the user path for the current kicad version which acts as the root for other user paths. More...
 

Detailed Description

Helper class to centralize the paths used throughout kicad.

Definition at line 26 of file paths.h.

Constructor & Destructor Documentation

◆ PATHS()

PATHS::PATHS ( )
inlineprivate

Definition at line 137 of file paths.h.

137 {}

Member Function Documentation

◆ EnsurePathExists()

bool PATHS::EnsurePathExists ( const wxString &  aPath)
static

Attempts to create a given path if it does not exist.

Definition at line 259 of file paths.cpp.

260 {
261  wxFileName path( aPath );
262  if( !path.Normalize() )
263  {
264  return false;
265  }
266 
267  if( !wxFileName::DirExists( aPath ) )
268  {
269  if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
270  {
271  return false;
272  }
273  }
274 
275  return true;
276 }

References path.

Referenced by EnsureUserPathsExist().

◆ EnsureUserPathsExist()

void PATHS::EnsureUserPathsExist ( )
static

Ensures/creates user default paths.

Definition at line 279 of file paths.cpp.

280 {
289 }
static bool EnsurePathExists(const wxString &aPath)
Attempts to create a given path if it does not exist.
Definition: paths.cpp:259
static wxString GetDefaultUser3DModelsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:119
static wxString GetUserScriptingPath()
Gets the user path for python scripts.
Definition: paths.cpp:75
static wxString GetUserPlugins3DPath()
Gets the user path for 3d viewer plugin.
Definition: paths.cpp:64
static wxString GetUserPluginsPath()
Gets the user path for plugins.
Definition: paths.cpp:53
static wxString GetUserTemplatesPath()
Gets the user path for custom templates.
Definition: paths.cpp:86
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:130
static wxString GetDefaultUserSymbolsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:97
static wxString GetDefaultUserFootprintsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:108

References EnsurePathExists(), GetDefaultUser3DModelsPath(), GetDefaultUserFootprintsPath(), GetDefaultUserProjectsPath(), GetDefaultUserSymbolsPath(), GetUserPlugins3DPath(), GetUserPluginsPath(), GetUserScriptingPath(), and GetUserTemplatesPath().

Referenced by SETTINGS_MANAGER::SETTINGS_MANAGER().

◆ GetDefaultUser3DModelsPath()

wxString PATHS::GetDefaultUser3DModelsPath ( )
static

Gets the default path we point users to create projects.

Definition at line 119 of file paths.cpp.

120 {
121  wxFileName tmp;
122  getUserDocumentPath( tmp );
123 
124  tmp.AppendDir( "3dmodels" );
125 
126  return tmp.GetPath();
127 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by EnsureUserPathsExist().

◆ GetDefaultUserFootprintsPath()

wxString PATHS::GetDefaultUserFootprintsPath ( )
static

Gets the default path we point users to create projects.

Definition at line 108 of file paths.cpp.

109 {
110  wxFileName tmp;
111  getUserDocumentPath( tmp );
112 
113  tmp.AppendDir( "footprints" );
114 
115  return tmp.GetPath();
116 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), PCB_BASE_EDIT_FRAME::CreateNewLibrary(), EnsureUserPathsExist(), and PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE().

◆ GetDefaultUserProjectsPath()

wxString PATHS::GetDefaultUserProjectsPath ( )
static

Gets the default path we point users to create projects.

Definition at line 130 of file paths.cpp.

131 {
132  wxFileName tmp;
133  getUserDocumentPath( tmp );
134 
135  tmp.AppendDir( "projects" );
136 
137  return tmp.GetPath();
138 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by AskLoadBoardFileName(), PCB_EDIT_FRAME::doAutoSave(), EDA_BASE_FRAME::EDA_BASE_FRAME(), EnsureUserPathsExist(), PCB_EDIT_FRAME::Files_io_from_id(), DIALOG_GENDRILL::OnGenReportFile(), PROJECT_TREE_PANE::onOpenDirectory(), PROJECT_TREE_PANE::ReCreateTreePrj(), and SCH_EDIT_FRAME::SaveEEFile().

◆ GetDefaultUserSymbolsPath()

wxString PATHS::GetDefaultUserSymbolsPath ( )
static

Gets the default path we point users to create projects.

Definition at line 97 of file paths.cpp.

98 {
99  wxFileName tmp;
100  getUserDocumentPath( tmp );
101 
102  tmp.AppendDir( "symbols" );
103 
104  return tmp.GetPath();
105 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by SYMBOL_EDIT_FRAME::AddLibraryFile(), EnsureUserPathsExist(), and PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE().

◆ GetDocumentationPath()

wxString PATHS::GetDocumentationPath ( )
static

Gets the documentation path, which is the base path for help files.

Definition at line 243 of file paths.cpp.

244 {
245  wxString path;
246 
247 #if defined( __WXMAC__ )
248  path = GetOSXKicadDataDir();
249 #elif defined( __WXMSW__ )
250  path = Pgm().GetExecutablePath() + "../share/doc/kicad";
251 #else
252  path = wxString::FromUTF8Unchecked( KICAD_DOCS );
253 #endif
254 
255  return path;
256 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106

References path, and Pgm().

Referenced by SearchHelpFileFullPath().

◆ GetStockDataPath()

wxString PATHS::GetStockDataPath ( bool  aRespectRunFromBuildDir = true)
static

Gets the stock (install) data path, which is the base path for things like scripting, etc.

Definition at line 141 of file paths.cpp.

142 {
143  wxString path;
144 
145  if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
146  {
147  // Allow debugging from build dir by placing relevant files/folders in the build root
148  path = Pgm().GetExecutablePath() + wxT( ".." );
149  }
150  else
151  {
152 #if defined( __WXMAC__ )
153  path = GetOSXKicadDataDir();
154 #elif defined( __WXMSW__ )
155  path = Pgm().GetExecutablePath() + wxT( "../share/kicad" );
156 #else
157  path = wxString::FromUTF8Unchecked( KICAD_DATA );
158 #endif
159  }
160 
161  return path;
162 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106

References path, and Pgm().

Referenced by BITMAP_STORE::BITMAP_STORE(), GetBitmapStore(), GetStockEDALibraryPath(), GetStockPluginsPath(), and GetStockScriptingPath().

◆ GetStockEDALibraryPath()

wxString PATHS::GetStockEDALibraryPath ( )
static

Gets the stock (install) EDA library data path, which is the base path for templates, schematic symbols, footprints, and 3D models.

Definition at line 165 of file paths.cpp.

166 {
167  wxString path;
168 
169 #if defined( __WXMAC__ )
170  path = GetOSXKicadMachineDataDir();
171 #elif defined( __WXMSW__ )
172  path = GetStockDataPath( false );
173 #else
174  path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
175 #endif
176 
177  return path;
178 }
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:141

References GetStockDataPath(), and path.

Referenced by PGM_BASE::InitPgm(), and SystemDirsAppend().

◆ GetStockPlugins3DPath()

wxString PATHS::GetStockPlugins3DPath ( )
static

Gets the stock (install) 3d viewer pluginspath.

Definition at line 207 of file paths.cpp.

208 {
209  wxFileName fn;
210 
211 #ifdef __WXGTK__
212  // KICAD_PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path
213  // corresponding to the install path used for constructing KICAD_USER_PLUGIN
214  wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
215  fn.Assign( tfname, "" );
216  fn.AppendDir( wxT( "kicad" ) );
217  fn.AppendDir( wxT( "plugins" ) );
218 #elif defined( __WXMAC__ )
219  fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
220 #else
221  fn.AssignDir( Pgm().GetExecutablePath() );
222  fn.AppendDir( wxT( "plugins" ) );
223 #endif
224 
225  fn.AppendDir( "3d" );
226 
227  return fn.GetPathWithSep();
228 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106

References Pgm().

Referenced by S3D_PLUGIN_MANAGER::loadPlugins().

◆ GetStockPluginsPath()

wxString PATHS::GetStockPluginsPath ( )
static

Gets the stock (install) plugins path.

Definition at line 191 of file paths.cpp.

192 {
193  wxFileName fn;
194 
195 #if defined( __WXMSW__ )
196  fn.AssignDir( Pgm().GetExecutablePath() );
197  fn.AppendDir( wxT( "scripting" ) );
198 #else
199  fn.AssignDir( PATHS::GetStockDataPath( false ) );
200 #endif
201  fn.AppendDir( wxT( "plugins" ) );
202 
203  return fn.GetPathWithSep();
204 }
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:141

References GetStockDataPath(), and Pgm().

Referenced by BOM_GENERATOR_HANDLER::FindFilePath(), and DIALOG_BOM::pluginInit().

◆ GetStockScriptingPath()

wxString PATHS::GetStockScriptingPath ( )
static

Gets the stock (install) scripting path.

Definition at line 181 of file paths.cpp.

182 {
183  wxString path;
184 
185  path = GetStockDataPath() + wxT( "/scripting" );
186 
187  return path;
188 }
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:141

References GetStockDataPath(), and path.

Referenced by PyScriptingPath().

◆ GetUserCachePath()

wxString PATHS::GetUserCachePath ( )
static

Gets the stock (install) 3d viewer pluginspath.

Definition at line 231 of file paths.cpp.

232 {
233  wxFileName tmp;
234 
235  tmp.AssignDir( KIPLATFORM::ENV::GetUserCachePath() );
236  tmp.AppendDir( KICAD_PATH_STR );
237  tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
238 
239  return tmp.GetPathWithSep();
240 }
wxString GetUserCachePath()
Retrieves the operating system specific path for user's application cache.
#define KICAD_PATH_STR
Definition: paths.cpp:35
static std::string GetSettingsVersion()
Parses the current KiCad build version and extracts the major and minor revision to use as the name o...

References SETTINGS_MANAGER::GetSettingsVersion(), KIPLATFORM::ENV::GetUserCachePath(), and KICAD_PATH_STR.

Referenced by S3D_CACHE::Set3DConfigDir().

◆ getUserDocumentPath()

void PATHS::getUserDocumentPath ( wxFileName &  aPath)
staticprivate

Gets the user path for the current kicad version which acts as the root for other user paths.

Parameters
aPathVariable to receive the path

Definition at line 39 of file paths.cpp.

40 {
41  wxString envPath;
42 
43  if( wxGetEnv( wxT( "KICAD_DOCUMENTS_HOME" ), &envPath ) )
44  aPath.AssignDir( envPath );
45  else
46  aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
47 
48  aPath.AppendDir( KICAD_PATH_STR );
49  aPath.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
50 }
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
#define KICAD_PATH_STR
Definition: paths.cpp:35
static std::string GetSettingsVersion()
Parses the current KiCad build version and extracts the major and minor revision to use as the name o...

References KIPLATFORM::ENV::GetDocumentsPath(), SETTINGS_MANAGER::GetSettingsVersion(), and KICAD_PATH_STR.

Referenced by GetDefaultUser3DModelsPath(), GetDefaultUserFootprintsPath(), GetDefaultUserProjectsPath(), GetDefaultUserSymbolsPath(), GetUserPluginsPath(), GetUserScriptingPath(), and GetUserTemplatesPath().

◆ GetUserPlugins3DPath()

wxString PATHS::GetUserPlugins3DPath ( )
static

Gets the user path for 3d viewer plugin.

Definition at line 64 of file paths.cpp.

65 {
66  wxFileName tmp;
67 
68  tmp.AssignDir( PATHS::GetUserPluginsPath() );
69  tmp.AppendDir( "3d" );
70 
71  return tmp.GetPath();
72 }
static wxString GetUserPluginsPath()
Gets the user path for plugins.
Definition: paths.cpp:53

References GetUserPluginsPath().

Referenced by EnsureUserPathsExist(), and S3D_PLUGIN_MANAGER::loadPlugins().

◆ GetUserPluginsPath()

wxString PATHS::GetUserPluginsPath ( )
static

Gets the user path for plugins.

Definition at line 53 of file paths.cpp.

54 {
55  wxFileName tmp;
56  getUserDocumentPath( tmp );
57 
58  tmp.AppendDir( "plugins" );
59 
60  return tmp.GetPath();
61 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by DIALOG_BOM::chooseGenerator(), EnsureUserPathsExist(), BOM_GENERATOR_HANDLER::FindFilePath(), GetUserPlugins3DPath(), and DIALOG_BOM::pluginInit().

◆ GetUserScriptingPath()

wxString PATHS::GetUserScriptingPath ( )
static

Gets the user path for python scripts.

Definition at line 75 of file paths.cpp.

76 {
77  wxFileName tmp;
78  getUserDocumentPath( tmp );
79 
80  tmp.AppendDir( "scripting" );
81 
82  return tmp.GetPath();
83 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by EnsureUserPathsExist(), and PyScriptingPath().

◆ GetUserTemplatesPath()

wxString PATHS::GetUserTemplatesPath ( )
static

Gets the user path for custom templates.

Definition at line 86 of file paths.cpp.

87 {
88  wxFileName tmp;
89  getUserDocumentPath( tmp );
90 
91  tmp.AppendDir( "template" );
92 
93  return tmp.GetPathWithSep();
94 }
static void getUserDocumentPath(wxFileName &aPath)
Gets the user path for the current kicad version which acts as the root for other user paths.
Definition: paths.cpp:39

References getUserDocumentPath().

Referenced by EnsureUserPathsExist(), PL_EDITOR_FRAME::Files_io(), PGM_BASE::InitPgm(), and PGM_KICAD::OnPgmInit().


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