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.

199 lines
7.5 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-2021 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 <advanced_config.h>
  23. #include <macros.h>
  24. #include <bitmaps.h>
  25. #include <tool/action_toolbar.h>
  26. #include <tool/conditional_menu.h>
  27. #include <tool/tool_manager.h>
  28. #include <tools/pcb_selection_tool.h>
  29. #include <tools/pcb_actions.h>
  30. #include "footprint_viewer_frame.h"
  31. #include "pcbnew_id.h"
  32. #include <widgets/wx_menubar.h>
  33. #include <wx/choice.h>
  34. void FOOTPRINT_VIEWER_FRAME::ReCreateHToolbar()
  35. {
  36. // Note:
  37. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  38. // all wxAuiToolBarItems.
  39. // However the wxAuiToolBarItems are not the owners of controls managed by
  40. // them ( m_zoomSelectBox and m_gridSelectBox ), and therefore do not delete them
  41. // So we do not recreate them after clearing the tools.
  42. if( m_mainToolBar )
  43. {
  44. m_mainToolBar->ClearToolbar();
  45. }
  46. else
  47. {
  48. m_mainToolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
  49. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
  50. wxAUI_TB_HORIZONTAL );
  51. m_mainToolBar->SetAuiManager( &m_auimgr );
  52. }
  53. // Set up toolbar
  54. m_mainToolBar->AddTool( ID_MODVIEW_PREVIOUS, wxEmptyString,
  55. KiScaledBitmap( BITMAPS::lib_previous, this ),
  56. _( "Display previous footprint" ) );
  57. m_mainToolBar->AddTool( ID_MODVIEW_NEXT, wxEmptyString,
  58. KiScaledBitmap( BITMAPS::lib_next, this ),
  59. _( "Display next footprint" ) );
  60. m_mainToolBar->AddScaledSeparator( this );
  61. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  62. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  63. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  64. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  65. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  66. m_mainToolBar->AddScaledSeparator( this );
  67. m_mainToolBar->Add( ACTIONS::show3DViewer );
  68. m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
  69. KiScaledBitmap( BITMAPS::insert_module_board, this ),
  70. _( "Insert footprint in board" ) );
  71. m_mainToolBar->AddScaledSeparator( this );
  72. // Grid selection choice box.
  73. if( m_gridSelectBox == nullptr )
  74. {
  75. m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT, wxDefaultPosition,
  76. wxDefaultSize, 0, nullptr );
  77. }
  78. UpdateGridSelectBox();
  79. m_mainToolBar->AddControl( m_gridSelectBox );
  80. m_mainToolBar->AddScaledSeparator( this );
  81. // Zoom selection choice box.
  82. if( m_zoomSelectBox == nullptr )
  83. {
  84. m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT, wxDefaultPosition,
  85. wxDefaultSize, 0, nullptr );
  86. }
  87. UpdateZoomSelectBox();
  88. m_mainToolBar->AddControl( m_zoomSelectBox );
  89. // Option to run Zoom automatique on footprint selection change
  90. m_mainToolBar->AddTool( ID_FPVIEWER_AUTOZOOM_TOOL, wxEmptyString,
  91. KiScaledBitmap( BITMAPS::zoom_auto_fit_in_page, this ),
  92. _( "Automatic Zoom on footprint change" ),
  93. wxITEM_CHECK );
  94. m_mainToolBar->AddScaledSeparator( this );
  95. // after adding the buttons to the toolbar, must call Realize() to
  96. // reflect the changes
  97. m_mainToolBar->KiRealize();
  98. }
  99. void FOOTPRINT_VIEWER_FRAME::ReCreateOptToolbar()
  100. {
  101. if( m_optionsToolBar )
  102. {
  103. m_optionsToolBar->ClearToolbar();
  104. }
  105. else
  106. {
  107. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
  108. wxDefaultSize,
  109. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  110. m_optionsToolBar->SetAuiManager( &m_auimgr );
  111. }
  112. m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  113. m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  114. m_optionsToolBar->AddScaledSeparator( this );
  115. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  116. m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  117. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  118. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  119. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  120. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  121. m_optionsToolBar->AddScaledSeparator( this );
  122. m_optionsToolBar->Add( PCB_ACTIONS::showPadNumbers, ACTION_TOOLBAR::TOGGLE );
  123. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  124. m_optionsToolBar->Add( PCB_ACTIONS::textOutlines, ACTION_TOOLBAR::TOGGLE );
  125. m_optionsToolBar->Add( PCB_ACTIONS::graphicsOutlines, ACTION_TOOLBAR::TOGGLE );
  126. if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
  127. m_optionsToolBar->Add( ACTIONS::toggleBoundingBoxes, ACTION_TOOLBAR::TOGGLE );
  128. m_optionsToolBar->KiRealize();
  129. }
  130. void FOOTPRINT_VIEWER_FRAME::ReCreateVToolbar()
  131. {
  132. // This toolbar is not currently used
  133. }
  134. void FOOTPRINT_VIEWER_FRAME::doReCreateMenuBar()
  135. {
  136. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  137. // wxWidgets handles the Mac Application menu behind the scenes, but that means
  138. // we always have to start from scratch with a new wxMenuBar.
  139. wxMenuBar* oldMenuBar = GetMenuBar();
  140. WX_MENUBAR* menuBar = new WX_MENUBAR();
  141. //----- File menu -----------------------------------------------------------
  142. //
  143. ACTION_MENU* fileMenu = new ACTION_MENU( false, selTool );
  144. fileMenu->AddClose( _( "Footprint Viewer" ) );
  145. //----- View menu -----------------------------------------------------------
  146. //
  147. ACTION_MENU* viewMenu = new ACTION_MENU( false, selTool );
  148. viewMenu->AppendSeparator();
  149. viewMenu->Add( ACTIONS::zoomInCenter );
  150. viewMenu->Add( ACTIONS::zoomOutCenter );
  151. viewMenu->Add( ACTIONS::zoomFitScreen );
  152. viewMenu->Add( ACTIONS::zoomRedraw );
  153. viewMenu->AppendSeparator();
  154. viewMenu->Add( ACTIONS::show3DViewer );
  155. //----- Menubar -------------------------------------------------------------
  156. //
  157. menuBar->Append( fileMenu, _( "&File" ) );
  158. menuBar->Append( viewMenu, _( "&View" ) );
  159. AddStandardHelpMenu( menuBar );
  160. SetMenuBar( menuBar );
  161. delete oldMenuBar;
  162. }