2007-08-20 01:20:48 +00:00
|
|
|
/**********************************************/
|
|
|
|
/* Footprints selection and loading functions */
|
|
|
|
/**********************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "eda_doc.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
|
|
|
#include "get_component_dialog.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "pcbnew.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
class ModList
|
|
|
|
{
|
|
|
|
public:
|
2007-08-20 01:20:48 +00:00
|
|
|
ModList* Next;
|
|
|
|
wxString m_Name, m_Doc, m_KeyWord;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
public:
|
2007-09-01 12:00:30 +00:00
|
|
|
ModList()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
Next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
~ModList()
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Fonctions locales */
|
2007-08-20 01:20:48 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name );
|
|
|
|
static void ReadDocLib( const wxString& ModLibName );
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*****/
|
|
|
|
|
|
|
|
/* variables locales */
|
2007-08-20 01:20:48 +00:00
|
|
|
static ModList* MList;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
void WinEDA_ModuleEditFrame::Load_Module_Module_From_BOARD( MODULE* Module )
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* NewModule;
|
2008-12-08 15:27:13 +00:00
|
|
|
WinEDA_BasePcbFrame* parent = (WinEDA_BasePcbFrame*) GetParent();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
if( parent->GetBoard() == NULL || parent->GetBoard()->m_Modules == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = Select_1_Module_From_BOARD( parent->GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-12-03 06:54:19 +00:00
|
|
|
Clear_Pcb( TRUE );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
|
|
|
NewModule = new MODULE( GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
NewModule->Copy( Module );
|
|
|
|
NewModule->m_Link = Module->m_TimeStamp;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Module = NewModule;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( Module );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Module->m_Flags = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->Build_Pads_Full_List();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur.x = GetScreen()->m_Curseur.y = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
Place_Module( Module, NULL );
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Module->GetLayer() != CMP_N )
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Change_Side_Module( Module, NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
Rotate_Module( NULL, Module, 0, FALSE );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->ClrModify();
|
2007-08-20 01:20:48 +00:00
|
|
|
Zoom_Automatique( TRUE );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* WinEDA_BasePcbFrame::Load_Module_From_Library( const wxString& library,
|
|
|
|
wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Permet de charger un module directement a partir de la librairie */
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* module;
|
2008-04-17 16:25:29 +00:00
|
|
|
wxPoint curspos = GetScreen()->m_Curseur;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString ModuleName, keys;
|
|
|
|
static wxArrayString HistoryList;
|
|
|
|
bool AllowWildSeach = TRUE;
|
|
|
|
|
|
|
|
/* Ask for a component name or key words */
|
2008-10-01 19:57:10 +00:00
|
|
|
ModuleName = GetComponentName( this, HistoryList, _( "Place module" ), NULL );
|
2007-08-20 01:20:48 +00:00
|
|
|
ModuleName.MakeUpper();
|
|
|
|
if( ModuleName.IsEmpty() ) /* Cancel command */
|
|
|
|
{
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( ModuleName[0] == '=' ) // Selection by keywords
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
|
|
|
keys = ModuleName.AfterFirst( '=' );
|
|
|
|
ModuleName = Select_1_Module_From_List( this, library, wxEmptyString, keys );
|
|
|
|
if( ModuleName.IsEmpty() ) /* Cancel command */
|
|
|
|
{
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( ( ModuleName.Contains( wxT( "?" ) ) ) || ( ModuleName.Contains( wxT( "*" ) ) ) ) // Selection wild card
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
|
|
|
ModuleName = Select_1_Module_From_List( this, library, ModuleName, wxEmptyString );
|
|
|
|
if( ModuleName.IsEmpty() )
|
|
|
|
{
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
return NULL; /* annulation de commande */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
module = Get_Librairie_Module( library, ModuleName, FALSE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( (module == NULL) && AllowWildSeach ) /* Attemp to search with wildcard */
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
|
|
|
wxString wildname = wxChar( '*' ) + ModuleName + wxChar( '*' );
|
|
|
|
ModuleName = wildname;
|
|
|
|
ModuleName = Select_1_Module_From_List( this, library, ModuleName, wxEmptyString );
|
|
|
|
if( ModuleName.IsEmpty() )
|
|
|
|
{
|
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
return NULL; /* annulation de commande */
|
|
|
|
}
|
|
|
|
else
|
2009-04-06 16:05:25 +00:00
|
|
|
module = Get_Librairie_Module( library, ModuleName, TRUE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->m_Curseur = curspos;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->MouseToCursorSchema();
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
AddHistoryComponentName( HistoryList, ModuleName );
|
|
|
|
|
|
|
|
module->m_Flags = IS_NEW;
|
|
|
|
module->m_Link = 0;
|
|
|
|
module->m_TimeStamp = GetTimeStamp();
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
module->SetPosition( curspos );
|
2009-05-24 18:28:36 +00:00
|
|
|
GetBoard()->Build_Pads_Full_List();
|
2009-05-21 12:45:21 +00:00
|
|
|
if ( DC )
|
|
|
|
module->Draw( DrawPanel, DC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
/** function Get_Librairie_Module
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-04-06 16:05:25 +00:00
|
|
|
* Read active libraries or one library to find and load a given module
|
|
|
|
* If found the lodule is linked to the tail of linked list of modules
|
|
|
|
* @param aLibrary: the full filename of the library to read. If empty, all active libraries are read
|
|
|
|
* @param aModuleName = module name to load
|
|
|
|
* @param aDisplayMessageError = true to display an error message if any.
|
|
|
|
* @return a MODULE * pointer to the new module, or NULL
|
2009-04-05 20:49:15 +00:00
|
|
|
*
|
2009-04-06 16:05:25 +00:00
|
|
|
*/
|
|
|
|
MODULE* WinEDA_BasePcbFrame::Get_Librairie_Module( const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aModuleName,
|
|
|
|
bool aDisplayMessageError )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int LineNum, Found = 0;
|
|
|
|
wxFileName fn;
|
|
|
|
char Line[512];
|
|
|
|
wxString Name;
|
|
|
|
wxString msg, tmp;
|
|
|
|
MODULE* NewModule;
|
|
|
|
FILE* file = NULL;
|
|
|
|
unsigned ii;
|
2009-04-06 16:05:25 +00:00
|
|
|
bool one_lib = aLibraryFullFilename.IsEmpty() ? false : true;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
for( ii = 0; ii < g_LibName_List.GetCount(); ii++ )
|
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if ( one_lib )
|
|
|
|
fn = aLibraryFullFilename;
|
|
|
|
else
|
2009-04-08 18:06:22 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibName_List[ii],
|
|
|
|
ModuleFileExtension );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "PCB footprint library file <%s> not found in search paths." ),
|
|
|
|
fn.GetFullName().c_str() );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = wxFopen( tmp, wxT( "rt" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( file == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Could not open PCB footprint library file <%s>." ),
|
|
|
|
tmp.c_str() );
|
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
2007-08-20 01:20:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
msg.Printf( _( "Scan Lib: %s" ), tmp.c_str() );
|
2007-08-20 01:20:48 +00:00
|
|
|
Affiche_Message( msg );
|
|
|
|
|
|
|
|
/* lecture entete chaine definie par ENTETE_LIBRAIRIE */
|
|
|
|
LineNum = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
GetLine( file, Line, &LineNum );
|
2007-08-20 01:20:48 +00:00
|
|
|
StrPurge( Line );
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library file." ),
|
|
|
|
tmp.c_str() );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
fclose( file );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture de la liste des composants de la librairie */
|
|
|
|
Found = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
while( !Found && GetLine( file, Line, &LineNum ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
while( GetLine( file, Line, &LineNum ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
StrPurge( Line );
|
|
|
|
msg = CONV_FROM_UTF8( Line );
|
2009-04-06 16:05:25 +00:00
|
|
|
if( msg.CmpNoCase( aModuleName ) == 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Found = 1;
|
|
|
|
break; /* Trouve! */
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture de la librairie */
|
2009-04-05 20:49:15 +00:00
|
|
|
while( Found && GetLine( file, Line, &LineNum ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( Line[1] != 'M' )
|
|
|
|
continue;
|
|
|
|
if( strnicmp( Line, "$MODULE", 7 ) != 0 )
|
|
|
|
continue;
|
|
|
|
/* Lecture du nom du composant */
|
|
|
|
Name = CONV_FROM_UTF8( Line + 8 );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( Name.CmpNoCase( aModuleName ) == 0 ) /* composant localise */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-01-05 05:21:35 +00:00
|
|
|
NewModule = new MODULE( GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// Switch the locale to standard C (needed to print
|
|
|
|
// floating point numbers like 1.3)
|
2008-06-06 16:39:45 +00:00
|
|
|
SetLocaleTo_C_standard( );
|
2009-04-05 20:49:15 +00:00
|
|
|
NewModule->ReadDescr( file, &LineNum );
|
|
|
|
SetLocaleTo_Default( ); // revert to the current locale
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( NewModule, ADD_APPEND );
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2007-08-20 01:20:48 +00:00
|
|
|
Affiche_Message( wxEmptyString );
|
|
|
|
return NewModule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
2009-04-06 16:05:25 +00:00
|
|
|
if ( one_lib )
|
|
|
|
break;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aDisplayMessageError )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
msg.Printf( _( "Module <%s> not found" ), aModuleName.c_str() );
|
|
|
|
DisplayError( NULL, msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************************/
|
|
|
|
wxString WinEDA_BasePcbFrame::Select_1_Module_From_List(
|
2007-08-20 01:20:48 +00:00
|
|
|
WinEDA_DrawFrame* active_window,
|
2009-04-06 16:05:25 +00:00
|
|
|
const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aMask, const wxString& aKeyWord )
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
/** Function Select_1_Module_From_List
|
|
|
|
* Display a list of modules found in active libraries or a given library
|
|
|
|
* @param aLibraryFullFilename = library to list (if aLibraryFullFilename == void, list all modules)
|
|
|
|
* @param aMask = Display filter (wildcart)( Mask = wxEmptyString if not used )
|
|
|
|
* @param aKeyWord = keyword list, to display a filtered list of module having one (or more) of these keyworks in their keywork list
|
|
|
|
* ( aKeyWord = wxEmptyString if not used )
|
2008-04-01 05:21:50 +00:00
|
|
|
*
|
2009-04-06 16:05:25 +00:00
|
|
|
* @return wxEmptyString if abort or fails, or the selected module name if Ok
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int LineNum;
|
|
|
|
unsigned ii, NbModules;
|
|
|
|
char Line[1024];
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
2007-08-20 01:20:48 +00:00
|
|
|
static wxString OldName;/* Memorise le nom du dernier composant charge */
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString CmpName, tmp;
|
|
|
|
FILE* file;
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
WinEDAListBox* ListBox = new WinEDAListBox( active_window, wxEmptyString,
|
2009-04-05 20:49:15 +00:00
|
|
|
NULL, OldName, DisplayCmpDoc,
|
|
|
|
wxColour( 200, 200, 255 ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
|
|
|
/* Recherche des composants en librairies */
|
|
|
|
NbModules = 0;
|
|
|
|
for( ii = 0; ii < g_LibName_List.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
/* Calcul du nom complet de la librairie */
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibName_List[ii],
|
|
|
|
ModuleFileExtension );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-06 16:05:25 +00:00
|
|
|
fn = aLibraryFullFilename;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-08 18:06:22 +00:00
|
|
|
tmp = wxGetApp().FindLibraryPath( fn );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( !tmp )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "PCB footprint library file <%s> not found in search paths." ),
|
|
|
|
fn.GetFullName().c_str() );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadDocLib( tmp );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aKeyWord.IsEmpty() ) /* Inutile de lire la librairie si selection
|
2007-08-20 01:20:48 +00:00
|
|
|
* par mots cles, deja lus */
|
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
file = wxFopen( tmp, wxT( "rt" ) );
|
|
|
|
|
|
|
|
if( file == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-10-05 10:56:43 +00:00
|
|
|
// Statusbar library loaded message
|
2009-04-05 20:49:15 +00:00
|
|
|
msg = _( "Library " ) + fn.GetFullPath() + _(" loaded");
|
2007-08-20 01:20:48 +00:00
|
|
|
Affiche_Message( msg );
|
|
|
|
|
|
|
|
/* lecture entete */
|
|
|
|
LineNum = 0;
|
2009-04-05 20:49:15 +00:00
|
|
|
GetLine( file, Line, &LineNum, sizeof(Line) - 1 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( strnicmp( Line, ENTETE_LIBRAIRIE, L_ENTETE_LIB ) != 0 )
|
|
|
|
{
|
2009-05-21 17:42:42 +00:00
|
|
|
msg.Printf( _( "<%s> is not a valid Kicad PCB footprint library file." ),
|
|
|
|
tmp.c_str() );
|
2009-04-05 20:49:15 +00:00
|
|
|
wxMessageBox( msg, _( "Library Load Error" ),
|
|
|
|
wxOK | wxICON_ERROR, this );
|
|
|
|
fclose( file );
|
|
|
|
continue;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Lecture de la librairie */
|
2009-04-05 20:49:15 +00:00
|
|
|
while( GetLine( file, Line, &LineNum, sizeof(Line) - 1 ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( strnicmp( Line, "$MODULE", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
if( strnicmp( Line, "$INDEX", 6 ) == 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
while( GetLine( file, Line, &LineNum ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$EndINDEX", 9 ) == 0 )
|
|
|
|
break;
|
|
|
|
strupper( Line );
|
|
|
|
msg = CONV_FROM_UTF8( StrPurge( Line ) );
|
2009-04-06 16:05:25 +00:00
|
|
|
if( aMask.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
ListBox->Append( msg );
|
|
|
|
NbModules++;
|
|
|
|
}
|
2009-04-06 16:05:25 +00:00
|
|
|
else if( WildCompareString( aMask, msg, FALSE ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
ListBox->Append( msg );
|
|
|
|
NbModules++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* Fin Lecture INDEX */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fin lecture 1 Librairie */
|
2009-04-05 20:49:15 +00:00
|
|
|
fclose( file );
|
|
|
|
file = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aLibraryFullFilename.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* creation de la liste des modules si recherche par mots-cles */
|
2009-04-06 16:05:25 +00:00
|
|
|
if( !aKeyWord.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
ModList* ItemMod = MList;
|
|
|
|
while( ItemMod != NULL )
|
|
|
|
{
|
2009-04-06 16:05:25 +00:00
|
|
|
if( KeyWordOk( aKeyWord, ItemMod->m_KeyWord ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
NbModules++;
|
|
|
|
ListBox->Append( ItemMod->m_Name );
|
|
|
|
}
|
|
|
|
ItemMod = ItemMod->Next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxEndBusyCursor();
|
|
|
|
|
2008-10-01 19:57:10 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), NbModules );
|
2007-08-20 01:20:48 +00:00
|
|
|
ListBox->SetTitle( msg );
|
|
|
|
ListBox->SortList();
|
|
|
|
|
|
|
|
ii = ListBox->ShowModal();
|
|
|
|
if( ii >= 0 )
|
|
|
|
CmpName = ListBox->GetTextSelection();
|
|
|
|
else
|
|
|
|
CmpName.Empty();
|
|
|
|
|
|
|
|
ListBox->Destroy();
|
|
|
|
|
|
|
|
/* liberation mem de la liste des textes doc module */
|
|
|
|
while( MList != NULL )
|
|
|
|
{
|
|
|
|
ModList* NewMod = MList->Next;
|
|
|
|
delete MList;
|
|
|
|
MList = NewMod;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( CmpName != wxEmptyString )
|
|
|
|
OldName = CmpName;
|
|
|
|
|
|
|
|
return CmpName;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name )
|
2007-05-06 16:03:28 +00:00
|
|
|
/*******************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Routine de recherche et d'affichage de la doc du composant Name
|
2007-08-20 01:20:48 +00:00
|
|
|
* La liste des doc est pointee par MList
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
ModList* Mod = MList;
|
|
|
|
|
|
|
|
if( !Mod )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Name.Empty();
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Recherche de la description */
|
|
|
|
while( Mod )
|
|
|
|
{
|
|
|
|
if( !Mod->m_Name.IsEmpty() && (Mod->m_Name.CmpNoCase( Name ) == 0) )
|
|
|
|
break;
|
|
|
|
Mod = Mod->Next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Mod )
|
|
|
|
{
|
|
|
|
Name = !Mod->m_Doc.IsEmpty() ? Mod->m_Doc : wxT( "No Doc" );
|
|
|
|
Name += wxT( "\nKeyW: " );
|
|
|
|
Name += !Mod->m_KeyWord.IsEmpty() ? Mod->m_KeyWord : wxT( "No Keyword" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Name = wxEmptyString;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
static void ReadDocLib( const wxString& ModLibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Routine de lecture du fichier Doc associe a la librairie ModLibName.
|
2007-08-20 01:20:48 +00:00
|
|
|
* Cree en memoire la chaine liste des docs pointee par MList
|
|
|
|
* ModLibName = full file Name de la librairie Modules
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
ModList* NewMod;
|
|
|
|
char Line[1024];
|
|
|
|
FILE* LibDoc;
|
|
|
|
wxFileName fn = ModLibName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( EXT_DOC );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( ( LibDoc = wxFopen( fn.GetFullPath(), wxT( "rt" ) ) ) == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 );
|
|
|
|
if( strnicmp( Line, ENTETE_LIBDOC, L_ENTETE_LIB ) != 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Lecture de la librairie */
|
|
|
|
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( Line[0] != '$' )
|
|
|
|
continue;
|
|
|
|
if( Line[1] == 'E' )
|
|
|
|
break;;
|
|
|
|
if( Line[1] == 'M' ) /* Debut decription 1 module */
|
|
|
|
{
|
|
|
|
NewMod = new ModList();
|
|
|
|
NewMod->Next = MList;
|
|
|
|
MList = NewMod;
|
|
|
|
while( GetLine( LibDoc, Line, NULL, sizeof(Line) - 1 ) )
|
|
|
|
{
|
|
|
|
if( Line[0] == '$' ) /* $EndMODULE */
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch( Line[0] )
|
|
|
|
{
|
|
|
|
case 'L': /* LibName */
|
|
|
|
NewMod->m_Name = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K': /* KeyWords */
|
|
|
|
NewMod->m_KeyWord = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C': /* Doc */
|
|
|
|
NewMod->m_Doc = CONV_FROM_UTF8( StrPurge( Line + 3 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* lecture 1 descr module */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fin lecture librairie */
|
|
|
|
fclose( LibDoc );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/********************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
MODULE* WinEDA_BasePcbFrame::Select_1_Module_From_BOARD( BOARD* Pcb )
|
2007-05-06 16:03:28 +00:00
|
|
|
/********************************************************************/
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Affiche la liste des modules du PCB en cours
|
2007-08-20 01:20:48 +00:00
|
|
|
* Retourne un pointeur si module selectionne
|
|
|
|
* retourne NULL sinon
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii;
|
|
|
|
MODULE* Module;
|
|
|
|
static wxString OldName;/* Memorise le nom du dernier composant charge */
|
|
|
|
wxString CmpName, msg;
|
|
|
|
|
|
|
|
WinEDAListBox* ListBox = new WinEDAListBox( this, wxEmptyString,
|
2009-04-05 20:49:15 +00:00
|
|
|
NULL, wxEmptyString, NULL,
|
|
|
|
wxColour( 200, 200, 255 ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
/* Recherche des composants en BOARD */
|
|
|
|
ii = 0;
|
|
|
|
Module = Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
ii++;
|
|
|
|
ListBox->Append( Module->m_Reference->m_Text );
|
|
|
|
}
|
|
|
|
|
2008-10-01 19:57:10 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), ii );
|
2007-08-20 01:20:48 +00:00
|
|
|
ListBox->SetTitle( msg );
|
|
|
|
|
|
|
|
ListBox->SortList();
|
|
|
|
|
|
|
|
ii = ListBox->ShowModal();
|
|
|
|
if( ii >= 0 )
|
|
|
|
CmpName = ListBox->GetTextSelection();
|
|
|
|
else
|
|
|
|
CmpName.Empty();
|
|
|
|
|
|
|
|
ListBox->Destroy();
|
|
|
|
|
|
|
|
if( CmpName == wxEmptyString )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
OldName = CmpName;
|
|
|
|
|
|
|
|
// Recherche du pointeur sur le module
|
|
|
|
Module = Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
if( CmpName.CmpNoCase( Module->m_Reference->m_Text ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|