← Back to team overview

kicad-developers team mailing list archive

Re: cvPCB search

 

Hi

   Which search dialog do you mean? I didn't know there is some mechanism
for searching for footprints thus I made mine. I improved it a little and
attached a patch (made with bzr diff). The only thing I didn't know how to
do is a new icon, thus I used library filtering one. I mean I made the SVG
one, but didn't know how to convert it to cpp.

Best regards.

On Wed, Apr 22, 2015 at 3:47 PM, Nick Østergaard <oe.nick@xxxxxxxxx> wrote:

> I was wondering... Why not use the search dialog from eeschema that Henner
> made?
> Den 22/04/2015 15.06 skrev "jp charras" <jp.charras@xxxxxxxxxx>:
>
>> Le 22/04/2015 01:43, Lukasz Iwaszkiewicz a écrit :
>> > Hi
>> >
>> >   I made simple search mechanism for finding footprints in cvPCB
>> > (accessible from menu and Ctrl-F) because I badly needed it:
>> >
>> > https://www.youtube.com/watch?v=JaATBRrfTsM
>> >
>> > Do you think it is of some use for others? Should I improve it or don't
>> > bother?
>> > Regards.
>> >
>>
>> Thanks for your interest in Kicad.
>> Send us your patch.
>> The best way to appreciate it is to try it.
>>
>>
>> --
>> Jean-Pierre CHARRAS
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>
=== modified file 'cvpcb/cvframe.cpp'
--- cvpcb/cvframe.cpp	2015-04-08 12:50:36 +0000
+++ cvpcb/cvframe.cpp	2015-04-22 23:38:14 +0000
@@ -69,6 +69,7 @@
     EVT_MENU( wxID_HELP, CVPCB_MAINFRAME::GetKicadHelp )
     EVT_MENU( wxID_ABOUT, CVPCB_MAINFRAME::GetKicadAbout )
     EVT_MENU( ID_SAVE_PROJECT, CVPCB_MAINFRAME::SaveProjectFile )
+    EVT_MENU( ID_FIND_ITEMS, CVPCB_MAINFRAME::OnMenuSearch )
     EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, CVPCB_MAINFRAME::OnConfigurePaths )
     EVT_MENU( ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE, CVPCB_MAINFRAME::OnKeepOpenOnSave )
     EVT_MENU( ID_CVPCB_EQUFILES_LIST_EDIT, CVPCB_MAINFRAME::OnEditEquFilesList )
@@ -89,6 +90,8 @@
               CVPCB_MAINFRAME::OnSelectFilteringFootprint )
     EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST,
               CVPCB_MAINFRAME::OnSelectFilteringFootprint )
+    EVT_TOOL( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME,
+              CVPCB_MAINFRAME::OnToolbarSearch )
 
     // Frame events
     EVT_CLOSE( CVPCB_MAINFRAME::OnCloseWindow )
@@ -225,6 +228,9 @@
     if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
         state |= FOOTPRINTS_LISTBOX::BY_LIBRARY;
 
+//    if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME ) )
+//        state |= FOOTPRINTS_LISTBOX::BY_NAME;
+
     aCfg->Write( wxT( FILTERFOOTPRINTKEY ), state );
 }
 
@@ -556,75 +562,120 @@
         return;
 
     wxString   libraryName;
-    COMPONENT* component = NULL;
-    int        filter = FOOTPRINTS_LISTBOX::UNFILTERED;
-
-    if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
-        filter |= FOOTPRINTS_LISTBOX::BY_COMPONENT;
-
-    if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
-        filter |= FOOTPRINTS_LISTBOX::BY_PIN_COUNT;
-
-    if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
-        filter |= FOOTPRINTS_LISTBOX::BY_LIBRARY;
-
-    component = GetSelectedComponent();
+    COMPONENT* component = GetSelectedComponent();
+    int filter = getFilterType ();
     libraryName = m_libListBox->GetSelectedLibrary();
-    m_footprintListBox->SetFootprints( m_footprints, libraryName, component, filter );
-
-    // Tell AuiMgr that objects are changed !
-    if( m_auimgr.GetManagedWindow() )   // Be sure Aui Manager is initialized
-                                        // (could be not the case when starting CvPcb
-        m_auimgr.Update();
-
-    if( component == NULL )
-        return;
-
-    // Preview of the already assigned footprint.
-    // Find the footprint that was already chosen for this component and select it,
-    // but only if the selection is made from the component list or the library list.
-    // If the selection is made from the footprint list, do not change the current
-    // selected footprint.
-    if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
-    {
-        wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
-
-        bool found = false;
-
-        for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
-        {
-            wxString footprintName;
-            wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
-            msg.Trim( true );
-            msg.Trim( false );
-            footprintName = msg.AfterFirst( wxChar( ' ' ) );
-
-            if( module.Cmp( footprintName ) == 0 )
-            {
-                m_footprintListBox->SetSelection( ii, true );
-                found = true;
-                break;
-            }
-        }
-
-        if( !found )
-        {
-            int ii = m_footprintListBox->GetSelection();
-
-            if ( ii >= 0 )
-                m_footprintListBox->SetSelection( ii, false );
-
-            if( GetFpViewerFrame() )
-            {
-                CreateScreenCmp();
-            }
-        }
-    }
-
-    SendMessageToEESCHEMA();
-    DisplayStatus();
-}
-
+    m_footprintListBox->SetFootprints( m_footprints, libraryName, component, m_currentSearch, filter);
+    RefreshAfterComponentSearch (component);
+}
+
+void CVPCB_MAINFRAME::OnToolbarSearch( wxCommandEvent& aEvent )
+{
+        if( m_skipComponentSelect )
+            return;
+
+        if(m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME ) ) {
+                SearchDialogAndStore ();
+        }
+        else {
+                m_currentSearch = "";
+        }
+
+        OnSelectFilteringFootprint (aEvent);
+}
+
+void CVPCB_MAINFRAME::OnMenuSearch( wxCommandEvent& aEvent )
+{
+        if( m_skipComponentSelect )
+            return;
+
+        SearchDialogAndStore ();
+        OnSelectFilteringFootprint (aEvent);
+}
+
+void CVPCB_MAINFRAME::SearchDialogAndStore ()
+{
+        wxTextEntryDialog myDialog (this, _ ("Find footprint"), _ ("Find"), "");
+        if (myDialog.ShowModal () == wxID_OK) {
+                m_currentSearch = myDialog.GetValue ();
+        }
+
+        m_mainToolBar->ToggleTool ( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, !m_currentSearch.empty ());
+}
+
+int CVPCB_MAINFRAME::getFilterType ()
+{
+        int filter = FOOTPRINTS_LISTBOX::UNFILTERED;
+
+        if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST ) )
+            filter |= FOOTPRINTS_LISTBOX::BY_COMPONENT;
+
+        if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST ) )
+            filter |= FOOTPRINTS_LISTBOX::BY_PIN_COUNT;
+
+        if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST ) )
+            filter |= FOOTPRINTS_LISTBOX::BY_LIBRARY;
+
+        if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME) )
+            filter |= FOOTPRINTS_LISTBOX::BY_NAME;
+
+        return filter;
+}
+
+void CVPCB_MAINFRAME::RefreshAfterComponentSearch (COMPONENT* component)
+{
+        // Tell AuiMgr that objects are changed !
+        if( m_auimgr.GetManagedWindow() )   // Be sure Aui Manager is initialized
+                                            // (could be not the case when starting CvPcb
+            m_auimgr.Update();
+
+        if( component == NULL )
+            return;
+
+        // Preview of the already assigned footprint.
+        // Find the footprint that was already chosen for this component and select it,
+        // but only if the selection is made from the component list or the library list.
+        // If the selection is made from the footprint list, do not change the current
+        // selected footprint.
+        if( FindFocus() == m_compListBox || FindFocus() == m_libListBox )
+        {
+            wxString module = FROM_UTF8( component->GetFPID().Format().c_str() );
+
+            bool found = false;
+
+            for( int ii = 0; ii < m_footprintListBox->GetCount(); ii++ )
+            {
+                wxString footprintName;
+                wxString msg = m_footprintListBox->OnGetItemText( ii, 0 );
+                msg.Trim( true );
+                msg.Trim( false );
+                footprintName = msg.AfterFirst( wxChar( ' ' ) );
+
+                if( module.Cmp( footprintName ) == 0 )
+                {
+                    m_footprintListBox->SetSelection( ii, true );
+                    found = true;
+                    break;
+                }
+            }
+
+            if( !found )
+            {
+                int ii = m_footprintListBox->GetSelection();
+
+                if ( ii >= 0 )
+                    m_footprintListBox->SetSelection( ii, false );
+
+                if( GetFpViewerFrame() )
+                {
+                    CreateScreenCmp();
+                }
+            }
+        }
+
+        SendMessageToEESCHEMA();
+        DisplayStatus();
+}
 
 void CVPCB_MAINFRAME::OnSelectFilteringFootprint( wxCommandEvent& event )
 {
@@ -710,6 +761,14 @@
             filters += _( "library" );
         }
 
+        if( m_mainToolBar->GetToolToggled( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME ) )
+        {
+            if( !filters.IsEmpty() )
+                filters += wxT( "+" );
+
+            filters += _( "name" );
+        }
+
         if( filters.IsEmpty() )
             msg = _( "No filtering" );
         else
@@ -944,7 +1003,7 @@
     }
 
     m_footprintListBox->SetFootprints( m_footprints, wxEmptyString, NULL,
-                                       FOOTPRINTS_LISTBOX::UNFILTERED );
+                    wxEmptyString, FOOTPRINTS_LISTBOX::UNFILTERED );
     DisplayStatus();
 }
 

=== modified file 'cvpcb/cvpcb_id.h'
--- cvpcb/cvpcb_id.h	2015-03-03 10:50:50 +0000
+++ cvpcb/cvpcb_id.h	2015-04-22 21:14:32 +0000
@@ -54,6 +54,7 @@
     ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST,
     ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST,
     ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST,
+    ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME,
     ID_CVPCB_CONFIG_KEEP_OPEN_ON_SAVE,
     ID_CVPCB_LIBRARY_LIST,
     ID_CVPCB_EQUFILES_LIST_EDIT,

=== modified file 'cvpcb/cvpcb_mainframe.h'
--- cvpcb/cvpcb_mainframe.h	2015-03-29 21:22:53 +0000
+++ cvpcb/cvpcb_mainframe.h	2015-04-22 23:37:44 +0000
@@ -58,6 +58,7 @@
     friend struct CV::IFACE;
 
     wxArrayString             m_footprintListEntries;
+    wxString                  m_currentSearch;
 
 public:
     bool                      m_KeepCvpcbOpen;
@@ -101,6 +102,8 @@
      * * Updates the footprint shown in footprint display window (if opened)
      */
     void             OnSelectComponent( wxListEvent& event );
+    void             OnToolbarSearch (wxCommandEvent& aEvent);
+    void             OnMenuSearch (wxCommandEvent& aEvent);
 
     /**
      * Function OnEditFootrprintLibraryTable
@@ -307,6 +310,11 @@
      */
     int buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wxString * aErrorMessages = NULL );
 
+    void RefreshAfterComponentSearch (COMPONENT* component);
+    int getFilterType ();
+    void SearchDialogAndStore ();
+
+
     DECLARE_EVENT_TABLE()
 };
 

=== modified file 'cvpcb/cvstruct.h'
--- cvpcb/cvstruct.h	2015-02-17 18:47:21 +0000
+++ cvpcb/cvstruct.h	2015-04-20 23:09:41 +0000
@@ -85,6 +85,7 @@
         BY_COMPONENT = 0x0001,
         BY_PIN_COUNT = 0x0002,
         BY_LIBRARY   = 0x0004,
+        BY_NAME      = 0x0008,
     };
 
     FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent, wxWindowID id,
@@ -108,7 +109,9 @@
      * @param aFilterType defines the criteria to filter \a aList.
      */
     void     SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
-                            COMPONENT* aComponent, int aFilterType );
+                            COMPONENT* aComponent, const wxString &footPrintName, int aFilterType );
+
+//    void searchByName (FOOTPRINT_LIST& aList, const wxString &footPrintName);
 
     wxString GetSelectedFootprint();
 

=== modified file 'cvpcb/menubar.cpp'
--- cvpcb/menubar.cpp	2015-03-29 21:22:53 +0000
+++ cvpcb/menubar.cpp	2015-04-22 21:18:32 +0000
@@ -104,6 +104,13 @@
     // Separator
     filesMenu->AppendSeparator();
 
+    AddMenuItem( filesMenu, ID_FIND_ITEMS,
+                 _( "&Find footprint\tCtrl+F" ),
+                 _( "Find footprint by its name" ),
+                 KiBitmap( info_xpm ));
+
+    filesMenu->AppendSeparator();
+
     // Quit
     AddMenuItem( filesMenu, wxID_EXIT,
                  _( "&Quit" ), _( "Quit CvPcb" ),

=== modified file 'cvpcb/tool_cvpcb.cpp'
--- cvpcb/tool_cvpcb.cpp	2015-03-03 10:50:50 +0000
+++ cvpcb/tool_cvpcb.cpp	2015-04-22 21:17:11 +0000
@@ -113,11 +113,17 @@
                             _( "Filter footprint list by library" ),
                             wxEmptyString );
 
+    m_mainToolBar->AddTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME,
+                            KiBitmap( module_library_list_xpm ),
+                            wxNullBitmap, true, NULL,
+                            _( "Filter footprint list by name" ),
+                            wxEmptyString );
     if( config )
     {
         wxString key = wxT( FILTERFOOTPRINTKEY );
         int      opt = config->Read( key, (long) 1 );
 
+        m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_NAME, opt & 8 );
         m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_BY_LIBRARY_LIST, opt & 4 );
         m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_PIN_FILTERED_LIST, opt & 2 );
         m_mainToolBar->ToggleTool( ID_CVPCB_FOOTPRINT_DISPLAY_FILTERED_LIST, opt & 1 );


Follow ups

References