KiCad PCB EDA Suite
modview_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-2017 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>
35 #include <wxPcbStruct.h>
37 #include <dialog_helpers.h>
38 #include <msgpanel.h>
39 #include <fp_lib_table.h>
40 #include <lib_id.h>
41 #include <confirm.h>
42 #include <bitmaps.h>
43 
44 #include <class_board.h>
45 #include <class_module.h>
46 
47 #include <pcbnew.h>
48 #include <pcbnew_id.h>
49 #include <modview_frame.h>
50 #include <footprint_info.h>
51 
52 #include <hotkeys.h>
54 #include <config_params.h>
55 
56 #include <tool/tool_manager.h>
57 #include <tool/tool_dispatcher.h>
58 #include <tool/common_tools.h>
59 #include "tools/pcbnew_control.h"
60 #include "tools/pcb_actions.h"
61 
62 #include <functional>
63 #include <memory>
64 using namespace std::placeholders;
65 
66 
67 #define NEXT_PART 1
68 #define NEW_PART 0
69 #define PREVIOUS_PART -1
70 
71 
72 BEGIN_EVENT_TABLE( FOOTPRINT_VIEWER_FRAME, EDA_DRAW_FRAME )
73  // Window events
74  EVT_CLOSE( FOOTPRINT_VIEWER_FRAME::OnCloseWindow )
75  EVT_SIZE( FOOTPRINT_VIEWER_FRAME::OnSize )
76  EVT_ACTIVATE( FOOTPRINT_VIEWER_FRAME::OnActivate )
77 
78  // Menu (and/or hotkey) events
79  EVT_MENU( wxID_EXIT, FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer )
81 
82  // Menu Help
83  EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
84  EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
85  EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
86  EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
87 
88  // Toolbar events
90  FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary )
92  FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
94  FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
96  FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
98  FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint )
100 
101  // listbox events
102  EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList )
103  EVT_LISTBOX( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList )
104  EVT_LISTBOX_DCLICK( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList )
105 
106 END_EVENT_TABLE()
107 
108 
109 /* Note:
110  * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
111  * In modal mode:
112  * a tool to export the selected footprint is shown in the toolbar
113  * the style is wxFRAME_FLOAT_ON_PARENT
114  * Note:
115  * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed
116  * its parent frame is sometimes brought to the foreground when closing the
117  * LIB_VIEW_FRAME frame.
118  * If it still happens, it could be better to use wxSTAY_ON_TOP
119  * instead of wxFRAME_FLOAT_ON_PARENT
120  */
121 #ifdef __WINDOWS__
122 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT // could be wxSTAY_ON_TOP if issues
123 #else
124 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT
125 #endif
126 
127 #define FOOTPRINT_VIEWER_FRAME_NAME "ModViewFrame"
128 #define FOOTPRINT_VIEWER_FRAME_NAME_MODAL "ModViewFrameModal"
129 
130 
131 FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) :
132  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
133  wxDefaultPosition, wxDefaultSize,
134  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
135  aParent ?
137  : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP
139  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
142 {
143  wxASSERT( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ||
144  aFrameType == FRAME_PCB_MODULE_VIEWER );
145 
146  if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL )
147  SetModal( true );
148 
149  // Force the frame name used in config. the footprint viewer frame has a name
150  // depending on aFrameType (needed to identify the frame by wxWidgets),
151  // but only one configuration is preferable.
152  m_configFrameName = FOOTPRINT_VIEWER_FRAME_NAME;
153 
154  m_showAxis = true; // true to draw axis.
155 
156  // Give an icon
157  wxIcon icon;
158  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
159  SetIcon( icon );
160 
161  m_hotkeysDescrList = g_Module_Viewer_Hokeys_Descr;
162 
163  m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST,
164  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
165 
166  m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST,
167  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
168 
169  SetBoard( new BOARD() );
170  // In viewer, the default net clearance is not known (it depends on the actual board).
171  // So we do not show the default clearance, by setting it to 0
172  // The footprint or pad specific clearance will be shown
173  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
174 
175  // Ensure all layers and items are visible:
177  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
178 
179  GetScreen()->m_Center = true; // Center coordinate origins on screen.
180  LoadSettings( config() );
181 
182  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
183 
184  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
185 
186  // Menu bar is not mandatory: uncomment/comment the next line
187  // to add/remove the menubar
188  ReCreateMenuBar();
189  ReCreateHToolbar();
190  ReCreateVToolbar();
191 
192  ReCreateLibraryList();
193  UpdateTitle();
194 
195  // See for an existing board editor frame opened
196  // (we need it just to know some settings )
197  // TODO: find a better way to retrieve these settings)
198  bool isBordEditorRunning = Kiway().Player( FRAME_PCB, false ) != nullptr;
199  PCB_BASE_FRAME* pcbEditorFrame = static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, true ) );
200 
201  // Create GAL canvas
202  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
203  pcbEditorFrame->GetGalDisplayOptions(),
204  pcbEditorFrame->GetGalCanvas()->GetBackend() );
205  SetGalCanvas( drawPanel );
206  bool switchToGalCanvas = pcbEditorFrame->IsGalCanvasActive();
207 
208  // delete pcbEditorFrame if it was not yet in use:
209  if( !isBordEditorRunning )
210  pcbEditorFrame->Destroy();
211 
212  // Create the manager and dispatcher & route draw panel events to the dispatcher
213  m_toolManager = new TOOL_MANAGER;
214  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
215  drawPanel->GetViewControls(), this );
216  m_actions = new PCB_ACTIONS();
217  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
218  drawPanel->SetEventDispatcher( m_toolDispatcher );
219 
220  m_toolManager->RegisterTool( new PCBNEW_CONTROL );
221  m_toolManager->RegisterTool( new COMMON_TOOLS );
222  m_toolManager->InitTools();
223 
224  // If a footprint was previously loaded, reload it
225  if( getCurNickname().size() && getCurFootprintName().size() )
226  {
227  LIB_ID id;
228 
229  id.SetLibNickname( getCurNickname() );
230  id.SetLibItemName( getCurFootprintName() );
231  GetBoard()->Add( loadFootprint( id ) );
232  }
233 
234  drawPanel->DisplayBoard( m_Pcb );
235  updateView();
236 
237  m_auimgr.SetManagedWindow( this );
238 
239  wxSize minsize(100,-1); // Min size of list boxes
240 
241  // Main toolbar is initially docked at the top of the main window and dockable on any side.
242  // The close button is disable because the footprint viewer has no main menu to re-enable it.
243  // The tool bar will only be dockable on the top or bottom of the main frame window. This is
244  // most likely due to the fact that the other windows are not dockable and are preventing the
245  // tool bar from docking on the right and left.
246  wxAuiPaneInfo toolbarPaneInfo;
247  toolbarPaneInfo.Name( "m_mainToolBar" ).ToolbarPane().Top().CloseButton( false );
248 
249  EDA_PANEINFO info;
250  info.InfoToolbarPane();
251 
252  EDA_PANEINFO mesg;
253  mesg.MessageToolbarPane();
254 
255  // Manage main toolbar, top pane
256  m_auimgr.AddPane( m_mainToolBar, toolbarPaneInfo );
257 
258  // Manage the list of libraries, left pane.
259  m_auimgr.AddPane( m_libList,
260  wxAuiPaneInfo( info ).Name( "m_libList" )
261  .Left().Row( 1 ).MinSize( minsize ) );
262 
263  // Manage the list of footprints, center pane.
264  m_auimgr.AddPane( m_footprintList,
265  wxAuiPaneInfo( info ).Name( "m_footprintList" )
266  .Left().Row( 2 ).MinSize( minsize ) );
267 
268  // Manage the draw panel, right pane.
269  m_auimgr.AddPane( m_canvas,
270  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
271  m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
272  wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() );
273 
274  // Manage the message panel, bottom pane.
275  m_auimgr.AddPane( m_messagePanel,
276  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom() );
277 
278  if( !m_perspective.IsEmpty() )
279  {
280  // Restore last saved sizes, pos and other params
281  // However m_mainToolBar size cannot be set to its last saved size
282  // because the actual size change depending on the way modview was called:
283  // the tool to export the current footprint exist or not.
284  // and the saved size is not always OK
285  // the trick is to get the default toolbar size, and set the size after
286  // calling LoadPerspective
287  wxSize tbsize = m_mainToolBar->GetSize();
288  m_auimgr.LoadPerspective( m_perspective, false );
289  m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize );
290  }
291 
292  // after changing something to the aui manager,
293  // call Update()() to reflect the changes
294  m_auimgr.Update();
295 
296  // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
297 #ifdef USE_WX_GRAPHICS_CONTEXT
298  GetScreen()->SetZoom( BestZoom() );
299 #else
300  Zoom_Automatique( false );
301 #endif
302 
303  UseGalCanvas( switchToGalCanvas );
304 
305  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
306  {
307  Raise(); // On some window managers, this is needed
308  Show( true );
309  }
310 }
311 
312 
314 {
315  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
316 
317  if( draw3DFrame )
318  draw3DFrame->Destroy();
319 }
320 
321 
322 
323 void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
324 {
325  DBG(printf( "%s:\n", __func__ );)
326 
327  // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
328  // when the aui toolbar is not docked (i.e. shown in a miniframe)
329  // (usefull on windows only)
330  m_mainToolBar->SetFocus();
331 
332  if( IsGalCanvasActive() )
334 
335  if( IsModal() )
336  {
337  // Only dismiss a modal frame once, so that the return values set by
338  // the prior DismissModal() are not bashed for ShowModal().
339  if( !IsDismissed() )
340  DismissModal( false );
341 
342  // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
343  }
344  else
345  Destroy();
346 }
347 
348 
349 void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
350 {
351  if( m_auimgr.GetManagedWindow() )
352  m_auimgr.Update();
353 
354  SizeEv.Skip();
355 }
356 
357 
358 void FOOTPRINT_VIEWER_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
359 {
361  UpdateStatusBar();
362 }
363 
364 
366 {
367  m_libList->Clear();
368 
369  std::vector< wxString > nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
370 
371  for( unsigned ii = 0; ii < nicknames.size(); ii++ )
372  m_libList->Append( nicknames[ii] );
373 
374  // Search for a previous selection:
375  int index = m_libList->FindString( getCurNickname() );
376 
377  if( index != wxNOT_FOUND )
378  {
379  m_libList->SetSelection( index, true );
380  }
381  else
382  {
383  // If not found, clear current library selection because it can be
384  // deleted after a configuration change.
385  setCurNickname( wxEmptyString );
386  setCurFootprintName( wxEmptyString );
387  }
388 
391 
392  m_canvas->Refresh();
393 }
394 
395 
397 {
398  m_footprintList->Clear();
399 
400  if( !getCurNickname() )
401  {
402  setCurFootprintName( wxEmptyString );
403  return;
404  }
405 
406  auto fp_info_list( FOOTPRINT_LIST::GetInstance( Kiway() ) );
407 
408  wxString nickname = getCurNickname();
409 
410  fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
411 
412  if( fp_info_list->GetErrorCount() )
413  {
414  fp_info_list->DisplayErrors( this );
415 
416  // For footprint libraries that support one footprint per file, there may have been
417  // valid footprints read so show the footprints that loaded properly.
418  if( fp_info_list->GetList().size() == 0 )
419  return;
420  }
421 
422  for( auto& footprint : fp_info_list->GetList() )
423  {
424  m_footprintList->Append( footprint->GetFootprintName() );
425  }
426 
427  int index = m_footprintList->FindString( getCurFootprintName() );
428 
429  if( index == wxNOT_FOUND )
430  setCurFootprintName( wxEmptyString );
431  else
432  m_footprintList->SetSelection( index, true );
433 }
434 
435 
436 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
437 {
438  int ii = m_libList->GetSelection();
439 
440  if( ii < 0 )
441  return;
442 
443  wxString name = m_libList->GetString( ii );
444 
445  if( getCurNickname() == name )
446  return;
447 
448  setCurNickname( name );
449 
451  UpdateTitle();
453 }
454 
455 
456 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
457 {
458  if( m_footprintList->GetCount() == 0 )
459  return;
460 
461  int ii = m_footprintList->GetSelection();
462 
463  if( ii < 0 )
464  return;
465 
466  wxString name = m_footprintList->GetString( ii );
467 
468  if( getCurFootprintName().CmpNoCase( name ) != 0 )
469  {
470  setCurFootprintName( name );
471 
472  SetCurItem( NULL );
473 
474  // Delete the current footprint
476 
477  LIB_ID id;
479  id.SetLibItemName( getCurFootprintName() );
480 
481  try
482  {
483  GetBoard()->Add( loadFootprint( id ) );
484  }
485  catch( const IO_ERROR& ioe )
486  {
487  wxString msg = wxString::Format(
488  _( "Could not load footprint \"%s\" from library \"%s\".\n\nError %s." ),
491  GetChars( ioe.What() ) );
492 
493  DisplayError( this, msg );
494  }
495 
496  UpdateTitle();
497 
498  if( IsGalCanvasActive() )
499  updateView();
500 
501  Zoom_Automatique( false );
502  m_canvas->Refresh();
503  Update3D_Frame();
504  }
505 }
506 
507 
509 {
510  if( IsModal() )
511  {
512  // @todo(DICK)
513  ExportSelectedFootprint( event );
514 
515  // Prevent the double click from being as a single mouse button release
516  // event in the parent window which would cause the part to be parked
517  // rather than staying in move mode.
518  // Remember the mouse button will be released in the parent window
519  // thus creating a mouse button release event which should be ignored
520  PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
521 
522  // The parent may not be the board editor:
523  if( pcbframe )
524  {
525  pcbframe->SkipNextLeftButtonReleaseEvent();
526  }
527  }
528 }
529 
530 
532 {
533  int ii = m_footprintList->GetSelection();
534 
535  if( ii >= 0 )
536  {
537  wxString fp_name = m_footprintList->GetString( ii );
538 
539  LIB_ID fpid;
540 
541  fpid.SetLibNickname( getCurNickname() );
542  fpid.SetLibItemName( fp_name );
543 
544  DismissModal( true, fpid.Format() );
545  }
546  else
547  {
548  DismissModal( false );
549  }
550 
551  Close( true );
552 }
553 
554 
555 void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
556 {
558  m_configSettings.Load( aCfg ); // mainly, load the color config
559 }
560 
561 
562 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
563 {
565 }
566 
567 
569 {
571 }
572 
573 
574 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
575 {
577 }
578 
579 
581 {
583 }
584 
585 
586 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
587 {
589 }
590 
591 
592 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
593 {
595 
596  // Ensure we do not have old selection:
597  if( !event.GetActive() )
598  return;
599 
600  // Ensure we have the right library list:
601  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
602 
603  if( libNicknames.size() == m_libList->GetCount() )
604  {
605  unsigned ii;
606 
607  for( ii = 0; ii < libNicknames.size(); ii++ )
608  {
609  if( libNicknames[ii] != m_libList->GetString( ii ) )
610  break;
611  }
612 
613  if( ii == libNicknames.size() )
614  return;
615  }
616 
617  // If we are here, the library list has changed, rebuild it
619  UpdateTitle();
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  if( draw3DFrame )
660  {
661  // Raising the window does not show the window on Windows if iconized.
662  // This should work on any platform.
663  if( draw3DFrame->IsIconized() )
664  draw3DFrame->Iconize( false );
665 
666  draw3DFrame->Raise();
667 
668  // Raising the window does not set the focus on Linux. This should work on any platform.
669  if( wxWindow::FindFocus() != draw3DFrame )
670  draw3DFrame->SetFocus();
671 
672  return;
673  }
674 
675  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, wxEmptyString );
676  Update3D_Frame( false );
677  draw3DFrame->Raise(); // Needed with some Window Managers
678  draw3DFrame->Show( true );
679 }
680 
681 
682 void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
683 {
684  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
685 
686  if( draw3DFrame == NULL )
687  return;
688 
689  wxString title = wxString::Format(
690  _( "3D Viewer" ) + L" \u2014 %s",
692 
693  draw3DFrame->SetTitle( title );
694 
695  if( aForceReloadFootprint )
696  {
697  // Force 3D screen refresh immediately
698  draw3DFrame->NewDisplay( true );
699  }
700 }
701 
702 
704 {
705  return Settings().Colors().GetItemColor( LAYER_GRID );
706 }
707 
708 
710 {
711  switch( event.GetId() )
712  {
713  case ID_MODVIEW_NEXT:
715  break;
716 
717  case ID_MODVIEW_PREVIOUS:
719  break;
720 
721  default:
722  wxString id = wxString::Format( "%i", event.GetId() );
723  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
724  }
725 }
726 
727 
728 void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
729 {
730 }
731 
732 
733 bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
734 {
735  return true;
736 }
737 
738 
740 {
741  wxString title;
742  wxString path;
743 
744  title.Printf( _( "Library Browser" ) + L" \u2014 %s",
745  getCurNickname().size()
746  ? getCurNickname()
747  : _( "no library selected" ) );
748 
749  // Now, add the full path, for info
750  if( getCurNickname().size() )
751  {
752  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
753  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
754 
755  if( row )
756  title << L" \u2014 " << row->GetFullURI( true );
757  }
758 
759  SetTitle( title );
760 }
761 
762 
763 void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
764 {
765  wxString selection = SelectLibrary( getCurNickname() );
766 
767  if( !!selection && selection != getCurNickname() )
768  {
769  setCurNickname( selection );
770 
771  UpdateTitle();
773 
774  int id = m_libList->FindString( getCurNickname() );
775 
776  if( id >= 0 )
777  m_libList->SetSelection( id );
778  }
779 }
780 
781 
783 {
784  wxString curr_nickname = getCurNickname();
785  MODULE* oldmodule = GetBoard()->m_Modules;
786  MODULE* module = LoadModuleFromLibrary( curr_nickname, Prj().PcbFootprintLibs(), false );
787 
788  if( module )
789  {
790  module->SetPosition( wxPoint( 0, 0 ) );
791 
792  // Only one footprint allowed: remove the previous footprint (if exists)
793  if( oldmodule )
794  {
795  GetBoard()->Remove( oldmodule );
796  delete oldmodule;
797  }
798 
800 
801  wxString nickname = module->GetFPID().GetLibNickname();
802 
803  if( !getCurNickname() && nickname.size() )
804  {
805  // Set the listbox
806  int index = m_libList->FindString( nickname );
807  if( index != wxNOT_FOUND )
808  m_libList->SetSelection( index, true );
809 
810  setCurNickname( nickname );
811  }
812 
813  module->ClearFlags();
814  SetCurItem( NULL );
815 
816  Zoom_Automatique( false );
817  m_canvas->Refresh();
818  Update3D_Frame();
819  m_footprintList->SetStringSelection( getCurFootprintName() );
820  }
821 }
822 
823 
825 {
826  if( !getCurNickname() )
827  return;
828 
829  int selection = m_footprintList->FindString( getCurFootprintName() );
830 
831  if( aMode == NEXT_PART )
832  {
833  if( selection != wxNOT_FOUND && selection < (int)m_footprintList->GetCount()-1 )
834  selection++;
835  }
836 
837  if( aMode == PREVIOUS_PART )
838  {
839  if( selection != wxNOT_FOUND && selection > 0 )
840  selection--;
841  }
842 
843  if( selection != wxNOT_FOUND )
844  {
845  m_footprintList->SetSelection( selection );
846  setCurFootprintName( m_footprintList->GetString( selection ) );
847  SetCurItem( NULL );
848 
849  // Delete the current footprint
851 
852  MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad(
854 
855  if( footprint )
856  GetBoard()->Add( footprint, ADD_APPEND );
857 
858  Update3D_Frame();
859 
860  if( IsGalCanvasActive() )
861  updateView();
862  }
863 
864 
865  UpdateTitle();
866  Zoom_Automatique( false );
867  m_canvas->Refresh();
868 }
869 
870 
871 void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
872 {
873  if( !GetBoard() )
874  return;
875 
876  m_canvas->DrawBackGround( DC );
877  GetBoard()->Draw( m_canvas, DC, GR_COPY );
878 
879  MODULE* module = GetBoard()->m_Modules;
880 
881  m_canvas->DrawCrossHair( DC );
882 
883  ClearMsgPanel();
884 
885  if( module )
886  SetMsgPanel( module );
887 }
888 
889 
891 {
892  if( IsGalCanvasActive() )
893  {
894  auto dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
895  dp->UseColorScheme( &Settings().Colors() );
896  dp->DisplayBoard( GetBoard() );
899  }
900 }
901 
902 
903 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
904 {
905  Close();
906 }
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:95
#define KICAD_DEFAULT_DRAWFRAME_STYLE
Definition: wxstruct.h:55
void ClickOnLibList(wxCommandEvent &event)
void DisplayBoard(const BOARD *aBoard)
Function DisplayBoard adds all items from the current board to the VIEW, so they can be displayed by ...
bool OnRightClick(const wxPoint &MousePos, wxMenu *PopMenu) override
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.
Class LIB_TABLE_ROW.
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Function GetGalDisplayOptions Returns a reference to the gal rendering options used by GAL for render...
Definition: draw_frame.h:891
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
Function OnHotKey handle hot key events.
void ClickOnFootprintList(wxCommandEvent &event)
EVT_TOOL(ID_MODVIEW_SELECT_LIB, FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary) EVT_TOOL(ID_MODVIEW_SELECT_PART
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
Model changes (required full reload)
Definition: tool_base.h:83
GAL_TYPE GetBackend() const
Function GetBackend Returns the type of backend currently used by GAL canvas.
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...
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.
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
#define MODAL_MODE_EXTRASTYLE
void setCurFootprintName(const wxString &aName)
Class BOARD to handle a board.
void OnCloseWindow(wxCloseEvent &Event) override
MODULE * FootprintLoad(const wxString &aNickname, const wxString &aFootprintName)
Function FootprintLoad.
void DrawCrossHair(wxDC *aDC, COLOR4D aColor=COLOR4D::WHITE)
Function DrawCrossHair draws the user cross hair.
Definition: draw_panel.cpp:215
Component library viewer main window.
Definition: modview_frame.h:44
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
MODULE * LoadModuleFromLibrary(const wxString &aLibrary, FP_LIB_TABLE *aTable, bool aUseFootprintViewer=true, wxDC *aDC=NULL)
Function LoadModuleFromLibrary opens a dialog to select a footprint, and loads it into current board...
Definition: loadcmp.cpp:163
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.
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
#define FOOTPRINT_VIEWER_FRAME_NAME_MODAL
wxAuiManager m_auimgr
Definition: wxstruct.h:149
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()
function SkipNextLeftButtonReleaseEvent after calling this function, if the left mouse button is down...
Definition: draw_frame.cpp:286
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
Class LIB_ID.
Definition: lib_id.h:56
void Show3D_Frame(wxCommandEvent &event) override
Function Show3D_Frame (virtual) displays 3D view of the footprint (module) being edited.
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:54
void OnSize(wxSizeEvent &event) override
Function OnSize recalculates the size of toolbars and display panel when the frame size changes...
void setCurNickname(const wxString &aNickname)
static std::unique_ptr< FOOTPRINT_LIST > GetInstance(KIWAY &aKiway)
Factory function to return a new FOOTPRINT_LIST via Kiway.
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Definition: draw_frame.cpp:746
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:478
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Pcbnew hotkeys.
Class PCBNEW_CONTROL.
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Function GeneralControlKeyMovement Handle the common part of GeneralControl dedicated to global curso...
#define NEXT_PART
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
const LIB_ID & GetFPID() const
Definition: class_module.h:164
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)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
void Zoom_Automatique(bool aWarpPointer)
Function Zoom_Automatique redraws the screen with best zoom level and the best centering that shows a...
Definition: zoom.cpp:77
void SelectAndViewFootprint(int aMode)
Function SelectAndViewFootprint Select and load the next or the previous footprint if no current foot...
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
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)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:784
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).
PCB_GENERAL_SETTINGS & Settings()
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
EVT_MENU(ID_SELECT_PREFERED_PDF_BROWSER_NAME, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser) EVT_MENU_RANGE(ID_LANGUAGE_CHOICE
const wxString getCurFootprintName()
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
wxListBox * m_footprintList
Definition: modview_frame.h:68
The common library.
Helper dialog and control classes.
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey=0) override
Function GeneralControl performs application specific control using aDC at aPosition in logical units...
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:532
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:257
void OnLeftClick(wxDC *DC, const wxPoint &MousePos) override
uint32_t EDA_KEY
Definition: common.h:52
#define FOOTPRINT_VIEWER_FRAME_NAME
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:862
PCB_GENERAL_SETTINGS m_configSettings
void ExportSelectedFootprint(wxCommandEvent &event)
Function ExportSelectedFootprint exports the current footprint name and close the library browser...
void SetPosition(const wxPoint &aPos) override
bool IsModal()
Definition: kiway_player.h:259
EDA_PANEINFO & InfoToolbarPane()
Function InfoToolbarPane Change *this to a information panel for for KiCad.
Definition: wxstruct.h:552
void SelectCurrentFootprint(wxCommandEvent &event)
Function SelectCurrentFootprint Selects the current footprint name and display it.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:145
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
Definition: draw_frame.cpp:716
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
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.
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:162
BOARD * GetBoard()
VTBL_ENTRY FP_LIB_TABLE * PcbFootprintLibs(KIWAY &aKiway)
Return the table of footprint libraries.
int SetLibNickname(const UTF8 &aNickname)
Function SetLibNickname.
Definition: lib_id.cpp:219
void SelectCurrentLibrary(wxCommandEvent &event)
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:93
const wxString getCurNickname()
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:177
virtual void UpdateStatusBar() override
Function UpdateStatusBar updates the status bar information.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
EDA_PANEINFO & MessageToolbarPane()
Function MessageToolbarPane Change *this to a message pane for KiCad.
Definition: wxstruct.h:524
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.
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 DismissModal(bool aRetVal, const wxString &aResult=wxEmptyString)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
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:245
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:117
void ReCreateLibraryList()
Function ReCreateLibraryList.
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
UTF8 Format() const
Function Format.
Definition: lib_id.cpp:263
const char * name
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...
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:268
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:870
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:665
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, const wxPoint &aOffset=ZeroOffset) override
Function Draw.
Definition: tracepcb.cpp:135
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
wxString SelectLibrary(const wxString &aNicknameExisting)
Function SelectLibrary puts up a dialog and allows the user to pick a library, for unspecified use...
Definition: librairi.cpp:847
#define DBG(x)
Definition: fctsys.h:33
void ReCreateHToolbar() override
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)
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Function SetCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
Message panel definition file.
virtual COLOR4D GetGridColor() override
Function GetGridColor() , virtual.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
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:71
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition 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:47
MODULE * loadFootprint(const LIB_ID &aFootprintId)
Function loadFootprint attempts to load aFootprintId from the footprint library table.
Definition: loadcmp.cpp:334
virtual void OnActivate(wxActivateEvent &event)
Function OnActivate (virtual) is called when activating the frame.
Definition: draw_frame.cpp:268
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:139
#define PREVIOUS_PART
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:775
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
void StopDrawing()
Function StopDrawing() Prevents the GAL canvas from further drawing till it is recreated or StartDraw...
std::vector< wxString > GetLogicalLibs()
Function GetLogicalLibs.
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
KIWAY Kiway
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
struct EDA_HOTKEY_CONFIG g_Module_Viewer_Hokeys_Descr[]