2013-05-06 17:57:18 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Jean-Pierre Charras, <jp.charras@wanadoo.fr>
|
|
|
|
* Copyright (C) 1992-2011 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
|
|
|
|
*/
|
|
|
|
|
2011-02-05 18:00:05 +00:00
|
|
|
/**
|
2011-02-22 20:59:16 +00:00
|
|
|
* @file footprint_info.cpp
|
2011-02-05 18:00:05 +00:00
|
|
|
*/
|
2009-11-05 19:26:52 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-22 17:59:46 +00:00
|
|
|
* Functions to read footprint libraries and fill m_footprints by available footprints names
|
2009-11-23 21:03:26 +00:00
|
|
|
* and their documentation (comments and keywords)
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <appl_wxstruct.h>
|
2013-05-10 01:51:55 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <footprint_info.h>
|
2012-04-16 03:18:41 +00:00
|
|
|
#include <io_mgr.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_module.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-02-22 17:59:46 +00:00
|
|
|
// Clear data before reading files
|
|
|
|
m_filesNotFound.Empty();
|
|
|
|
m_filesInvalid.Empty();
|
|
|
|
m_List.clear();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
// try
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2012-04-17 06:13:22 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
// Parse Libraries Listed
|
|
|
|
for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2013-05-10 01:51:55 +00:00
|
|
|
// Footprint library file names can be fully qualified or file name only.
|
2013-05-08 20:47:23 +00:00
|
|
|
wxFileName filename = aFootprintsLibNames[ii];
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-05-10 01:51:55 +00:00
|
|
|
if( !filename.FileExists() )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
2013-05-10 01:51:55 +00:00
|
|
|
filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
|
|
|
|
|
|
|
|
if( !filename.FileExists() )
|
|
|
|
{
|
|
|
|
filename = wxFileName( wxEmptyString, aFootprintsLibNames[ii],
|
|
|
|
LegacyFootprintLibPathExtension );
|
|
|
|
|
|
|
|
filename = wxGetApp().FindLibraryPath( filename.GetFullName() );
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
}
|
2012-04-17 06:13:22 +00:00
|
|
|
|
2013-05-10 19:22:29 +00:00
|
|
|
wxLogDebug( wxT( "Path <%s> -> <%s>." ), GetChars( aFootprintsLibNames[ii] ),
|
|
|
|
GetChars( filename.GetFullPath() ) );
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !filename.FileExists() )
|
2012-04-16 03:18:41 +00:00
|
|
|
{
|
2013-05-06 17:57:18 +00:00
|
|
|
m_filesNotFound << filename.GetFullName() << wxT( "\n" );
|
2012-04-17 06:13:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxArrayString fpnames = pi->FootprintEnumerate( filename.GetFullPath() );
|
2012-04-17 06:13:22 +00:00
|
|
|
|
|
|
|
for( unsigned i=0; i<fpnames.GetCount(); ++i )
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
std::auto_ptr<MODULE> m( pi->FootprintLoad( filename.GetFullPath(),
|
|
|
|
fpnames[i] ) );
|
2011-02-05 16:15:48 +00:00
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
// we're loading what we enumerated, all must be there.
|
|
|
|
wxASSERT( m.get() );
|
2011-02-05 16:15:48 +00:00
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
fpinfo->SetLibraryName( filename.GetName() );
|
|
|
|
fpinfo->SetLibraryPath( filename.GetFullPath() );
|
2012-04-17 06:13:22 +00:00
|
|
|
fpinfo->m_Module = fpnames[i];
|
|
|
|
fpinfo->m_padCount = m->GetPadCount();
|
|
|
|
fpinfo->m_KeyWord = m->GetKeywords();
|
|
|
|
fpinfo->m_Doc = m->GetDescription();
|
|
|
|
|
|
|
|
AddItem( fpinfo );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
m_filesInvalid << ioe.errorText << wxT( "\n" );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2011-02-05 16:15:48 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
/* caller should catch this, UI seems not wanted here.
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( NULL, ioe.errorText );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2011-02-22 17:59:46 +00:00
|
|
|
m_List.sort();
|
2009-07-05 16:59:12 +00:00
|
|
|
|
2009-10-05 04:22:27 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|