KiCad PCB EDA Suite
symbol_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) 2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 3
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  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 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 #include "symbol_tree_pane.h"
26 
27 #include <widgets/lib_tree.h>
28 #include <eeschema_id.h>
29 #include <lib_manager.h>
30 #include <lib_edit_frame.h>
31 #include <symbol_lib_table.h>
32 #include <menus_helpers.h>
33 
34 
36  : wxPanel( aParent ),
37  m_libEditFrame( aParent ), m_tree( nullptr ), m_libMgr( aLibMgr )
38 {
39  // Create widgets
40  wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
43  boxSizer->Add( m_tree, 1, wxEXPAND, 5 );
44 
45  SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
46  Layout();
47  boxSizer->Fit( this );
48 
49  // Setup right click-context menus
50  std::unique_ptr<wxMenu> menuLibrary = std::make_unique<wxMenu>();
51 
52  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_NEW_LIBRARY, _( "&New Library..." ),
53  KiBitmap( new_library_xpm ) );
54  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_ADD_LIBRARY, _( "&Add Library..." ),
55  KiBitmap( add_library_xpm ) );
56  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_SAVE, _( "&Save" ),
57  KiBitmap( save_xpm ) );
58  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_SAVE_AS, _( "Save As..." ),
59  KiBitmap( save_as_xpm ) );
60  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_REVERT, _( "Revert" ),
61  KiBitmap( undo_xpm ) );
62 
63  menuLibrary->AppendSeparator();
64  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_NEW_PART, _( "New Sy&mbol..." ),
65  KiBitmap( new_component_xpm ) );
66  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_IMPORT_PART, _( "&Import Symbol..." ),
67  KiBitmap( import_part_xpm ) );
68  AddMenuItem( menuLibrary.get(), ID_LIBEDIT_PASTE_PART, _( "Paste Symbol" ),
69  KiBitmap( paste_xpm ) );
70 
71  std::unique_ptr<wxMenu> menuPart = std::make_unique<wxMenu>();
72  AddMenuItem( menuPart.get(), ID_LIBEDIT_EDIT_PART, _( "&Edit Symbol" ),
73  KiBitmap( edit_xpm ) );
74 
75  menuPart->AppendSeparator();
76  AddMenuItem( menuPart.get(), ID_LIBEDIT_SAVE, _( "&Save" ),
77  KiBitmap( save_xpm ) );
78  AddMenuItem( menuPart.get(), ID_LIBEDIT_SAVE_AS, _( "Save a Copy As..." ),
79  KiBitmap( save_xpm ) );
80  AddMenuItem( menuPart.get(), ID_LIBEDIT_DUPLICATE_PART, _( "Duplicate" ),
81  KiBitmap( duplicate_xpm ) );
82  AddMenuItem( menuPart.get(), ID_LIBEDIT_REMOVE_PART, _( "Delete" ),
83  KiBitmap( delete_xpm ) );
84  AddMenuItem( menuPart.get(), ID_LIBEDIT_REVERT, _( "Revert" ),
85  KiBitmap( undo_xpm ) );
86 
87  menuPart->AppendSeparator();
88  AddMenuItem( menuPart.get(), ID_LIBEDIT_CUT_PART, _( "Cut" ),
89  KiBitmap( cut_xpm ) );
90  AddMenuItem( menuPart.get(), ID_LIBEDIT_COPY_PART, _( "Copy" ),
91  KiBitmap( copy_xpm ) );
92 
93  menuPart->AppendSeparator();
94  AddMenuItem( menuPart.get(), ID_LIBEDIT_EXPORT_PART, _( "E&xport Symbol..." ),
95  KiBitmap( export_part_xpm ) );
96 
97  // Menu displayed when nothing is selected
98  std::unique_ptr<wxMenu> menuNoSelection = std::make_unique<wxMenu>();
99  AddMenuItem( menuNoSelection.get(), ID_LIBEDIT_NEW_LIBRARY, _( "&New Library..." ),
100  KiBitmap( new_library_xpm ) );
101  AddMenuItem( menuNoSelection.get(), ID_LIBEDIT_ADD_LIBRARY, _( "&Add Library..." ),
102  KiBitmap( add_library_xpm ) );
103 
104  m_tree->SetMenu( LIB_TREE_NODE::LIBID, std::move( menuPart ) );
105  m_tree->SetMenu( LIB_TREE_NODE::LIB, std::move( menuLibrary ) );
106  m_tree->SetMenu( LIB_TREE_NODE::INVALID, std::move( menuNoSelection ) );
107 
108  // Event handlers
109  Bind( COMPONENT_SELECTED, &SYMBOL_TREE_PANE::onComponentSelected, this );
110 }
111 
112 
114 {
115  m_tree->Destroy();
116 }
117 
118 
120 {
121  if( m_tree )
122  m_tree->Regenerate();
123 }
124 
125 
126 void SYMBOL_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
127 {
128  wxCommandEvent evt( ID_LIBEDIT_EDIT_PART );
129  m_libEditFrame->OnEditPart( evt );
130 
131  // Make sure current-part highlighting doesn't get lost in seleciton highlighting
132  m_tree->Unselect();
133 }
static SYMBOL_LIB_TABLE & GetGlobalLibTable()
LIB_MANAGER * m_libMgr
wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmap &aImage, wxItemKind aType=wxITEM_NORMAL)
Function AddMenuItem is an inline helper function to create and insert a menu item with an icon into ...
Definition: bitmap.cpp:223
LIB_EDIT_FRAME * m_libEditFrame
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
void SetMenu(LIB_TREE_NODE::TYPE aType, std::unique_ptr< wxMenu > aMenu)
Associates a right click context menu for a specific node type.
Definition: lib_tree.h:97
void onComponentSelected(wxCommandEvent &aEvent)
LIB_TREE * m_tree
component search tree widget
void Unselect()
Unselect currently selected item in wxDataViewCtrl.
Definition: lib_tree.cpp:174
Class to handle modifications to the symbol libraries.
Definition: lib_manager.h:49
The symbol library editor main window.
void Regenerate()
Regenerates the tree.
Definition: lib_tree.cpp:185
void OnEditPart(wxCommandEvent &aEvent)
Opens the selected part for editing.
Definition: libedit.cpp:330
Definition of class LIB_EDIT_FRAME.
SYMBOL_TREE_PANE(LIB_EDIT_FRAME *aParent, LIB_MANAGER *aLibMgr)
LIB_TREE_MODEL_ADAPTER::PTR & GetAdapter()
Returns the adapter object that provides the stored data.
Definition: lib_manager.h:235
void Regenerate()
Updates the component tree
Widget displaying a tree of components with optional search text control and description panel...
Definition: lib_tree.h:42