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

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

parent b85a7133
Loading
Loading
Loading
Loading
+0 −2
Original line number Original line Diff line number Diff line
@@ -47,8 +47,6 @@ option( KICAD_SCRIPTING_WXPYTHON
# python binary file should be is exec path.
# 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 )
option( BUILD_GITHUB_PLUGIN "Build the GITHUB_PLUGIN for pcbnew." OFF )




+0 −3
Original line number Original line Diff line number Diff line
@@ -58,9 +58,6 @@
/// The legacy file format revision of the *.brd file created by this build
/// The legacy file format revision of the *.brd file created by this build
#define LEGACY_BOARD_FILE_VERSION 2
#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.
/// The install prefix defined in CMAKE_INSTALL_PREFIX.
#define DEFAULT_INSTALL_PATH               "@CMAKE_INSTALL_PREFIX"
#define DEFAULT_INSTALL_PATH               "@CMAKE_INSTALL_PREFIX"


+1 −6
Original line number Original line Diff line number Diff line
@@ -566,12 +566,7 @@ void EDA_BASE_FRAME::CopyVersionInfoToClipboard( wxCommandEvent& event )
    tmp << wxT( "OFF\n" );
    tmp << wxT( "OFF\n" );
#endif
#endif


    tmp << wxT( "         USE_FP_LIB_TABLE=" );
    tmp << wxT( "         USE_FP_LIB_TABLE=HARD_CODED_ON\n" );
#ifdef USE_FP_LIB_TABLE
    tmp << wxT( "ON\n" );
#else
    tmp << wxT( "OFF\n" );
#endif


    tmp << wxT( "         BUILD_GITHUB_PLUGIN=" );
    tmp << wxT( "         BUILD_GITHUB_PLUGIN=" );
#ifdef BUILD_GITHUB_PLUGIN
#ifdef BUILD_GITHUB_PLUGIN
+17 −142
Original line number Original line Diff line number Diff line
@@ -30,7 +30,6 @@


#define USE_WORKER_THREADS      1       // 1:yes, 0:no. use worker thread to load libraries
#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
 * Functions to read footprint libraries and fill m_footprints by available footprints names
 * and their documentation (comments and keywords)
 * and their documentation (comments and keywords)
@@ -46,10 +45,7 @@
#include <fp_lib_table.h>
#include <fp_lib_table.h>
#include <fpid.h>
#include <fpid.h>
#include <class_module.h>
#include <class_module.h>

#if defined(USE_FP_LIB_TABLE)
#include <boost/thread.hpp>
#include <boost/thread.hpp>
#endif




/*
/*
@@ -97,94 +93,22 @@ static wxString ToHTMLFragment( const IO_ERROR* aDerivative )
*/
*/




#if !defined( USE_FP_LIB_TABLE )
void FOOTPRINT_INFO::load()

bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintLibNames )
{
    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 ) );
    FP_LIB_TABLE*   fptable = m_owner->GetTable();


        // Parse Libraries Listed
    wxASSERT( fptable );
        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() )
    std::auto_ptr<MODULE> m( fptable->FootprintLoad( m_nickname, m_fpname ) );
            {
                filename = wxGetApp().FindLibraryPath( filename.GetFullName() );


                if( !filename.FileExists() )
    m_pad_count = m->GetPadCount( MODULE::DO_NOT_INCLUDE_NPTH );
                {
    m_keywords  = m->GetKeywords();
                    filename = wxFileName( wxEmptyString, aFootprintLibNames[ii],
    m_doc       = m->GetDescription();
                                           LegacyFootprintLibPathExtension );


                    filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
    // tell ensure_loaded() I'm loaded.
                }
    m_loaded = true;
}
}


            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();

                    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();

                    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;
}

#else       // yes USE_FP_LIB_TABLE, by all means:


#define JOBZ                6       // no. libraries per worker thread.  It takes about
#define JOBZ                6       // no. libraries per worker thread.  It takes about
                                    // a second to load a GITHUB library, so assigning
                                    // 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 )
            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( this, nickname, fpnames[ni] );

                FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO();


                fpinfo->SetNickname( nickname );
                addItem( fpinfo );

                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();

                AddItem( fpinfo );
            }
            }
        }
        }
        catch( const PARSE_ERROR& pe )
        catch( const PARSE_ERROR& pe )
@@ -346,27 +261,12 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* a


    return retv;
    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 )
    BOOST_FOREACH( FOOTPRINT_INFO& fp, m_list )

    // 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 )
    {
    {
#if defined( USE_FP_LIB_TABLE )
        FPID fpid;
        FPID fpid;


        wxCHECK_MSG( fpid.Parse( aFootprintName ) < 0, NULL,
        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 libNickname   = FROM_UTF8( fpid.GetLibNickname().c_str() );
        wxString footprintName = FROM_UTF8( fpid.GetFootprintName().c_str() );
        wxString footprintName = FROM_UTF8( fpid.GetFootprintName().c_str() );


        if( libNickname == footprint.m_nickname && footprintName == footprint.m_Module )
        if( libNickname == fp.GetNickname() && footprintName == fp.GetFootprintName() )
            return &footprint;
            return &fp;
#else
        if( aFootprintName.CmpNoCase( footprint.m_Module ) == 0 )
            return &footprint;
#endif
    }
    }

    return NULL;
    return NULL;
}
}




bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
bool FOOTPRINT_INFO::InLibrary( const wxString& aLibrary ) const
{
{
#if defined( USE_FP_LIB_TABLE )
    return aLibrary == m_nickname;
    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
}
}




+1 −1
Original line number Original line Diff line number Diff line
@@ -185,7 +185,7 @@ void CVPCB_MAINFRAME::AssocieModule( wxCommandEvent& event )


                for( size_t jj = 0; jj < filtercount && !found; jj++ )
                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
            else
Loading