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 
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( TO_UTF8( 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 
542  fpid.SetLibItemName( TO_UTF8( fp_name ) );
543 
544  DismissModal( true, FROM_UTF8( 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 }
559 
560 
561 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
562 {
564 }
565 
566 
568 {
570 }
571 
572 
573 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
574 {
576 }
577 
578 
580 {
582 }
583 
584 
585 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
586 {
588 }
589 
590 
591 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
592 {
594 
595  // Ensure we do not have old selection:
596  if( !event.GetActive() )
597  return;
598 
599  // Ensure we have the right library list:
600  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
601 
602  if( libNicknames.size() == m_libList->GetCount() )
603  {
604  unsigned ii;
605 
606  for( ii = 0; ii < libNicknames.size(); ii++ )
607  {
608  if( libNicknames[ii] != m_libList->GetString( ii ) )
609  break;
610  }
611 
612  if( ii == libNicknames.size() )
613  return;
614  }
615 
616  // If we are here, the library list has changed, rebuild it
618  UpdateTitle();
619 }
620 
621 
622 bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
623 {
624  bool eventHandled = true;
625 
626  // Filter out the 'fake' mouse motion after a keyboard movement
627  if( !aHotKey && m_movingCursorWithKeyboard )
628  {
630  return false;
631  }
632 
633  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
634  cmd.SetEventObject( this );
635 
636  wxPoint oldpos = GetCrossHairPosition();
637  wxPoint pos = aPosition;
638  GeneralControlKeyMovement( aHotKey, &pos, true );
639 
640  if( aHotKey )
641  {
642  eventHandled = OnHotKey( aDC, aHotKey, aPosition );
643  }
644 
645  SetCrossHairPosition( pos );
646  RefreshCrossHair( oldpos, aPosition, aDC );
647 
648  UpdateStatusBar(); // Display new cursor coordinates
649 
650  return eventHandled;
651 }
652 
653 
654 void FOOTPRINT_VIEWER_FRAME::Show3D_Frame( wxCommandEvent& event )
655 {
656  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
657 
658  if( draw3DFrame )
659  {
660  // Raising the window does not show the window on Windows if iconized.
661  // This should work on any platform.
662  if( draw3DFrame->IsIconized() )
663  draw3DFrame->Iconize( false );
664 
665  draw3DFrame->Raise();
666 
667  // Raising the window does not set the focus on Linux. This should work on any platform.
668  if( wxWindow::FindFocus() != draw3DFrame )
669  draw3DFrame->SetFocus();
670 
671  return;
672  }
673 
674  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, wxEmptyString );
675  Update3D_Frame( false );
676  draw3DFrame->Raise(); // Needed with some Window Managers
677  draw3DFrame->Show( true );
678 }
679 
680 
681 void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
682 {
683  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
684 
685  if( draw3DFrame == NULL )
686  return;
687 
688  wxString title = wxString::Format(
689  _( "3D Viewer" ) + L" \u2014 %s",
691 
692  draw3DFrame->SetTitle( title );
693 
694  if( aForceReloadFootprint )
695  {
696  // Force 3D screen refresh immediately
697  draw3DFrame->NewDisplay( true );
698  }
699 }
700 
701 
703 {
705 }
706 
707 
709 {
710  switch( event.GetId() )
711  {
712  case ID_MODVIEW_NEXT:
714  break;
715 
716  case ID_MODVIEW_PREVIOUS:
718  break;
719 
720  default:
721  wxString id = wxString::Format( "%i", event.GetId() );
722  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
723  }
724 }
725 
726 
727 void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
728 {
729 }
730 
731 
732 bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
733 {
734  return true;
735 }
736 
737 
739 {
740  wxString title;
741  wxString path;
742 
743  title.Printf( _( "Library Browser" ) + L" \u2014 %s",
744  getCurNickname().size()
745  ? getCurNickname()
746  : _( "no library selected" ) );
747 
748  // Now, add the full path, for info
749  if( getCurNickname().size() )
750  {
751  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
752  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
753 
754  if( row )
755  title << L" \u2014 " << row->GetFullURI( true );
756  }
757 
758  SetTitle( title );
759 }
760 
761 
762 void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
763 {
764  wxString selection = SelectLibrary( getCurNickname() );
765 
766  if( !!selection && selection != getCurNickname() )
767  {
768  setCurNickname( selection );
769 
770  UpdateTitle();
772 
773  int id = m_libList->FindString( getCurNickname() );
774 
775  if( id >= 0 )
776  m_libList->SetSelection( id );
777  }
778 }
779 
780 
782 {
783  wxString curr_nickname = getCurNickname();
784  MODULE* oldmodule = GetBoard()->m_Modules;
785  MODULE* module = LoadModuleFromLibrary( curr_nickname, Prj().PcbFootprintLibs(), false );
786 
787  if( module )
788  {
789  module->SetPosition( wxPoint( 0, 0 ) );
790 
791  // Only one footprint allowed: remove the previous footprint (if exists)
792  if( oldmodule )
793  {
794  GetBoard()->Remove( oldmodule );
795  delete oldmodule;
796  }
797 
799 
800  wxString nickname = FROM_UTF8( module->GetFPID().GetLibNickname() );
801 
802  if( !getCurNickname() && nickname.size() )
803  {
804  // Set the listbox
805  int index = m_libList->FindString( nickname );
806  if( index != wxNOT_FOUND )
807  m_libList->SetSelection( index, true );
808 
809  setCurNickname( nickname );
810  }
811 
812  module->ClearFlags();
813  SetCurItem( NULL );
814 
815  Zoom_Automatique( false );
816  m_canvas->Refresh();
817  Update3D_Frame();
818  m_footprintList->SetStringSelection( getCurFootprintName() );
819  }
820 }
821 
822 
824 {
825  if( !getCurNickname() )
826  return;
827 
828  int selection = m_footprintList->FindString( getCurFootprintName() );
829 
830  if( aMode == NEXT_PART )
831  {
832  if( selection != wxNOT_FOUND && selection < (int)m_footprintList->GetCount()-1 )
833  selection++;
834  }
835 
836  if( aMode == PREVIOUS_PART )
837  {
838  if( selection != wxNOT_FOUND && selection > 0 )
839  selection--;
840  }
841 
842  if( selection != wxNOT_FOUND )
843  {
844  m_footprintList->SetSelection( selection );
845  setCurFootprintName( m_footprintList->GetString( selection ) );
846  SetCurItem( NULL );
847 
848  // Delete the current footprint
850 
851  MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad(
853 
854  if( footprint )
855  GetBoard()->Add( footprint, ADD_APPEND );
856 
857  Update3D_Frame();
858 
859  if( IsGalCanvasActive() )
860  updateView();
861  }
862 
863 
864  UpdateTitle();
865  Zoom_Automatique( false );
866  m_canvas->Refresh();
867 }
868 
869 
870 void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
871 {
872  if( !GetBoard() )
873  return;
874 
875  m_canvas->DrawBackGround( DC );
876  GetBoard()->Draw( m_canvas, DC, GR_COPY );
877 
878  MODULE* module = GetBoard()->m_Modules;
879 
880  m_canvas->DrawCrossHair( DC );
881 
882  ClearMsgPanel();
883 
884  if( module )
885  SetMsgPanel( module );
886 }
887 
888 
890 {
891  if( IsGalCanvasActive() )
892  {
893  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() );
896  }
897 }
898 
899 
900 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
901 {
902  Close();
903 }
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:838
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:140
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:735
Specialization of the wxAuiPaneInfo class for KiCad panels.
Definition: wxstruct.h:466
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:164
#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:773
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
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:533
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:809
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:540
void SelectCurrentFootprint(wxCommandEvent &event)
Function SelectCurrentFootprint Selects the current footprint name and display it.
wxAuiToolBar * m_mainToolBar
Standard horizontal Toolbar.
Definition: wxstruct.h:136
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
Definition: draw_frame.cpp:705
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:512
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: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:113
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:817
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:764
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[]