diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 091515a32e..1e19082675 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -27,7 +27,6 @@ set( EESCHEMA_DLGS dialogs/dialog_bom_base.cpp dialogs/dialog_bom_cfg_keywords.cpp dialogs/dialog_choose_component.cpp - dialogs/dialog_choose_component_base.cpp dialogs/dialog_lib_edit_text.cpp dialogs/dialog_lib_edit_text_base.cpp dialogs/dialog_edit_component_in_lib.cpp diff --git a/eeschema/dialogs/dialog_choose_component.cpp b/eeschema/dialogs/dialog_choose_component.cpp index 1b6f3a6f79..f5dc9765cc 100644 --- a/eeschema/dialogs/dialog_choose_component.cpp +++ b/eeschema/dialogs/dialog_choose_component.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller + * Copyright (C) 2017 Chris Pavlina * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -28,13 +29,25 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include #include #include #include -#include // Tree navigation helpers. static wxDataViewItem GetPrevItem( const wxDataViewCtrl& ctrl, const wxDataViewItem& item ); @@ -42,78 +55,148 @@ static wxDataViewItem GetNextItem( const wxDataViewCtrl& ctrl, const wxDataViewI static wxDataViewItem GetPrevSibling( const wxDataViewCtrl& ctrl, const wxDataViewItem& item ); static wxDataViewItem GetNextSibling( const wxDataViewCtrl& ctrl, const wxDataViewItem& item ); -DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle, - CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, - int aDeMorganConvert ) - : DIALOG_CHOOSE_COMPONENT_BASE( aParent, wxID_ANY, aTitle ), m_adapter( aAdapter ), - m_footprintPreviewPanel( nullptr ) +DIALOG_CHOOSE_COMPONENT::DIALOG_CHOOSE_COMPONENT( + SCH_BASE_FRAME* aParent, const wxString& aTitle, + CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert ): + DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, + wxSize( 800, 650 ), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ), + m_fp_viewer( nullptr ), + m_parent( aParent ), + m_adapter( aAdapter ), + m_deMorganConvert( aDeMorganConvert >= 0 ? aDeMorganConvert : 0 ), + m_external_browser_requested( false ) { - m_parent = aParent; - m_deMorganConvert = aDeMorganConvert >= 0 ? aDeMorganConvert : 0; - m_external_browser_requested = false; - m_adapter->AttachTo( m_libraryComponentTree ); - m_componentView->SetLayoutDirection( wxLayout_LeftToRight ); - m_dbl_click_timer = std::make_unique( this ); + auto sizer = new wxBoxSizer( wxVERTICAL ); - // Search box styling. wxSearchBox can handle this, but it's buggy... - m_searchBox->SetHint( _( "Search" ) ); - #if defined( __WXMAC__ ) || defined( __WINDOWS__ ) - { - // On Linux, the "Search" hint disappears when the dialog is focused, - // meaning it's not present initially when the dialog opens. To ensure - // the box is understood, a search icon is also provided. - // - // The icon provided by wx is ugly on macOS and Windows, *plus* these - // ports display the "Search" hint in the empty field even when the - // field is focused. Therefore, the icon is not required on these - // platforms. - m_searchBoxIcon->Hide(); - m_searchBoxIcon->GetParent()->Layout(); - } - #endif // __WXMAC__ + auto splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE ); + auto left_panel = ConstructLeftPanel( splitter ); + auto right_panel = ConstructRightPanel( splitter ); + auto buttons = new wxStdDialogButtonSizer(); + m_dbl_click_timer = new wxTimer( this ); - // Initialize footprint preview through Kiway - m_footprintPreviewPanel = - FOOTPRINT_PREVIEW_PANEL::InstallOnPanel( Kiway(), m_footprintView, true ); + splitter->SetSashGravity( 0.9 ); + splitter->SetMinimumPaneSize( 1 ); + splitter->SplitVertically( left_panel, right_panel, -300 ); - if( m_footprintPreviewPanel ) - { - // This hides the GAL panel and shows the status label - m_footprintPreviewPanel->SetStatusText( wxEmptyString ); - } + buttons->AddButton( new wxButton( this, wxID_OK ) ); + buttons->AddButton( new wxButton( this, wxID_CANCEL ) ); + buttons->Realize(); -#ifndef KICAD_FOOTPRINT_SELECTOR - // Footprint chooser isn't implemented yet or isn't selected, don't show it. - m_chooseFootprint->Hide(); - m_chooseFootprint->GetParent()->Layout(); -#endif + sizer->Add( splitter, 1, wxEXPAND | wxALL, 5 ); + sizer->Add( buttons, 0, wxEXPAND | wxBOTTOM, 10 ); + SetSizer( sizer ); + Bind( wxEVT_INIT_DIALOG, &DIALOG_CHOOSE_COMPONENT::OnInitDialog, this ); Bind( wxEVT_TIMER, &DIALOG_CHOOSE_COMPONENT::OnCloseTimer, this ); - Bind( wxEVT_CHAR_HOOK, &DIALOG_CHOOSE_COMPONENT::OnSearchBoxCharHook, this ); + + 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 ); + 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 ); + Layout(); Centre(); - - // Per warning in component_tree_search_container.h, this must be called - // near the end of the constructor. - m_adapter->UpdateSearchString( wxEmptyString ); - updateSelection(); } -DIALOG_CHOOSE_COMPONENT::~DIALOG_CHOOSE_COMPONENT() +wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructLeftPanel( wxWindow* aParent ) { - //m_search_container->SetTree( NULL ); + auto panel = new wxPanel( aParent ); + auto sizer = new wxBoxSizer( wxVERTICAL ); + auto search_sizer = new wxBoxSizer( wxHORIZONTAL ); + + m_query_ctrl = new wxTextCtrl( panel, wxID_ANY, + wxEmptyString, wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER ); + + m_tree_ctrl = new wxDataViewCtrl( panel, wxID_ANY, + wxDefaultPosition, wxDefaultSize, + wxDV_SINGLE ); + m_adapter->AttachTo( m_tree_ctrl ); + + m_details_ctrl = new wxHtmlWindow( panel, wxID_ANY, + wxDefaultPosition, wxSize( 320,240 ), + wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER ); + + // Additional visual cue for GTK, which hides the placeholder text on focus +#ifdef __WXGTK__ + search_sizer->Add( + new wxStaticBitmap( + panel, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ) ), + 0, wxALIGN_CENTER | wxALL, 5 ); +#endif + + search_sizer->Add( m_query_ctrl, 1, wxALIGN_CENTER | wxALL | wxEXPAND, 5 ); + + sizer->Add( search_sizer, 0, wxEXPAND, 5 ); + sizer->Add( m_tree_ctrl, 1, wxALL | wxEXPAND, 5 ); + sizer->Add( m_details_ctrl, 1, wxALL | wxEXPAND, 5 ); + + panel->SetSizer( sizer ); + panel->Layout(); + sizer->Fit( panel ); + return panel; } -void DIALOG_CHOOSE_COMPONENT::OnInitDialog( wxInitDialogEvent& event ) + +wxPanel* DIALOG_CHOOSE_COMPONENT::ConstructRightPanel( wxWindow* aParent ) { - m_searchBox->SetFocus(); + auto panel = new wxPanel( aParent ); + auto sizer = new wxBoxSizer( wxVERTICAL ); + + m_sch_view_ctrl = new wxPanel( panel, wxID_ANY, + wxDefaultPosition, wxSize( -1, -1 ), + wxFULL_REPAINT_ON_RESIZE | wxSUNKEN_BORDER | wxTAB_TRAVERSAL ); + m_sch_view_ctrl->SetLayoutDirection( wxLayout_LeftToRight ); + + m_fp_sel_ctrl = new wxChoice( panel, wxID_ANY ); + m_fp_sel_ctrl->SetSelection( 0 ); + + m_fp_view_ctrl = new wxPanel( panel, wxID_ANY, + wxDefaultPosition, wxSize( -1,-1 ), + wxFULL_REPAINT_ON_RESIZE | wxSUNKEN_BORDER | wxTAB_TRAVERSAL ); + + m_fp_viewer = FOOTPRINT_PREVIEW_PANEL::InstallOnPanel( Kiway(), m_fp_view_ctrl, true ); + + sizer->Add( m_sch_view_ctrl, 1, wxEXPAND | wxALL, 5 ); + sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxALL, 5 ); + sizer->Add( m_fp_view_ctrl, 1, wxEXPAND | wxALL, 5 ); + +#ifndef KICAD_FOOTPRINT_SELECTOR + m_fp_sel_ctrl->Hide(); +#endif + + panel->SetSizer( sizer ); + panel->Layout(); + sizer->Fit( panel ); + + return panel; +} + + +void DIALOG_CHOOSE_COMPONENT::OnInitDialog( wxInitDialogEvent& aEvent ) +{ + // 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 ); + + if( m_fp_viewer ) + { + // This hides the GAL panel and shows the status label + m_fp_viewer->SetStatusText( wxEmptyString ); + } } LIB_ALIAS* DIALOG_CHOOSE_COMPONENT::GetSelectedAlias( int* aUnit ) const { - auto sel = m_libraryComponentTree->GetSelection(); + auto sel = m_tree_ctrl->GetSelection(); if( aUnit && m_adapter->GetUnitFor( sel ) ) *aUnit = m_adapter->GetUnitFor( sel ); @@ -122,43 +205,53 @@ LIB_ALIAS* DIALOG_CHOOSE_COMPONENT::GetSelectedAlias( int* aUnit ) const } -void DIALOG_CHOOSE_COMPONENT::OnSearchBoxChange( wxCommandEvent& aEvent ) +void DIALOG_CHOOSE_COMPONENT::OnQueryText( wxCommandEvent& aEvent ) { - m_adapter->UpdateSearchString( m_searchBox->GetLineText( 0 ) ); - updateSelection(); + m_adapter->UpdateSearchString( m_query_ctrl->GetLineText( 0 ) ); + PostSelectEvent(); + + // Required to avoid interaction with SetHint() + // See documentation for wxTextEntry::SetHint + aEvent.Skip(); } -void DIALOG_CHOOSE_COMPONENT::OnSearchBoxEnter( wxCommandEvent& aEvent ) +void DIALOG_CHOOSE_COMPONENT::OnQueryEnter( wxCommandEvent& aEvent ) { HandleItemSelection(); } -void DIALOG_CHOOSE_COMPONENT::selectIfValid( const wxDataViewItem& aTreeId ) +void DIALOG_CHOOSE_COMPONENT::SelectIfValid( const wxDataViewItem& aTreeId ) { if( aTreeId.IsOk() ) { - m_libraryComponentTree->Select( aTreeId ); - m_libraryComponentTree->EnsureVisible( aTreeId ); + m_tree_ctrl->EnsureVisible( aTreeId ); + m_tree_ctrl->Select( aTreeId ); + PostSelectEvent(); } - - updateSelection(); } -void DIALOG_CHOOSE_COMPONENT::OnSearchBoxCharHook( wxKeyEvent& aKeyStroke ) +void DIALOG_CHOOSE_COMPONENT::PostSelectEvent() { - auto const sel = m_libraryComponentTree->GetSelection(); + wxDataViewEvent evt( wxEVT_DATAVIEW_SELECTION_CHANGED ); + m_tree_ctrl->GetEventHandler()->ProcessEvent( evt ); +} + + +void DIALOG_CHOOSE_COMPONENT::OnQueryCharHook( wxKeyEvent& aKeyStroke ) +{ + auto const sel = m_tree_ctrl->GetSelection(); switch( aKeyStroke.GetKeyCode() ) { case WXK_UP: - selectIfValid( GetPrevItem( *m_libraryComponentTree, sel ) ); + SelectIfValid( GetPrevItem( *m_tree_ctrl, sel ) ); break; case WXK_DOWN: - selectIfValid( GetNextItem( *m_libraryComponentTree, sel ) ); + SelectIfValid( GetNextItem( *m_tree_ctrl, sel ) ); break; default: @@ -170,13 +263,29 @@ void DIALOG_CHOOSE_COMPONENT::OnSearchBoxCharHook( wxKeyEvent& aKeyStroke ) void DIALOG_CHOOSE_COMPONENT::OnTreeSelect( wxDataViewEvent& aEvent ) { - updateSelection(); + auto sel = m_tree_ctrl->GetSelection(); + int unit = m_adapter->GetUnitFor( sel ); + LIB_ALIAS* alias = m_adapter->GetAliasFor( sel ); + + m_sch_view_ctrl->Refresh(); + + if( alias ) + { + m_details_ctrl->SetPage( GenerateAliasInfo( alias, unit ) ); + ShowFootprintFor( alias ); + } + else + { + m_details_ctrl->SetPage( wxEmptyString ); + + if( m_fp_viewer ) + m_fp_viewer->SetStatusText( wxEmptyString ); + } } void DIALOG_CHOOSE_COMPONENT::OnTreeActivate( wxDataViewEvent& aEvent ) { - updateSelection(); HandleItemSelection(); } @@ -202,54 +311,20 @@ void DIALOG_CHOOSE_COMPONENT::OnCloseTimer( wxTimerEvent& aEvent ) } -void DIALOG_CHOOSE_COMPONENT::OnStartComponentBrowser( wxMouseEvent& aEvent ) +void DIALOG_CHOOSE_COMPONENT::OnSchViewDClick( wxMouseEvent& aEvent ) { m_external_browser_requested = true; EndModal( wxID_OK ); } -bool DIALOG_CHOOSE_COMPONENT::updateSelection() +void DIALOG_CHOOSE_COMPONENT::ShowFootprintFor( LIB_ALIAS* aAlias ) { - auto sel = m_libraryComponentTree->GetSelection(); - int unit = m_adapter->GetUnitFor( sel ); - LIB_ALIAS* alias = m_adapter->GetAliasFor( sel ); - - m_componentView->Refresh(); - - if( alias == NULL ) - { - if( m_footprintPreviewPanel ) - { - m_footprintPreviewPanel->SetStatusText( wxEmptyString ); - } - - m_componentDetails->SetPage( wxEmptyString ); - - return false; - } - - m_componentDetails->SetPage( GenerateAliasInfo( alias, unit ) ); - - updateFootprint(); - - return true; -} - - -void DIALOG_CHOOSE_COMPONENT::updateFootprint() -{ - if( !m_footprintPreviewPanel ) - return; - - auto sel = m_libraryComponentTree->GetSelection(); - LIB_ALIAS* alias = m_adapter->GetAliasFor( sel ); - - if( !alias ) + if( !m_fp_viewer ) return; LIB_FIELDS fields; - alias->GetPart()->GetFields( fields ); + aAlias->GetPart()->GetFields( fields ); for( auto const & field: fields ) { @@ -258,33 +333,33 @@ void DIALOG_CHOOSE_COMPONENT::updateFootprint() wxString fpname = field.GetFullText(); if( fpname == wxEmptyString ) { - m_footprintPreviewPanel->SetStatusText( _( "No footprint specified" ) ); + m_fp_viewer->SetStatusText( _( "No footprint specified" ) ); } else { - m_footprintPreviewPanel->ClearStatus(); - m_footprintPreviewPanel->CacheFootprint( LIB_ID( fpname ) ); - m_footprintPreviewPanel->DisplayFootprint( LIB_ID( fpname ) ); + m_fp_viewer->ClearStatus(); + m_fp_viewer->CacheFootprint( LIB_ID( fpname ) ); + m_fp_viewer->DisplayFootprint( LIB_ID( fpname ) ); } break; } } -void DIALOG_CHOOSE_COMPONENT::OnDatasheetClick( wxHtmlLinkEvent& aEvent ) +void DIALOG_CHOOSE_COMPONENT::OnDetailsLink( wxHtmlLinkEvent& aEvent ) { const wxHtmlLinkInfo & info = aEvent.GetLinkInfo(); ::wxLaunchDefaultBrowser( info.GetHref() ); } -void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEvent ) +void DIALOG_CHOOSE_COMPONENT::OnSchViewPaint( wxPaintEvent& aEvent ) { - auto sel = m_libraryComponentTree->GetSelection(); + auto sel = m_tree_ctrl->GetSelection(); int unit = m_adapter->GetUnitFor( sel ); LIB_ALIAS* alias = m_adapter->GetAliasFor( sel ); - LIB_PART* part = alias ? alias->GetPart() : NULL; + LIB_PART* part = alias ? alias->GetPart() : nullptr; // Don't draw anything (not even the background) if we don't have // a part to show @@ -294,7 +369,7 @@ void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEven if( alias->IsRoot() ) { // just show the part directly - renderPreview( part, unit ); + RenderPreview( part, unit ); } else { @@ -302,18 +377,16 @@ void DIALOG_CHOOSE_COMPONENT::OnHandlePreviewRepaint( wxPaintEvent& aRepaintEven wxString tmp( part->GetName() ); part->SetName( alias->GetName() ); - renderPreview( part, unit ); + RenderPreview( part, unit ); part->SetName( tmp ); } } -// Render the preview in our m_componentView. If this gets more complicated, we should -// probably have a derived class from wxPanel; but this keeps things local. -void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit ) +void DIALOG_CHOOSE_COMPONENT::RenderPreview( LIB_PART* aComponent, int aUnit ) { - wxPaintDC dc( m_componentView ); + wxPaintDC dc( m_sch_view_ctrl ); const wxSize dc_size = dc.GetSize(); @@ -328,7 +401,7 @@ void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit ) dc.SetBackground( wxBrush( bgColor.ToColour() ) ); dc.Clear(); - if( aComponent == NULL ) + if( !aComponent ) return; if( aUnit <= 0 ) @@ -348,13 +421,13 @@ void DIALOG_CHOOSE_COMPONENT::renderPreview( LIB_PART* aComponent, int aUnit ) auto opts = PART_DRAW_OPTIONS::Default(); opts.draw_hidden_fields = false; - aComponent->Draw( NULL, &dc, offset, aUnit, m_deMorganConvert, opts ); + aComponent->Draw( nullptr, &dc, offset, aUnit, m_deMorganConvert, opts ); } void DIALOG_CHOOSE_COMPONENT::HandleItemSelection() { - if( m_adapter->GetAliasFor( m_libraryComponentTree->GetSelection() ) ) + if( m_adapter->GetAliasFor( m_tree_ctrl->GetSelection() ) ) { // 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 @@ -372,12 +445,12 @@ void DIALOG_CHOOSE_COMPONENT::HandleItemSelection() } else { - auto const sel = m_libraryComponentTree->GetSelection(); + auto const sel = m_tree_ctrl->GetSelection(); - if( m_libraryComponentTree->IsExpanded( sel ) ) - m_libraryComponentTree->Collapse( sel ); + if( m_tree_ctrl->IsExpanded( sel ) ) + m_tree_ctrl->Collapse( sel ); else - m_libraryComponentTree->Expand( sel ); + m_tree_ctrl->Expand( sel ); } } diff --git a/eeschema/dialogs/dialog_choose_component.h b/eeschema/dialogs/dialog_choose_component.h index b41ca48b00..f54863f171 100644 --- a/eeschema/dialogs/dialog_choose_component.h +++ b/eeschema/dialogs/dialog_choose_component.h @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2014 Henner Zeller + * Copyright (C) 2017 Chris Pavlina * Copyright (C) 2014-2017 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or @@ -24,10 +25,19 @@ #ifndef DIALOG_CHOOSE_COMPONENT_H #define DIALOG_CHOOSE_COMPONENT_H -#include +#include "dialog_shim.h" #include -#include -#include + +class wxStaticBitmap; +class wxTextCtrl; +class wxStdDialogButtonSizer; +class wxDataViewCtrl; +class wxHtmlWindow; +class wxHtmlLinkEvent; +class wxPanel; +class wxChoice; +class wxButton; +class wxTimer; class FOOTPRINT_PREVIEW_PANEL; class LIB_ALIAS; @@ -69,13 +79,8 @@ class SCH_BASE_FRAME; * } * */ -class DIALOG_CHOOSE_COMPONENT : public DIALOG_CHOOSE_COMPONENT_BASE +class DIALOG_CHOOSE_COMPONENT : public DIALOG_SHIM { - SCH_BASE_FRAME* m_parent; - CMP_TREE_MODEL_ADAPTER::PTR m_adapter; - int m_deMorganConvert; - bool m_external_browser_requested; - public: /** @@ -91,8 +96,6 @@ public: DIALOG_CHOOSE_COMPONENT( SCH_BASE_FRAME* aParent, const wxString& aTitle, CMP_TREE_MODEL_ADAPTER::PTR& aAdapter, int aDeMorganConvert ); - virtual ~DIALOG_CHOOSE_COMPONENT(); - void OnInitDialog( wxInitDialogEvent& event ) override; /** Function GetSelectedAlias * To be called after this dialog returns from ShowModal(). @@ -110,24 +113,47 @@ public: bool IsExternalBrowserSelected() const { return m_external_browser_requested; } protected: - virtual void OnSearchBoxChange( wxCommandEvent& aEvent ) override; - virtual void OnSearchBoxEnter( wxCommandEvent& aEvent ) override; - void OnSearchBoxCharHook( wxKeyEvent& aEvent ); - virtual void OnTreeSelect( wxDataViewEvent& aEvent ) override; - virtual void OnTreeActivate( wxDataViewEvent& aEvent ) override; + static constexpr int DblClickDelay = 100; // milliseconds - virtual void OnStartComponentBrowser( wxMouseEvent& aEvent ) override; - virtual void OnHandlePreviewRepaint( wxPaintEvent& aRepaintEvent ) override; - virtual void OnDatasheetClick( wxHtmlLinkEvent& aEvent ) override; + wxPanel* ConstructLeftPanel( wxWindow* aParent ); + wxPanel* ConstructRightPanel( wxWindow* aParent ); - virtual void OnCloseTimer( wxTimerEvent& aEvent ); + void OnInitDialog( wxInitDialogEvent& aEvent ); + void OnCloseTimer( wxTimerEvent& aEvent ); -private: - bool updateSelection(); - void updateFootprint(); - void selectIfValid( const wxDataViewItem& aTreeId ); - void renderPreview( LIB_PART* aComponent, int aUnit ); + void OnQueryText( wxCommandEvent& aEvent ); + void OnQueryEnter( wxCommandEvent& aEvent ); + void OnQueryCharHook( wxKeyEvent& aEvent ); + + void OnTreeSelect( wxDataViewEvent& aEvent ); + void OnTreeActivate( wxDataViewEvent& aEvent ); + + void OnDetailsLink( wxHtmlLinkEvent& aEvent ); + + void OnSchViewDClick( wxMouseEvent& aEvent ); + void OnSchViewPaint( wxPaintEvent& aEvent ); + + /** + * Look up the footprint for a given alias and display it. + */ + void ShowFootprintFor( LIB_ALIAS* aAlias ); + + /** + * 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 + * that a new part has been selected. + */ + void PostSelectEvent(); + + /** + * Display a given component into the schematic symbol preview. + */ + void RenderPreview( LIB_PART* aComponent, int aUnit ); /** * Handle the selection of an item. This is called when either the search @@ -137,10 +163,21 @@ private: */ void HandleItemSelection(); - std::unique_ptr m_dbl_click_timer; - FOOTPRINT_PREVIEW_PANEL* m_footprintPreviewPanel; + wxTimer* m_dbl_click_timer; + wxTextCtrl* m_query_ctrl; + wxDataViewCtrl* m_tree_ctrl; + wxHtmlWindow* m_details_ctrl; + wxPanel* m_sch_view_ctrl; + wxChoice* m_fp_sel_ctrl; + wxPanel* m_fp_view_ctrl; + + FOOTPRINT_PREVIEW_PANEL* m_fp_viewer; + + SCH_BASE_FRAME* m_parent; + CMP_TREE_MODEL_ADAPTER::PTR m_adapter; + int m_deMorganConvert; + bool m_external_browser_requested; - static constexpr int DblClickDelay = 100; // milliseconds }; #endif /* DIALOG_CHOOSE_COMPONENT_H */ diff --git a/eeschema/dialogs/dialog_choose_component_base.cpp b/eeschema/dialogs/dialog_choose_component_base.cpp deleted file mode 100644 index e7a7ef6427..0000000000 --- a/eeschema/dialogs/dialog_choose_component_base.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Feb 6 2017) -// http://www.wxformbuilder.org/ -// -// PLEASE DO "NOT" EDIT THIS FILE! -/////////////////////////////////////////////////////////////////////////// - -#include "dialog_choose_component_base.h" - -/////////////////////////////////////////////////////////////////////////// - -DIALOG_CHOOSE_COMPONENT_BASE::DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) -{ - this->SetSizeHints( wxSize( -1,-1 ), wxDefaultSize ); - - wxBoxSizer* bSizerMain; - bSizerMain = new wxBoxSizer( wxVERTICAL ); - - m_splitter1 = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_LIVE_UPDATE ); - m_splitter1->SetSashGravity( 0.9 ); - m_splitter1->Connect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::m_splitter1OnIdle ), NULL, this ); - m_splitter1->SetMinimumPaneSize( 1 ); - - m_panel3 = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* bSizer10; - bSizer10 = new wxBoxSizer( wxVERTICAL ); - - wxBoxSizer* m_searchBoxSizer; - m_searchBoxSizer = new wxBoxSizer( wxHORIZONTAL ); - - m_searchBoxIcon = new wxStaticBitmap( m_panel3, wxID_ANY, wxArtProvider::GetBitmap( wxART_FIND, wxART_FRAME_ICON ), wxDefaultPosition, wxDefaultSize, 0 ); - m_searchBoxSizer->Add( m_searchBoxIcon, 0, wxALIGN_CENTER|wxALL, 5 ); - - m_searchBox = new wxTextCtrl( m_panel3, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); - m_searchBoxSizer->Add( m_searchBox, 1, wxALIGN_CENTER|wxALL|wxEXPAND, 5 ); - - - bSizer10->Add( m_searchBoxSizer, 0, wxEXPAND, 5 ); - - m_libraryComponentTree = new wxDataViewCtrl( m_panel3, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_SINGLE ); - bSizer10->Add( m_libraryComponentTree, 1, wxALL|wxEXPAND, 5 ); - - m_componentDetails = new wxHtmlWindow( m_panel3, wxID_ANY, wxDefaultPosition, wxSize( 320,240 ), wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER ); - bSizer10->Add( m_componentDetails, 1, wxALL|wxEXPAND, 5 ); - - - m_panel3->SetSizer( bSizer10 ); - m_panel3->Layout(); - bSizer10->Fit( m_panel3 ); - m_panel4 = new wxPanel( m_splitter1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); - wxBoxSizer* bSizer11; - bSizer11 = new wxBoxSizer( wxVERTICAL ); - - wxBoxSizer* bSizer12; - bSizer12 = new wxBoxSizer( wxVERTICAL ); - - m_componentView = new wxPanel( m_panel4, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); - bSizer12->Add( m_componentView, 1, wxEXPAND | wxALL, 5 ); - - wxBoxSizer* bSizer13; - bSizer13 = new wxBoxSizer( wxVERTICAL ); - - wxBoxSizer* bSizer14; - bSizer14 = new wxBoxSizer( wxHORIZONTAL ); - - wxArrayString m_chooseFootprintChoices; - m_chooseFootprint = new wxChoice( m_panel4, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_chooseFootprintChoices, 0 ); - m_chooseFootprint->SetSelection( 0 ); - bSizer14->Add( m_chooseFootprint, 1, wxALL|wxEXPAND, 5 ); - - - bSizer13->Add( bSizer14, 0, wxEXPAND, 5 ); - - m_footprintView = new wxPanel( m_panel4, wxID_ANY, wxDefaultPosition, wxSize( -1,-1 ), wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL ); - bSizer13->Add( m_footprintView, 1, wxEXPAND | wxALL, 5 ); - - - bSizer12->Add( bSizer13, 1, wxEXPAND, 5 ); - - - bSizer11->Add( bSizer12, 1, wxEXPAND, 5 ); - - - m_panel4->SetSizer( bSizer11 ); - m_panel4->Layout(); - bSizer11->Fit( m_panel4 ); - m_splitter1->SplitVertically( m_panel3, m_panel4, -300 ); - bSizerMain->Add( m_splitter1, 1, wxALL|wxEXPAND, 5 ); - - m_stdButtons = new wxStdDialogButtonSizer(); - m_stdButtonsOK = new wxButton( this, wxID_OK ); - m_stdButtons->AddButton( m_stdButtonsOK ); - m_stdButtonsCancel = new wxButton( this, wxID_CANCEL ); - m_stdButtons->AddButton( m_stdButtonsCancel ); - m_stdButtons->Realize(); - - bSizerMain->Add( m_stdButtons, 0, wxBOTTOM|wxEXPAND, 10 ); - - - this->SetSizer( bSizerMain ); - this->Layout(); - - this->Centre( wxBOTH ); - - // Connect Events - this->Connect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnIdle ) ); - this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInitDialog ) ); - m_searchBox->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxChange ), NULL, this ); - m_searchBox->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxEnter ), NULL, this ); - m_libraryComponentTree->Connect( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeActivate ), NULL, this ); - m_libraryComponentTree->Connect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); - m_componentDetails->Connect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDatasheetClick ), NULL, this ); - m_componentView->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); - m_componentView->Connect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); -} - -DIALOG_CHOOSE_COMPONENT_BASE::~DIALOG_CHOOSE_COMPONENT_BASE() -{ - // Disconnect Events - this->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnIdle ) ); - this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnInitDialog ) ); - m_searchBox->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxChange ), NULL, this ); - m_searchBox->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnSearchBoxEnter ), NULL, this ); - m_libraryComponentTree->Disconnect( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeActivate ), NULL, this ); - m_libraryComponentTree->Disconnect( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnTreeSelect ), NULL, this ); - m_componentDetails->Disconnect( wxEVT_COMMAND_HTML_LINK_CLICKED, wxHtmlLinkEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnDatasheetClick ), NULL, this ); - m_componentView->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnStartComponentBrowser ), NULL, this ); - m_componentView->Disconnect( wxEVT_PAINT, wxPaintEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::OnHandlePreviewRepaint ), NULL, this ); - -} diff --git a/eeschema/dialogs/dialog_choose_component_base.fbp b/eeschema/dialogs/dialog_choose_component_base.fbp deleted file mode 100644 index 0a1acde0bb..0000000000 --- a/eeschema/dialogs/dialog_choose_component_base.fbp +++ /dev/null @@ -1,997 +0,0 @@ - - - - - - C++ - 1 - source_name - 0 - 0 - res - UTF-8 - connect - dialog_choose_component_base - 1000 - none - 1 - dialog_choose_component_base - - . - - 1 - 1 - 1 - 1 - UI - 0 - 0 - - 0 - wxAUI_MGR_DEFAULT - - wxBOTH - - 1 - 1 - impl_virtual - - - - 0 - wxID_ANY - - -1,-1 - DIALOG_CHOOSE_COMPONENT_BASE - - 800,650 - wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER - DIALOG_SHIM; dialog_shim.h - - - - - - - - - - - - - - - - - - - - OnIdle - OnInitDialog - - - - - - - - - - - - - - - - - - - - - - - bSizerMain - wxVERTICAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - 1 - - 0 - - 1 - m_splitter1 - 1 - - - protected - 1 - - Resizable - 0.9 - -300 - -1 - 1 - - wxSPLIT_VERTICAL - wxSP_LIVE_UPDATE - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_panel3 - 1 - - - protected - 1 - - Resizable - 1 - - - 0 - - - - wxTAB_TRAVERSAL - - - - - - - - - - - - - - - - - - - - - - - - - - bSizer10 - wxVERTICAL - none - - 5 - wxEXPAND - 0 - - - m_searchBoxSizer - wxHORIZONTAL - none - - 5 - wxALIGN_CENTER|wxALL - 0 - - 1 - 1 - 1 - 1 - - - - - - - Load From Art Provider; wxART_FIND; wxART_FRAME_ICON - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_searchBoxIcon - 1 - - - protected - 1 - - Resizable - 1 - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER|wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - - 0 - - 1 - m_searchBox - 1 - - - protected - 1 - - Resizable - 1 - - wxTE_PROCESS_ENTER - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - OnSearchBoxChange - OnSearchBoxEnter - - - - - - - - - 5 - wxALL|wxEXPAND - 1 - - - - 1 - 1 - - - 0 - wxID_ANY - - - m_libraryComponentTree - protected - - - wxDV_SINGLE - - - - - - - - - - - OnTreeActivate - - - - - - - - - - - - - OnTreeSelect - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_componentDetails - 1 - - - protected - 1 - - Resizable - 1 - 320,240 - wxHW_SCROLLBAR_AUTO - - 0 - - - - wxSUNKEN_BORDER - - - - - - OnDatasheetClick - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_panel4 - 1 - - - protected - 1 - - Resizable - 1 - - - 0 - - - - wxTAB_TRAVERSAL - - - - - - - - - - - - - - - - - - - - - - - - - - bSizer11 - wxVERTICAL - none - - 5 - wxEXPAND - 1 - - - bSizer12 - wxVERTICAL - none - - 5 - wxEXPAND | wxALL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_componentView - 1 - - - protected - 1 - - Resizable - 1 - -1,-1 - - 0 - - - - wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL - - - - - - - - OnStartComponentBrowser - - - - - - - - - OnHandlePreviewRepaint - - - - - - - - - - 5 - wxEXPAND - 1 - - - bSizer13 - wxVERTICAL - none - - 5 - wxEXPAND - 0 - - - bSizer14 - wxHORIZONTAL - none - - 5 - wxALL|wxEXPAND - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_chooseFootprint - 1 - - - protected - 1 - - Resizable - 0 - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND | wxALL - 1 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - - 0 - - 1 - m_footprintView - 1 - - - protected - 1 - - Resizable - 1 - -1,-1 - - 0 - - - - wxFULL_REPAINT_ON_RESIZE|wxSUNKEN_BORDER|wxTAB_TRAVERSAL - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 10 - wxBOTTOM|wxEXPAND - 0 - - 0 - 1 - 0 - 0 - 0 - 1 - 0 - 0 - - m_stdButtons - protected - - - - - - - - - - - - - - diff --git a/eeschema/dialogs/dialog_choose_component_base.h b/eeschema/dialogs/dialog_choose_component_base.h deleted file mode 100644 index 15436575d4..0000000000 --- a/eeschema/dialogs/dialog_choose_component_base.h +++ /dev/null @@ -1,86 +0,0 @@ -/////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Feb 6 2017) -// http://www.wxformbuilder.org/ -// -// PLEASE DO "NOT" EDIT THIS FILE! -/////////////////////////////////////////////////////////////////////////// - -#ifndef __DIALOG_CHOOSE_COMPONENT_BASE_H__ -#define __DIALOG_CHOOSE_COMPONENT_BASE_H__ - -#include -#include -#include -class DIALOG_SHIM; - -#include "dialog_shim.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/////////////////////////////////////////////////////////////////////////// - - -/////////////////////////////////////////////////////////////////////////////// -/// Class DIALOG_CHOOSE_COMPONENT_BASE -/////////////////////////////////////////////////////////////////////////////// -class DIALOG_CHOOSE_COMPONENT_BASE : public DIALOG_SHIM -{ - private: - - protected: - wxSplitterWindow* m_splitter1; - wxPanel* m_panel3; - wxStaticBitmap* m_searchBoxIcon; - wxTextCtrl* m_searchBox; - wxDataViewCtrl* m_libraryComponentTree; - wxHtmlWindow* m_componentDetails; - wxPanel* m_panel4; - wxPanel* m_componentView; - wxChoice* m_chooseFootprint; - wxPanel* m_footprintView; - wxStdDialogButtonSizer* m_stdButtons; - wxButton* m_stdButtonsOK; - wxButton* m_stdButtonsCancel; - - // Virtual event handlers, overide them in your derived class - virtual void OnIdle( wxIdleEvent& event ) { event.Skip(); } - virtual void OnInitDialog( wxInitDialogEvent& event ) { event.Skip(); } - virtual void OnSearchBoxChange( wxCommandEvent& event ) { event.Skip(); } - virtual void OnSearchBoxEnter( wxCommandEvent& event ) { event.Skip(); } - virtual void OnTreeActivate( wxDataViewEvent& event ) { event.Skip(); } - virtual void OnTreeSelect( wxDataViewEvent& event ) { event.Skip(); } - virtual void OnDatasheetClick( wxHtmlLinkEvent& event ) { event.Skip(); } - virtual void OnStartComponentBrowser( wxMouseEvent& event ) { event.Skip(); } - virtual void OnHandlePreviewRepaint( wxPaintEvent& event ) { event.Skip(); } - - - public: - - DIALOG_CHOOSE_COMPONENT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 800,650 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); - ~DIALOG_CHOOSE_COMPONENT_BASE(); - - void m_splitter1OnIdle( wxIdleEvent& ) - { - m_splitter1->SetSashPosition( -300 ); - m_splitter1->Disconnect( wxEVT_IDLE, wxIdleEventHandler( DIALOG_CHOOSE_COMPONENT_BASE::m_splitter1OnIdle ), NULL, this ); - } - -}; - -#endif //__DIALOG_CHOOSE_COMPONENT_BASE_H__