KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_chooser_frame.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) 2023 CERN
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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <wx/button.h>
22#include <wx/checkbox.h>
23#include <wx/splitter.h>
24
25#include <pgm_base.h>
26#include <kiface_base.h>
27#include <kiway.h>
28#include <kiway_mail.h>
29#include <board.h>
30#include <footprint.h>
31#include <kiplatform/ui.h>
32#include <lset.h>
37#include <tool/tool_manager.h>
39#include <tool/common_tools.h>
40#include <tool/zoom_tool.h>
42#include <tools/pcb_actions.h>
46#include "wx/display.h"
49#include <project_pcb.h>
53
54
55static wxArrayString s_FootprintHistoryList;
56static unsigned s_FootprintHistoryMaxCount = 8;
57
58static void AddFootprintToHistory( const wxString& aName )
59{
60 // Remove duplicates
61 for( int ii = (int) s_FootprintHistoryList.GetCount() - 1; ii >= 0; --ii )
62 {
63 if( s_FootprintHistoryList[ ii ] == aName )
64 s_FootprintHistoryList.RemoveAt( (size_t) ii );
65 }
66
67 // Add the new name at the beginning of the history list
68 s_FootprintHistoryList.Insert( aName, 0 );
69
70 // Remove extra names
72 s_FootprintHistoryList.RemoveAt( s_FootprintHistoryList.GetCount() - 1 );
73}
74
75
76BEGIN_EVENT_TABLE( FOOTPRINT_CHOOSER_FRAME, PCB_BASE_FRAME )
78 EVT_BUTTON( wxID_OK, FOOTPRINT_CHOOSER_FRAME::OnOK )
79 EVT_BUTTON( wxID_CANCEL, FOOTPRINT_CHOOSER_FRAME::closeFootprintChooser )
81END_EVENT_TABLE()
82
83
84#define PARENT_STYLE ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
85 | wxWANTS_CHARS | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
86#define MODAL_STYLE ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
87 | wxWANTS_CHARS | wxFRAME_NO_TASKBAR )
88
89
91 PCB_BASE_FRAME( aKiway, aParent, FRAME_FOOTPRINT_CHOOSER, _( "Footprint Chooser" ),
92 wxDefaultPosition, wxDefaultSize, aParent ? PARENT_STYLE : MODAL_STYLE,
94 m_filterByPinCount( nullptr ),
95 m_filterByFPFilters( nullptr ),
99 m_pinCount( 0 ),
100 m_firstPaintEvent( true )
101{
102 SetModal( true );
103
104 m_messagePanel->Hide();
105
106 m_bottomPanel = new wxPanel( this );
107 wxBoxSizer* bottomSizer = new wxBoxSizer( wxVERTICAL );
108 wxBoxSizer* frameSizer = new wxBoxSizer( wxVERTICAL );
109
111 // Filter
112 [this]( LIB_TREE_NODE& aNode ) -> bool
113 {
114 return filterFootprint( aNode );
115 },
116 // Accept handler
117 [this]()
118 {
119 wxCommandEvent dummy;
120 OnOK( dummy );
121 },
122 // Escape handler
123 [this]()
124 {
126 } );
127
128 frameSizer->Add( m_chooserPanel, 1, wxEXPAND );
129
130 SetCanvas( m_chooserPanel->GetViewerPanel()->GetPreviewPanel()->GetCanvas() );
131 SetBoard( m_chooserPanel->GetViewerPanel()->GetPreviewPanel()->GetBoard() );
132
133 // This board will only be used to hold a footprint for viewing
135
136 build3DCanvas(); // must be called after creating m_chooserPanel
138
139 // buttonsSizer contains the BITMAP buttons
140 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
141
142 buttonsSizer->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
143
144
145 m_toggleDescription = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
146 m_toggleDescription->SetIsRadioButton();
148 m_toggleDescription->SetToolTip( _( "Show/hide description panel" ) );
150 buttonsSizer->Add( m_toggleDescription, 0, wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 1 );
151
152 BITMAP_BUTTON* separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
153 separator->SetIsSeparator();
154 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
155
156 m_grButton3DView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
157 m_grButton3DView->SetIsRadioButton();
159 m_grButton3DView->SetToolTip( _( "Show/hide 3D view panel" ) );
161 buttonsSizer->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
162
163 m_grButtonFpView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
164 m_grButtonFpView->SetIsRadioButton();
166 m_grButtonFpView->SetToolTip( _( "Show/hide footprint view panel" ) );
168 buttonsSizer->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
169
170 separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
171 separator->SetIsSeparator();
172 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
173
174 m_show3DViewer = new wxCheckBox( m_bottomPanel, wxID_ANY, _( "Show 3D viewer in own window" ) );
175 buttonsSizer->Add( m_show3DViewer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 3 );
176
177 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
178 wxButton* okButton = new wxButton( m_bottomPanel, wxID_OK );
179 wxButton* cancelButton = new wxButton( m_bottomPanel, wxID_CANCEL );
180
181 sdbSizer->AddButton( okButton );
182 sdbSizer->AddButton( cancelButton );
183 sdbSizer->Realize();
184
185 buttonsSizer->Add( 20, 0, 0, 0, 5 ); // Add spacer
186 buttonsSizer->Add( sdbSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
187 bottomSizer->Add( buttonsSizer, 0, wxEXPAND, 5 );
188
189 m_bottomPanel->SetSizer( bottomSizer );
190 frameSizer->Add( m_bottomPanel, 0, wxEXPAND );
191
192 SetSizer( frameSizer );
193
194 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
195 m_chooserPanel->GetItemCount() ) );
196
197 Layout();
198 m_chooserPanel->FinishSetup();
199
200 Bind( wxEVT_CHAR_HOOK, &PANEL_FOOTPRINT_CHOOSER::OnChar, m_chooserPanel );
201
202 if( !m_showDescription )
203 {
204 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 0 );
205 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
206 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
207
209 }
210
211 // Create the manager and dispatcher & route draw panel events to the dispatcher
213 m_toolManager->SetEnvironment( GetBoard(), GetCanvas()->GetView(),
214 GetCanvas()->GetViewControls(), GetViewerSettingsBase(), this );
215 m_actions = new PCB_ACTIONS();
218
219 m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
220 m_toolManager->RegisterTool( new PCB_PICKER_TOOL ); // for setting grid origin
221 m_toolManager->RegisterTool( new ZOOM_TOOL );
222 m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
224
225 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
226 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetIsDefaultTool( true );
227
228 m_toolManager->InitTools();
229
232
233 // clang-format off
234 // Connect Events
235 m_toggleDescription->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
236 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
237 nullptr, this );
238
239 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
240 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
241 nullptr, this );
242
243 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
244 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
245 nullptr, this );
246
247 m_show3DViewer->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
249 nullptr, this );
250
251 Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
252 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
253 // clang-format on
254
255 // Needed on Linux to fix the position of widgets in bottomPanel
256 PostSizeEvent();
257}
258
259
261{
262 Unbind( wxEVT_CHAR_HOOK, &PANEL_FOOTPRINT_CHOOSER::OnChar, m_chooserPanel );
263
264 // Shutdown all running tools
265 if( m_toolManager )
266 m_toolManager->ShutdownAllTools();
267
268 // Idempotent; normally already ran from OnOK() or doCloseWindow() before DismissModal.
270
271 // Disconnect board, which is owned by FOOTPRINT_PREVIEW_PANEL.
272 m_pcb = nullptr;
273
274 // The 3D canvas holds references to m_boardAdapter and m_trackBallCamera, and wx would not
275 // destroy this grandchild window until well after those members are gone
276 delete m_preview3DCanvas;
277 m_preview3DCanvas = nullptr;
278
279 // clang-format off
280 // Disconnect Events
281 m_toggleDescription->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
282 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
283 nullptr, this );
284
285 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
286 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
287 nullptr, this );
288 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
289 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
290 nullptr, this );
291
292 m_show3DViewer->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
294 nullptr, this );
295
296 Disconnect( FP_SELECTION_EVENT,
297 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
298
299 // clang-format on
300
301 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
302 {
304 cfg->m_FootprintChooser.use_fp_filters = m_filterByFPFilters->GetValue();
305
307 cfg->m_FootprintChooser.filter_on_pin_count = m_filterByPinCount->GetValue();
308 }
309}
310
311
313{
314 if( m_quiesced )
315 return;
316
317 m_quiesced = true;
318
319 // Running this teardown before DismissModal() ensures the preview cannot
320 // receive further paint or timer events during KIWAY_PLAYER::ShowModal()'s
321 // post-loop wxSafeYield() while the frame is hidden but not yet destroyed.
322
323 // Work around assertion firing when we try to LockCtx on a hidden 3D canvas
325 {
326 m_preview3DCanvas->Show();
327
328 wxCloseEvent dummy;
329 m_preview3DCanvas->OnCloseWindow( dummy );
330 m_preview3DCanvas->SetEvtHandlerEnabled( false );
331 }
332
333 if( m_chooserPanel )
334 {
335 FOOTPRINT_PREVIEW_WIDGET* viewerPanel = m_chooserPanel->GetViewerPanel();
336
337 if( viewerPanel )
338 {
339 if( FOOTPRINT_PREVIEW_PANEL* previewPanel =
340 static_cast<FOOTPRINT_PREVIEW_PANEL*>( viewerPanel->GetPreviewPanel() ) )
341 {
342 previewPanel->GetCanvas()->StopDrawing();
343 previewPanel->GetCanvas()->SetEvtHandlerEnabled( false );
344 previewPanel->ClearViewAndData();
345 }
346 }
347 }
348}
349
350
352{
353 if( aEvent.IsChecked() )
354 {
355 if( m_grButton3DView->IsChecked() )
356 Show3DViewerFrame(); // show external 3D viewer
357 }
358 else
359 {
360 // Close the external 3D viewer frame, if it is still enabled
362
363 if( viewer3D )
364 viewer3D->Close( true );
365 }
366
368}
369
370
372{
373 bool do_reload_board = true; // reload board flag
374
375 // At EDA_3D_VIEWER_FRAME creation, the current board is loaded, so disable loading
376 // the current board if the 3D frame is not yet created
377 if( Get3DViewerFrame() == nullptr )
378 do_reload_board = false;
379
381
382 // A stronger version of Raise() which promotes the window to its parent's level.
383 KIPLATFORM::UI::ReparentModal( draw3DFrame );
384
385 // And load or update the current board (if needed)
386 if( do_reload_board )
387 Update3DView( true, true );
388}
389
390
391void FOOTPRINT_CHOOSER_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
392{
393 LIB_ID fpID = m_chooserPanel->GetSelectedLibId();
394 wxString footprintName;
395
396 if( fpID.IsValid() )
397 footprintName << fpID.Format();
398
399 wxString title = _( "3D Viewer" ) + wxT( " \u2014 " ) + footprintName;
400 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &title );
401}
402
403
405{
407 return m_filterByPinCount->GetValue();
408
409 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
410 return cfg->m_FootprintChooser.filter_on_pin_count;
411
412 return false;
413}
414
415
417{
419 return m_filterByFPFilters->GetValue();
420
421 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
422 return cfg->m_FootprintChooser.use_fp_filters;
423
424 return false;
425}
426
427
429{
430 if( aNode.m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
431 {
432 // Normally lib nodes get scored by the max of their children's scores. However, if a
433 // lib node *has* no children then the scorer will call the filter on the lib node itself,
434 // and we just want to return true if we're not filtering at all.
435 return !filterByPinCount() && !filterByFPFilters();
436 }
437
438 auto patternMatch =
439 []( LIB_ID& id, std::vector<std::unique_ptr<EDA_PATTERN_MATCH>>& filters ) -> bool
440 {
441 // The matching is case insensitive
442 wxString name;
443
444 for( const std::unique_ptr<EDA_PATTERN_MATCH>& filter : filters )
445 {
446 name.Empty();
447
448 // If the filter contains a ':' then include the library name in the pattern
449 if( filter->GetPattern().Contains( wxS( ":" ) ) )
450 name = id.GetUniStringLibNickname().Lower() + wxS( ":" );
451
452 name += id.GetUniStringLibItemName().Lower();
453
454 if( filter->Find( name ) )
455 return true;
456 }
457
458 return false;
459 };
460
461 if( m_pinCount > 0 && filterByPinCount() )
462 {
463 if( aNode.m_PinCount != m_pinCount )
464 return false;
465 }
466
467 if( !m_fpFilters.empty() && filterByFPFilters() )
468 {
469 if( !patternMatch( aNode.m_LibId, m_fpFilters ) )
470 return false;
471 }
472
473 return true;
474}
475
476
478{
479 // Tear down the preview canvases before DismissModal() so nothing can paint
480 // or timer-fire into them during the post-loop wxSafeYield().
482
483 // Only dismiss a modal frame once, so that the return values set by
484 // the prior DismissModal() are not bashed for ShowModal().
485 if( !IsDismissed() )
486 DismissModal( false );
487
488 // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
489}
490
491
493{
494 if( PCBNEW_SETTINGS* pcb_cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
495 return &pcb_cfg->m_FootprintViewer;
496 else if( CVPCB_SETTINGS* cvpcb_cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg ) )
497 return &cvpcb_cfg->m_FootprintViewer;
498
499 wxFAIL_MSG( wxT( "FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS or CVPCB_SETTINGS" ) );
500 return &aCfg->m_Window; // non-null fail-safe
501}
502
503
505{
507 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
508}
509
510
511static wxRect s_dialogRect( 0, 0, 0, 0 );
512
513
515{
516 const std::string& payload = mail.GetPayload();
517
518 switch( mail.Command() )
519 {
521 {
522 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "MAIL_SYMBOL_NETLIST received: size=%zu" ), payload.size() );
523 wxSizer* filtersSizer = m_chooserPanel->GetFiltersSizer();
524 wxWindow* filtersWindow = filtersSizer->GetContainingWindow();
525 wxString msg;
526
527 m_pinCount = 0;
528 m_fpFilters.clear();
529 bool needRegen = false;
530 /*
531 * Symbol netlist format:
532 * pinNumber pinName <tab> pinNumber pinName...
533 * fpFilter fpFilter...
534 */
535 std::map<wxString, wxString> pinNames;
536 std::vector<std::string> strings = split( payload, "\r" );
537
538 if( strings.size() >= 1 && !strings[0].empty() )
539 {
540 wxArrayString tokens = wxSplit( strings[0], '\t' );
541
542 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "First line entries=%u" ), (unsigned) tokens.size() );
543
544 for( const wxString& pin : tokens )
545 pinNames[ pin.BeforeFirst( ' ' ) ] = pin.AfterFirst( ' ' );
546
547 m_pinCount = (int) pinNames.size();
548
549 wxString pinList;
550
551 for( const auto& kv : pinNames )
552 {
553 if( !pinList.IsEmpty() )
554 pinList << wxS( "," );
555
556 pinList << kv.first;
557 }
558
559 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "Parsed pins=%d -> [%s]" ), m_pinCount, pinList );
560 }
561
562 if( strings.size() >= 2 && !strings[1].empty() )
563 {
564 for( const wxString& filter : wxSplit( strings[1], ' ' ) )
565 {
566 m_fpFilters.push_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>() );
567 m_fpFilters.back()->SetPattern( filter.Lower() );
568 }
569 }
570
571 if( !m_fpFilters.empty() )
572 {
573 msg.Printf( _( "Apply footprint filters (%s)" ), strings[1] );
574
576 {
577 m_filterByFPFilters = new wxCheckBox( filtersWindow, wxID_ANY, msg );
578
579 m_filterByFPFilters->Bind( wxEVT_CHECKBOX,
580 [&]( wxCommandEvent& evt )
581 {
582 m_chooserPanel->Regenerate();
583 } );
584
585 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
586 {
587 m_filterByFPFilters->SetValue( cfg->m_FootprintChooser.use_fp_filters );
588 needRegen = cfg->m_FootprintChooser.use_fp_filters;
589 }
590
591 m_chooserPanel->GetFiltersSizer()->Add( m_filterByFPFilters, 0, wxEXPAND|wxBOTTOM, 4 );
592 }
593
594 m_filterByFPFilters->SetLabel( msg );
595 }
596 else
597 {
599 m_filterByFPFilters->Hide();
600 }
601
602 if( m_pinCount > 0 )
603 {
604 msg.Printf( _( "Filter by pin count (%d)" ), m_pinCount );
605 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "Pin-count label: %s" ), msg );
606
607 if( !m_filterByPinCount )
608 {
609 m_filterByPinCount = new wxCheckBox( filtersWindow, wxID_ANY, msg );
610
611 m_filterByPinCount->Bind( wxEVT_CHECKBOX,
612 [&]( wxCommandEvent& evt )
613 {
614 m_chooserPanel->Regenerate();
615 } );
616
617 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
618 {
619 m_filterByPinCount->SetValue( cfg->m_FootprintChooser.filter_on_pin_count );
620 needRegen = needRegen || cfg->m_FootprintChooser.filter_on_pin_count;
621 }
622
623 m_chooserPanel->GetFiltersSizer()->Add( m_filterByPinCount, 0, wxEXPAND|wxBOTTOM, 4 );
624 }
625
626 m_filterByPinCount->SetLabel( msg );
627 }
628 else
629 {
631 m_filterByPinCount->Hide();
632 }
633
634 // Regenerate footprint tree to account for pin number filter and footprint filters being applied in settings.
635 if( needRegen )
636 m_chooserPanel->Regenerate();
637
638 m_chooserPanel->GetViewerPanel()->SetPinFunctions( pinNames );
639 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "SetPinFunctions called with %zu entries" ), pinNames.size() );
640
641 // Save the wxFormBuilder size of the dialog...
642 if( s_dialogRect.GetSize().x == 0 || s_dialogRect.GetSize().y == 0 )
643 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
644
645 // ... and then give it a kick to get it to layout the new items
646 GetSizer()->SetSizeHints( this );
647 break;
648 }
649
650 default:
651 break;
652 }
653}
654
655
657{
658 return static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->GetCurrentFootprint();
659}
660
661
662bool FOOTPRINT_CHOOSER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
663{
664 if( aFootprint && !aFootprint->IsEmpty() )
665 {
666 LIB_ID fpid;
667
668 fpid.Parse( *aFootprint, true );
669
670 if( fpid.IsValid() )
671 m_chooserPanel->SetPreselect( fpid );
672 }
673
674 return KIWAY_PLAYER::ShowModal( aFootprint, aParent );
675}
676
677
678void FOOTPRINT_CHOOSER_FRAME::SetPosition( const wxPoint& aNewPosition )
679{
680 PCB_BASE_FRAME::SetPosition( aNewPosition );
681
682 s_dialogRect.SetPosition( aNewPosition );
683}
684
685
687{
688 bool ret;
689
690 // Show or hide the window. If hiding, save current position and size.
691 // If showing, use previous position and size.
692 if( show )
693 {
694#ifndef __WINDOWS__
695 PCB_BASE_FRAME::Raise(); // Needed on OS X and some other window managers (i.e. Unity)
696#endif
697 ret = PCB_BASE_FRAME::Show( show );
698
699 // returns a zeroed-out default wxRect if none existed before.
700 wxRect savedDialogRect = s_dialogRect;
701
702 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
703 {
704 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
705 std::max( wxWindow::GetSize().x, savedDialogRect.GetSize().x ),
706 std::max( wxWindow::GetSize().y, savedDialogRect.GetSize().y ),
707 0 );
708 }
709
710 // Be sure that the dialog appears in a visible area
711 // (the dialog position might have been stored at the time when it was
712 // shown on another display)
713 if( wxDisplay::GetFromWindow( this ) == wxNOT_FOUND )
714 Centre();
715 }
716 else
717 {
718 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
719 ret = PCB_BASE_FRAME::Show( show );
720 }
721
722 return ret;
723}
724
725
726void FOOTPRINT_CHOOSER_FRAME::OnPaint( wxPaintEvent& aEvent )
727{
729 {
731 KIPLATFORM::UI::ForceFocus( m_chooserPanel->GetFocusTarget() );
732
733 m_firstPaintEvent = false;
734 }
735
736 aEvent.Skip();
737}
738
739
740void FOOTPRINT_CHOOSER_FRAME::OnOK( wxCommandEvent& aEvent )
741{
742 // A queued accept event can still fire during the post-loop wxSafeYield()
743 // after Escape/Cancel already dismissed the frame; don't bash that result.
744 if( IsDismissed() )
745 return;
746
747 LIB_ID fpID = m_chooserPanel->GetSelectedLibId();
748
749 // Tear down the preview canvases before DismissModal() so nothing can paint
750 // or timer-fire into them during the post-loop wxSafeYield().
752
753 if( fpID.IsValid() )
754 {
755 wxString footprint = fpID.Format();
756
757 AddFootprintToHistory( footprint );
758 DismissModal( true, footprint );
759 }
760 else
761 {
762 DismissModal( false );
763 }
764}
765
766
768{
769 Close( false );
770}
771
772
773void FOOTPRINT_CHOOSER_FRAME::onFpChanged( wxCommandEvent& event )
774{
775 updateViews();
776
778}
779
780
782{
783 // initialize m_boardAdapter used by the 3D canvas
784 BOARD* dummyBoard = GetBoard();
785 m_boardAdapter.SetBoard( dummyBoard );
786 m_boardAdapter.m_IsBoardView = false;
787 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
788
790
791 // Build the 3D canvas
796
797 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
798 m_chooserPanel->m_RightPanel->Layout();
799
800 BOARD_DESIGN_SETTINGS& dummy_bds = dummyBoard->GetDesignSettings();
801 dummy_bds.SetBoardThickness( pcbIUScale.mmToIU( 1.6 ) );
803 BOARD_STACKUP& dummy_board_stackup = dummyBoard->GetDesignSettings().GetStackupDescriptor();
804 dummy_board_stackup.RemoveAll();
805 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
806}
807
808
810{
812
814
815 m_chooserPanel->GetDetailsPanel()->Show( m_showDescription );
816
817 if( !m_showDescription )
818 {
819 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( GetSize().GetHeight() );
820 m_chooserPanel->GetVerticalSpliter()->SetSashPosition(
821 GetSize().GetHeight() + m_chooserPanel->GetDetailsPanel()->GetSize().GetHeight() );
822
823 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
824 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
825
827 }
828 else
829 {
830 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 80 );
831 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Show();
832 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible( false );
833
835 }
836
837 m_chooserPanel->GetVerticalSpliter()->UpdateSize();
838
839 m_chooserPanel->Layout();
840 m_chooserPanel->Refresh();
841}
842
843
844void FOOTPRINT_CHOOSER_FRAME::on3DviewReq( wxCommandEvent& event )
845{
846 if( m_show3DMode == true )
847 {
848 if( m_showFpMode == true )
849 {
850 m_show3DMode = false;
853 }
854 }
855 else
856 {
857 if( m_show3DViewer->IsChecked() )
858 {
860 }
861 else
862 {
863 // Close 3D viewer frame, if it is still enabled
865
866 if( viewer3D )
867 viewer3D->Close( true );
868 }
869
870 m_show3DMode = true;
873 }
874}
875
876
877void FOOTPRINT_CHOOSER_FRAME::onFpViewReq( wxCommandEvent& event )
878{
879 if( m_showFpMode == true )
880 {
881 if( m_show3DMode == true )
882 {
883 m_showFpMode = false;
886 }
887 }
888 else
889 {
890 m_showFpMode = true;
893 }
894}
895
896
898{
899 // A selection event queued before dismissal can still dispatch during the
900 // post-loop wxSafeYield(). The 3D canvas stays IsShown() after quiescePreview()
901 // released its GL context, so reloading it here would touch torn-down state.
902 if( m_quiesced )
903 return;
904
906
907 if( m_preview3DCanvas->IsShown() )
908 {
909 m_preview3DCanvas->ReloadRequest();
910 m_preview3DCanvas->Request_refresh();
911 }
912
913 if( viewer3D )
914 {
915 Update3DView( true, true );
916 }
917
918 m_chooserPanel->m_RightPanel->Layout();
919 m_chooserPanel->m_RightPanel->Refresh();
920}
921
922
924{
925 FOOTPRINT_PREVIEW_WIDGET* viewFpPanel = m_chooserPanel->GetViewerPanel();
926 viewFpPanel->Show( m_showFpMode );
928
929 updateViews();
930}
931
932
934{
936
937 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
938 PCB_EDITOR_CONDITIONS cond( this );
939
940 wxASSERT( mgr );
941
942 // clang-format off
943#define CHECK( x ) ACTION_CONDITIONS().Check( x )
944
949
954
955#undef CHECK
956 // clang-format on
957}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ text_visibility_off
@ text_visibility
@ FPHOLDER
Definition board.h:402
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
static TOOL_ACTION toggleGrid
Definition actions.h:194
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:148
static TOOL_ACTION measureTool
Definition actions.h:248
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:150
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:149
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
WINDOW_SETTINGS m_Window
wxString m_ColorTheme
Active color theme name.
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
void SetIsSeparator()
Render button as a toolbar separator.
Container for design settings for a BOARD object.
void SetEnabledLayers(const LSET &aMask)
Change the bit-mask of enabled layers to aMask.
BOARD_STACKUP & GetStackupDescriptor()
void SetBoardThickness(int aThickness)
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Manage layers needed to make a physical board.
void RemoveAll()
Delete all items in list and clear the list.
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:422
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1301
Color settings are a bit different than most of the settings objects in that there can be more than o...
Handles action that are shared between different applications.
Implement a canvas based on a wxGLCanvas.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
EDA_MSG_PANEL * m_messagePanel
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
SELECTION_CONDITION CursorSmallCrosshairs()
Create a functor testing if the cursor is full screen in a frame.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION Cursor45Crosshairs()
SELECTION_CONDITION CursorFullCrosshairs()
void onFpViewReq(wxCommandEvent &event)
void updateViews()
Must be called after loading a new footprint: update footprint and/or 3D views.
void quiescePreview()
Stop the preview canvases and release their GPU/board state before the modal loop exits.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void KiwayMailIn(KIWAY_MAIL_EVENT &mail) override
Receive KIWAY_MAIL_EVENT messages from other players.
void closeFootprintChooser(wxCommandEvent &aEvent)
bool filterFootprint(LIB_TREE_NODE &aNode)
void on3DviewReq(wxCommandEvent &event)
void onFpChanged(wxCommandEvent &event)
FOOTPRINT_CHOOSER_FRAME(KIWAY *aKiway, wxWindow *aParent)
bool ShowModal(wxString *aFootprint, wxWindow *aParent) override
void OnPaint(wxPaintEvent &aEvent)
BOARD_ITEM_CONTAINER * GetModel() const override
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
bool Show(bool show) override
void OnOK(wxCommandEvent &aEvent)
void updatePanelsVisibility()
Show hide footprint view panel and/or 3d view panel according to the options (display 3D shapes and u...
void toggleBottomSplit(wxCommandEvent &event)
void SetPosition(const wxPoint &aNewPosition)
Force the position of the dialog to a new position.
void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr) override
Update the 3D view, if the viewer is opened by this frame.
std::vector< std::unique_ptr< EDA_PATTERN_MATCH > > m_fpFilters
void onExternalViewer3DEnable(wxCommandEvent &aEvent)
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh) const override
Helper to retrieve the current color settings.
PANEL_FOOTPRINT_CHOOSER * m_chooserPanel
Selection tool for the footprint viewer in CvPcb.
Panel that renders a single footprint via Cairo GAL, meant to be exported through Kiface.
FOOTPRINT * GetCurrentFootprint() const
FOOTPRINT_PREVIEW_PANEL_BASE * GetPreviewPanel()
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition kiway_mail.h:34
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
Definition kiway_mail.h:52
MAIL_T Command()
Returns the MAIL_T associated with this mail.
Definition kiway_mail.h:44
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
void SetModal(bool aIsModal)
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
UTF8 Format() const
Definition lib_id.cpp:132
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:718
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:725
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
void OnChar(wxKeyEvent &aEvent)
Gather all the actions that are shared by tools.
Definition pcb_actions.h:51
static TOOL_ACTION padDisplayMode
static TOOL_ACTION graphicsOutlines
Display footprint graphics as outlines.
static TOOL_ACTION textOutlines
Display texts as lines.
static TOOL_ACTION showPadNumbers
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
virtual PCB_VIEWERS_SETTINGS_BASE * GetViewerSettingsBase() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void SetBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Set the m_pcb member in such as way as to ensure deleting any previous BOARD.
BOARD * GetBoard() const
EDA_3D_VIEWER_FRAME * CreateAndShow3D_Frame()
Show the 3D view frame.
EDA_3D_VIEWER_FRAME * Get3DViewerFrame()
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
Group generic conditions for PCB editor states.
SELECTION_CONDITION PadFillDisplay()
Create a functor that tests if the frame fills the pads.
SELECTION_CONDITION GraphicsFillDisplay()
Create a functor that tests if the frame fills graphics items.
SELECTION_CONDITION PadNumbersDisplay()
Create a functor that tests if the pad numbers are displayed.
SELECTION_CONDITION TextFillDisplay()
Create a functor that tests if the frame fills text items.
Generic tool for picking an item.
Tool useful for viewing footprints.
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
TOOL_MANAGER * m_toolManager
TOOL_DISPATCHER * m_toolDispatcher
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
ACTIONS * m_actions
Master controller class:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
#define CHECK(x)
#define _(s)
Declaration of the eda_3d_viewer class.
#define FOOTPRINT_CHOOSER_FRAME_NAME
static wxRect s_dialogRect(0, 0, 0, 0)
static wxArrayString s_FootprintHistoryList
static unsigned s_FootprintHistoryMaxCount
static void AddFootprintToHistory(const wxString &aName)
@ FRAME_FOOTPRINT_CHOOSER
Definition frame_type.h:40
PROJECT & Prj()
Definition kicad.cpp:733
EVT_MENU(ID_COMPARE_PROJECT_BRANCHES, KICAD_MANAGER_FRAME::OnCompareProjectBranches) KICAD_MANAGER_FRAME
@ MAIL_SYMBOL_NETLIST
Definition mail_type.h:41
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition wxgtk/ui.cpp:266
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition wxgtk/ui.cpp:127
void ReparentModal(wxNonOwnedWindow *aWindow)
Move a window's parent to be the top-level window and force the window to be on top.
Definition wxgtk/ui.cpp:254
see class PGM_BASE
static const std::vector< std::string > filters
Definition plugin.cpp:64
#define DEFAULT_THEME
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
static std::vector< std::string > split(const std::string &aStr, const std::string &aDelim)
Split the input string into a vector of output strings.
Store the common settings that are saved and loaded for each window / frame.
#define PARENT_STYLE
#define MODAL_STYLE
KIBIS_PIN * pin
#define kv