void CMP_LIBRARY::SearchEntryNames( std::vector<wxArrayString>& aNames,
                                    const wxString& aNameSearch,
                                    const wxString& aKeySearch,
                                    bool aSort )
{
    LIB_ALIAS_MAP::iterator it;

    for( it = aliases.begin();  it!=aliases.end();  it++ )
    {

        if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
        {
            wxArrayString item;
            item.Add( (*it).first );
            item.Add( GetLogicalName() );
            aNames.push_back( item );
        }

        if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
                                                         (*it).second->GetName(), false ) )
        {
            wxArrayString item;
            item.Add( (*it).first );
            item.Add( GetLogicalName() );
            aNames.push_back( item );
        }
    }

    if( aSort )
        std::sort( aNames.begin(), aNames.end(), sortFunction );
}
Exemple #2
0
void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
                                    const wxString& aNameSearch,
                                    const wxString& aKeySearch,
                                    bool aSort )
{
    LIB_ALIAS_MAP::iterator it;

    for( it=aliases.begin();  it!=aliases.end();  it++ )
    {
        if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
            aNames.Add( (*it).first );

        if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
                                                         (*it).second->GetName(), false ) )
            aNames.Add( (*it).first );
    }

    if( aSort )
        aNames.Sort();
}
wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
                                          const wxString& aLibraryName,
                                          const wxString& aMask,
                                          const wxString& aKeyWord,
                                          FP_LIB_TABLE*   aTable )
{
    static wxString oldName;    // Save the name of the last module loaded.

    wxString        fpname;
    wxString        msg;
    wxArrayString   libraries;

    std::vector< wxArrayString > rows;

    wxASSERT( aTable != NULL );

    MList.ReadFootprintFiles( aTable, !aLibraryName ? NULL : &aLibraryName );

    if( MList.GetErrorCount() )
    {
        MList.DisplayErrors( this );
        return wxEmptyString;
    }

    if( MList.GetCount() == 0 )
    {
        wxString tmp;

        for( unsigned i = 0;  i < libraries.GetCount();  i++ )
        {
            tmp += libraries[i] + wxT( "\n" );
        }

        msg.Printf( _( "No footprints could be read from library file(s):\n\n%s\nin any of "
                       "the library search paths.  Verify your system is configured properly "
                       "so the footprint libraries can be found." ), GetChars( tmp ) );
        DisplayError( aWindow, msg );
        return wxEmptyString;
    }

    if( !aKeyWord.IsEmpty() )       // Create a list of modules found by keyword.
    {
        for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
        {
            if( KeyWordOk( aKeyWord, MList.GetItem( ii ).GetKeywords() ) )
            {
                wxArrayString   cols;
                cols.Add( MList.GetItem( ii ).GetFootprintName() );
                cols.Add( MList.GetItem( ii ).GetNickname() );
                rows.push_back( cols );
            }
        }
    }
    else if( !aMask.IsEmpty() )     // Create a list of modules found by pattern
    {
        for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
        {
            const wxString& candidate = MList.GetItem( ii ).GetFootprintName();

            if( WildCompareString( aMask, candidate, false ) )
            {
                wxArrayString   cols;
                cols.Add( MList.GetItem( ii ).GetFootprintName() );
                cols.Add( MList.GetItem( ii ).GetNickname() );
                rows.push_back( cols );
            }
        }
    }
    else                            // Create the full list of modules
    {
        for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
        {
            wxArrayString   cols;
            cols.Add( MList.GetItem( ii ).GetFootprintName() );
            cols.Add( MList.GetItem( ii ).GetNickname() );
            rows.push_back( cols );
        }
    }

    if( !rows.empty() )
    {
        wxArrayString headers;

        headers.Add( _( "Module" ) );
        headers.Add( _( "Library" ) );

        msg.Printf( _( "Modules [%d items]" ), (int) rows.size() );

        EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, oldName, DisplayCmpDoc );

        if( dlg.ShowModal() == wxID_OK )
        {
            fpname = dlg.GetTextSelection();

            fpname = dlg.GetTextSelection( 1 ) + wxT( ":" ) + fpname;

            SkipNextLeftButtonReleaseEvent();
        }
        else
            fpname.Empty();
    }
    else
    {
        DisplayError( aWindow, _( "No footprint found." ) );
        fpname.Empty();
    }

    if( fpname != wxEmptyString )
        oldName = fpname;

    wxLogDebug( wxT( "Footprint '%s' was selected." ), GetChars( fpname ) );

    return fpname;
}
wxString WinEDA_BasePcbFrame::Select_1_Module_From_List(
				wxWindow * active_window,
				const wxString & Library,
				const wxString & Mask, const wxString & KeyWord)
/***************************************************************/
/*
 Affiche la liste des modules des librairies
	Recherche dans la librairie Library ou generale si Library == NULL
	Mask = Filtre d'affichage( Mask = wxEmptyString pour listage non filtré )
	KeyWord = Liste de mots cles, Recherche limitee aux composants
		ayant ces mots cles ( KeyWord = wxEmptyString pour listage de tous les modules )

	retourne wxEmptyString si abort ou probleme
	ou le nom du module
*/
{
int LineNum;
unsigned ii, NbModules;
char Line[1024];
wxString FullLibName;
static wxString OldName;	/* Memorise le nom du dernier composant charge */
wxString CmpName;
FILE * lib_module;
wxString msg;
	
WinEDAListBox * ListBox = new WinEDAListBox(active_window, wxEmptyString,
			NULL, OldName, DisplayCmpDoc, wxColour(200, 200, 255) );

	wxBeginBusyCursor();

	/* Recherche des composants en librairies */
	NbModules = 0;
	for( ii = 0; ii < g_LibName_List.GetCount(); ii++)
	{
		/* Calcul du nom complet de la librairie */
		if( Library.IsEmpty() )
		{
			FullLibName = MakeFileName(g_RealLibDirBuffer,
						g_LibName_List[ii], LibExtBuffer);
		}
		else
			FullLibName = MakeFileName(g_RealLibDirBuffer,Library,LibExtBuffer);

		ReadDocLib(FullLibName );

		if( ! KeyWord.IsEmpty())	/* Inutile de lire la librairie si selection
						par mots cles, deja lus */
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		if ((lib_module = wxFopen(FullLibName, wxT("rt")))  == NULL )
		{
			if( ! Library.IsEmpty() ) break;
			continue ;
		}

		msg = _("Library: "); msg << FullLibName;
		Affiche_Message(msg);

		/* lecture entete */
		LineNum = 0;
		GetLine(lib_module, Line, &LineNum, sizeof(Line) -1);

		if(strnicmp( Line,ENTETE_LIBRAIRIE, L_ENTETE_LIB) != 0)
		{
			DisplayError(this, wxT("This file is not an Eeschema libray file"), 20); continue;
		}

		/* Lecture de la librairie */
		while( GetLine(lib_module,Line, &LineNum, sizeof(Line) -1) )
		{
			if( Line[0] != '$' ) continue;
			if( strnicmp( Line, "$MODULE",6) == 0 ) break;
			if( strnicmp( Line,"$INDEX",6) == 0 )
			{
				while( GetLine(lib_module,Line, &LineNum) )
				{
					if( strnicmp( Line,"$EndINDEX",9) == 0 ) break;
                    strupper(Line);
					msg = CONV_FROM_UTF8(StrPurge(Line));
					if ( Mask.IsEmpty() )
					{
						ListBox->Append( msg );
						NbModules++;
					}
					else if ( WildCompareString(Mask, msg, FALSE) )
					{
						ListBox->Append( msg );
						NbModules++;
					}
				}
			} /* Fin Lecture INDEX */
		}  /* Fin lecture 1 Librairie */

		fclose(lib_module) ; lib_module = NULL;
		if( ! Library.IsEmpty() ) break;
	}

	/*  creation de la liste des modules si recherche par mots-cles */
	if( ! KeyWord.IsEmpty() )
	{
		ModList * ItemMod = MList;
		while( ItemMod != NULL )
		{
			if( KeyWordOk(KeyWord, ItemMod->m_KeyWord) )
			{
				NbModules++;
				ListBox->Append( ItemMod->m_Name );
			}
			ItemMod = ItemMod->Next;
		}
	}

	wxEndBusyCursor();

	msg.Printf( _("Modules (%d items)"), NbModules);
	ListBox->SetTitle(msg);
	ListBox->SortList();
	
	ii = ListBox->ShowModal();
	if ( ii >= 0 ) CmpName = ListBox->GetTextSelection();
	else CmpName.Empty();

	ListBox->Destroy();

	/* liberation mem de la liste des textes doc module */
	while( MList != NULL )
	{
		ModList * NewMod = MList->Next;
		delete MList;
		MList = NewMod;
	}

	if( CmpName != wxEmptyString ) OldName = CmpName;

	return(CmpName);
}