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
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "kicad_string.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "appl_wxstruct.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
#include "pcbcommon.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "pcbstruct.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2011-02-21 18:27:47 +00:00
|
|
|
#include "footprint_info.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_pad.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
|
2011-02-22 17:59:46 +00:00
|
|
|
/* Read the list of libraries (*.mod files)
|
2011-02-05 16:15:48 +00:00
|
|
|
* for each module are stored
|
|
|
|
* the module name
|
|
|
|
* documentation string
|
|
|
|
* associated keywords
|
2011-02-22 17:59:46 +00:00
|
|
|
* lib name
|
2009-11-05 19:26:52 +00:00
|
|
|
* Module description format:
|
2011-02-05 16:15:48 +00:00
|
|
|
* $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 ..)
|
2009-11-05 19:26:52 +00:00
|
|
|
* $Endmodule
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2011-02-22 17:59:46 +00:00
|
|
|
bool FOOTPRINT_LIST::ReadFootprintFiles( wxArrayString & aFootprintsLibNames )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-05 19:26:52 +00:00
|
|
|
FILE* file;
|
2009-10-05 04:22:27 +00:00
|
|
|
wxFileName filename;
|
2011-02-05 16:15:48 +00:00
|
|
|
wxString libname;
|
2009-10-05 04:22:27 +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
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
/* Parse Libraries Listed */
|
2011-02-22 17:59:46 +00:00
|
|
|
for( unsigned ii = 0; ii < aFootprintsLibNames.GetCount(); ii++ )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-22 17:59:46 +00:00
|
|
|
filename = aFootprintsLibNames[ii];
|
2009-07-05 16:59:12 +00:00
|
|
|
filename.SetExt( ModuleFileExtension );
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
libname = wxGetApp().FindLibraryPath( filename );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
if( libname.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-02-22 17:59:46 +00:00
|
|
|
m_filesNotFound << filename.GetFullName() << wxT("\n");
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
/* Open library file */
|
2011-02-05 16:15:48 +00:00
|
|
|
file = wxFopen( libname, wxT( "rt" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( file == NULL )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-22 17:59:46 +00:00
|
|
|
m_filesInvalid << libname << _(" (file cannot be opened)") << wxT("\n");
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-06 19:19:03 +00:00
|
|
|
FILE_LINE_READER fileReader( file, libname );
|
|
|
|
FILTER_READER reader( fileReader );
|
2011-02-05 16:15:48 +00:00
|
|
|
|
|
|
|
/* Read header. */
|
|
|
|
reader.ReadLine();
|
2011-02-06 19:19:03 +00:00
|
|
|
char * line = reader.Line();
|
|
|
|
StrPurge( line );
|
2011-02-05 16:15:48 +00:00
|
|
|
|
2011-09-24 18:33:28 +00:00
|
|
|
if( strnicmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) != 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-05 16:15:48 +00:00
|
|
|
wxString msg;
|
2011-09-30 18:15:37 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid KiCad PCB footprint library." ),
|
2011-02-05 16:15:48 +00:00
|
|
|
GetChars( libname ) );
|
2011-02-22 17:59:46 +00:00
|
|
|
m_filesInvalid << msg << wxT("\n");
|
2009-02-04 15:25:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
// Read library
|
|
|
|
bool end = false;
|
|
|
|
while( !end && reader.ReadLine() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-06 19:19:03 +00:00
|
|
|
line = reader.Line();
|
|
|
|
StrPurge( line );
|
|
|
|
if( strnicmp( line, "$EndLIBRARY", 11 ) == 0 )
|
2011-02-05 16:15:48 +00:00
|
|
|
{
|
|
|
|
end = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-02-06 19:19:03 +00:00
|
|
|
if( strnicmp( line, "$MODULE", 7 ) == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-05 16:15:48 +00:00
|
|
|
|
2011-02-06 19:19:03 +00:00
|
|
|
line += 7;
|
2011-02-21 18:27:47 +00:00
|
|
|
FOOTPRINT_INFO* ItemLib = new FOOTPRINT_INFO();
|
2011-02-28 18:36:19 +00:00
|
|
|
ItemLib->m_Module = FROM_UTF8( StrPurge( line ) );
|
2011-02-05 16:15:48 +00:00
|
|
|
ItemLib->m_LibName = libname;
|
2011-02-22 17:59:46 +00:00
|
|
|
AddItem( ItemLib );
|
2011-02-05 16:15:48 +00:00
|
|
|
|
|
|
|
while( reader.ReadLine() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-06 19:19:03 +00:00
|
|
|
line = reader.Line();
|
|
|
|
StrPurge( line );
|
|
|
|
if( strnicmp( line, "$EndMODULE", 10 ) == 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
break;
|
|
|
|
|
2011-02-06 19:19:03 +00:00
|
|
|
int id = ((line[0] & 0xFF) << 8) + (line[1] & 0xFF);
|
2011-02-05 16:15:48 +00:00
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
/* KeyWords */
|
|
|
|
case (('K'<<8) + 'w'):
|
2011-02-28 18:36:19 +00:00
|
|
|
ItemLib->m_KeyWord = FROM_UTF8( StrPurge( line + 3 ) );
|
2011-02-05 16:15:48 +00:00
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
/* Doc */
|
|
|
|
case (('C'<<8) + 'd'):
|
2011-02-28 18:36:19 +00:00
|
|
|
ItemLib->m_Doc = FROM_UTF8( StrPurge( line + 3 ) );
|
2011-02-05 16:15:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
if( !end )
|
|
|
|
{
|
2011-02-22 17:59:46 +00:00
|
|
|
m_filesInvalid << libname << _(" (Unexpected end of file)") << wxT("\n");
|
2011-02-05 16:15:48 +00:00
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|