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  // Toolbar events
84  FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary )
86  FOOTPRINT_VIEWER_FRAME::SelectCurrentFootprint )
88  FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
90  FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList )
92  FOOTPRINT_VIEWER_FRAME::ExportSelectedFootprint )
94 
95  // listbox events
96  EVT_LISTBOX( ID_MODVIEW_LIB_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnLibList )
97  EVT_LISTBOX( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList )
98  EVT_LISTBOX_DCLICK( ID_MODVIEW_FOOTPRINT_LIST, FOOTPRINT_VIEWER_FRAME::DClickOnFootprintList )
99 
100 END_EVENT_TABLE()
101 
102 
103 /* Note:
104  * FOOTPRINT_VIEWER_FRAME can be created in "modal mode", or as a usual frame.
105  * In modal mode:
106  * a tool to export the selected footprint is shown in the toolbar
107  * the style is wxFRAME_FLOAT_ON_PARENT
108  * Note:
109  * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed
110  * its parent frame is sometimes brought to the foreground when closing the
111  * LIB_VIEW_FRAME frame.
112  * If it still happens, it could be better to use wxSTAY_ON_TOP
113  * instead of wxFRAME_FLOAT_ON_PARENT
114  */
115 #ifdef __WINDOWS__
116 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT // could be wxSTAY_ON_TOP if issues
117 #else
118 #define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT
119 #endif
120 
121 #define FOOTPRINT_VIEWER_FRAME_NAME "ModViewFrame"
122 #define FOOTPRINT_VIEWER_FRAME_NAME_MODAL "ModViewFrameModal"
123 
124 
125 FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType ) :
126  PCB_BASE_FRAME( aKiway, aParent, aFrameType, _( "Footprint Library Browser" ),
127  wxDefaultPosition, wxDefaultSize,
128  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
129  aParent ?
131  : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP
133  aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ?
136 {
137  wxASSERT( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL ||
138  aFrameType == FRAME_PCB_MODULE_VIEWER );
139 
140  if( aFrameType == FRAME_PCB_MODULE_VIEWER_MODAL )
141  SetModal( true );
142 
143  // Force the frame name used in config. the footprint viewer frame has a name
144  // depending on aFrameType (needed to identify the frame by wxWidgets),
145  // but only one configuration is preferable.
146  m_configFrameName = FOOTPRINT_VIEWER_FRAME_NAME;
147 
148  m_showAxis = true; // true to draw axis.
149 
150  // Give an icon
151  wxIcon icon;
152  icon.CopyFromBitmap( KiBitmap( modview_icon_xpm ) );
153  SetIcon( icon );
154 
155  m_hotkeysDescrList = g_Module_Viewer_Hokeys_Descr;
156 
157  m_libList = new wxListBox( this, ID_MODVIEW_LIB_LIST,
158  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
159 
160  m_footprintList = new wxListBox( this, ID_MODVIEW_FOOTPRINT_LIST,
161  wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_HSCROLL );
162 
163  SetBoard( new BOARD() );
164  // In viewer, the default net clearance is not known (it depends on the actual board).
165  // So we do not show the default clearance, by setting it to 0
166  // The footprint or pad specific clearance will be shown
167  GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0);
168 
169  // Ensure all layers and items are visible:
171  SetScreen( new PCB_SCREEN( GetPageSizeIU() ) );
172 
173  GetScreen()->m_Center = true; // Center coordinate origins on screen.
174  LoadSettings( config() );
175 
176  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
177 
178  GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
179 
180  // Menu bar is not mandatory: uncomment/comment the next line
181  // to add/remove the menubar
182  ReCreateMenuBar();
183  ReCreateHToolbar();
184  ReCreateVToolbar();
185 
186  ReCreateLibraryList();
187  UpdateTitle();
188 
189  PCB_BASE_FRAME* parentFrame = static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, true ) );
190 
191  // Create GAL canvas
192  PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
193  parentFrame->GetGalDisplayOptions(),
194  parentFrame->GetGalCanvas()->GetBackend() );
195  SetGalCanvas( drawPanel );
196 
197  // Create the manager and dispatcher & route draw panel events to the dispatcher
198  m_toolManager = new TOOL_MANAGER;
199  m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
200  drawPanel->GetViewControls(), this );
201  m_actions = new PCB_ACTIONS();
202  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
203  drawPanel->SetEventDispatcher( m_toolDispatcher );
204 
205  m_toolManager->RegisterTool( new PCBNEW_CONTROL );
206  m_toolManager->RegisterTool( new COMMON_TOOLS );
207  m_toolManager->InitTools();
208 
209  // If a footprint was previously loaded, reload it
210  if( getCurNickname().size() && getCurFootprintName().size() )
211  {
212  LIB_ID id;
213 
214  id.SetLibNickname( TO_UTF8( getCurNickname() ) );
215  id.SetLibItemName( TO_UTF8( getCurFootprintName() ) );
216  GetBoard()->Add( loadFootprint( id ) );
217  }
218 
219  drawPanel->DisplayBoard( m_Pcb );
220  updateView();
221 
222  m_auimgr.SetManagedWindow( this );
223 
224  wxSize minsize(100,-1); // Min size of list boxes
225 
226  // Main toolbar is initially docked at the top of the main window and dockable on any side.
227  // The close button is disable because the footprint viewer has no main menu to re-enable it.
228  // The tool bar will only be dockable on the top or bottom of the main frame window. This is
229  // most likely due to the fact that the other windows are not dockable and are preventing the
230  // tool bar from docking on the right and left.
231  wxAuiPaneInfo toolbarPaneInfo;
232  toolbarPaneInfo.Name( "m_mainToolBar" ).ToolbarPane().Top().CloseButton( false );
233 
234  EDA_PANEINFO info;
235  info.InfoToolbarPane();
236 
237  EDA_PANEINFO mesg;
238  mesg.MessageToolbarPane();
239 
240  // Manage main toolbar, top pane
241  m_auimgr.AddPane( m_mainToolBar, toolbarPaneInfo );
242 
243  // Manage the list of libraries, left pane.
244  m_auimgr.AddPane( m_libList,
245  wxAuiPaneInfo( info ).Name( "m_libList" )
246  .Left().Row( 1 ).MinSize( minsize ) );
247 
248  // Manage the list of footprints, center pane.
249  m_auimgr.AddPane( m_footprintList,
250  wxAuiPaneInfo( info ).Name( "m_footprintList" )
251  .Left().Row( 2 ).MinSize( minsize ) );
252 
253  // Manage the draw panel, right pane.
254  m_auimgr.AddPane( m_canvas,
255  wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
256  m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
257  wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() );
258 
259  // Manage the message panel, bottom pane.
260  m_auimgr.AddPane( m_messagePanel,
261  wxAuiPaneInfo( mesg ).Name( "MsgPanel" ).Bottom() );
262 
263  if( !m_perspective.IsEmpty() )
264  {
265  // Restore last saved sizes, pos and other params
266  // However m_mainToolBar size cannot be set to its last saved size
267  // because the actual size change depending on the way modview was called:
268  // the tool to export the current footprint exist or not.
269  // and the saved size is not always OK
270  // the trick is to get the default toolbar size, and set the size after
271  // calling LoadPerspective
272  wxSize tbsize = m_mainToolBar->GetSize();
273  m_auimgr.LoadPerspective( m_perspective, false );
274  m_auimgr.GetPane( m_mainToolBar ).BestSize( tbsize );
275  }
276 
277  // after changing something to the aui manager,
278  // call Update()() to reflect the changes
279  m_auimgr.Update();
280 
281  // Now Drawpanel is sized, we can use BestZoom to show the component (if any)
282 #ifdef USE_WX_GRAPHICS_CONTEXT
283  GetScreen()->SetZoom( BestZoom() );
284 #else
285  Zoom_Automatique( false );
286 #endif
287 
288  UseGalCanvas( parentFrame->IsGalCanvasActive() );
289 
290  if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
291  {
292  Raise(); // On some window managers, this is needed
293  Show( true );
294  }
295 }
296 
297 
299 {
300  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
301 
302  if( draw3DFrame )
303  draw3DFrame->Destroy();
304 }
305 
306 
307 
308 void FOOTPRINT_VIEWER_FRAME::OnCloseWindow( wxCloseEvent& Event )
309 {
310  DBG(printf( "%s:\n", __func__ );)
311 
312  // A workaround to avoid flicker, in modal mode when modview frame is destroyed,
313  // when the aui toolbar is not docked (i.e. shown in a miniframe)
314  // (usefull on windows only)
315  m_mainToolBar->SetFocus();
316 
317  if( IsGalCanvasActive() )
319 
320  if( IsModal() )
321  {
322  // Only dismiss a modal frame once, so that the return values set by
323  // the prior DismissModal() are not bashed for ShowModal().
324  if( !IsDismissed() )
325  DismissModal( false );
326 
327  // window to be destroyed by the caller of KIWAY_PLAYER::ShowModal()
328  }
329  else
330  Destroy();
331 }
332 
333 
334 void FOOTPRINT_VIEWER_FRAME::OnSize( wxSizeEvent& SizeEv )
335 {
336  if( m_auimgr.GetManagedWindow() )
337  m_auimgr.Update();
338 
339  SizeEv.Skip();
340 }
341 
342 
343 void FOOTPRINT_VIEWER_FRAME::OnSetRelativeOffset( wxCommandEvent& event )
344 {
346  UpdateStatusBar();
347 }
348 
349 
351 {
352  m_libList->Clear();
353 
354  std::vector< wxString > nicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
355 
356  for( unsigned ii = 0; ii < nicknames.size(); ii++ )
357  m_libList->Append( nicknames[ii] );
358 
359  // Search for a previous selection:
360  int index = m_libList->FindString( getCurNickname() );
361 
362  if( index != wxNOT_FOUND )
363  {
364  m_libList->SetSelection( index, true );
365  }
366  else
367  {
368  // If not found, clear current library selection because it can be
369  // deleted after a configuration change.
370  setCurNickname( wxEmptyString );
371  setCurFootprintName( wxEmptyString );
372  }
373 
376 
377  m_canvas->Refresh();
378 }
379 
380 
382 {
383  m_footprintList->Clear();
384 
385  if( !getCurNickname() )
386  {
387  setCurFootprintName( wxEmptyString );
388  return;
389  }
390 
391  auto fp_info_list( FOOTPRINT_LIST::GetInstance( Kiway() ) );
392 
393  wxString nickname = getCurNickname();
394 
395  fp_info_list->ReadFootprintFiles( Prj().PcbFootprintLibs(), !nickname ? NULL : &nickname );
396 
397  if( fp_info_list->GetErrorCount() )
398  {
399  fp_info_list->DisplayErrors( this );
400  return;
401  }
402 
403  for( auto& footprint : fp_info_list->GetList() )
404  {
405  m_footprintList->Append( footprint->GetFootprintName() );
406  }
407 
408  int index = m_footprintList->FindString( getCurFootprintName() );
409 
410  if( index == wxNOT_FOUND )
411  setCurFootprintName( wxEmptyString );
412  else
413  m_footprintList->SetSelection( index, true );
414 }
415 
416 
417 void FOOTPRINT_VIEWER_FRAME::ClickOnLibList( wxCommandEvent& event )
418 {
419  int ii = m_libList->GetSelection();
420 
421  if( ii < 0 )
422  return;
423 
424  wxString name = m_libList->GetString( ii );
425 
426  if( getCurNickname() == name )
427  return;
428 
429  setCurNickname( name );
430 
432  UpdateTitle();
434 }
435 
436 
437 void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
438 {
439  if( m_footprintList->GetCount() == 0 )
440  return;
441 
442  int ii = m_footprintList->GetSelection();
443 
444  if( ii < 0 )
445  return;
446 
447  wxString name = m_footprintList->GetString( ii );
448 
449  if( getCurFootprintName().CmpNoCase( name ) != 0 )
450  {
451  setCurFootprintName( name );
452 
453  SetCurItem( NULL );
454 
455  // Delete the current footprint
457 
458  LIB_ID id;
460  id.SetLibItemName( TO_UTF8( getCurFootprintName() ) );
461 
462  try
463  {
464  GetBoard()->Add( loadFootprint( id ) );
465  }
466  catch( const IO_ERROR& ioe )
467  {
468  wxString msg = wxString::Format(
469  _( "Could not load footprint \"%s\" from library \"%s\".\n\nError %s." ),
472  GetChars( ioe.What() ) );
473 
474  DisplayError( this, msg );
475  }
476 
477  UpdateTitle();
478 
479  if( IsGalCanvasActive() )
480  updateView();
481 
482  Zoom_Automatique( false );
483  m_canvas->Refresh();
484  Update3D_Frame();
485  }
486 }
487 
488 
490 {
491  if( IsModal() )
492  {
493  // @todo(DICK)
494  ExportSelectedFootprint( event );
495 
496  // Prevent the double click from being as a single mouse button release
497  // event in the parent window which would cause the part to be parked
498  // rather than staying in move mode.
499  // Remember the mouse button will be released in the parent window
500  // thus creating a mouse button release event which should be ignored
501  PCB_EDIT_FRAME* pcbframe = dynamic_cast<PCB_EDIT_FRAME*>( GetParent() );
502 
503  // The parent may not be the board editor:
504  if( pcbframe )
505  {
506  pcbframe->SkipNextLeftButtonReleaseEvent();
507  }
508  }
509 }
510 
511 
513 {
514  int ii = m_footprintList->GetSelection();
515 
516  if( ii >= 0 )
517  {
518  wxString fp_name = m_footprintList->GetString( ii );
519 
520  LIB_ID fpid;
521 
523  fpid.SetLibItemName( TO_UTF8( fp_name ) );
524 
525  DismissModal( true, FROM_UTF8( fpid.Format() ) );
526  }
527  else
528  {
529  DismissModal( false );
530  }
531 
532  Close( true );
533 }
534 
535 
536 void FOOTPRINT_VIEWER_FRAME::LoadSettings( wxConfigBase* aCfg )
537 {
539 }
540 
541 
542 void FOOTPRINT_VIEWER_FRAME::SaveSettings( wxConfigBase* aCfg )
543 {
545 }
546 
547 
549 {
551 }
552 
553 
554 void FOOTPRINT_VIEWER_FRAME::setCurNickname( const wxString& aNickname )
555 {
557 }
558 
559 
561 {
563 }
564 
565 
566 void FOOTPRINT_VIEWER_FRAME::setCurFootprintName( const wxString& aName )
567 {
569 }
570 
571 
572 void FOOTPRINT_VIEWER_FRAME::OnActivate( wxActivateEvent& event )
573 {
575 
576  // Ensure we do not have old selection:
577  if( !event.GetActive() )
578  return;
579 
580  // Ensure we have the right library list:
581  std::vector< wxString > libNicknames = Prj().PcbFootprintLibs()->GetLogicalLibs();
582 
583  if( libNicknames.size() == m_libList->GetCount() )
584  {
585  unsigned ii;
586 
587  for( ii = 0; ii < libNicknames.size(); ii++ )
588  {
589  if( libNicknames[ii] != m_libList->GetString( ii ) )
590  break;
591  }
592 
593  if( ii == libNicknames.size() )
594  return;
595  }
596 
597  // If we are here, the library list has changed, rebuild it
599  UpdateTitle();
600 }
601 
602 
603 bool FOOTPRINT_VIEWER_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
604 {
605  bool eventHandled = true;
606 
607  // Filter out the 'fake' mouse motion after a keyboard movement
608  if( !aHotKey && m_movingCursorWithKeyboard )
609  {
611  return false;
612  }
613 
614  wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
615  cmd.SetEventObject( this );
616 
617  wxPoint oldpos = GetCrossHairPosition();
618  wxPoint pos = aPosition;
619  GeneralControlKeyMovement( aHotKey, &pos, true );
620 
621  if( aHotKey )
622  {
623  eventHandled = OnHotKey( aDC, aHotKey, aPosition );
624  }
625 
626  SetCrossHairPosition( pos );
627  RefreshCrossHair( oldpos, aPosition, aDC );
628 
629  UpdateStatusBar(); // Display new cursor coordinates
630 
631  return eventHandled;
632 }
633 
634 
635 void FOOTPRINT_VIEWER_FRAME::Show3D_Frame( wxCommandEvent& event )
636 {
637  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
638 
639  if( draw3DFrame )
640  {
641  // Raising the window does not show the window on Windows if iconized.
642  // This should work on any platform.
643  if( draw3DFrame->IsIconized() )
644  draw3DFrame->Iconize( false );
645 
646  draw3DFrame->Raise();
647 
648  // Raising the window does not set the focus on Linux. This should work on any platform.
649  if( wxWindow::FindFocus() != draw3DFrame )
650  draw3DFrame->SetFocus();
651 
652  return;
653  }
654 
655  draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, wxEmptyString );
656  Update3D_Frame( false );
657  draw3DFrame->Raise(); // Needed with some Window Managers
658  draw3DFrame->Show( true );
659 }
660 
661 
662 void FOOTPRINT_VIEWER_FRAME::Update3D_Frame( bool aForceReloadFootprint )
663 {
664  EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
665 
666  if( draw3DFrame == NULL )
667  return;
668 
669  wxString title = wxString::Format(
670  _( "3D Viewer" ) + L" \u2014 %s",
672 
673  draw3DFrame->SetTitle( title );
674 
675  if( aForceReloadFootprint )
676  {
677  draw3DFrame->ReloadRequest();
678 
679  // Force 3D screen refresh immediately
680  if( GetBoard()->m_Modules )
681  draw3DFrame->NewDisplay();
682  }
683 }
684 
685 
687 {
689 }
690 
691 
693 {
694  switch( event.GetId() )
695  {
696  case ID_MODVIEW_NEXT:
698  break;
699 
700  case ID_MODVIEW_PREVIOUS:
702  break;
703 
704  default:
705  wxString id = wxString::Format( "%i", event.GetId() );
706  wxFAIL_MSG( "FOOTPRINT_VIEWER_FRAME::OnIterateFootprintList error: id = " + id );
707  }
708 }
709 
710 
711 void FOOTPRINT_VIEWER_FRAME::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
712 {
713 }
714 
715 
716 bool FOOTPRINT_VIEWER_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
717 {
718  return true;
719 }
720 
721 
723 {
724  wxString title;
725  wxString path;
726 
727  title.Printf( _( "Library Browser" ) + L" \u2014 %s",
728  getCurNickname().size()
729  ? getCurNickname()
730  : _( "no library selected" ) );
731 
732  // Now, add the full path, for info
733  if( getCurNickname().size() )
734  {
735  FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
736  const LIB_TABLE_ROW* row = libtable->FindRow( getCurNickname() );
737 
738  if( row )
739  title << L" \u2014 " << row->GetFullURI( true );
740  }
741 
742  SetTitle( title );
743 }
744 
745 
746 void FOOTPRINT_VIEWER_FRAME::SelectCurrentLibrary( wxCommandEvent& event )
747 {
748  wxString selection = SelectLibrary( getCurNickname() );
749 
750  if( !!selection && selection != getCurNickname() )
751  {
752  setCurNickname( selection );
753 
754  UpdateTitle();
756 
757  int id = m_libList->FindString( getCurNickname() );
758 
759  if( id >= 0 )
760  m_libList->SetSelection( id );
761  }
762 }
763 
764 
766 {
767  wxString curr_nickname = getCurNickname();
768  MODULE* oldmodule = GetBoard()->m_Modules;
769  MODULE* module = LoadModuleFromLibrary( curr_nickname, Prj().PcbFootprintLibs(), false );
770 
771  if( module )
772  {
773  module->SetPosition( wxPoint( 0, 0 ) );
774 
775  // Only one footprint allowed: remove the previous footprint (if exists)
776  if( oldmodule )
777  {
778  GetBoard()->Remove( oldmodule );
779  delete oldmodule;
780  }
781 
783 
784  wxString nickname = FROM_UTF8( module->GetFPID().GetLibNickname() );
785 
786  if( !getCurNickname() && nickname.size() )
787  {
788  // Set the listbox
789  int index = m_libList->FindString( nickname );
790  if( index != wxNOT_FOUND )
791  m_libList->SetSelection( index, true );
792 
793  setCurNickname( nickname );
794  }
795 
796  module->ClearFlags();
797  SetCurItem( NULL );
798 
799  Zoom_Automatique( false );
800  m_canvas->Refresh();
801  Update3D_Frame();
802  m_footprintList->SetStringSelection( getCurFootprintName() );
803  }
804 }
805 
806 
808 {
809  if( !getCurNickname() )
810  return;
811 
812  int selection = m_footprintList->FindString( getCurFootprintName() );
813 
814  if( aMode == NEXT_PART )
815  {
816  if( selection != wxNOT_FOUND && selection < (int)m_footprintList->GetCount()-1 )
817  selection++;
818  }
819 
820  if( aMode == PREVIOUS_PART )
821  {
822  if( selection != wxNOT_FOUND && selection > 0 )
823  selection--;
824  }
825 
826  if( selection != wxNOT_FOUND )
827  {
828  m_footprintList->SetSelection( selection );
829  setCurFootprintName( m_footprintList->GetString( selection ) );
830  SetCurItem( NULL );
831 
832  // Delete the current footprint
834 
835  MODULE* footprint = Prj().PcbFootprintLibs()->FootprintLoad(
837 
838  if( footprint )
839  GetBoard()->Add( footprint, ADD_APPEND );
840 
841  Update3D_Frame();
842 
843  if( IsGalCanvasActive() )
844  updateView();
845  }
846 
847 
848  UpdateTitle();
849  Zoom_Automatique( false );
850  m_canvas->Refresh();
851 }
852 
853 
854 void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
855 {
856  if( !GetBoard() )
857  return;
858 
859  m_canvas->DrawBackGround( DC );
860  GetBoard()->Draw( m_canvas, DC, GR_COPY );
861 
862  MODULE* module = GetBoard()->m_Modules;
863 
864  m_canvas->DrawCrossHair( DC );
865 
866  ClearMsgPanel();
867 
868  if( module )
869  SetMsgPanel( module );
870 }
871 
872 
874 {
875  if( IsGalCanvasActive() )
876  {
877  static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() );
880  }
881 }
882 
883 
884 void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event )
885 {
886  Close();
887 }
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:713
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:151
#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:751
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.
void NewDisplay(int dummy=0)
Definition: eda_3d_viewer.h:71
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
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
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:818
#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.
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:742
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[]