2009-02-04 15:25:03 +00:00
|
|
|
/**************/
|
|
|
|
/* savecmp() */
|
|
|
|
/**************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* sauvegarde la liste des associations composants/empreintes */
|
|
|
|
|
|
|
|
#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"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "cvpcb.h"
|
|
|
|
#include "protos.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "cvstruct.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Chaines de caractere d'identification */
|
2009-02-04 15:25:03 +00:00
|
|
|
char EnteteCmpMod[] = { "Cmp-Mod V01" };
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
const wxString titleComponentLibErr( _( "Component Library Error" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de sauvegarde du fichier des modules
|
2009-02-04 15:25:03 +00:00
|
|
|
* Retourne 1 si OK
|
|
|
|
* 0 si ecriture non faite
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
int WinEDA_CvpcbFrame::SaveComponentList( const wxString& NetlistFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
STORECMP* Cmp;
|
|
|
|
FILE* dest;
|
|
|
|
wxFileName fn( NetlistFullFileName );
|
|
|
|
char Line[1024];
|
|
|
|
wxString Title = wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
/* calcul du nom du fichier */
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
dest = wxFopen( fn.GetFullPath(), wxT( "wt" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( dest == NULL )
|
|
|
|
return 0; /* Erreur ecriture */
|
|
|
|
|
|
|
|
fprintf( dest, "%s", EnteteCmpMod );
|
|
|
|
fprintf( dest, " Created by %s", CONV_TO_UTF8( Title ) );
|
|
|
|
fprintf( dest, " date = %s\n", DateAndTime( Line ) );
|
|
|
|
|
|
|
|
for( Cmp = g_BaseListeCmp; Cmp != NULL; Cmp = Cmp->Pnext )
|
|
|
|
{
|
|
|
|
fprintf( dest, "\nBeginCmp\n" );
|
|
|
|
fprintf( dest, "TimeStamp = %s;\n", CONV_TO_UTF8( Cmp->m_TimeStamp ) );
|
|
|
|
fprintf( dest, "Reference = %s;\n", CONV_TO_UTF8( Cmp->m_Reference ) );
|
|
|
|
fprintf( dest, "ValeurCmp = %s;\n", CONV_TO_UTF8( Cmp->m_Valeur ) );
|
|
|
|
fprintf( dest, "IdModule = %s;\n", CONV_TO_UTF8( Cmp->m_Module ) );
|
|
|
|
fprintf( dest, "EndCmp\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( dest, "\nEndListe\n" );
|
|
|
|
fclose( dest );
|
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************/
|
|
|
|
/* recupere la liste des associations composants/empreintes
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
/****************/
|
|
|
|
bool loadcmp( const wxString& fileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString timestamp, valeur, ilib, namecmp, msg;
|
|
|
|
bool read_cmp_data = FALSE, eof = FALSE;
|
|
|
|
STORECMP* Cmp;
|
|
|
|
char Line[1024], * ident, * data;
|
|
|
|
FILE* source;
|
|
|
|
wxFileName fn = fileName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
/* calcul du nom du fichier */
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( ComponentFileExtension );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
source = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
if( source == NULL )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Cannot open component library <%s>." ),
|
|
|
|
fn.GetFullPath().c_str() );
|
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Identification du Type de fichier CmpMod */
|
|
|
|
if( fgets( Line, 79, source ) == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( " <%s> does not appear to be a valid Kicad component " \
|
|
|
|
"library." ), fn.GetFullPath().c_str() );
|
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
|
|
|
fclose( source );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( strnicmp( Line, EnteteCmpMod, 11 ) != 0 ) /* old file version*/
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "<%s> is an old version component file." ) );
|
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
2009-02-04 15:25:03 +00:00
|
|
|
fclose( source );
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* lecture de la liste */
|
|
|
|
while( !eof && fgets( Line, 79, source ) != 0 )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "EndListe", 8 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Recherche du debut de description du composant */
|
|
|
|
if( strnicmp( Line, "BeginCmp", 8 ) != 0 )
|
|
|
|
continue;
|
|
|
|
timestamp.Empty();
|
|
|
|
valeur.Empty();
|
|
|
|
ilib.Empty();
|
|
|
|
namecmp.Empty();
|
|
|
|
read_cmp_data = TRUE;
|
|
|
|
|
|
|
|
while( !eof && read_cmp_data )
|
|
|
|
{
|
|
|
|
if( fgets( Line, 1024, source ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
eof = TRUE;
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( Line, "EndCmp", 6 ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
read_cmp_data = TRUE;
|
|
|
|
break;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ident = strtok( Line, "=;\n\r" );
|
|
|
|
data = strtok( NULL, ";\n\r" );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( strnicmp( ident, "TimeStamp", 9 ) == 0 )
|
|
|
|
{
|
|
|
|
timestamp = CONV_FROM_UTF8( data );
|
|
|
|
timestamp.Trim( TRUE );
|
|
|
|
timestamp.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "Reference", 9 ) == 0 )
|
|
|
|
{
|
|
|
|
namecmp = CONV_FROM_UTF8( data );
|
|
|
|
namecmp.Trim( TRUE );
|
|
|
|
namecmp.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "ValeurCmp", 9 ) == 0 )
|
|
|
|
{
|
|
|
|
valeur = CONV_FROM_UTF8( data );
|
|
|
|
valeur.Trim( TRUE );
|
|
|
|
valeur.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ident, "IdModule", 8 ) == 0 )
|
|
|
|
{
|
|
|
|
ilib = CONV_FROM_UTF8( data );
|
|
|
|
ilib.Trim( TRUE );
|
|
|
|
ilib.Trim( FALSE );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} /* Fin lecture description de 1 composant */
|
|
|
|
|
|
|
|
/* Recherche du composant correspondant en netliste et
|
|
|
|
* mise a jour de ses parametres */
|
|
|
|
for( Cmp = g_BaseListeCmp; Cmp != NULL; Cmp = Cmp->Pnext )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
if( namecmp != Cmp->m_Reference )
|
|
|
|
continue;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
/* composant identifie , copie du nom du module correspondant */
|
|
|
|
Cmp->m_Module = ilib;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|