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