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>
47#include "wx/display.h"
50#include <project_pcb.h>
54
55
56static wxArrayString s_FootprintHistoryList;
57static unsigned s_FootprintHistoryMaxCount = 8;
58
59static void AddFootprintToHistory( const wxString& aName )
60{
61 // Remove duplicates
62 for( int ii = (int) s_FootprintHistoryList.GetCount() - 1; ii >= 0; --ii )
63 {
64 if( s_FootprintHistoryList[ ii ] == aName )
65 s_FootprintHistoryList.RemoveAt( (size_t) ii );
66 }
67
68 // Add the new name at the beginning of the history list
69 s_FootprintHistoryList.Insert( aName, 0 );
70
71 // Remove extra names
73 s_FootprintHistoryList.RemoveAt( s_FootprintHistoryList.GetCount() - 1 );
74}
75
76
77BEGIN_EVENT_TABLE( FOOTPRINT_CHOOSER_FRAME, PCB_BASE_FRAME )
79 EVT_BUTTON( wxID_OK, FOOTPRINT_CHOOSER_FRAME::OnOK )
80 EVT_BUTTON( wxID_CANCEL, FOOTPRINT_CHOOSER_FRAME::closeFootprintChooser )
82END_EVENT_TABLE()
83
84
85#define MODAL_FRAME ( wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN \
86 | wxWANTS_CHARS | wxFRAME_NO_TASKBAR | wxFRAME_FLOAT_ON_PARENT )
87
88
90 PCB_BASE_FRAME( aKiway, aParent, FRAME_FOOTPRINT_CHOOSER, _( "Footprint Chooser" ),
91 wxDefaultPosition, wxDefaultSize, MODAL_FRAME,
93 m_filterByPinCount( nullptr ),
94 m_filterByFPFilters( nullptr ),
95 m_boardAdapter(),
96 m_currentCamera( m_trackBallCamera ),
97 m_trackBallCamera( 2 * RANGE_SCALE_3D ),
98 m_pinCount( 0 ),
99 m_firstPaintEvent( true )
100{
101 SetModal( true );
102
103 m_messagePanel->Hide();
104
105 m_bottomPanel = new wxPanel( this );
106 wxBoxSizer* bottomSizer = new wxBoxSizer( wxVERTICAL );
107 wxBoxSizer* frameSizer = new wxBoxSizer( wxVERTICAL );
108
110 // Filter
111 [this]( LIB_TREE_NODE& aNode ) -> bool
112 {
113 return filterFootprint( aNode );
114 },
115 // Accept handler
116 [this]()
117 {
118 wxCommandEvent dummy;
119 OnOK( dummy );
120 },
121 // Escape handler
122 [this]()
123 {
124 DismissModal( false );
125 } );
126
127 frameSizer->Add( m_chooserPanel, 1, wxEXPAND );
128
131
132 // This board will only be used to hold a footprint for viewing
133 GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
134
135 build3DCanvas(); // must be called after creating m_chooserPanel
137
138 // buttonsSizer contains the BITMAP buttons
139 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
140
141 buttonsSizer->Add( 0, 0, 1, 0, 5 ); // Add spacer to right-align buttons
142
143
144 m_toggleDescription = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
146 m_toggleDescription->SetBitmap( KiBitmapBundle( BITMAPS::text_visibility_off ) );
148 buttonsSizer->Add( m_toggleDescription, 0, wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 1 );
149
150 BITMAP_BUTTON* separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
151 separator->SetIsSeparator();
152 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
153
154 m_grButton3DView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
156 m_grButton3DView->SetBitmap( KiBitmapBundle( BITMAPS::shape_3d ) );
158 buttonsSizer->Add( m_grButton3DView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
159
160 m_grButtonFpView = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
162 m_grButtonFpView->SetBitmap( KiBitmapBundle( BITMAPS::module ) );
164 buttonsSizer->Add( m_grButtonFpView, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
165
166 separator = new BITMAP_BUTTON( m_bottomPanel, wxID_ANY, wxNullBitmap );
167 separator->SetIsSeparator();
168 buttonsSizer->Add( separator, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 1 );
169
170 m_show3DViewer = new wxCheckBox( m_bottomPanel, wxID_ANY, _( "Show 3D viewer in own window" ) );
171 buttonsSizer->Add( m_show3DViewer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 3 );
172
173 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
174 wxButton* okButton = new wxButton( m_bottomPanel, wxID_OK );
175 wxButton* cancelButton = new wxButton( m_bottomPanel, wxID_CANCEL );
176
177 sdbSizer->AddButton( okButton );
178 sdbSizer->AddButton( cancelButton );
179 sdbSizer->Realize();
180
181 buttonsSizer->Add( 20, 0, 0, 0, 5 ); // Add spacer
182 buttonsSizer->Add( sdbSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
183 bottomSizer->Add( buttonsSizer, 0, wxEXPAND, 5 );
184
185 m_bottomPanel->SetSizer( bottomSizer );
186 frameSizer->Add( m_bottomPanel, 0, wxEXPAND );
187
188 SetSizer( frameSizer );
189
190 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
192
193 Layout();
195
196 if( !m_showDescription )
197 {
198 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 0 );
199 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
200 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
201
202 m_toggleDescription->SetBitmap( KiBitmapBundle( BITMAPS::text_visibility ) );
203 }
204
205 // Create the manager and dispatcher & route draw panel events to the dispatcher
208 GetCanvas()->GetViewControls(), GetViewerSettingsBase(), this );
209 m_actions = new PCB_ACTIONS();
212
213 m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
214 m_toolManager->RegisterTool( new PCB_PICKER_TOOL ); // for setting grid origin
218
219 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
220 m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetIsDefaultTool( true );
221
223
226
227 // clang-format off
228 // Connect Events
229 m_toggleDescription->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
230 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
231 nullptr, this );
232
233 m_grButton3DView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
234 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
235 nullptr, this );
236
237 m_grButtonFpView->Connect( wxEVT_COMMAND_BUTTON_CLICKED ,
238 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
239 nullptr, this );
240
241 m_show3DViewer->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
243 nullptr, this );
244
245 Connect( FP_SELECTION_EVENT, // custom event fired by a PANEL_FOOTPRINT_CHOOSER
246 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
247 // clang-format on
248
249 // Needed on Linux to fix the position of widgets in bottomPanel
250 PostSizeEvent();
251}
252
253
255{
256 // Work around assertion firing when we try to LockCtx on a hidden 3D canvas during dtor
257 wxCloseEvent dummy;
258 m_preview3DCanvas->Show();
260
261 // Ensure view and data used by the preview panel are cleared before deleting other items
262 static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->ClearViewAndData();
263
264 // Disconnect board, which is owned by FOOTPRINT_PREVIEW_PANEL.
265 m_pcb = nullptr;
266
267 // clang-format off
268 // Disconnect Events
269 m_toggleDescription->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
270 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::toggleBottomSplit ),
271 nullptr, this );
272
273 m_grButton3DView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
274 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::on3DviewReq ),
275 nullptr, this );
276 m_grButtonFpView->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
277 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpViewReq ),
278 nullptr, this );
279
280 m_show3DViewer->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED ,
282 nullptr, this );
283
284 Disconnect( FP_SELECTION_EVENT,
285 wxCommandEventHandler( FOOTPRINT_CHOOSER_FRAME::onFpChanged ), nullptr, this );
286 // clang-format on
287
288 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
289 {
291 cfg->m_FootprintChooser.use_fp_filters = m_filterByFPFilters->GetValue();
292
294 cfg->m_FootprintChooser.filter_on_pin_count = m_filterByPinCount->GetValue();
295 }
296}
297
298
300{
301 if( aEvent.IsChecked() )
302 {
304 Show3DViewerFrame(); // show external 3D viewer
305 }
306 else
307 {
308 // Close the external 3D viewer frame, if it is still enabled
310
311 if( viewer3D )
312 viewer3D->Close( true );
313 }
314
316}
317
318
320{
321 bool do_reload_board = true; // reload board flag
322
323 // At EDA_3D_VIEWER_FRAME creation, the current board is loaded, so disable loading
324 // the current board if the 3D frame is not yet created
325 if( Get3DViewerFrame() == nullptr )
326 do_reload_board = false;
327
329
330 // A stronger version of Raise() which promotes the window to its parent's level.
331 KIPLATFORM::UI::ReparentModal( draw3DFrame );
332
333 // And load or update the current board (if needed)
334 if( do_reload_board )
335 Update3DView( true, true );
336}
337
338
339void FOOTPRINT_CHOOSER_FRAME::Update3DView( bool aMarkDirty, bool aRefresh, const wxString* aTitle )
340{
342 wxString footprintName;
343
344 if( fpID.IsValid() )
345 footprintName << fpID.Format();
346
347 wxString title = _( "3D Viewer" ) + wxT( " \u2014 " ) + footprintName;
348 PCB_BASE_FRAME::Update3DView( aMarkDirty, aRefresh, &title );
349}
350
351
353{
355 return m_filterByPinCount->GetValue();
356
357 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
358 return cfg->m_FootprintChooser.filter_on_pin_count;
359
360 return false;
361}
362
363
365{
367 return m_filterByFPFilters->GetValue();
368
369 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
370 return cfg->m_FootprintChooser.use_fp_filters;
371
372 return false;
373}
374
375
377{
378 if( aNode.m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
379 {
380 // Normally lib nodes get scored by the max of their children's scores. However, if a
381 // lib node *has* no children then the scorer will call the filter on the lib node itself,
382 // and we just want to return true if we're not filtering at all.
383 return !filterByPinCount() && !filterByFPFilters();
384 }
385
386 auto patternMatch =
387 []( LIB_ID& id, std::vector<std::unique_ptr<EDA_PATTERN_MATCH>>& filters ) -> bool
388 {
389 // The matching is case insensitive
390 wxString name;
391
392 for( const std::unique_ptr<EDA_PATTERN_MATCH>& filter : filters )
393 {
394 name.Empty();
395
396 // If the filter contains a ':' then include the library name in the pattern
397 if( filter->GetPattern().Contains( wxS( ":" ) ) )
398 name = id.GetUniStringLibNickname().Lower() + wxS( ":" );
399
400 name += id.GetUniStringLibItemName().Lower();
401
402 if( filter->Find( name ) )
403 return true;
404 }
405
406 return false;
407 };
408
409 if( m_pinCount > 0 && filterByPinCount() )
410 {
411 if( aNode.m_PinCount != m_pinCount )
412 return false;
413 }
414
415 if( !m_fpFilters.empty() && filterByFPFilters() )
416 {
417 if( !patternMatch( aNode.m_LibId, m_fpFilters ) )
418 return false;
419 }
420
421 return true;
422}
423
424
426{
427 // Only dismiss a modal frame once, so that the return values set by
428 // the prior DismissModal() are not bashed for ShowModal().
429 if( !IsDismissed() )
430 DismissModal( false );
431
432 // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
433}
434
435
437{
438 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
439 wxCHECK_MSG( cfg, nullptr, wxT( "config not existing" ) );
440
441 return &cfg->m_FootprintViewer;
442}
443
444
446{
447 FOOTPRINT_EDITOR_SETTINGS* cfg = GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>( "fpedit" );
448 return ::GetColorSettings( cfg ? cfg->m_ColorTheme : DEFAULT_THEME );
449}
450
451
452static wxRect s_dialogRect( 0, 0, 0, 0 );
453
454
456{
457 const std::string& payload = mail.GetPayload();
458
459 switch( mail.Command() )
460 {
462 {
463 wxSizer* filtersSizer = m_chooserPanel->GetFiltersSizer();
464 wxWindow* filtersWindow = filtersSizer->GetContainingWindow();
465 wxString msg;
466
467 m_pinCount = 0;
468 m_fpFilters.clear();
469
470 /*
471 * Symbol netlist format:
472 * pinNumber pinName <tab> pinNumber pinName...
473 * fpFilter fpFilter...
474 */
475 std::map<wxString, wxString> pinNames;
476 std::vector<std::string> strings = split( payload, "\r" );
477
478 if( strings.size() >= 1 && !strings[0].empty() )
479 {
480 for( const wxString& pin : wxSplit( strings[0], '\t' ) )
481 pinNames[ pin.BeforeFirst( ' ' ) ] = pin.AfterFirst( ' ' );
482
483 m_pinCount = pinNames.size();
484
485 if( m_pinCount > 0 )
486 {
487 msg.Printf( _( "Filter by pin count (%d)" ), m_pinCount );
488 m_filterByPinCount = new wxCheckBox( filtersWindow, wxID_ANY, msg );
489
490 m_filterByPinCount->Bind( wxEVT_CHECKBOX,
491 [&]( wxCommandEvent& evt )
492 {
494 } );
495
496 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
497 m_filterByPinCount->SetValue( cfg->m_FootprintChooser.filter_on_pin_count );
498 }
499 }
500
501 if( strings.size() >= 2 && !strings[1].empty() )
502 {
503 for( const wxString& filter : wxSplit( strings[1], ' ' ) )
504 {
505 m_fpFilters.push_back( std::make_unique<EDA_PATTERN_MATCH_WILDCARD_ANCHORED>() );
506 m_fpFilters.back()->SetPattern( filter.Lower() );
507 }
508
509 msg.Printf( _( "Apply footprint filters (%s)" ), strings[1] );
510 m_filterByFPFilters = new wxCheckBox( filtersWindow, wxID_ANY, msg );
511
512 m_filterByFPFilters->Bind( wxEVT_CHECKBOX,
513 [&]( wxCommandEvent& evt )
514 {
516 } );
517
518 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
519 m_filterByFPFilters->SetValue( cfg->m_FootprintChooser.use_fp_filters );
520 }
521
523 m_chooserPanel->GetFiltersSizer()->Add( m_filterByFPFilters, 0, wxEXPAND|wxBOTTOM, 4 );
524
526 m_chooserPanel->GetFiltersSizer()->Add( m_filterByPinCount, 0, wxEXPAND|wxBOTTOM, 4 );
527
529
530 // Save the wxFormBuilder size of the dialog...
531 if( s_dialogRect.GetSize().x == 0 || s_dialogRect.GetSize().y == 0 )
532 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
533
534 // ... and then give it a kick to get it to layout the new items
535 GetSizer()->SetSizeHints( this );
536 break;
537 }
538
539 default:
540 break;
541 }
542}
543
544
546{
547 return static_cast<FOOTPRINT_PREVIEW_PANEL*>( m_chooserPanel->GetViewerPanel()->GetPreviewPanel() )->GetCurrentFootprint();
548}
549
550
551bool FOOTPRINT_CHOOSER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
552{
553 if( aFootprint && !aFootprint->IsEmpty() )
554 {
555 LIB_ID fpid;
556
557 fpid.Parse( *aFootprint, true );
558
559 if( fpid.IsValid() )
561 }
562
563 return KIWAY_PLAYER::ShowModal( aFootprint, aParent );
564}
565
566
567void FOOTPRINT_CHOOSER_FRAME::SetPosition( const wxPoint& aNewPosition )
568{
569 PCB_BASE_FRAME::SetPosition( aNewPosition );
570
571 s_dialogRect.SetPosition( aNewPosition );
572}
573
574
576{
577 bool ret;
578
579 // Show or hide the window. If hiding, save current position and size.
580 // If showing, use previous position and size.
581 if( show )
582 {
583#ifndef __WINDOWS__
584 PCB_BASE_FRAME::Raise(); // Needed on OS X and some other window managers (i.e. Unity)
585#endif
586 ret = PCB_BASE_FRAME::Show( show );
587
588 // returns a zeroed-out default wxRect if none existed before.
589 wxRect savedDialogRect = s_dialogRect;
590
591 if( savedDialogRect.GetSize().x != 0 && savedDialogRect.GetSize().y != 0 )
592 {
593 SetSize( savedDialogRect.GetPosition().x, savedDialogRect.GetPosition().y,
594 std::max( wxWindow::GetSize().x, savedDialogRect.GetSize().x ),
595 std::max( wxWindow::GetSize().y, savedDialogRect.GetSize().y ),
596 0 );
597 }
598
599 // Be sure that the dialog appears in a visible area
600 // (the dialog position might have been stored at the time when it was
601 // shown on another display)
602 if( wxDisplay::GetFromWindow( this ) == wxNOT_FOUND )
603 Centre();
604 }
605 else
606 {
607 s_dialogRect = wxRect( wxWindow::GetPosition(), wxWindow::GetSize() );
608 ret = PCB_BASE_FRAME::Show( show );
609 }
610
611 return ret;
612}
613
614
615void FOOTPRINT_CHOOSER_FRAME::OnPaint( wxPaintEvent& aEvent )
616{
618 {
621
622 m_firstPaintEvent = false;
623 }
624
625 aEvent.Skip();
626}
627
628
629void FOOTPRINT_CHOOSER_FRAME::OnOK( wxCommandEvent& aEvent )
630{
632
633 if( fpID.IsValid() )
634 {
635 wxString footprint = fpID.Format();
636
637 AddFootprintToHistory( footprint );
638 DismissModal( true, footprint );
639 }
640 else
641 {
642 DismissModal( false );
643 }
644}
645
646
648{
649 Close( false );
650}
651
652
653void FOOTPRINT_CHOOSER_FRAME::onFpChanged( wxCommandEvent& event )
654{
655 updateViews();
656
658}
659
660
662{
663 // initialize m_boardAdapter used by the 3D canvas
664 BOARD* dummyBoard = GetBoard();
665 m_boardAdapter.SetBoard( dummyBoard );
667 m_boardAdapter.m_IsPreviewer = true; // Force display 3D models, regardless the 3D viewer options
668
669 m_boardAdapter.m_Cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" );
670
671 // Build the 3D canvas
673 OGL_ATT_LIST::GetAttributesList( ANTIALIASING_MODE::AA_8X ),
676
677 m_chooserPanel->m_RightPanelSizer->Add( m_preview3DCanvas, 1, wxEXPAND, 5 );
678 m_chooserPanel->m_RightPanel->Layout();
679
680 BOARD_DESIGN_SETTINGS& dummy_bds = dummyBoard->GetDesignSettings();
681 dummy_bds.SetBoardThickness( pcbIUScale.mmToIU( 1.6 ) );
683 BOARD_STACKUP& dummy_board_stackup = dummyBoard->GetDesignSettings().GetStackupDescriptor();
684 dummy_board_stackup.RemoveAll();
685 dummy_board_stackup.BuildDefaultStackupList( &dummy_bds, 2 );
686}
687
688
690{
692
694
696
697 if( !m_showDescription )
698 {
699 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( GetSize().GetHeight() );
700 m_chooserPanel->GetVerticalSpliter()->SetSashPosition(
701 GetSize().GetHeight() + m_chooserPanel->GetDetailsPanel()->GetSize().GetHeight() );
702
703 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Hide();
704 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible();
705
706 m_toggleDescription->SetBitmap( KiBitmapBundle( BITMAPS::text_visibility ) );
707 }
708 else
709 {
710 m_chooserPanel->GetVerticalSpliter()->SetMinimumPaneSize( 80 );
711 m_chooserPanel->GetVerticalSpliter()->GetWindow2()->Show();
712 m_chooserPanel->GetVerticalSpliter()->SetSashInvisible( false );
713
714 m_toggleDescription->SetBitmap( KiBitmapBundle( BITMAPS::text_visibility_off ) );
715 }
716
717 m_chooserPanel->GetVerticalSpliter()->UpdateSize();
718
719 m_chooserPanel->Layout();
720 m_chooserPanel->Refresh();
721}
722
723void FOOTPRINT_CHOOSER_FRAME::on3DviewReq( wxCommandEvent& event )
724{
725 if( m_show3DMode == true )
726 {
727 if( m_showFpMode == true )
728 {
729 m_show3DMode = false;
732 }
733 }
734 else
735 {
736 if( m_show3DViewer->IsChecked() )
737 {
739 }
740 else
741 {
742 // Close 3D viewer frame, if it is still enabled
744 if( viewer3D )
745 viewer3D->Close( true );
746 }
747
748 m_show3DMode = true;
751 }
752}
753
754
755void FOOTPRINT_CHOOSER_FRAME::onFpViewReq( wxCommandEvent& event )
756{
757 if( m_showFpMode == true )
758 {
759 if( m_show3DMode == true )
760 {
761 m_showFpMode = false;
764 }
765 }
766 else
767 {
768 m_showFpMode = true;
771 }
772}
773
774
776{
778
779 if( m_preview3DCanvas->IsShown() )
780 {
783 }
784
785 if( viewer3D )
786 {
787 Update3DView( true, true );
788 }
789
790 m_chooserPanel->m_RightPanel->Layout();
791 m_chooserPanel->m_RightPanel->Refresh();
792}
793
795{
797 viewFpPanel->Show( m_showFpMode );
799
800 updateViews();
801}
802
803
805{
807
809 PCB_EDITOR_CONDITIONS cond( this );
810
811 wxASSERT( mgr );
812
813 // clang-format off
814#define CHECK( x ) ACTION_CONDITIONS().Check( x )
815
818
819 mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MM ) ) );
820 mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCH ) ) );
821 mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
822
824
829
830#undef CHECK
831 // clang-format on
832}
833
834
const char * name
Definition: DXF_plotter.cpp:62
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
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: board_adapter.h:66
static TOOL_ACTION toggleGrid
Definition: actions.h:195
static TOOL_ACTION millimetersUnits
Definition: actions.h:203
static TOOL_ACTION milsUnits
Definition: actions.h:202
static TOOL_ACTION inchesUnits
Definition: actions.h:201
static TOOL_ACTION toggleCursorStyle
Definition: actions.h:151
static TOOL_ACTION measureTool
Definition: actions.h:245
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.
Definition: app_settings.h:108
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:235
A bitmap button widget that behaves like an AUI toolbar item's button when it is drawn.
Definition: bitmap_button.h:42
void SetIsRadioButton()
bool IsChecked() const
void Check(bool aCheck=true)
Check the control.
void SetIsSeparator()
Render button as a toolbar separator.
void SetBitmap(const wxBitmapBundle &aBmp)
Set the bitmap shown when the button is enabled.
bool m_IsPreviewer
true if we're in a 3D preview panel, false for the standard 3D viewer
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
EDA_3D_VIEWER_SETTINGS * m_Cfg
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:317
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
Definition: board.h:329
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:946
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.
Definition: common_tools.h:38
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:51
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
void OnCloseWindow(wxCloseEvent &event)
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
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 Units(EDA_UNITS aUnit)
Create a functor that tests if the frame has the specified units.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION FullscreenCursor()
Create a functor testing if the cursor is full screen in a frame.
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.
virtual BOARD * GetBoard()=0
virtual EDA_DRAW_PANEL_GAL * GetCanvas()=0
Get the GAL canvas.
Panel that renders a single footprint via Cairo GAL, meant to be exported through Kiface.
void SetPinFunctions(const std::map< wxString, wxString > &aPinFunctions)
Set the pin functions from the symbol's netlist.
FOOTPRINT_PREVIEW_PANEL_BASE * GetPreviewPanel()
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
Definition: kiway_express.h:40
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
Definition: kiway_express.h:58
MAIL_T Command()
Returns the MAIL_T associated with this mail.
Definition: kiway_express.h:50
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...
bool IsDismissed()
void SetModal(bool aIsModal)
Definition: kiway_player.h:155
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:285
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.
enum TYPE m_Type
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition: lset.cpp:708
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition: lset.cpp:715
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
wxWindow * GetFocusTarget() const
wxSplitterWindow * GetVerticalSpliter() const
FOOTPRINT_PREVIEW_WIDGET * GetViewerPanel() const
void SetPreselect(const LIB_ID &aPreselect)
LIB_ID GetSelectedLibId() const
To be called after this dialog returns from ShowModal().
WINDOW_SETTINGS m_FootprintViewer
Gather all the actions that are shared by tools.
Definition: pcb_actions.h:51
static TOOL_ACTION toggleHV45Mode
Definition: pcb_actions.h:540
static TOOL_ACTION padDisplayMode
Definition: pcb_actions.h:319
static TOOL_ACTION graphicsOutlines
Display footprint graphics as outlines.
Definition: pcb_actions.h:512
static TOOL_ACTION textOutlines
Display texts as lines.
Definition: pcb_actions.h:515
static TOOL_ACTION showPadNumbers
Definition: pcb_actions.h:326
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
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 Get45degMode()
Create a functor that tests whether only 45 degree lines should be allowed.
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.
Definition: project_pcb.cpp:77
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:173
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
ACTIONS * m_actions
Definition: tools_holder.h:172
Master controller class:
Definition: tool_manager.h:62
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:306
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initialize all registered tools.
#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)
#define MODAL_FRAME
@ FRAME_FOOTPRINT_CHOOSER
Definition: frame_type.h:44
PROJECT & Prj()
Definition: kicad.cpp:597
@ MAIL_SYMBOL_NETLIST
Definition: mail_type.h:45
void FixupCancelButtonCmdKeyCollision(wxWindow *aWindow)
Definition: wxgtk/ui.cpp:151
void ForceFocus(wxWindow *aWindow)
Pass the current focus to the window.
Definition: wxgtk/ui.cpp:124
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:145
see class PGM_BASE
#define DEFAULT_THEME
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.
Definition: string_utils.h:327
constexpr int mmToIU(double mm) const
Definition: base_units.h:92
Store the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:90