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 
26 #include <fctsys.h>
27 #include <pgm_base.h>
28 #include <kiway.h>
29 #include <pcb_draw_panel_gal.h>
31 #include <dialog_helpers.h>
32 #include <msgpanel.h>
33 #include <fp_lib_table.h>
34 #include <lib_id.h>
35 #include <confirm.h>
36 #include <bitmaps.h>
37 #include <pcb_painter.h>
38 #include <class_board.h>
39 #include <class_module.h>
40 #include <pcbnew.h>
41 #include <pcbnew_id.h>
42 #include <footprint_viewer_frame.h>
43 #include <footprint_info.h>
45 #include <tool/tool_manager.h>
46 #include <tool/tool_dispatcher.h>
47 #include <tool/action_toolbar.h>
48 #include <tool/common_tools.h>
49 #include <tool/common_control.h>
50 #include <tools/selection_tool.h>
51 #include <tools/pcbnew_control.h>
52 #include <tools/pcb_actions.h>
54 #include <board_commit.h>
55 #include <memory>
56 #include <eda_pattern_match.h>
57 #include <wx/tokenzr.h>
58 
59 using namespace std::placeholders;
60 
61 
62 #define NEXT_PART 1
63 #define NEW_PART 0
64 #define PREVIOUS_PART -1
65 
66 
67 BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
68  // Window events
72 
73  EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::OnExitKiCad )
74  EVT_MENU( wxID_CLOSE, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
75 
76  // Toolbar events
83 
87 
90 
91  // listbox events
95 
96 END_EVENT_TABLE()
97 
98 
99 /* Note:
100  * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
101  * In modal mode:
102  * a tool to export the selected footprint is shown in the toolbar
103  * the style is wxFRAME_FLOAT_ON_PARENT
104  */
105 
106 #define PARENT_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
107 #define MODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP )
108 #define NONMODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
109 
110 
112  FRAME_T aFrameType ) :
113  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
114  wxDefaultPosition, wxDefaultSize,
115  aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE )
116  : NONMODAL_STYLE,
119 {
120  wxASSERT( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL || aFrameType == FRAME_FOOTPRINT_VIEWER );
121 
122  if( aFrameType == FRAME_FOOTPRINT_VIEWER_MODAL )
123  SetModal( true );
124 
125  m_AboutTitle = "Footprint Library Viewer";
126 
127  // Force the frame name used in config. the footprint viewer frame has a name
128  // depending on aFrameType (needed to identify the frame by wxWidgets),
129  // but only one configuration is preferable.
131 
132  // Give an icon
133  wxIcon icon;
134  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
135  SetIcon( icon );
136 
137  wxPanel* libPanel = new wxPanel( this );
138  wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
139 
140  m_libFilter = new wxTextCtrl( libPanel, ID_MODVIEW_LIB_FILTER, wxEmptyString,
141  wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
142  m_libFilter->SetHint( _( "Filter" ) );
143  libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
144 
145  m_libList = new wxListBox( libPanel, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
146  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
147  libSizer->Add( m_libList, 1, wxEXPAND, 5 );
148 
149  libPanel->SetSizer( libSizer );
150  libPanel->Fit();
151 
152  wxPanel* fpPanel = new wxPanel( this );
153  wxSizer* fpSizer = new wxBoxSizer( wxVERTICAL );
154 
155  m_fpFilter = new wxTextCtrl( fpPanel, ID_MODVIEW_FOOTPRINT_FILTER, wxEmptyString,
156  wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
157  m_fpFilter->SetHint( _( "Filter" ) );
158  m_fpFilter->SetToolTip(
159  _( "Filter on footprint name, keywords, description and pad count.\n"
160  "Search terms are separated by spaces. All search terms must match.\n"
161  "A term which is a number will also match against the pad count." ) );
162  fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
163 
164  m_fpList = new wxListBox( fpPanel, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
165  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
166  fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
167 
168  fpPanel->SetSizer( fpSizer );
169  fpPanel->Fit();
170 
171  SetBoard( new BOARD() );
172  // In viewer, the default net clearance is not known (it depends on the actual board).
173  // So we do not show the default clearance, by setting it to 0
174  // The footprint or pad specific clearance will be shown
175  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
176 
177  // Don't show the default board solder mask clearance in the footprint viewer. Only the
178  // footprint or pad clearance setting should be shown if it is not 0.
180 
181  // Ensure all layers and items are visible:
183  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
184 
185  GetScreen()->m_Center = true; // Center coordinate origins on screen.
186  LoadSettings( config() );
188 
189  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
190 
192 
193  // Create GAL canvas
195  auto drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
197  SetCanvas( drawPanel );
198 
199  // Create the manager and dispatcher & route draw panel events to the dispatcher
201  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
202  drawPanel->GetViewControls(), this );
203  m_actions = new PCB_ACTIONS();
205  drawPanel->SetEventDispatcher( m_toolDispatcher );
206 
209  m_toolManager->RegisterTool( new COMMON_TOOLS ); // for std context menus (zoom & grid)
211  m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); // for setting grid origin
213  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
214 
215  ReCreateMenuBar();
218 
220  UpdateTitle();
221 
222  // If a footprint was previously loaded, reload it
223  if( getCurNickname().size() && getCurFootprintName().size() )
224  {
225  LIB_ID id;
226 
228  id.SetLibItemName( getCurFootprintName() );
229  GetBoard()->Add( loadFootprint( id ) );
230  }
231 
232  drawPanel->DisplayBoard( m_Pcb );
233 
234  m_auimgr.SetManagedWindow( this );
235 
236  // Horizontal items; layers 4 - 6
237  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().VToolbar().Name( "MainToolbar" ).Top().Layer(6) );
238  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
239 
240  // Vertical items; layers 1 - 3
241  m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
242  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
243  m_auimgr.AddPane( fpPanel, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer( 1)
244  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
245 
246  m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
247 
248  // after changing something to the aui manager call Update() to reflect the changes
249  m_auimgr.Update();
250 
251  // The canvas should not steal the focus from the list boxes
252  GetCanvas()->SetCanFocus( false );
253  GetCanvas()->GetGAL()->SetAxesEnabled( true );
256 
257  // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
259 
260  updateView();
261  InitExitKey();
262 
263  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
264  {
266  Raise(); // On some window managers, this is needed
267  Show( true );
268  }
269 }
270 
271 
273 {
274  GetCanvas()->StopDrawing();
275  GetCanvas()->GetView()->Clear();
276  // Be sure any event cannot be fired after frame deletion:
277  GetCanvas()->SetEvtHandlerEnabled( false );
278 }
279 
280 
281 void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
282 {
283  // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
284  // when the aui toolbar is not docked (i.e. shown in a miniframe)
285  // (useful on windows only)
286  m_mainToolBar->SetFocus();
287 
288  GetCanvas()->StopDrawing();
289 
290  if( IsModal() )
291  {
292  // Only dismiss a modal frame once, so that the return values set by
293  // the prior DismissModal() are not bashed for ShowModal().
294  if( !IsDismissed() )
295  DismissModal( false );
296 
297  // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
298  }
299  else
300  Destroy();
301 }
302 
303 
304 void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
305 {
306  if( m_auimgr.GetManagedWindow() )
307  m_auimgr.Update();
308 
309  SizeEv.Skip();
310 }
311 
312 
314 {
315  m_libList->Clear();
316 
317  std::vector<wxString> nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
318  std::set<wxString> excludes;
319 
320  if( !m_libFilter->GetValue().IsEmpty() )
321  {
322  wxStringTokenizer tokenizer( m_libFilter->GetValue() );
323 
324  while( tokenizer.HasMoreTokens() )
325  {
326  const wxString term = tokenizer.GetNextToken().Lower();
327  EDA_COMBINED_MATCHER matcher( term );
328  int matches, position;
329 
330  for( const wxString& nickname : nicknames )
331  {
332  if( !matcher.Find( nickname.Lower(), matches, position ) )
333  excludes.insert( nickname );
334  }
335  }
336  }
337 
338  for( const wxString& nickname : nicknames )
339  {
340  if( !excludes.count( nickname ) )
341  m_libList->Append( nickname );
342  }
343 
344  // Search for a previous selection:
345  int index = m_libList->FindString( getCurNickname(), true );
346 
347  if( index == wxNOT_FOUND )
348  {
349  if( m_libList->GetCount() > 0 )
350  {
351  m_libList->SetSelection( 0 );
352  wxCommandEvent dummy;
354  }
355  else
356  {
357  setCurNickname( wxEmptyString );
358  setCurFootprintName( wxEmptyString );
359  }
360  }
361  else
362  {
363  m_libList->SetSelection( index, true );
364  wxCommandEvent dummy;
366  }
367 
368  GetCanvas()->Refresh();
369 }
370 
371 
373 {
374  m_fpList->Clear();
375 
376  if( !getCurNickname() )
377  setCurFootprintName( wxEmptyString );
378 
379  auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
380 
381  wxString nickname = getCurNickname();
382 
383  fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
384 
385  if( fp_info_list->GetErrorCount() )
386  {
387  fp_info_list->DisplayErrors( this );
388 
389  // For footprint libraries that support one footprint per file, there may have been
390  // valid footprints read so show the footprints that loaded properly.
391  if( fp_info_list->GetList().empty() )
392  return;
393  }
394 
395  std::set<wxString> excludes;
396 
397  if( !m_fpFilter->GetValue().IsEmpty() )
398  {
399  wxStringTokenizer tokenizer( m_fpFilter->GetValue() );
400 
401  while( tokenizer.HasMoreTokens() )
402  {
403  const wxString term = tokenizer.GetNextToken().Lower();
404  EDA_COMBINED_MATCHER matcher( term );
405  int matches, position;
406 
407  for( const unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
408  {
409  wxString search = footprint->GetFootprintName() + " " + footprint->GetSearchText();
410  bool matched = matcher.Find( search.Lower(), matches, position );
411 
412  if( !matched && term.IsNumber() )
413  matched = ( wxAtoi( term ) == (int)footprint->GetPadCount() );
414 
415  if( !matched )
416  excludes.insert( footprint->GetFootprintName() );
417  }
418  }
419  }
420 
421  for( const unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
422  {
423  if( !excludes.count( footprint->GetFootprintName() ) )
424  m_fpList->Append( footprint->GetFootprintName() );
425  }
426 
427  int index = m_fpList->FindString( getCurFootprintName(), true );
428 
429  if( index == wxNOT_FOUND )
430  {
431  if( m_fpList->GetCount() > 0 )
432  {
433  m_fpList->SetSelection( 0 );
434  m_fpList->EnsureVisible( 0 );
435 
436  wxCommandEvent dummy;
438  }
439  else
440  setCurFootprintName( wxEmptyString );
441  }
442  else
443  {
444  m_fpList->SetSelection( index, true );
445  m_fpList->EnsureVisible( index );
446  }
447 }
448 
449 
450 void FOOTPRINT_VIEWER_FRAME::OnLibFilter( wxCommandEvent& aEvent )
451 {
453 
454  // Required to avoid interaction with SetHint()
455  // See documentation for wxTextEntry::SetHint
456  aEvent.Skip();
457 }
458 
459 
460 void FOOTPRINT_VIEWER_FRAME::OnFPFilter( wxCommandEvent& aEvent )
461 {
463 
464  // Required to avoid interaction with SetHint()
465  // See documentation for wxTextEntry::SetHint
466  aEvent.Skip();
467 }
468 
469 
470 void FOOTPRINT_VIEWER_FRAME::OnCharHook( wxKeyEvent& aEvent )
471 {
472  if( aEvent.GetKeyCode() == WXK_UP )
473  {
474  wxWindow* focused = FindFocus();
475 
476  if( m_libFilter->HasFocus() || m_libList->HasFocus() )
478  else
479  selectPrev( m_fpList );
480 
481  // Need to reset the focus after selection due to GTK mouse-refresh
482  // that captures the mouse into the canvas to update scrollbars
483  if( focused )
484  focused->SetFocus();
485  }
486  else if( aEvent.GetKeyCode() == WXK_DOWN )
487  {
488  wxWindow* focused = FindFocus();
489 
490  if( m_libFilter->HasFocus() || m_libList->HasFocus() )
492  else
493  selectNext( m_fpList );
494 
495  // Need to reset the focus after selection due to GTK mouse-refresh
496  // that captures the mouse into the canvas to update scrollbars
497  if( focused )
498  focused->SetFocus();
499  }
500  else if( aEvent.GetKeyCode() == WXK_TAB && m_libFilter->HasFocus() )
501  {
502  if( !aEvent.ShiftDown() )
503  m_fpFilter->SetFocus();
504  else
505  aEvent.Skip();
506  }
507  else if( aEvent.GetKeyCode() == WXK_TAB && m_fpFilter->HasFocus() )
508  {
509  if( aEvent.ShiftDown() )
510  m_libFilter->SetFocus();
511  else
512  aEvent.Skip();
513  }
514  else if( aEvent.GetKeyCode() == WXK_RETURN && m_fpList->GetSelection() >= 0 )
515  {
516  wxCommandEvent dummy;
518  }
519  else
520  aEvent.Skip();
521 }
522 
523 
524 void FOOTPRINT_VIEWER_FRAME::selectPrev( wxListBox* aListBox )
525 {
526  int prev = aListBox->GetSelection() - 1;
527 
528  if( prev >= 0 )
529  {
530  aListBox->SetSelection( prev );
531  aListBox->EnsureVisible( prev );
532 
533  wxCommandEvent dummy;
534 
535  if( aListBox == m_libList )
537  else
539  }
540 }
541 
542 
543 void FOOTPRINT_VIEWER_FRAME::selectNext( wxListBox* aListBox )
544 {
545  int next = aListBox->GetSelection() + 1;
546 
547  if( next < (int)aListBox->GetCount() )
548  {
549  aListBox->SetSelection( next );
550  aListBox->EnsureVisible( next );
551 
552  wxCommandEvent dummy;
553 
554  if( aListBox == m_libList )
556  else
558  }
559 }
560 
561 
562 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& aEvent )
563 {
564  int ii = m_libList->GetSelection();
565 
566  if( ii < 0 )
567  return;
568 
569  wxString name = m_libList->GetString( ii );
570 
571  if( getCurNickname() == name )
572  return;
573 
574  setCurNickname( name );
575 
577  UpdateTitle();
578 }
579 
580 
581 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& aEvent )
582 {
583  if( m_fpList->GetCount() == 0 )
584  return;
585 
586  int ii = m_fpList->GetSelection();
587 
588  if( ii < 0 )
589  return;
590 
591  wxString name = m_fpList->GetString( ii );
592 
593  if( getCurFootprintName().CmpNoCase( name ) != 0 )
594  {
596 
597  // Delete the current footprint (MUST reset tools first)
599 
601 
602  LIB_ID id;
604  id.SetLibItemName( getCurFootprintName() );
605 
606  try
607  {
608  GetBoard()->Add( loadFootprint( id ) );
609  }
610  catch( const IO_ERROR& ioe )
611  {
612  wxString msg = wxString::Format( _( "Could not load footprint '%s' from library '%s'."
613  "\n\n%s" ),
615  getCurNickname(),
616  ioe.Problem() );
617  DisplayError( this, msg );
618  }
619 
620  UpdateTitle();
621 
622  updateView();
623 
624  GetCanvas()->Refresh();
625  Update3DView( true );
626  }
627 }
628 
629 
630 void FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList( wxCommandEvent& aEvent )
631 {
632  AddFootprintToPCB( aEvent );
633 }
634 
635 
636 void FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB( wxCommandEvent& aEvent )
637 {
638  if( IsModal() )
639  {
640  if( m_fpList->GetSelection() >= 0 )
641  {
642  LIB_ID fpid( getCurNickname(), m_fpList->GetStringSelection() );
643  DismissModal( true, fpid.Format() );
644  }
645  else
646  {
647  DismissModal( false );
648  }
649 
650  Close( true );
651  }
652  else if( GetBoard()->GetFirstModule() )
653  {
654  PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
655 
656  if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
657  {
658  DisplayErrorMessage( this, _( "No board currently open." ) );
659  return;
660  }
661 
663  BOARD_COMMIT commit( pcbframe );
664 
665  // Create the "new" module
666  MODULE* newmodule = new MODULE( *GetBoard()->GetFirstModule() );
667  newmodule->SetParent( pcbframe->GetBoard() );
668  newmodule->SetLink( 0 );
669 
670  KIGFX::VIEW_CONTROLS* viewControls = pcbframe->GetCanvas()->GetViewControls();
671  VECTOR2D cursorPos = viewControls->GetCursorPosition();
672 
673  commit.Add( newmodule );
674  viewControls->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false );
675  pcbframe->PlaceModule( newmodule );
676  newmodule->SetPosition( wxPoint( 0, 0 ) );
677  viewControls->SetCrossHairCursorPosition( cursorPos, false );
678  newmodule->SetTimeStamp( GetNewTimeStamp() );
679  commit.Push( wxT( "Insert module" ) );
680 
681  pcbframe->Raise();
682  pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::placeModule, true, newmodule );
683 
684  newmodule->ClearFlags();
685  }
686 }
687 
688 
689 void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
690 {
692 
693  // Fetch grid settings from Footprint Editor
694  wxString footprintEditor = FOOTPRINT_EDIT_FRAME_NAME;
695  bool btmp;
696  COLOR4D wtmp;
697 
698  if( aCfg->Read( footprintEditor + ShowGridEntryKeyword, &btmp ) )
699  SetGridVisibility( btmp );
700 
701  if( wtmp.SetFromWxString( aCfg->Read( footprintEditor + GridColorEntryKeyword,
702  wxT( "NONE" ) ) ) )
703  SetGridColor( wtmp );
704 
705  // Grid shape, etc.
706  GetGalDisplayOptions().ReadAppConfig( *aCfg, footprintEditor );
707 
708  m_configSettings.Load( aCfg ); // mainly, load the color config
709 
710  aCfg->Read( ConfigBaseName() + AUTO_ZOOM_KEY, &m_autoZoom, true );
711  aCfg->Read( ConfigBaseName() + ZOOM_KEY, &m_lastZoom, 10.0 );
712 }
713 
714 
715 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
716 {
718 
719  aCfg->Write( ConfigBaseName() + AUTO_ZOOM_KEY, m_autoZoom );
720  aCfg->Write( ConfigBaseName() + ZOOM_KEY, GetCanvas()->GetView()->GetScale() );
721 }
722 
723 
725 {
726  PCB_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
727 
728  if( aEnvVarsChanged )
730 }
731 
732 
734 {
736 }
737 
738 
739 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
740 {
742 }
743 
744 
746 {
748 }
749 
750 
751 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
752 {
754 }
755 
756 
757 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
758 {
759  if( event.GetActive() )
760  {
761  // Ensure we have the right library list:
762  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
763  bool stale = false;
764 
765  if( libNicknames.size() != m_libList->GetCount() )
766  stale = true;
767  else
768  {
769  for( unsigned ii = 0; ii < libNicknames.size(); ii++ )
770  {
771  if( libNicknames[ii] != m_libList->GetString( ii ) )
772  {
773  stale = true;
774  break;
775  }
776  }
777  }
778 
779  if( stale )
780  {
782  UpdateTitle();
783  }
784  }
785 
786  event.Skip(); // required under wxMAC
787 }
788 
789 
790 void FOOTPRINT_VIEWER_FRAME::OnUpdateFootprintButton( wxUpdateUIEvent& aEvent )
791 {
792  aEvent.Enable( GetBoard()->GetFirstModule() != nullptr );
793 }
794 
795 
796 bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
797 {
798  if( aFootprint && !aFootprint->IsEmpty() )
799  {
800  wxString msg;
801  LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
802  LIB_ID fpid;
803 
804  fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true );
805 
806  if( fpid.IsValid() )
807  {
808  wxString nickname = fpid.GetLibNickname();
809 
810  if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) )
811  {
812  msg.sprintf( _( "The current configuration does not include a library with the\n"
813  "nickname \"%s\". Use Manage Footprint Libraries\n"
814  "to edit the configuration." ), nickname );
815  DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg );
816  }
817  else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) )
818  {
819  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
820  "in the current configuration. Use Manage Footprint Libraries to\n"
821  "edit the configuration." ), nickname );
822  DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg );
823  }
824  else
825  {
826  // Update last selection:
827  setCurNickname( nickname );
829  m_libList->SetStringSelection( nickname );
830  }
831  }
832  }
833 
834  // Rebuild the fp list from the last selected library,
835  // and show the last selected footprint
838 
839  bool retval = KIWAY_PLAYER::ShowModal( aFootprint, aParent );
840 
841  m_libFilter->SetFocus();
842  return retval;
843 }
844 
845 
846 void FOOTPRINT_VIEWER_FRAME::Update3DView( bool aForceReload, const wxString* aTitle )
847 {
848  wxString title = wxString::Format( _( "3D Viewer" ) + wxT( " \u2014 %s" ),
850  PCB_BASE_FRAME::Update3DView( aForceReload, &title );
851 }
852 
853 
855 {
856  return Settings().Colors().GetItemColor( LAYER_GRID );
857 }
858 
859 
861 {
862  switch( event.GetId() )
863  {
864  case ID_MODVIEW_NEXT:
866  break;
867 
868  case ID_MODVIEW_PREVIOUS:
870  break;
871 
872  default:
873  wxString id = wxString::Format( "%i", event.GetId() );
874  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
875  }
876 }
877 
878 
880 {
881  wxString title;
882  wxString path;
883 
884  title.Printf( _( "Footprint Library Browser" ) + L" \u2014 %s",
885  getCurNickname().IsEmpty() ? _( "no library selected" ) : getCurNickname() );
886 
887  // Now, add the full path, for info
888  if( !getCurNickname().IsEmpty() )
889  {
890  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
891  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
892 
893  if( row )
894  title << L" \u2014 " << row->GetFullURI( true );
895  }
896 
897  SetTitle( title );
898 }
899 
900 
902 {
903  if( !getCurNickname() )
904  return;
905 
906  int selection = m_fpList->FindString( getCurFootprintName(), true );
907 
908  if( aMode == NEXT_PART )
909  {
910  if( selection != wxNOT_FOUND && selection < (int)m_fpList->GetCount() - 1 )
911  selection++;
912  }
913 
914  if( aMode == PREVIOUS_PART )
915  {
916  if( selection != wxNOT_FOUND && selection > 0 )
917  selection--;
918  }
919 
920  if( selection != wxNOT_FOUND )
921  {
922  m_fpList->SetSelection( selection );
923  m_fpList->EnsureVisible( selection );
924 
925  setCurFootprintName( m_fpList->GetString((unsigned) selection ) );
926 
927  // Delete the current footprint
929 
932 
933  if( footprint )
934  GetBoard()->Add( footprint, ADD_MODE::APPEND );
935 
936  Update3DView( true );
937 
938  updateView();
939  }
940 
941  UpdateTitle();
942 
943  GetCanvas()->Refresh();
944 }
945 
946 
948 {
949  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetCanvas()->GetView()->GetPainter() );
950  KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
951  settings->LoadDisplayOptions( m_DisplayOptions, false );
952 
954  GetCanvas()->Refresh();
955 }
956 
957 
959 {
960  GetCanvas()->UseColorScheme( &Settings().Colors() );
962 
964 
965  if( m_autoZoom )
967  else
969 
970  UpdateMsgPanel();
971 }
972 
973 
974 void FOOTPRINT_VIEWER_FRAME::OnExitKiCad( wxCommandEvent& event )
975 {
976  Kiway().OnKiCadExit();
977 }
978 
979 
980 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
981 {
982  Close( false );
983 }
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:236
CITER next(CITER it)
Definition: ptree.cpp:130
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.
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:249
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:82
This file is part of the common library.
TOOL_DISPATCHER * m_toolDispatcher
void Load(wxConfigBase *aCfg) override
bool IsDismissed()
Function IsDismissed returns false only if both the frame is acting in modal mode and it has not been...
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
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
wxString ConfigBaseName()
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:109
wxString m_AboutTitle
EDA_DRAW_PANEL_GAL::GAL_TYPE LoadCanvasTypeSetting()
Returns the canvas type stored in the application settings.
virtual wxConfigBase * config()
Returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
wxAuiManager m_auimgr
#define PARENT_STYLE
ACTION_TOOLBAR * m_mainToolBar
virtual void SetGridColor(COLOR4D aColor)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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)
static const wxChar AUTO_ZOOM_KEY[]
Key in KifaceSettings to store the canvas type.
PCBNEW_CONTROL.
Abstract pattern-matching tool and implementations.
bool m_axesEnabled
Whether or not to draw the coordinate system axes
void ClickOnLibList(wxCommandEvent &aEvent)
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
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:61
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:79
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:215
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.
double GetZoomLevelCoeff() const
Return the coefficient to convert internal display scale factor to zoom level.
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 SetLink(timestamp_t aLink)
Definition: class_module.h:550
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:216
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
PCB_GENERAL_SETTINGS & Settings()
void OnUpdateSelectGrid(wxUpdateUIEvent &aEvent)
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
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)
Definition of file extensions used in Kicad.
Helper dialog and control classes.
#define FOOTPRINT_EDIT_FRAME_NAME
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:274
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 ...
PCB_GENERAL_SETTINGS m_configSettings
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 SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
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.
void ReadAppConfig(wxConfigBase &aCfg, const wxString &aBaseName)
Read GAL config options from applicaton-level config.
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...
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
COMMON_TOOLS.
Definition: common_tools.h:38
COLORS_DESIGN_SETTINGS & Colors()
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:171
#define NONMODAL_STYLE
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
Definition: project.cpp:400
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)
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:186
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:160
void LoadSettings(wxConfigBase *aCfg) override
Load common frame parameters from a configuration file.
#define _(s)
Definition: 3d_actions.cpp:31
#define ShowGridEntryKeyword
Nonzero to show grid (suffix)
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:256
void DeleteAllModules()
Removes all modules from the deque and frees the memory associated with them.
Definition: class_board.h:283
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.
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
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...
#define GridColorEntryKeyword
Grid color ID (suffix)
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...
static const wxChar ZOOM_KEY[]
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
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.
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212
void SaveSettings(wxConfigBase *aCfg) override
Saves common frame parameters to a configuration data file.
virtual void UpdateMsgPanel()
Redraw the message panel.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.