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 <pcbnew_config.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( TO_UTF8( getCurNickname() ) );
230  id.SetLibItemName( TO_UTF8( 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  return;
416  }
417 
418  for( auto& footprint : fp_info_list->GetList() )
419  {
420  m_footprintList->Append( footprint->GetFootprintName() );
421  }
422 
423  int index = m_footprintList->FindString( getCurFootprintName() );
424 
425  if( index == wxNOT_FOUND )
426  setCurFootprintName( wxEmptyString );
427  else
428  m_footprintList->SetSelection( index, true );
429 }
430 
431 
432 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
433 {
434  int ii = m_libList->GetSelection();
435 
436  if( ii < 0 )
437  return;
438 
439  wxString name = m_libList->GetString( ii );
440 
441  if( getCurNickname() == name )
442  return;
443 
444  setCurNickname( name );
445 
447  UpdateTitle();
449 }
450 
451 
452 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
453 {
454  if( m_footprintList->GetCount() == 0 )
455  return;
456 
457  int ii = m_footprintList->GetSelection();
458 
459  if( ii < 0 )
460  return;
461 
462  wxString name = m_footprintList->GetString( ii );
463 
464  if( getCurFootprintName().CmpNoCase( name ) != 0 )
465  {
466  setCurFootprintName( name );
467 
468  SetCurItem( NULL );
469 
470  // Delete the current footprint
472 
473  LIB_ID id;
475  id.SetLibItemName( TO_UTF8( getCurFootprintName() ) );
476 
477  try
478  {
479  GetBoard()->Add( loadFootprint( id ) );
480  }
481  catch( const IO_ERROR& ioe )
482  {
483  wxString msg = wxString::Format(
484  _( "Could not load footprint \"%s\" from library \"%s\".\n\nError %s." ),
487  GetChars( ioe.What() ) );
488 
489  DisplayError( this, msg );
490  }
491 
492  UpdateTitle();
493 
494  if( IsGalCanvasActive() )
495  updateView();
496 
497  Zoom_Automatique( false );
498  m_canvas->Refresh();
499  Update3D_Frame();
500  }
501 }
502 
503 
505 {
506  if( IsModal() )
507  {
508  // @todo(DICK)
509  ExportSelectedFootprint( event );
510 
511  // Prevent the double click from being as a single mouse button release
512  // event in the parent window which would cause the part to be parked
513  // rather than staying in move mode.
514  // Remember the mouse button will be released in the parent window
515  // thus creating a mouse button release event which should be ignored
516  PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
517 
518  // The parent may not be the board editor:
519  if( pcbframe )
520  {
521  pcbframe->SkipNextLeftButtonReleaseEvent();
522  }
523  }
524 }
525 
526 
528 {
529  int ii = m_footprintList->GetSelection();
530 
531  if( ii >= 0 )
532  {
533  wxString fp_name = m_footprintList->GetString( ii );
534 
535  LIB_ID fpid;
536 
538  fpid.SetLibItemName( TO_UTF8( fp_name ) );
539 
540  DismissModal( true, FROM_UTF8( fpid.Format() ) );
541  }
542  else
543  {
544  DismissModal( false );
545  }
546 
547  Close( true );
548 }
549 
550 
551 void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
552 {
554 }
555 
556 
557 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
558 {
560 }
561 
562 
564 {
566 }
567 
568 
569 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
570 {
572 }
573 
574 
576 {
578 }
579 
580 
581 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
582 {
584 }
585 
586 
587 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
588 {
590 
591  // Ensure we do not have old selection:
592  if( !event.GetActive() )
593  return;
594 
595  // Ensure we have the right library list:
596  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
597 
598  if( libNicknames.size() == m_libList->GetCount() )
599  {
600  unsigned ii;
601 
602  for( ii = 0; ii < libNicknames.size(); ii++ )
603  {
604  if( libNicknames[ii] != m_libList->GetString( ii ) )
605  break;
606  }
607 
608  if( ii == libNicknames.size() )
609  return;
610  }
611 
612  // If we are here, the library list has changed, rebuild it
614  UpdateTitle();
615 }
616 
617 
618 bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
619 {
620  bool eventHandled = true;
621 
622  // Filter out the 'fake' mouse motion after a keyboard movement
623  if( !aHotKey && m_movingCursorWithKeyboard )
624  {
626  return false;
627  }
628 
629  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
630  cmd.SetEventObject( this );
631 
632  wxPoint oldpos = GetCrossHairPosition();
633  wxPoint pos = aPosition;
634  GeneralControlKeyMovement( aHotKey, &pos, true );
635 
636  if( aHotKey )
637  {
638  eventHandled = OnHotKey( aDC, aHotKey, aPosition );
639  }
640 
641  SetCrossHairPosition( pos );
642  RefreshCrossHair( oldpos, aPosition, aDC );
643 
644  UpdateStatusBar(); // Display new cursor coordinates
645 
646  return eventHandled;
647 }
648 
649 
650 void FOOTPRINT_VIEWER_FRAME::Show3D_Frame( wxCommandEvent& event )
651 {
652  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
653 
654  if( draw3DFrame )
655  {
656  // Raising the window does not show the window on Windows if iconized.
657  // This should work on any platform.
658  if( draw3DFrame->IsIconized() )
659  draw3DFrame->Iconize( false );
660 
661  draw3DFrame->Raise();
662 
663  // Raising the window does not set the focus on Linux. This should work on any platform.
664  if( wxWindow::FindFocus() != draw3DFrame )
665  draw3DFrame->SetFocus();
666 
667  return;
668  }
669 
670  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, wxEmptyString );
671  Update3D_Frame( false );
672  draw3DFrame->Raise(); // Needed with some Window Managers
673  draw3DFrame->Show( true );
674 }
675 
676 
677 void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
678 {
679  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
680 
681  if( draw3DFrame == NULL )
682  return;
683 
684  wxString title = wxString::Format(
685  _( "3D Viewer" ) + L" \u2014 %s",
687 
688  draw3DFrame->SetTitle( title );
689 
690  if( aForceReloadFootprint )
691  {
692  // Force 3D screen refresh immediately
693  draw3DFrame->NewDisplay( true );
694  }
695 }
696 
697 
699 {
701 }
702 
703 
705 {
706  switch( event.GetId() )
707  {
708  case ID_MODVIEW_NEXT:
710  break;
711 
712  case ID_MODVIEW_PREVIOUS:
714  break;
715 
716  default:
717  wxString id = wxString::Format( "%i", event.GetId() );
718  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
719  }
720 }
721 
722 
723 void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
724 {
725 }
726 
727 
728 bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
729 {
730  return true;
731 }
732 
733 
735 {
736  wxString title;
737  wxString path;
738 
739  title.Printf( _( "Library Browser" ) + L" \u2014 %s",
740  getCurNickname().size()
741  ? getCurNickname()
742  : _( "no library selected" ) );
743 
744  // Now, add the full path, for info
745  if( getCurNickname().size() )
746  {
747  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
748  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
749 
750  if( row )
751  title << L" \u2014 " << row->GetFullURI( true );
752  }
753 
754  SetTitle( title );
755 }
756 
757 
758 void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
759 {
760  wxString selection = SelectLibrary( getCurNickname() );
761 
762  if( !!selection && selection != getCurNickname() )
763  {
764  setCurNickname( selection );
765 
766  UpdateTitle();
768 
769  int id = m_libList->FindString( getCurNickname() );
770 
771  if( id >= 0 )
772  m_libList->SetSelection( id );
773  }
774 }
775 
776 
778 {
779  wxString curr_nickname = getCurNickname();
780  MODULE* oldmodule = GetBoard()->m_Modules;
781  MODULE* module = LoadModuleFromLibrary( curr_nickname, Prj().PcbFootprintLibs(), false );
782 
783  if( module )
784  {
785  module->SetPosition( wxPoint( 0, 0 ) );
786 
787  // Only one footprint allowed: remove the previous footprint (if exists)
788  if( oldmodule )
789  {
790  GetBoard()->Remove( oldmodule );
791  delete oldmodule;
792  }
793 
795 
796  wxString nickname = FROM_UTF8( module->GetFPID().GetLibNickname() );
797 
798  if( !getCurNickname() && nickname.size() )
799  {
800  // Set the listbox
801  int index = m_libList->FindString( nickname );
802  if( index != wxNOT_FOUND )
803  m_libList->SetSelection( index, true );
804 
805  setCurNickname( nickname );
806  }
807 
808  module->ClearFlags();
809  SetCurItem( NULL );
810 
811  Zoom_Automatique( false );
812  m_canvas->Refresh();
813  Update3D_Frame();
814  m_footprintList->SetStringSelection( getCurFootprintName() );
815  }
816 }
817 
818 
820 {
821  if( !getCurNickname() )
822  return;
823 
824  int selection = m_footprintList->FindString( getCurFootprintName() );
825 
826  if( aMode == NEXT_PART )
827  {
828  if( selection != wxNOT_FOUND && selection < (int)m_footprintList->GetCount()-1 )
829  selection++;
830  }
831 
832  if( aMode == PREVIOUS_PART )
833  {
834  if( selection != wxNOT_FOUND && selection > 0 )
835  selection--;
836  }
837 
838  if( selection != wxNOT_FOUND )
839  {
840  m_footprintList->SetSelection( selection );
841  setCurFootprintName( m_footprintList->GetString( selection ) );
842  SetCurItem( NULL );
843 
844  // Delete the current footprint
846 
847  MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad(
849 
850  if( footprint )
851  GetBoard()->Add( footprint, ADD_APPEND );
852 
853  Update3D_Frame();
854 
855  if( IsGalCanvasActive() )
856  updateView();
857  }
858 
859 
860  UpdateTitle();
861  Zoom_Automatique( false );
862  m_canvas->Refresh();
863 }
864 
865 
866 void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
867 {
868  if( !GetBoard() )
869  return;
870 
871  m_canvas->DrawBackGround( DC );
872  GetBoard()->Draw( m_canvas, DC, GR_COPY );
873 
874  MODULE* module = GetBoard()->m_Modules;
875 
876  m_canvas->DrawCrossHair( DC );
877 
878  ClearMsgPanel();
879 
880  if( module )
881  SetMsgPanel( module );
882 }
883 
884 
886 {
887  if( IsGalCanvasActive() )
888  {
889  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() );
892  }
893 }
894 
895 
896 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
897 {
898  Close();
899 }
TOOL_MANAGER * m_toolManager
Definition: draw_frame.h:94
virtual COLOR4D GetGridColor() const override
Function GetGridColor() , virtual.
#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.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Function GetGalDisplayOptions Returns a reference to the gal rendering options used by GAL for render...
Definition: draw_frame.h:824
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
Definition: draw_panel.cpp:326
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...
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:216
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
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:139
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:275
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:53
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:716
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:465
const wxString GetFullURI(bool aSubstituted=false) const
Function GetFullURI.
Pcbnew hotkeys.
Class PCBNEW_CONTROL.
EVT_MENU(ID_SELECT_PREFERED_PDF_BROWSER_NAME, KICAD_MANAGER_FRAME::OnSelectPreferredPdfBrowser) EVT_MENU_RANGE(ID_PREFERENCES_HOTKEY_START
#define NEXT_PART
COLOR4D GetItemColor(int aItemIdx) const
Function GetItemColor.
const LIB_ID & GetFPID() const
Definition: class_module.h:152
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
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)
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:754
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).
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
const wxString getCurFootprintName()
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
>
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:530
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
Configuration parameters for Pcbnew.
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:795
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:216
COLORS_DESIGN_SETTINGS g_ColorsSettings
Definition: pcbnew.cpp:68
EDA_PANEINFO & InfoToolbarPane()
Function InfoToolbarPane Change *this to a information panel for for KiCad.
Definition: wxstruct.h:539
void SelectCurrentFootprint(wxCommandEvent &event)
Function SelectCurrentFootprint Selects the current footprint name and display it.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:135
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
Definition: draw_frame.cpp:686
int SetLibItemName(const UTF8 &aLibItemName, bool aTestForRev=true)
Function SetLibItemName.
Definition: lib_id.cpp:232
Class COMMON_TOOLS.
Definition: common_tools.h:38
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:92
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:511
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 GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Function GeneralControlKeyMovement Handle the common part of GeneralControl dedicated to global curso...
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:166
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:243
Class EDA_BASE_FRAME is the base frame for deriving all KiCad main window classes.
Definition: wxstruct.h:112
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:254
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Function GetGalCanvas returns a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:803
void DrawBackGround(wxDC *DC)
Function DrawBackGround.
Definition: draw_panel.cpp:666
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:822
#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.
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:69
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:257
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:138
#define PREVIOUS_PART
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:745
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void Remove(BOARD_ITEM *aBoardItem) override
>
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[]