2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file database.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "eda_doc.h"
|
|
|
|
#include "kicad_string.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 "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
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
extern void DisplayCmpDocAndKeywords( wxString& Name );
|
|
|
|
|
|
|
|
// Used in DataBaseGetName: this is a callback function for EDA_LIST_DIALOG
|
|
|
|
// to display keywords and description of a component
|
|
|
|
void DisplayCmpDocAndKeywords( wxString& Name )
|
|
|
|
{
|
|
|
|
LIB_ALIAS* CmpEntry = NULL;
|
|
|
|
|
|
|
|
CmpEntry = CMP_LIBRARY::FindLibraryEntry( Name );
|
|
|
|
|
|
|
|
if( CmpEntry == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Name = wxT( "Description: " ) + CmpEntry->GetDescription();
|
|
|
|
Name += wxT( "\nKey Words: " ) + CmpEntry->GetKeyWords();
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-09-22 11:19:37 +00:00
|
|
|
* Displays a list of filterd components found in libraries for selection,
|
|
|
|
* Keys is a list of keywords to filter components which do not match these keywords
|
|
|
|
* If Keys is empty, list components that match BufName mask (with * and?)
|
2009-02-04 15:25:03 +00:00
|
|
|
*
|
2012-09-22 11:19:37 +00:00
|
|
|
* Returns the name of the selected component, or an ampty string
|
2009-02-04 15:25:03 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
wxString DataBaseGetName( EDA_DRAW_FRAME* frame, wxString& Keys, wxString& BufName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
wxArrayString nameList;
|
|
|
|
wxString msg;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2010-10-22 15:02:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
2009-02-04 15:25:03 +00:00
|
|
|
BufName.MakeUpper();
|
2010-10-22 15:02:11 +00:00
|
|
|
#endif
|
2009-02-04 15:25:03 +00:00
|
|
|
Keys.MakeUpper();
|
|
|
|
|
2009-11-03 13:26:31 +00:00
|
|
|
/* Review the list of libraries for counting. */
|
2009-09-18 14:56:05 +00:00
|
|
|
BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
lib.SearchEntryNames( nameList, BufName, Keys );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( nameList.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
msg = _( "No components found matching " );
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( !BufName.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2009-08-27 11:41:56 +00:00
|
|
|
msg += _( "name search criteria <" ) + BufName + wxT( "> " );
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( !Keys.IsEmpty() )
|
2009-08-27 11:41:56 +00:00
|
|
|
msg += _( "and " );
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( !Keys.IsEmpty() )
|
|
|
|
msg += _( "key search criteria <" ) + Keys + wxT( "> " );
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
DisplayInfoMessage( frame, msg );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
return wxEmptyString;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 21:16:28 +00:00
|
|
|
// Show candidate list:
|
|
|
|
wxString cmpname;
|
2012-09-22 11:19:37 +00:00
|
|
|
EDA_LIST_DIALOG dlg( frame, _( "Select Component" ), nameList, cmpname,
|
|
|
|
DisplayCmpDocAndKeywords );
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2009-08-27 11:41:56 +00:00
|
|
|
return wxEmptyString;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
cmpname = dlg.GetTextSelection();
|
2010-11-18 21:16:28 +00:00
|
|
|
return cmpname;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|