kicad-source/common/footprint_info.cpp

131 lines
4.0 KiB
C++
Raw Normal View History

/*
* 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
*/
/**
* @file footprint_info.cpp
*/
/*
* Functions to read footprint libraries and fill m_footprints by available footprints names
* and their documentation (comments and keywords)
*/
#include <fctsys.h>
#include <wxstruct.h>
#include <common.h>
#include <kicad_string.h>
#include <macros.h>
#include <appl_wxstruct.h>
#include <pcbcommon.h>
#include <pcbstruct.h>
#include <footprint_info.h>
2012-04-15 22:18:41 -05:00
#include <io_mgr.h>
#include <class_pad.h>
#include <class_module.h>
#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
*/
2012-04-15 22:18:41 -05:00
bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString& aFootprintsLibNames )
{
// Clear data before reading files
m_filesNotFound.Empty();
m_filesInvalid.Empty();
m_List.clear();
2012-04-17 01:13:22 -05:00
// try
{
2012-04-17 01:13:22 -05:00
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
2012-04-17 01:13:22 -05:00
// Parse Libraries Listed
for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ )
{
wxFileName filename( wxEmptyString, aFootprintsLibNames[ii],
LegacyFootprintLibPathExtension );
2012-04-17 01:13:22 -05:00
wxString libPath = wxGetApp().FindLibraryPath( filename );
if( !libPath )
2012-04-15 22:18:41 -05:00
{
m_filesNotFound << filename.GetFullName() << wxT( "\n" );
2012-04-17 01:13:22 -05:00
continue;
}
try
{
wxArrayString fpnames = pi->FootprintEnumerate( libPath );
for( unsigned i=0; i<fpnames.GetCount(); ++i )
{
std::auto_ptr<MODULE> m( pi->FootprintLoad( libPath, fpnames[i] ) );
2012-04-17 01:13:22 -05:00
// we're loading what we enumerated, all must be there.
wxASSERT( m.get() );
2012-04-17 01:13:22 -05:00
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO();
2012-04-17 01:13:22 -05:00
fpinfo->m_Module = fpnames[i];
fpinfo->m_LibName = libPath;
fpinfo->m_padCount = m->GetPadCount();
fpinfo->m_KeyWord = m->GetKeywords();
fpinfo->m_Doc = m->GetDescription();
AddItem( fpinfo );
}
}
catch( IO_ERROR ioe )
{
m_filesInvalid << ioe.errorText << wxT("\n");
}
}
}
2012-04-17 01:13:22 -05:00
/* caller should catch this, UI seems not wanted here.
catch( IO_ERROR ioe )
{
DisplayError( NULL, ioe.errorText );
return false;
}
*/
m_List.sort();
2009-07-05 16:59:12 +00:00
return true;
}