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"
|
|
|
|
|
|
|
|
|
|
/* 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-04-05 20:49:15 +00:00
|
|
|
|
FILE* file; /* pour lecture librairie */
|
|
|
|
|
char buffer[1024];
|
|
|
|
|
wxFileName fn;
|
|
|
|
|
int end;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
FOOTPRINT* ItemLib;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
unsigned ii;
|
|
|
|
|
wxString tmp, msg;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
|
if( !list.empty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
|
list.DeleteContents( true );
|
|
|
|
|
list.Clear();
|
|
|
|
|
list.DeleteContents( false );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
|
if( libNames.GetCount() == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
{
|
|
|
|
|
wxMessageBox( _( "No PCB foot print libraries are listed in the " \
|
|
|
|
|
"current project file." ), _( "Project File Error" ),
|
|
|
|
|
wxOK | wxICON_ERROR );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
|
/* Lecture des Librairies */
|
2009-04-23 15:02:18 +00:00
|
|
|
|
for( ii = 0; ii < libNames.GetCount(); ii++ )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
|
|
|
|
/* Calcul du nom complet de la librairie */
|
2009-04-23 15:02:18 +00:00
|
|
|
|
fn = libNames[ii];
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fn.SetExt( ModuleFileExtension );
|
|
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "PCB foot print library file <%s> could not be " \
|
|
|
|
|
"found in the default search paths." ),
|
|
|
|
|
fn.GetFullName().c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
/* acces a une librairie */
|
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-04-05 20:49:15 +00:00
|
|
|
|
msg.Printf( _( "Could not open PCB foot print library file <%s>." ),
|
|
|
|
|
tmp.c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Controle du type de la librairie : */
|
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-04-05 20:49:15 +00:00
|
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB foot print library" ),
|
|
|
|
|
tmp.c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
|
|
|
|
fclose( file );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
|
/* lecture nom des composants : */
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "Unexpected end of file occurred while " \
|
|
|
|
|
"parsing PCB foot print library <%s>." ),
|
|
|
|
|
tmp.c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
|
|
|
|
}
|
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-04-23 15:02:18 +00:00
|
|
|
|
list.Sort( compare );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +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-04-23 15:02:18 +00:00
|
|
|
|
static void ReadDocLib( const wxString& ModLibName, FOOTPRINT_LIST& list )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
|
FOOTPRINT* NewMod;
|
|
|
|
|
FOOTPRINT* tmp;
|
|
|
|
|
char Line[1024];
|
|
|
|
|
wxString ModuleName;
|
|
|
|
|
wxString msg;
|
|
|
|
|
FILE* LibDoc;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxFileName fn = ModLibName;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
FOOTPRINT_LIST::iterator i;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fn.SetExt( wxT( "mdc" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
if( ( LibDoc = wxFopen( fn.GetFullPath(), wxT( "rt" ) ) ) == NULL )
|
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "Could not open PCB foot print library document " \
|
|
|
|
|
"file <%s>." ), fn.GetFullPath().c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
|
GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 );
|
|
|
|
|
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "<%s> is not a valid PCB foot print library " \
|
|
|
|
|
"document file." ), fn.GetFullPath().c_str() );
|
|
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
|
|
/* Lecture de la librairie */
|
|
|
|
|
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
|
{
|
|
|
|
|
NewMod = NULL;
|
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
|
continue;
|
|
|
|
|
if( Line[1] == 'E' )
|
|
|
|
|
break;;
|
|
|
|
|
if( Line[1] == 'M' ) /* Debut decription 1 module */
|
|
|
|
|
{
|
|
|
|
|
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
|
{
|
|
|
|
|
if( Line[0] == '$' ) /* $EndMODULE */
|
|
|
|
|
break;
|
|
|
|
|
switch( Line[0] )
|
|
|
|
|
{
|
|
|
|
|
case 'L': /* LibName */
|
|
|
|
|
ModuleName = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
2009-04-23 15:02:18 +00:00
|
|
|
|
for( i = list.begin(); i != list.end(); ++i )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
|
tmp = *i;
|
|
|
|
|
|
|
|
|
|
if( ModuleName == tmp->m_Module )
|
|
|
|
|
{
|
|
|
|
|
NewMod = tmp;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
break;
|
2009-04-23 15:02:18 +00:00
|
|
|
|
}
|
2009-02-04 15:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'K': /* KeyWords */
|
|
|
|
|
if( NewMod && (!NewMod->m_KeyWord) )
|
|
|
|
|
NewMod->m_KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'C': /* Doc */
|
2009-04-23 15:02:18 +00:00
|
|
|
|
if( NewMod && ( !NewMod->m_Doc ) )
|
2009-02-04 15:25:03 +00:00
|
|
|
|
NewMod->m_Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} /* lecture 1 descr module */
|
|
|
|
|
} /* Fin lecture librairie */
|
|
|
|
|
|
|
|
|
|
fclose( LibDoc );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|