2011-02-05 18:00:05 +00:00
|
|
|
/**
|
|
|
|
* @file listlib.cpp
|
|
|
|
*/
|
2009-11-05 19:26:52 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2011-02-05 18:00:05 +00:00
|
|
|
* Functions to read footprint libraries and fill m_footprints by availlable 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"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvpcb.h"
|
2011-02-05 18:00:05 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
#include "dialog_load_error.h"
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
/*
|
|
|
|
* Read the list of libraries (*.mod files) and generate a m_footprints of modules.
|
|
|
|
* for each module are stored
|
|
|
|
* the module name
|
|
|
|
* documentation string
|
|
|
|
* associated keywords
|
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-05 16:15:48 +00:00
|
|
|
bool CVPCB_MAINFRAME::LoadFootprintFiles( )
|
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;
|
|
|
|
wxString files_not_found;
|
|
|
|
wxString files_invalid;
|
2009-10-05 04:22:27 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
/* Check if footprint m_footprints is not empty */
|
|
|
|
if( !m_footprints.empty() )
|
|
|
|
m_footprints.clear();
|
2009-10-05 04:22:27 +00:00
|
|
|
|
|
|
|
/* Check if there are footprint libraries in project file */
|
2011-02-05 16:15:48 +00:00
|
|
|
if( m_ModuleLibNames.GetCount() == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2011-02-05 18:00:05 +00:00
|
|
|
wxMessageBox( _( "No PCB footprint libraries are listed in the current project file." ),
|
2009-05-21 17:42:42 +00:00
|
|
|
_( "Project File Error" ), wxOK | wxICON_ERROR );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
/* Parse Libraries Listed */
|
2011-02-05 16:15:48 +00:00
|
|
|
for( unsigned ii = 0; ii < m_ModuleLibNames.GetCount(); ii++ )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-05 16:15:48 +00:00
|
|
|
filename = m_ModuleLibNames[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-05 16:15:48 +00:00
|
|
|
files_not_found << 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-05 16:15:48 +00:00
|
|
|
files_invalid << 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-02-06 19:19:03 +00:00
|
|
|
if( strnicmp( line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2011-02-05 16:15:48 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library." ),
|
|
|
|
GetChars( libname ) );
|
|
|
|
files_invalid << 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-05 16:15:48 +00:00
|
|
|
FOOTPRINT* ItemLib = new FOOTPRINT();
|
2011-02-06 19:19:03 +00:00
|
|
|
ItemLib->m_Module = CONV_FROM_UTF8( StrPurge( line ) );
|
2011-02-05 16:15:48 +00:00
|
|
|
ItemLib->m_LibName = libname;
|
|
|
|
m_footprints.push_back( ItemLib );
|
|
|
|
|
|
|
|
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-06 19:19:03 +00:00
|
|
|
ItemLib->m_KeyWord = CONV_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-06 19:19:03 +00:00
|
|
|
ItemLib->m_Doc = CONV_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 )
|
|
|
|
{
|
|
|
|
files_invalid << libname << _(" (Unexpected end of file)") << wxT("\n");
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
2011-02-05 16:15:48 +00:00
|
|
|
m_footprints.sort();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
/* Display error messages, if any */
|
|
|
|
if( !files_not_found.IsEmpty() || !files_invalid.IsEmpty() )
|
2009-07-13 07:01:57 +00:00
|
|
|
{
|
|
|
|
DIALOG_LOAD_ERROR dialog(NULL);
|
2011-02-05 16:15:48 +00:00
|
|
|
if( !files_not_found.IsEmpty() )
|
2009-07-13 07:01:57 +00:00
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
wxString message = _("Some files could not be found!");
|
2009-07-13 07:01:57 +00:00
|
|
|
dialog.MessageSet(message);
|
2011-02-05 16:15:48 +00:00
|
|
|
dialog.ListSet(files_not_found);
|
2009-07-13 07:01:57 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 16:15:48 +00:00
|
|
|
/* Display if there are invalid files */
|
|
|
|
if( !files_invalid.IsEmpty() )
|
2009-07-13 07:01:57 +00:00
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
dialog.MessageSet( _("Some files are invalid!"));
|
2011-02-05 16:15:48 +00:00
|
|
|
dialog.ListSet(files_invalid);
|
2009-07-13 07:01:57 +00:00
|
|
|
}
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
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
|
|
|
}
|