2009-11-05 19:26:52 +00:00
|
|
|
/***************/
|
|
|
|
/* loadcmp.cpp */
|
|
|
|
/***************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "wxstruct.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"
|
2011-02-05 16:15:48 +00:00
|
|
|
#include "cvpcb_mainframe.h"
|
2010-02-01 21:23:27 +00:00
|
|
|
#include "class_DisplayFootprintsFrame.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
|
|
|
#include "filter_reader.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/**
|
2011-02-22 20:59:16 +00:00
|
|
|
* Read libraries to find a module.
|
|
|
|
* If this module is found, copy it into memory
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-11-05 19:26:52 +00:00
|
|
|
* @param CmpName - Module name
|
2011-02-22 20:59:16 +00:00
|
|
|
* @return - a pointer to the loaded module or NULL.
|
2009-11-05 19:26:52 +00:00
|
|
|
*/
|
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
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
int Found = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
unsigned ii;
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
|
|
|
char Name[255];
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString tmp, msg;
|
|
|
|
wxFileName fn;
|
|
|
|
MODULE* Module = NULL;
|
2011-02-05 16:15:48 +00:00
|
|
|
CVPCB_MAINFRAME* parent = ( CVPCB_MAINFRAME* ) 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;
|
|
|
|
}
|
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
FILE_LINE_READER fileReader( file, tmp );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
|
|
|
|
2009-11-05 19:26:52 +00:00
|
|
|
/* Read header. */
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
|
|
|
Line = reader.Line();
|
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;
|
2011-01-14 17:43:30 +00:00
|
|
|
while( !Found && reader.ReadLine() )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
2009-01-05 05:21:35 +00:00
|
|
|
if( strncmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
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 );
|
2011-02-28 18:36:19 +00:00
|
|
|
if( stricmp( Line, TO_UTF8( CmpName ) ) == 0 )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( Found && reader.ReadLine() )
|
2009-01-05 05:21:35 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = reader.Line();
|
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 );
|
2011-02-28 18:36:19 +00:00
|
|
|
if( stricmp( Name, 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();
|
2011-01-14 17:43:30 +00:00
|
|
|
Module->ReadDescr( &reader );
|
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 ) );
|
|
|
|
return Module;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|