2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file database.cpp
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "macros.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 "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
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2009-11-03 13:26:31 +00:00
|
|
|
* Routine name selection of a component library for loading,
|
|
|
|
* Keys leading the list of the keywords filter
|
|
|
|
* If Keys = "", research components that correspond
|
|
|
|
* BufName mask (with * and?)
|
2009-02-04 15:25:03 +00:00
|
|
|
*
|
2009-11-03 13:26:31 +00:00
|
|
|
* Returns
|
2011-10-07 14:41:30 +00:00
|
|
|
* true if the selected component
|
2009-11-03 13:26:31 +00:00
|
|
|
* FALSE canceled order
|
|
|
|
* Place the name of the component has loaded, select from a list in
|
|
|
|
* BufName
|
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
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
DisplayError( frame, msg );
|
|
|
|
|
|
|
|
return wxEmptyString;
|
2009-02-04 15:25:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-18 21:16:28 +00:00
|
|
|
// Show candidate list:
|
|
|
|
wxString cmpname;
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG dlg( frame, _( "Select Component" ), nameList, cmpname, DisplayCmpDoc );
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
void DisplayCmpDoc( wxString& Name )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* CmpEntry = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
CmpEntry = CMP_LIBRARY::FindLibraryEntry( Name );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
if( CmpEntry == NULL )
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
wxLogDebug( wxT( "Selected component <%s>, m_Doc: <%s>, m_KeyWord: <%s>." ),
|
2009-12-15 21:11:05 +00:00
|
|
|
GetChars( Name ), GetChars( CmpEntry->GetDescription() ),
|
|
|
|
GetChars( CmpEntry->GetKeyWords() ) );
|
2009-09-02 18:12:45 +00:00
|
|
|
|
2009-12-15 21:11:05 +00:00
|
|
|
Name = wxT( "Description: " ) + CmpEntry->GetDescription();
|
|
|
|
Name += wxT( "\nKey Words: " ) + CmpEntry->GetKeyWords();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|