KiCad PCB EDA Suite
component_tree.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
5  * Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef COMPONENT_TREE_H
26 #define COMPONENT_TREE_H
27 
28 #include <wx/panel.h>
29 #include <cmp_tree_model_adapter.h>
30 
31 class wxDataViewCtrl;
32 class wxTextCtrl;
33 class wxHtmlWindow;
34 class wxHtmlLinkEvent;
35 class LIB_ID;
36 class SYMBOL_LIB_TABLE;
37 
38 
42 class COMPONENT_TREE : public wxPanel
43 {
44 public:
46  enum WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF };
47 
58  COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTable,
59  CMP_TREE_MODEL_ADAPTER_BASE::PTR& aAdapter, WIDGETS aWidgets = ALL,
60  wxHtmlWindow *aDetails = nullptr );
61 
71  LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
72 
78  void SelectLibId( const LIB_ID& aLibId );
79 
83  void Unselect();
84 
90  void SetMenu( CMP_TREE_NODE::TYPE aType, std::unique_ptr<wxMenu> aMenu )
91  {
92  m_menus[aType] = std::move( aMenu );
93  }
94 
99  bool IsMenuActive() const
100  {
101  return m_menuActive;
102  }
103 
107  void Regenerate();
108 
109 protected:
113  void toggleExpand( const wxDataViewItem& aTreeId );
114 
118  void selectIfValid( const wxDataViewItem& aTreeId );
119 
124  void postPreselectEvent();
125 
129  void postSelectEvent();
130 
134  struct STATE
135  {
137  std::vector<wxDataViewItem> expanded;
138 
141  };
142 
146  STATE getState() const;
147 
151  void setState( const STATE& aState );
152 
153  void onQueryText( wxCommandEvent& aEvent );
154  void onQueryEnter( wxCommandEvent& aEvent );
155  void onQueryCharHook( wxKeyEvent& aEvent );
156 
157  void onTreeSelect( wxDataViewEvent& aEvent );
158  void onTreeActivate( wxDataViewEvent& aEvent );
159 
160  void onDetailsLink( wxHtmlLinkEvent& aEvent );
161  void onPreselect( wxCommandEvent& aEvent );
162  void onContextMenu( wxDataViewEvent& aEvent );
163 
166 
167  wxTextCtrl* m_query_ctrl;
168  wxDataViewCtrl* m_tree_ctrl;
169  wxHtmlWindow* m_details_ctrl;
170 
172  std::vector<std::unique_ptr<wxMenu>> m_menus;
173 
176 
179 
182 };
183 
185 wxDECLARE_EVENT( COMPONENT_PRESELECTED, wxCommandEvent );
186 
188 wxDECLARE_EVENT( COMPONENT_SELECTED, wxCommandEvent );
189 
190 #endif /* COMPONENT_TREE_H */
void onQueryCharHook(wxKeyEvent &aEvent)
std::vector< std::unique_ptr< wxMenu > > m_menus
Right click context menus for each tree level
void Regenerate()
Regenerates the tree.
void onPreselect(wxCommandEvent &aEvent)
STATE getState() const
Returns the component tree widget state.
void onTreeActivate(wxDataViewEvent &aEvent)
wxHtmlWindow * m_details_ctrl
SYMBOL_LIB_TABLE * m_sym_lib_table
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
std::vector< wxDataViewItem > expanded
List of expanded nodes
bool m_filtering
Flag indicating whether the results are filtered using the search query
bool m_menuActive
Flag indicating whether a right-click context menu is active
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
void setState(const STATE &aState)
Restores the component tree widget state from an object.
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
void onContextMenu(wxDataViewEvent &aEvent)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit components, if the user selects the component itself rather than picking an individual...
wxObjectDataPtr< CMP_TREE_MODEL_ADAPTER_BASE > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
bool IsMenuActive() const
Returns the status of right-click context menu.
wxDataViewCtrl * m_tree_ctrl
void onQueryText(wxCommandEvent &aEvent)
STATE m_unfilteredState
State of the widget before any filters applied
Widget displaying a tree of components with optional search text control and description panel...
LIB_ID selection
Current selection, might be not valid if nothing was selected
void SelectLibId(const LIB_ID &aLibId)
Select a part in the tree widget.
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
WIDGETS
Flags to select extra widgets
COMPONENT_TREE(wxWindow *aParent, SYMBOL_LIB_TABLE *aSymLibTable, CMP_TREE_MODEL_ADAPTER_BASE::PTR &aAdapter, WIDGETS aWidgets=ALL, wxHtmlWindow *aDetails=nullptr)
Construct a component tree.
void onQueryEnter(wxCommandEvent &aEvent)
void SetMenu(CMP_TREE_NODE::TYPE aType, std::unique_ptr< wxMenu > aMenu)
Associates a right click context menu for a specific node type.
CMP_TREE_MODEL_ADAPTER_BASE::PTR m_adapter
void onDetailsLink(wxHtmlLinkEvent &aEvent)
wxDECLARE_EVENT(COMPONENT_PRESELECTED, wxCommandEvent)
Custom event sent when a new component is preselected
Structure storing state of the component tree widget.
void toggleExpand(const wxDataViewItem &aTreeId)
Expands or collapses a node, switching it to the opposite state.
void onTreeSelect(wxDataViewEvent &aEvent)
void postSelectEvent()
Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected...
wxTextCtrl * m_query_ctrl