2017-04-10 14:22:41 +00:00
|
|
|
/* -*- c++ -*-
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2018-01-03 02:52:35 +00:00
|
|
|
* Copyright (C) 2014-2018 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-04-10 14:22:41 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMPONENT_TREE_H
|
|
|
|
#define COMPONENT_TREE_H
|
|
|
|
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <cmp_tree_model_adapter.h>
|
|
|
|
|
|
|
|
class wxDataViewCtrl;
|
|
|
|
class wxTextCtrl;
|
|
|
|
class wxHtmlWindow;
|
|
|
|
class wxHtmlLinkEvent;
|
2017-09-15 14:17:44 +00:00
|
|
|
class LIB_ID;
|
|
|
|
class SYMBOL_LIB_TABLE;
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
/**
|
2017-04-10 14:43:25 +00:00
|
|
|
* Widget displaying a tree of components with optional search text control and description panel.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
|
|
|
class COMPONENT_TREE : public wxPanel
|
|
|
|
{
|
|
|
|
public:
|
2017-04-10 14:43:25 +00:00
|
|
|
///> Flags to select extra widgets
|
|
|
|
enum WIDGETS { NONE = 0x00, SEARCH = 0x01, DETAILS = 0x02, ALL = 0xFF };
|
|
|
|
|
2018-01-03 02:52:35 +00:00
|
|
|
/**
|
|
|
|
* Construct a component tree.
|
|
|
|
*
|
|
|
|
* @param aParent parent window containing this tree widget
|
|
|
|
* @param aSymLibTable table containing symbols to display
|
|
|
|
* @param aAdapter a CMP_TREE_MODEL_ADAPTER instance to use
|
|
|
|
* @param aWidgets selection of sub-widgets to include
|
|
|
|
* @param aDetails if not null, a custom wxHtmlWindow to hold symbol details. If null this will
|
|
|
|
* be created inside the COMPONENT_TREE.
|
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
COMPONENT_TREE( wxWindow* aParent, SYMBOL_LIB_TABLE* aSymLibTable,
|
2018-01-03 02:52:35 +00:00
|
|
|
CMP_TREE_MODEL_ADAPTER_BASE::PTR& aAdapter, WIDGETS aWidgets = ALL,
|
|
|
|
wxHtmlWindow *aDetails = nullptr );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For multi-unit components, if the user selects the component itself
|
|
|
|
* rather than picking an individual unit, 0 will be returned in aUnit.
|
|
|
|
* Beware that this is an invalid unit number - this should be replaced
|
|
|
|
* with whatever default is desired (usually 1).
|
|
|
|
*
|
|
|
|
* @param aUnit if not NULL, the selected unit is filled in here.
|
2017-09-15 14:17:44 +00:00
|
|
|
* @return the library id of the symbol that has been selected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID GetSelectedLibId( int* aUnit = nullptr ) const;
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-11-14 11:03:19 +00:00
|
|
|
/**
|
|
|
|
* Select a part in the tree widget.
|
|
|
|
*
|
|
|
|
* @param aLibId is the identifier of part to be selected.
|
|
|
|
*/
|
|
|
|
void SelectLibId( const LIB_ID& aLibId );
|
|
|
|
|
2018-01-09 12:48:00 +00:00
|
|
|
/**
|
|
|
|
* Unselect currently selected item in wxDataViewCtrl
|
|
|
|
*/
|
|
|
|
void Unselect();
|
|
|
|
|
2017-10-28 16:59:49 +00:00
|
|
|
/**
|
|
|
|
* Associates a right click context menu for a specific node type.
|
|
|
|
* @param aType is the node type to have a menu associated.
|
|
|
|
* @param aMenu is the associated menu.
|
|
|
|
*/
|
|
|
|
void SetMenu( CMP_TREE_NODE::TYPE aType, std::unique_ptr<wxMenu> aMenu )
|
|
|
|
{
|
|
|
|
m_menus[aType] = std::move( aMenu );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the status of right-click context menu.
|
|
|
|
* @return True in case a right-click context menu is active.
|
|
|
|
*/
|
|
|
|
bool IsMenuActive() const
|
|
|
|
{
|
|
|
|
return m_menuActive;
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
/**
|
|
|
|
* Regenerates the tree.
|
|
|
|
*/
|
|
|
|
void Regenerate();
|
|
|
|
|
2018-06-08 23:50:06 +00:00
|
|
|
void SetFocus() override;
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
protected:
|
2017-12-20 11:25:12 +00:00
|
|
|
/**
|
|
|
|
* Expands or collapses a node, switching it to the opposite state.
|
|
|
|
*/
|
|
|
|
void toggleExpand( const wxDataViewItem& aTreeId );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
/**
|
|
|
|
* If a wxDataViewitem is valid, select it and post a selection event.
|
|
|
|
*/
|
|
|
|
void selectIfValid( const wxDataViewItem& aTreeId );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post a wxEVT_DATAVIEW_SELECTION_CHANGED to notify the selection handler
|
2017-06-25 21:13:39 +00:00
|
|
|
* that a new part has been preselected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-06-25 21:13:39 +00:00
|
|
|
void postPreselectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
|
|
|
/**
|
2017-06-25 21:13:39 +00:00
|
|
|
* Post COMPONENT_SELECTED event to notify the selection handler that a part has been selected.
|
2017-04-10 14:22:41 +00:00
|
|
|
*/
|
2017-06-25 21:13:39 +00:00
|
|
|
void postSelectEvent();
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
/**
|
|
|
|
* Structure storing state of the component tree widget.
|
|
|
|
*/
|
|
|
|
struct STATE
|
|
|
|
{
|
|
|
|
///> List of expanded nodes
|
|
|
|
std::vector<wxDataViewItem> expanded;
|
|
|
|
|
|
|
|
///> Current selection, might be not valid if nothing was selected
|
2017-12-11 10:22:24 +00:00
|
|
|
LIB_ID selection;
|
2017-11-30 11:31:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the component tree widget state.
|
|
|
|
*/
|
|
|
|
STATE getState() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the component tree widget state from an object.
|
|
|
|
*/
|
|
|
|
void setState( const STATE& aState );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
void onQueryText( wxCommandEvent& aEvent );
|
|
|
|
void onQueryEnter( wxCommandEvent& aEvent );
|
|
|
|
void onQueryCharHook( wxKeyEvent& aEvent );
|
|
|
|
|
|
|
|
void onTreeSelect( wxDataViewEvent& aEvent );
|
|
|
|
void onTreeActivate( wxDataViewEvent& aEvent );
|
|
|
|
|
|
|
|
void onDetailsLink( wxHtmlLinkEvent& aEvent );
|
2017-06-25 21:13:39 +00:00
|
|
|
void onPreselect( wxCommandEvent& aEvent );
|
2017-10-28 16:59:49 +00:00
|
|
|
void onContextMenu( wxDataViewEvent& aEvent );
|
2017-04-10 14:22:41 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
SYMBOL_LIB_TABLE* m_sym_lib_table;
|
2017-11-21 13:54:30 +00:00
|
|
|
CMP_TREE_MODEL_ADAPTER_BASE::PTR m_adapter;
|
2017-10-28 16:59:49 +00:00
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
wxTextCtrl* m_query_ctrl;
|
|
|
|
wxDataViewCtrl* m_tree_ctrl;
|
|
|
|
wxHtmlWindow* m_details_ctrl;
|
2017-10-28 16:59:49 +00:00
|
|
|
|
|
|
|
///> Right click context menus for each tree level
|
|
|
|
std::vector<std::unique_ptr<wxMenu>> m_menus;
|
|
|
|
|
|
|
|
///> Flag indicating whether a right-click context menu is active
|
|
|
|
bool m_menuActive;
|
2017-11-21 13:54:30 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
///> Flag indicating whether the results are filtered using the search query
|
2017-11-21 13:54:30 +00:00
|
|
|
bool m_filtering;
|
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
///> State of the widget before any filters applied
|
|
|
|
STATE m_unfilteredState;
|
2017-04-10 14:22:41 +00:00
|
|
|
};
|
|
|
|
|
2017-06-25 21:13:39 +00:00
|
|
|
///> Custom event sent when a new component is preselected
|
|
|
|
wxDECLARE_EVENT( COMPONENT_PRESELECTED, wxCommandEvent );
|
|
|
|
|
|
|
|
///> Custom event sent when a component is selected
|
|
|
|
wxDECLARE_EVENT( COMPONENT_SELECTED, wxCommandEvent );
|
|
|
|
|
2017-04-10 14:22:41 +00:00
|
|
|
#endif /* COMPONENT_TREE_H */
|