2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file selpart.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
|
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#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
|
|
|
wxArrayString libNamesList;
|
|
|
|
CMP_LIBRARY* Lib = NULL;
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
int count = CMP_LIBRARY::GetLibraryCount();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
|
|
|
headers.Add( wxT("Library") );
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
libNamesList = CMP_LIBRARY::GetLibraryNames();
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
|
|
|
|
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < libNamesList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( libNamesList[i] );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
EDA_LIST_DIALOG dlg( frame, _( "Select Library" ), headers, itemsToDisplay, OldLibName );
|
2009-08-23 14:21:41 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return NULL;
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
wxString libname = dlg.GetTextSelection();
|
2009-06-04 10:42:59 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
if( libname.IsEmpty() )
|
2009-09-02 18:12:45 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-10-18 19:31:40 +00:00
|
|
|
Lib = CMP_LIBRARY::FindLibrary( libname );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
|
|
|
if( Lib != NULL )
|
2012-10-18 19:31:40 +00:00
|
|
|
OldLibName = libname;
|
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
|
|
|
}
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
extern void DisplayCmpDocAndKeywords( wxString& Name );
|
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
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
|
|
|
headers.Add( wxT("Component") );
|
|
|
|
headers.Add( wxT("Library") );
|
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
|
|
|
|
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < nameList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( nameList[i] );
|
|
|
|
item.Add( Library->GetLogicalName() );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
|
|
|
EDA_LIST_DIALOG dlg( frame, _( "Select Component" ), headers, itemsToDisplay,
|
|
|
|
OldName, DisplayCmpDocAndKeywords );
|
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 );
|
2013-03-19 01:25:19 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( ii <= 0 || BufName.IsEmpty() )
|
2009-08-23 14:21:41 +00:00
|
|
|
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
|
|
|
}
|