KiCad PCB EDA Suite
lib_tree.h
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) 2014 Henner Zeller <[email protected]>
5  * Copyright (C) 2014-2021 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 LIB_TREE_H
26 #define LIB_TREE_H
27 
28 #include <wx/panel.h>
29 #include <lib_tree_model_adapter.h>
30 #include <html_window.h>
31 
32 class wxDataViewCtrl;
33 class wxTextCtrl;
34 class wxHtmlLinkEvent;
35 class wxSearchCtrl;
36 class wxTimer;
37 class wxTimerEvent;
38 class ACTION_MENU;
39 class LIB_ID;
40 class LIB_TABLE;
41 
45 class LIB_TREE : public wxPanel
46 {
47 public:
49  enum WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF };
50 
61  LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable,
62  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter, WIDGETS aWidgets = ALL,
63  HTML_WINDOW* aDetails = nullptr );
64 
65  ~LIB_TREE() override;
66 
76  LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
77 
79 
83  void SelectLibId( const LIB_ID& aLibId );
84 
88  void CenterLibId( const LIB_ID& aLibId );
89 
93  void Unselect();
94 
98  void ExpandLibId( const LIB_ID& aLibId );
99 
103  void Regenerate( bool aKeepState );
104 
108  void RefreshLibTree();
109 
110  wxWindow* GetFocusTarget();
111 
112 protected:
116  void toggleExpand( const wxDataViewItem& aTreeId );
117 
121  void selectIfValid( const wxDataViewItem& aTreeId );
122 
123  void centerIfValid( const wxDataViewItem& aTreeId );
124 
125  void expandIfValid( const wxDataViewItem& aTreeId );
126 
131  void postPreselectEvent();
132 
136  void postSelectEvent();
137 
141  struct STATE
142  {
144  std::vector<wxDataViewItem> expanded;
145  std::vector<wxString> pinned;
146 
149  };
150 
154  STATE getState() const;
155 
159  void setState( const STATE& aState );
160 
161  void onQueryText( wxCommandEvent& aEvent );
162  void onQueryEnter( wxCommandEvent& aEvent );
163  void onQueryCharHook( wxKeyEvent& aEvent );
164 
165  void onTreeSelect( wxDataViewEvent& aEvent );
166  void onTreeActivate( wxDataViewEvent& aEvent );
167 
168  void onDetailsLink( wxHtmlLinkEvent& aEvent );
169  void onPreselect( wxCommandEvent& aEvent );
170  void onContextMenu( wxDataViewEvent& aEvent );
171 
172  void onDebounceTimer( wxTimerEvent& aEvent );
173 
174 protected:
176 
177  wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
178 
179  wxSearchCtrl* m_query_ctrl;
180  wxDataViewCtrl* m_tree_ctrl;
182  wxTimer* m_debounceTimer;
183 
185 };
186 
188 wxDECLARE_EVENT( SYMBOL_PRESELECTED, wxCommandEvent );
189 
191 wxDECLARE_EVENT( SYMBOL_SELECTED, wxCommandEvent );
192 
193 #endif /* LIB_TREE_H */
void selectIfValid(const wxDataViewItem &aTreeId)
If a wxDataViewitem is valid, select it and post a selection event.
Definition: lib_tree.cpp:258
LIB_ID m_last_libid
Definition: lib_tree.h:184
wxSearchCtrl * m_query_ctrl
Definition: lib_tree.h:179
void toggleExpand(const wxDataViewItem &aTreeId)
Expand or collapse a node, switching it to the opposite state.
Definition: lib_tree.cpp:246
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
STATE getState() const
Return the symbol tree widget state.
Definition: lib_tree.cpp:338
void onQueryEnter(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:382
wxWindow * GetFocusTarget()
Definition: lib_tree.cpp:237
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
Definition: lib_tree.h:177
void centerIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:269
void postSelectEvent()
Post SYMBOL_SELECTED event to notify the selection handler that a part has been selected.
Definition: lib_tree.cpp:331
wxDataViewCtrl * m_tree_ctrl
Definition: lib_tree.h:180
LIB_ID selection
Definition: lib_tree.h:148
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
LIB_TREE(wxWindow *aParent, LIB_TABLE *aLibTable, wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > &aAdapter, WIDGETS aWidgets=ALL, HTML_WINDOW *aDetails=nullptr)
Construct a symbol tree.
Definition: lib_tree.cpp:38
~LIB_TREE() override
Definition: lib_tree.cpp:153
void onPreselect(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:466
LIB_TABLE * m_lib_table
Definition: lib_tree.h:175
std::vector< wxString > pinned
Current selection, might be not valid if nothing was selected.
Definition: lib_tree.h:145
void onQueryCharHook(wxKeyEvent &aEvent)
Definition: lib_tree.cpp:395
HTML_WINDOW * m_details_ctrl
Definition: lib_tree.h:181
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:179
void onTreeActivate(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:445
void onQueryText(wxCommandEvent &aEvent)
Definition: lib_tree.cpp:372
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:165
void Regenerate(bool aKeepState)
Regenerate the tree.
Definition: lib_tree.cpp:213
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:202
void onTreeSelect(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:438
wxTimer * m_debounceTimer
Definition: lib_tree.h:182
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void onDetailsLink(wxHtmlLinkEvent &aEvent)
Definition: lib_tree.cpp:459
void RefreshLibTree()
Refreshes the tree (mainly to update highlighting and asterisking)
Definition: lib_tree.cpp:231
void onDebounceTimer(wxTimerEvent &aEvent)
Definition: lib_tree.cpp:389
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:33
void ExpandLibId(const LIB_ID &aLibId)
Expand and item i the tree widget.
Definition: lib_tree.cpp:207
WIDGETS
< Flags to select extra widgets
Definition: lib_tree.h:49
void expandIfValid(const wxDataViewItem &aTreeId)
Definition: lib_tree.cpp:317
std::vector< wxDataViewItem > expanded
< List of expanded nodes
Definition: lib_tree.h:144
Structure storing state of the symbol tree widget.
Definition: lib_tree.h:141
wxDECLARE_EVENT(SYMBOL_PRESELECTED, wxCommandEvent)
Custom event sent when a symbol is selected.
void postPreselectEvent()
Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler that a new part has been pres...
Definition: lib_tree.cpp:324
void setState(const STATE &aState)
Restore the symbol tree widget state from an object.
Definition: lib_tree.cpp:356
void CenterLibId(const LIB_ID &aLibId)
Ensure that an item is visible (preferably centered).
Definition: lib_tree.cpp:196
Widget displaying a tree of symbols with optional search text control and description panel....
Definition: lib_tree.h:45
void SelectLibId(const LIB_ID &aLibId)
Select an item in the tree widget.
Definition: lib_tree.cpp:190
void onContextMenu(wxDataViewEvent &aEvent)
Definition: lib_tree.cpp:483
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.