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>
|
2017-03-08 17:00:07 +00:00
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
2017-02-05 19:18:29 +00:00
|
|
|
* Copyright (C) 2016-2017 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
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <dialog_choose_component.h>
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <algorithm>
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <set>
|
|
|
|
#include <wx/tokenzr.h>
|
2017-02-19 02:39:55 +00:00
|
|
|
#include <wx/utils.h>
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
#include <wx/artprov.h>
|
|
|
|
#include <wx/bitmap.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/choice.h>
|
2017-03-08 17:00:07 +00:00
|
|
|
#include <wx/dataview.h>
|
|
|
|
#include <wx/html/htmlwin.h>
|
|
|
|
#include <wx/panel.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <wx/sizer.h>
|
2017-03-08 17:00:07 +00:00
|
|
|
#include <wx/splitter.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <wx/statbmp.h>
|
|
|
|
#include <wx/textctrl.h>
|
2017-03-08 17:00:07 +00:00
|
|
|
#include <wx/timer.h>
|
2017-03-08 20:10:50 +00:00
|
|
|
#include <wx/utils.h>
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <class_library.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <generate_alias_info.h>
|
2014-02-14 08:05:04 +00:00
|
|
|
#include <sch_base_frame.h>
|
2017-02-19 14:00:02 +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>
|
2017-03-31 01:46:48 +00:00
|
|
|
#include <wxdataviewctrl_helpers.h>
|
2014-02-14 08:05:04 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
FOOTPRINT_ASYNC_LOADER DIALOG_CHOOSE_COMPONENT::m_fp_loader;
|
|
|
|
std::unique_ptr<FOOTPRINT_LIST> DIALOG_CHOOSE_COMPONENT::m_fp_list;
|
|
|
|
|
|
|
|
DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle,
|
|
|
|
CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert, bool aAllowFieldEdits )
|
|
|
|
: DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxSize( 800, 650 ),
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_adapter( aAdapter ),
|
|
|
|
m_deMorganConvert( aDeMorganConvert >= 0 ? aDeMorganConvert : 0 ),
|
|
|
|
m_allow_field_edits( aAllowFieldEdits ),
|
|
|
|
m_external_browser_requested( false )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-08 20:10:50 +00:00
|
|
|
wxBusyCursor busy_while_loading;
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
auto sizer = new wxBoxSizer( wxVERTICAL );
|
2017-02-24 19:27:49 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
auto splitter = new wxSplitterWindow(
|
|
|
|
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE );
|
2017-03-08 17:00:07 +00:00
|
|
|
auto left_panel = ConstructLeftPanel( splitter );
|
|
|
|
auto right_panel = ConstructRightPanel( splitter );
|
|
|
|
auto buttons = new wxStdDialogButtonSizer();
|
|
|
|
m_dbl_click_timer = new wxTimer( this );
|
2014-02-22 12:39:59 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
splitter->SetSashGravity( 0.9 );
|
|
|
|
splitter->SetMinimumPaneSize( 1 );
|
|
|
|
splitter->SplitVertically( left_panel, right_panel, -300 );
|
2014-11-19 14:22:47 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
buttons->AddButton( new wxButton( this, wxID_OK ) );
|
|
|
|
buttons->AddButton( new wxButton( this, wxID_CANCEL ) );
|
|
|
|
buttons->Realize();
|
2015-03-30 19:34:41 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
sizer->Add( splitter, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
sizer->Add( buttons, 0, wxEXPAND | wxBOTTOM, 10 );
|
2017-03-08 17:00:07 +00:00
|
|
|
SetSizer( sizer );
|
|
|
|
|
|
|
|
Bind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_COMPONENT::OnInitDialog, this );
|
2017-03-23 00:59:25 +00:00
|
|
|
Bind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this, m_dbl_click_timer->GetId() );
|
|
|
|
|
|
|
|
m_query_ctrl->Bind( wxEVT_TEXT, &DIALOG_CHOOSE_COMPONENT::OnQueryText, this );
|
|
|
|
m_query_ctrl->Bind( wxEVT_TEXT_ENTER, &DIALOG_CHOOSE_COMPONENT::OnQueryEnter, this );
|
|
|
|
m_query_ctrl->Bind( wxEVT_CHAR_HOOK, &DIALOG_CHOOSE_COMPONENT::OnQueryCharHook, this );
|
|
|
|
m_tree_ctrl->Bind(
|
|
|
|
wxEVT_DATAVIEW_ITEM_ACTIVATED, &DIALOG_CHOOSE_COMPONENT::OnTreeActivate, this );
|
|
|
|
m_tree_ctrl->Bind(
|
|
|
|
wxEVT_DATAVIEW_SELECTION_CHANGED, &DIALOG_CHOOSE_COMPONENT::OnTreeSelect, this );
|
2017-03-08 17:00:07 +00:00
|
|
|
m_details_ctrl->Bind( wxEVT_HTML_LINK_CLICKED, &DIALOG_CHOOSE_COMPONENT::OnDetailsLink, this );
|
|
|
|
m_sch_view_ctrl->Bind( wxEVT_LEFT_DCLICK, &DIALOG_CHOOSE_COMPONENT::OnSchViewDClick, this );
|
|
|
|
m_sch_view_ctrl->Bind( wxEVT_PAINT, &DIALOG_CHOOSE_COMPONENT::OnSchViewPaint, this );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
if( m_fp_sel_ctrl )
|
|
|
|
m_fp_sel_ctrl->Bind(
|
|
|
|
EVT_FOOTPRINT_SELECTED, &DIALOG_CHOOSE_COMPONENT::OnFootprintSelected, this );
|
|
|
|
|
2017-02-19 02:39:55 +00:00
|
|
|
Layout();
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 15:52:05 +00:00
|
|
|
DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT()
|
|
|
|
{
|
|
|
|
// I am not sure the following two lines are necessary,
|
|
|
|
// but they will not hurt anyone
|
|
|
|
m_dbl_click_timer->Stop();
|
|
|
|
Unbind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this );
|
|
|
|
|
|
|
|
delete m_dbl_click_timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructLeftPanel( wxWindow* aParent )
|
|
|
|
{
|
|
|
|
auto panel = new wxPanel( aParent );
|
|
|
|
auto sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
auto search_sizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
m_query_ctrl = new wxTextCtrl(
|
|
|
|
panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
m_tree_ctrl =
|
|
|
|
new wxDataViewCtrl( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE );
|
2017-03-08 17:00:07 +00:00
|
|
|
m_adapter->AttachTo( m_tree_ctrl );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
m_details_ctrl = new wxHtmlWindow( panel, wxID_ANY, wxDefaultPosition, wxSize( 320, 240 ),
|
2017-03-08 17:00:07 +00:00
|
|
|
wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
// Additional visual cue for GTK, which hides the placeholder text on focus
|
2017-03-08 17:00:07 +00:00
|
|
|
#ifdef __WXGTK__
|
2017-03-23 00:59:25 +00:00
|
|
|
search_sizer->Add( new wxStaticBitmap( panel, wxID_ANY,
|
|
|
|
wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ),
|
|
|
|
0, wxALIGN_CENTER | wxALL, 5 );
|
2017-03-08 17:00:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 );
|
2017-02-21 23:09:34 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
sizer->Add( search_sizer, 0, wxEXPAND, 5 );
|
|
|
|
sizer->Add( m_tree_ctrl, 1, wxALL | wxEXPAND, 5 );
|
2017-03-08 17:00:07 +00:00
|
|
|
sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 );
|
|
|
|
|
|
|
|
panel->SetSizer( sizer );
|
|
|
|
panel->Layout();
|
|
|
|
sizer->Fit( panel );
|
|
|
|
return panel;
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
auto panel = new wxPanel( aParent );
|
|
|
|
auto sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
m_sch_view_ctrl = new wxPanel( panel, wxID_ANY, wxDefaultPosition, wxSize( -1, -1 ),
|
2017-03-08 17:00:07 +00:00
|
|
|
wxFULL_REPAINT_ON_RESIZE | wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
|
|
|
|
m_sch_view_ctrl->SetLayoutDirection( wxLayout_LeftToRight );
|
|
|
|
|
2017-04-13 08:58:10 +00:00
|
|
|
if( m_allow_field_edits )
|
2017-03-23 00:59:25 +00:00
|
|
|
m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( panel, m_fp_loader, m_fp_list, true );
|
|
|
|
else
|
|
|
|
m_fp_sel_ctrl = nullptr;
|
2017-03-08 17:00:07 +00:00
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
m_fp_view_ctrl = new FOOTPRINT_PREVIEW_WIDGET( panel, Kiway() );
|
2017-03-08 17:00:07 +00:00
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
sizer->Add( m_sch_view_ctrl, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
|
|
|
if( m_fp_sel_ctrl )
|
|
|
|
sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxALL, 5 );
|
|
|
|
|
|
|
|
sizer->Add( m_fp_view_ctrl, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
|
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
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnInitDialog( wxInitDialogEvent& aEvent )
|
2017-01-22 22:29:16 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
// If wxTextCtrl::SetHint() is called before binding wxEVT_TEXT, the event
|
|
|
|
// handler will intermittently fire.
|
|
|
|
m_query_ctrl->SetHint( _( "Search" ) );
|
|
|
|
m_query_ctrl->SetFocus();
|
|
|
|
m_query_ctrl->SetValue( wxEmptyString );
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( m_fp_view_ctrl->IsInitialized() )
|
2017-03-08 17:00:07 +00:00
|
|
|
{
|
|
|
|
// This hides the GAL panel and shows the status label
|
2017-03-10 19:11:41 +00:00
|
|
|
m_fp_view_ctrl->SetStatusText( wxEmptyString );
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
if( m_fp_sel_ctrl )
|
|
|
|
m_fp_sel_ctrl->Load( Kiway(), Prj() );
|
|
|
|
|
|
|
|
// There may be a part preselected in the model. Make sure it is displayed.
|
|
|
|
PostSelectEvent();
|
2017-01-22 22:29:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2014-02-24 10:52:08 +00:00
|
|
|
LIB_ALIAS* DIALOG_CHOOSE_COMPONENT::GetSelectedAlias( int* aUnit ) const
|
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
auto sel = m_tree_ctrl->GetSelection();
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
if( aUnit )
|
2017-03-06 14:50:48 +00:00
|
|
|
*aUnit = m_adapter->GetUnitFor( sel );
|
|
|
|
|
|
|
|
return m_adapter->GetAliasFor( sel );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
std::vector<std::pair<int, wxString>> DIALOG_CHOOSE_COMPONENT::GetFields() const
|
|
|
|
{
|
|
|
|
return m_field_edits;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnQueryText( wxCommandEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
m_adapter->UpdateSearchString( m_query_ctrl->GetLineText( 0 ) );
|
|
|
|
PostSelectEvent();
|
|
|
|
|
|
|
|
// Required to avoid interaction with SetHint()
|
|
|
|
// See documentation for wxTextEntry::SetHint
|
|
|
|
aEvent.Skip();
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnQueryEnter( wxCommandEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-03 21:05:13 +00:00
|
|
|
HandleItemSelection();
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::SelectIfValid( const wxDataViewItem& aTreeId )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-06 14:50:48 +00:00
|
|
|
if( aTreeId.IsOk() )
|
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
m_tree_ctrl->EnsureVisible( aTreeId );
|
|
|
|
m_tree_ctrl->Select( aTreeId );
|
|
|
|
PostSelectEvent();
|
2017-03-06 14:50:48 +00:00
|
|
|
}
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-19 15:01:45 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::PostSelectEvent()
|
|
|
|
{
|
|
|
|
wxDataViewEvent evt( wxEVT_DATAVIEW_SELECTION_CHANGED );
|
|
|
|
m_tree_ctrl->GetEventHandler()->ProcessEvent( evt );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnQueryCharHook( wxKeyEvent& aKeyStroke )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
auto const sel = m_tree_ctrl->GetSelection();
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
switch( aKeyStroke.GetKeyCode() )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
case WXK_UP: SelectIfValid( GetPrevItem( *m_tree_ctrl, sel ) ); break;
|
2014-02-14 08:05:04 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
case WXK_DOWN: SelectIfValid( GetNextItem( *m_tree_ctrl, sel ) ); break;
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2014-02-14 08:05:04 +00:00
|
|
|
default:
|
2017-03-23 00:59:25 +00:00
|
|
|
aKeyStroke.Skip(); // Any other key: pass on to search box directly.
|
2014-02-14 08:05:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-06 14:50:48 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnTreeSelect( wxDataViewEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
auto sel = m_tree_ctrl->GetSelection();
|
|
|
|
int unit = m_adapter->GetUnitFor( sel );
|
2017-03-08 17:00:07 +00:00
|
|
|
LIB_ALIAS* alias = m_adapter->GetAliasFor( sel );
|
|
|
|
|
|
|
|
m_sch_view_ctrl->Refresh();
|
|
|
|
|
|
|
|
if( alias )
|
|
|
|
{
|
|
|
|
m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) );
|
|
|
|
ShowFootprintFor( alias );
|
2017-03-23 00:59:25 +00:00
|
|
|
PopulateFootprintSelector( alias );
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_details_ctrl->SetPage( wxEmptyString );
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
if( m_fp_view_ctrl->IsInitialized() )
|
|
|
|
m_fp_view_ctrl->SetStatusText( wxEmptyString );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
PopulateFootprintSelector( nullptr );
|
2017-03-08 17:00:07 +00:00
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-06 14:50:48 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnTreeActivate( wxDataViewEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
2017-03-03 21:05:13 +00:00
|
|
|
HandleItemSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-24 01:29:03 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::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
|
|
|
|
// DIALOG_CHOOSE_COMPONENT::OnDoubleClickTreeActivation for the beginning
|
|
|
|
// 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.
|
|
|
|
m_dbl_click_timer->StartOnce( DIALOG_CHOOSE_COMPONENT::DblClickDelay );
|
|
|
|
}
|
2017-02-24 01:59:15 +00:00
|
|
|
else
|
2017-02-24 01:29:03 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
EndQuasiModal( wxID_OK );
|
2017-02-24 01:29:03 +00:00
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 01:59:15 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnSchViewDClick( wxMouseEvent& aEvent )
|
2014-02-14 08:05:04 +00:00
|
|
|
{
|
|
|
|
m_external_browser_requested = true;
|
2017-03-23 00:59:25 +00:00
|
|
|
EndQuasiModal( wxID_OK );
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ALIAS* aAlias )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
if( !m_fp_view_ctrl->IsInitialized() )
|
2017-02-19 02:39:55 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
LIB_FIELD* fp_field = aAlias->GetPart()->GetField( FOOTPRINT );
|
|
|
|
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
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::ShowFootprint( wxString const& aName )
|
|
|
|
{
|
|
|
|
if( aName == wxEmptyString )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
m_fp_view_ctrl->SetStatusText( _( "No footprint specified" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LIB_ID lib_id( aName );
|
|
|
|
|
|
|
|
m_fp_view_ctrl->ClearStatus();
|
|
|
|
m_fp_view_ctrl->CacheFootprint( lib_id );
|
|
|
|
m_fp_view_ctrl->DisplayFootprint( lib_id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CHOOSE_COMPONENT::PopulateFootprintSelector( LIB_ALIAS* aAlias )
|
|
|
|
{
|
|
|
|
if( !m_fp_sel_ctrl )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_fp_sel_ctrl->ClearFilters();
|
|
|
|
|
|
|
|
if( aAlias )
|
|
|
|
{
|
|
|
|
LIB_PINS temp_pins;
|
|
|
|
LIB_FIELD* fp_field = aAlias->GetPart()->GetField( FOOTPRINT );
|
|
|
|
wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
|
|
|
|
|
|
|
|
aAlias->GetPart()->GetPins( temp_pins );
|
|
|
|
|
|
|
|
m_fp_sel_ctrl->FilterByPinCount( temp_pins.size() );
|
|
|
|
m_fp_sel_ctrl->FilterByFootprintFilters( aAlias->GetPart()->GetFootPrints(), true );
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnDetailsLink( wxHtmlLinkEvent& aEvent )
|
2017-02-19 02:39:55 +00:00
|
|
|
{
|
2017-03-23 00:59:25 +00:00
|
|
|
const wxHtmlLinkInfo& info = aEvent.GetLinkInfo();
|
2017-02-19 02:39:55 +00:00
|
|
|
::wxLaunchDefaultBrowser( info.GetHref() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnSchViewPaint( wxPaintEvent& aEvent )
|
2014-02-18 21:41:27 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
auto sel = m_tree_ctrl->GetSelection();
|
2017-03-06 14:50:48 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
int unit = m_adapter->GetUnitFor( sel );
|
2017-03-06 14:50:48 +00:00
|
|
|
LIB_ALIAS* alias = m_adapter->GetAliasFor( sel );
|
2017-03-23 00:59:25 +00:00
|
|
|
LIB_PART* part = alias ? alias->GetPart() : nullptr;
|
2014-10-09 00:49:29 +00:00
|
|
|
|
|
|
|
// Don't draw anything (not even the background) if we don't have
|
|
|
|
// a part to show
|
|
|
|
if( !part )
|
|
|
|
return;
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2017-03-06 14:50:48 +00:00
|
|
|
if( alias->IsRoot() )
|
2014-10-09 00:49:29 +00:00
|
|
|
{
|
|
|
|
// just show the part directly
|
2017-03-08 17:00:07 +00:00
|
|
|
RenderPreview( part, unit );
|
2014-10-09 00:49:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// switch out the name temporarily for the alias name
|
|
|
|
wxString tmp( part->GetName() );
|
2017-03-06 14:50:48 +00:00
|
|
|
part->SetName( alias->GetName() );
|
2014-10-09 00:49:29 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
RenderPreview( part, unit );
|
2014-10-09 00:49:29 +00:00
|
|
|
|
|
|
|
part->SetName( tmp );
|
|
|
|
}
|
2014-02-14 08:05:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::OnFootprintSelected( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_fp_override = aEvent.GetString();
|
|
|
|
|
|
|
|
m_field_edits.erase(
|
|
|
|
std::remove_if( m_field_edits.begin(), m_field_edits.end(),
|
|
|
|
[]( std::pair<int, wxString> const& i ) { return i.first == FOOTPRINT; } ),
|
|
|
|
m_field_edits.end() );
|
|
|
|
|
|
|
|
m_field_edits.push_back( std::make_pair( FOOTPRINT, m_fp_override ) );
|
|
|
|
|
|
|
|
ShowFootprint( m_fp_override );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit )
|
2014-02-18 21:41:27 +00:00
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
wxPaintDC dc( m_sch_view_ctrl );
|
2015-08-30 14:46:34 +00:00
|
|
|
|
|
|
|
const wxSize dc_size = dc.GetSize();
|
|
|
|
|
|
|
|
// Avoid rendering when either dimension is zero
|
|
|
|
if( dc_size.x == 0 || dc_size.y == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
GRResetPenAndBrush( &dc );
|
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D bgColor = m_parent->GetDrawBgColor();
|
2014-10-09 00:49:29 +00:00
|
|
|
|
2017-02-20 16:57:41 +00:00
|
|
|
dc.SetBackground( wxBrush( bgColor.ToColour() ) );
|
2014-02-18 21:41:27 +00:00
|
|
|
dc.Clear();
|
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
if( !aComponent )
|
2014-02-18 21:41:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( aUnit <= 0 )
|
|
|
|
aUnit = 1;
|
|
|
|
|
|
|
|
dc.SetDeviceOrigin( dc_size.x / 2, dc_size.y / 2 );
|
|
|
|
|
|
|
|
// Find joint bounding box for everything we are about to draw.
|
2017-03-23 00:59:25 +00:00
|
|
|
EDA_RECT bBox = aComponent->GetUnitBoundingBox( aUnit, m_deMorganConvert );
|
2014-02-18 21:41:27 +00:00
|
|
|
const double xscale = (double) dc_size.x / bBox.GetWidth();
|
|
|
|
const double yscale = (double) dc_size.y / bBox.GetHeight();
|
2017-03-23 00:59:25 +00:00
|
|
|
const double scale = std::min( xscale, yscale ) * 0.85;
|
2014-02-18 21:41:27 +00:00
|
|
|
|
|
|
|
dc.SetUserScale( scale, scale );
|
|
|
|
|
2015-06-26 13:41:56 +00:00
|
|
|
wxPoint offset = -bBox.Centre();
|
2014-02-18 21:41:27 +00:00
|
|
|
|
2017-02-19 18:40:26 +00:00
|
|
|
auto opts = PART_DRAW_OPTIONS::Default();
|
2017-02-19 18:43:50 +00:00
|
|
|
opts.draw_hidden_fields = false;
|
2017-03-08 17:00:07 +00:00
|
|
|
aComponent->Draw( nullptr, &dc, offset, aUnit, m_deMorganConvert, opts );
|
2014-02-18 21:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-03 21:05:13 +00:00
|
|
|
void DIALOG_CHOOSE_COMPONENT::HandleItemSelection()
|
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
if( m_adapter->GetAliasFor( m_tree_ctrl->GetSelection() ) )
|
2017-03-03 21:05:13 +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.
|
|
|
|
m_dbl_click_timer->StartOnce( DIALOG_CHOOSE_COMPONENT::DblClickDelay );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-08 17:00:07 +00:00
|
|
|
auto const sel = m_tree_ctrl->GetSelection();
|
2017-03-03 21:05:13 +00:00
|
|
|
|
2017-03-08 17:00:07 +00:00
|
|
|
if( m_tree_ctrl->IsExpanded( sel ) )
|
|
|
|
m_tree_ctrl->Collapse( sel );
|
2017-03-03 21:05:13 +00:00
|
|
|
else
|
2017-03-08 17:00:07 +00:00
|
|
|
m_tree_ctrl->Expand( sel );
|
2017-03-03 21:05:13 +00:00
|
|
|
}
|
|
|
|
}
|