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 GetDefault3rdPartyPath ()
 Gets the default path for PCM packages. 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 plugins path. More...
 
static wxString GetStockDemosPath ()
 Gets the stock (install) demos path. More...
 
static wxString GetUserCachePath ()
 Gets the stock (install) 3d viewer plugins path. 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 29 of file paths.h.

Constructor & Destructor Documentation

◆ PATHS()

PATHS::PATHS ( )
inlineprivate

Definition at line 150 of file paths.h.

150 {}

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 291 of file paths.cpp.

292 {
293  wxFileName path( aPath );
294  if( !path.Normalize() )
295  {
296  return false;
297  }
298 
299  if( !wxFileName::DirExists( aPath ) )
300  {
301  if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
302  {
303  return false;
304  }
305  }
306 
307  return true;
308 }

References path.

Referenced by EnsureUserPathsExist().

◆ EnsureUserPathsExist()

void PATHS::EnsureUserPathsExist ( )
static

Ensures/creates user default paths.

Definition at line 311 of file paths.cpp.

312 {
322 }
static bool EnsurePathExists(const wxString &aPath)
Attempts to create a given path if it does not exist.
Definition: paths.cpp:291
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:139
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
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
Definition: paths.cpp:129

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

Referenced by SETTINGS_MANAGER::SETTINGS_MANAGER().

◆ GetDefault3rdPartyPath()

wxString PATHS::GetDefault3rdPartyPath ( )
static

Gets the default path for PCM packages.

Definition at line 129 of file paths.cpp.

130 {
131  wxFileName tmp;
132  getUserDocumentPath( tmp );
133 
134  tmp.AppendDir( "3rdparty" );
135 
136  return tmp.GetPath();
137 }
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(), COMMON_SETTINGS::InitializeEnvironment(), SETTINGS_MANAGER::loadAllColorSettings(), and PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_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 139 of file paths.cpp.

140 {
141  wxFileName tmp;
142  getUserDocumentPath( tmp );
143 
144  tmp.AppendDir( "projects" );
145 
146  return tmp.GetPath();
147 }
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(), EDA_BASE_FRAME::commonInit(), PCB_EDIT_FRAME::doAutoSave(), EnsureUserPathsExist(), PCB_EDIT_FRAME::Files_io_from_id(), DIALOG_GENDRILL::OnGenReportFile(), PROJECT_TREE_PANE::onOpenDirectory(), PROJECT_TREE_PANE::ReCreateTreePrj(), and SCH_EDIT_FRAME::SaveProject().

◆ 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 275 of file paths.cpp.

276 {
277  wxString path;
278 
279 #if defined( __WXMAC__ )
280  path = GetOSXKicadDataDir();
281 #elif defined( __WXMSW__ )
282  path = getWindowsKiCadRoot() + "share/doc/kicad";
283 #else
284  path = wxString::FromUTF8Unchecked( KICAD_DOCS );
285 #endif
286 
287  return path;
288 }

References path.

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 150 of file paths.cpp.

151 {
152  wxString path;
153 
154  if( aRespectRunFromBuildDir && wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
155  {
156  // Allow debugging from build dir by placing relevant files/folders in the build root
157 #if defined( __WXMAC__ )
158  wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
159 
160  fn.RemoveLastDir();
161  fn.RemoveLastDir();
162  fn.RemoveLastDir();
163  fn.RemoveLastDir();
164  path = fn.GetPath();
165 #elif defined( __WXMSW__ )
166  path = getWindowsKiCadRoot();
167 #else
168  path = Pgm().GetExecutablePath() + wxT( ".." );
169 #endif
170  }
171  else
172  {
173 #if defined( __WXMAC__ )
174  path = GetOSXKicadDataDir();
175 #elif defined( __WXMSW__ )
176  path = getWindowsKiCadRoot() + wxT( "share/kicad" );
177 #else
178  path = wxString::FromUTF8Unchecked( KICAD_DATA );
179 #endif
180  }
181 
182  return path;
183 }
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(), GetStockDemosPath(), GetStockEDALibraryPath(), GetStockPluginsPath(), GetStockScriptingPath(), and PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER().

◆ GetStockDemosPath()

wxString PATHS::GetStockDemosPath ( )
static

Gets the stock (install) demos path.

Definition at line 252 of file paths.cpp.

253 {
254  wxFileName fn;
255 
256  fn.AssignDir( PATHS::GetStockDataPath( false ) );
257  fn.AppendDir( wxT( "demos" ) );
258 
259  return fn.GetPathWithSep();
260 }
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:150

References GetStockDataPath().

Referenced by KICAD_MANAGER_CONTROL::OpenDemoProject(), and KICAD_MANAGER_FRAME::ReCreateMenuBar().

◆ 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 186 of file paths.cpp.

187 {
188  wxString path;
189 
190 #if defined( __WXMAC__ )
191  path = GetOSXKicadMachineDataDir();
192 #elif defined( __WXMSW__ )
193  path = GetStockDataPath( false );
194 #else
195  path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
196 #endif
197 
198  return path;
199 }
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:150

References GetStockDataPath(), and path.

Referenced by COMMON_SETTINGS::InitializeEnvironment(), and SystemDirsAppend().

◆ GetStockPlugins3DPath()

wxString PATHS::GetStockPlugins3DPath ( )
static

Gets the stock (install) 3d viewer plugins path.

Definition at line 228 of file paths.cpp.

229 {
230  wxFileName fn;
231 
232 #ifdef __WXGTK__
233  // KICAD_PLUGINDIR = CMAKE_INSTALL_FULL_LIBDIR path is the absolute path
234  // corresponding to the install path used for constructing KICAD_USER_PLUGIN
235  wxString tfname = wxString::FromUTF8Unchecked( KICAD_PLUGINDIR );
236  fn.Assign( tfname, "" );
237  fn.AppendDir( wxT( "kicad" ) );
238  fn.AppendDir( wxT( "plugins" ) );
239 #elif defined( __WXMAC__ )
240  fn.Assign( wxStandardPaths::Get().GetPluginsDir(), wxEmptyString );
241 #else
242  fn.AssignDir( Pgm().GetExecutablePath() );
243  fn.AppendDir( wxT( "plugins" ) );
244 #endif
245 
246  fn.AppendDir( "3d" );
247 
248  return fn.GetPathWithSep();
249 }
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 212 of file paths.cpp.

213 {
214  wxFileName fn;
215 
216 #if defined( __WXMSW__ )
217  fn.AssignDir( Pgm().GetExecutablePath() );
218  fn.AppendDir( wxT( "scripting" ) );
219 #else
220  fn.AssignDir( PATHS::GetStockDataPath( false ) );
221 #endif
222  fn.AppendDir( wxT( "plugins" ) );
223 
224  return fn.GetPathWithSep();
225 }
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:150

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 202 of file paths.cpp.

203 {
204  wxString path;
205 
206  path = GetStockDataPath() + wxT( "/scripting" );
207 
208  return path;
209 }
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:150

References GetStockDataPath(), and path.

◆ GetUserCachePath()

wxString PATHS::GetUserCachePath ( )
static

Gets the stock (install) 3d viewer plugins path.

Definition at line 263 of file paths.cpp.

264 {
265  wxFileName tmp;
266 
267  tmp.AssignDir( KIPLATFORM::ENV::GetUserCachePath() );
268  tmp.AppendDir( KICAD_PATH_STR );
269  tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
270 
271  return tmp.GetPathWithSep();
272 }
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 GetDefault3rdPartyPath(), 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().

◆ 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(), COMMON_SETTINGS::InitializeEnvironment(), and PGM_KICAD::OnPgmInit().


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