2009-08-23 14:21:41 +00:00
|
|
|
/**************************/
|
|
|
|
/* EESchema - selpart.cpp */
|
|
|
|
/**************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* SelectLibraryFromList( WinEDA_DrawFrame* frame )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-23 14:21:41 +00:00
|
|
|
static wxString OldLibName;
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg;
|
|
|
|
wxArrayString libNamesList;
|
|
|
|
int count = CMP_LIBRARY::GetLibraryCount();
|
|
|
|
CMP_LIBRARY* Lib = NULL;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
if( count == 0 )
|
2009-08-23 14:21:41 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
DisplayError( frame, _( "No component libraries are loaded." ) );
|
2009-08-23 14:21:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
libNamesList = CMP_LIBRARY::GetLibraryNames();
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
msg.Printf( _( " Select 1 of %d libraries." ), count );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
wxSingleChoiceDialog dlg( frame, msg, _( "Select Library" ), libNamesList );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
int index = libNamesList.Index( OldLibName );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
if( index != wxNOT_FOUND )
|
|
|
|
dlg.SetSelection( index );
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
Lib = CMP_LIBRARY::FindLibrary( dlg.GetStringSelection() );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
|
|
|
if( Lib != NULL )
|
|
|
|
OldLibName = dlg.GetStringSelection();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
return Lib;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* Library,
|
2009-08-27 11:41:56 +00:00
|
|
|
wxString& Buffer, wxString& OldName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
size_t i;
|
|
|
|
wxArrayString nameList;
|
|
|
|
const wxChar** ListNames;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
|
|
|
if( Library == NULL )
|
|
|
|
Library = SelectLibraryFromList( frame );
|
|
|
|
|
|
|
|
if( Library == NULL )
|
|
|
|
return 0;
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
Library->GetEntryNames( nameList );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
ListNames = (const wxChar**) MyZMalloc( ( nameList.GetCount() + 1 ) *
|
|
|
|
sizeof( wxChar* ) );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
if( ListNames == NULL )
|
|
|
|
return 0;
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
for( i = 0; i < nameList.GetCount(); i++ )
|
|
|
|
ListNames[i] = (const wxChar*) nameList[i];
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
WinEDAListBox dlg( frame, _( "Select Component" ), ListNames, OldName,
|
|
|
|
DisplayCmpDoc, wxColour( 255, 255, 255 ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-10-01 14:17:47 +00:00
|
|
|
if( !OldName.IsEmpty() )
|
|
|
|
dlg.m_List->SetStringSelection( OldName );
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
dlg.MoveMouseToOrigin();
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
int rsp = dlg.ShowModal();
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( rsp >= 0 )
|
|
|
|
Buffer = ListNames[rsp];
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
free( ListNames );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( rsp < 0 )
|
2009-08-23 14:21:41 +00:00
|
|
|
return 0;
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
int GetNameOfPartToLoad( WinEDA_DrawFrame* frame, CMP_LIBRARY* Library,
|
2009-09-02 18:12:45 +00:00
|
|
|
wxString& BufName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-23 14:21:41 +00:00
|
|
|
int ii;
|
|
|
|
static wxString OldCmpName;
|
|
|
|
|
|
|
|
ii = DisplayComponentsNamesInLib( frame, Library, BufName, OldCmpName );
|
|
|
|
if( ii <= 0 )
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-23 14:21:41 +00:00
|
|
|
OldCmpName = BufName;
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|