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.

276 lines
11 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 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-2022 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 <tool/actions.h>
  23. #include <footprint_edit_frame.h>
  24. #include <pcbnew_id.h>
  25. #include <bitmaps.h>
  26. #include <tool/action_toolbar.h>
  27. #include <tool/tool_manager.h>
  28. #include <tools/pcb_actions.h>
  29. #include <tools/pcb_selection_tool.h>
  30. #include <pcb_layer_box_selector.h>
  31. #include <wx/choice.h>
  32. #include <wx/wupdlock.h>
  33. #include <advanced_config.h>
  34. void FOOTPRINT_EDIT_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, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  49. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT |
  50. wxAUI_TB_HORIZONTAL );
  51. m_mainToolBar->SetAuiManager( &m_auimgr );
  52. }
  53. wxString msg;
  54. // Set up toolbar
  55. m_mainToolBar->Add( PCB_ACTIONS::newFootprint );
  56. m_mainToolBar->Add( PCB_ACTIONS::createFootprint );
  57. m_mainToolBar->Add( ACTIONS::save );
  58. m_mainToolBar->AddScaledSeparator( this );
  59. m_mainToolBar->Add( ACTIONS::print );
  60. m_mainToolBar->AddScaledSeparator( this );
  61. m_mainToolBar->Add( ACTIONS::undo );
  62. m_mainToolBar->Add( ACTIONS::redo );
  63. m_mainToolBar->AddScaledSeparator( this );
  64. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  65. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  66. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  67. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  68. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  69. m_mainToolBar->AddScaledSeparator( this );
  70. m_mainToolBar->Add( PCB_ACTIONS::rotateCcw );
  71. m_mainToolBar->Add( PCB_ACTIONS::rotateCw );
  72. m_mainToolBar->Add( PCB_ACTIONS::mirror );
  73. m_mainToolBar->Add( PCB_ACTIONS::group );
  74. m_mainToolBar->Add( PCB_ACTIONS::ungroup );
  75. m_mainToolBar->AddScaledSeparator( this );
  76. m_mainToolBar->Add( PCB_ACTIONS::footprintProperties );
  77. m_mainToolBar->Add( PCB_ACTIONS::defaultPadProperties );
  78. m_mainToolBar->Add( PCB_ACTIONS::checkFootprint );
  79. m_mainToolBar->AddScaledSeparator( this );
  80. m_mainToolBar->AddTool( ID_LOAD_FOOTPRINT_FROM_BOARD, wxEmptyString,
  81. KiScaledBitmap( BITMAPS::import_brd_file, this ),
  82. _( "Load footprint from current board" ) );
  83. m_mainToolBar->AddTool( ID_ADD_FOOTPRINT_TO_BOARD, wxEmptyString,
  84. KiScaledBitmap( BITMAPS::insert_module_board, this ),
  85. _( "Insert footprint into current board" ) );
  86. m_mainToolBar->AddScaledSeparator( this );
  87. // Grid selection choice box.
  88. if( m_gridSelectBox == nullptr )
  89. m_gridSelectBox = new wxChoice( m_mainToolBar, ID_ON_GRID_SELECT,
  90. wxDefaultPosition, wxDefaultSize, 0, nullptr );
  91. UpdateGridSelectBox();
  92. m_mainToolBar->AddControl( m_gridSelectBox );
  93. m_mainToolBar->AddScaledSeparator( this );
  94. // Zoom selection choice box.
  95. if( m_zoomSelectBox == nullptr )
  96. m_zoomSelectBox = new wxChoice( m_mainToolBar, ID_ON_ZOOM_SELECT,
  97. wxDefaultPosition, wxDefaultSize, 0, nullptr );
  98. UpdateZoomSelectBox();
  99. m_mainToolBar->AddControl( m_zoomSelectBox );
  100. m_mainToolBar->AddScaledSeparator( this );
  101. // Layer selection choice box.
  102. if( m_selLayerBox == nullptr )
  103. {
  104. m_selLayerBox = new PCB_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_PCB_SELECT_LAYER );
  105. m_selLayerBox->SetBoardFrame( this );
  106. // Some layers cannot be select (they are shown in the layer manager
  107. // only to set the color and visibility, but not for selection)
  108. // Disable them in layer box
  109. m_selLayerBox->SetNotAllowedLayerSet( LSET::ForbiddenFootprintLayers() );
  110. m_selLayerBox->Resync();
  111. }
  112. ReCreateLayerBox( false );
  113. m_mainToolBar->AddControl( m_selLayerBox );
  114. // Go through and ensure the comboboxes are the correct size, since the strings in the
  115. // box could have changed widths.
  116. m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER );
  117. m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
  118. m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
  119. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  120. m_mainToolBar->KiRealize();
  121. }
  122. void FOOTPRINT_EDIT_FRAME::ReCreateVToolbar()
  123. {
  124. wxWindowUpdateLocker dummy( this );
  125. if( m_drawToolBar )
  126. {
  127. m_drawToolBar->ClearToolbar();
  128. }
  129. else
  130. {
  131. m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  132. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  133. m_drawToolBar->SetAuiManager( &m_auimgr );
  134. }
  135. // Groups contained on this toolbar
  136. static ACTION_GROUP* dimensionGroup = nullptr;
  137. if( !dimensionGroup )
  138. {
  139. dimensionGroup = new ACTION_GROUP( "group.pcbDimensions",
  140. { &PCB_ACTIONS::drawAlignedDimension,
  141. &PCB_ACTIONS::drawOrthogonalDimension,
  142. &PCB_ACTIONS::drawCenterDimension,
  143. &PCB_ACTIONS::drawRadialDimension,
  144. &PCB_ACTIONS::drawLeader } );
  145. }
  146. m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  147. m_drawToolBar->AddScaledSeparator( this );
  148. m_drawToolBar->Add( PCB_ACTIONS::placePad, ACTION_TOOLBAR::TOGGLE );
  149. m_drawToolBar->Add( PCB_ACTIONS::drawRuleArea, ACTION_TOOLBAR::TOGGLE );
  150. m_drawToolBar->AddScaledSeparator( this );
  151. m_drawToolBar->Add( PCB_ACTIONS::drawLine, ACTION_TOOLBAR::TOGGLE );
  152. m_drawToolBar->Add( PCB_ACTIONS::drawArc, ACTION_TOOLBAR::TOGGLE );
  153. m_drawToolBar->Add( PCB_ACTIONS::drawRectangle, ACTION_TOOLBAR::TOGGLE );
  154. m_drawToolBar->Add( PCB_ACTIONS::drawCircle, ACTION_TOOLBAR::TOGGLE );
  155. m_drawToolBar->Add( PCB_ACTIONS::drawPolygon, ACTION_TOOLBAR::TOGGLE );
  156. m_drawToolBar->Add( PCB_ACTIONS::placeText, ACTION_TOOLBAR::TOGGLE );
  157. m_drawToolBar->Add( PCB_ACTIONS::drawTextBox, ACTION_TOOLBAR::TOGGLE );
  158. m_drawToolBar->AddGroup( dimensionGroup, ACTION_TOOLBAR::TOGGLE );
  159. m_drawToolBar->Add( ACTIONS::deleteTool, ACTION_TOOLBAR::TOGGLE );
  160. m_drawToolBar->AddScaledSeparator( this );
  161. m_drawToolBar->Add( PCB_ACTIONS::setAnchor, ACTION_TOOLBAR::TOGGLE );
  162. m_drawToolBar->Add( PCB_ACTIONS::gridSetOrigin, ACTION_TOOLBAR::TOGGLE );
  163. m_drawToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  164. m_drawToolBar->KiRealize();
  165. }
  166. void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar()
  167. {
  168. if( m_optionsToolBar )
  169. {
  170. m_optionsToolBar->ClearToolbar();
  171. }
  172. else
  173. {
  174. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR, wxDefaultPosition,
  175. wxDefaultSize,
  176. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  177. m_optionsToolBar->SetAuiManager( &m_auimgr );
  178. }
  179. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  180. m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  181. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  182. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  183. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  184. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  185. m_optionsToolBar->AddScaledSeparator( this );
  186. m_optionsToolBar->Add( PCB_ACTIONS::toggleHV45Mode, ACTION_TOOLBAR::TOGGLE );
  187. m_optionsToolBar->AddScaledSeparator( this );
  188. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  189. m_optionsToolBar->Add( PCB_ACTIONS::graphicsOutlines, ACTION_TOOLBAR::TOGGLE );
  190. m_optionsToolBar->Add( PCB_ACTIONS::textOutlines, ACTION_TOOLBAR::TOGGLE );
  191. m_optionsToolBar->Add( ACTIONS::highContrastMode, ACTION_TOOLBAR::TOGGLE );
  192. if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
  193. m_optionsToolBar->Add( ACTIONS::toggleBoundingBoxes, ACTION_TOOLBAR::TOGGLE );
  194. m_optionsToolBar->AddScaledSeparator( this );
  195. m_optionsToolBar->Add( PCB_ACTIONS::showFootprintTree, ACTION_TOOLBAR::TOGGLE );
  196. m_optionsToolBar->Add( PCB_ACTIONS::showLayersManager, ACTION_TOOLBAR::TOGGLE );
  197. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  198. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  199. gridMenu->Add( ACTIONS::gridProperties );
  200. m_optionsToolBar->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  201. m_optionsToolBar->KiRealize();
  202. }
  203. void FOOTPRINT_EDIT_FRAME::UpdateToolbarControlSizes()
  204. {
  205. if( m_mainToolBar )
  206. {
  207. // Update the item widths
  208. m_mainToolBar->UpdateControlWidth( ID_TOOLBARH_PCB_SELECT_LAYER );
  209. m_mainToolBar->UpdateControlWidth( ID_ON_ZOOM_SELECT );
  210. m_mainToolBar->UpdateControlWidth( ID_ON_GRID_SELECT );
  211. }
  212. }
  213. void FOOTPRINT_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
  214. {
  215. if( m_selLayerBox == nullptr || m_mainToolBar == nullptr )
  216. return;
  217. m_selLayerBox->SetToolTip( _( "+/- to switch" ) );
  218. m_selLayerBox->Resync();
  219. if( aForceResizeToolbar )
  220. UpdateToolbarControlSizes();
  221. }
  222. void FOOTPRINT_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
  223. {
  224. m_selLayerBox->SetLayerSelection( GetActiveLayer() );
  225. }