Commit 9fe5ce67 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

Modular-Kicad milestone B), minor portion:

*)  Implement a framework for "Data Load On Demand".

*)  Implement FP_LIB_TABLE* PROJECT::PcbFootprintLibs(), which is the first
    prototype.

This allows the project specific footprint tables to be part of the Module Editor
when invoked from Eeschema.
parent dc745aa6
Loading
Loading
Loading
Loading
+14 −1
Original line number Original line Diff line number Diff line
@@ -137,6 +137,12 @@ FP_LIB_TABLE::FP_LIB_TABLE( FP_LIB_TABLE* aFallBackTable ) :
}
}




FP_LIB_TABLE::~FP_LIB_TABLE()
{
    // *fallBack is not owned here.
}


wxArrayString FP_LIB_TABLE::FootprintEnumerate( const wxString& aNickname )
wxArrayString FP_LIB_TABLE::FootprintEnumerate( const wxString& aNickname )
{
{
    const ROW* row = FindRow( aNickname );
    const ROW* row = FindRow( aNickname );
@@ -514,9 +520,16 @@ std::vector<wxString> FP_LIB_TABLE::GetLogicalLibs()


    } while( ( cur = cur->fallBack ) != 0 );
    } while( ( cur = cur->fallBack ) != 0 );


    ret.reserve( unique.size() );

    // DBG(printf( "%s: count:%zd\n", __func__, unique.size() );)

    // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
    // return a sorted, unique set of nicknames in a std::vector<wxString> to caller
    for( std::set<wxString>::const_iterator it = unique.begin();  it!=unique.end();  ++it )
    for( std::set<wxString>::const_iterator it = unique.begin();  it!=unique.end();  ++it )
    {
        //DBG(printf( " %s\n", TO_UTF8( *it ) );)
        ret.push_back( *it );
        ret.push_back( *it );
    }


    return ret;
    return ret;
}
}
@@ -738,7 +751,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
void FP_LIB_TABLE::Load( const wxString& aFileName )
void FP_LIB_TABLE::Load( const wxString& aFileName )
    throw( IO_ERROR )
    throw( IO_ERROR )
{
{
    // Empty footprint library tables are valid.
    // It's OK if footprint library tables are missing.
    if( wxFileName::IsFileReadable( aFileName ) )
    if( wxFileName::IsFileReadable( aFileName ) )
    {
    {
        FILE_LINE_READER    reader( aFileName );
        FILE_LINE_READER    reader( aFileName );
+27 −12
Original line number Original line Diff line number Diff line
@@ -42,15 +42,22 @@ PROJECT::PROJECT()
    memset( m_elems, 0, sizeof(m_elems) );
    memset( m_elems, 0, sizeof(m_elems) );
}
}


PROJECT::~PROJECT()

void PROJECT::ElemsClear()
{
{
#if 1
    // careful here, this should work, but the virtual destructor may not
    // careful here, this may work, but the virtual destructor may not
    // be in the same link image as PROJECT.
    // be in the same link image as PROJECT.

    for( unsigned i = 0;  i<DIM(m_elems);  ++i )
    for( unsigned i = 0;  i<DIM(m_elems);  ++i )
    {
        delete m_elems[i];
        delete m_elems[i];
#endif
        m_elems[i] = NULL;
    }
}


PROJECT::~PROJECT()
{
    ElemsClear();
}
}




@@ -145,21 +152,29 @@ RETAINED_PATH& PROJECT::RPath( RETPATH_T aIndex )
}
}




PROJECT::_ELEM* PROJECT::Elem( ELEM_T aIndex, _ELEM* aElem )
PROJECT::_ELEM* PROJECT::GetElem( ELEM_T aIndex )
{
{
    unsigned ndx = unsigned( aIndex );
    // This is virtual, so implement it out of line


    if( ndx < DIM( m_elems ) )
    if( unsigned( aIndex ) < DIM( m_elems ) )
    {
    {
        if( aElem )
        return m_elems[aIndex];
            m_elems[ndx] = aElem;

        return m_elems[ndx];
    }
    }
    return NULL;
    return NULL;
}
}




void PROJECT::SetElem( ELEM_T aIndex, _ELEM* aElem )
{
    // This is virtual, so implement it out of line

    if( unsigned( aIndex ) < DIM( m_elems ) )
    {
        m_elems[aIndex] = aElem;
    }
}


// non-member so it can be moved easily, and kept REALLY private.
// non-member so it can be moved easily, and kept REALLY private.
// Do NOT Clear() in here.
// Do NOT Clear() in here.
static void add_search_paths( SEARCH_STACK* aDst, wxConfigBase* aCfg, int aIndex )
static void add_search_paths( SEARCH_STACK* aDst, wxConfigBase* aCfg, int aIndex )
+2 −17
Original line number Original line Diff line number Diff line
@@ -81,23 +81,8 @@ void CVPCB_MAINFRAME::LoadProjectFile( const wxString& aFileName )
    if( m_NetlistFileExtension.IsEmpty() )
    if( m_NetlistFileExtension.IsEmpty() )
        m_NetlistFileExtension = wxT( "net" );
        m_NetlistFileExtension = wxT( "net" );


    // empty the table, Load() it again below.
    // Force it to be loaded on demand.
    FootprintLibs()->Clear();
    prj.ElemClear( PROJECT::ELEM_FPTBL );

    /* this is done by ConfigLoad(), and that sets the env var too.
    prj.SetProjectFullName( fn.GetFullPath() );
    */

    wxString projectFpLibTableFileName = prj.FootprintLibTblName();

    try
    {
        FootprintLibs()->Load( projectFpLibTableFileName );
    }
    catch( const IO_ERROR& ioe )
    {
        DisplayError( this, ioe.errorText );
    }
}
}




+2 −1
Original line number Original line Diff line number Diff line
@@ -488,7 +488,8 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
        wxLogDebug( wxT( "Load footprint <%s> from library <%s>." ),
        wxLogDebug( wxT( "Load footprint <%s> from library <%s>." ),
                    fpname.c_str(), nickname.c_str()  );
                    fpname.c_str(), nickname.c_str()  );


        footprint = FootprintLibs()->FootprintLoad( FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) );
        footprint = Prj().PcbFootprintLibs()->FootprintLoad(
                FROM_UTF8( nickname.c_str() ), FROM_UTF8( fpname.c_str() ) );
    }
    }
    catch( const IO_ERROR& ioe )
    catch( const IO_ERROR& ioe )
    {
    {
+1 −1
Original line number Original line Diff line number Diff line
@@ -128,7 +128,7 @@ void LIBRARY_LISTBOX::SetLibraryList( const wxArrayString& aList )
    {
    {
        RefreshItems( 0L, m_libraryList.Count()-1 );
        RefreshItems( 0L, m_libraryList.Count()-1 );


#if defined (__WXGTK__ ) // && wxMINOR_VERSION == 8
#if defined (__WXGTK__ ) && wxMINOR_VERSION == 8
        // @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
        // @bug On GTK and wxWidgets 2.8.x, this will assert in debug builds because the
        //      column parameter is -1.  This was the only way to prevent GTK3 from
        //      column parameter is -1.  This was the only way to prevent GTK3 from
        //      ellipsizing long strings down to a few characters.  It still doesn't set
        //      ellipsizing long strings down to a few characters.  It still doesn't set
Loading