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, 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
25#include <wx/button.h>
26#include <wx/checkbox.h>
27#include <wx/splitter.h>
28
29#include <pgm_base.h>
30#include <kiface_base.h>
31#include <kiway.h>
32#include <kiway_mail.h>
33#include <board.h>
34#include <footprint.h>
35#include <kiplatform/ui.h>
36#include <lset.h>
41#include <tool/tool_manager.h>
43#include <tool/common_tools.h>
44#include <tool/zoom_tool.h>
46#include <tools/pcb_actions.h>
50#include "wx/display.h"
53#include <project_pcb.h>
57
58
59static wxArrayString s_FootprintHistoryList;
60static unsigned s_FootprintHistoryMaxCount = 8;
61
62static void AddFootprintToHistory( const wxString& aName )
63{
64 // Remove duplicates
65 for( int ii = (int) s_FootprintHistoryList.GetCount() - 1; ii >= 0; --ii )
66 {
67 if( s_FootprintHistoryList[ ii ] == aName )
68 s_FootprintHistoryList.RemoveAt( (size_t) ii );
69 }
70
71 // Add the new name at the beginning of the history list
72 s_FootprintHistoryList.Insert( aName, 0 );
73
74 // Remove extra names
76 s_FootprintHistoryList.RemoveAt( s_FootprintHistoryList.GetCount() - 1 );
77}
78
79
80BEGIN_EVENT_TABLE( FOOTPRINT_CHOOSER_FRAME, PCB_BASE_FRAME )
82 EVT_BUTTON( wxID_OK, FOOTPRINT_CHOOSER_FRAME::OnOK )
83 EVT_BUTTON( wxID_CANCEL, FOOTPRINT_CHOOSER_FRAME::closeFootprintChooser )
85END_EVENT_TABLE()
86
87
88#define PARENT_STYLE ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
89 | wxWANTS_CHARS | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
90#define MODAL_STYLE ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
91 | wxWANTS_CHARS | wxFRAME_NO_TASKBAR )
92
93
95 PCB_BASE_FRAME( aKiway, aParent, FRAME_FOOTPRINT_CHOOSER, _( "Footprint Chooser" ),
96 wxDefaultPosition, wxDefaultSize, aParent ? PARENT_STYLE : MODAL_STYLE,
98 m_filterByPinCount( nullptr ),
99 m_filterByFPFilters( nullptr ),
103 m_pinCount( 0 ),
104 m_firstPaintEvent( true )
105{
106 SetModal( true );
107
108 m_messagePanel->Hide();
109
110 m_bottomPanel = new wxPanel( this );
111 wxBoxSizer* bottomSizer = new wxBoxSizer( wxVERTICAL );
112 wxBoxSizer* frameSizer = new wxBoxSizer( wxVERTICAL );
113
115 // Filter
116 [this]( LIB_TREE_NODE& aNode ) -> bool
117 {
118 return filterFootprint( aNode );
119 },
120 // Accept handler
121 [this]()
122 {
123 wxCommandEvent dummy;
124 OnOK( dummy );
125 },
126 // Escape handler
127 [this]()
128 {
129 DismissModal( false );
130 } );
131
132 frameSizer->Add( m_chooserPanel, 1, wxEXPAND );
133
134 SetCanvas( m_chooserPanel->GetViewerPanel()->GetPreviewPanel()->GetCanvas() );
135 SetBoard( m_chooserPanel->GetViewerPanel()->GetPreviewPanel()->GetBoard() );
136
137 // This board will only be used to hold a footprint for viewing
139
140 build3DCanvas(); // must be called after creating m_chooserPanel
142
143 // buttonsSizer contains the BITMAP buttons
144 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
145
146 buttonsSizer->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
147
148
149 m_toggleDescription = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
150 m_toggleDescription->SetIsRadioButton();
152 m_toggleDescription->SetToolTip( _( "Show/hide description panel" ) );
154 buttonsSizer->Add( m_toggleDescription, 0, wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 1 );
155
156 BITMAP_BUTTON* separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
157 separator->SetIsSeparator();
158 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
159
160 m_grButton3DView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
161 m_grButton3DView->SetIsRadioButton();
163 m_grButton3DView->SetToolTip( _( "Show/hide 3D view panel" ) );
165 buttonsSizer->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
166
167 m_grButtonFpView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
168 m_grButtonFpView->SetIsRadioButton();
170 m_grButtonFpView->SetToolTip( _( "Show/hide footprint view panel" ) );
172 buttonsSizer->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
173
174 separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
175 separator->SetIsSeparator();
176 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
177
178 m_show3DViewer = new wxCheckBox( m_bottomPanel, wxID_ANY, _( "Show 3D viewer in own window" ) );
179 buttonsSizer->Add( m_show3DViewer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 3 );
180
181 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
182 wxButton* okButton = new wxButton( m_bottomPanel, wxID_OK );
183 wxButton* cancelButton = new wxButton( m_bottomPanel, wxID_CANCEL );
184
185 sdbSizer->AddButton( okButton );
186 sdbSizer->AddButton( cancelButton );
187 sdbSizer->Realize();
188
189 buttonsSizer->Add( 20, 0, 0, 0, 5 ); // Add spacer
190 buttonsSizer->Add( sdbSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
191 bottomSizer->Add( buttonsSizer, 0, wxEXPAND, 5 );
192
193 m_bottomPanel->SetSizer( bottomSizer );
194 frameSizer->Add( m_bottomPanel, 0, wxEXPAND );
195
196 SetSizer( frameSizer );
197
198 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
199 m_chooserPanel->GetItemCount() ) );
200
201 Layout();
202 m_chooserPanel->FinishSetup();
203
204 Bind( wxEVT_CHAR_HOOK, &PANEL_FOOTPRINT_CHOOSER::OnChar, m_chooserPanel );
205
206 if( !m_showDescription )
207 {
208 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 0 );
209 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
210 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
211
213 }
214
215 // Create the manager and dispatcher & route draw panel events to the dispatcher
217 m_toolManager->SetEnvironment( GetBoard(), GetCanvas()->GetView(),
218 GetCanvas()->GetViewControls(), GetViewerSettingsBase(), this );
219 m_actions = new PCB_ACTIONS();
222
223 m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
224 m_toolManager->RegisterTool( new PCB_PICKER_TOOL ); // for setting grid origin
225 m_toolManager->RegisterTool( new ZOOM_TOOL );
226 m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
228
229 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
230 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetIsDefaultTool( true );
231
232 m_toolManager->InitTools();
233
236
237 // clang-format off
238 // Connect Events
239 m_toggleDescription->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
240 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
241 nullptr, this );
242
243 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
244 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
245 nullptr, this );
246
247 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
248 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
249 nullptr, this );
250
251 m_show3DViewer->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
253 nullptr, this );
254
255 Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
256 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
257 // clang-format on
258
259 // Needed on Linux to fix the position of widgets in bottomPanel
260 PostSizeEvent();
261}
262
263
265{
266 Unbind( wxEVT_CHAR_HOOK, &PANEL_FOOTPRINT_CHOOSER::OnChar, m_chooserPanel );
267
268 // Shutdown all running tools
269 if( m_toolManager )
270 m_toolManager->ShutdownAllTools();
271
272 // Work around assertion firing when we try to LockCtx on a hidden 3D canvas during dtor
273 wxCloseEvent dummy;
274 m_preview3DCanvas->Show();
275 m_preview3DCanvas->OnCloseWindow( dummy );
276
277 // Ensure view and data used by the preview panel are cleared before deleting other items
278 static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->ClearViewAndData();
279
280 // Disconnect board, which is owned by FOOTPRINT_PREVIEW_PANEL.
281 m_pcb = nullptr;
282
283 // clang-format off
284 // Disconnect Events
285 m_toggleDescription->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
286 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
287 nullptr, this );
288
289 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
290 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
291 nullptr, this );
292 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
293 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
294 nullptr, this );
295
296 m_show3DViewer->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
298 nullptr, this );
299
300 Disconnect( FP_SELECTION_EVENT,
301 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
302
303 // clang-format on
304
305 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
306 {
308 cfg->m_FootprintChooser.use_fp_filters = m_filterByFPFilters->GetValue();
309
311 cfg->m_FootprintChooser.filter_on_pin_count = m_filterByPinCount->GetValue();
312 }
313}
314
315
317{
318 if( aEvent.IsChecked() )
319 {
320 if( m_grButton3DView->IsChecked() )
321 Show3DViewerFrame(); // show external 3D viewer
322 }
323 else
324 {
325 // Close the external 3D viewer frame, if it is still enabled
327
328 if( viewer3D )
329 viewer3D->Close( true );
330 }
331
333}
334
335
337{
338 bool do_reload_board = true; // reload board flag
339
340 // At EDA_3D_VIEWER_FRAME creation, the current board is loaded, so disable loading
341 // the current board if the 3D frame is not yet created
342 if( Get3DViewerFrame() == nullptr )
343 do_reload_board = false;
344
346
347 // A stronger version of Raise() which promotes the window to its parent's level.
348 KIPLATFORM::UI::ReparentModal( draw3DFrame );
349
350 // And load or update the current board (if needed)
351 if( do_reload_board )
352 Update3DView( true, true );
353}
354
355
356void FOOTPRINT_CHOOSER_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
357{
358 LIB_ID fpID = m_chooserPanel->GetSelectedLibId();
359 wxString footprintName;
360
361 if( fpID.IsValid() )
362 footprintName << fpID.Format();
363
364 wxString title = _( "3D Viewer" ) + wxT( " \u2014 " ) + footprintName;
365 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &title );
366}
367
368
370{
372 return m_filterByPinCount->GetValue();
373
374 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
375 return cfg->m_FootprintChooser.filter_on_pin_count;
376
377 return false;
378}
379
380
382{
384 return m_filterByFPFilters->GetValue();
385
386 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
387 return cfg->m_FootprintChooser.use_fp_filters;
388
389 return false;
390}
391
392
394{
395 if( aNode.m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
396 {
397 // Normally lib nodes get scored by the max of their children's scores. However, if a
398 // lib node *has* no children then the scorer will call the filter on the lib node itself,
399 // and we just want to return true if we're not filtering at all.
400 return !filterByPinCount() && !filterByFPFilters();
401 }
402
403 auto patternMatch =
404 []( LIB_ID& id, std::vector<std::unique_ptr<EDA_PATTERN_MATCH>>& filters ) -> bool
405 {
406 // The matching is case insensitive
407 wxString name;
408
409 for( const std::unique_ptr<EDA_PATTERN_MATCH>& filter : filters )
410 {
411 name.Empty();
412
413 // If the filter contains a ':' then include the library name in the pattern
414 if( filter->GetPattern().Contains( wxS( ":" ) ) )
415 name = id.GetUniStringLibNickname().Lower() + wxS( ":" );
416
417 name += id.GetUniStringLibItemName().Lower();
418
419 if( filter->Find( name ) )
420 return true;
421 }
422
423 return false;
424 };
425
426 if( m_pinCount > 0 && filterByPinCount() )
427 {
428 if( aNode.m_PinCount != m_pinCount )
429 return false;
430 }
431
432 if( !m_fpFilters.empty() && filterByFPFilters() )
433 {
434 if( !patternMatch( aNode.m_LibId, m_fpFilters ) )
435 return false;
436 }
437
438 return true;
439}
440
441
443{
444 // Only dismiss a modal frame once, so that the return values set by
445 // the prior DismissModal() are not bashed for ShowModal().
446 if( !IsDismissed() )
447 DismissModal( false );
448
449 // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
450}
451
452
454{
455 if( PCBNEW_SETTINGS* pcb_cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg ) )
456 return &pcb_cfg->m_FootprintViewer;
457 else if( CVPCB_SETTINGS* cvpcb_cfg = dynamic_cast<CVPCB_SETTINGS*>( aCfg ) )
458 return &cvpcb_cfg->m_FootprintViewer;
459
460 wxFAIL_MSG( wxT( "FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS or CVPCB_SETTINGS" ) );
461 return &aCfg->m_Window; // non-null fail-safe
462}
463
464
466{
468 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
469}
470
471
472static wxRect s_dialogRect( 0, 0, 0, 0 );
473
474
476{
477 const std::string& payload = mail.GetPayload();
478
479 switch( mail.Command() )
480 {
482 {
483 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "MAIL_SYMBOL_NETLIST received: size=%zu" ), payload.size() );
484 wxSizer* filtersSizer = m_chooserPanel->GetFiltersSizer();
485 wxWindow* filtersWindow = filtersSizer->GetContainingWindow();
486 wxString msg;
487
488 m_pinCount = 0;
489 m_fpFilters.clear();
490
491 /*
492 * Symbol netlist format:
493 * pinNumber pinName <tab> pinNumber pinName...
494 * fpFilter fpFilter...
495 */
496 std::map<wxString, wxString> pinNames;
497 std::vector<std::string> strings = split( payload, "\r" );
498
499 if( strings.size() >= 1 && !strings[0].empty() )
500 {
501 wxArrayString tokens = wxSplit( strings[0], '\t' );
502
503 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "First line entries=%u" ), (unsigned) tokens.size() );
504
505 for( const wxString& pin : tokens )
506 pinNames[ pin.BeforeFirst( ' ' ) ] = pin.AfterFirst( ' ' );
507
508 m_pinCount = (int) pinNames.size();
509
510 wxString pinList;
511
512 for( const auto& kv : pinNames )
513 {
514 if( !pinList.IsEmpty() )
515 pinList << wxS( "," );
516
517 pinList << kv.first;
518 }
519
520 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "Parsed pins=%d -> [%s]" ), m_pinCount, pinList );
521 }
522
523 if( strings.size() >= 2 && !strings[1].empty() )
524 {
525 for( const wxString& filter : wxSplit( strings[1], ' ' ) )
526 {
527 m_fpFilters.push_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>() );
528 m_fpFilters.back()->SetPattern( filter.Lower() );
529 }
530 }
531
532 if( !m_fpFilters.empty() )
533 {
534 msg.Printf( _( "Apply footprint filters (%s)" ), strings[1] );
535
537 {
538 m_filterByFPFilters = new wxCheckBox( filtersWindow, wxID_ANY, msg );
539
540 m_filterByFPFilters->Bind( wxEVT_CHECKBOX,
541 [&]( wxCommandEvent& evt )
542 {
543 m_chooserPanel->Regenerate();
544 } );
545
546 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
547 m_filterByFPFilters->SetValue( cfg->m_FootprintChooser.use_fp_filters );
548
549 m_chooserPanel->GetFiltersSizer()->Add( m_filterByFPFilters, 0, wxEXPAND|wxBOTTOM, 4 );
550 }
551
552 m_filterByFPFilters->SetLabel( msg );
553 }
554 else
555 {
557 m_filterByFPFilters->Hide();
558 }
559
560 if( m_pinCount > 0 )
561 {
562 msg.Printf( _( "Filter by pin count (%d)" ), m_pinCount );
563 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "Pin-count label: %s" ), msg );
564
565 if( !m_filterByPinCount )
566 {
567 m_filterByPinCount = new wxCheckBox( filtersWindow, wxID_ANY, msg );
568
569 m_filterByPinCount->Bind( wxEVT_CHECKBOX,
570 [&]( wxCommandEvent& evt )
571 {
572 m_chooserPanel->Regenerate();
573 } );
574
575 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
576 m_filterByPinCount->SetValue( cfg->m_FootprintChooser.filter_on_pin_count );
577
578 m_chooserPanel->GetFiltersSizer()->Add( m_filterByPinCount, 0, wxEXPAND|wxBOTTOM, 4 );
579 }
580
581 m_filterByPinCount->SetLabel( msg );
582 }
583 else
584 {
586 m_filterByPinCount->Hide();
587 }
588
589 m_chooserPanel->GetViewerPanel()->SetPinFunctions( pinNames );
590 wxLogTrace( "FOOTPRINT_CHOOSER", wxS( "SetPinFunctions called with %zu entries" ), pinNames.size() );
591
592 // Save the wxFormBuilder size of the dialog...
593 if( s_dialogRect.GetSize().x == 0 || s_dialogRect.GetSize().y == 0 )
594 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
595
596 // ... and then give it a kick to get it to layout the new items
597 GetSizer()->SetSizeHints( this );
598 break;
599 }
600
601 default:
602 break;
603 }
604}
605
606
608{
609 return static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->GetCurrentFootprint();
610}
611
612
613bool FOOTPRINT_CHOOSER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
614{
615 if( aFootprint && !aFootprint->IsEmpty() )
616 {
617 LIB_ID fpid;
618
619 fpid.Parse( *aFootprint, true );
620
621 if( fpid.IsValid() )
622 m_chooserPanel->SetPreselect( fpid );
623 }
624
625 return KIWAY_PLAYER::ShowModal( aFootprint, aParent );
626}
627
628
629void FOOTPRINT_CHOOSER_FRAME::SetPosition( const wxPoint& aNewPosition )
630{
631 PCB_BASE_FRAME::SetPosition( aNewPosition );
632
633 s_dialogRect.SetPosition( aNewPosition );
634}
635
636
638{
639 bool ret;
640
641 // Show or hide the window. If hiding, save current position and size.
642 // If showing, use previous position and size.
643 if( show )
644 {
645#ifndef __WINDOWS__
646 PCB_BASE_FRAME::Raise(); // Needed on OS X and some other window managers (i.e. Unity)
647#endif
648 ret = PCB_BASE_FRAME::Show( show );
649
650 // returns a zeroed-out default wxRect if none existed before.
651 wxRect savedDialogRect = s_dialogRect;
652
653 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
654 {
655 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
656 std::max( wxWindow::GetSize().x, savedDialogRect.GetSize().x ),
657 std::max( wxWindow::GetSize().y, savedDialogRect.GetSize().y ),
658 0 );
659 }
660
661 // Be sure that the dialog appears in a visible area
662 // (the dialog position might have been stored at the time when it was
663 // shown on another display)
664 if( wxDisplay::GetFromWindow( this ) == wxNOT_FOUND )
665 Centre();
666 }
667 else
668 {
669 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
670 ret = PCB_BASE_FRAME::Show( show );
671 }
672
673 return ret;
674}
675
676
677void FOOTPRINT_CHOOSER_FRAME::OnPaint( wxPaintEvent& aEvent )
678{
680 {
682 KIPLATFORM::UI::ForceFocus( m_chooserPanel->GetFocusTarget() );
683
684 m_firstPaintEvent = false;
685 }
686
687 aEvent.Skip();
688}
689
690
691void FOOTPRINT_CHOOSER_FRAME::OnOK( wxCommandEvent& aEvent )
692{
693 LIB_ID fpID = m_chooserPanel->GetSelectedLibId();
694
695 if( fpID.IsValid() )
696 {
697 wxString footprint = fpID.Format();
698
699 AddFootprintToHistory( footprint );
700 DismissModal( true, footprint );
701 }
702 else
703 {
704 DismissModal( false );
705 }
706}
707
708
710{
711 Close( false );
712}
713
714
715void FOOTPRINT_CHOOSER_FRAME::onFpChanged( wxCommandEvent& event )
716{
717 updateViews();
718
720}
721
722
724{
725 // initialize m_boardAdapter used by the 3D canvas
726 BOARD* dummyBoard = GetBoard();
727 m_boardAdapter.SetBoard( dummyBoard );
728 m_boardAdapter.m_IsBoardView = false;
729 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
730
732
733 // Build the 3D canvas
738
739 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
740 m_chooserPanel->m_RightPanel->Layout();
741
742 BOARD_DESIGN_SETTINGS& dummy_bds = dummyBoard->GetDesignSettings();
743 dummy_bds.SetBoardThickness( pcbIUScale.mmToIU( 1.6 ) );
745 BOARD_STACKUP& dummy_board_stackup = dummyBoard->GetDesignSettings().GetStackupDescriptor();
746 dummy_board_stackup.RemoveAll();
747 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
748}
749
750
752{
754
756
757 m_chooserPanel->GetDetailsPanel()->Show( m_showDescription );
758
759 if( !m_showDescription )
760 {
761 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( GetSize().GetHeight() );
762 m_chooserPanel->GetVerticalSpliter()->SetSashPosition(
763 GetSize().GetHeight() + m_chooserPanel->GetDetailsPanel()->GetSize().GetHeight() );
764
765 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
766 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
767
769 }
770 else
771 {
772 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 80 );
773 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Show();
774 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible( false );
775
777 }
778
779 m_chooserPanel->GetVerticalSpliter()->UpdateSize();
780
781 m_chooserPanel->Layout();
782 m_chooserPanel->Refresh();
783}
784
785
786void FOOTPRINT_CHOOSER_FRAME::on3DviewReq( wxCommandEvent& event )
787{
788 if( m_show3DMode == true )
789 {
790 if( m_showFpMode == true )
791 {
792 m_show3DMode = false;
795 }
796 }
797 else
798 {
799 if( m_show3DViewer->IsChecked() )
800 {
802 }
803 else
804 {
805 // Close 3D viewer frame, if it is still enabled
807
808 if( viewer3D )
809 viewer3D->Close( true );
810 }
811
812 m_show3DMode = true;
815 }
816}
817
818
819void FOOTPRINT_CHOOSER_FRAME::onFpViewReq( wxCommandEvent& event )
820{
821 if( m_showFpMode == true )
822 {
823 if( m_show3DMode == true )
824 {
825 m_showFpMode = false;
828 }
829 }
830 else
831 {
832 m_showFpMode = true;
835 }
836}
837
838
840{
842
843 if( m_preview3DCanvas->IsShown() )
844 {
845 m_preview3DCanvas->ReloadRequest();
846 m_preview3DCanvas->Request_refresh();
847 }
848
849 if( viewer3D )
850 {
851 Update3DView( true, true );
852 }
853
854 m_chooserPanel->m_RightPanel->Layout();
855 m_chooserPanel->m_RightPanel->Refresh();
856}
857
858
860{
861 FOOTPRINT_PREVIEW_WIDGET* viewFpPanel = m_chooserPanel->GetViewerPanel();
862 viewFpPanel->Show( m_showFpMode );
864
865 updateViews();
866}
867
868
870{
872
873 ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
874 PCB_EDITOR_CONDITIONS cond( this );
875
876 wxASSERT( mgr );
877
878 // clang-format off
879#define CHECK( x ) ACTION_CONDITIONS().Check( x )
880
885
890
891#undef CHECK
892 // clang-format on
893}
const char * name
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ text_visibility_off
@ text_visibility
@ FPHOLDER
Definition board.h:314
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
static TOOL_ACTION toggleGrid
Definition actions.h:198
static TOOL_ACTION cursorSmallCrosshairs
Definition actions.h:152
static TOOL_ACTION measureTool
Definition actions.h:252
static TOOL_ACTION cursor45Crosshairs
Definition actions.h:154
static TOOL_ACTION cursorFullCrosshairs
Definition actions.h:153
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:322
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition board.h:334
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1083
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.
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_ROUTED_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
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition kiway_mail.h:38
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
Definition kiway_mail.h:56
MAIL_T Command()
Returns the MAIL_T associated with this mail.
Definition kiway_mail.h:48
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:295
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
UTF8 Format() const
Definition lib_id.cpp:119
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:722
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:729
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:44
PROJECT & Prj()
Definition kicad.cpp:642
@ MAIL_SYMBOL_NETLIST
Definition mail_type.h:45
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition wxgtk/ui.cpp:180
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition wxgtk/ui.cpp:125
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:168
see class PGM_BASE
#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