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.

234 lines
8.7 KiB

9 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  7. * Copyright (C) 2019 CERN
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <advanced_config.h>
  27. #include <api/api_plugin_manager.h>
  28. #include <sch_draw_panel.h>
  29. #include <sch_edit_frame.h>
  30. #include <kiface_base.h>
  31. #include <bitmaps.h>
  32. #include <eeschema_id.h>
  33. #include <pgm_base.h>
  34. #include <python_scripting.h>
  35. #include <tool/tool_manager.h>
  36. #include <tool/action_toolbar.h>
  37. #include <tools/sch_actions.h>
  38. #include <tools/sch_selection_tool.h>
  39. #include <widgets/hierarchy_pane.h>
  40. #include <widgets/wx_aui_utils.h>
  41. #include <widgets/sch_design_block_pane.h>
  42. #include <widgets/sch_properties_panel.h>
  43. #include <widgets/sch_search_pane.h>
  44. #include <toolbars_sch_editor.h>
  45. std::optional<TOOLBAR_CONFIGURATION> SCH_EDIT_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
  46. {
  47. TOOLBAR_CONFIGURATION config;
  48. // clang-format off
  49. switch( aToolbar )
  50. {
  51. case TOOLBAR_LOC::TOP_AUX:
  52. return std::nullopt;
  53. case TOOLBAR_LOC::LEFT:
  54. config.AppendAction( ACTIONS::toggleGrid )
  55. .AppendAction( ACTIONS::toggleGridOverrides )
  56. .AppendAction( ACTIONS::inchesUnits )
  57. .AppendAction( ACTIONS::milsUnits )
  58. .AppendAction( ACTIONS::millimetersUnits )
  59. .AppendAction( ACTIONS::toggleCursorStyle );
  60. config.AppendSeparator()
  61. .AppendAction( SCH_ACTIONS::toggleHiddenPins );
  62. config.AppendSeparator()
  63. .AppendAction( SCH_ACTIONS::lineModeFree )
  64. .AppendAction( SCH_ACTIONS::lineMode90 )
  65. .AppendAction( SCH_ACTIONS::lineMode45 );
  66. config.AppendSeparator()
  67. .AppendAction( SCH_ACTIONS::toggleAnnotateAuto );
  68. config.AppendSeparator()
  69. .AppendAction( SCH_ACTIONS::showHierarchy )
  70. .AppendAction( ACTIONS::showProperties );
  71. if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
  72. config.AppendAction( ACTIONS::toggleBoundingBoxes );
  73. /* TODO (ISM): Handle context menus
  74. EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  75. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  76. gridMenu->Add( ACTIONS::gridProperties );
  77. m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  78. */
  79. break;
  80. case TOOLBAR_LOC::RIGHT:
  81. config.AppendAction( ACTIONS::selectionTool )
  82. .AppendAction( SCH_ACTIONS::highlightNetTool );
  83. config.AppendSeparator()
  84. .AppendAction( SCH_ACTIONS::placeSymbol )
  85. .AppendAction( SCH_ACTIONS::placePower )
  86. .AppendAction( SCH_ACTIONS::drawWire )
  87. .AppendAction( SCH_ACTIONS::drawBus )
  88. .AppendAction( SCH_ACTIONS::placeBusWireEntry )
  89. .AppendAction( SCH_ACTIONS::placeNoConnect )
  90. .AppendAction( SCH_ACTIONS::placeJunction )
  91. .AppendAction( SCH_ACTIONS::placeLabel )
  92. .AppendAction( SCH_ACTIONS::placeClassLabel )
  93. .AppendAction( SCH_ACTIONS::drawRuleArea )
  94. .AppendAction( SCH_ACTIONS::placeGlobalLabel )
  95. .AppendAction( SCH_ACTIONS::placeHierLabel )
  96. .AppendAction( SCH_ACTIONS::drawSheet )
  97. .AppendAction( SCH_ACTIONS::placeSheetPin )
  98. .AppendAction( SCH_ACTIONS::syncAllSheetsPins );
  99. config.AppendSeparator()
  100. .AppendAction( SCH_ACTIONS::placeSchematicText )
  101. .AppendAction( SCH_ACTIONS::drawTextBox )
  102. .AppendAction( SCH_ACTIONS::drawTable )
  103. .AppendAction( SCH_ACTIONS::drawRectangle )
  104. .AppendAction( SCH_ACTIONS::drawCircle )
  105. .AppendAction( SCH_ACTIONS::drawArc )
  106. .AppendAction( SCH_ACTIONS::drawBezier )
  107. .AppendAction( SCH_ACTIONS::drawLines )
  108. .AppendAction( SCH_ACTIONS::placeImage )
  109. .AppendAction( ACTIONS::deleteTool );
  110. break;
  111. case TOOLBAR_LOC::TOP_MAIN:
  112. if( Kiface().IsSingle() ) // not when under a project mgr
  113. {
  114. config.AppendAction( ACTIONS::doNew );
  115. config.AppendAction( ACTIONS::open );
  116. }
  117. config.AppendAction( ACTIONS::save );
  118. config.AppendSeparator()
  119. .AppendAction( SCH_ACTIONS::schematicSetup );
  120. config.AppendSeparator()
  121. .AppendAction( ACTIONS::pageSettings )
  122. .AppendAction( ACTIONS::print )
  123. .AppendAction( ACTIONS::plot );
  124. config.AppendSeparator()
  125. .AppendAction( ACTIONS::paste );
  126. config.AppendSeparator()
  127. .AppendAction( ACTIONS::undo )
  128. .AppendAction( ACTIONS::redo );
  129. config.AppendSeparator()
  130. .AppendAction( ACTIONS::find )
  131. .AppendAction( ACTIONS::findAndReplace );
  132. config.AppendSeparator()
  133. .AppendAction( ACTIONS::zoomRedraw )
  134. .AppendAction( ACTIONS::zoomInCenter )
  135. .AppendAction( ACTIONS::zoomOutCenter )
  136. .AppendAction( ACTIONS::zoomFitScreen )
  137. .AppendAction( ACTIONS::zoomFitObjects )
  138. .AppendAction( ACTIONS::zoomTool );
  139. config.AppendSeparator()
  140. .AppendAction( SCH_ACTIONS::navigateBack )
  141. .AppendAction( SCH_ACTIONS::navigateUp )
  142. .AppendAction( SCH_ACTIONS::navigateForward );
  143. config.AppendSeparator()
  144. .AppendAction( SCH_ACTIONS::rotateCCW )
  145. .AppendAction( SCH_ACTIONS::rotateCW )
  146. .AppendAction( SCH_ACTIONS::mirrorV )
  147. .AppendAction( SCH_ACTIONS::mirrorH )
  148. .AppendAction( ACTIONS::group )
  149. .AppendAction( ACTIONS::ungroup );
  150. config.AppendSeparator()
  151. .AppendAction( ACTIONS::showSymbolEditor )
  152. .AppendAction( ACTIONS::showSymbolBrowser )
  153. .AppendAction( ACTIONS::showFootprintEditor );
  154. config.AppendSeparator()
  155. .AppendAction( SCH_ACTIONS::annotate )
  156. .AppendAction( SCH_ACTIONS::runERC )
  157. .AppendAction( SCH_ACTIONS::showSimulator )
  158. .AppendAction( SCH_ACTIONS::assignFootprints )
  159. .AppendAction( SCH_ACTIONS::editSymbolFields )
  160. .AppendAction( SCH_ACTIONS::generateBOM );
  161. config.AppendSeparator()
  162. .AppendAction( SCH_ACTIONS::showPcbNew );
  163. // Insert all the IPC plugins here on the toolbar
  164. // TODO (ISM): Move this to individual actions for each script
  165. config.AppendControl( ACTION_TOOLBAR_CONTROLS::ipcScripting );
  166. break;
  167. }
  168. // clang-format on
  169. return config;
  170. }
  171. void SCH_EDIT_FRAME::configureToolbars()
  172. {
  173. SCH_BASE_FRAME::configureToolbars();
  174. // IPC/Scripting plugin control
  175. // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire
  176. // control
  177. auto pluginControlFactory =
  178. [this]( ACTION_TOOLBAR* aToolbar )
  179. {
  180. // Add scripting console and API plugins
  181. bool scriptingAvailable = SCRIPTING::IsWxAvailable();
  182. #ifdef KICAD_IPC_API
  183. bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server &&
  184. !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty();
  185. #else
  186. bool haveApiPlugins = false;
  187. #endif
  188. if( scriptingAvailable || haveApiPlugins )
  189. {
  190. aToolbar->AddScaledSeparator( aToolbar->GetParent() );
  191. if( haveApiPlugins )
  192. AddApiPluginTools( aToolbar );
  193. }
  194. };
  195. RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory );
  196. }