KiCad PCB EDA Suite
footprint_tree_pane.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * https://www.gnu.org/licenses/gpl-3.0.html
19  * or you may search the http://www.gnu.org website for the version 3 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #include "footprint_tree_pane.h"
26 #include <widgets/lib_tree.h>
27 #include <pcbnew_id.h>
28 #include <footprint_edit_frame.h>
29 #include <fp_lib_table.h>
30 
32  : wxPanel( aParent ),
33  m_frame( aParent ),
34  m_tree( nullptr )
35 {
36  // Create widgets
37  wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
39  boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
40 
41  SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
42  Layout();
43  boxSizer->Fit( this );
44 
45  // Event handlers
46  Bind( COMPONENT_SELECTED, &FOOTPRINT_TREE_PANE::onComponentSelected, this );
47  m_tree->Bind( wxEVT_UPDATE_UI, &FOOTPRINT_TREE_PANE::onUpdateUI, this );
48 }
49 
50 
52 {
53  m_tree->Destroy();
54 }
55 
56 
58 {
59  if( m_tree )
60  m_tree->Regenerate( true );
61 }
62 
63 
64 void FOOTPRINT_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
65 {
66  m_frame->LoadModuleFromLibrary( GetLibTree()->GetSelectedLibId() );
67  // Make sure current-part highlighting doesn't get lost in seleciton highlighting
68  m_tree->Unselect();
69 }
70 
71 
72 void FOOTPRINT_TREE_PANE::onUpdateUI( wxUpdateUIEvent& aEvent )
73 {
74  if( m_frame->GetCanvas()->HasFocus() )
75  {
76  // Don't allow a selected item in the tree when the canvas has focus: it's too easy
77  // to confuse the selected-highlighting with the being-edited-on-canvas-highlighting.
78  m_tree->Unselect();
79  }
80 }
LIB_TREE_MODEL_ADAPTER::PTR & GetLibTreeAdapter()
Returns the adapter object that provides the stored data.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void LoadModuleFromLibrary(LIB_ID aFPID)
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:311
FOOTPRINT_EDIT_FRAME * m_frame
void Regenerate()
Updates the footprint tree
void onComponentSelected(wxCommandEvent &aEvent)
void Regenerate(bool aKeepState)
Regenerates the tree.
Definition: lib_tree.cpp:186
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:175
LIB_TREE * GetLibTree() const
LIB_TREE * m_tree
component search tree widget
void onUpdateUI(wxUpdateUIEvent &aEvent)
FOOTPRINT_TREE_PANE(FOOTPRINT_EDIT_FRAME *aParent)
Widget displaying a tree of components with optional search text control and description panel.
Definition: lib_tree.h:42