KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_symbol_chooser.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014 Henner Zeller <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26
27#include <pgm_base.h>
28#include <kiface_base.h>
29#include <sch_base_frame.h>
30#include <project_sch.h>
31#include <widgets/lib_tree.h>
37#include <eeschema_settings.h>
39#include <symbol_library.h> // For SYMBOL_LIBRARY_FILTER
40#include <symbol_lib_table.h>
41#include <wx/button.h>
42#include <wx/clipbrd.h>
43#include <wx/panel.h>
44#include <wx/sizer.h>
45#include <wx/splitter.h>
46#include <wx/timer.h>
47#include <wx/wxhtml.h>
48#include <wx/log.h>
49
50
53
54
56 const SYMBOL_LIBRARY_FILTER* aFilter,
57 std::vector<PICKED_SYMBOL>& aHistoryList,
58 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
59 bool aAllowFieldEdits, bool aShowFootprints,
60 std::function<void()> aAcceptHandler,
61 std::function<void()> aEscapeHandler ) :
62 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
63 m_symbol_preview( nullptr ),
64 m_hsplitter( nullptr ),
65 m_vsplitter( nullptr ),
66 m_fp_sel_ctrl( nullptr ),
67 m_fp_preview( nullptr ),
68 m_tree( nullptr ),
69 m_details( nullptr ),
70 m_frame( aFrame ),
71 m_acceptHandler( std::move( aAcceptHandler ) ),
72 m_escapeHandler( std::move( aEscapeHandler ) ),
73 m_showPower( false ),
74 m_allow_field_edits( aAllowFieldEdits ),
75 m_show_footprints( aShowFootprints )
76{
80
81 // Make sure settings are loaded before we start running multi-threaded symbol loaders
84
86 SYMBOL_TREE_MODEL_ADAPTER* adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( m_adapter.get() );
87 bool loaded = false;
88
89 if( aFilter )
90 {
91 const wxArrayString& liblist = aFilter->GetAllowedLibList();
92
93 for( const wxString& nickname : liblist )
94 {
95 if( libs->HasLibrary( nickname, true ) )
96 {
97 loaded = true;
98
99 bool pinned = alg::contains( session.pinned_symbol_libs, nickname )
100 || alg::contains( project.m_PinnedSymbolLibs, nickname );
101
102 SYMBOL_LIB_TABLE_ROW* row = libs->FindRow( nickname );
103
104 if( row && row->GetIsVisible() )
105 adapter->AddLibrary( nickname, pinned );
106 }
107 }
108
109 adapter->AssignIntrinsicRanks();
110
111 if( aFilter->GetFilterPowerSymbols() )
112 {
113 // HACK ALERT: when loading symbols we presume that *any* filter is a power symbol
114 // filter. So the filter only needs to return true for libraries.
115 static std::function<bool( LIB_TREE_NODE& )> powerFilter =
116 []( LIB_TREE_NODE& aNode ) -> bool
117 {
118 return true;
119 };
120
121 adapter->SetFilter( &powerFilter );
122
123 m_showPower = true;
124 m_show_footprints = false;
125 }
126 }
127
128 std::vector<LIB_SYMBOL> history_list_storage;
129 std::vector<LIB_TREE_ITEM*> history_list;
130 std::vector<LIB_SYMBOL> already_placed_storage;
131 std::vector<LIB_TREE_ITEM*> already_placed;
132
133 // Lambda to encapsulate the common logic
134 auto processList =
135 [&]( const std::vector<PICKED_SYMBOL>& inputList,
136 std::vector<LIB_SYMBOL>& storageList,
137 std::vector<LIB_TREE_ITEM*>& resultList )
138 {
139 storageList.reserve( inputList.size() );
140
141 for( const PICKED_SYMBOL& i : inputList )
142 {
143 LIB_SYMBOL* symbol = m_frame->GetLibSymbol( i.LibId );
144
145 if( symbol )
146 {
147 storageList.emplace_back( *symbol );
148
149 for( const std::pair<int, wxString>& fieldDef : i.Fields )
150 {
151 SCH_FIELD* field = storageList.back().GetFieldById( fieldDef.first );
152
153 if( field )
154 field->SetText( fieldDef.second );
155 }
156
157 resultList.push_back( &storageList.back() );
158 }
159 }
160 };
161
162 // Sort the already placed list since it is potentially from multiple sessions,
163 // but not the most recent list since we want this listed by most recent usage.
164 std::sort( aAlreadyPlaced.begin(), aAlreadyPlaced.end(),
165 []( PICKED_SYMBOL const& a, PICKED_SYMBOL const& b )
166 {
167 return a.LibId.GetLibItemName() < b.LibId.GetLibItemName();
168 } );
169
170 processList( aHistoryList, history_list_storage, history_list );
171 processList( aAlreadyPlaced, already_placed_storage, already_placed );
172
173 adapter->DoAddLibrary( wxT( "-- " ) + _( "Recently Used" ) + wxT( " --" ), wxEmptyString,
174 history_list, false, true )
175 .m_IsRecentlyUsedGroup = true;
176
177 if( !aHistoryList.empty() )
178 adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
179
180 adapter->DoAddLibrary( wxT( "-- " ) + _( "Already Placed" ) + wxT( " --" ), wxEmptyString,
181 already_placed, false, true )
183
184 const std::vector< wxString > libNicknames = libs->GetLogicalLibs();
185
186 if( !loaded )
187 {
188 if( !adapter->AddLibraries( libNicknames, m_frame ) )
189 {
190 // loading cancelled by user
192 }
193 }
194
195 // -------------------------------------------------------------------------------------
196 // Construct the actual panel
197 //
198
199 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
200
201 // Use a slightly different layout, with a details pane spanning the entire window,
202 // if we're not showing footprints.
204 {
205 m_hsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
206 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
207
208 //Avoid the splitter window being assigned as the Parent to additional windows
209 m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
210
211 sizer->Add( m_hsplitter, 1, wxEXPAND, 5 );
212 }
213 else
214 {
215 m_vsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
216 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
217
218 m_hsplitter = new wxSplitterWindow( m_vsplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
219 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
220
221 // Avoid the splitter window being assigned as the parent to additional windows.
222 m_vsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
223 m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
224
225 wxPanel* detailsPanel = new wxPanel( m_vsplitter );
226 wxBoxSizer* detailsSizer = new wxBoxSizer( wxVERTICAL );
227 detailsPanel->SetSizer( detailsSizer );
228
229 m_details = new HTML_WINDOW( detailsPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize );
230 detailsSizer->Add( m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
231 detailsPanel->Layout();
232 detailsSizer->Fit( detailsPanel );
233
234 m_vsplitter->SetSashGravity( 0.5 );
235 m_vsplitter->SetMinimumPaneSize( 20 );
236 m_vsplitter->SplitHorizontally( m_hsplitter, detailsPanel );
237
238 sizer->Add( m_vsplitter, 1, wxEXPAND | wxBOTTOM, 5 );
239 }
240
241 wxPanel* treePanel = new wxPanel( m_hsplitter );
242 wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL );
243 treePanel->SetSizer( treeSizer );
244
245 m_tree = new LIB_TREE( treePanel, m_showPower ? wxT( "power" ) : wxT( "symbols" ),
247
248 treeSizer->Add( m_tree, 1, wxALL | wxEXPAND, 5 );
249 treePanel->Layout();
250 treeSizer->Fit( treePanel );
251
252 m_adapter->FinishTreeInitialization();
253
254 if( m_showPower )
256 else
258
259 m_hsplitter->SetSashGravity( 0.8 );
260 m_hsplitter->SetMinimumPaneSize( 20 );
261 m_hsplitter->SplitVertically( treePanel, constructRightPanel( m_hsplitter ) );
262
263 m_dbl_click_timer = new wxTimer( this );
264 m_open_libs_timer = new wxTimer( this );
265
266 SetSizer( sizer );
267
268 Layout();
269
270 Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onCloseTimer, this, m_dbl_click_timer->GetId() );
271 Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onOpenLibsTimer, this, m_open_libs_timer->GetId() );
272 Bind( EVT_LIBITEM_SELECTED, &PANEL_SYMBOL_CHOOSER::onSymbolSelected, this );
273 Bind( EVT_LIBITEM_CHOSEN, &PANEL_SYMBOL_CHOOSER::onSymbolChosen, this );
274 Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, this );
275 aFrame->Bind( wxEVT_MENU_OPEN, &PANEL_SYMBOL_CHOOSER::onMenuOpen, this );
276 aFrame->Bind( wxEVT_MENU_CLOSE, &PANEL_SYMBOL_CHOOSER::onMenuClose, this );
277
278 if( m_fp_sel_ctrl )
279 {
280 m_fp_sel_ctrl->Bind( EVT_FOOTPRINT_SELECTED, &PANEL_SYMBOL_CHOOSER::onFootprintSelected,
281 this );
282 }
283
284 if( m_details )
285 {
286 m_details->Connect( wxEVT_CHAR_HOOK,
287 wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
288 nullptr, this );
289 }
290
291 // Open the user's previously opened libraries on timer expiration.
292 // This is done on a timer because we need a gross hack to keep GTK from garbling the
293 // display. Must be longer than the search debounce timer.
294 m_open_libs_timer->StartOnce( 300 );
295}
296
297
299{
300 m_frame->Unbind( wxEVT_MENU_OPEN, &PANEL_SYMBOL_CHOOSER::onMenuOpen, this );
301 m_frame->Unbind( wxEVT_MENU_CLOSE, &PANEL_SYMBOL_CHOOSER::onMenuClose, this );
302 Unbind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onCloseTimer, this );
303 Unbind( EVT_LIBITEM_SELECTED, &PANEL_SYMBOL_CHOOSER::onSymbolSelected, this );
304 Unbind( EVT_LIBITEM_CHOSEN, &PANEL_SYMBOL_CHOOSER::onSymbolChosen, this );
305 Unbind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, this );
306
307 // Stop the timer during destruction early to avoid potential race conditions (that do happen)
308 m_dbl_click_timer->Stop();
309 m_open_libs_timer->Stop();
310 delete m_dbl_click_timer;
311 delete m_open_libs_timer;
312
313 if( m_showPower )
315 else
317
318 if( m_fp_sel_ctrl )
319 {
320 m_fp_sel_ctrl->Unbind( EVT_FOOTPRINT_SELECTED, &PANEL_SYMBOL_CHOOSER::onFootprintSelected,
321 this );
322 }
323
324 if( m_details )
325 {
326 m_details->Disconnect( wxEVT_CHAR_HOOK,
327 wxKeyEventHandler( PANEL_SYMBOL_CHOOSER::OnDetailsCharHook ),
328 nullptr, this );
329 }
330
331 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
332 {
333 // Save any changes to column widths, etc.
334 m_adapter->SaveSettings();
335
336 cfg->m_SymChooserPanel.width = GetParent()->GetSize().x;
337 cfg->m_SymChooserPanel.height = GetParent()->GetSize().y;
338
339 cfg->m_SymChooserPanel.sash_pos_h = m_hsplitter->GetSashPosition();
340
341 if( m_vsplitter )
342 cfg->m_SymChooserPanel.sash_pos_v = m_vsplitter->GetSashPosition();
343
344 cfg->m_SymChooserPanel.sort_mode = m_tree->GetSortMode();
345 }
346}
347
348
349void PANEL_SYMBOL_CHOOSER::onMenuOpen( wxMenuEvent& aEvent )
350{
351 m_tree->BlockPreview( true );
352 aEvent.Skip();
353}
354
355
356void PANEL_SYMBOL_CHOOSER::onMenuClose( wxMenuEvent& aEvent )
357{
358 m_tree->BlockPreview( false );
359 aEvent.Skip();
360}
361
362
363void PANEL_SYMBOL_CHOOSER::OnChar( wxKeyEvent& aEvent )
364{
365 if( aEvent.GetKeyCode() == WXK_ESCAPE )
366 {
367 wxObject* eventSource = aEvent.GetEventObject();
368
369 if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( eventSource ) )
370 {
371 // First escape cancels search string value
372 if( textCtrl->GetValue() == m_tree->GetSearchString()
373 && !m_tree->GetSearchString().IsEmpty() )
374 {
375 m_tree->SetSearchString( wxEmptyString );
376 return;
377 }
378 }
379
381 }
382 else
383 {
384 aEvent.Skip();
385 }
386}
387
388
389wxPanel* PANEL_SYMBOL_CHOOSER::constructRightPanel( wxWindow* aParent )
390{
392
393 if( m_frame->GetCanvas() )
394 {
395 backend = m_frame->GetCanvas()->GetBackend();
396 }
397 else
398 {
400 EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
401
403 }
404
405 wxPanel* panel = new wxPanel( aParent );
406 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
407
408 m_symbol_preview = new SYMBOL_PREVIEW_WIDGET( panel, &m_frame->Kiway(), true, backend );
409 m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
410
412 {
414
415 sizer->Add( m_symbol_preview, 11, wxEXPAND | wxALL, 5 );
416
417 if ( fp_list )
418 {
420 m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( m_frame, panel, fp_list, true );
421
424 }
425
426 if( m_fp_sel_ctrl )
427 sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
428
429 if( m_fp_preview )
430 sizer->Add( m_fp_preview, 10, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
431 }
432 else
433 {
434 sizer->Add( m_symbol_preview, 1, wxEXPAND | wxALL, 5 );
435 }
436
437 panel->SetSizer( sizer );
438 panel->Layout();
439 sizer->Fit( panel );
440
441 return panel;
442}
443
444
446{
447 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
448 {
449 auto horizPixelsFromDU =
450 [&]( int x ) -> int
451 {
452 wxSize sz( x, 0 );
453 return GetParent()->ConvertDialogToPixels( sz ).x;
454 };
455
456 EESCHEMA_SETTINGS::PANEL_SYM_CHOOSER& panelCfg = cfg->m_SymChooserPanel;
457
458 int w = panelCfg.width > 40 ? panelCfg.width : horizPixelsFromDU( 440 );
459 int h = panelCfg.height > 40 ? panelCfg.height : horizPixelsFromDU( 340 );
460
461 GetParent()->SetSize( wxSize( w, h ) );
462 GetParent()->Layout();
463
464 // We specify the width of the right window (m_symbol_view_panel), because specify
465 // the width of the left window does not work as expected when SetSashGravity() is called
466
467 if( panelCfg.sash_pos_h < 0 )
468 panelCfg.sash_pos_h = horizPixelsFromDU( 220 );
469
470 if( panelCfg.sash_pos_v < 0 )
471 panelCfg.sash_pos_v = horizPixelsFromDU( 230 );
472
473 m_hsplitter->SetSashPosition( panelCfg.sash_pos_h );
474
475 if( m_vsplitter )
476 m_vsplitter->SetSashPosition( panelCfg.sash_pos_v );
477
478 m_adapter->SetSortMode( (LIB_TREE_MODEL_ADAPTER::SORT_MODE) panelCfg.sort_mode );
479 }
480
482 {
483 // This hides the GAL panel and shows the status label
484 m_fp_preview->SetStatusText( wxEmptyString );
485 }
486
487 if( m_fp_sel_ctrl )
489}
490
491
493{
494 if( m_details && e.GetKeyCode() == 'C' && e.ControlDown() &&
495 !e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
496 {
497 wxString txt = m_details->SelectionToText();
498 wxLogNull doNotLog; // disable logging of failed clipboard actions
499
500 if( wxTheClipboard->Open() )
501 {
502 wxTheClipboard->SetData( new wxTextDataObject( txt ) );
503 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
504 wxTheClipboard->Close();
505 }
506 }
507 else
508 {
509 e.Skip();
510 }
511}
512
513
515{
516 m_adapter->SetPreselectNode( aPreselect, 0 );
517}
518
519
521{
522 return m_tree->GetSelectedLibId( aUnit );
523}
524
525
526void PANEL_SYMBOL_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
527{
528 // Hack because of eaten MouseUp event. See PANEL_SYMBOL_CHOOSER::onSymbolChosen
529 // for the beginning of this spaghetti noodle.
530
531 wxMouseState state = wxGetMouseState();
532
533 if( state.LeftIsDown() )
534 {
535 // Mouse hasn't been raised yet, so fire the timer again. Otherwise the
536 // purpose of this timer is defeated.
538 }
539 else
540 {
542 }
543}
544
545
546void PANEL_SYMBOL_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
547{
548 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
549 m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
550}
551
552
554{
556 return;
557
558 LIB_SYMBOL* symbol = nullptr;
559
560 try
561 {
562 symbol = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->LoadSymbol( aLibId );
563 }
564 catch( const IO_ERROR& ioe )
565 {
566 wxLogError( _( "Error loading symbol %s from library '%s'." ) + wxS( "\n%s" ),
567 aLibId.GetLibItemName().wx_str(),
568 aLibId.GetLibNickname().wx_str(),
569 ioe.What() );
570 }
571
572 if( !symbol )
573 return;
574
575 SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
576 wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
577
578 showFootprint( fp_name );
579}
580
581
582void PANEL_SYMBOL_CHOOSER::showFootprint( wxString const& aFootprint )
583{
585 return;
586
587 if( aFootprint == wxEmptyString )
588 {
589 m_fp_preview->SetStatusText( _( "No footprint specified" ) );
590 }
591 else
592 {
593 LIB_ID lib_id;
594
595 if( lib_id.Parse( aFootprint ) == -1 && lib_id.IsValid() )
596 {
599 }
600 else
601 {
602 m_fp_preview->SetStatusText( _( "Invalid footprint specified" ) );
603 }
604 }
605}
606
607
609{
610 if( !m_fp_sel_ctrl )
611 return;
612
614
615 LIB_SYMBOL* symbol = nullptr;
616
617 if( aLibId.IsValid() )
618 {
619 try
620 {
621 symbol = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->LoadSymbol( aLibId );
622 }
623 catch( const IO_ERROR& ioe )
624 {
625 wxLogError( _( "Error loading symbol %s from library '%s'." ) + wxS( "\n%s" ),
626 aLibId.GetLibItemName().wx_str(),
627 aLibId.GetLibNickname().wx_str(),
628 ioe.What() );
629 }
630 }
631
632 if( symbol != nullptr )
633 {
634 int pinCount = symbol->GetPins( 0 /* all units */, 1 /* single bodyStyle */ ).size();
635 SCH_FIELD* fp_field = symbol->GetFieldById( FOOTPRINT_FIELD );
636 wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
637
638 m_fp_sel_ctrl->FilterByPinCount( pinCount );
643 }
644 else
645 {
647 m_fp_sel_ctrl->Disable();
648 }
649}
650
651
652void PANEL_SYMBOL_CHOOSER::onFootprintSelected( wxCommandEvent& aEvent )
653{
654 m_fp_override = aEvent.GetString();
655
656 alg::delete_if( m_field_edits, []( std::pair<int, wxString> const& i )
657 {
658 return i.first == FOOTPRINT_FIELD;
659 } );
660
661 m_field_edits.emplace_back( std::make_pair( FOOTPRINT_FIELD, m_fp_override ) );
662
664}
665
666
667void PANEL_SYMBOL_CHOOSER::onSymbolSelected( wxCommandEvent& aEvent )
668{
670
671 if( node && node->m_LibId.IsValid() )
672 {
674
675 if( !node->m_Footprint.IsEmpty() )
676 showFootprint( node->m_Footprint );
677 else
678 showFootprintFor( node->m_LibId );
679
681 }
682 else
683 {
684 m_symbol_preview->SetStatusText( _( "No symbol selected" ) );
685
687 m_fp_preview->SetStatusText( wxEmptyString );
688
690 }
691}
692
693
694void PANEL_SYMBOL_CHOOSER::onSymbolChosen( wxCommandEvent& aEvent )
695{
697 {
698 // Got a selection. We can't just end the modal dialog here, because wx leaks some events
699 // back to the parent window (in particular, the MouseUp following a double click).
700 //
701 // NOW, here's where it gets really fun. wxTreeListCtrl eats MouseUp. This isn't really
702 // feasible to bypass without a fully custom wxDataViewCtrl implementation, and even then
703 // might not be fully possible (docs are vague). To get around this, we use a one-shot
704 // timer to schedule the dialog close.
705 //
706 // See PANEL_SYMBOL_CHOOSER::onCloseTimer for the other end of this spaghetti noodle.
708 }
709}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
Holds a list of FOOTPRINT_INFO objects, along with a list of IO_ERRORs or PARSE_ERRORs that were thro...
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
void DisplayFootprint(const LIB_ID &aFPID)
Set the currently displayed footprint.
void SetUserUnits(EDA_UNITS aUnits)
Set the units for the preview.
bool IsInitialized() const
Return whether the widget initialized properly.
void SetStatusText(const wxString &aText)
Set the contents of the status label and display it.
void ClearStatus()
Clear the contents of the status label and hide it.
virtual bool Enable(bool aEnable=true) override
Enable or disable the control for input.
void FilterByFootprintFilters(const wxArrayString &aFilters, bool aZeroFilters)
Filter by footprint filter list.
void SetDefaultFootprint(const wxString &aFp)
Set the default footprint for a part.
void FilterByPinCount(int aPinCount)
Filter by pin count.
bool UpdateList()
Update the contents of the list to match the filters.
void ClearFilters()
Clear all filters.
void Load(KIWAY &aKiway, PROJECT &aProject)
Start loading.
Add dark theme support to wxHtmlWindow.
Definition: html_window.h:35
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:55
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:172
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
Define a library symbol object.
Definition: lib_symbol.h:84
std::vector< SCH_PIN * > GetPins(int aUnit, int aBodyStyle) const
Return a list of pin object pointers from the draw item list.
Definition: lib_symbol.cpp:857
SCH_FIELD * GetFieldById(int aId) const
Return pointer to the requested field.
wxArrayString GetFPFilters() const
Definition: lib_symbol.h:217
bool GetIsVisible() const
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
void AssignIntrinsicRanks()
Sort the tree and assign ranks after adding libraries.
LIB_TREE_NODE_LIBRARY & DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
Add the given list of symbols by alias.
void SetFilter(std::function< bool(LIB_TREE_NODE &aNode)> *aFilter)
Set the filter.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
bool m_IsAlreadyPlacedGroup
bool m_IsRecentlyUsedGroup
wxString m_Footprint
Widget displaying a tree of symbols with optional search text control and description panel.
Definition: lib_tree.h:49
LIB_TREE_NODE * GetCurrentTreeNode() const
Definition: lib_tree.cpp:338
LIB_TREE_MODEL_ADAPTER::SORT_MODE GetSortMode() const
Definition: lib_tree.h:142
wxString GetSearchString() const
Definition: lib_tree.cpp:393
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:301
@ ALL_WIDGETS
Definition: lib_tree.h:58
void SetSearchString(const wxString &aSearchString)
Save/restore search string.
Definition: lib_tree.cpp:387
void BlockPreview(bool aBlock)
Definition: lib_tree.h:165
PANEL_SYMBOL_CHOOSER(SCH_BASE_FRAME *aFrame, wxWindow *aParent, const SYMBOL_LIBRARY_FILTER *aFilter, std::vector< PICKED_SYMBOL > &aHistoryList, std::vector< PICKED_SYMBOL > &aAlreadyPlaced, bool aAllowFieldEdits, bool aShowFootprints, std::function< void()> aAcceptHandler, std::function< void()> aEscapeHandler)
Create dialog to choose symbol.
SYMBOL_PREVIEW_WIDGET * m_symbol_preview
void onSymbolSelected(wxCommandEvent &aEvent)
void showFootprintFor(const LIB_ID &aLibId)
Look up the footprint for a given symbol specified in the LIB_ID and display it.
void onMenuClose(wxMenuEvent &aEvent)
wxSplitterWindow * m_hsplitter
FOOTPRINT_SELECT_WIDGET * m_fp_sel_ctrl
std::function< void()> m_escapeHandler
void OnDetailsCharHook(wxKeyEvent &aEvt)
static wxString g_symbolSearchString
void onMenuOpen(wxMenuEvent &aEvent)
Handle parent frame menu events to block tree preview.
void onCloseTimer(wxTimerEvent &aEvent)
wxSplitterWindow * m_vsplitter
std::vector< std::pair< int, wxString > > m_field_edits
void showFootprint(const wxString &aFootprint)
Display the given footprint by name.
void populateFootprintSelector(const LIB_ID &aLibId)
Populate the footprint selector for a given alias.
void onOpenLibsTimer(wxTimerEvent &aEvent)
void onFootprintSelected(wxCommandEvent &aEvent)
static wxString g_powerSearchString
void OnChar(wxKeyEvent &aEvent)
void SetPreselect(const LIB_ID &aPreselect)
std::function< void()> m_acceptHandler
static constexpr int DBLCLICK_DELAY
FOOTPRINT_PREVIEW_WIDGET * m_fp_preview
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > m_adapter
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void onSymbolChosen(wxCommandEvent &aEvent)
Handle the selection of an item.
wxPanel * constructRightPanel(wxWindow *aParent)
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:689
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:72
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
LIB_SYMBOL * GetLibSymbol(const LIB_ID &aLibId, bool aUseCacheLib=false, bool aShowErrorMsg=false)
Load symbol from symbol library table.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:53
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:334
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1214
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
Helper object to filter a list of libraries.
const wxArrayString & GetAllowedLibList() const
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_IO object i...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
void SetStatusText(const wxString &aText)
Set the contents of the status label and display it.
void DisplaySymbol(const LIB_ID &aSymbolID, int aUnit, int aBodyStyle=0)
Set the currently displayed symbol.
bool AddLibraries(const std::vector< wxString > &aNicknames, SCH_BASE_FRAME *aFrame)
Add all the libraries in a SYMBOL_LIB_TABLE to the model.
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(SCH_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
void AddLibrary(wxString const &aLibNickname, bool pinned)
EDA_UNITS GetUserUnits() const
wxString wx_str() const
Definition: utf8.cpp:45
#define _(s)
void delete_if(_Container &__c, _Function &&__f)
Deletes all values from __c for which __f returns true.
Definition: kicad_algo.h:174
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
STL namespace.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
std::vector< wxString > pinned_symbol_libs
Definition for symbol library class.
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".