KiCad PCB EDA Suite
footprint_viewer_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) 2012-2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008-2016 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
27 #include <bitmaps.h>
28 #include <board_commit.h>
29 #include <class_board.h>
30 #include <class_module.h>
31 #include <confirm.h>
32 #include <dialog_helpers.h>
33 #include <eda_pattern_match.h>
34 #include <fctsys.h>
35 #include <footprint_info.h>
36 #include <footprint_viewer_frame.h>
37 #include <fp_lib_table.h>
38 #include <kiway.h>
39 #include <lib_id.h>
40 #include <memory>
41 #include <msgpanel.h>
42 #include <pcb_draw_panel_gal.h>
43 #include <pcb_painter.h>
44 #include <pcbnew.h>
45 #include <pcbnew_id.h>
46 #include <pcbnew_settings.h>
48 #include <pgm_base.h>
50 #include <tool/action_toolbar.h>
51 #include <tool/common_control.h>
52 #include <tool/common_tools.h>
53 #include <tool/tool_dispatcher.h>
54 #include <tool/tool_manager.h>
55 #include <tools/pcb_actions.h>
56 #include <tools/pcbnew_control.h>
58 #include <tools/selection_tool.h>
60 #include <wx/tokenzr.h>
61 
62 using namespace std::placeholders;
63 
64 
65 #define NEXT_PART 1
66 #define NEW_PART 0
67 #define PREVIOUS_PART -1
68 
69 
70 BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
71  // Window events
75 
76  EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::OnExitKiCad )
77  EVT_MENU( wxID_CLOSE, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
78 
79  // Toolbar events
86 
90 
93 
94  // listbox events
98 
99 END_EVENT_TABLE()
100 
101 
102 /* Note:
103  * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
104  * In modal mode:
105  * a tool to export the selected footprint is shown in the toolbar
106  * the style is wxFRAME_FLOAT_ON_PARENT
107  */
108 
109 #define PARENT_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
110 #define MODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP )
111 #define NONMODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
112 
113 
115  FRAME_T aFrameType ) :
116  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
117  wxDefaultPosition, wxDefaultSize,
118  aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE )
119  : NONMODAL_STYLE,
122 {
123  wxASSERT( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL || aFrameType == FRAME_FOOTPRINT_VIEWER );
124 
125  if( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL )
126  SetModal( true );
127 
128  m_AboutTitle = "Footprint Library Viewer";
129 
130  // Force the frame name used in config. the footprint viewer frame has a name
131  // depending on aFrameType (needed to identify the frame by wxWidgets),
132  // but only one configuration is preferable.
134 
135  // Give an icon
136  wxIcon icon;
137  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
138  SetIcon( icon );
139 
140  wxPanel* libPanel = new wxPanel( this );
141  wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
142 
143  m_libFilter = new wxTextCtrl( libPanel, ID_MODVIEW_LIB_FILTER, wxEmptyString,
144  wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
145  m_libFilter->SetHint( _( "Filter" ) );
146  libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
147 
148  m_libList = new wxListBox( libPanel, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
149  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
150  libSizer->Add( m_libList, 1, wxEXPAND, 5 );
151 
152  libPanel->SetSizer( libSizer );
153  libPanel->Fit();
154 
155  wxPanel* fpPanel = new wxPanel( this );
156  wxSizer* fpSizer = new wxBoxSizer( wxVERTICAL );
157 
158  m_fpFilter = new wxTextCtrl( fpPanel, ID_MODVIEW_FOOTPRINT_FILTER, wxEmptyString,
159  wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
160  m_fpFilter->SetHint( _( "Filter" ) );
161  m_fpFilter->SetToolTip(
162  _( "Filter on footprint name, keywords, description and pad count.\n"
163  "Search terms are separated by spaces. All search terms must match.\n"
164  "A term which is a number will also match against the pad count." ) );
165  fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
166 
167  m_fpList = new wxListBox( fpPanel, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
168  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
169  fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
170 
171  fpPanel->SetSizer( fpSizer );
172  fpPanel->Fit();
173 
174  SetBoard( new BOARD() );
175  // In viewer, the default net clearance is not known (it depends on the actual board).
176  // So we do not show the default clearance, by setting it to 0
177  // The footprint or pad specific clearance will be shown
178  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
179 
180  // Don't show the default board solder mask clearance in the footprint viewer. Only the
181  // footprint or pad clearance setting should be shown if it is not 0.
183 
184  // Ensure all layers and items are visible:
186  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
187 
188  GetScreen()->m_Center = true; // Center coordinate origins on screen.
189  LoadSettings( config() );
191 
192  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
193 
195 
196  // Create GAL canvas
198  auto drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
200  SetCanvas( drawPanel );
201 
202  // Create the manager and dispatcher & route draw panel events to the dispatcher
204  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
205  drawPanel->GetViewControls(), this );
206  m_actions = new PCB_ACTIONS();
208  drawPanel->SetEventDispatcher( m_toolDispatcher );
209 
212  m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
214  m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); // for setting grid origin
216  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
217 
218  ReCreateMenuBar();
221 
223  UpdateTitle();
224 
225  // If a footprint was previously loaded, reload it
226  if( getCurNickname().size() && getCurFootprintName().size() )
227  {
228  LIB_ID id;
229 
231  id.SetLibItemName( getCurFootprintName() );
232  GetBoard()->Add( loadFootprint( id ) );
233  }
234 
235  drawPanel->DisplayBoard( m_Pcb );
236 
237  m_auimgr.SetManagedWindow( this );
238 
239  // Horizontal items; layers 4 - 6
240  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().VToolbar().Name( "MainToolbar" ).Top().Layer(6) );
241  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
242 
243  // Vertical items; layers 1 - 3
244  m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
245  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
246  m_auimgr.AddPane( fpPanel, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer( 1)
247  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
248 
249  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
250 
251  // after changing something to the aui manager call Update() to reflect the changes
252  m_auimgr.Update();
253 
254  // The canvas should not steal the focus from the list boxes
255  GetCanvas()->SetCanFocus( false );
256  GetCanvas()->GetGAL()->SetAxesEnabled( true );
259 
260  // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
262 
263  updateView();
264  InitExitKey();
265 
266  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
267  {
269  Raise(); // On some window managers, this is needed
270  Show( true );
271  }
272 }
273 
274 
276 {
277  // Shutdown all running tools
278  if( m_toolManager )
280 
281  GetCanvas()->StopDrawing();
282  GetCanvas()->GetView()->Clear();
283  // Be sure any event cannot be fired after frame deletion:
284  GetCanvas()->SetEvtHandlerEnabled( false );
285 }
286 
287 
288 void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
289 {
290  // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
291  // when the aui toolbar is not docked (i.e. shown in a miniframe)
292  // (useful on windows only)
293  m_mainToolBar->SetFocus();
294 
295  GetCanvas()->StopDrawing();
296 
297  if( IsModal() )
298  {
299  // Only dismiss a modal frame once, so that the return values set by
300  // the prior DismissModal() are not bashed for ShowModal().
301  if( !IsDismissed() )
302  DismissModal( false );
303 
304  // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
305  }
306  else
307  Destroy();
308 }
309 
310 
311 void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
312 {
313  if( m_auimgr.GetManagedWindow() )
314  m_auimgr.Update();
315 
316  SizeEv.Skip();
317 }
318 
319 
321 {
322  m_libList->Clear();
323 
324  std::vector<wxString> nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
325  std::set<wxString> excludes;
326 
327  if( !m_libFilter->GetValue().IsEmpty() )
328  {
329  wxStringTokenizer tokenizer( m_libFilter->GetValue() );
330 
331  while( tokenizer.HasMoreTokens() )
332  {
333  const wxString term = tokenizer.GetNextToken().Lower();
334  EDA_COMBINED_MATCHER matcher( term );
335  int matches, position;
336 
337  for( const wxString& nickname : nicknames )
338  {
339  if( !matcher.Find( nickname.Lower(), matches, position ) )
340  excludes.insert( nickname );
341  }
342  }
343  }
344 
345  for( const wxString& nickname : nicknames )
346  {
347  if( !excludes.count( nickname ) )
348  m_libList->Append( nickname );
349  }
350 
351  // Search for a previous selection:
352  int index = m_libList->FindString( getCurNickname(), true );
353 
354  if( index == wxNOT_FOUND )
355  {
356  if( m_libList->GetCount() > 0 )
357  {
358  m_libList->SetSelection( 0 );
359  wxCommandEvent dummy;
361  }
362  else
363  {
364  setCurNickname( wxEmptyString );
365  setCurFootprintName( wxEmptyString );
366  }
367  }
368  else
369  {
370  m_libList->SetSelection( index, true );
371  wxCommandEvent dummy;
373  }
374 
375  GetCanvas()->Refresh();
376 }
377 
378 
380 {
381  m_fpList->Clear();
382 
383  if( !getCurNickname() )
384  setCurFootprintName( wxEmptyString );
385 
386  auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
387 
388  wxString nickname = getCurNickname();
389 
390  fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
391 
392  if( fp_info_list->GetErrorCount() )
393  {
394  fp_info_list->DisplayErrors( this );
395 
396  // For footprint libraries that support one footprint per file, there may have been
397  // valid footprints read so show the footprints that loaded properly.
398  if( fp_info_list->GetList().empty() )
399  return;
400  }
401 
402  std::set<wxString> excludes;
403 
404  if( !m_fpFilter->GetValue().IsEmpty() )
405  {
406  wxStringTokenizer tokenizer( m_fpFilter->GetValue() );
407 
408  while( tokenizer.HasMoreTokens() )
409  {
410  const wxString term = tokenizer.GetNextToken().Lower();
411  EDA_COMBINED_MATCHER matcher( term );
412  int matches, position;
413 
414  for( const unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
415  {
416  wxString search = footprint->GetFootprintName() + " " + footprint->GetSearchText();
417  bool matched = matcher.Find( search.Lower(), matches, position );
418 
419  if( !matched && term.IsNumber() )
420  matched = ( wxAtoi( term ) == (int)footprint->GetPadCount() );
421 
422  if( !matched )
423  excludes.insert( footprint->GetFootprintName() );
424  }
425  }
426  }
427 
428  for( const unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
429  {
430  if( !excludes.count( footprint->GetFootprintName() ) )
431  m_fpList->Append( footprint->GetFootprintName() );
432  }
433 
434  int index = m_fpList->FindString( getCurFootprintName(), true );
435 
436  if( index == wxNOT_FOUND )
437  {
438  if( m_fpList->GetCount() > 0 )
439  {
440  m_fpList->SetSelection( 0 );
441  m_fpList->EnsureVisible( 0 );
442 
443  wxCommandEvent dummy;
445  }
446  else
447  setCurFootprintName( wxEmptyString );
448  }
449  else
450  {
451  m_fpList->SetSelection( index, true );
452  m_fpList->EnsureVisible( index );
453  }
454 }
455 
456 
457 void FOOTPRINT_VIEWER_FRAME::OnLibFilter( wxCommandEvent& aEvent )
458 {
460 
461  // Required to avoid interaction with SetHint()
462  // See documentation for wxTextEntry::SetHint
463  aEvent.Skip();
464 }
465 
466 
467 void FOOTPRINT_VIEWER_FRAME::OnFPFilter( wxCommandEvent& aEvent )
468 {
470 
471  // Required to avoid interaction with SetHint()
472  // See documentation for wxTextEntry::SetHint
473  aEvent.Skip();
474 }
475 
476 
477 void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
478 {
479  if( aEvent.GetKeyCode() == WXK_UP )
480  {
481  wxWindow* focused = FindFocus();
482 
483  if( m_libFilter->HasFocus() || m_libList->HasFocus() )
485  else
486  selectPrev( m_fpList );
487 
488  // Need to reset the focus after selection due to GTK mouse-refresh
489  // that captures the mouse into the canvas to update scrollbars
490  if( focused )
491  focused->SetFocus();
492  }
493  else if( aEvent.GetKeyCode() == WXK_DOWN )
494  {
495  wxWindow* focused = FindFocus();
496 
497  if( m_libFilter->HasFocus() || m_libList->HasFocus() )
499  else
500  selectNext( m_fpList );
501 
502  // Need to reset the focus after selection due to GTK mouse-refresh
503  // that captures the mouse into the canvas to update scrollbars
504  if( focused )
505  focused->SetFocus();
506  }
507  else if( aEvent.GetKeyCode() == WXK_TAB && m_libFilter->HasFocus() )
508  {
509  if( !aEvent.ShiftDown() )
510  m_fpFilter->SetFocus();
511  else
512  aEvent.Skip();
513  }
514  else if( aEvent.GetKeyCode() == WXK_TAB && m_fpFilter->HasFocus() )
515  {
516  if( aEvent.ShiftDown() )
517  m_libFilter->SetFocus();
518  else
519  aEvent.Skip();
520  }
521  else if( aEvent.GetKeyCode() == WXK_RETURN && m_fpList->GetSelection() >= 0 )
522  {
523  wxCommandEvent dummy;
525  }
526  else
527  aEvent.Skip();
528 }
529 
530 
531 void FOOTPRINT_VIEWER_FRAME::selectPrev( wxListBox* aListBox )
532 {
533  int prev = aListBox->GetSelection() - 1;
534 
535  if( prev >= 0 )
536  {
537  aListBox->SetSelection( prev );
538  aListBox->EnsureVisible( prev );
539 
540  wxCommandEvent dummy;
541 
542  if( aListBox == m_libList )
544  else
546  }
547 }
548 
549 
550 void FOOTPRINT_VIEWER_FRAME::selectNext( wxListBox* aListBox )
551 {
552  int next = aListBox->GetSelection() + 1;
553 
554  if( next < (int)aListBox->GetCount() )
555  {
556  aListBox->SetSelection( next );
557  aListBox->EnsureVisible( next );
558 
559  wxCommandEvent dummy;
560 
561  if( aListBox == m_libList )
563  else
565  }
566 }
567 
568 
569 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& aEvent )
570 {
571  int ii = m_libList->GetSelection();
572 
573  if( ii < 0 )
574  return;
575 
576  wxString name = m_libList->GetString( ii );
577 
578  if( getCurNickname() == name )
579  return;
580 
581  setCurNickname( name );
582 
584  UpdateTitle();
585 }
586 
587 
588 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent )
589 {
590  if( m_fpList->GetCount() == 0 )
591  return;
592 
593  int ii = m_fpList->GetSelection();
594 
595  if( ii < 0 )
596  return;
597 
598  wxString name = m_fpList->GetString( ii );
599 
600  if( getCurFootprintName().CmpNoCase( name ) != 0 )
601  {
603 
604  // Delete the current footprint (MUST reset tools first)
606 
608 
609  LIB_ID id;
611  id.SetLibItemName( getCurFootprintName() );
612 
613  try
614  {
615  GetBoard()->Add( loadFootprint( id ) );
616  }
617  catch( const IO_ERROR& ioe )
618  {
619  wxString msg = wxString::Format( _( "Could not load footprint '%s' from library '%s'."
620  "\n\n%s" ),
622  getCurNickname(),
623  ioe.Problem() );
624  DisplayError( this, msg );
625  }
626 
627  UpdateTitle();
628 
629  updateView();
630 
631  GetCanvas()->Refresh();
632  Update3DView( true );
633  }
634 }
635 
636 
637 void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxCommandEvent& aEvent )
638 {
639  AddFootprintToPCB( aEvent );
640 }
641 
642 
643 void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
644 {
645  if( IsModal() )
646  {
647  if( m_fpList->GetSelection() >= 0 )
648  {
649  LIB_ID fpid( getCurNickname(), m_fpList->GetStringSelection() );
650  DismissModal( true, fpid.Format() );
651  }
652  else
653  {
654  DismissModal( false );
655  }
656 
657  Close( true );
658  }
659  else if( GetBoard()->GetFirstModule() )
660  {
661  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
662 
663  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
664  {
665  DisplayErrorMessage( this, _( "No board currently open." ) );
666  return;
667  }
668 
670  BOARD_COMMIT commit( pcbframe );
671 
672  // Create the "new" module
673  MODULE* newmodule = (MODULE*) GetBoard()->GetFirstModule()->Duplicate();
674  newmodule->SetParent( pcbframe->GetBoard() );
675  newmodule->SetLink( 0 );
676 
677  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
678  VECTOR2D cursorPos = viewControls->GetCursorPosition();
679 
680  commit.Add( newmodule );
681  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
682  pcbframe->PlaceModule( newmodule );
683  newmodule->SetPosition( wxPoint( 0, 0 ) );
684  viewControls->SetCrossHairCursorPosition( cursorPos, false );
685  commit.Push( wxT( "Insert module" ) );
686 
687  pcbframe->Raise();
688  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
689 
690  newmodule->ClearFlags();
691  }
692 }
693 
694 
696 {
697  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
698  wxASSERT( cfg );
699 
701 
702  // Fetch grid settings from Footprint Editor
703  auto fpedit = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
704 
705  SetGridVisibility( fpedit->m_Window.grid.show );
706 
707  GetGalDisplayOptions().ReadWindowSettings( fpedit->m_Window );
708 
709  m_autoZoom = cfg->m_FootprintViewer.auto_zoom;
710  m_lastZoom = cfg->m_FootprintViewer.zoom;
711 }
712 
713 
715 {
716  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
717  wxASSERT( cfg );
718 
719  // We don't want to store anything other than the window settings
721 
722  cfg->m_FootprintViewer.auto_zoom = m_autoZoom;
723  cfg->m_FootprintViewer.zoom = GetCanvas()->GetView()->GetScale();
724 }
725 
726 
728 {
729  auto cfg = dynamic_cast<PCBNEW_SETTINGS*>( aCfg );
730  wxASSERT( cfg );
731 
732  return &cfg->m_FootprintViewer;
733 }
734 
735 
737 {
738  PCB_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
739 
740  if( aEnvVarsChanged )
742 }
743 
744 
746 {
748 }
749 
750 
751 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
752 {
754 }
755 
756 
758 {
760 }
761 
762 
763 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
764 {
766 }
767 
768 
769 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
770 {
771  if( event.GetActive() )
772  {
773  // Ensure we have the right library list:
774  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
775  bool stale = false;
776 
777  if( libNicknames.size() != m_libList->GetCount() )
778  stale = true;
779  else
780  {
781  for( unsigned ii = 0; ii < libNicknames.size(); ii++ )
782  {
783  if( libNicknames[ii] != m_libList->GetString( ii ) )
784  {
785  stale = true;
786  break;
787  }
788  }
789  }
790 
791  if( stale )
792  {
794  UpdateTitle();
795  }
796  }
797 
798  event.Skip(); // required under wxMAC
799 }
800 
801 
802 void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent )
803 {
804  aEvent.Enable( GetBoard()->GetFirstModule() != nullptr );
805 }
806 
807 
808 bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
809 {
810  if( aFootprint && !aFootprint->IsEmpty() )
811  {
812  wxString msg;
813  LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
814  LIB_ID fpid;
815 
816  fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true );
817 
818  if( fpid.IsValid() )
819  {
820  wxString nickname = fpid.GetLibNickname();
821 
822  if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) )
823  {
824  msg.sprintf( _( "The current configuration does not include a library with the\n"
825  "nickname \"%s\". Use Manage Footprint Libraries\n"
826  "to edit the configuration." ), nickname );
827  DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg );
828  }
829  else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) )
830  {
831  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
832  "in the current configuration. Use Manage Footprint Libraries to\n"
833  "edit the configuration." ), nickname );
834  DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg );
835  }
836  else
837  {
838  // Update last selection:
839  setCurNickname( nickname );
841  m_libList->SetStringSelection( nickname );
842  }
843  }
844  }
845 
846  // Rebuild the fp list from the last selected library,
847  // and show the last selected footprint
850 
851  bool retval = KIWAY_PLAYER::ShowModal( aFootprint, aParent );
852 
853  m_libFilter->SetFocus();
854  return retval;
855 }
856 
857 
858 void FOOTPRINT_VIEWER_FRAME::Update3DView( bool aForceReload, const wxString* aTitle )
859 {
860  wxString title = wxString::Format( _( "3D Viewer" ) + wxT( " \u2014 %s" ),
862  PCB_BASE_FRAME::Update3DView( aForceReload, &title );
863 }
864 
865 
867 {
868  return ColorSettings()->GetColor( LAYER_GRID );
869 }
870 
871 
873 {
874  switch( event.GetId() )
875  {
876  case ID_MODVIEW_NEXT:
878  break;
879 
880  case ID_MODVIEW_PREVIOUS:
882  break;
883 
884  default:
885  wxString id = wxString::Format( "%i", event.GetId() );
886  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
887  }
888 }
889 
890 
892 {
893  wxString title;
894  wxString path;
895 
896  title.Printf( _( "Footprint Library Browser" ) + L" \u2014 %s",
897  getCurNickname().IsEmpty() ? _( "no library selected" ) : getCurNickname() );
898 
899  // Now, add the full path, for info
900  if( !getCurNickname().IsEmpty() )
901  {
902  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
903  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
904 
905  if( row )
906  title << L" \u2014 " << row->GetFullURI( true );
907  }
908 
909  SetTitle( title );
910 }
911 
912 
914 {
915  if( !getCurNickname() )
916  return;
917 
918  int selection = m_fpList->FindString( getCurFootprintName(), true );
919 
920  if( aMode == NEXT_PART )
921  {
922  if( selection != wxNOT_FOUND && selection < (int)m_fpList->GetCount() - 1 )
923  selection++;
924  }
925 
926  if( aMode == PREVIOUS_PART )
927  {
928  if( selection != wxNOT_FOUND && selection > 0 )
929  selection--;
930  }
931 
932  if( selection != wxNOT_FOUND )
933  {
934  m_fpList->SetSelection( selection );
935  m_fpList->EnsureVisible( selection );
936 
937  setCurFootprintName( m_fpList->GetString((unsigned) selection ) );
938 
939  // Delete the current footprint
941 
944 
945  if( footprint )
946  GetBoard()->Add( footprint, ADD_MODE::APPEND );
947 
948  Update3DView( true );
949 
950  updateView();
951  }
952 
953  UpdateTitle();
954 
955  GetCanvas()->Refresh();
956 }
957 
958 
960 {
961  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
962  KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
963  settings->LoadDisplayOptions( m_DisplayOptions, false );
964 
966  GetCanvas()->Refresh();
967 }
968 
969 
971 {
972  GetCanvas()->UpdateColors();
974 
976 
977  if( m_autoZoom )
979  else
981 
982  UpdateMsgPanel();
983 }
984 
985 
986 void FOOTPRINT_VIEWER_FRAME::OnExitKiCad( wxCommandEvent& event )
987 {
988  Kiway().OnKiCadExit();
989 }
990 
991 
992 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
993 {
994  Close( false );
995 }
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
CITER next(CITER it)
Definition: ptree.cpp:130
void SetLink(const KIID &aLink)
Definition: class_module.h:550
int m_SolderMaskMargin
Solder mask margin.
static TOOL_ACTION placeModule
Definition: pcb_actions.h:160
virtual void SetBoard(BOARD *aBoard)
Function SetBoard sets the m_Pcb member in such as way as to ensure deleting any previous BOARD.
void DClickOnFootprintList(wxCommandEvent &aEvent)
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const BITMAP_OPAQUE modview_icon_xpm[1]
void OnKiCadExit()
Definition: kiway.cpp:522
#define PREVIOUS_PART
void OnExitKiCad(wxCommandEvent &event)
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool ShowModal(wxString *aFootprint, wxWindow *aParent) override
Function ShowModal.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
void UpdateTitle()
Function UpdateTitle updates the window title with current library information.
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:252
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Model changes (required full reload)
Definition: tool_base.h:81
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
This file is part of the common library.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Returns a pointer to the window settings for this frame.
TOOL_DISPATCHER * m_toolDispatcher
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
virtual void SetScreen(BASE_SCREEN *aScreen)
FRAME_T
Enum FRAME_T is the set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:34
EDA_DRAW_PANEL_GAL::GAL_TYPE m_canvasType
The current canvas type.
void setCurFootprintName(const wxString &aName)
SELECTION_TOOL.
void OnCloseWindow(wxCloseEvent &Event) override
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
Component library viewer main window.
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1444
FOOTPRINT_VIEWER_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType)
ACTIONS * m_actions
static TOOL_ACTION zoomFitScreen
Definition: actions.h:93
void selectNext(wxListBox *aListBox)
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:139
wxString m_AboutTitle
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
wxAuiManager m_auimgr
#define PARENT_STYLE
ACTION_TOOLBAR * m_mainToolBar
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
Item needs to be redrawn.
Definition: view_item.h:61
The base class for create windows for drawing purpose.
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
bool IsValid() const
Definition: lib_id.h:171
void setCurNickname(const wxString &aNickname)
void OnUpdateFootprintButton(wxUpdateUIEvent &aEvent)
Update the ID_ADD_FOOTPRINT_TO_BOARD tool state in main toolbar.
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:49
void OnUpdateSelectZoom(wxUpdateUIEvent &aEvent)
#define NEW_PART
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.
void InstallDisplayOptions(wxCommandEvent &aEvent)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
PCBNEW_CONTROL.
Abstract pattern-matching tool and implementations.
bool m_axesEnabled
Whether or not to draw the coordinate system axes
void ClickOnLibList(wxCommandEvent &aEvent)
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
void ApplyDisplaySettingsToGAL()
Updates the GAL with display settings changes.
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:60
TOOL_MANAGER.
Definition: tool_manager.h:50
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:52
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
static TOOL_ACTION centerContents
Definition: actions.h:96
void SelectAndViewFootprint(int aMode)
Function SelectAndViewFootprint Select and load the next or the previous footprint if no current foot...
Generic tool for picking a point.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
double GetZoomLevelCoeff() const
Return the coefficient to convert internal display scale factor to zoom level.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:75
virtual void ActivateGalCanvas() override
#define NULL
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:341
void DisplayBoard(BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:218
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1111
bool m_Center
Center on screen.
Definition: base_screen.h:121
#define NEXT_PART
EDA_MSG_PANEL * m_messagePanel
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
COLOR_SETTINGS * ColorSettings()
Helper to retrieve the current color settings.
void OnCharHook(wxKeyEvent &aEvent) override
Capture the key event before it is sent to the GUI.
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:283
Definition of file extensions used in Kicad.
Helper dialog and control classes.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void OnActivate(wxActivateEvent &event)
Function OnActivate is called when the frame frame is activate to reload the libraries and component ...
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Moves the graphic crosshair cursor to the requested position expressed in world coordinates.
#define MODAL_STYLE
void SetPosition(const wxPoint &aPos) override
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
#define FOOTPRINT_VIEWER_FRAME_NAME
bool IsModal()
Definition: kiway_player.h:163
void InitExitKey()
Sets the common key-pair for exiting the application (Ctrl-Q) and ties it to the wxID_EXIT event id.
void OnFPFilter(wxCommandEvent &aEvent)
COMMON_CONTROL.
void selectPrev(wxListBox *aListBox)
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
virtual KIGFX::PCB_VIEW * GetView() const override
Function GetView() Returns a pointer to the VIEW instance used in the panel.
Specialization of the wxAuiPaneInfo class for KiCad panels.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
COMMON_TOOLS.
Definition: common_tools.h:38
void UpdateColors()
Updates the color settings in the painter and GAL.
TOOL_DISPATCHER.
PCB_DISPLAY_OPTIONS m_DisplayOptions
void SetModal(bool aIsModal)
Definition: kiway_player.h:164
VTBL_ENTRY void SetRString(RSTRING_T aStringId, const wxString &aString)
Function SetRString stores a "retained string", which is any session and project specific string iden...
Definition: project.cpp:198
#define NONMODAL_STYLE
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:427
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
virtual void SetScale(double aScale, VECTOR2D aAnchor={ 0, 0 })
Function SetScale() Sets the scaling factor, zooming around a given anchor point.
Definition: view.cpp:578
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
void SetCanvas(EDA_DRAW_PANEL_GAL *aPanel)
COLOR4D GetColor(int aLayer) const
VTBL_ENTRY const wxString & GetRString(RSTRING_T aStringId)
Function GetRString returns a "retained string", which is any session and project specific string ide...
Definition: project.cpp:213
PCB_ACTIONS.
Definition: pcb_actions.h:62
see class PGM_BASE
virtual void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
Declaration of the eda_3d_viewer class.
const char * name
Definition: DXF_plotter.cpp:60
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
NETCLASSPTR GetDefault() const
Function GetDefault.
void CloseFootprintViewer(wxCommandEvent &event)
void AddFootprintToPCB(wxCommandEvent &aEvent)
Function AddFootprintToPCB exports the current footprint name and close the library browser.
void ReCreateMenuBar() override
Recreates the menu bar.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
void ClickOnFootprintList(wxCommandEvent &aEvent)
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
#define _(s)
Definition: 3d_actions.cpp:33
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aShowPageLimits)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode,...
virtual void SetGridVisibility(bool aVisible) override
Function SetGridVisibility() Turn the display of the canvas grid on/off.
void ReCreateLibraryList()
Function ReCreateLibraryList.
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
PCB_EDIT_FRAME is the main frame for Pcbnew.
void OnLibFilter(wxCommandEvent &aEvent)
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:258
void DeleteAllModules()
Removes all modules from the deque and frees the memory associated with them.
Definition: class_board.h:291
TOOL_MANAGER * m_toolManager
Module description (excepted pads)
void OnIterateFootprintList(wxCommandEvent &event)
void InitTools()
Function InitTools() Initializes all registered tools.
BOARD * GetBoard() const
void PlaceModule(MODULE *aModule, bool aRecreateRatsnest=true)
Function PlaceModule places aModule at the current cursor position and updates module coordinates wit...
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
virtual void Update3DView(bool aForceReload, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
double GetScale() const
Function GetScale()
Definition: view.h:257
int Parse(const UTF8 &aId, LIB_ID_TYPE aType, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
virtual APP_SETTINGS_BASE * config()
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
Message panel definition file.
virtual COLOR4D GetGridColor() override
void Update3DView(bool aForceReload, const wxString *aTitle=nullptr) override
Function Update3DView must be called after a footprint selection Updates the 3D view and 3D frame tit...
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
MODULE * loadFootprint(const LIB_ID &aFootprintId)
Function loadFootprint attempts to load aFootprintId from the footprint library table.
virtual bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
wxString m_configName
BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.
void RegisterTool(TOOL_BASE *aTool)
Function RegisterTool() Adds a tool to the manager set and sets it up.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
virtual void UpdateMsgPanel()
Redraw the message panel.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from applicaton-level config.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.