2017-11-12 17:55:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 3
|
|
|
|
* 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:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cmp_tree_pane.h"
|
|
|
|
|
|
|
|
#include <component_tree.h>
|
|
|
|
#include <eeschema_id.h>
|
|
|
|
#include <lib_manager.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2018-01-07 12:18:18 +00:00
|
|
|
#include <menus_helpers.h>
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr )
|
|
|
|
: wxPanel( aParent ),
|
2017-11-30 11:31:36 +00:00
|
|
|
m_libEditFrame( aParent ), m_tree( nullptr ), m_libMgr( aLibMgr )
|
2017-11-12 17:55:20 +00:00
|
|
|
{
|
|
|
|
// Create widgets
|
|
|
|
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(),
|
|
|
|
m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH );
|
|
|
|
boxSizer->Add( m_tree, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
2017-11-30 11:31:36 +00:00
|
|
|
SetSizer( boxSizer ); // should remove the previous sizer according to wxWidgets docs
|
2017-11-12 17:55:20 +00:00
|
|
|
Layout();
|
|
|
|
boxSizer->Fit( this );
|
|
|
|
|
|
|
|
// Setup right click-context menus
|
|
|
|
std::unique_ptr<wxMenu> menuLibrary = std::make_unique<wxMenu>();
|
2018-01-07 12:18:18 +00:00
|
|
|
|
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_NEW_LIBRARY, _( "&New Library..." ),
|
|
|
|
KiBitmap( new_library_xpm ) );
|
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_ADD_LIBRARY, _( "&Add Library..." ),
|
|
|
|
KiBitmap( add_library_xpm ) );
|
2018-01-07 15:31:15 +00:00
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_SAVE_LIBRARY, _( "&Save Library" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( save_library_xpm ) );
|
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_SAVE_LIBRARY_AS, _( "Save Library As..." ),
|
|
|
|
KiBitmap( save_library_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_REVERT_LIBRARY, _( "Revert Library" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( undo_xpm ) );
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
menuLibrary->AppendSeparator();
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_NEW_PART, _( "New Sy&mbol..." ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( new_component_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_IMPORT_PART, _( "&Import Symbol..." ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( import_part_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuLibrary.get(), ID_LIBEDIT_PASTE_PART, _( "Paste Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( paste_xpm ) );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
std::unique_ptr<wxMenu> menuPart = std::make_unique<wxMenu>();
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_EDIT_PART, _( "&Edit Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( edit_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_REMOVE_PART, _( "Remove Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( delete_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_EXPORT_PART, _( "E&xport Symbol..." ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( export_part_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_SAVE_PART, _( "&Save Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( save_part_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_REVERT_PART, _( "Revert Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( undo_xpm ) );
|
|
|
|
|
2017-11-12 17:55:20 +00:00
|
|
|
menuPart->AppendSeparator();
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_CUT_PART, _( "Cut Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( cut_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_COPY_PART, _( "Copy Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( copy_xpm ) );
|
2018-01-18 10:23:59 +00:00
|
|
|
AddMenuItem( menuPart.get(), ID_LIBEDIT_DUPLICATE_PART, _( "Duplicate Symbol" ),
|
2018-01-07 12:18:18 +00:00
|
|
|
KiBitmap( duplicate_xpm ) );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
2017-11-20 20:03:54 +00:00
|
|
|
// Menu displayed when nothing is selected
|
2017-11-12 17:55:20 +00:00
|
|
|
std::unique_ptr<wxMenu> menuNoSelection = std::make_unique<wxMenu>();
|
2018-01-07 12:18:18 +00:00
|
|
|
AddMenuItem( menuNoSelection.get(), ID_LIBEDIT_NEW_LIBRARY, _( "&New Library..." ),
|
|
|
|
KiBitmap( new_library_xpm ) );
|
|
|
|
AddMenuItem( menuNoSelection.get(), ID_LIBEDIT_ADD_LIBRARY, _( "&Add Library..." ),
|
|
|
|
KiBitmap( add_library_xpm ) );
|
2017-11-12 17:55:20 +00:00
|
|
|
|
|
|
|
m_tree->SetMenu( CMP_TREE_NODE::LIBID, std::move( menuPart ) );
|
|
|
|
m_tree->SetMenu( CMP_TREE_NODE::LIB, std::move( menuLibrary ) );
|
|
|
|
m_tree->SetMenu( CMP_TREE_NODE::INVALID, std::move( menuNoSelection ) );
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
Bind( COMPONENT_SELECTED, &CMP_TREE_PANE::onComponentSelected, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CMP_TREE_PANE::~CMP_TREE_PANE()
|
|
|
|
{
|
2017-11-30 11:31:36 +00:00
|
|
|
m_tree->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMP_TREE_PANE::Regenerate()
|
|
|
|
{
|
|
|
|
if( m_tree )
|
|
|
|
m_tree->Regenerate();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CMP_TREE_PANE::onComponentSelected( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
// Repost the event
|
|
|
|
wxCommandEvent evt( ID_LIBEDIT_EDIT_PART );
|
|
|
|
// I cannot figure out why the two methods below do not work..
|
|
|
|
//wxPostEvent( libEditFrame, evt );
|
|
|
|
//wxQueueEvent( m_libEditFrame, new wxCommandEvent( ID_LIBEDIT_EDIT_PART ) );
|
|
|
|
m_libEditFrame->OnEditPart( evt );
|
2018-01-20 17:15:46 +00:00
|
|
|
|
|
|
|
// Make sure current-part highlighting doesn't get lost in seleciton highlighting
|
|
|
|
m_tree->Unselect();
|
2017-11-12 17:55:20 +00:00
|
|
|
}
|