Commit cf86e18f authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Footprint library table work, minor fixes, and code cleaning.

* Fix a bug when full file name and path are passed to FOOTPRINT_INFO::
  ReadFootprintFiles() which I created in bug fix lp:593989.
* Fix a wxString debug assertion in EDA_APP::InitEDA_Appl() when the KICAD
  environment variable is defined as an empty string.
* Add error dialog when libraries cannot be found in system search path
  when loading footprint using the select footprint dialog.
* Add footprint library name column to the EDA_LIST_DIALOG when selecting
  footprints from the list.
* Allow reading all columns from the selected row in EDA_LIST_DIALOG.
* Remove redundant sort from EDA_LIST_DIALOG constructor
* Add library name member variable and accessors to FOOTPRINT_INFO.
* Make headers translatable for Eeschema select component from list dialog.
* Add some helper methods to FPID for identifying the FPID type and validity.
* Remove a bunch of trailing whitespace and add missing license comments.
parent 2e6969fe
Loading
Loading
Loading
Loading
+68 −23
Original line number Diff line number Diff line
/*
 * 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-2013 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 displlst.cpp
 */
@@ -25,23 +49,22 @@ EDA_LIST_DIALOG::EDA_LIST_DIALOG( EDA_DRAW_FRAME* aParent, const wxString& aTitl
        column.SetId( i );
        column.SetText( aItemHeaders.Item( i ) );
        column.SetWidth( 300 / aItemHeaders.Count() );
        EDA_LIST_DIALOG_BASE::m_listBox->InsertColumn( i, column );
        m_listBox->InsertColumn( i, column );
    }

    InsertItems( aItemList, 0 );

    if( m_sortList )
        sortList();

    if( !aRefText.IsEmpty() )    // try to select the item matching aRefText
    {
        for( unsigned ii = 0; ii < aItemList.size(); ii++ )
        {
            if( aItemList[ii][0] == aRefText )
            {
                m_listBox->SetItemState( ii, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
                break;
            }
        }
    }

    if( m_callBackFct == NULL )
    {
@@ -85,12 +108,25 @@ void EDA_LIST_DIALOG::textChangeInFilterBox( wxCommandEvent& event )
        sortList();
}

wxString EDA_LIST_DIALOG::GetTextSelection()

wxString EDA_LIST_DIALOG::GetTextSelection( int aColumn )
{
    wxCHECK_MSG( aColumn < m_listBox->GetColumnCount(), wxEmptyString,
                 wxT( "Invalid list control column." ) );

    wxListItem info;
    wxString   text;
    long       item = -1;
    item = m_listBox->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
    wxString text = m_listBox->GetItemText( item );
    return text;

    info.m_mask = wxLIST_MASK_TEXT;
    info.m_itemId = item;
    info.m_col = aColumn;

    if( !m_listBox->GetItem( info ) )
        return wxEmptyString;

    return info.m_text;
}


@@ -107,18 +143,26 @@ void EDA_LIST_DIALOG::Append( const wxArrayString& itemList )
    }
}

void EDA_LIST_DIALOG::InsertItems( const std::vector<wxArrayString>& itemList,
                                   int position )

void EDA_LIST_DIALOG::InsertItems( const std::vector< wxArrayString >& itemList, int position )
{
    for( unsigned i = 0; i < itemList.size(); i++ )
    for( unsigned row = 0; row < itemList.size(); row++ )
    {
        long itemIndex = m_listBox->InsertItem( position+i, itemList[i].Item( 0 ) );
        m_listBox->SetItemData( itemIndex, (long) &( itemList[i].Item( 0 ) ) );
        wxASSERT( (int) itemList[row].GetCount() == m_listBox->GetColumnCount() );

        // Adding the next columns content
        for( unsigned j = 1; j < itemList[i].GetCount(); j++ )
        for( unsigned col = 0; col < itemList[row].GetCount(); col++ )
        {
            long itemIndex;

            if( col == 0 )
            {
                itemIndex = m_listBox->InsertItem( row+position, itemList[row].Item( col ) );
                m_listBox->SetItemData( itemIndex, (long) &itemList[row].Item( col ) );
            }
            else
            {
            m_listBox->SetItem( itemIndex, j, itemList[i].Item( j ) );
                m_listBox->SetItem( itemIndex, col, itemList[row].Item( col ) );
            }
        }
    }

@@ -174,6 +218,7 @@ static int wxCALLBACK MyCompareFunction( long aItem1, long aItem2, long aSortDat
    return StrNumCmp( *component1Name, *component2Name, INT_MAX, true );
}


void EDA_LIST_DIALOG::sortList()
{
    m_listBox->SortItems( MyCompareFunction, 0 );
+1 −1
Original line number Diff line number Diff line
@@ -326,7 +326,7 @@ void EDA_APP::InitEDA_Appl( const wxString& aName, EDA_APP_T aId )
    {
        m_KicadEnv.Replace( WIN_STRING_DIR_SEP, UNIX_STRING_DIR_SEP );

        if( m_KicadEnv.Last() != '/' )
        if( !m_KicadEnv.IsEmpty() && m_KicadEnv.Last() != '/' )
            m_KicadEnv += UNIX_STRING_DIR_SEP;
    }

+15 −22
Original line number Diff line number Diff line
@@ -48,20 +48,6 @@
#include <wildcards_and_files_ext.h>


/* Read the list of libraries (*.mod files)
 * for each module are stored
 *      the module name
 *      documentation string
 *      associated keywords
 *      lib name
 * Module description format:
 *   $MODULE c64acmd                    First line of module description
 *   Li c64acmd DIN connector           Library reference
 *   Cd Europe 96 AC male vertical      documentation string
 *   Kw PAD_CONN DIN                    associated keywords
 *   ...... other data (pads, outlines ..)
 *   $Endmodule
 */
bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
{
    // Clear data before reading files
@@ -76,12 +62,17 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
        // Parse Libraries Listed
        for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ )
        {
            wxFileName filename( wxEmptyString, aFootprintsLibNames[ii],
                                 LegacyFootprintLibPathExtension );
            // File names can be fully qualified or file name only.
            wxFileName filename = aFootprintsLibNames[ii];

            wxString libPath = wxGetApp().FindLibraryPath( filename );
            if( !filename.IsAbsolute() )
            {
                filename = wxFileName( wxEmptyString, aFootprintsLibNames[ii],
                                       LegacyFootprintLibPathExtension );
                filename = wxGetApp().FindLibraryPath( filename );
            }

            if( !libPath )
            if( !filename.FileExists() )
            {
                m_filesNotFound << filename.GetFullName() << wxT( "\n" );
                continue;
@@ -89,19 +80,21 @@ bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )

            try
            {
                wxArrayString fpnames = pi->FootprintEnumerate( libPath );
                wxArrayString fpnames = pi->FootprintEnumerate( filename.GetFullPath() );

                for( unsigned i=0; i<fpnames.GetCount();  ++i )
                {
                    std::auto_ptr<MODULE> m( pi->FootprintLoad( libPath, fpnames[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->SetLibraryName( filename.GetName() );
                    fpinfo->SetLibraryPath( filename.GetFullPath() );
                    fpinfo->m_Module   = fpnames[i];
                    fpinfo->m_LibName  = libPath;
                    fpinfo->m_padCount = m->GetPadCount();
                    fpinfo->m_KeyWord  = m->GetKeywords();
                    fpinfo->m_Doc      = m->GetDescription();
+2 −1
Original line number Diff line number Diff line
@@ -533,9 +533,10 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()

        const wxChar *libname;
        if( module_info )
            libname = GetChars( module_info->m_LibName );
            libname = GetChars( module_info->GetLibraryPath() );
        else
            libname = GetChars( wxT( "???" ) );

        msg.Printf( _( "Lib: %s" ), libname );

        SetStatusText( msg, 0 );
+32 −6
Original line number Diff line number Diff line
/*
 * 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-2013 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 database.cpp
 */
@@ -16,6 +40,7 @@

extern void DisplayCmpDocAndKeywords( wxString& Name );


// Used in DataBaseGetName: this is a callback function for EDA_LIST_DIALOG
// to display keywords and description of a component
void DisplayCmpDocAndKeywords( wxString& Name )
@@ -31,6 +56,7 @@ void DisplayCmpDocAndKeywords( wxString& Name )
    Name += wxT( "\nKey Words: " ) + CmpEntry->GetKeyWords();
}


/*
 * Displays a list of filtered components found in libraries for selection,
 * Keys is a list of keywords to filter components which do not match these keywords
@@ -88,8 +114,8 @@ wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufNa
    }

    wxArrayString headers;
    headers.Add( wxT("Component") );
    headers.Add( wxT("Library") );
    headers.Add( _( "Component" ) );
    headers.Add( _( "Library" ) );

    // Show candidate list:
    wxString cmpname;
Loading