Commit 7ba078b6 authored by Dick Hollenbeck's avatar Dick Hollenbeck

remove USE_FP_LIB_TABLE code, make it the norm. Add lazy loading support to FOOTPRINT_INFO.

parent b85a7133
......@@ -47,8 +47,6 @@ option( KICAD_SCRIPTING_WXPYTHON
# python binary file should be is exec path.
option( USE_FP_LIB_TABLE "Use the new footprint library table implementation. ( default OFF)" ON )
option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." OFF )
......
......@@ -58,9 +58,6 @@
/// The legacy file format revision of the *.brd file created by this build
#define LEGACY_BOARD_FILE_VERSION 2
/// Definition to compile with Pcbnew footprint library table implementation.
#cmakedefine USE_FP_LIB_TABLE
/// The install prefix defined in CMAKE_INSTALL_PREFIX.
#define DEFAULT_INSTALL_PATH "@CMAKE_INSTALL_PREFIX"
......
......@@ -566,12 +566,7 @@ void EDA_BASE_FRAME::CopyVersionInfoToClipboard( wxCommandEvent& event )
tmp << wxT( "OFF\n" );
#endif
tmp << wxT( " USE_FP_LIB_TABLE=" );
#ifdef USE_FP_LIB_TABLE
tmp << wxT( "ON\n" );
#else
tmp << wxT( "OFF\n" );
#endif
tmp << wxT( " USE_FP_LIB_TABLE=HARD_CODED_ON\n" );
tmp << wxT( " BUILD_GITHUB_PLUGIN=" );
#ifdef BUILD_GITHUB_PLUGIN
......
......@@ -30,7 +30,6 @@
#define USE_WORKER_THREADS 1 // 1:yes, 0:no. use worker thread to load libraries
/*
* Functions to read footprint libraries and fill m_footprints by available footprints names
* and their documentation (comments and keywords)
......@@ -46,10 +45,7 @@
#include <fp_lib_table.h>
#include <fpid.h>
#include <class_module.h>
#if defined(USE_FP_LIB_TABLE)
#include <boost/thread.hpp>
#endif
#include <boost/thread.hpp>
/*
......@@ -97,94 +93,22 @@ static wxString ToHTMLFragment( const IO_ERROR* aDerivative )
*/
#if !defined( USE_FP_LIB_TABLE )
bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintLibNames )
void FOOTPRINT_INFO::load()
{
bool retv = true;
// Clear data before reading files
m_error_count = 0;
m_errors.clear();
m_list.clear();
// try
{
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
// Parse Libraries Listed
for( unsigned ii = 0; ii < aFootprintLibNames.GetCount(); ii++ )
{
// Footprint library file names can be fully qualified or file name only.
wxFileName filename = aFootprintLibNames[ii];
if( !filename.FileExists() )
{
filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
FP_LIB_TABLE* fptable = m_owner->GetTable();
if( !filename.FileExists() )
{
filename = wxFileName( wxEmptyString, aFootprintLibNames[ii],
LegacyFootprintLibPathExtension );
wxASSERT( fptable );
filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
}
}
wxLogDebug( wxT( "Path <%s> -> <%s>." ), GetChars( aFootprintLibNames[ii] ),
GetChars( filename.GetFullPath() ) );
try
{
wxArrayString fpnames = pi->FootprintEnumerate( filename.GetFullPath() );
for( unsigned i=0; i<fpnames.GetCount(); ++i )
{
std::auto_ptr<MODULE> m( pi->FootprintLoad( filename.GetFullPath(),
fpnames[i] ) );
// we're loading what we enumerated, all must be there.
wxASSERT( m.get() );
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO();
std::auto_ptr<MODULE> m( fptable->FootprintLoad( m_nickname, m_fpname ) );
fpinfo->SetNickname( filename.GetName() );
fpinfo->SetLibPath( filename.GetFullPath() );
fpinfo->m_Module = fpnames[i];
fpinfo->m_padCount = m->GetPadCount( MODULE::DO_NOT_INCLUDE_NPTH );
fpinfo->m_KeyWord = m->GetKeywords();
fpinfo->m_Doc = m->GetDescription();
m_pad_count = m->GetPadCount( MODULE::DO_NOT_INCLUDE_NPTH );
m_keywords = m->GetKeywords();
m_doc = m->GetDescription();
AddItem( fpinfo );
}
}
catch( const PARSE_ERROR& pe )
{
m_errors.push_back( new PARSE_ERROR( pe ) );
retv = false;
}
catch( const IO_ERROR& ioe )
{
m_errors.push_back( new IO_ERROR( ioe ) );
retv = false;
}
}
}
/* caller should catch this, UI seems not wanted here.
catch( const IO_ERROR& ioe )
{
DisplayError( NULL, ioe.errorText );
return false;
}
*/
m_list.sort();
return retv;
// tell ensure_loaded() I'm loaded.
m_loaded = true;
}
#else // yes USE_FP_LIB_TABLE, by all means:
#define JOBZ 6 // no. libraries per worker thread. It takes about
// a second to load a GITHUB library, so assigning
......@@ -214,18 +138,9 @@ void FOOTPRINT_LIST::loader_job( const wxString* aNicknameList, int aJobZ )
for( unsigned ni=0; ni<fpnames.GetCount(); ++ni )
{
std::auto_ptr<MODULE> m( m_lib_table->FootprintLoad( nickname, fpnames[ni] ) );
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO();
fpinfo->SetNickname( nickname );
fpinfo->m_Module = fpnames[ni];
fpinfo->m_padCount = m->GetPadCount( MODULE::DO_NOT_INCLUDE_NPTH );
fpinfo->m_KeyWord = m->GetKeywords();
fpinfo->m_Doc = m->GetDescription();
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO( this, nickname, fpnames[ni] );
AddItem( fpinfo );
addItem( fpinfo );
}
}
catch( const PARSE_ERROR& pe )
......@@ -346,27 +261,12 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* a
return retv;
}
#endif // USE_FP_LIB_TABLE
void FOOTPRINT_LIST::AddItem( FOOTPRINT_INFO* aItem )
FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
{
#if defined( USE_FP_LIB_TABLE )
// m_list is not thread safe, and this function is called from
// worker threads, lock m_list.
MUTLOCK lock( m_list_lock );
#endif
m_list.push_back( aItem );
}
const FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintName )
{
BOOST_FOREACH( const FOOTPRINT_INFO& footprint, m_list )
BOOST_FOREACH( FOOTPRINT_INFO& fp, m_list )
{
#if defined( USE_FP_LIB_TABLE )
FPID fpid;
wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
......@@ -376,42 +276,17 @@ const FOOTPRINT_INFO* FOOTPRINT_LIST::GetModuleInfo( const wxString& aFootprintN
wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() );
wxString footprintName = FROM_UTF8( fpid.GetFootprintName().c_str() );
if( libNickname == footprint.m_nickname && footprintName == footprint.m_Module )
return &footprint;
#else
if( aFootprintName.CmpNoCase( footprint.m_Module ) == 0 )
return &footprint;
#endif
if( libNickname == fp.GetNickname() && footprintName == fp.GetFootprintName() )
return &fp;
}
return NULL;
}
bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
{
#if defined( USE_FP_LIB_TABLE )
return aLibrary == m_nickname;
#else
if( aLibrary.IsEmpty() )
return false;
if( aLibrary == m_nickname || aLibrary == m_lib_path )
return true;
wxFileName filename = aLibrary;
if( filename.GetExt().IsEmpty() )
filename.SetExt( LegacyFootprintLibPathExtension );
if( filename.GetFullPath() == m_lib_path )
return true;
if( filename.GetPath().IsEmpty() )
filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
return filename.GetFullPath() == m_lib_path;
#endif
}
......
......@@ -185,7 +185,7 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )
for( size_t jj = 0; jj < filtercount && !found; jj++ )
{
found = module->m_Module.Matches( component->GetFootprintFilters()[jj] );
found = module->GetFootprintName().Matches( component->GetFootprintFilters()[jj] );
}
}
else
......
......@@ -89,7 +89,6 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
// User library path takes precedent over default library search paths.
wxGetApp().InsertLibraryPath( m_UserLibraryPath, 1 );
#if defined( USE_FP_LIB_TABLE )
delete m_footprintLibTable;
// Attempt to load the project footprint library table if it exists.
......@@ -111,7 +110,6 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
{
DisplayError( this, ioe.errorText );
}
#endif
}
......
......@@ -479,7 +479,6 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
try
{
#if defined( USE_FP_LIB_TABLE )
FPID fpid;
if( fpid.Parse( aFootprintName ) >= 0 )
......@@ -496,35 +495,6 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
fpname.c_str(), nickname.c_str() );
footprint = m_footprintLibTable->FootprintLoad( FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) );
#else
CVPCB_MAINFRAME* parent = ( CVPCB_MAINFRAME* ) GetParent();
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
for( unsigned i = 0; i < parent->m_ModuleLibNames.GetCount(); ++i )
{
wxFileName fn( wxEmptyString, parent->m_ModuleLibNames[i],
LegacyFootprintLibPathExtension );
wxString libPath = wxGetApp().FindLibraryPath( fn );
if( !libPath )
{
wxString msg = wxString::Format( _( "PCB footprint library file <%s> could not "
"be found in the default search paths." ),
fn.GetFullName().GetData() );
// @todo we should not be using wxMessageBox directly.
wxMessageBox( msg, wxEmptyString, wxOK | wxICON_ERROR, this );
continue;
}
footprint = pi->FootprintLoad( libPath, aFootprintName );
if( footprint != NULL )
break;
}
#endif
}
catch( IO_ERROR ioe )
{
......
......@@ -135,14 +135,9 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a
{
if( aFilterType == UNFILTERED )
{
#if !defined( USE_FP_LIB_TABLE )
msg.Printf( wxT( "%3zu %s" ), newList.GetCount() + 1,
GetChars( aList.GetItem( ii ).m_Module ) );
#else
msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
GetChars( aList.GetItem( ii ).GetNickname() ),
GetChars( aList.GetItem( ii ).m_Module ) );
#endif
GetChars( aList.GetItem( ii ).GetFootprintName() ) );
newList.Add( msg );
continue;
}
......@@ -151,22 +146,17 @@ void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& a
&& !aList.GetItem( ii ).InLibrary( aLibName ) )
continue;
if( (aFilterType & BY_COMPONENT) && (aComponent != NULL)
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).m_Module ) )
if( (aFilterType & BY_COMPONENT) && aComponent
&& !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetFootprintName() ) )
continue;
if( (aFilterType & BY_PIN_COUNT) && (aComponent!= NULL)
&& (aComponent->GetNetCount() != aList.GetItem( ii ).m_padCount) )
if( (aFilterType & BY_PIN_COUNT) && aComponent
&& aComponent->GetNetCount() != aList.GetItem( ii ).GetPadCount() )
continue;
#if !defined( USE_FP_LIB_TABLE )
msg.Printf( wxT( "%3zu %s" ), newList.GetCount() + 1,
aList.GetItem( ii ).m_Module.GetData() );
#else
msg.Printf( wxT( "%3zu %s:%s" ), newList.GetCount() + 1,
GetChars( aList.GetItem( ii ).GetNickname() ),
GetChars( aList.GetItem( ii ).m_Module ) );
#endif
GetChars( aList.GetItem( ii ).GetFootprintName() ) );
newList.Add( msg );
}
......
......@@ -73,9 +73,7 @@ BEGIN_EVENT_TABLE( CVPCB_MAINFRAME, EDA_BASE_FRAME )
EVT_MENU( ID_SAVE_PROJECT_AS, CVPCB_MAINFRAME::SaveProjectFile )
EVT_MENU( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnKeepOpenOnSave )
#if defined( USE_FP_LIB_TABLE )
EVT_MENU( ID_CVPCB_LIB_TABLE_EDIT, CVPCB_MAINFRAME::OnEditFootprintLibraryTable )
#endif
EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, CVPCB_MAINFRAME::SetLanguage )
......@@ -122,10 +120,8 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( const wxString& title, long style ) :
m_undefinedComponentCnt = 0;
m_skipComponentSelect = false;
#if defined( USE_FP_LIB_TABLE )
m_globalFootprintTable = NULL;
m_footprintLibTable = NULL;
#endif
/* Name of the document footprint list
* usually located in share/modules/footprints_doc
......@@ -199,7 +195,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( const wxString& title, long style ) :
m_auimgr.Update();
#if defined( USE_FP_LIB_TABLE )
if( m_globalFootprintTable == NULL )
{
try
......@@ -229,8 +224,6 @@ CVPCB_MAINFRAME::CVPCB_MAINFRAME( const wxString& title, long style ) :
m_footprintLibTable = new FP_LIB_TABLE( m_globalFootprintTable );
}
#endif
}
......@@ -511,7 +504,6 @@ void CVPCB_MAINFRAME::ConfigCvpcb( wxCommandEvent& event )
}
#if defined( USE_FP_LIB_TABLE )
void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
{
bool tableChanged = false;
......@@ -558,7 +550,6 @@ void CVPCB_MAINFRAME::OnEditFootprintLibraryTable( wxCommandEvent& aEvent )
if( tableChanged )
BuildLIBRARY_LISTBOX();
}
#endif
void CVPCB_MAINFRAME::OnKeepOpenOnSave( wxCommandEvent& event )
......@@ -705,14 +696,14 @@ void CVPCB_MAINFRAME::DisplayStatus()
{
wxString footprintName = m_FootprintList->GetSelectedFootprint();
const FOOTPRINT_INFO* module = m_footprints.GetModuleInfo( footprintName );
FOOTPRINT_INFO* module = m_footprints.GetModuleInfo( footprintName );
if( module ) // can be NULL if no netlist loaded
{
msg = _( "Description: " ) + module->m_Doc;
msg = _( "Description: " ) + module->GetDoc();
SetStatusText( msg, 0 );
msg = _( "Key words: " ) + module->m_KeyWord;
msg = _( "Key words: " ) + module->GetKeywords();
SetStatusText( msg, 1 );
}
}
......@@ -762,12 +753,8 @@ bool CVPCB_MAINFRAME::LoadFootprintFiles()
return false;
}
#if !defined( USE_FP_LIB_TABLE )
m_footprints.ReadFootprintFiles( m_ModuleLibNames );
#else
if( m_footprintLibTable != NULL )
m_footprints.ReadFootprintFiles( m_footprintLibTable );
#endif
if( m_footprints.GetErrorCount() )
{
......@@ -936,9 +923,7 @@ void CVPCB_MAINFRAME::CreateScreenCmp()
wxSize( 600, 400 ),
KICAD_DEFAULT_DRAWFRAME_STYLE );
#if defined( USE_FP_LIB_TABLE )
m_DisplayFootprintFrame->SetFootprintLibTable( m_footprintLibTable );
#endif
m_DisplayFootprintFrame->Show( true );
}
......@@ -1035,7 +1020,6 @@ void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
wxFONTWEIGHT_NORMAL ) );
}
#if defined( USE_FP_LIB_TABLE )
if( m_footprintLibTable )
{
wxArrayString libNames;
......@@ -1047,9 +1031,6 @@ void CVPCB_MAINFRAME::BuildLIBRARY_LISTBOX()
m_LibraryList->SetLibraryList( libNames );
}
#else
m_LibraryList->SetLibraryList( m_ModuleLibNames );
#endif
}
......
......@@ -99,9 +99,7 @@ bool EDA_APP::OnInit()
InitEDA_Appl( wxT( "CvPcb" ), APP_CVPCB_T );
#if defined( USE_FP_LIB_TABLE )
SetFootprintLibTablePath();
#endif
if( m_Checker && m_Checker->IsAnotherRunning() )
{
......
......@@ -55,7 +55,6 @@ class CVPCB_MAINFRAME : public EDA_BASE_FRAME
{
wxArrayString m_footprintListEntries;
#if defined( USE_FP_LIB_TABLE )
/// The global footprint library table.
FP_LIB_TABLE* m_globalFootprintTable;
......@@ -63,7 +62,6 @@ class CVPCB_MAINFRAME : public EDA_BASE_FRAME
/// footprint library table and the global footprint table. This is the one to
/// use when finding a #MODULE.
FP_LIB_TABLE* m_footprintLibTable;
#endif
public:
bool m_KeepCvpcbOpen;
......@@ -148,9 +146,7 @@ public:
* Function OnEditLibraryTable
* envokes the footpirnt library table edit dialog.
*/
#if defined( USE_FP_LIB_TABLE )
void OnEditFootprintLibraryTable( wxCommandEvent& aEvent );
#endif
void OnKeepOpenOnSave( wxCommandEvent& event );
void DisplayModule( wxCommandEvent& event );
......
......@@ -110,17 +110,9 @@ void CVPCB_MAINFRAME::ReCreateMenuBar()
// Menu Preferences:
wxMenu* preferencesMenu = new wxMenu;
#if !defined( USE_FP_LIB_TABLE )
// Libraries to load
AddMenuItem( preferencesMenu, wxID_PREFERENCES,
_( "&Libraries" ),
_( "Set footprint libraries to load and library search paths" ),
KiBitmap( config_xpm ) );
#else
AddMenuItem( preferencesMenu, ID_CVPCB_LIB_TABLE_EDIT,
_( "Li&brary Tables" ), _( "Setup footprint libraries" ),
KiBitmap( library_table_xpm ) );
#endif
// Language submenu
wxGetApp().AddMenuLanguageList( preferencesMenu );
......
......@@ -159,8 +159,6 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
isLegacy = false; // None of the components have footprints assigned.
}
#if defined( USE_FP_LIB_TABLE )
wxString missingLibs;
// Check if footprint links were generated before the footprint library table was implemented.
......@@ -217,7 +215,6 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
}
}
}
#endif
for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{
......@@ -272,7 +269,6 @@ int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
if( !fn.HasExt() )
fn.SetExt( ComponentFileExtension );
#if defined( USE_FP_LIB_TABLE )
// Save the project specific footprint library table.
if( !m_footprintLibTable->IsEmpty( false ) )
{
......@@ -298,8 +294,6 @@ int CVPCB_MAINFRAME::SaveCmpLinkFile( const wxString& aFullFileName )
}
}
}
#endif
}
if( !IsWritable( fn.GetFullPath() ) )
......
......@@ -33,14 +33,15 @@
#include <boost/ptr_container/ptr_vector.hpp>
#include <boost/foreach.hpp>
#if defined( USE_FP_LIB_TABLE )
#include <ki_mutex.h>
#endif
#include <ki_mutex.h>
#include <kicad_string.h>
#define USE_FPI_LAZY 0 // 1:yes lazy, 0:no early
class FP_LIB_TABLE;
class FOOTPRINT_LIST;
class wxTopLevelWindow;
......@@ -51,38 +52,52 @@ class wxTopLevelWindow;
*/
class FOOTPRINT_INFO
{
friend bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 );
public:
// friend bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 );
// These two accessors do not have to call ensure_loaded(), because constructor
// fills in these fields:
wxString m_nickname; ///< the library nickname, eventually
const wxString& GetFootprintName() const { return m_fpname; }
const wxString& GetNickname() const { return m_nickname; }
#if !defined(USE_FP_LIB_TABLE)
wxString m_lib_path;
FOOTPRINT_INFO( FOOTPRINT_LIST* aOwner, const wxString& aNickname, const wxString& aFootprintName ) :
m_owner( aOwner ),
m_loaded( false ),
m_nickname( aNickname ),
m_fpname( aFootprintName ),
m_num( 0 ),
m_pad_count( 0 )
{
#if !USE_FPI_LAZY
load();
#endif
}
wxString m_Module; ///< Module name.
int m_Num; ///< Order number in the display list.
wxString m_Doc; ///< Footprint description.
wxString m_KeyWord; ///< Footprint key words.
unsigned m_padCount; ///< Number of pads
FOOTPRINT_INFO()
const wxString& GetDoc()
{
m_Num = 0;
m_padCount = 0;
ensure_loaded();
return m_doc;
}
const wxString& GetFootprintName() const { return m_Module; }
const wxString& GetKeywords()
{
ensure_loaded();
return m_keywords;
}
void SetNickname( const wxString& aLibNickname ) { m_nickname = aLibNickname; }
const wxString& GetNickname() const { return m_nickname; }
unsigned GetPadCount()
{
ensure_loaded();
return m_pad_count;
}
#if !defined(USE_FP_LIB_TABLE)
void SetLibPath( const wxString& aLibPath ) { m_lib_path = aLibPath; }
const wxString& GetLibPath() const { return m_lib_path; }
#endif
int GetOrderNum()
{
ensure_loaded();
return m_num;
}
/**
* Function InLibrary
......@@ -94,20 +109,40 @@ public:
* false.
*/
bool InLibrary( const wxString& aLibrary ) const;
private:
void ensure_loaded()
{
if( !m_loaded )
load();
}
/// lazily load stuff not filled in by constructor. This may throw IO_ERRORS.
void load();
FOOTPRINT_LIST* m_owner; ///< provides access to FP_LIB_TABLE
bool m_loaded;
wxString m_nickname; ///< library as known in FP_LIB_TABLE
wxString m_fpname; ///< Module name.
int m_num; ///< Order number in the display list.
int m_pad_count; ///< Number of pads
wxString m_doc; ///< Footprint description.
wxString m_keywords; ///< Footprint keywords.
};
/// FOOTPRINT object list sort function.
inline bool operator<( const FOOTPRINT_INFO& item1, const FOOTPRINT_INFO& item2 )
{
#if defined( USE_FP_LIB_TABLE )
int retv = StrNumCmp( item1.m_nickname, item2.m_nickname, INT_MAX, true );
if( retv != 0 )
return retv < 0;
#endif
return StrNumCmp( item1.m_Module, item2.m_Module, INT_MAX, true ) < 0;
return StrNumCmp( item1.m_fpname, item2.m_fpname, INT_MAX, true ) < 0;
}
......@@ -121,17 +156,14 @@ class FOOTPRINT_LIST
FP_LIB_TABLE* m_lib_table; ///< no ownership
volatile int m_error_count; ///< thread safe to read.
typedef boost::ptr_vector< FOOTPRINT_INFO > FPILIST;
typedef boost::ptr_vector< IO_ERROR > ERRLIST;
FPILIST m_list;
ERRLIST m_errors; ///< some can be PARSE_ERRORs also
#if defined( USE_FP_LIB_TABLE )
MUTEX m_errors_lock;
MUTEX m_list_lock;
#endif
/**
* Function loader_job
......@@ -143,6 +175,16 @@ class FOOTPRINT_LIST
*/
void loader_job( const wxString* aNicknameList, int aJobZ );
void addItem( FOOTPRINT_INFO* aItem )
{
// m_list is not thread safe, and this function is called from
// worker threads, lock m_list.
MUTLOCK lock( m_list_lock );
m_list.push_back( aItem );
}
public:
FOOTPRINT_LIST() :
......@@ -163,16 +205,16 @@ public:
/**
* Function GetModuleInfo
* @param aFootprintName = the footprint name inside the FOOTPRINT_INFO of interest.
* @return const FOOTPRINT_INF* - the item stored in list if found
* @return FOOTPRINT_INF* - the item stored in list if found
*/
const FOOTPRINT_INFO* GetModuleInfo( const wxString& aFootprintName );
FOOTPRINT_INFO* GetModuleInfo( const wxString& aFootprintName );
/**
* Function GetItem
* @param aIdx = index of the given item
* @return the aIdx item in list
*/
const FOOTPRINT_INFO& GetItem( unsigned aIdx ) const { return m_list[aIdx]; }
FOOTPRINT_INFO& GetItem( unsigned aIdx ) { return m_list[aIdx]; }
/**
* Function AddItem
......@@ -185,15 +227,6 @@ public:
const IO_ERROR* GetError( unsigned aIdx ) const { return &m_errors[aIdx]; }
#if !defined( USE_FP_LIB_TABLE )
/**
* Function ReadFootprintFiles
*
* @param aFootprintsLibNames = an array string giving the list of libraries to load
*/
bool ReadFootprintFiles( wxArrayString& aFootprintsLibNames );
#endif
/**
* Function ReadFootprintFiles
* reads all the footprints provided by the combination of aTable and aNickname.
......@@ -208,6 +241,8 @@ public:
bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = NULL );
void DisplayErrors( wxTopLevelWindow* aCaller = NULL );
FP_LIB_TABLE* GetTable() const { return m_lib_table; }
};
#endif // FOOTPRINT_INFO_H_
......@@ -640,26 +640,4 @@ protected:
FP_LIB_TABLE* fallBack;
};
#if 0 // I don't think this is going to be needed.
/**
* Function LookupPart
* finds and loads a MODULE, and parses it. As long as the part is
* accessible in any LIB_SOURCE, opened or not opened, this function
* will find it and load it into its containing LIB, even if that means
* having to open a LIB in this table that was not previously opened.
*
* @param aFootprintId The fully qualified name of the footprint to look up.
*
* @return MODULE* - this will never be NULL, and no ownership is transferred because
* all MODULEs live in LIBs. You only get to point to them in some LIB. If the MODULE
* cannot be found, then an exception is thrown.
*
* @throw IO_ERROR if any problem occurs or if the footprint cannot be found.
*/
MODULE* LookupFootprint( const FP_LIB_ID& aFootprintId ) throw( IO_ERROR );
#endif
#endif // FP_LIB_TABLE_H_
......@@ -141,7 +141,6 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
{
Clear_Pcb( true );
#if defined( USE_FP_LIB_TABLE )
// Create a new empty footprint library table for the new board.
delete m_footprintLibTable;
m_footprintLibTable = new FP_LIB_TABLE( m_globalFootprintTable );
......@@ -158,7 +157,6 @@ void PCB_EDIT_FRAME::Files_io( wxCommandEvent& event )
wxFileName emptyFileName;
FP_LIB_TABLE::SetProjectPathEnvVariable( emptyFileName );
#endif
wxFileName fn;
fn.AssignCwd();
......@@ -535,7 +533,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
GetChars( pcbFileName.GetFullPath() ) )) )
return false;
#if defined( USE_FP_LIB_TABLE )
// Save the project specific footprint library table.
if( !m_footprintLibTable->IsEmpty( false ) )
{
......@@ -561,8 +558,6 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool aCreateBackupF
}
}
}
#endif
}
else
{
......
......@@ -464,8 +464,6 @@ wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
{
#if defined(USE_FP_LIB_TABLE)
wxString nickname = getLibNickName();
if( !m_footprintLibTable->IsFootprintLibWritable( nickname ) )
......@@ -509,48 +507,9 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
SetStatusText( msg );
return true;
#else
PCB_EDIT_FRAME* parent = (PCB_EDIT_FRAME*) GetParent();
wxString libPath = getLibPath();
wxString footprintName = PCB_BASE_FRAME::SelectFootprint( this, libPath,
wxEmptyString, wxEmptyString,
parent->GetFootprintLibraryTable() );
if( !footprintName )
return false;
// Confirmation
wxString msg = wxString::Format( FMT_OK_DELETE, footprintName.GetData(), libPath.GetData() );
if( !IsOK( this, msg ) )
return false;
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( libPath );
try
{
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
pi->FootprintDelete( libPath, footprintName );
}
catch( IO_ERROR ioe )
{
DisplayError( NULL, ioe.errorText );
return false;
}
msg.Printf( FMT_MOD_DELETED, footprintName.GetData(), libPath.GetData() );
SetStatusText( msg );
return true;
#endif
}
#if defined(USE_FP_LIB_TABLE)
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
{
if( GetBoard()->m_Modules == NULL )
......@@ -608,90 +567,6 @@ void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
DisplayError( this, ioe.errorText );
}
}
#else
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( bool aNewModulesOnly )
{
wxString fileName;
wxString path;
if( GetBoard()->m_Modules == NULL )
{
DisplayInfoMessage( this, FMT_NO_MODULES );
return;
}
path = wxGetApp().ReturnLastVisitedLibraryPath();
{
wxFileDialog dlg( this, FMT_LIBRARY, path,
wxEmptyString,
wxGetTranslation( LegacyFootprintLibPathWildcard ),
wxFD_SAVE );
if( dlg.ShowModal() == wxID_CANCEL )
return;
fileName = dlg.GetPath();
}
wxFileName fn( fileName );
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
bool lib_exists = wxFileExists( fileName );
if( !aNewModulesOnly && lib_exists )
{
wxString msg = wxString::Format( FMT_OK_OVERWRITE, GetChars( fileName ) );
if( !IsOK( this, msg ) )
return;
}
m_canvas->SetAbortRequest( false );
try
{
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
// Delete old library if we're replacing it entirely.
if( lib_exists && !aNewModulesOnly )
{
pi->FootprintLibDelete( fileName );
lib_exists = false;
}
if( !lib_exists )
{
pi->FootprintLibCreate( fileName );
}
if( !aNewModulesOnly )
{
for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() )
{
pi->FootprintSave( fileName, m );
}
}
else
{
for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() )
{
if( !Save_Module_In_Library( fileName, m, false, false ) )
break;
// Check for request to stop backup (ESCAPE key actuated)
if( m_canvas->GetAbortRequest() )
break;
}
}
}
catch( IO_ERROR ioe )
{
DisplayError( this, ioe.errorText );
}
}
#endif
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary,
......@@ -744,7 +619,6 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary,
bool module_exists = false;
#if defined(USE_FP_LIB_TABLE)
try
{
MODULE* m = m_footprintLibTable->FootprintLoad( aLibrary, footprintName );
......@@ -774,45 +648,6 @@ bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibrary,
// this always overwrites any existing footprint, but should yell on its
// own if the library or footprint is not writable.
m_footprintLibTable->FootprintSave( aLibrary, aModule );
#else
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( aLibrary );
try
{
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
MODULE* m = pi->FootprintLoad( aLibrary, footprintName );
if( m )
{
delete m;
module_exists = true;
// an existing footprint is found in current lib
if( aDisplayDialog )
{
wxString msg = wxString::Format( FMT_MOD_EXISTS,
footprintName.GetData(), aLibrary.GetData() );
SetStatusText( msg );
}
if( !aOverwrite )
{
// Do not save the given footprint: an old one exists
return true;
}
}
// this always overwrites any existing footprint, but should yell on its
// own if the library or footprint is not writable.
pi->FootprintSave( aLibrary, aModule );
#endif
}
catch( IO_ERROR ioe )
{
......@@ -890,50 +725,6 @@ MODULE* PCB_BASE_FRAME::Create_1_Module( const wxString& aModuleName )
}
#if !defined( USE_FP_LIB_TABLE )
wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
{
if( g_LibraryNames.GetCount() == 0 )
return wxEmptyString;
wxArrayString headers;
headers.Add( _( "Library" ) );
std::vector<wxArrayString> itemsToDisplay;
// Conversion from wxArrayString to vector of ArrayString
for( unsigned i = 0; i < g_LibraryNames.GetCount(); i++ )
{
wxArrayString item;
item.Add( g_LibraryNames[i] );
itemsToDisplay.push_back( item );
}
EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, headers, itemsToDisplay, aNicknameExisting );
if( dlg.ShowModal() != wxID_OK )
return wxEmptyString;
wxFileName fileName = wxFileName( wxEmptyString, dlg.GetTextSelection(),
LegacyFootprintLibPathExtension );
fileName = wxGetApp().FindLibraryPath( fileName );
if( !fileName.IsOk() || !fileName.FileExists() )
{
wxString msg = wxString::Format( FMT_BAD_PATHS, GetChars( dlg.GetTextSelection() ) );
DisplayError( this, msg );
return wxEmptyString;
}
return fileName.GetFullPath();
}
#else
wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
{
wxArrayString headers;
......@@ -965,5 +756,3 @@ wxString PCB_BASE_FRAME::SelectLibrary( const wxString& aNicknameExisting )
return nickname;
}
#endif
......@@ -138,13 +138,7 @@ wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser()
if( !!fpname )
{
#if !defined( USE_FP_LIB_TABLE )
// Returns the full fp name, i.e. the lib name and the fp name,
// separated by a '/' (/ is now an illegal char in fp names)
fpid = viewer->GetSelectedLibraryFullName() + wxT( "/" ) + fpname;
#else
fpid = viewer->GetSelectedLibrary() + wxT( ":" ) + fpname;
#endif
}
viewer->Destroy();
......@@ -179,13 +173,7 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
{
// SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e.
// <lib_name>/<footprint name> or FPID format "lib_name:fp_name:rev#"
#if !defined( USE_FP_LIB_TABLE )
wxString full_fpname = SelectFootprintFromLibBrowser();
moduleName = full_fpname.AfterLast( '/' );
libName = full_fpname.BeforeLast( '/' );
#else
moduleName = SelectFootprintFromLibBrowser();
#endif
}
else
{
......@@ -223,9 +211,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
}
}
#if !defined( USE_FP_LIB_TABLE )
module = GetModuleLibrary( libName, moduleName, false );
#else
FPID fpid;
wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
......@@ -241,7 +226,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
fpid.Format().c_str(), GetChars( ioe.errorText ) );
}
#endif
if( !module && allowWildSeach ) // Search with wild card
{
......@@ -259,9 +243,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
}
else
{
#if !defined( USE_FP_LIB_TABLE )
module = GetModuleLibrary( libName, moduleName, true );
#else
FPID fpid;
wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
......@@ -277,7 +258,6 @@ MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
wxLogDebug( wxT( "An error occurred attemping to load footprint '%s'.\n\nError: %s" ),
fpid.Format().c_str(), GetChars( ioe.errorText ) );
}
#endif
}
}
......@@ -514,27 +494,6 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
std::vector< wxArrayString > rows;
#if !defined( USE_FP_LIB_TABLE )
if( aLibraryName.IsEmpty() )
{
libraries = g_LibraryNames;
}
else
{
libraries.Add( aLibraryName );
}
if( libraries.IsEmpty() )
{
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
return wxEmptyString;
}
MList.ReadFootprintFiles( libraries );
#else
wxASSERT( aTable != NULL );
MList.ReadFootprintFiles( aTable, !aLibraryName ? NULL : &aLibraryName );
......@@ -545,8 +504,6 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
return wxEmptyString;
}
#endif
if( MList.GetCount() == 0 )
{
wxString tmp;
......@@ -567,7 +524,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
{
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
{
if( KeyWordOk( aKeyWord, MList.GetItem( ii ).m_KeyWord ) )
if( KeyWordOk( aKeyWord, MList.GetItem( ii ).GetKeywords() ) )
{
wxArrayString cols;
cols.Add( MList.GetItem( ii ).GetFootprintName() );
......@@ -580,7 +537,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
{
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
{
const wxString& candidate = MList.GetItem( ii ).m_Module;
const wxString& candidate = MList.GetItem( ii ).GetFootprintName();
if( WildCompareString( aMask, candidate, false ) )
{
......@@ -617,9 +574,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
{
fpname = dlg.GetTextSelection();
#if defined( USE_FP_LIB_TABLE )
fpname = dlg.GetTextSelection( 1 ) + wxT( ":" ) + fpname;
#endif
SkipNextLeftButtonReleaseEvent();
}
......@@ -643,7 +598,7 @@ wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
static void DisplayCmpDoc( wxString& aName )
{
const FOOTPRINT_INFO* module_info = MList.GetModuleInfo( aName );
FOOTPRINT_INFO* module_info = MList.GetModuleInfo( aName );
if( !module_info )
{
......@@ -651,8 +606,8 @@ static void DisplayCmpDoc( wxString& aName )
return;
}
aName = _( "Description: " ) + module_info->m_Doc;
aName += _( "\nKey words: " ) + module_info->m_KeyWord;
aName = _( "Description: " ) + module_info->GetDoc();
aName += _( "\nKey words: " ) + module_info->GetKeywords();
}
......
......@@ -142,8 +142,8 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
KiBitmap( tools_xpm ) );
AddMenuItem( fabricationOutputsMenu, ID_PCB_GEN_D356_FILE,
_( "IPC-D-356 Netlist File" ),
_( "Generate IPC-D-356 netlist file" ),
_( "IPC-D-356 Netlist File" ),
_( "Generate IPC-D-356 netlist file" ),
KiBitmap( netlist_xpm ) );
// Component File
......@@ -467,15 +467,9 @@ void PCB_EDIT_FRAME::ReCreateMenuBar()
wxMenu* configmenu = new wxMenu;
// Library
#if !defined( USE_FP_LIB_TABLE )
AddMenuItem( configmenu, ID_CONFIG_REQ,
_( "Li&brary" ), _( "Setting libraries, directories and others..." ),
KiBitmap( library_xpm ) );
#else
AddMenuItem( configmenu, ID_PCB_LIB_TABLE_EDIT,
_( "Li&brary Tables" ), _( "Setup footprint libraries" ),
KiBitmap( library_table_xpm ) );
#endif
// Colors and Visibility are also handled by the layers manager toolbar
AddMenuItem( configmenu, ID_MENU_PCB_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
......
......@@ -254,14 +254,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( library.size() )
{
#if defined(USE_FP_LIB_TABLE)
setLibNickName( library );
#else
wxFileName fileName( library );
setLibNickName( fileName.GetName() );
setLibPath( fileName.GetFullPath() );
#endif
updateTitle();
}
}
......@@ -364,19 +357,11 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_MODEDIT_SAVE_LIBMODULE:
#if defined(USE_FP_LIB_TABLE)
if( GetBoard()->m_Modules && getLibNickName().size() )
{
Save_Module_In_Library( getLibNickName(), GetBoard()->m_Modules, true, true );
GetScreen()->ClrModify();
}
#else
if( GetBoard()->m_Modules && getLibPath() != wxEmptyString )
{
Save_Module_In_Library( getLibPath(), GetBoard()->m_Modules, true, true );
GetScreen()->ClrModify();
}
#endif
break;
case ID_MODEDIT_INSERT_MODULE_IN_BOARD:
......@@ -507,11 +492,7 @@ void FOOTPRINT_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
Clear_Pcb( true );
SetCrossHairPosition( wxPoint( 0, 0 ) );
#if !defined( USE_FP_LIB_TABLE )
LoadModuleFromLibrary( getLibPath(), m_footprintLibTable, true );
#else
LoadModuleFromLibrary( getLibNickName(), m_footprintLibTable, true );
#endif
redraw = true;
if( GetBoard()->m_Modules )
......
......@@ -437,18 +437,8 @@ protected:
void setLibNickName( const wxString& aNickname );
#if !defined(USE_FP_LIB_TABLE)
wxString m_lib_path;
void setLibPath( const wxString& aLibPath ) { m_lib_path = aLibPath; }
/// The libPath is the full string used in the PLUGIN::Footprint*() calls.
wxString getLibPath() const { return m_lib_path; }
#else
/// The libPath is not publicly visible, grab it from the FP_LIB_TABLE if we must.
wxString getLibPath();
#endif
};
#endif // MODULE_EDITOR_FRAME_H_
......@@ -268,7 +268,6 @@ void FOOTPRINT_EDIT_FRAME::setLibNickName( const wxString& aNickname )
}
#if 1 && defined(USE_FP_LIB_TABLE)
wxString FOOTPRINT_EDIT_FRAME::getLibPath()
{
try
......@@ -284,7 +283,7 @@ wxString FOOTPRINT_EDIT_FRAME::getLibPath()
return wxEmptyString;
}
}
#endif
const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
{
......@@ -363,15 +362,9 @@ void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
case wxID_YES:
// code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions,
// at case ID_MODEDIT_SAVE_LIBMODULE
#if defined(USE_FP_LIB_TABLE)
if( GetBoard()->m_Modules && getLibNickName().size() )
{
if( Save_Module_In_Library( getLibNickName(), GetBoard()->m_Modules, true, true ) )
#else
if( GetBoard()->m_Modules && getLibPath() != wxEmptyString )
{
if( Save_Module_In_Library( getLibPath(), GetBoard()->m_Modules, true, true ) )
#endif
{
// save was correct
GetScreen()->ClrModify();
......@@ -492,11 +485,7 @@ void FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard( wxUpdateUIEvent& aEvent
void FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib( wxUpdateUIEvent& aEvent )
{
#if defined( USE_FP_LIB_TABLE )
aEvent.Enable( m_footprintLibTable && !m_footprintLibTable->IsEmpty() );
#else
aEvent.Enable( !g_LibraryNames.IsEmpty() );
#endif
}
......@@ -623,42 +612,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
{
wxString title = _( "Module Editor " );
#if !defined(USE_FP_LIB_TABLE)
wxString libPath = getLibPath();
if( !libPath )
{
L_none:
title += _( "(no active library)" );
}
else
{
// See if we can open and test write-ability of the library.
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( libPath );
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
try
{
bool writable = pi->IsFootprintLibWritable( libPath );
// no exception was thrown, this means libPath is valid, but it may be read only.
title = _( "Module Editor (active library: " ) + getLibNickName() + wxT( ")" );
if( !writable )
title += _( " [Read Only]" );
}
catch( IO_ERROR ioe )
{
// user may be bewildered as to why after selecting a library it is not showing up
// in the title, we could show an error message, but that should have been done at time
// of libary selection UI.
goto L_none;
}
}
#else
wxString nickname = getLibNickName();
if( !nickname )
......@@ -686,7 +639,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
goto L_none;
}
}
#endif
SetTitle( title );
}
......@@ -195,18 +195,10 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( PCB_BASE_FRAME* aParent,
// If a footprint was previously loaded, reload it
if( !m_libraryName.IsEmpty() && !m_footprintName.IsEmpty() )
{
#if !defined( USE_FP_LIB_TABLE )
MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension,
m_footprintName, false );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
#else
FPID id;
id.SetLibNickname( m_libraryName );
id.SetFootprintName( m_footprintName );
GetBoard()->Add( loadFootprint( id ) );
#endif
}
if( m_canvas )
......@@ -338,17 +330,10 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateLibraryList()
m_LibList->Clear();
#if !defined( USE_FP_LIB_TABLE )
for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
{
m_LibList->Append( g_LibraryNames[ii] );
}
#else
std::vector< wxString > libName = m_footprintLibTable->GetLogicalLibs();
for( unsigned ii = 0; ii < libName.size(); ii++ )
m_LibList->Append( libName[ii] );
#endif
// Search for a previous selection:
int index = m_LibList->FindString( m_libraryName );
......@@ -388,17 +373,8 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
FOOTPRINT_LIST fp_info_list;
wxArrayString libsList;
#if !defined( USE_FP_LIB_TABLE )
libsList.Add( m_libraryName );
fp_info_list.ReadFootprintFiles( libsList );
#else
fp_info_list.ReadFootprintFiles( m_footprintLibTable, &m_libraryName );
#endif
if( fp_info_list.GetErrorCount() )
{
fp_info_list.DisplayErrors( this );
......@@ -409,7 +385,7 @@ void FOOTPRINT_VIEWER_FRAME::ReCreateFootprintList()
BOOST_FOREACH( const FOOTPRINT_INFO& footprint, fp_info_list.GetList() )
{
fpList.Add( footprint.m_Module );
fpList.Add( footprint.GetFootprintName() );
}
m_FootprintList->Append( fpList );
......@@ -461,13 +437,6 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
SetCurItem( NULL );
// Delete the current footprint
GetBoard()->m_Modules.DeleteAll();
#if !defined( USE_FP_LIB_TABLE )
MODULE* footprint = GetModuleLibrary( m_libraryName + wxT( "." ) + LegacyFootprintLibPathExtension,
m_footprintName, true );
if( footprint )
GetBoard()->Add( footprint, ADD_APPEND );
#else
FPID id;
id.SetLibNickname( m_libraryName );
id.SetFootprintName( m_footprintName );
......@@ -484,7 +453,6 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
GetChars( ioe.errorText ) );
DisplayError( this, msg );
}
#endif
DisplayLibInfos();
Zoom_Automatique( false );
......@@ -555,21 +523,6 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
m_selectedFootprintName.Empty();
// Ensure we have the right library list:
#if !defined( USE_FP_LIB_TABLE )
if( g_LibraryNames.GetCount() == m_LibList->GetCount() )
{
unsigned ii;
for( ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
{
if( m_LibList->GetString( ii ) != g_LibraryNames[ii] )
break;
}
if( ii == g_LibraryNames.GetCount() )
return;
}
#else
std::vector< wxString > libNicknames = m_footprintLibTable->GetLogicalLibs();
if( libNicknames.size() == m_LibList->GetCount() )
......@@ -585,7 +538,6 @@ void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
if( ii == libNicknames.size() )
return;
}
#endif
// If we are here, the library list has changed, rebuild it
ReCreateLibraryList();
......
......@@ -161,164 +161,8 @@ MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName()
}
#if !defined( USE_FP_LIB_TABLE )
void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
throw( IO_ERROR, PARSE_ERROR )
{
wxString msg;
FPID lastFPID;
std::vector< FPID > nofoundFootprints; // A list of footprints used in netlist
// but not found in any library
// to avoid a full search in all libs
// each time a non existent footprint is needed
COMPONENT* component;
MODULE* module = 0;
MODULE* fpOnBoard;
if( aNetlist.IsEmpty() )
return;
aNetlist.SortByFPID();
wxString libPath;
wxFileName fn;
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
{
component = aNetlist.GetComponent( ii );
if( component->GetFPID().empty() )
{
if( aReporter )
{
msg.Printf( _( "No footprint defined for component '%s'.\n" ),
GetChars( component->GetReference() ) );
aReporter->Report( msg );
}
continue;
}
// Check if component footprint is already on BOARD and only load the footprint from
// the library if it's needed.
if( aNetlist.IsFindByTimeStamp() )
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true );
else
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() );
bool footprintMisMatch = fpOnBoard &&
fpOnBoard->GetFPID() != component->GetFPID();
if( footprintMisMatch && !aNetlist.GetReplaceFootprints() )
{
if( aReporter )
{
msg.Printf( _( "* Warning: component '%s' has footprint '%s' and should be '%s'\n" ),
GetChars( component->GetReference() ),
fpOnBoard->GetFPID().Format().c_str(),
component->GetFPID().GetFootprintName().c_str() );
aReporter->Report( msg );
}
continue;
}
if( !aNetlist.GetReplaceFootprints() )
footprintMisMatch = false;
bool loadFootprint = (fpOnBoard == NULL) || footprintMisMatch;
if( loadFootprint && (component->GetFPID() != lastFPID) )
{
module = NULL;
// Speed up the search: a search for a non existent footprint
// is hightly costly in time becuse the full set of libs is read.
// So it should be made only once.
// Therefore search in not found list first:
bool alreadySearched = false;
for( unsigned ii = 0; ii < nofoundFootprints.size(); ii++ )
{
if( component->GetFPID() == nofoundFootprints[ii] )
{
alreadySearched = true;
break;
}
}
if( alreadySearched )
continue;
for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
{
fn = wxFileName( wxEmptyString, g_LibraryNames[ii],
LegacyFootprintLibPathExtension );
libPath = wxGetApp().FindLibraryPath( fn );
if( !libPath )
{
if( aReporter )
{
msg.Printf( _( "*** Warning: Cannot find footprint library file \"%s\" "
"in any of the standard KiCad library search paths. ***\n" ),
GetChars( fn.GetFullPath() ) );
aReporter->Report( msg );
}
continue;
}
module = pi->FootprintLoad( libPath,
FROM_UTF8( component->GetFPID().GetFootprintName().c_str() ) );
if( module )
{
lastFPID = component->GetFPID();
break;
}
}
if( module == NULL && !alreadySearched )
{
if( aReporter )
{
msg.Printf( _( "*** Warning: component '%s' footprint '%s' was not found in "
"any libraries. ***\n" ),
GetChars( component->GetReference() ),
component->GetFPID().GetFootprintName().c_str() );
aReporter->Report( msg );
}
nofoundFootprints.push_back( component->GetFPID() );
continue;
}
}
else
{
// Footprint already loaded from a library, duplicate it (faster)
if( module == NULL )
continue; // Module does not exist in any library.
module = new MODULE( *module );
}
if( loadFootprint && module != NULL )
component->SetModule( module );
}
}
#else
#define ALLOW_PARTIAL_FPID 1
void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
throw( IO_ERROR, PARSE_ERROR )
{
......@@ -444,4 +288,3 @@ void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
}
}
#endif
......@@ -315,10 +315,8 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
m_microWaveToolBar = NULL;
m_useCmpFileForFpNames = true;
#if defined( USE_FP_LIB_TABLE )
m_footprintLibTable = NULL;
m_globalFootprintTable = NULL;
#endif
#ifdef KICAD_SCRIPTING_WXPYTHON
m_pythonPanel = NULL;
......@@ -471,7 +469,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
m_auimgr.Update();
#if defined( USE_FP_LIB_TABLE )
if( m_globalFootprintTable == NULL )
{
try
......@@ -499,7 +496,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title,
DisplayError( this, msg );
}
}
#endif
setupTools();
}
......@@ -515,10 +511,8 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
delete m_drc;
#if defined( USE_FP_LIB_TABLE )
delete m_footprintLibTable;
delete m_globalFootprintTable;
#endif
}
......
......@@ -213,10 +213,8 @@ bool EDA_APP::OnInit()
* display the real hotkeys in menus or tool tips */
ReadHotkeyConfig( wxT( "PcbFrame" ), g_Board_Editor_Hokeys_Descr );
#if defined( USE_FP_LIB_TABLE )
// Set any environment variables before loading FP_LIB_TABLE
SetFootprintLibTablePath();
#endif
frame = new PCB_EDIT_FRAME( NULL, wxT( "Pcbnew" ), wxPoint( 0, 0 ), wxSize( 600, 400 ) );
......
......@@ -256,7 +256,6 @@ bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
// 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 )
FP_LIB_TABLE::SetProjectPathEnvVariable( fn );
delete m_footprintLibTable;
......@@ -284,7 +283,6 @@ bool PCB_EDIT_FRAME::LoadProjectSettings( const wxString& aProjectFileName )
if( viewFrame )
viewFrame->SetFootprintLibTable( m_footprintLibTable );
#endif
// Load the page layout decr file, from the filename stored in
// BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
......
......@@ -397,11 +397,7 @@ bool DIALOG_EXCHANGE_MODULE::Change_1_Module( MODULE* aModule,
wxString moduleName = FROM_UTF8( aNewFootprintFPID.GetFootprintName().c_str() );
wxString libName = FROM_UTF8( aNewFootprintFPID.GetLibNickname().c_str() );
#if !defined( USE_FP_LIB_TABLE )
newModule = m_parent->GetModuleLibrary( libName, moduleName, aShowError );
#else
newModule = m_parent->LoadFootprint( aNewFootprintFPID );
#endif
if( newModule == NULL ) // New module not found, redraw the old one.
{
......
......@@ -30,7 +30,6 @@ WORKING_TREES=~/kicad_sources
# CMake Options
OPTS="$OPTS -DCMAKE_BUILD_TYPE=Release"
OPTS="$OPTS -DUSE_FP_LIB_TABLE=ON"
OPTS="$OPTS -DBUILD_GITHUB_PLUGIN=ON"
# Python scripting, uncomment to enable
......
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