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 <algorithm>
42#include <wx/button.h>
43#include <wx/clipbrd.h>
44#include <wx/panel.h>
45#include <wx/sizer.h>
46#include <wx/splitter.h>
47#include <wx/timer.h>
48#include <wx/wxhtml.h>
49#include <wx/log.h>
50
51
55
57 const SYMBOL_LIBRARY_FILTER* aFilter,
58 std::vector<PICKED_SYMBOL>& aHistoryList,
59 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
60 bool aAllowFieldEdits, bool aShowFootprints, bool& aCancelled,
61 std::function<void()> aAcceptHandler,
62 std::function<void()> aEscapeHandler ) :
63 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize ),
64 m_symbol_preview( nullptr ),
65 m_hsplitter( nullptr ),
66 m_vsplitter( nullptr ),
67 m_fp_sel_ctrl( nullptr ),
68 m_fp_preview( nullptr ),
69 m_tree( nullptr ),
70 m_details( nullptr ),
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{
77 m_frame = aFrame;
78
81 PROJECT_FILE& project = m_frame->Prj().GetProjectFile();
82
83 // Make sure settings are loaded before we start running multi-threaded symbol loaders
86
88 SYMBOL_TREE_MODEL_ADAPTER* adapter = static_cast<SYMBOL_TREE_MODEL_ADAPTER*>( m_adapter.get() );
89 bool loaded = false;
90
91 if( aFilter )
92 {
93 const wxArrayString& liblist = aFilter->GetAllowedLibList();
94
95 for( const wxString& nickname : liblist )
96 {
97 if( libs->HasLibrary( nickname, true ) )
98 {
99 loaded = true;
100
101 bool pinned = alg::contains( session.pinned_symbol_libs, nickname )
102 || alg::contains( project.m_PinnedSymbolLibs, nickname );
103
104 SYMBOL_LIB_TABLE_ROW* row = libs->FindRow( nickname );
105
106 if( row && row->GetIsVisible() )
107 adapter->AddLibrary( nickname, pinned );
108 }
109 }
110
111 adapter->AssignIntrinsicRanks();
112
113 if( aFilter->GetFilterPowerSymbols() )
114 {
115 static std::function<bool( LIB_TREE_NODE& )> powerFilter =
116 []( LIB_TREE_NODE& aNode ) -> bool
117 {
119 {
120 LIB_SYMBOL* symbol = PANEL_SYMBOL_CHOOSER::m_frame->GetLibSymbol(aNode.m_LibId);
121
122 if (symbol && symbol->IsPower())
123 return true;
124
125 }
126
127 return false;
128 };
129
130 adapter->SetFilter( &powerFilter );
131
132 m_showPower = true;
133 m_show_footprints = false;
134 }
135 }
136
137 std::vector<LIB_SYMBOL> history_list_storage;
138 std::vector<LIB_TREE_ITEM*> history_list;
139 std::vector<LIB_SYMBOL> already_placed_storage;
140 std::vector<LIB_TREE_ITEM*> already_placed;
141
142 // Lambda to encapsulate the common logic
143 auto processList =
144 [&]( const std::vector<PICKED_SYMBOL>& inputList,
145 std::vector<LIB_SYMBOL>& storageList,
146 std::vector<LIB_TREE_ITEM*>& resultList )
147 {
148 storageList.reserve( inputList.size() );
149
150 for( const PICKED_SYMBOL& i : inputList )
151 {
152 LIB_SYMBOL* symbol = m_frame->GetLibSymbol( i.LibId );
153
154 if( symbol )
155 {
156 storageList.emplace_back( *symbol );
157
158 for( const auto& [fieldType, fieldValue] : i.Fields )
159 {
160 SCH_FIELD* field = storageList.back().GetField( fieldType );
161
162 if( field )
163 field->SetText( fieldValue );
164 }
165
166 resultList.push_back( &storageList.back() );
167 }
168 }
169 };
170
171 // Sort the already placed list since it is potentially from multiple sessions,
172 // but not the most recent list since we want this listed by most recent usage.
173 std::sort( aAlreadyPlaced.begin(), aAlreadyPlaced.end(),
174 []( PICKED_SYMBOL const& a, PICKED_SYMBOL const& b )
175 {
176 return a.LibId.GetLibItemName() < b.LibId.GetLibItemName();
177 } );
178
179 processList( aHistoryList, history_list_storage, history_list );
180 processList( aAlreadyPlaced, already_placed_storage, already_placed );
181
182 adapter->DoAddLibrary( wxT( "-- " ) + _( "Recently Used" ) + wxT( " --" ), wxEmptyString,
183 history_list, false, true )
184 .m_IsRecentlyUsedGroup = true;
185
186 if( !aHistoryList.empty() )
187 adapter->SetPreselectNode( aHistoryList[0].LibId, aHistoryList[0].Unit );
188
189 adapter->DoAddLibrary( wxT( "-- " ) + _( "Already Placed" ) + wxT( " --" ), wxEmptyString,
190 already_placed, false, true )
192
193 const std::vector< wxString > libNicknames = libs->GetLogicalLibs();
194
195 if( !loaded )
196 {
197 if( !adapter->AddLibraries( libNicknames, m_frame ) )
198 {
199 // loading cancelled by user
200 aCancelled = true;
201 }
202 }
203
204 // -------------------------------------------------------------------------------------
205 // Construct the actual panel
206 //
207
208 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
209
210 // Use a slightly different layout, with a details pane spanning the entire window,
211 // if we're not showing footprints.
213 {
214 m_hsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
215 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
216
217 //Avoid the splitter window being assigned as the Parent to additional windows
218 m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
219
220 sizer->Add( m_hsplitter, 1, wxEXPAND, 5 );
221 }
222 else
223 {
224 m_vsplitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
225 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
226
227 m_hsplitter = new wxSplitterWindow( m_vsplitter, wxID_ANY, wxDefaultPosition, wxDefaultSize,
228 wxSP_LIVE_UPDATE | wxSP_NOBORDER | wxSP_3DSASH );
229
230 // Avoid the splitter window being assigned as the parent to additional windows.
231 m_vsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
232 m_hsplitter->SetExtraStyle( wxWS_EX_TRANSIENT );
233
234 wxPanel* detailsPanel = new wxPanel( m_vsplitter );
235 wxBoxSizer* detailsSizer = new wxBoxSizer( wxVERTICAL );
236 detailsPanel->SetSizer( detailsSizer );
237
238 m_details = new HTML_WINDOW( detailsPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize );
239 detailsSizer->Add( m_details, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
240 detailsPanel->Layout();
241 detailsSizer->Fit( detailsPanel );
242
243 m_vsplitter->SetSashGravity( 0.5 );
244 m_vsplitter->SetMinimumPaneSize( 20 );
245 m_vsplitter->SplitHorizontally( m_hsplitter, detailsPanel );
246
247 sizer->Add( m_vsplitter, 1, wxEXPAND | wxBOTTOM, 5 );
248 }
249
250 wxPanel* treePanel = new wxPanel( m_hsplitter );
251 wxBoxSizer* treeSizer = new wxBoxSizer( wxVERTICAL );
252 treePanel->SetSizer( treeSizer );
253
254 m_tree = new LIB_TREE( treePanel, m_showPower ? wxT( "power" ) : wxT( "symbols" ), libs, m_adapter,
256
257 treeSizer->Add( m_tree, 1, wxALL | wxEXPAND, 5 );
258 treePanel->Layout();
259 treeSizer->Fit( treePanel );
260
261 m_adapter->FinishTreeInitialization();
262
263 if( m_showPower )
264 m_tree->SetSearchString( g_powerSearchString );
265 else
266 m_tree->SetSearchString( g_symbolSearchString );
267
268 m_hsplitter->SetSashGravity( 0.8 );
269 m_hsplitter->SetMinimumPaneSize( 20 );
270 m_hsplitter->SplitVertically( treePanel, constructRightPanel( m_hsplitter ) );
271
272 m_dbl_click_timer = new wxTimer( this );
273 m_open_libs_timer = new wxTimer( this );
274
275 SetSizer( sizer );
276
277 Layout();
278
279 Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onCloseTimer, this, m_dbl_click_timer->GetId() );
280 Bind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onOpenLibsTimer, this, m_open_libs_timer->GetId() );
281 Bind( EVT_LIBITEM_SELECTED, &PANEL_SYMBOL_CHOOSER::onSymbolSelected, this );
282 Bind( EVT_LIBITEM_CHOSEN, &PANEL_SYMBOL_CHOOSER::onSymbolChosen, this );
283 aFrame->Bind( wxEVT_MENU_OPEN, &PANEL_SYMBOL_CHOOSER::onMenuOpen, this );
284 aFrame->Bind( wxEVT_MENU_CLOSE, &PANEL_SYMBOL_CHOOSER::onMenuClose, this );
285
286 if( m_fp_sel_ctrl )
287 m_fp_sel_ctrl->Bind( EVT_FOOTPRINT_SELECTED, &PANEL_SYMBOL_CHOOSER::onFootprintSelected, this );
288
289 if( m_details )
290 m_details->Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnDetailsCharHook, this );
291
292 // Open the user's previously opened libraries on timer expiration.
293 // This is done on a timer because we need a gross hack to keep GTK from garbling the
294 // display. Must be longer than the search debounce timer.
295 m_open_libs_timer->StartOnce( 300 );
296}
297
298
300{
301 m_frame->Unbind( wxEVT_MENU_OPEN, &PANEL_SYMBOL_CHOOSER::onMenuOpen, this );
302 m_frame->Unbind( wxEVT_MENU_CLOSE, &PANEL_SYMBOL_CHOOSER::onMenuClose, this );
303 Unbind( wxEVT_TIMER, &PANEL_SYMBOL_CHOOSER::onCloseTimer, this );
304 Unbind( EVT_LIBITEM_SELECTED, &PANEL_SYMBOL_CHOOSER::onSymbolSelected, this );
305 Unbind( EVT_LIBITEM_CHOSEN, &PANEL_SYMBOL_CHOOSER::onSymbolChosen, 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 )
314 g_powerSearchString = m_tree->GetSearchString();
315 else
316 g_symbolSearchString = m_tree->GetSearchString();
317
318 if( m_fp_sel_ctrl )
319 m_fp_sel_ctrl->Unbind( EVT_FOOTPRINT_SELECTED, &PANEL_SYMBOL_CHOOSER::onFootprintSelected, this );
320
321 if( m_details )
322 m_details->Unbind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnDetailsCharHook, this );
323
324 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
325 {
326 // Save any changes to column widths, etc.
327 m_adapter->SaveSettings();
328
329 cfg->m_SymChooserPanel.width = GetParent()->GetSize().x;
330 cfg->m_SymChooserPanel.height = GetParent()->GetSize().y;
331
332 cfg->m_SymChooserPanel.sash_pos_h = m_hsplitter->GetSashPosition();
333
334 if( m_vsplitter )
335 cfg->m_SymChooserPanel.sash_pos_v = m_vsplitter->GetSashPosition();
336
337 cfg->m_SymChooserPanel.sort_mode = m_tree->GetSortMode();
338 }
339
340 m_frame = nullptr;
341}
342
343
344void PANEL_SYMBOL_CHOOSER::onMenuOpen( wxMenuEvent& aEvent )
345{
346 m_tree->BlockPreview( true );
347 aEvent.Skip();
348}
349
350
351void PANEL_SYMBOL_CHOOSER::onMenuClose( wxMenuEvent& aEvent )
352{
353 m_tree->BlockPreview( false );
354 aEvent.Skip();
355}
356
357
358void PANEL_SYMBOL_CHOOSER::OnChar( wxKeyEvent& aEvent )
359{
360 if( aEvent.GetKeyCode() == WXK_ESCAPE )
361 {
362 wxObject* eventSource = aEvent.GetEventObject();
363
364 if( wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( eventSource ) )
365 {
366 // First escape cancels search string value
367 if( textCtrl->GetValue() == m_tree->GetSearchString()
368 && !m_tree->GetSearchString().IsEmpty() )
369 {
370 m_tree->SetSearchString( wxEmptyString );
371 return;
372 }
373 }
374
376 }
377 else
378 {
379 aEvent.Skip();
380 }
381}
382
383
384wxPanel* PANEL_SYMBOL_CHOOSER::constructRightPanel( wxWindow* aParent )
385{
387
388 if( m_frame->GetCanvas() )
389 backend = m_frame->GetCanvas()->GetBackend();
390 else if( COMMON_SETTINGS* cfg = Pgm().GetCommonSettings() )
391 backend = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( cfg->m_Graphics.canvas_type );
392
393 wxPanel* panel = new wxPanel( aParent );
394 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
395
396 m_symbol_preview = new SYMBOL_PREVIEW_WIDGET( panel, &m_frame->Kiway(), true, backend );
397 m_symbol_preview->SetLayoutDirection( wxLayout_LeftToRight );
398
400 {
402
403 sizer->Add( m_symbol_preview, 11, wxEXPAND | wxALL, 5 );
404
405 if ( fp_list )
406 {
408 m_fp_sel_ctrl = new FOOTPRINT_SELECT_WIDGET( m_frame, panel, fp_list, true );
409
410 m_fp_preview = new FOOTPRINT_PREVIEW_WIDGET( panel, m_frame->Kiway() );
411 m_fp_preview->SetUserUnits( m_frame->GetUserUnits() );
412 }
413
414 if( m_fp_sel_ctrl )
415 sizer->Add( m_fp_sel_ctrl, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
416
417 if( m_fp_preview )
418 sizer->Add( m_fp_preview, 10, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
419 }
420 else
421 {
422 sizer->Add( m_symbol_preview, 1, wxEXPAND | wxALL, 5 );
423 }
424
425 panel->SetSizer( sizer );
426 panel->Layout();
427 sizer->Fit( panel );
428
429 return panel;
430}
431
432
434{
435 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
436 {
437 auto horizPixelsFromDU =
438 [&]( int x ) -> int
439 {
440 wxSize sz( x, 0 );
441 return GetParent()->ConvertDialogToPixels( sz ).x;
442 };
443
444 EESCHEMA_SETTINGS::PANEL_SYM_CHOOSER& panelCfg = cfg->m_SymChooserPanel;
445
446 int w = panelCfg.width > 40 ? panelCfg.width : horizPixelsFromDU( 440 );
447 int h = panelCfg.height > 40 ? panelCfg.height : horizPixelsFromDU( 340 );
448
449 GetParent()->SetSize( wxSize( w, h ) );
450 GetParent()->Layout();
451
452 // We specify the width of the right window (m_symbol_view_panel), because specify
453 // the width of the left window does not work as expected when SetSashGravity() is called
454
455 if( panelCfg.sash_pos_h < 0 )
456 panelCfg.sash_pos_h = horizPixelsFromDU( 220 );
457
458 if( panelCfg.sash_pos_v < 0 )
459 panelCfg.sash_pos_v = horizPixelsFromDU( 230 );
460
461 m_hsplitter->SetSashPosition( panelCfg.sash_pos_h );
462
463 if( m_vsplitter )
464 m_vsplitter->SetSashPosition( panelCfg.sash_pos_v );
465
466 m_adapter->SetSortMode( (LIB_TREE_MODEL_ADAPTER::SORT_MODE) panelCfg.sort_mode );
467 }
468
469 if( m_fp_preview && m_fp_preview->IsInitialized() )
470 {
471 // This hides the GAL panel and shows the status label
472 m_fp_preview->SetStatusText( wxEmptyString );
473 }
474
475 if( m_fp_sel_ctrl )
476 m_fp_sel_ctrl->Load( m_frame->Kiway(), m_frame->Prj() );
477}
478
479
481{
482 if( m_details && e.GetKeyCode() == 'C' && e.ControlDown() &&
483 !e.AltDown() && !e.ShiftDown() && !e.MetaDown() )
484 {
485 wxString txt = m_details->SelectionToText();
486 wxLogNull doNotLog; // disable logging of failed clipboard actions
487
488 if( wxTheClipboard->Open() )
489 {
490 wxTheClipboard->SetData( new wxTextDataObject( txt ) );
491 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
492 wxTheClipboard->Close();
493 }
494 }
495 else
496 {
497 e.Skip();
498 }
499}
500
501
503{
504 m_adapter->SetPreselectNode( aPreselect, 0 );
505}
506
507
509{
510 return m_tree->GetSelectedLibId( aUnit );
511}
512
513
515{
516 m_symbol_preview->GetCanvas()->SetEvtHandlerEnabled( false );
517 m_symbol_preview->GetCanvas()->StopDrawing();
518
519 if( m_fp_preview )
520 {
521 m_fp_preview->GetPreviewPanel()->GetCanvas()->SetEvtHandlerEnabled( false );
522 m_fp_preview->GetPreviewPanel()->GetCanvas()->StopDrawing();
523 }
524}
525
526
527void PANEL_SYMBOL_CHOOSER::onCloseTimer( wxTimerEvent& aEvent )
528{
529 // Hack because of eaten MouseUp event. See PANEL_SYMBOL_CHOOSER::onSymbolChosen
530 // for the beginning of this spaghetti noodle.
531
532 wxMouseState state = wxGetMouseState();
533
534 if( state.LeftIsDown() )
535 {
536 // Mouse hasn't been raised yet, so fire the timer again. Otherwise the
537 // purpose of this timer is defeated.
539 }
540 else
541 {
543 }
544}
545
546
547void PANEL_SYMBOL_CHOOSER::onOpenLibsTimer( wxTimerEvent& aEvent )
548{
549 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
550 m_adapter->OpenLibs( cfg->m_LibTree.open_libs );
551}
552
553
555{
556 if( !m_fp_preview || !m_fp_preview->IsInitialized() )
557 return;
558
559 LIB_SYMBOL* symbol = nullptr;
560
561 try
562 {
563 symbol = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->LoadSymbol( aLibId );
564 }
565 catch( const IO_ERROR& ioe )
566 {
567 wxLogError( _( "Error loading symbol %s from library '%s'." ) + wxS( "\n%s" ),
568 aLibId.GetLibItemName().wx_str(),
569 aLibId.GetLibNickname().wx_str(),
570 ioe.What() );
571 }
572
573 if( !symbol )
574 return;
575
576 SCH_FIELD* fp_field = symbol->GetField( FIELD_T::FOOTPRINT );
577 wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
578
579 showFootprint( fp_name );
580}
581
582
583void PANEL_SYMBOL_CHOOSER::showFootprint( wxString const& aFootprint )
584{
585 if( !m_fp_preview || !m_fp_preview->IsInitialized() )
586 return;
587
588 if( aFootprint == wxEmptyString )
589 {
590 m_fp_preview->SetStatusText( _( "No footprint specified" ) );
591 }
592 else
593 {
594 LIB_ID lib_id;
595
596 if( lib_id.Parse( aFootprint ) == -1 && lib_id.IsValid() )
597 {
598 m_fp_preview->ClearStatus();
599 m_fp_preview->DisplayFootprint( lib_id );
600 }
601 else
602 {
603 m_fp_preview->SetStatusText( _( "Invalid footprint specified" ) );
604 }
605 }
606}
607
608
610{
611 if( !m_fp_sel_ctrl )
612 return;
613
614 m_fp_sel_ctrl->ClearFilters();
615
616 LIB_SYMBOL* symbol = nullptr;
617
618 if( aLibId.IsValid() )
619 {
620 try
621 {
622 symbol = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() )->LoadSymbol( aLibId );
623 }
624 catch( const IO_ERROR& ioe )
625 {
626 wxLogError( _( "Error loading symbol %s from library '%s'." ) + wxS( "\n%s" ),
627 aLibId.GetLibItemName().wx_str(),
628 aLibId.GetLibNickname().wx_str(),
629 ioe.What() );
630 }
631 }
632
633 if( symbol != nullptr )
634 {
635 int pinCount = symbol->GetGraphicalPins( 0 /* all units */, 1 /* single bodyStyle */ ).size();
636 SCH_FIELD* fp_field = symbol->GetField( FIELD_T::FOOTPRINT );
637 wxString fp_name = fp_field ? fp_field->GetFullText() : wxString( "" );
638
639 m_fp_sel_ctrl->FilterByPinCount( pinCount );
640 m_fp_sel_ctrl->FilterByFootprintFilters( symbol->GetFPFilters(), true );
641 m_fp_sel_ctrl->SetDefaultFootprint( fp_name );
642 m_fp_sel_ctrl->UpdateList();
643 m_fp_sel_ctrl->Enable();
644 }
645 else
646 {
647 m_fp_sel_ctrl->UpdateList();
648 m_fp_sel_ctrl->Disable();
649 }
650}
651
652
653void PANEL_SYMBOL_CHOOSER::onFootprintSelected( wxCommandEvent& aEvent )
654{
655 m_fp_override = aEvent.GetString();
656
657 std::erase_if( m_field_edits, []( std::pair<FIELD_T, wxString> const& i )
658 {
659 return i.first == FIELD_T::FOOTPRINT;
660 } );
661
662 m_field_edits.emplace_back( std::make_pair( FIELD_T::FOOTPRINT, m_fp_override ) );
663
665}
666
667
668void PANEL_SYMBOL_CHOOSER::onSymbolSelected( wxCommandEvent& aEvent )
669{
670 LIB_TREE_NODE* node = m_tree->GetCurrentTreeNode();
671
672 if( node && node->m_LibId.IsValid() )
673 {
674 m_symbol_preview->DisplaySymbol( node->m_LibId, node->m_Unit );
675
676 if( !node->m_Footprint.IsEmpty() )
677 showFootprint( node->m_Footprint );
678 else
679 showFootprintFor( node->m_LibId );
680
682 }
683 else
684 {
685 m_symbol_preview->SetStatusText( _( "No symbol selected" ) );
686
687 if( m_fp_preview && m_fp_preview->IsInitialized() )
688 m_fp_preview->SetStatusText( wxEmptyString );
689
691 }
692}
693
694
695void PANEL_SYMBOL_CHOOSER::onSymbolChosen( wxCommandEvent& aEvent )
696{
697 if( m_tree->GetSelectedLibId().IsValid() )
698 {
699 // Got a selection. We can't just end the modal dialog here, because wx leaks some events
700 // back to the parent window (in particular, the MouseUp following a double click).
701 //
702 // NOW, here's where it gets really fun. wxTreeListCtrl eats MouseUp. This isn't really
703 // feasible to bypass without a fully custom wxDataViewCtrl implementation, and even then
704 // might not be fully possible (docs are vague). To get around this, we use a one-shot
705 // timer to schedule the dialog close.
706 //
707 // See PANEL_SYMBOL_CHOOSER::onCloseTimer for the other end of this spaghetti noodle.
709 }
710}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ GAL_TYPE_OPENGL
OpenGL implementation.
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.
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.
virtual const wxString What() const
A composite of Problem() and Where()
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:52
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:85
bool IsPower() const override
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
wxArrayString GetFPFilters() const
Definition lib_symbol.h:217
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
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
wxString m_Footprint
Widget displaying a tree of symbols with optional search text control and description panel.
Definition lib_tree.h:49
@ ALL_WIDGETS
Definition lib_tree.h:58
SYMBOL_PREVIEW_WIDGET * m_symbol_preview
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, bool &aCancelled, std::function< void()> aAcceptHandler, std::function< void()> aEscapeHandler)
Create dialog to choose symbol.
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.
std::vector< std::pair< FIELD_T, wxString > > m_field_edits
void onCloseTimer(wxTimerEvent &aEvent)
wxSplitterWindow * m_vsplitter
static SCH_BASE_FRAME * m_frame
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:576
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
wxString GetFullText(int unit=1) const
Return the text of a field.
void SetText(const wxString &aText) override
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...
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)
wxString wx_str() const
Definition utf8.cpp:45
#define _(s)
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:913
see class PGM_BASE
T * GetAppSettings(const char *aFilename)
std::vector< wxString > pinned_symbol_libs
Definition for symbol library class.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".