2013-05-08 20:47:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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"
|
2013-05-02 18:06:58 +00:00
|
|
|
#include <macros.h>
|
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 );
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2012-09-22 11:19:37 +00:00
|
|
|
// 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
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2013-03-19 01:25:19 +00:00
|
|
|
* Displays a list of filtered components found in libraries for selection,
|
2012-09-22 11:19:37 +00:00
|
|
|
* 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
|
|
|
*
|
2013-03-19 01:25:19 +00:00
|
|
|
* Returns the name of the selected component, or an empty 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
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> nameList;
|
2009-08-27 11:41:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
if( nameList.empty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !BufName.IsEmpty() )
|
2009-02-04 15:25:03 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !Keys.IsEmpty() )
|
2013-04-09 17:49:01 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "No components found matching name search criteria '%s' and key search criteria '%s'" ),
|
|
|
|
GetChars( BufName ), GetChars( Keys ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "No components found matching name search criteria '%s'" ),
|
|
|
|
GetChars( BufName ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !Keys.IsEmpty() )
|
2013-04-09 17:49:01 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "No components found matching key search criteria '%s'" ),
|
|
|
|
GetChars( Keys ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = _( "No components found matching" );
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2013-05-08 20:47:23 +00:00
|
|
|
headers.Add( _( "Component" ) );
|
|
|
|
headers.Add( _( "Library" ) );
|
|
|
|
|
2010-11-18 21:16:28 +00:00
|
|
|
// Show candidate list:
|
|
|
|
wxString cmpname;
|
2013-03-19 01:25:19 +00:00
|
|
|
EDA_LIST_DIALOG dlg( frame, _( "Select Component" ), headers, nameList, cmpname,
|
|
|
|
DisplayCmpDocAndKeywords, true );
|
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
|
|
|
}
|