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-2018 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 
30 #include <fctsys.h>
31 #include <pgm_base.h>
32 #include <kiway.h>
33 #include <class_drawpanel.h>
34 #include <pcb_draw_panel_gal.h>
36 #include <dialog_helpers.h>
37 #include <msgpanel.h>
38 #include <fp_lib_table.h>
39 #include <lib_id.h>
40 #include <confirm.h>
41 #include <bitmaps.h>
43 #include <eda_dockart.h>
44 #include <pcb_painter.h>
45 #include <class_board.h>
46 #include <class_module.h>
47 
48 #include <pcbnew.h>
49 #include <pcbnew_id.h>
50 #include <footprint_viewer_frame.h>
51 #include <footprint_info.h>
52 
53 #include <hotkeys.h>
55 #include <config_params.h>
56 
57 #include <tool/tool_manager.h>
58 #include <tool/tool_dispatcher.h>
59 #include <tool/common_tools.h>
60 #include "tools/selection_tool.h"
61 #include "tools/pcbnew_control.h"
62 #include "tools/pcb_actions.h"
63 
64 #include <functional>
65 #include <memory>
66 using namespace std::placeholders;
67 
68 
69 #define NEXT_PART 1
70 #define NEW_PART 0
71 #define PREVIOUS_PART -1
72 
73 
74 BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
75  // Window events
76  EVT_CLOSE( FOOTPRINT_VIEWER_FRAME::OnCloseWindow )
77  EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize )
78  EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate )
79 
80  // Menu (and/or hotkey) events
81  EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
83 
84  // Menu Help
85  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
86  EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
87  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
88  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
89 
90  // Toolbar events
91  EVT_TOOL( ID_MODVIEW_SELECT_PART, FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
92  EVT_TOOL( ID_MODVIEW_OPTIONS, FOOTPRINT_VIEWER_FRAME::InstallDisplayOptions )
93  EVT_TOOL( ID_MODVIEW_NEXT, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
94  EVT_TOOL( ID_MODVIEW_PREVIOUS, FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
97  EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectZoom )
98  EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnSelectGrid )
99 
100  EVT_UPDATE_UI( ID_ON_GRID_SELECT, FOOTPRINT_VIEWER_FRAME::OnUpdateSelectGrid )
101  EVT_UPDATE_UI( ID_ON_ZOOM_SELECT, FOOTPRINT_VIEWER_FRAME::OnUpdateSelectZoom )
102 
103  // listbox events
104  EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList )
105  EVT_LISTBOX( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList )
106  EVT_LISTBOX_DCLICK( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList )
107 
108 END_EVENT_TABLE()
109 
110 
111 /* Note:
112  * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
113  * In modal mode:
114  * a tool to export the selected footprint is shown in the toolbar
115  * the style is wxFRAME_FLOAT_ON_PARENT
116  * Note:
117  * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed
118  * its parent frame is sometimes brought to the foreground when closing the
119  * LIB_VIEW_FRAME frame.
120  * If it still happens, it could be better to use wxSTAY_ON_TOP
121  * instead of wxFRAME_FLOAT_ON_PARENT
122  */
123 
124 #define PARENT_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
125 #define MODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP )
126 #define NONMODAL_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
127 
128 
130  FRAME_T aFrameType ) :
131  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
132  wxDefaultPosition, wxDefaultSize,
133  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ? ( aParent ? PARENT_STYLE : MODAL_STYLE )
134  : NONMODAL_STYLE,
137 {
138  wxASSERT( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ||
139  aFrameType == FRAME_PCB_MODULE_VIEWER );
140 
141  if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL )
142  SetModal( true );
143 
144  // Force the frame name used in config. the footprint viewer frame has a name
145  // depending on aFrameType (needed to identify the frame by wxWidgets),
146  // but only one configuration is preferable.
148 
149  m_showAxis = true; // true to draw axis.
150 
151  // Give an icon
152  wxIcon icon;
153  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
154  SetIcon( icon );
155 
157 
158  m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST, wxDefaultPosition, wxDefaultSize,
159  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
160 
161  m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST, wxDefaultPosition, wxDefaultSize,
162  0, NULL, wxLB_HSCROLL | wxNO_BORDER );
163 
164  SetBoard( new BOARD() );
165  // In viewer, the default net clearance is not known (it depends on the actual board).
166  // So we do not show the default clearance, by setting it to 0
167  // The footprint or pad specific clearance will be shown
168  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
169 
170  // Don't show the default board solder mask clearance in the footprint viewer. Only the
171  // footprint or pad clearance setting should be shown if it is not 0.
173 
174  // Ensure all layers and items are visible:
176  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
177 
178  GetScreen()->m_Center = true; // Center coordinate origins on screen.
179  LoadSettings( config() );
181 
182  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
183 
185 
186  // Menu bar is not mandatory: uncomment/comment the next line
187  // to add/remove the menubar
188  ReCreateMenuBar();
191 
193  UpdateTitle();
194 
195  // Create GAL canvas
196 #ifdef __WXMAC__
197  // Cairo renderer doesn't handle Retina displays
199 #else
201 #endif
202  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
203  GetGalDisplayOptions(), backend );
204  SetGalCanvas( drawPanel );
205 
206  // Create the manager and dispatcher & route draw panel events to the dispatcher
208  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
209  drawPanel->GetViewControls(), this );
210  m_actions = new PCB_ACTIONS();
212  drawPanel->SetEventDispatcher( m_toolDispatcher );
213 
215  m_toolManager->RegisterTool( new SELECTION_TOOL ); // for std context menus (zoom & grid)
218  m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
219 
220  // If a footprint was previously loaded, reload it
221  if( getCurNickname().size() && getCurFootprintName().size() )
222  {
223  LIB_ID id;
224 
226  id.SetLibItemName( getCurFootprintName() );
227  GetBoard()->Add( loadFootprint( id ) );
228  }
229 
230  drawPanel->DisplayBoard( m_Pcb );
231 
232  m_auimgr.SetManagedWindow( this );
233  m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
234 
235  // Horizontal items; layers 4 - 6
236  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().VToolbar().Name( "MainToolbar" ).Top().Layer(6) );
237  m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
238 
239  // Vertical items; layers 1 - 3
240  m_auimgr.AddPane( m_libList, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
241  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
242  m_auimgr.AddPane( m_footprintList, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer(1)
243  .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
244 
245  m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
246  m_auimgr.AddPane( GetGalCanvas(), EDA_PANE().Canvas().Name( "DrawFrameGal" ).Center().Hide() );
247 
248  // after changing something to the aui manager,
249  // call Update()() to reflect the changes
250  m_auimgr.Update();
251 
252  GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
253  UseGalCanvas( true );
254 
255  // Restore last zoom. (If auto-zooming we'll adjust when we load the footprint.)
257 
258  updateView();
259 
260  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
261  {
262  Raise(); // On some window managers, this is needed
263  Show( true );
264  }
265 }
266 
267 
269 {
271  GetGalCanvas()->GetView()->Clear();
272  // Be sure any event cannot be fired after frame deletion:
273  GetGalCanvas()->SetEvtHandlerEnabled( false );
274 }
275 
276 
277 void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
278 {
279  // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
280  // when the aui toolbar is not docked (i.e. shown in a miniframe)
281  // (usefull on windows only)
282  m_mainToolBar->SetFocus();
283 
285 
286  if( IsModal() )
287  {
288  // Only dismiss a modal frame once, so that the return values set by
289  // the prior DismissModal() are not bashed for ShowModal().
290  if( !IsDismissed() )
291  DismissModal( false );
292 
293  // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
294  }
295  else
296  Destroy();
297 }
298 
299 
300 void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
301 {
302  if( m_auimgr.GetManagedWindow() )
303  m_auimgr.Update();
304 
305  SizeEv.Skip();
306 }
307 
308 
309 void FOOTPRINT_VIEWER_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
310 {
312  UpdateStatusBar();
313 }
314 
315 
317 {
318  m_libList->Clear();
319 
320  std::vector< wxString > nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
321 
322  for( unsigned ii = 0; ii < nicknames.size(); ii++ )
323  m_libList->Append( nicknames[ii] );
324 
325  // Search for a previous selection:
326  int index = m_libList->FindString( getCurNickname() );
327 
328  if( index != wxNOT_FOUND )
329  {
330  m_libList->SetSelection( index, true );
331  }
332  else
333  {
334  // If not found, clear current library selection because it can be
335  // deleted after a configuration change.
336  setCurNickname( wxEmptyString );
337  setCurFootprintName( wxEmptyString );
338  }
339 
341 
342  m_canvas->Refresh();
343 }
344 
345 
347 {
348  m_footprintList->Clear();
349 
350  if( !getCurNickname() )
351  {
352  setCurFootprintName( wxEmptyString );
353  return;
354  }
355 
356  auto fp_info_list = FOOTPRINT_LIST::GetInstance( Kiway() );
357 
358  wxString nickname = getCurNickname();
359 
360  fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
361 
362  if( fp_info_list->GetErrorCount() )
363  {
364  fp_info_list->DisplayErrors( this );
365 
366  // For footprint libraries that support one footprint per file, there may have been
367  // valid footprints read so show the footprints that loaded properly.
368  if( fp_info_list->GetList().size() == 0 )
369  return;
370  }
371 
372  for( auto& footprint : fp_info_list->GetList() )
373  {
374  m_footprintList->Append( footprint->GetFootprintName() );
375  }
376 
377  int index = m_footprintList->FindString( getCurFootprintName() );
378 
379  if( index == wxNOT_FOUND )
380  setCurFootprintName( wxEmptyString );
381  else
382  {
383  m_footprintList->SetSelection( index, true );
384  m_footprintList->EnsureVisible( index );
385  }
386 }
387 
388 
389 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
390 {
391  int ii = m_libList->GetSelection();
392 
393  if( ii < 0 )
394  return;
395 
396  wxString name = m_libList->GetString( ii );
397 
398  if( getCurNickname() == name )
399  return;
400 
401  setCurNickname( name );
402 
404  UpdateTitle();
405 }
406 
407 
408 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
409 {
410  if( m_footprintList->GetCount() == 0 )
411  return;
412 
413  int ii = m_footprintList->GetSelection();
414 
415  if( ii < 0 )
416  return;
417 
418  wxString name = m_footprintList->GetString( ii );
419 
420  if( getCurFootprintName().CmpNoCase( name ) != 0 )
421  {
422  setCurFootprintName( name );
423 
424  // Delete the current footprint (MUST reset tools first)
426  SetCurItem( nullptr );
428 
429  LIB_ID id;
431  id.SetLibItemName( getCurFootprintName() );
432 
433  try
434  {
435  GetBoard()->Add( loadFootprint( id ) );
436  }
437  catch( const IO_ERROR& ioe )
438  {
439  wxString msg = wxString::Format(
440  _( "Could not load footprint \"%s\" from library \"%s\".\n\nError %s." ),
443  GetChars( ioe.What() ) );
444 
445  DisplayError( this, msg );
446  }
447 
448  UpdateTitle();
449 
450  updateView();
451 
452  m_canvas->Refresh();
453  Update3D_Frame();
454  }
455 }
456 
457 
459 {
460  if( IsModal() )
461  {
462  // @todo(DICK)
463  ExportSelectedFootprint( event );
464 
465  // Prevent the double click from being as a single mouse button release
466  // event in the parent window which would cause the part to be parked
467  // rather than staying in move mode.
468  // Remember the mouse button will be released in the parent window
469  // thus creating a mouse button release event which should be ignored
470  PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
471 
472  // The parent may not be the board editor:
473  if( pcbframe )
474  {
475  pcbframe->SkipNextLeftButtonReleaseEvent();
476  }
477  }
478 }
479 
480 
482 {
483  int ii = m_footprintList->GetSelection();
484 
485  if( ii >= 0 )
486  {
487  wxString fp_name = m_footprintList->GetString( ii );
488 
489  LIB_ID fpid;
490 
491  fpid.SetLibNickname( getCurNickname() );
492  fpid.SetLibItemName( fp_name );
493 
494  DismissModal( true, fpid.Format() );
495  }
496  else
497  {
498  DismissModal( false );
499  }
500 
501  Close( true );
502 }
503 
504 
505 void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
506 {
508 
509  m_configSettings.Load( aCfg ); // mainly, load the color config
510 
511  aCfg->Read( ConfigBaseName() + AUTO_ZOOM_KEY, &m_autoZoom, true );
512  aCfg->Read( ConfigBaseName() + ZOOM_KEY, &m_lastZoom, 10.0 );
513 }
514 
515 
516 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
517 {
519 
520  aCfg->Write( ConfigBaseName() + AUTO_ZOOM_KEY, m_autoZoom );
521  aCfg->Write( ConfigBaseName() + ZOOM_KEY, GetGalCanvas()->GetView()->GetScale() );
522 }
523 
524 
526 {
528 }
529 
530 
531 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
532 {
534 }
535 
536 
538 {
540 }
541 
542 
543 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
544 {
546 }
547 
548 
549 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
550 {
552 
553  // Ensure we do not have old selection:
554  if( !event.GetActive() )
555  return;
556 
557  // Ensure we have the right library list:
558  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
559 
560  if( libNicknames.size() == m_libList->GetCount() )
561  {
562  unsigned ii;
563 
564  for( ii = 0; ii < libNicknames.size(); ii++ )
565  {
566  if( libNicknames[ii] != m_libList->GetString( ii ) )
567  break;
568  }
569 
570  if( ii == libNicknames.size() )
571  return;
572  }
573 
574  // If we are here, the library list has changed, rebuild it
576  UpdateTitle();
577 }
578 
579 
580 bool FOOTPRINT_VIEWER_FRAME::ShowModal( wxString* aFootprint, wxWindow* aParent )
581 {
582  if( aFootprint && !aFootprint->IsEmpty() )
583  {
584  wxString msg;
585  LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
586  LIB_ID fpid;
587 
588  fpid.Parse( *aFootprint, LIB_ID::ID_PCB, true );
589 
590  if( fpid.IsValid() )
591  {
592  wxString nickname = fpid.GetLibNickname();
593 
594  if( !fpTable->HasLibrary( fpid.GetLibNickname(), false ) )
595  {
596  msg.sprintf( _( "The current configuration does not include a library with the\n"
597  "nickname \"%s\". Use Manage Footprint Libraries\n"
598  "to edit the configuration." ), nickname );
599  DisplayErrorMessage( aParent, _( "Footprint library not found." ), msg );
600  }
601  else if ( !fpTable->HasLibrary( fpid.GetLibNickname(), true ) )
602  {
603  msg.sprintf( _( "The library with the nickname \"%s\" is not enabled\n"
604  "in the current configuration. Use Manage Footprint Libraries to\n"
605  "edit the configuration." ), nickname );
606  DisplayErrorMessage( aParent, _( "Footprint library not enabled." ), msg );
607  }
608  else
609  {
610  setCurNickname( nickname );
613  }
614 
616  }
617  }
618 
619  return KIWAY_PLAYER::ShowModal( aFootprint, aParent );
620 }
621 
622 
623 bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
624 {
625  bool eventHandled = true;
626 
627  // Filter out the 'fake' mouse motion after a keyboard movement
628  if( !aHotKey && m_movingCursorWithKeyboard )
629  {
631  return false;
632  }
633 
634  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
635  cmd.SetEventObject( this );
636 
637  wxPoint oldpos = GetCrossHairPosition();
638  wxPoint pos = aPosition;
639  GeneralControlKeyMovement( aHotKey, &pos, true );
640 
641  if( aHotKey )
642  {
643  eventHandled = OnHotKey( aDC, aHotKey, aPosition );
644  }
645 
646  SetCrossHairPosition( pos );
647  RefreshCrossHair( oldpos, aPosition, aDC );
648 
649  UpdateStatusBar(); // Display new cursor coordinates
650 
651  return eventHandled;
652 }
653 
654 
655 void FOOTPRINT_VIEWER_FRAME::Show3D_Frame( wxCommandEvent& event )
656 {
657  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
658 
659  // We can probably remove this for 6.0, but just to be safe we'll stick to
660  // one 3DFrame at a time for 5.0
661  if( draw3DFrame )
662  draw3DFrame->Close( true );
663 
664  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, _( "3D Viewer" ) );
665  Update3D_Frame( false );
666 
667 #ifdef __WXMAC__
668  // A stronger version of Raise() which promotes the window to its parent's level.
669  draw3DFrame->ReparentQuasiModal();
670 #else
671  draw3DFrame->Raise(); // Needed with some Window Managers
672 #endif
673 
674  draw3DFrame->Show( true );
675 }
676 
677 
678 void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
679 {
680  wxString title = wxString::Format( _( "3D Viewer" ) + wxT( " \u2014 %s" ),
682 
683  Update3DView( &title );
684 }
685 
686 
688 {
689  return Settings().Colors().GetItemColor( LAYER_GRID );
690 }
691 
692 
694 {
695  switch( event.GetId() )
696  {
697  case ID_MODVIEW_NEXT:
699  break;
700 
701  case ID_MODVIEW_PREVIOUS:
703  break;
704 
705  default:
706  wxString id = wxString::Format( "%i", event.GetId() );
707  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
708  }
709 }
710 
711 
712 void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
713 {
714 }
715 
716 
717 bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
718 {
719  return true;
720 }
721 
722 
724 {
725  wxString title;
726  wxString path;
727 
728  title.Printf( _( "Library Browser" ) + L" \u2014 %s",
729  getCurNickname().size()
730  ? getCurNickname()
731  : _( "no library selected" ) );
732 
733  // Now, add the full path, for info
734  if( getCurNickname().size() )
735  {
736  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
737  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
738 
739  if( row )
740  title << L" \u2014 " << row->GetFullURI( true );
741  }
742 
743  SetTitle( title );
744 }
745 
746 
748 {
749  MODULE* module = SelectFootprintFromLibTree( false );
750 
751  if( module )
752  {
753  const LIB_ID& fpid = module->GetFPID();
754 
755  setCurNickname( fpid.GetLibNickname() );
757 
758  int index = m_libList->FindString( fpid.GetLibNickname() );
759 
760  if( index != wxNOT_FOUND )
761  {
762  m_libList->SetSelection( index, true );
763  m_libList->EnsureVisible( index );
764  }
765 
767 
769  }
770 }
771 
772 
774 {
775  if( !getCurNickname() )
776  return;
777 
778  int selection = m_footprintList->FindString( getCurFootprintName() );
779 
780  if( aMode == NEXT_PART )
781  {
782  if( selection != wxNOT_FOUND && selection < (int)m_footprintList->GetCount()-1 )
783  selection++;
784  }
785 
786  if( aMode == PREVIOUS_PART )
787  {
788  if( selection != wxNOT_FOUND && selection > 0 )
789  selection--;
790  }
791 
792  if( selection != wxNOT_FOUND )
793  {
794  m_footprintList->SetSelection( selection );
795  m_footprintList->EnsureVisible( selection );
796 
797  setCurFootprintName( m_footprintList->GetString( (unsigned) selection ) );
798  SetCurItem( NULL );
799 
800  // Delete the current footprint
802 
805 
806  if( footprint )
807  GetBoard()->Add( footprint, ADD_APPEND );
808 
809  Update3D_Frame();
810 
811  updateView();
812  }
813 
814  UpdateTitle();
815 
816  m_canvas->Refresh();
817 }
818 
819 
820 void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
821 {
822  if( !GetBoard() )
823  return;
824 
825  m_canvas->DrawBackGround( DC );
826  GetBoard()->Draw( m_canvas, DC, GR_COPY );
827 
828  m_canvas->DrawCrossHair( DC );
829 
830  UpdateMsgPanel();
831 }
832 
833 
835 {
836  BOARD_ITEM* footprint = GetBoard()->m_Modules;
837 
838  if( footprint )
839  {
840  MSG_PANEL_ITEMS items;
841 
842  footprint->GetMsgPanelInfo( m_UserUnits, items );
843  SetMsgPanel( items );
844  }
845  else
846  ClearMsgPanel();
847 }
848 
849 
851 {
852  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetGalCanvas()->GetView()->GetPainter() );
853  KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
854  settings->LoadDisplayOptions( &m_DisplayOptions, false );
855 
857  GetGalCanvas()->Refresh();
858 }
859 
860 
862 {
863  auto dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
864  dp->UseColorScheme( &Settings().Colors() );
865  dp->DisplayBoard( GetBoard() );
866 
868 
869  if( m_autoZoom )
871  else
873 
874  UpdateMsgPanel();
875 }
876 
877 
878 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
879 {
880  Close();
881 }
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:125
bool IsValid() const
Definition: lib_id.h:171
int m_SolderMaskMargin
Solder mask margin.
void ClickOnLibList(wxCommandEvent &event)
virtual void SetBoard(BOARD *aBoard)
Function SetBoard sets the m_Pcb member in such as way as to ensure deleting any previous BOARD...
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hotkeys_Descr[]
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
MODULE * SelectFootprintFromLibTree(bool aUseFootprintViewer=true)
Function SelectFootprintFromLibTree opens a dialog to select a footprint.
#define PREVIOUS_PART
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar FOOTPRINT_EDIT_FRAME::ProcessPreferences FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions FOOTPRINT_EDIT_FRAME::Process_Special_Functions EVT_UPDATE_UI(ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard) EVT_UPDATE_UI(ID_MODEDIT_INSERT_MODULE_IN_BOARD
bool ShowModal(wxString *aFootprint, wxWindow *aParent) override
Function ShowModal.
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
NETCLASSPTR GetDefault() const
Function GetDefault.
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...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Function DisplayErrorMessage displays an error message with aMessage.
Definition: confirm.cpp:259
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:946
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey handle hot key events.
void ClickOnFootprintList(wxCommandEvent &event)
bool m_showAxis
True shows the X and Y axis indicators.
Definition: draw_frame.h:133
Model changes (required full reload)
Definition: tool_base.h:83
This file is part of the common library.
void Update3D_Frame(bool aForceReloadFootprint=true)
Function Update3D_Frame must be called after a footprint selection Updates the 3D view and 3D frame t...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
TOOL_DISPATCHER * m_toolDispatcher
Definition: draw_frame.h:126
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
Function LoadSettings loads common frame parameters from a configuration file.
virtual void SetScreen(BASE_SCREEN *aScreen)
Definition: draw_frame.h:181
void DClickOnFootprintList(wxCommandEvent &event)
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
void setCurFootprintName(const wxString &aName)
Class SELECTION_TOOL.
Class BOARD to handle a board.
void OnCloseWindow(wxCloseEvent &Event) override
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
Component library viewer main window.
void UpdateAllItems(int aUpdateFlags)
Updates all items in the view according to the given flags.
Definition: view.cpp:1434
FOOTPRINT_VIEWER_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType)
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
static TOOL_ACTION zoomFitScreen
Definition: actions.h:56
wxString ConfigBaseName()
Function ConfigBaseName.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
The common library.
virtual wxConfigBase * config()
Function config returns the wxConfigBase used in SaveSettings(), and is overloaded in KICAD_MANAGER_F...
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
void SetGalCanvas(EDA_DRAW_PANEL_GAL *aPanel)
Definition: draw_frame.h:929
wxAuiManager m_auimgr
#define PARENT_STYLE
void RedrawActiveWindow(wxDC *DC, bool EraseBg) override
Function RedrawActiveWindow Display the current selected component.
KIGFX::VIEW * GetView() const
Function GetView() Returns a pointer to the VIEW instance used in the panel.
void SkipNextLeftButtonReleaseEvent()
After calling this function, if the left mouse button is down, the next left mouse button release eve...
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:44
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
void Show3D_Frame(wxCommandEvent &event) override
Function Show3D_Frame (virtual) displays 3D view of the footprint (module) being edited.
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
void setCurNickname(const wxString &aNickname)
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:211
void SetScale(double aScale)
Function SetScale() Sets the scaling factor.
Definition: view.h:250
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
#define NEW_PART
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
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...
static const wxChar AUTO_ZOOM_KEY[]
Pcbnew hotkeys.
Class PCBNEW_CONTROL.
virtual void UseGalCanvas(bool aEnable) override
>
bool m_axesEnabled
Whether or not to draw the coordinate system axes
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Handle the common part of GeneralControl dedicated to global cursor keys (i.e.
void ApplyDisplaySettingsToGAL()
Updates the GAL with display settings changes.
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
const LIB_ID & GetFPID() const
Definition: class_module.h:193
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
Class TOOL_MANAGER.
Definition: tool_manager.h:49
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
KIGFX::GAL * GetGAL() const
Function GetGAL() Returns a pointer to the GAL instance used in the panel.
static FOOTPRINT_LIST * GetInstance(KIWAY &aKiway)
Factory function to return a FOOTPRINT_LIST via Kiway.
void UpdateMsgPanel() override
redraws the message panel.
static TOOL_ACTION centerContents
Definition: actions.h:59
void SelectAndViewFootprint(int aMode)
Function SelectAndViewFootprint Select and load the next or the previous footprint if no current foot...
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
EDA_HOTKEY_CONFIG * m_hotkeysDescrList
Definition: draw_frame.h:105
void RefreshCrossHair(const wxPoint &aOldPos, const wxPoint &aEvtPos, wxDC *aDC)
Move and refresh the crosshair after movement and call the mouse capture function.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
#define FOOTPRINT_VIEWER_FRAME_NAME
Definition: draw_frame.h:54
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, wxWindow *aFrame)
Sets the work environment (model, view, view controls and the parent window).
void DisplayBoard(BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
void Clear()
Function Clear() Removes all items from the view.
Definition: view.cpp:1108
bool m_Center
Center on screen.
Definition: base_screen.h:202
#define NEXT_PART
EDA_MSG_PANEL * m_messagePanel
Panel used to display information at the bottom of the main window.
Definition: draw_frame.h:163
PCB_GENERAL_SETTINGS & Settings()
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
The common library.
Helper dialog and control classes.
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey=0) override
Perform application specific control using aDC at aPosition in logical units.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets all tools (i.e.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
virtual void DrawCrossHair(wxDC *aDC=nullptr, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
uint32_t EDA_KEY
Definition: common.h:73
wxString m_configFrameName
prefix used in config to identify some params (frame size...) if empty, the frame name defined in CTO...
PCB_GENERAL_SETTINGS m_configSettings
EVT_TOOL(ID_FOOTPRINT_WIZARD_SELECT_WIZARD, FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard) EVT_TOOL(ID_FOOTPRINT_WIZARD_RESET_TO_DEFAULT
#define MODAL_STYLE
void ExportSelectedFootprint(wxCommandEvent &event)
Function ExportSelectedFootprint exports the current footprint name and close the library browser...
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
virtual void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList)
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
Definition: base_struct.h:297
bool IsModal()
Definition: kiway_player.h:226
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
int m_LastGridSizeId
Definition: draw_frame.h:107
void SetAxesEnabled(bool aAxesEnabled)
Enables drawing the axes.
Specialization of the wxAuiPaneInfo class for KiCad panels.
void SelectCurrentFootprint(wxCommandEvent &event)
Function SelectCurrentFootprint Selects the current footprint name and display it.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
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...
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:206
void UseColorScheme(const COLORS_DESIGN_SETTINGS *aSettings)
Function UseColorScheme Applies layer color settings.
Class COMMON_TOOLS.
Definition: common_tools.h:38
COLORS_DESIGN_SETTINGS & Colors()
Class TOOL_DISPATCHER.
PCB_DISPLAY_OPTIONS m_DisplayOptions
void SetModal(bool aIsModal)
Definition: kiway_player.h:227
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
FOOTPRINT_EDIT_FRAME::OnVerticalToolbar EVT_MENU(ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST, FOOTPRINT_EDIT_FRAME::ProcessPreferences) EVT_MENU(ID_PCB_LIB_TABLE_EDIT
#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL
Definition: draw_frame.h:55
#define NONMODAL_STYLE
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS *aOptions, bool aShowPageLimits)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode...
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:123
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:934
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
virtual void UpdateStatusBar() override
Update the status bar information.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void OnSetRelativeOffset(wxCommandEvent &event)
Class PCB_ACTIONS.
Definition: pcb_actions.h:42
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
see class PGM_BASE
Declaration of the eda_3d_viewer class.
const char * name
Definition: DXF_plotter.cpp:61
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
void CloseFootprintViewer(wxCommandEvent &event)
void ReCreateMenuBar() override
Function ReCreateMenuBar Creates recreates the menu bar.
void DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets a dispatcher that processes events and forwards them to tools...
DLIST< MODULE > m_Modules
Definition: class_board.h:248
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
void ReCreateLibraryList()
Function ReCreateLibraryList.
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
UTF8 Format() const
Definition: lib_id.cpp:237
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.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel...
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:928
virtual void DrawBackGround(wxDC *DC)
Function DrawBackGround.
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw.
Class EDA_3D_VIEWER Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard...
Definition: eda_3d_viewer.h:50
virtual void OnActivate(wxActivateEvent &event) override
Function OnActivate is called when the frame frame is activate to reload the libraries and component ...
Module description (excepted pads)
void OnIterateFootprintList(wxCommandEvent &event)
void InitTools()
Function InitTools() Initializes all registered tools.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
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
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:120
ACTIONS * m_actions
Definition: draw_frame.h:127
EDA_3D_VIEWER * Get3DViewerFrame()
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
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 void OnActivate(wxActivateEvent &event)
Called when activating the frame.
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:173
VTBL_ENTRY 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...
void ClearMsgPanel(void)
Clear all messages from the message panel.
class 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[]
bool Update3DView(const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
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 SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Class 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.