Commit bd199b89 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Set default footprint library table and 3D model library environment variables.

parent 4265fa60
...@@ -61,6 +61,15 @@ ...@@ -61,6 +61,15 @@
/// The install prefix defined in CMAKE_INSTALL_PREFIX. /// The install prefix defined in CMAKE_INSTALL_PREFIX.
#define DEFAULT_INSTALL_PATH "@CMAKE_INSTALL_PREFIX@" #define DEFAULT_INSTALL_PATH "@CMAKE_INSTALL_PREFIX@"
/// The install prefix used for KiCad's libraries.
/// These paths are only intended to be reasonable default values that work if
/// the user installs KiCad in the default path for a given platform.
#if defined( APPLE )
#define KICAD_DATA_PATH "/Library/Application Support/kicad"
#else
#define KICAD_DATA_PATH "@CMAKE_INSTALL_PREFIX@/@KICAD_DATA@"
#endif
/// When defined, build the GITHUB_PLUGIN for pcbnew. /// When defined, build the GITHUB_PLUGIN for pcbnew.
#cmakedefine BUILD_GITHUB_PLUGIN #cmakedefine BUILD_GITHUB_PLUGIN
......
...@@ -59,6 +59,8 @@ const wxChar PGM_BASE::workingDirKey[] = wxT( "WorkingDir" ); // public ...@@ -59,6 +59,8 @@ const wxChar PGM_BASE::workingDirKey[] = wxT( "WorkingDir" ); // public
static const wxChar languageCfgKey[] = wxT( "LanguageID" ); static const wxChar languageCfgKey[] = wxT( "LanguageID" );
static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" ); static const wxChar kicadFpLibPath[] = wxT( "KicadFootprintLibraryPath" );
static const wxChar pathEnvVariables[] = wxT( "EnvironmentVariables" );
static const wxChar traceEnvVars[] = wxT( "KIENVVARS" );
/** /**
...@@ -353,7 +355,8 @@ bool PGM_BASE::initPgm() ...@@ -353,7 +355,8 @@ bool PGM_BASE::initPgm()
wxInitAllImageHandlers(); wxInitAllImageHandlers();
m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId(), GetKicadLockFilePath() ); m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) +
wxGetUserId(), GetKicadLockFilePath() );
if( m_pgm_checker->IsAnotherRunning() ) if( m_pgm_checker->IsAnotherRunning() )
{ {
...@@ -361,6 +364,7 @@ bool PGM_BASE::initPgm() ...@@ -361,6 +364,7 @@ bool PGM_BASE::initPgm()
_( "%s is already running, Continue?" ), _( "%s is already running, Continue?" ),
GetChars( pgm_name.GetName() ) GetChars( pgm_name.GetName() )
); );
if( !IsOK( NULL, quiz ) ) if( !IsOK( NULL, quiz ) )
return false; return false;
} }
...@@ -399,6 +403,17 @@ bool PGM_BASE::initPgm() ...@@ -399,6 +403,17 @@ bool PGM_BASE::initPgm()
SetLanguagePath(); SetLanguagePath();
// Useful local environment variable settings.
m_local_env_vars[ wxString( wxT( "KIGITHUB" ) ) ] =
wxString( wxT( "https://github.com/KiCad" ) );
wxFileName tmpFileName;
tmpFileName.AssignDir( wxString( wxT( KICAD_DATA_PATH ) ) );
tmpFileName.AppendDir( wxT( "modules" ) );
m_local_env_vars[ wxString( wxT( "KISYSMOD" ) ) ] = tmpFileName.GetPath();
tmpFileName.AppendDir( wxT( "packages3d" ) );
m_local_env_vars[ wxString( wxT( "KISYS3DMOD" ) ) ] = tmpFileName.GetPath();
// OS specific instantiation of wxConfigBase derivative: // OS specific instantiation of wxConfigBase derivative:
m_common_settings = GetNewConfig( KICAD_COMMON ); m_common_settings = GetNewConfig( KICAD_COMMON );
...@@ -425,6 +440,7 @@ bool PGM_BASE::setExecutablePath() ...@@ -425,6 +440,7 @@ bool PGM_BASE::setExecutablePath()
// bundle directory, e.g., /Applications/kicad.app/ // bundle directory, e.g., /Applications/kicad.app/
wxFileName fn( m_bin_dir ); wxFileName fn( m_bin_dir );
if( fn.GetName() == wxT( "kicad" ) ) if( fn.GetName() == wxT( "kicad" ) )
{ {
// kicad launcher, so just remove the Contents/MacOS part // kicad launcher, so just remove the Contents/MacOS part
...@@ -440,6 +456,7 @@ bool PGM_BASE::setExecutablePath() ...@@ -440,6 +456,7 @@ bool PGM_BASE::setExecutablePath()
fn.RemoveLastDir(); fn.RemoveLastDir();
fn.RemoveLastDir(); fn.RemoveLastDir();
} }
m_bin_dir = fn.GetPath() + wxT( "/" ); m_bin_dir = fn.GetPath() + wxT( "/" );
#else #else
// Use unix notation for paths. I am not sure this is a good idea, // Use unix notation for paths. I am not sure this is a good idea,
...@@ -479,6 +496,33 @@ void PGM_BASE::loadCommonSettings() ...@@ -479,6 +496,33 @@ void PGM_BASE::loadCommonSettings()
} }
m_editor_name = m_common_settings->Read( wxT( "Editor" ) ); m_editor_name = m_common_settings->Read( wxT( "Editor" ) );
wxString entry, oldPath;
wxArrayString entries;
long index = 0L;
oldPath = m_common_settings->GetPath();
m_common_settings->SetPath( pathEnvVariables );
while( m_common_settings->GetNextEntry( entry, index ) )
{
wxLogTrace( traceEnvVars,
wxT( "Enumerating over entry %s, %ld." ), GetChars( entry ), index );
entries.Add( entry );
}
for( unsigned i = 0; i < entries.GetCount(); i++ )
{
wxString val = m_common_settings->Read( entries[i], wxEmptyString );
m_local_env_vars[ entries[i] ] = val;
}
for( std::map<wxString, wxString>::iterator it = m_local_env_vars.begin();
it != m_local_env_vars.end();
++it )
SetLocalEnvVariable( it->first, it->second );
m_common_settings->SetPath( oldPath );
} }
...@@ -491,6 +535,20 @@ void PGM_BASE::saveCommonSettings() ...@@ -491,6 +535,20 @@ void PGM_BASE::saveCommonSettings()
wxString cur_dir = wxGetCwd(); wxString cur_dir = wxGetCwd();
m_common_settings->Write( workingDirKey, cur_dir ); m_common_settings->Write( workingDirKey, cur_dir );
// Save the local environment variables.
m_common_settings->SetPath( pathEnvVariables );
for( std::map<wxString, wxString>::iterator it = m_local_env_vars.begin();
it != m_local_env_vars.end();
++it )
{
wxLogTrace( traceEnvVars, wxT( "Saving environment varaiable config entry %s as %s" ),
GetChars( it->first ), GetChars( it->second ) );
m_common_settings->Write( it->first, it->second );
}
m_common_settings->SetPath( wxT( ".." ) );
} }
} }
...@@ -665,3 +723,21 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu ) ...@@ -665,3 +723,21 @@ void PGM_BASE::AddMenuLanguageList( wxMenu* MasterMenu )
} }
} }
bool PGM_BASE::SetLocalEnvVariable( const wxString& aName, const wxString& aValue )
{
wxString env;
// Check to see if the environment variable is already set.
if( wxGetEnv( aName, &env ) )
{
wxLogTrace( traceEnvVars, wxT( "Environment variable %s already set to %s." ),
GetChars( aName ), GetChars( env ) );
return env == aValue;
}
wxLogTrace( traceEnvVars, wxT( "Setting local environment variable %s to %s." ),
GetChars( aName ), GetChars( aValue ) );
return wxSetEnv( aName, aValue );
}
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004-2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008-2015 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#ifndef PGM_BASE_H_ #ifndef PGM_BASE_H_
#define PGM_BASE_H_ #define PGM_BASE_H_
#include <map>
#include <wx/filename.h> #include <wx/filename.h>
#include <search_stack.h> #include <search_stack.h>
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
...@@ -109,7 +110,7 @@ public: ...@@ -109,7 +110,7 @@ public:
/** /**
* Function UseSystemPdfBrowser * Function UseSystemPdfBrowser
* returns true if the PDF browser is the default (system) PDF browser * returns true if the PDF browser is the default (system) PDF browser
* and false if the PDF browser is the prefered (selected) browser, else * and false if the PDF browser is the preferred (selected) browser, else
* returns false if there is no selected browser * returns false if there is no selected browser
*/ */
VTBL_ENTRY bool UseSystemPdfBrowser() const VTBL_ENTRY bool UseSystemPdfBrowser() const
...@@ -119,7 +120,7 @@ public: ...@@ -119,7 +120,7 @@ public:
/** /**
* Function ForceSystemPdfBrowser * Function ForceSystemPdfBrowser
* forces the use of system PDF browser, even if a preferend PDF browser is set. * forces the use of system PDF browser, even if a preferred PDF browser is set.
*/ */
VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; } VTBL_ENTRY void ForceSystemPdfBrowser( bool aFlg ) { m_use_system_pdf_browser = aFlg; }
...@@ -168,6 +169,22 @@ public: ...@@ -168,6 +169,22 @@ public:
*/ */
VTBL_ENTRY void WritePdfBrowserInfos(); VTBL_ENTRY void WritePdfBrowserInfos();
/**
* Function SetLocalEnvVariable
*
* Sets the environment variable \a aName to \a aValue.
*
* This function first checks to see if the environment variable \a aName is already
* defined. If it is not defined, then the environment variable \a aName is set to
* a value. Otherwise, the environment variable is left unchanged. This allows the user
* to override environment variables for testing purposes.
*
* @param aName is a wxString containing the environment variable name.
* @param aValue is a wxString containing the environment variable value.
* @return true if the environment variable \a Name was set to \a aValue.
*/
VTBL_ENTRY bool SetLocalEnvVariable( const wxString& aName, const wxString& aValue );
/** /**
* Function App * Function App
* returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe. * returns a bare naked wxApp, which may come from wxPython, SINGLE_TOP, or kicad.exe.
...@@ -247,6 +264,10 @@ protected: ...@@ -247,6 +264,10 @@ protected:
wxString m_editor_name; wxString m_editor_name;
wxSize m_help_size; wxSize m_help_size;
/// Local environment variable expansion settings such as KIGITHUB, KISYSMOD, and KISYS3DMOD.
/// library table.
std::map<wxString, wxString> m_local_env_vars;
wxApp* m_wx_app; wxApp* m_wx_app;
// The PGM_* classes can have difficulties at termination if they // The PGM_* classes can have difficulties at termination if they
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment