2009-11-05 19:26:52 +00:00
|
|
|
/***************/
|
|
|
|
/* loadcmp.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-02-01 21:23:27 +00:00
|
|
|
#include "class_DisplayFootprintsFrame.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/**
|
|
|
|
* Analyze the libraries to find the module.
|
|
|
|
* If this module is found, copy it into memory, and
|
|
|
|
* string end of the list of modules.
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-11-05 19:26:52 +00:00
|
|
|
* @param CmpName - Module name
|
|
|
|
* @return - Module if found otherwise NULL.
|
|
|
|
*/
|
2010-02-01 21:23:27 +00:00
|
|
|
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& CmpName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int LineNum, Found = 0;
|
|
|
|
unsigned ii;
|
|
|
|
char Line[1024], Name[255];
|
|
|
|
wxString tmp, msg;
|
|
|
|
wxFileName fn;
|
|
|
|
MODULE* Module = NULL;
|
2009-04-23 15:02:18 +00:00
|
|
|
WinEDA_CvpcbFrame* parent = ( WinEDA_CvpcbFrame* ) GetParent();
|
2009-01-05 05:21:35 +00:00
|
|
|
|
2009-04-23 15:02:18 +00:00
|
|
|
for( ii = 0; ii < parent->m_ModuleLibNames.GetCount(); ii++ )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
2009-04-23 15:02:18 +00:00
|
|
|
fn = parent->m_ModuleLibNames[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 )
|
|
|
|
{
|
2009-06-01 18:28:34 +00:00
|
|
|
msg.Printf( _( "PCB foot print library file <%s> could not be \
|
|
|
|
found in the default search paths." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( fn.GetFullName() ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-06 10:56:17 +00:00
|
|
|
FILE* file = wxFopen( tmp, wxT( "rt" ) );
|
2009-01-05 05:21:35 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( file == NULL )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Could not open PCB foot print library file <%s>." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( tmp ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
|
2009-01-05 05:21:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Read header. */
|
2009-01-05 05:21:35 +00:00
|
|
|
LineNum = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
GetLine( file, Line, &LineNum );
|
2009-01-05 05:21:35 +00:00
|
|
|
StrPurge( Line );
|
|
|
|
|
|
|
|
if( strnicmp( Line, 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." ),
|
2009-10-13 09:00:46 +00:00
|
|
|
GetChars( tmp ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, titleLibLoadError, wxOK | wxICON_ERROR, this );
|
|
|
|
fclose( file );
|
2009-01-05 05:21:35 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Found = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
while( !Found && GetLine( file, Line, &LineNum ) )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
|
|
|
if( strncmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
while( GetLine( file, Line, &LineNum ) )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
StrPurge( Line );
|
|
|
|
if( stricmp( Line, CONV_TO_UTF8( CmpName ) ) == 0 )
|
|
|
|
{
|
|
|
|
Found = 1;
|
2009-11-05 19:26:52 +00:00
|
|
|
break;
|
2009-01-05 05:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
while( Found && GetLine( file, Line, &LineNum ) )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( Line[1] != 'M' )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Read component name. */
|
2009-01-05 05:21:35 +00:00
|
|
|
sscanf( Line + 7, " %s", Name );
|
2009-11-05 19:26:52 +00:00
|
|
|
if( stricmp( Name, CONV_TO_UTF8( CmpName ) ) == 0 )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
|
|
|
Module = new MODULE( GetBoard() );
|
2009-11-05 19:26:52 +00:00
|
|
|
// Switch the locale to standard C (needed to print floating
|
|
|
|
// point numbers like 1.3)
|
2009-01-05 05:21:35 +00:00
|
|
|
SetLocaleTo_C_standard();
|
2009-04-05 20:49:15 +00:00
|
|
|
Module->ReadDescr( file, &LineNum );
|
2009-11-05 19:26:52 +00:00
|
|
|
SetLocaleTo_Default(); // revert to the current locale
|
2009-01-05 05:21:35 +00:00
|
|
|
Module->SetPosition( wxPoint( 0, 0 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2009-01-05 05:21:35 +00:00
|
|
|
return Module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2009-04-06 10:56:17 +00:00
|
|
|
file = NULL;
|
2009-01-05 05:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg.Printf( _( "Module %s not found" ), CmpName.GetData() );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|