You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
6.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software: you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation, either version 3 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <macros.h>
  23. #include <bitmaps.h>
  24. #include <tool/action_toolbar.h>
  25. #include <tool/conditional_menu.h>
  26. #include <tool/tool_manager.h>
  27. #include <tools/pcb_selection_tool.h>
  28. #include <tools/pcb_actions.h>
  29. #include "footprint_viewer_frame.h"
  30. #include "pcbnew_id.h"
  31. #include <widgets/wx_menubar.h>
  32. void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
  33. {
  34. // Note:
  35. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  36. // all wxAuiToolBarItems.
  37. // However the wxAuiToolBarItems are not the owners of controls managed by
  38. // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
  39. // So we do not recreate them after clearing the tools.
  40. if( m_mainToolBar )
  41. {
  42. m_mainToolBar->ClearToolbar();
  43. }
  44. else
  45. {
  46. m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  47. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
  48. m_mainToolBar->SetAuiManager( &m_auimgr );
  49. }
  50. // Set up toolbar
  51. m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
  52. KiScaledBitmap( lib_previous_xpm, this ),
  53. _( "Display previous footprint" ) );
  54. m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
  55. KiScaledBitmap( lib_next_xpm, this ),
  56. _( "Display next footprint" ) );
  57. m_mainToolBar->AddScaledSeparator( this );
  58. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  59. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  60. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  61. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  62. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  63. m_mainToolBar->Add( PCB_ACTIONS::zoomFootprintAutomatically, ACTION_TOOLBAR::TOGGLE );
  64. m_mainToolBar->AddScaledSeparator( this );
  65. m_mainToolBar->Add( ACTIONS::show3DViewer );
  66. m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
  67. KiScaledBitmap( export_xpm, this ),
  68. _( "Insert footprint in board" ) );
  69. m_mainToolBar->AddScaledSeparator( this );
  70. // Grid selection choice box.
  71. if( m_gridSelectBox == nullptr )
  72. m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT,
  73. wxDefaultPosition, wxDefaultSize, 0, NULL );
  74. UpdateGridSelectBox();
  75. m_mainToolBar->AddControl( m_gridSelectBox );
  76. m_mainToolBar->AddScaledSeparator( this );
  77. // Zoom selection choice box.
  78. if( m_zoomSelectBox == nullptr )
  79. m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT,
  80. wxDefaultPosition, wxDefaultSize, 0, NULL );
  81. UpdateZoomSelectBox();
  82. m_mainToolBar->AddControl( m_zoomSelectBox );
  83. // after adding the buttons to the toolbar, must call Realize() to
  84. // reflect the changes
  85. m_mainToolBar->KiRealize();
  86. }
  87. void FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar()
  88. {
  89. if( m_optionsToolBar )
  90. {
  91. m_optionsToolBar->ClearToolbar();
  92. }
  93. else
  94. {
  95. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  96. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  97. m_optionsToolBar->SetAuiManager( &m_auimgr );
  98. }
  99. m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  100. m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  101. m_optionsToolBar->AddScaledSeparator( this );
  102. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  103. m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  104. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  105. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  106. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  107. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  108. m_optionsToolBar->AddScaledSeparator( this );
  109. m_optionsToolBar->Add( PCB_ACTIONS::showPadNumbers, ACTION_TOOLBAR::TOGGLE );
  110. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  111. m_optionsToolBar->Add( PCB_ACTIONS::textOutlines, ACTION_TOOLBAR::TOGGLE );
  112. m_optionsToolBar->Add( PCB_ACTIONS::graphicsOutlines, ACTION_TOOLBAR::TOGGLE );
  113. m_optionsToolBar->KiRealize();
  114. }
  115. void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar()
  116. {
  117. // This toolbar is not currently used
  118. }
  119. void FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar()
  120. {
  121. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  122. // wxWidgets handles the Mac Application menu behind the scenes, but that means
  123. // we always have to start from scratch with a new wxMenuBar.
  124. wxMenuBar* oldMenuBar = GetMenuBar();
  125. WX_MENUBAR* menuBar = new WX_MENUBAR();
  126. //----- File menu -----------------------------------------------------------
  127. //
  128. ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
  129. fileMenu->AddClose( _( "Footprint Viewer" ) );
  130. //----- View menu -----------------------------------------------------------
  131. //
  132. ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
  133. viewMenu->AppendSeparator();
  134. viewMenu->Add( ACTIONS::zoomInCenter );
  135. viewMenu->Add( ACTIONS::zoomOutCenter );
  136. viewMenu->Add( ACTIONS::zoomFitScreen );
  137. viewMenu->Add( ACTIONS::zoomRedraw );
  138. viewMenu->AppendSeparator();
  139. viewMenu->Add( ACTIONS::show3DViewer );
  140. //----- Menubar -------------------------------------------------------------
  141. //
  142. menuBar->Append( fileMenu, _( "&File" ) );
  143. menuBar->Append( viewMenu, _( "&View" ) );
  144. AddStandardHelpMenu( menuBar );
  145. SetMenuBar( menuBar );
  146. delete oldMenuBar;
  147. }