2014-02-14 08:05:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Henner Zeller <h.zeller@acm.org>
|
2019-01-25 19:18:22 +00:00
|
|
|
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-02-14 08:05:04 +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
|
|
|
|
*/
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <algorithm>
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <class_library.h>
|
2020-12-08 18:30:14 +00:00
|
|
|
#include <dialog_choose_symbol.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
|
|
|
#include <kiface_i.h>
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <sch_base_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <template_fieldnames.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <widgets/footprint_preview_widget.h>
|
|
|
|
#include <widgets/footprint_select_widget.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <widgets/lib_tree.h>
|
2018-08-28 13:26:39 +00:00
|
|
|
#include <widgets/symbol_preview_widget.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <wx/button.h>
|
2019-08-06 06:18:51 +00:00
|
|
|
#include <wx/clipbrd.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <wx/dataview.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/splitter.h>
|
|
|
|
#include <wx/timer.h>
|
|
|
|
#include <wx/utils.h>
|
2019-08-26 10:57:07 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
std::mutex DIALOG_CHOOSE_SYMBOL::g_Mutex;
|
2018-04-16 22:18:02 +00:00
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
DIALOG_CHOOSE_SYMBOL::DIALOG_CHOOSE_SYMBOL( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>& aAdapter,
|
|
|
|
int aDeMorganConvert, bool aAllowFieldEdits,
|
|
|
|
bool aShowFootprints, bool aAllowBrowser )
|
2018-01-06 02:33:41 +00:00
|
|
|
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
|
2018-07-27 20:47:51 +00:00
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
|
2020-03-25 18:06:18 +00:00
|
|
|
m_symbol_preview( nullptr ),
|
2018-07-27 20:47:51 +00:00
|
|
|
m_browser_button( nullptr ),
|
2018-07-26 14:38:30 +00:00
|
|
|
m_hsplitter( nullptr ),
|
|
|
|
m_vsplitter( nullptr ),
|
2018-01-03 02:52:35 +00:00
|
|
|
m_fp_sel_ctrl( nullptr ),
|
2018-07-27 20:47:51 +00:00
|
|
|
m_fp_preview( nullptr ),
|
2020-03-25 18:06:18 +00:00
|
|
|
m_keepSymbol( nullptr ),
|
|
|
|
m_useUnits( nullptr ),
|
2019-08-06 06:18:51 +00:00
|
|
|
m_tree( nullptr ),
|
|
|
|
m_details( nullptr ),
|
2017-03-23 00:59:25 +00:00
|
|
|
m_parent( aParent ),
|
|
|
|
m_deMorganConvert( aDeMorganConvert >= 0 ? aDeMorganConvert : 0 ),
|
|
|
|
m_allow_field_edits( aAllowFieldEdits ),
|
2018-01-03 02:52:35 +00:00
|
|
|
m_show_footprints( aShowFootprints ),
|
2018-07-26 14:38:30 +00:00
|
|
|
m_external_browser_requested( false )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2020-10-25 21:27:06 +00:00
|
|
|
// Never show footprints in power symbol mode
|
|
|
|
if( aAdapter->GetFilter() == SYMBOL_TREE_MODEL_ADAPTER::CMP_FILTER_POWER )
|
|
|
|
m_show_footprints = false;
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
2017-02-24 19:27:49 +00:00
|
|
|
|
2018-01-03 02:52:35 +00:00
|
|
|
// Use a slightly different layout, with a details pane spanning the entire window,
|
|
|
|
// if we're not showing footprints.
|
2020-10-25 21:27:06 +00:00
|
|
|
if( m_show_footprints )
|
2018-07-25 23:16:34 +00:00
|
|
|
{
|
|
|
|
m_hsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2020-12-20 12:34:48 +00:00
|
|
|
wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
|
2018-01-03 02:52:35 +00:00
|
|
|
|
2018-07-25 23:16:34 +00:00
|
|
|
//Avoid the splitter window being assigned as the Parent to additional windows
|
|
|
|
m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
|
2018-01-03 02:52:35 +00:00
|
|
|
|
2018-07-25 23:16:34 +00:00
|
|
|
sizer->Add( m_hsplitter, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_vsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2020-12-20 12:34:48 +00:00
|
|
|
wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
|
2018-06-06 04:22:13 +00:00
|
|
|
|
2018-07-25 23:16:34 +00:00
|
|
|
m_hsplitter = new wxSplitterWindow( m_vsplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2020-12-20 12:34:48 +00:00
|
|
|
wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
|
2018-01-03 02:52:35 +00:00
|
|
|
|
2018-07-25 23:16:34 +00:00
|
|
|
//Avoid the splitter window being assigned as the Parent to additional windows
|
2020-12-20 12:34:48 +00:00
|
|
|
m_vsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
|
2018-07-25 23:16:34 +00:00
|
|
|
m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
|
2014-02-22 12:39:59 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
wxPanel* detailsPanel = new wxPanel( m_vsplitter );
|
|
|
|
wxBoxSizer* detailsSizer = new wxBoxSizer( wxVERTICAL );
|
2018-07-25 23:16:34 +00:00
|
|
|
detailsPanel->SetSizer( detailsSizer );
|
|
|
|
|
2019-08-06 06:18:51 +00:00
|
|
|
m_details = new wxHtmlWindow( detailsPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxHW_SCROLLBAR_AUTO );
|
|
|
|
detailsSizer->Add( m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
|
2018-07-25 23:16:34 +00:00
|
|
|
detailsPanel->Layout();
|
|
|
|
detailsSizer->Fit( detailsPanel );
|
|
|
|
|
|
|
|
m_vsplitter->SetSashGravity( 0.5 );
|
|
|
|
m_vsplitter->SetMinimumPaneSize( 20 );
|
|
|
|
m_vsplitter->SplitHorizontally( m_hsplitter, detailsPanel );
|
|
|
|
|
|
|
|
sizer->Add( m_vsplitter, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5 );
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
wxPanel* treePanel = new wxPanel( m_hsplitter );
|
|
|
|
wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
treePanel->SetSizer( treeSizer );
|
|
|
|
|
|
|
|
m_tree = new LIB_TREE( treePanel, Prj().SchSymbolLibTable(), aAdapter, LIB_TREE::WIDGETS::ALL,
|
|
|
|
m_details );
|
|
|
|
|
|
|
|
treeSizer->Add( m_tree, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
treePanel->Layout();
|
|
|
|
treeSizer->Fit( treePanel );
|
2018-07-25 23:16:34 +00:00
|
|
|
|
|
|
|
m_hsplitter->SetSashGravity( 0.8 );
|
|
|
|
m_hsplitter->SetMinimumPaneSize( 20 );
|
2020-12-20 12:34:48 +00:00
|
|
|
m_hsplitter->SplitVertically( treePanel, ConstructRightPanel( m_hsplitter ) );
|
2018-01-03 02:52:35 +00:00
|
|
|
|
2018-07-25 23:16:34 +00:00
|
|
|
m_dbl_click_timer = new wxTimer( this );
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
|
2018-07-27 20:47:51 +00:00
|
|
|
|
|
|
|
if( aAllowBrowser )
|
|
|
|
{
|
|
|
|
m_browser_button = new wxButton( this, wxID_ANY, _( "Select with Browser" ) );
|
2018-08-05 13:22:29 +00:00
|
|
|
buttonsSizer->Add( m_browser_button, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
|
2018-07-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
m_keepSymbol = new wxCheckBox( this, wxID_ANY, _("Place repeated copies"), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxALIGN_RIGHT );
|
|
|
|
m_keepSymbol->SetToolTip( _( "Keep the symbol selected for subsequent clicks." ) );
|
|
|
|
|
|
|
|
m_useUnits = new wxCheckBox( this, wxID_ANY, _("Place all units"), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxALIGN_RIGHT );
|
|
|
|
m_useUnits->SetToolTip( _( "Sequentially place all units of the symbol." ) );
|
|
|
|
|
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
|
|
|
{
|
|
|
|
m_keepSymbol->SetValue( cfg->m_SymChooserPanel.keep_symbol );
|
|
|
|
m_useUnits->SetValue( cfg->m_SymChooserPanel.place_all_units );
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonsSizer->Add( m_keepSymbol, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
buttonsSizer->Add( m_useUnits, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
|
|
|
|
wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
|
|
|
|
wxButton* okButton = new wxButton( this, wxID_OK );
|
|
|
|
wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
sdbSizer->AddButton( okButton );
|
|
|
|
sdbSizer->AddButton( cancelButton );
|
|
|
|
sdbSizer->Realize();
|
|
|
|
|
|
|
|
buttonsSizer->Add( sdbSizer, 1, wxALL, 5 );
|
2015-03-30 19:34:41 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
|
2017-03-08 17:00:07 +00:00
|
|
|
SetSizer( sizer );
|
|
|
|
|
2017-02-19 02:39:55 +00:00
|
|
|
Layout();
|
2018-01-06 02:33:41 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
2020-03-25 13:13:03 +00:00
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS::PANEL_SYM_CHOOSER& panelCfg = cfg->m_SymChooserPanel;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-03-25 13:13:03 +00:00
|
|
|
// We specify the width of the right window (m_symbol_view_panel), because specify
|
|
|
|
// the width of the left window does not work as expected when SetSashGravity() is called
|
|
|
|
m_hsplitter->SetSashPosition( panelCfg.sash_pos_h > 0 ? panelCfg.sash_pos_h :
|
2020-11-16 11:16:44 +00:00
|
|
|
horizPixelsFromDU( 220 ) );
|
2018-01-06 18:18:28 +00:00
|
|
|
|
2020-03-25 13:13:03 +00:00
|
|
|
if( m_vsplitter )
|
2020-12-08 17:44:44 +00:00
|
|
|
{
|
2020-03-25 13:13:03 +00:00
|
|
|
m_vsplitter->SetSashPosition( panelCfg.sash_pos_v > 0 ? panelCfg.sash_pos_v :
|
2020-11-16 11:16:44 +00:00
|
|
|
vertPixelsFromDU( 230 ) );
|
2020-12-08 17:44:44 +00:00
|
|
|
}
|
2018-07-25 23:16:34 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
wxSize dlgSize( panelCfg.width > 0 ? panelCfg.width : horizPixelsFromDU( 390 ),
|
|
|
|
panelCfg.height > 0 ? panelCfg.height : vertPixelsFromDU( 300 ) );
|
2020-03-25 13:13:03 +00:00
|
|
|
SetSize( dlgSize );
|
|
|
|
}
|
2018-07-27 20:47:51 +00:00
|
|
|
|
2020-12-08 17:44:44 +00:00
|
|
|
SetInitialFocus( m_tree->GetFocusTarget() );
|
2018-07-27 20:47:51 +00:00
|
|
|
okButton->SetDefault();
|
2019-01-25 19:18:22 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
Bind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_SYMBOL::OnInitDialog, this );
|
|
|
|
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_SYMBOL::OnCloseTimer, this, m_dbl_click_timer->GetId() );
|
|
|
|
Bind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_SYMBOL::OnComponentPreselected, this );
|
|
|
|
Bind( COMPONENT_SELECTED, &DIALOG_CHOOSE_SYMBOL::OnComponentSelected, this );
|
2019-01-25 19:18:22 +00:00
|
|
|
|
|
|
|
if( m_browser_button )
|
2020-12-08 17:44:44 +00:00
|
|
|
{
|
2020-12-08 18:30:14 +00:00
|
|
|
m_browser_button->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_CHOOSE_SYMBOL::OnUseBrowser,
|
|
|
|
this );
|
2020-12-08 17:44:44 +00:00
|
|
|
}
|
2019-01-25 19:18:22 +00:00
|
|
|
|
|
|
|
if( m_fp_sel_ctrl )
|
2020-12-08 17:44:44 +00:00
|
|
|
{
|
2020-12-08 18:30:14 +00:00
|
|
|
m_fp_sel_ctrl->Bind( EVT_FOOTPRINT_SELECTED, &DIALOG_CHOOSE_SYMBOL::OnFootprintSelected,
|
|
|
|
this );
|
2020-12-08 17:44:44 +00:00
|
|
|
}
|
2019-08-06 06:18:51 +00:00
|
|
|
|
2019-08-07 16:06:27 +00:00
|
|
|
if( m_details )
|
2020-12-08 17:44:44 +00:00
|
|
|
{
|
2020-12-08 18:30:14 +00:00
|
|
|
m_details->Connect( wxEVT_CHAR_HOOK, wxKeyEventHandler( DIALOG_CHOOSE_SYMBOL::OnCharHook ),
|
2020-03-25 13:13:03 +00:00
|
|
|
NULL, this );
|
2020-12-08 17:44:44 +00:00
|
|
|
}
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
DIALOG_CHOOSE_SYMBOL::~DIALOG_CHOOSE_SYMBOL()
|
2017-03-23 15:52:05 +00:00
|
|
|
{
|
2020-12-08 18:30:14 +00:00
|
|
|
Unbind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_SYMBOL::OnInitDialog, this );
|
|
|
|
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_SYMBOL::OnCloseTimer, this );
|
|
|
|
Unbind( COMPONENT_PRESELECTED, &DIALOG_CHOOSE_SYMBOL::OnComponentPreselected, this );
|
|
|
|
Unbind( COMPONENT_SELECTED, &DIALOG_CHOOSE_SYMBOL::OnComponentSelected, this );
|
2018-06-08 23:50:06 +00:00
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
if( m_browser_button )
|
2020-12-08 18:30:14 +00:00
|
|
|
{
|
2018-08-02 17:00:41 +00:00
|
|
|
m_browser_button->Unbind( wxEVT_COMMAND_BUTTON_CLICKED,
|
2020-12-08 18:30:14 +00:00
|
|
|
&DIALOG_CHOOSE_SYMBOL::OnUseBrowser, this );
|
|
|
|
}
|
2018-06-08 23:50:06 +00:00
|
|
|
|
|
|
|
if( m_fp_sel_ctrl )
|
2020-12-08 18:30:14 +00:00
|
|
|
{
|
|
|
|
m_fp_sel_ctrl->Unbind( EVT_FOOTPRINT_SELECTED, &DIALOG_CHOOSE_SYMBOL::OnFootprintSelected,
|
|
|
|
this );
|
|
|
|
}
|
2018-06-08 23:50:06 +00:00
|
|
|
|
2019-08-07 16:06:27 +00:00
|
|
|
if( m_details )
|
2020-12-08 18:30:14 +00:00
|
|
|
{
|
2019-08-07 16:06:27 +00:00
|
|
|
m_details->Disconnect( wxEVT_CHAR_HOOK,
|
2020-12-08 18:30:14 +00:00
|
|
|
wxKeyEventHandler( DIALOG_CHOOSE_SYMBOL::OnCharHook ), NULL, this );
|
|
|
|
}
|
2019-08-06 06:18:51 +00:00
|
|
|
|
|
|
|
// I am not sure the following two lines are necessary, but they will not hurt anyone
|
2017-03-23 15:52:05 +00:00
|
|
|
m_dbl_click_timer->Stop();
|
|
|
|
delete m_dbl_click_timer;
|
2018-01-06 02:33:41 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
|
|
|
|
{
|
|
|
|
cfg->m_SymChooserPanel.width = GetSize().x;
|
|
|
|
cfg->m_SymChooserPanel.height = GetSize().y;
|
2019-08-26 10:57:07 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
cfg->m_SymChooserPanel.keep_symbol = m_keepSymbol->GetValue();
|
|
|
|
cfg->m_SymChooserPanel.place_all_units = m_useUnits->GetValue();
|
2019-10-29 05:06:39 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
cfg->m_SymChooserPanel.sash_pos_h = m_hsplitter->GetSashPosition();
|
2018-07-25 23:16:34 +00:00
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
if( m_vsplitter )
|
|
|
|
cfg->m_SymChooserPanel.sash_pos_v = m_vsplitter->GetSashPosition();
|
|
|
|
}
|
2017-03-23 15:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
wxPanel* DIALOG_CHOOSE_SYMBOL::ConstructRightPanel( wxWindow* aParent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2020-03-25 18:06:18 +00:00
|
|
|
wxPanel* panel = new wxPanel( aParent );
|
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
EDA_DRAW_PANEL_GAL::GAL_TYPE backend = m_parent->GetCanvas()->GetBackend();
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2020-03-25 18:06:18 +00:00
|
|
|
m_symbol_preview = new SYMBOL_PREVIEW_WIDGET( panel, Kiway(), backend );
|
2018-07-27 20:47:51 +00:00
|
|
|
m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2018-01-03 02:52:35 +00:00
|
|
|
if( m_show_footprints )
|
|
|
|
{
|
2018-05-30 07:51:47 +00:00
|
|
|
FOOTPRINT_LIST* fp_list = FOOTPRINT_LIST::GetInstance( Kiway() );
|
|
|
|
|
2020-12-20 12:34:48 +00:00
|
|
|
sizer->Add( m_symbol_preview, 1, wxEXPAND | wxALL, 5 );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2018-10-12 21:42:59 +00:00
|
|
|
if ( fp_list )
|
|
|
|
{
|
|
|
|
if( m_allow_field_edits )
|
2020-08-09 10:55:00 +00:00
|
|
|
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( m_parent, panel, fp_list, true );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-10-12 21:42:59 +00:00
|
|
|
m_fp_preview = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
|
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-01-03 02:52:35 +00:00
|
|
|
if( m_fp_sel_ctrl )
|
2020-12-20 12:34:48 +00:00
|
|
|
sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 3 );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-10-12 21:42:59 +00:00
|
|
|
if( m_fp_preview )
|
2020-12-20 12:34:48 +00:00
|
|
|
sizer->Add( m_fp_preview, 1, wxEXPAND | wxALL, 5 );
|
2018-01-03 02:52:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-20 12:34:48 +00:00
|
|
|
sizer->Add( m_symbol_preview, 1, wxEXPAND | wxALL, 5 );
|
2018-01-03 02:52:35 +00:00
|
|
|
}
|
2017-03-08 17:00:07 +00:00
|
|
|
|
|
|
|
panel->SetSizer( sizer );
|
|
|
|
panel->Layout();
|
|
|
|
sizer->Fit( panel );
|
|
|
|
|
|
|
|
return panel;
|
2014-02-24 10:52:08 +00:00
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnInitDialog( wxInitDialogEvent& aEvent )
|
2017-01-22 22:29:16 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
if( m_fp_preview && m_fp_preview->IsInitialized() )
|
2017-03-08 17:00:07 +00:00
|
|
|
{
|
|
|
|
// This hides the GAL panel and shows the status label
|
2018-07-27 20:47:51 +00:00
|
|
|
m_fp_preview->SetStatusText( wxEmptyString );
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
2018-06-08 23:50:06 +00:00
|
|
|
|
|
|
|
if( m_fp_sel_ctrl )
|
|
|
|
m_fp_sel_ctrl->Load( Kiway(), Prj() );
|
2018-04-16 22:18:02 +00:00
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2018-04-16 22:18:02 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnCharHook( wxKeyEvent& e )
|
2019-08-06 06:18:51 +00:00
|
|
|
{
|
2019-08-07 16:06:27 +00:00
|
|
|
if( m_details && e.GetKeyCode() == 'C' && e.ControlDown() &&
|
|
|
|
!e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
|
2019-08-06 06:18:51 +00:00
|
|
|
{
|
|
|
|
wxString txt = m_details->SelectionToText();
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
2019-08-06 06:18:51 +00:00
|
|
|
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( txt ) );
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e.Skip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
LIB_ID DIALOG_CHOOSE_SYMBOL::GetSelectedLibId( int* aUnit ) const
|
2018-04-16 22:18:02 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
return m_tree->GetSelectedLibId( aUnit );
|
2017-01-22 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnUseBrowser( wxCommandEvent& aEvent )
|
2014-02-24 10:52:08 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
m_external_browser_requested = true;
|
2020-08-18 18:21:26 +00:00
|
|
|
|
|
|
|
if( IsQuasiModal() )
|
|
|
|
EndQuasiModal( wxID_OK );
|
|
|
|
else if( IsModal() )
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Dialog called with neither Modal nor QuasiModal" );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnCloseTimer( wxTimerEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-02-24 01:29:03 +00:00
|
|
|
// Hack handler because of eaten MouseUp event. See
|
2018-06-08 23:50:06 +00:00
|
|
|
// DIALOG_CHOOSE_COMPONENT::OnComponentSelected for the beginning
|
2017-02-24 01:29:03 +00:00
|
|
|
// of this spaghetti noodle.
|
|
|
|
|
|
|
|
auto state = wxGetMouseState();
|
|
|
|
|
|
|
|
if( state.LeftIsDown() )
|
|
|
|
{
|
|
|
|
// Mouse hasn't been raised yet, so fire the timer again. Otherwise the
|
|
|
|
// purpose of this timer is defeated.
|
2020-12-08 18:30:14 +00:00
|
|
|
m_dbl_click_timer->StartOnce( DIALOG_CHOOSE_SYMBOL::DblClickDelay );
|
2017-02-24 01:29:03 +00:00
|
|
|
}
|
2017-02-24 01:59:15 +00:00
|
|
|
else
|
2017-02-24 01:29:03 +00:00
|
|
|
{
|
2020-08-18 18:21:26 +00:00
|
|
|
if( IsQuasiModal() )
|
|
|
|
EndQuasiModal( wxID_OK );
|
|
|
|
else if( IsModal() )
|
|
|
|
EndModal( wxID_OK );
|
|
|
|
else
|
|
|
|
wxFAIL_MSG( "Dialog called with neither Modal nor QuasiModal" );
|
2017-02-24 01:29:03 +00:00
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 01:59:15 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::ShowFootprintFor( LIB_ID const& aLibId )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
if( !m_fp_preview || !m_fp_preview->IsInitialized() )
|
2017-02-19 02:39:55 +00:00
|
|
|
return;
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* symbol = nullptr;
|
2017-09-15 14:17:44 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
symbol = Prj().SchSymbolLibTable()->LoadSymbol( aLibId );
|
2017-09-15 14:17:44 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2018-08-28 13:26:39 +00:00
|
|
|
wxLogError( wxString::Format( _( "Error loading symbol %s from library %s.\n\n%s" ),
|
2017-09-15 14:17:44 +00:00
|
|
|
aLibId.GetLibItemName().wx_str(),
|
|
|
|
aLibId.GetLibNickname().wx_str(),
|
|
|
|
ioe.What() ) );
|
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !symbol )
|
2017-09-15 14:17:44 +00:00
|
|
|
return;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
LIB_FIELD* fp_field = symbol->GetField( FOOTPRINT_FIELD );
|
2017-03-23 00:59:25 +00:00
|
|
|
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
|
|
|
|
|
|
|
|
ShowFootprint( fp_name );
|
|
|
|
}
|
2017-02-19 02:39:55 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::ShowFootprint( wxString const& aName )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
if( !m_fp_preview || !m_fp_preview->IsInitialized() )
|
2018-01-03 02:52:35 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
if( aName == wxEmptyString )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
m_fp_preview->SetStatusText( _( "No footprint specified" ) );
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
LIB_ID lib_id;
|
|
|
|
|
2020-12-17 23:32:23 +00:00
|
|
|
if( lib_id.Parse( aName ) == -1 && lib_id.IsValid() )
|
2017-09-15 14:17:44 +00:00
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
m_fp_preview->ClearStatus();
|
|
|
|
m_fp_preview->DisplayFootprint( lib_id );
|
2017-09-15 14:17:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-27 20:47:51 +00:00
|
|
|
m_fp_preview->SetStatusText( _( "Invalid footprint specified" ) );
|
2017-09-15 14:17:44 +00:00
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::PopulateFootprintSelector( LIB_ID const& aLibId )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
if( !m_fp_sel_ctrl )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_fp_sel_ctrl->ClearFilters();
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
LIB_PART* symbol = nullptr;
|
2017-09-15 14:17:44 +00:00
|
|
|
|
2017-10-06 18:07:43 +00:00
|
|
|
if( aLibId.IsValid() )
|
2017-09-15 14:17:44 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
try
|
|
|
|
{
|
2019-11-06 19:15:42 +00:00
|
|
|
symbol = Prj().SchSymbolLibTable()->LoadSymbol( aLibId );
|
2017-10-06 18:07:43 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
|
|
|
|
"\n\n%s" ),
|
|
|
|
aLibId.GetLibItemName().wx_str(),
|
|
|
|
aLibId.GetLibNickname().wx_str(),
|
|
|
|
ioe.What() ) );
|
|
|
|
}
|
2017-09-15 14:17:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( symbol != nullptr )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
LIB_PINS temp_pins;
|
2020-11-12 21:31:41 +00:00
|
|
|
LIB_FIELD* fp_field = symbol->GetField( FOOTPRINT_FIELD );
|
2017-03-23 00:59:25 +00:00
|
|
|
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
|
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
symbol->GetPins( temp_pins );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
m_fp_sel_ctrl->FilterByPinCount( temp_pins.size() );
|
2020-12-14 13:47:32 +00:00
|
|
|
m_fp_sel_ctrl->FilterByFootprintFilters( symbol->GetFPFilters(), true );
|
2017-03-23 00:59:25 +00:00
|
|
|
m_fp_sel_ctrl->SetDefaultFootprint( fp_name );
|
|
|
|
m_fp_sel_ctrl->UpdateList();
|
|
|
|
m_fp_sel_ctrl->Enable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fp_sel_ctrl->UpdateList();
|
|
|
|
m_fp_sel_ctrl->Disable();
|
2017-02-19 02:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnFootprintSelected( wxCommandEvent& aEvent )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
|
|
|
m_fp_override = aEvent.GetString();
|
|
|
|
|
2020-03-25 18:06:18 +00:00
|
|
|
m_field_edits.erase( std::remove_if( m_field_edits.begin(), m_field_edits.end(),
|
|
|
|
[]( std::pair<int, wxString> const& i )
|
|
|
|
{
|
2020-11-12 21:31:41 +00:00
|
|
|
return i.first == FOOTPRINT_FIELD;
|
2020-03-25 18:06:18 +00:00
|
|
|
} ),
|
|
|
|
m_field_edits.end() );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
m_field_edits.emplace_back( std::make_pair( FOOTPRINT_FIELD, m_fp_override ) );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
ShowFootprint( m_fp_override );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnComponentPreselected( wxCommandEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
|
|
|
int unit = 0;
|
2017-09-15 14:17:44 +00:00
|
|
|
|
|
|
|
LIB_ID id = m_tree->GetSelectedLibId( &unit );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
if( id.IsValid() )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
2018-08-28 13:26:39 +00:00
|
|
|
m_symbol_preview->DisplaySymbol( id, unit );
|
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
ShowFootprintFor( id );
|
|
|
|
PopulateFootprintSelector( id );
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-28 13:26:39 +00:00
|
|
|
m_symbol_preview->SetStatusText( _( "No symbol selected" ) );
|
|
|
|
|
2018-07-27 20:47:51 +00:00
|
|
|
if( m_fp_preview && m_fp_preview->IsInitialized() )
|
|
|
|
m_fp_preview->SetStatusText( wxEmptyString );
|
2017-06-25 21:13:39 +00:00
|
|
|
|
2017-09-15 14:17:44 +00:00
|
|
|
PopulateFootprintSelector( id );
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-08 18:30:14 +00:00
|
|
|
void DIALOG_CHOOSE_SYMBOL::OnComponentSelected( wxCommandEvent& aEvent )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
2017-09-15 14:17:44 +00:00
|
|
|
if( m_tree->GetSelectedLibId().IsValid() )
|
2017-06-25 21:13:39 +00:00
|
|
|
{
|
|
|
|
// Got a selection. We can't just end the modal dialog here, because
|
|
|
|
// wx leaks some events back to the parent window (in particular, the
|
|
|
|
// MouseUp following a double click).
|
|
|
|
//
|
|
|
|
// NOW, here's where it gets really fun. wxTreeListCtrl eats MouseUp.
|
|
|
|
// This isn't really feasible to bypass without a fully custom
|
|
|
|
// wxDataViewCtrl implementation, and even then might not be fully
|
|
|
|
// possible (docs are vague). To get around this, we use a one-shot
|
|
|
|
// timer to schedule the dialog close.
|
|
|
|
//
|
|
|
|
// See DIALOG_CHOOSE_COMPONENT::OnCloseTimer for the other end of this
|
|
|
|
// spaghetti noodle.
|
2020-12-08 18:30:14 +00:00
|
|
|
m_dbl_click_timer->StartOnce( DIALOG_CHOOSE_SYMBOL::DblClickDelay );
|
2017-06-25 21:13:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|