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"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "wxstruct.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-18 21:16:28 +00:00
|
|
|
#include "dialog_helpers.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
CMP_LIBRARY* SelectLibraryFromList( EDA_DRAW_FRAME* 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
int DisplayComponentsNamesInLib( EDA_DRAW_FRAME* 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
|
|
|
wxArrayString nameList;
|
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
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
WinEDAListBox dlg( frame, _( "Select Component" ), nameList, OldName, DisplayCmpDoc );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2009-12-15 21:11:05 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
Buffer = dlg.GetTextSelection();
|
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
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
int GetNameOfPartToLoad( EDA_DRAW_FRAME* frame, CMP_LIBRARY* Library, 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
|
|
|
}
|