2009-11-05 19:26:52 +00:00
|
|
|
/****************/
|
|
|
|
/* savecmp.cpp */
|
|
|
|
/****************/
|
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"
|
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"
|
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
#include "build_version.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* File header. */
|
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
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
2009-11-05 19:26:52 +00:00
|
|
|
* Backup modules file.
|
|
|
|
*
|
|
|
|
* @param NetlistFullFileName - Name of net list file to save.
|
|
|
|
* @returns - 1 if OK, 0 if error.
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
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-23 15:02:18 +00:00
|
|
|
FILE* dest;
|
|
|
|
wxFileName fn( NetlistFullFileName );
|
|
|
|
char Line[1024];
|
|
|
|
wxString Title = wxGetApp().GetTitle() + wxT( " " ) + GetBuildVersion();
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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 )
|
2009-11-05 19:26:52 +00:00
|
|
|
return 0;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
|
|
|
fprintf( dest, "%s", EnteteCmpMod );
|
|
|
|
fprintf( dest, " Created by %s", CONV_TO_UTF8( Title ) );
|
|
|
|
fprintf( dest, " date = %s\n", DateAndTime( Line ) );
|
|
|
|
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, m_components )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
|
|
|
fprintf( dest, "\nBeginCmp\n" );
|
2009-05-06 11:55:36 +00:00
|
|
|
fprintf( dest, "TimeStamp = %s;\n",
|
|
|
|
CONV_TO_UTF8( component.m_TimeStamp ) );
|
|
|
|
fprintf( dest, "Reference = %s;\n",
|
|
|
|
CONV_TO_UTF8( component.m_Reference ) );
|
|
|
|
fprintf( dest, "ValeurCmp = %s;\n",
|
|
|
|
CONV_TO_UTF8( component.m_Value ) );
|
|
|
|
fprintf( dest, "IdModule = %s;\n",
|
|
|
|
CONV_TO_UTF8( component.m_Module ) );
|
2009-02-04 15:25:03 +00:00
|
|
|
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
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
/*
|
2009-11-05 19:26:52 +00:00
|
|
|
* Load list of associated components and footprints.
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2009-04-23 15:02:18 +00:00
|
|
|
bool LoadComponentFile( const wxString& fileName, COMPONENT_LIST& list )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
wxString timestamp, valeur, ilib, namecmp, msg;
|
|
|
|
bool read_cmp_data = FALSE, eof = FALSE;
|
|
|
|
char Line[1024], * ident, * data;
|
|
|
|
FILE* source;
|
|
|
|
wxFileName fn = fileName;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
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>." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleComponentLibErr, wxOK | wxICON_ERROR );
|
|
|
|
return false;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Identification of the type of file CmpMod */
|
2009-02-04 15:25:03 +00:00
|
|
|
if( fgets( Line, 79, source ) == 0 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( " <%s> does not appear to be a valid Kicad component library." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullPath() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
while( !eof && fgets( Line, 79, source ) != 0 )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "EndListe", 8 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Search the beginning of the component description. */
|
2009-02-04 15:25:03 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-11-05 19:26:52 +00:00
|
|
|
} /* End reading component description. */
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Search corresponding component and NetList
|
|
|
|
* Update its parameters. */
|
2009-05-06 11:55:36 +00:00
|
|
|
BOOST_FOREACH( COMPONENT& component, list )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-05-06 11:55:36 +00:00
|
|
|
if( namecmp != component.m_Reference )
|
2009-04-05 20:49:15 +00:00
|
|
|
continue;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Copy the name of the corresponding module. */
|
2009-05-06 11:55:36 +00:00
|
|
|
component.m_Module = ilib;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|