Commit 9ab7c18f authored by Wayne Stambaugh's avatar Wayne Stambaugh

Footprint library table ground work.

* Remove defined CMAKE_INSTALL_PREFIX for Windows from main CMakeList.txt.
* Move footprint library path detection code from pcbnew.cpp to EDA_APP
  object.
* Add CMAKE_INSTALL_PREFIX to config.h.cmake.
* Simplify and fix search path list code.
* Add CMAKE_INSTALL_PREFIX to the list of search paths in case KiCad was
  installed using `make install`.
* Add default global footprint library table to CMake install.
* Add method to set footprint library table to PCB_BASE_FRAME object.
* Remove unused function EDA_APP::GetLibraryFile().
* Minor FP_LIB_TABLE object improvements.
parent 36ae78ff
...@@ -197,10 +197,14 @@ else() ...@@ -197,10 +197,14 @@ else()
endif() endif()
endif() endif()
#================================================
# Locations for install targets. # Locations for install targets.
set( KICAD_BIN bin set( KICAD_BIN bin
CACHE PATH "Location of KiCad binaries." ) CACHE PATH "Location of KiCad binaries." )
set( KICAD_FP_LIB_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}"
CACHE PATH "Default path where footprint libraries are installed." )
if( UNIX ) if( UNIX )
# Everything without leading / is relative to CMAKE_INSTALL_PREFIX. # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
set( KICAD_PLUGINS lib/kicad/plugins set( KICAD_PLUGINS lib/kicad/plugins
...@@ -209,12 +213,10 @@ if( UNIX ) ...@@ -209,12 +213,10 @@ if( UNIX )
CACHE PATH "Location of KiCad data files." ) CACHE PATH "Location of KiCad data files." )
set( KICAD_DOCS share/doc/kicad set( KICAD_DOCS share/doc/kicad
CACHE PATH "Location of KiCad documentation files." ) CACHE PATH "Location of KiCad documentation files." )
set( KICAD_FP_LIB_INSTALL_PATH "${KICAD_FP_LIB_INSTALL_PATH}/share/kicad/modules" )
endif() endif()
if( MINGW ) if( MINGW )
# Like all variables, CMAKE_INSTALL_PREFIX can be over-ridden on the command line.
set( CMAKE_INSTALL_PREFIX c:/kicad
CACHE PATH "" )
# Everything without leading / is relative to CMAKE_INSTALL_PREFIX. # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
set( KICAD_PLUGINS ${KICAD_BIN}/plugins set( KICAD_PLUGINS ${KICAD_BIN}/plugins
CACHE PATH "Location of KiCad plugins." ) CACHE PATH "Location of KiCad plugins." )
...@@ -222,6 +224,7 @@ if( MINGW ) ...@@ -222,6 +224,7 @@ if( MINGW )
CACHE PATH "Location of KiCad data files." ) CACHE PATH "Location of KiCad data files." )
set( KICAD_DOCS doc set( KICAD_DOCS doc
CACHE PATH "Location of KiCad documentation files." ) CACHE PATH "Location of KiCad documentation files." )
set( KICAD_FP_LIB_INSTALL_PATH "${KICAD_FP_LIB_INSTALL_PATH}/modules" )
endif() endif()
set( KICAD_DEMOS ${KICAD_DATA}/demos set( KICAD_DEMOS ${KICAD_DATA}/demos
......
...@@ -81,6 +81,12 @@ ...@@ -81,6 +81,12 @@
/// Definition to compile with Pcbnew footprint library table implementation. /// Definition to compile with Pcbnew footprint library table implementation.
#cmakedefine USE_FP_LIB_TABLE #cmakedefine USE_FP_LIB_TABLE
/// The install prefix defined in CMAKE_INSTALL_PREFIX.
#define DEFAULT_INSTALL_PATH "@CMAKE_INSTALL_PREFIX"
/// Default footprint library install path when installed with `make install`.
#define DEFAULT_FP_LIB_PATH "@KICAD_FP_LIB_INSTALL_PATH@"
/// When defined, build the GITHUB_PLUGIN for pcbnew. /// When defined, build the GITHUB_PLUGIN for pcbnew.
#cmakedefine BUILD_GITHUB_PLUGIN #cmakedefine BUILD_GITHUB_PLUGIN
......
...@@ -64,18 +64,16 @@ static const wxChar* CommonConfigPath = wxT( "kicad_common" ); ...@@ -64,18 +64,16 @@ static const wxChar* CommonConfigPath = wxT( "kicad_common" );
* the size of the array. */ * the size of the array. */
#define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / sizeof( struct LANGUAGE_DESCR ) ) #define LANGUAGE_DESCR_COUNT ( sizeof( s_Language_List ) / sizeof( struct LANGUAGE_DESCR ) )
// Default font size
#define FONT_DEFAULT_SIZE 10 // Default font size.
// some key strings used to store parameters in config // some key strings used to store parameters in config
static wxString backgroundColorKey( wxT( "BackgroundColor" ) ); static wxString backgroundColorKey( wxT( "BackgroundColor" ) );
static wxString showPageLimitsKey( wxT( "ShowPageLimits" ) ); static wxString showPageLimitsKey( wxT( "ShowPageLimits" ) );
static wxString workingDirKey( wxT( "WorkingDir" ) ) ; static wxString workingDirKey( wxT( "WorkingDir" ) ) ;
static wxString languageCfgKey( wxT( "LanguageID" ) ); static wxString languageCfgKey( wxT( "LanguageID" ) );
static wxString kicadFpLibPath( wxT( "KicadFootprintLibraryPath" ) );
/** /**
* The real font size will be computed at run time
* A small class to handle the list on existing translations. * A small class to handle the list on existing translations.
* the locale translation is automatic. * the locale translation is automatic.
* the selection of languages is mainly for maintainer's convenience * the selection of languages is mainly for maintainer's convenience
...@@ -354,7 +352,7 @@ void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId ) ...@@ -354,7 +352,7 @@ void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId )
wxImage::AddHandler( new wxJPEGHandler ); wxImage::AddHandler( new wxJPEGHandler );
wxFileSystem::AddHandler( new wxZipFSHandler ); wxFileSystem::AddHandler( new wxZipFSHandler );
// Analise the command line & init binary path // Analyze the command line & init binary path
SetBinDir(); SetBinDir();
SetDefaultSearchPaths(); SetDefaultSearchPaths();
SetLanguagePath(); SetLanguagePath();
...@@ -496,24 +494,20 @@ void EDA_APP::SetDefaultSearchPaths( void ) ...@@ -496,24 +494,20 @@ void EDA_APP::SetDefaultSearchPaths( void )
* if the user is savvy enough to set an environment variable they know * if the user is savvy enough to set an environment variable they know
* what they are doing. */ * what they are doing. */
if( ::wxGetEnv( wxT( "KICAD" ), NULL ) ) if( ::wxGetEnv( wxT( "KICAD" ), NULL ) )
m_searchPaths.AddEnvList( wxT( "KICAD" ) ); tmp.AddEnvList( wxT( "KICAD" ) );
// Add the user's home path. // Add the user's home path.
m_searchPaths.Add( GetTraits()->GetStandardPaths().GetUserDataDir() ); tmp.Add( GetTraits()->GetStandardPaths().GetUserDataDir() );
// Standard application data path if it is different from the binary path. // Standard application data path if it is different from the binary path.
if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() ) if( fn.GetPath() != GetTraits()->GetStandardPaths().GetDataDir() )
{ {
m_searchPaths.Add( GetTraits()->GetStandardPaths().GetDataDir() ); tmp.Add( GetTraits()->GetStandardPaths().GetDataDir() );
} }
// Up one level relative to binary path with "share" appended for Windows. // Up one level relative to binary path with "share" appended for Windows.
fn.RemoveLastDir(); fn.RemoveLastDir();
m_searchPaths.Add( fn.GetPath() ); tmp.Add( fn.GetPath() );
fn.AppendDir( wxT( "share" ) );
m_searchPaths.Add( fn.GetPath() );
fn.AppendDir( wxT( "kicad" ) );
m_searchPaths.Add( fn.GetPath() );
/* The normal OS program file install paths allow for binary to be /* The normal OS program file install paths allow for binary to be
* installed in a different path from the library files. This is * installed in a different path from the library files. This is
...@@ -524,13 +518,16 @@ void EDA_APP::SetDefaultSearchPaths( void ) ...@@ -524,13 +518,16 @@ void EDA_APP::SetDefaultSearchPaths( void )
#ifdef __WXMSW__ #ifdef __WXMSW__
tmp.AddEnvList( wxT( "PROGRAMFILES" ) ); tmp.AddEnvList( wxT( "PROGRAMFILES" ) );
#elif __WXMAC__ #elif __WXMAC__
m_searchPaths.Add( wxT( "/Library/Application Support/kicad" ) ); tmp.Add( wxT( "/Library/Application Support" ) );
m_searchPaths.Add( wxString( wxGetenv( wxT( "HOME" ) ) ) + tmp.Add( wxString( wxGetenv( wxT( "HOME" ) ) ) + wxT( "/Library/Application Support" ) );
wxT("/Library/Application Support/kicad") );
#else #else
tmp.AddEnvList( wxT( "PATH" ) ); tmp.AddEnvList( wxT( "PATH" ) );
#endif #endif
// This is the equivalent of CMAKE_INSTALL_PREFIX. Useful when installed by `make install`.
tmp.Add( wxT( DEFAULT_INSTALL_PATH ) );
// Add kicad, kicad/share, share, and share/kicad to each possible base path.
for( i = 0; i < tmp.GetCount(); i++ ) for( i = 0; i < tmp.GetCount(); i++ )
{ {
fn = wxFileName( tmp[i], wxEmptyString ); fn = wxFileName( tmp[i], wxEmptyString );
...@@ -621,6 +618,13 @@ void EDA_APP::SetDefaultSearchPaths( void ) ...@@ -621,6 +618,13 @@ void EDA_APP::SetDefaultSearchPaths( void )
fn.RemoveLastDir(); fn.RemoveLastDir();
} }
} }
#if 1 && defined( DEBUG )
wxLogDebug( wxT( "Library search paths:" ) );
for( unsigned i = 0; i < m_libSearchPaths.GetCount(); i++ )
wxLogDebug( wxT( " %s" ), GetChars( m_libSearchPaths[i] ) );
#endif
} }
...@@ -662,11 +666,14 @@ void EDA_APP::GetSettings( bool aReopenLastUsedDirectory ) ...@@ -662,11 +666,14 @@ void EDA_APP::GetSettings( bool aReopenLastUsedDirectory )
} }
// FIXME OSX Mountain Lion (10.8) // FIXME OSX Mountain Lion (10.8)
// Seems that Read doesn't found anything and ColorFromInt Asserts - I'm unable to reproduce on 10.7 // Seems that Read doesn't found anything and ColorFromInt Asserts - I'm unable to reproduce
// In general terms i think is better have a failsafe default than an uninit variable // on 10.7
// In general terms I think is better have a failsafe default than an uninit variable
int draw_bg_color = (int)BLACK; // Default for all apps but Eeschema int draw_bg_color = (int)BLACK; // Default for all apps but Eeschema
if( m_Id == APP_EESCHEMA_T ) if( m_Id == APP_EESCHEMA_T )
draw_bg_color = (int)WHITE; // Default for Eeschema draw_bg_color = (int)WHITE; // Default for Eeschema
m_settings->Read( backgroundColorKey, &draw_bg_color ); m_settings->Read( backgroundColorKey, &draw_bg_color );
g_DrawBgColor = ColorFromInt( draw_bg_color ); g_DrawBgColor = ColorFromInt( draw_bg_color );
...@@ -876,7 +883,7 @@ void EDA_APP::AddMenuLanguageList( wxMenu* MasterMenu ) ...@@ -876,7 +883,7 @@ void EDA_APP::AddMenuLanguageList( wxMenu* MasterMenu )
wxString EDA_APP::FindFileInSearchPaths( const wxString& filename, wxString EDA_APP::FindFileInSearchPaths( const wxString& filename,
const wxArrayString* subdirs ) const wxArrayString* subdirs )
{ {
size_t i, j; size_t i, j;
wxFileName fn; wxFileName fn;
...@@ -979,21 +986,6 @@ wxString EDA_APP::GetHelpFile( void ) ...@@ -979,21 +986,6 @@ wxString EDA_APP::GetHelpFile( void )
} }
wxString EDA_APP::GetLibraryFile( const wxString& filename )
{
wxArrayString subdirs;
subdirs.Add( wxT( "share" ) );
#ifndef __WXMSW__
/* Up on level relative to binary path with "share/kicad" appended for
* all other platforms. */
subdirs.Add( wxT( "kicad" ) );
#endif
return FindFileInSearchPaths( filename, &subdirs );
}
wxString EDA_APP::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch ) wxString EDA_APP::ReturnLastVisitedLibraryPath( const wxString& aSubPathToSearch )
{ {
if( !m_LastVisitedLibPath.IsEmpty() ) if( !m_LastVisitedLibPath.IsEmpty() )
...@@ -1164,3 +1156,54 @@ bool EDA_APP::LockFile( const wxString& fileName ) ...@@ -1164,3 +1156,54 @@ bool EDA_APP::LockFile( const wxString& fileName )
return true; return true;
} }
bool EDA_APP::SetFootprintLibTablePath()
{
wxString path;
// Set the KISYSMOD environment variable for the current process if it is not already
// defined in the user's environment. This is required to expand the global footprint
// library table paths.
if( wxGetEnv( wxT( "KISYSMOD" ), &path ) && wxFileName::DirExists( path ) )
return true;
// Set the KISYSMOD environment variable to the path defined in the user's configuration
// if it is defined and the path exists.
if( m_commonSettings->Read( kicadFpLibPath, &path ) && wxFileName::DirExists( path ) )
{
wxSetEnv( wxT( "KISYSMOD" ), path );
wxLogDebug( wxT( "Setting $KISYSMOD=\"%s\"." ), GetChars( path ) );
return true;
}
// Attempt to determine where the footprint libraries were installed using the legacy
// library search paths.
if( !GetLibraryPathList().IsEmpty() )
{
unsigned modFileCount = 0;
wxString bestPath;
wxArrayString tmp;
for( unsigned i = 0; i < GetLibraryPathList().GetCount(); i++ )
{
unsigned cnt = wxDir::GetAllFiles( GetLibraryPathList()[i], &tmp, wxT( "*.mod" ),
wxDIR_DEFAULT & ~wxDIR_HIDDEN );
if( cnt > modFileCount )
{
modFileCount = cnt;
bestPath = GetLibraryPathList()[i];
}
}
if( modFileCount != 0 )
{
wxLogDebug( wxT( "Setting $KISYSMOD=\"%s\"." ), GetChars( bestPath ) );
wxSetEnv( wxT( "KISYSMOD" ), bestPath );
return true;
}
}
return false;
}
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <set> #include <set>
#include <appl_wxstruct.h>
#include <fp_lib_table_lexer.h> #include <fp_lib_table_lexer.h>
#include <fp_lib_table.h> #include <fp_lib_table.h>
...@@ -319,23 +320,38 @@ bool FP_LIB_TABLE::IsEmpty() const ...@@ -319,23 +320,38 @@ bool FP_LIB_TABLE::IsEmpty() const
} }
void FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR ) bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR )
{ {
bool tableExists = true;
wxFileName fn = GetGlobalTableFileName(); wxFileName fn = GetGlobalTableFileName();
wxLogDebug( wxT( "Loading global footprint table file: %s" ), GetChars( fn.GetFullPath() ) ); wxLogDebug( wxT( "Loading global footprint table file: %s" ), GetChars( fn.GetFullPath() ) );
if( !fn.FileExists() ) if( !fn.FileExists() )
{ {
/// @todo call some script to create initial global footprint table. tableExists = false;
}
else // Attempt to copy the default global file table from the KiCad template folder to
{ // the users home configuration path.
FILE_LINE_READER reader( fn.GetFullPath() ); wxString fileName( wxT( "fp_global_table" ) );
FP_LIB_TABLE_LEXER lexer( &reader ); fileName = wxGetApp().FindLibraryPath( fileName );
wxLogDebug( wxT( "Copying global footprint table from <%s>." ), GetChars( fileName ) );
aTable.Parse( &lexer ); // The fallback is to create an empty global footprint table for the user to populate.
if( fileName.IsEmpty() || !::wxCopyFile( fileName, fn.GetFullPath(), false ) )
{
FP_LIB_TABLE emptyTable;
FILE_OUTPUTFORMATTER sf( fn.GetFullPath() );
emptyTable.Format( &sf, 0 );
}
} }
FILE_LINE_READER reader( fn.GetFullPath() );
FP_LIB_TABLE_LEXER lexer( &reader );
aTable.Parse( &lexer );
return tableExists;
} }
...@@ -357,7 +373,26 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName() ...@@ -357,7 +373,26 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
wxString FP_LIB_TABLE::GetFileName() wxString FP_LIB_TABLE::GetFileName()
{ {
return wxString( wxT( ".fp-lib-table" ) ); return wxString( wxT( "fp-lib-table" ) );
}
void FP_LIB_TABLE::Load( const wxFileName& aFileName, FP_LIB_TABLE* aFallBackTable )
throw( IO_ERROR )
{
wxFileName fn = aFileName;
fallBack = aFallBackTable;
fn.SetName( FP_LIB_TABLE::GetFileName() );
fn.SetExt( wxEmptyString );
if( fn.FileExists() )
{
FILE_LINE_READER reader( fn.GetFullPath() );
FP_LIB_TABLE_LEXER lexer( &reader );
Parse( &lexer );
}
} }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/** /**
* @file cvpcb.cpp * @file cvpcb.cpp
*/ */
...@@ -22,7 +46,7 @@ ...@@ -22,7 +46,7 @@
// Colors for layers and items // Colors for layers and items
COLORS_DESIGN_SETTINGS g_ColorsSettings; COLORS_DESIGN_SETTINGS g_ColorsSettings;
/* Constant string definitions for CvPcb */ // Constant string definitions for CvPcb
const wxString RetroFileExtension( wxT( "stf" ) ); const wxString RetroFileExtension( wxT( "stf" ) );
const wxString FootprintAliasFileExtension( wxT( "equ" ) ); const wxString FootprintAliasFileExtension( wxT( "equ" ) );
...@@ -36,7 +60,7 @@ const wxString titleLibLoadError( _( "Library Load Error" ) ); ...@@ -36,7 +60,7 @@ const wxString titleLibLoadError( _( "Library Load Error" ) );
* MacOSX: Needed for file association * MacOSX: Needed for file association
* http://wiki.wxwidgets.org/WxMac-specific_topics * http://wiki.wxwidgets.org/WxMac-specific_topics
*/ */
void EDA_APP::MacOpenFile(const wxString &fileName) void EDA_APP::MacOpenFile( const wxString &fileName )
{ {
wxFileName filename = fileName; wxFileName filename = fileName;
wxString oldPath; wxString oldPath;
...@@ -48,7 +72,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName) ...@@ -48,7 +72,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName)
if( frame->m_NetlistFileName.DirExists() ) if( frame->m_NetlistFileName.DirExists() )
oldPath = frame->m_NetlistFileName.GetPath(); oldPath = frame->m_NetlistFileName.GetPath();
/* Update the library search path list. */ // Update the library search path list.
if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND ) if( wxGetApp().GetLibraryPathList().Index( oldPath ) != wxNOT_FOUND )
wxGetApp().GetLibraryPathList().Remove( oldPath ); wxGetApp().GetLibraryPathList().Remove( oldPath );
...@@ -58,6 +82,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName) ...@@ -58,6 +82,7 @@ void EDA_APP::MacOpenFile(const wxString &fileName)
frame->ReadNetListAndLinkFiles(); frame->ReadNetListAndLinkFiles();
} }
// Create a new application object // Create a new application object
IMPLEMENT_APP( EDA_APP ) IMPLEMENT_APP( EDA_APP )
...@@ -74,6 +99,10 @@ bool EDA_APP::OnInit() ...@@ -74,6 +99,10 @@ bool EDA_APP::OnInit()
InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T ); InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T );
#if defined( USE_FP_LIB_TABLE )
SetFootprintLibTablePath();
#endif
if( m_Checker && m_Checker->IsAnotherRunning() ) if( m_Checker && m_Checker->IsAnotherRunning() )
{ {
if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) ) if( !IsOK( NULL, _( "CvPcb is already running, Continue?" ) ) )
...@@ -88,7 +117,7 @@ bool EDA_APP::OnInit() ...@@ -88,7 +117,7 @@ bool EDA_APP::OnInit()
// read current setup and reopen last directory if no filename to open in command line // read current setup and reopen last directory if no filename to open in command line
bool reopenLastUsedDirectory = argc == 1; bool reopenLastUsedDirectory = argc == 1;
GetSettings(reopenLastUsedDirectory); GetSettings( reopenLastUsedDirectory );
g_DrawBgColor = BLACK; g_DrawBgColor = BLACK;
...@@ -97,15 +126,13 @@ bool EDA_APP::OnInit() ...@@ -97,15 +126,13 @@ bool EDA_APP::OnInit()
// Show the frame // Show the frame
SetTopWindow( frame ); SetTopWindow( frame );
frame->LoadProjectFile( filename.GetFullPath() );
frame->Show( true ); frame->Show( true );
frame->BuildFOOTPRINTS_LISTBOX(); frame->m_NetlistFileExtension = wxT( "net" );
frame->BuildLIBRARY_LISTBOX();
if( filename.IsOk() && filename.FileExists() ) if( filename.IsOk() && filename.FileExists() )
{ {
frame->m_NetlistFileName = filename; frame->m_NetlistFileName = filename;
frame->LoadProjectFile( filename.GetFullPath() );
if( frame->ReadNetListAndLinkFiles() ) if( frame->ReadNetListAndLinkFiles() )
{ {
...@@ -114,9 +141,6 @@ bool EDA_APP::OnInit() ...@@ -114,9 +141,6 @@ bool EDA_APP::OnInit()
} }
} }
frame->LoadFootprintFiles();
frame->m_NetlistFileExtension = wxT( "net" );
frame->m_NetlistFileName.Clear();
frame->UpdateTitle(); frame->UpdateTitle();
return true; return true;
......
...@@ -344,8 +344,6 @@ public: ...@@ -344,8 +344,6 @@ public:
*/ */
wxString GetHelpFile( void ); wxString GetHelpFile( void );
wxString GetLibraryFile( const wxString& filename );
/** /**
* Return the preferred editor name. * Return the preferred editor name.
*/ */
...@@ -414,6 +412,25 @@ public: ...@@ -414,6 +412,25 @@ public:
* @return false if the file was already locked, true otherwise. * @return false if the file was already locked, true otherwise.
*/ */
bool LockFile( const wxString& fileName ); bool LockFile( const wxString& fileName );
/**
* Function SetFootprintLibTableEnv
* attempts set the KISYSMOD environment variable to the best possible path.
*
* The path is determined by attempting to find the path with the most footprint library
* files. This may or may not be the best path but it provides the best solution for
* backwards compatibility with the previous library search path implementation. If the
* KISYSMOD environment variable is already set, then it left as is to respect the wishes
* of the user.
*
* @note This must be called after #SetDefaultSearchPaths() is called. Otherwise, the
* list of library search paths will be empty and KISYSMOD will be undefined making
* it impossible for the footprint libraries to be loaded from the footprint library
* table.
*
* @return false if the KISYSMOD path is not valid.
*/
bool SetFootprintLibTablePath();
}; };
......
...@@ -379,8 +379,11 @@ public: ...@@ -379,8 +379,11 @@ public:
* time being. * time being.
* *
* @param aTable the #FP_LIB_TABLE object to load. * @param aTable the #FP_LIB_TABLE object to load.
* @return true if the global library table exists and is loaded properly.
* @throw IO_ERROR if an error occurs attempting to load the footprint library
* table.
*/ */
static void LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR ); static bool LoadGlobalTable( FP_LIB_TABLE& aTable ) throw (IO_ERROR, PARSE_ERROR );
/** /**
* Function GetGlobalTableFileName * Function GetGlobalTableFileName
...@@ -394,6 +397,18 @@ public: ...@@ -394,6 +397,18 @@ public:
*/ */
static wxString GetFileName(); static wxString GetFileName();
/**
* Function Load
* loads the footprint library table using the path defined in \a aFileName with
* \a aFallBackTable.
*
* @param aFileName contains the path and possible the file name and extension.
* @param aFallBackTable the fall back footprint library table which can be NULL.
* @throw IO_ERROR if an error occurs attempting to load the footprint library
* table.
*/
void Load( const wxFileName& aFileName, FP_LIB_TABLE* aFallBackTable ) throw( IO_ERROR );
protected: protected:
/** /**
......
...@@ -173,6 +173,17 @@ public: ...@@ -173,6 +173,17 @@ public:
return m_Pcb; return m_Pcb;
} }
/**
* Function SetFootprintLibTable
* set the footprint library table to \a aFootprintLibTable.
*
* @param aFootprintLibTable is a pointer to the #FP_LIB_TABLE object.
*/
void SetFootprintLibTable( FP_LIB_TABLE* aFootprintLibTable )
{
m_footprintLibTable = aFootprintLibTable;
}
// General // General
virtual void OnCloseWindow( wxCloseEvent& Event ) = 0; virtual void OnCloseWindow( wxCloseEvent& Event ) = 0;
virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) { } virtual void RedrawActiveWindow( wxDC* DC, bool EraseBg ) { }
......
...@@ -202,12 +202,6 @@ protected: ...@@ -202,12 +202,6 @@ protected:
*/ */
void duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone ); void duplicateZone( wxDC* aDC, ZONE_CONTAINER* aZone );
/**
* Function loadFootprintLibTable
* deletes the existing #FP_LIB_TABLE and creates a new one when a new project is loaded.
*/
void loadFootprintLibTable();
public: public:
PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer PCB_LAYER_BOX_SELECTOR* m_SelLayerBox; // a combo box to display and select active layer
wxComboBox* m_SelTrackWidthBox; // a combo box to display and select current track width wxComboBox* m_SelTrackWidthBox; // a combo box to display and select current track width
......
...@@ -123,8 +123,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent, ...@@ -123,8 +123,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
PCB_BASE_FRAME( aParent, MODULE_VIEWER_FRAME_TYPE, _( "Footprint Library Browser" ), PCB_BASE_FRAME( aParent, MODULE_VIEWER_FRAME_TYPE, _( "Footprint Library Browser" ),
wxDefaultPosition, wxDefaultSize, aStyle, GetFootprintViewerFrameName() ) wxDefaultPosition, wxDefaultSize, aStyle, GetFootprintViewerFrameName() )
{ {
wxASSERT( aTable != NULL );
wxAcceleratorTable table( ACCEL_TABLE_CNT, accels ); wxAcceleratorTable table( ACCEL_TABLE_CNT, accels );
m_footprintLibTable = aTable; m_footprintLibTable = aTable;
......
...@@ -293,8 +293,11 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -293,8 +293,11 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
m_RecordingMacros = -1; m_RecordingMacros = -1;
m_microWaveToolBar = NULL; m_microWaveToolBar = NULL;
m_useCmpFileForFpNames = true; m_useCmpFileForFpNames = true;
#if defined( USE_FP_LIB_TABLE )
m_footprintLibTable = NULL; m_footprintLibTable = NULL;
m_globalFootprintTable = NULL; m_globalFootprintTable = NULL;
#endif
#ifdef KICAD_SCRIPTING_WXPYTHON #ifdef KICAD_SCRIPTING_WXPYTHON
m_pythonPanel = NULL; m_pythonPanel = NULL;
...@@ -443,12 +446,25 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -443,12 +446,25 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
m_auimgr.Update(); m_auimgr.Update();
#if defined( USE_FP_LIB_TABLE )
if( m_globalFootprintTable == NULL ) if( m_globalFootprintTable == NULL )
{ {
try try
{ {
m_globalFootprintTable = new FP_LIB_TABLE(); m_globalFootprintTable = new FP_LIB_TABLE();
FP_LIB_TABLE::LoadGlobalTable( *m_globalFootprintTable );
if( !FP_LIB_TABLE::LoadGlobalTable( *m_globalFootprintTable ) )
{
DisplayInfoMessage( this, wxT( "You have run Pcbnew for the first time using the "
"new footprint library table method for finding "
"footprints. Pcbnew has either copied the default "
"table or created an empty table in your home "
"folder. You must first configure the library "
"table to include all footprint libraries not "
"included with KiCad. See the \"Footprint Library "
"Table\" section of the CvPcb documentation for "
"more information." ) );
}
} }
catch( IO_ERROR ioe ) catch( IO_ERROR ioe )
{ {
...@@ -458,6 +474,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, ...@@ -458,6 +474,7 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
DisplayError( this, msg ); DisplayError( this, msg );
} }
} }
#endif
} }
...@@ -470,6 +487,7 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME() ...@@ -470,6 +487,7 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
m_Macros[i].m_Record.clear(); m_Macros[i].m_Record.clear();
delete m_drc; delete m_drc;
delete m_footprintLibTable;
delete m_globalFootprintTable; delete m_globalFootprintTable;
} }
......
...@@ -206,30 +206,9 @@ bool EDA_APP::OnInit() ...@@ -206,30 +206,9 @@ bool EDA_APP::OnInit()
// Some will be overwritten after loading the board file // Some will be overwritten after loading the board file
frame->LoadProjectSettings( fn.GetFullPath() ); frame->LoadProjectSettings( fn.GetFullPath() );
// Set the KISYSMOD environment variable for the current process if it is not already #if defined( USE_FP_LIB_TABLE )
// defined in the user's environment. This is required to expand the global footprint SetFootprintLibTablePath();
// library table paths. #endif
if( !wxGetEnv( wxT( "KISYSMOD" ), &msg ) && !GetLibraryPathList().IsEmpty() )
{
unsigned modFileCount = 0;
wxString bestPath;
wxArrayString tmp;
for( unsigned i = 0; i < GetLibraryPathList().GetCount(); i++ )
{
unsigned cnt = wxDir::GetAllFiles( GetLibraryPathList()[i], &tmp,
wxT( "*.mod" ), wxDIR_DEFAULT & ~wxDIR_HIDDEN );
if( cnt > modFileCount )
{
modFileCount = cnt;
bestPath = GetLibraryPathList()[i];
}
}
wxLogDebug( wxT( "Setting $KISYSMOD=\"%s\"." ), GetChars( bestPath ) );
wxSetEnv( wxT( "KISYSMOD" ), bestPath );
}
/* Load file specified in the command line. */ /* Load file specified in the command line. */
if( fn.IsOk() ) if( fn.IsOk() )
......
...@@ -222,13 +222,30 @@ bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName ) ...@@ -222,13 +222,30 @@ bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
SetElementVisibility( RATSNEST_VISIBLE, showRats ); SetElementVisibility( RATSNEST_VISIBLE, showRats );
#endif #endif
fn = GetBoard()->GetFileName();
// Check if a project footprint table is defined and load it. If no project footprint
// table is defined, then the global library table is the footprint library table.
#if defined( USE_FP_LIB_TABLE )
delete m_footprintLibTable;
m_footprintLibTable = new FP_LIB_TABLE();
try
{
m_footprintLibTable->Load( fn, m_globalFootprintTable );
}
catch( IO_ERROR ioe )
{
DisplayError( this, ioe.errorText );
}
#endif
// Load the page layout decr file, from the filename stored in // Load the page layout decr file, from the filename stored in
// BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
// If empty, the default descr is loaded // If empty, the default descr is loaded
WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance(); WORKSHEET_LAYOUT& pglayout = WORKSHEET_LAYOUT::GetTheInstance();
pglayout.SetPageLayout(BASE_SCREEN::m_PageLayoutDescrFileName); pglayout.SetPageLayout( BASE_SCREEN::m_PageLayoutDescrFileName );
loadFootprintLibTable();
return true; return true;
} }
...@@ -550,32 +567,3 @@ void PCB_EDIT_FRAME::ReadMacros() ...@@ -550,32 +567,3 @@ void PCB_EDIT_FRAME::ReadMacros()
macrosNode = (XNODE*) macrosNode->GetNext(); macrosNode = (XNODE*) macrosNode->GetNext();
} }
} }
void PCB_EDIT_FRAME::loadFootprintLibTable()
{
delete m_footprintLibTable;
wxFileName fn = GetBoard()->GetFileName();
fn.SetName( FP_LIB_TABLE::GetFileName() );
fn.SetExt( wxEmptyString );
// Check if a project footprint table is defined and load it. If no project footprint
// table is defined, then the global library table is the footprint library table.
m_footprintLibTable = new FP_LIB_TABLE( m_globalFootprintTable );
if( fn.FileExists() )
{
try
{
FILE_LINE_READER reader( fn.GetFullPath() );
FP_LIB_TABLE_LEXER lexer( &reader );
m_footprintLibTable->Parse( &lexer );
}
catch( IO_ERROR ioe )
{
DisplayError( this, ioe.errorText );
}
}
}
install(FILES kicad.pro install(FILES kicad.pro fp_global_table
DESTINATION ${KICAD_TEMPLATE} DESTINATION ${KICAD_TEMPLATE}
COMPONENT resources) COMPONENT resources)
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