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