2009-02-04 15:25:03 +00:00
|
|
|
|
/**************/
|
|
|
|
|
/* listlib.cpp */
|
|
|
|
|
/**************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2009-02-04 15:25:03 +00:00
|
|
|
|
* cherche toutes les ref <chemin lib>*.??? si nom fichier pr<EFBFBD>sent,
|
|
|
|
|
* ou examine <chemin lib>[MODULE.LIB]
|
|
|
|
|
*/
|
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 "confirm.h"
|
|
|
|
|
#include "kicad_string.h"
|
|
|
|
|
#include "gestfich.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"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
|
#include "dialog_load_error.h"
|
|
|
|
|
|
2009-07-15 07:10:07 +00:00
|
|
|
|
/* MDC and MOD file strings */
|
|
|
|
|
static wxString s_files_not_found;
|
|
|
|
|
static wxString s_files_invalid;
|
2009-07-05 16:59:12 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* routines locales : */
|
2009-04-23 15:02:18 +00:00
|
|
|
|
static void ReadDocLib( const wxString& ModLibName, FOOTPRINT_LIST& list );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* Routine lisant la liste des librairies, et generant la liste chainee
|
2009-02-04 15:25:03 +00:00
|
|
|
|
* des modules disponibles
|
|
|
|
|
*
|
|
|
|
|
* Module descr format:
|
|
|
|
|
* $MODULE c64acmd
|
|
|
|
|
* Li c64acmd
|
|
|
|
|
* Cd Connecteur DIN Europe 96 Contacts AC male droit
|
|
|
|
|
* Kw PAD_CONN DIN
|
|
|
|
|
* $EndMODULE
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
|
bool LoadFootprintFiles( const wxArrayString& libNames,
|
|
|
|
|
FOOTPRINT_LIST& list )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-07-05 16:59:12 +00:00
|
|
|
|
FILE* file; /* pour lecture librairie */
|
|
|
|
|
char buffer[1024];
|
|
|
|
|
wxFileName filename;
|
|
|
|
|
int end;
|
|
|
|
|
FOOTPRINT* ItemLib;
|
|
|
|
|
unsigned i;
|
|
|
|
|
wxString tmp, msg;
|
|
|
|
|
|
|
|
|
|
/* Check if footprint list is not empty */
|
|
|
|
|
if( !list.empty() )
|
|
|
|
|
list.clear();
|
|
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
|
/* Check if there are footprint libraries in project file */
|
2009-04-23 15:02:18 +00:00
|
|
|
|
if( libNames.GetCount() == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
|
wxMessageBox( _( "No PCB foot print libraries are listed in the current project file." ),
|
|
|
|
|
_( "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 */
|
|
|
|
|
for( i = 0; i < libNames.GetCount(); i++ )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
|
|
|
|
/* Calcul du nom complet de la librairie */
|
2009-07-05 16:59:12 +00:00
|
|
|
|
filename = libNames[i];
|
|
|
|
|
filename.SetExt( ModuleFileExtension );
|
|
|
|
|
|
|
|
|
|
tmp = wxGetApp().FindLibraryPath( filename );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_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 */
|
2009-04-05 20:49:15 +00:00
|
|
|
|
file = wxFopen( tmp, wxT( "rt" ) );
|
|
|
|
|
|
|
|
|
|
if( file == NULL )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_files_invalid << tmp << _(" (file cannot be opened)") << wxT("\n");
|
2009-02-04 15:25:03 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
|
/* Check if library type is valid */
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fgets( buffer, 32, file );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
if( strncmp( buffer, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_files_invalid << tmp << _(" (Not a Kicad file)") << wxT("\n");
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fclose( file );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
|
/* TODO Lecture du nombre de composants */
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fseek( file, 0, 0 );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
|
/* TODO lecture nom des composants : */
|
2009-02-04 15:25:03 +00:00
|
|
|
|
end = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
while( !end && fgets( buffer, 255, file ) != NULL )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
|
|
|
|
if( strnicmp( buffer, "$INDEX", 6 ) == 0 )
|
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
while( fgets( buffer, 255, file ) != NULL )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
|
|
|
|
if( strnicmp( buffer, "$EndINDEX", 6 ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
end = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
|
ItemLib = new FOOTPRINT();
|
|
|
|
|
ItemLib->m_Module = CONV_FROM_UTF8( StrPurge( buffer ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
ItemLib->m_LibName = tmp;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
list.push_back( ItemLib );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !end )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_files_invalid << tmp << _(" (Unexpected end of file)") << wxT("\n");
|
2009-04-05 20:49:15 +00:00
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fclose( file );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
ReadDocLib( tmp, list );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-07-05 16:59:12 +00:00
|
|
|
|
/* Display if there are mdc files not found */
|
2009-07-15 07:10:07 +00:00
|
|
|
|
if( !s_files_not_found.IsEmpty() || !s_files_invalid.IsEmpty() )
|
2009-07-13 07:01:57 +00:00
|
|
|
|
{
|
|
|
|
|
DIALOG_LOAD_ERROR dialog(NULL);
|
2009-07-15 07:10:07 +00:00
|
|
|
|
if( !s_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);
|
2009-07-15 07:10:07 +00:00
|
|
|
|
dialog.ListSet(s_files_not_found);
|
|
|
|
|
s_files_not_found.Empty();
|
2009-07-13 07:01:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Display if there are mdc files invalid */
|
2009-07-15 07:10:07 +00:00
|
|
|
|
if( !s_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!"));
|
|
|
|
|
dialog.ListSet(s_files_invalid);
|
|
|
|
|
s_files_invalid.Empty();
|
2009-07-13 07:01:57 +00:00
|
|
|
|
}
|
|
|
|
|
dialog.ShowModal();
|
|
|
|
|
}
|
2009-07-05 16:59:12 +00:00
|
|
|
|
|
|
|
|
|
list.sort();
|
|
|
|
|
|
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-07-13 06:20:18 +00:00
|
|
|
|
/**
|
2009-07-05 16:59:12 +00:00
|
|
|
|
* Routine de lecture du fichier Doc associe a la librairie ModLibName.
|
2009-02-04 15:25:03 +00:00
|
|
|
|
* Cree en memoire la chaine liste des docs pointee par MList
|
|
|
|
|
* ModLibName = full file Name de la librairie Modules
|
|
|
|
|
*/
|
2009-07-05 16:59:12 +00:00
|
|
|
|
static void
|
|
|
|
|
ReadDocLib( const wxString& ModLibName,
|
|
|
|
|
FOOTPRINT_LIST& list )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-07-05 16:59:12 +00:00
|
|
|
|
FOOTPRINT* NewMod;
|
|
|
|
|
char Line[1024];
|
|
|
|
|
wxString ModuleName;
|
|
|
|
|
FILE* mdc_file;
|
|
|
|
|
wxFileName mdc_filename = ModLibName;
|
|
|
|
|
|
|
|
|
|
/* Set mdc filename extension */
|
|
|
|
|
mdc_filename.SetExt( wxT( "mdc" ) );
|
|
|
|
|
|
|
|
|
|
/* Check if mdc file exists and can be opened */
|
|
|
|
|
if( ( mdc_file = wxFopen( mdc_filename.GetFullPath(), wxT( "rt" ) ) ) == NULL )
|
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_files_not_found += mdc_filename.GetFullPath() + wxT("\n");
|
2009-07-05 16:59:12 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if mdc file is valid */
|
|
|
|
|
GetLine( mdc_file, Line, NULL, sizeof(Line) - 1 );
|
|
|
|
|
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
|
|
|
|
|
{
|
2009-07-15 07:10:07 +00:00
|
|
|
|
s_files_invalid += mdc_filename.GetFullPath() + wxT("\n");
|
2009-07-05 16:59:12 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the mdc file */
|
|
|
|
|
while( GetLine( mdc_file, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
|
{
|
|
|
|
|
NewMod = NULL;
|
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
|
continue;
|
|
|
|
|
if( Line[1] == 'E' )
|
|
|
|
|
break;
|
|
|
|
|
if( Line[1] == 'M' ) /* 1 module description */
|
|
|
|
|
{
|
|
|
|
|
/* Parse file line by line */
|
|
|
|
|
while( GetLine( mdc_file, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
|
{
|
|
|
|
|
/* $EndMODULE */
|
|
|
|
|
if( Line[0] == '$' )
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
switch( Line[0] )
|
|
|
|
|
{
|
|
|
|
|
/* LibName */
|
|
|
|
|
case 'L': /* LibName */
|
|
|
|
|
ModuleName = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
BOOST_FOREACH( FOOTPRINT& footprint, list )
|
|
|
|
|
{
|
|
|
|
|
if( ModuleName == footprint.m_Module )
|
|
|
|
|
{
|
|
|
|
|
NewMod = &footprint;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* KeyWords */
|
|
|
|
|
case 'K':
|
|
|
|
|
if( NewMod && (!NewMod->m_KeyWord) )
|
|
|
|
|
NewMod->m_KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* Doc */
|
|
|
|
|
case 'C':
|
|
|
|
|
if( NewMod && ( !NewMod->m_Doc ) )
|
|
|
|
|
NewMod->m_Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* Parsed one module documentation */
|
|
|
|
|
} /* Parsed complete library documentation */
|
|
|
|
|
|
|
|
|
|
fclose( mdc_file );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|