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.

237 lines
9.0 KiB

8 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. .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Crosshair modes" ) )
  60. .AddAction( ACTIONS::cursorSmallCrosshairs )
  61. .AddAction( ACTIONS::cursorFullCrosshairs )
  62. .AddAction( ACTIONS::cursor45Crosshairs ) );
  63. config.AppendSeparator()
  64. .AppendAction( SCH_ACTIONS::toggleHiddenPins );
  65. config.AppendSeparator()
  66. .AppendAction( SCH_ACTIONS::lineModeFree )
  67. .AppendAction( SCH_ACTIONS::lineMode90 )
  68. .AppendAction( SCH_ACTIONS::lineMode45 );
  69. config.AppendSeparator()
  70. .AppendAction( SCH_ACTIONS::toggleAnnotateAuto );
  71. config.AppendSeparator()
  72. .AppendAction( SCH_ACTIONS::showHierarchy )
  73. .AppendAction( ACTIONS::showProperties );
  74. if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
  75. config.AppendAction( ACTIONS::toggleBoundingBoxes );
  76. /* TODO (ISM): Handle context menus
  77. EE_SELECTION_TOOL* selTool = m_toolManager->GetTool<EE_SELECTION_TOOL>();
  78. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  79. gridMenu->Add( ACTIONS::gridProperties );
  80. m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  81. */
  82. break;
  83. case TOOLBAR_LOC::RIGHT:
  84. config.AppendAction( ACTIONS::selectionTool )
  85. .AppendAction( SCH_ACTIONS::highlightNetTool );
  86. config.AppendSeparator()
  87. .AppendAction( SCH_ACTIONS::placeSymbol )
  88. .AppendAction( SCH_ACTIONS::placePower )
  89. .AppendAction( SCH_ACTIONS::drawWire )
  90. .AppendAction( SCH_ACTIONS::drawBus )
  91. .AppendAction( SCH_ACTIONS::placeBusWireEntry )
  92. .AppendAction( SCH_ACTIONS::placeNoConnect )
  93. .AppendAction( SCH_ACTIONS::placeJunction )
  94. .AppendAction( SCH_ACTIONS::placeLabel )
  95. .AppendAction( SCH_ACTIONS::placeClassLabel )
  96. .AppendAction( SCH_ACTIONS::drawRuleArea )
  97. .AppendAction( SCH_ACTIONS::placeGlobalLabel )
  98. .AppendAction( SCH_ACTIONS::placeHierLabel )
  99. .AppendAction( SCH_ACTIONS::drawSheet )
  100. .AppendAction( SCH_ACTIONS::placeSheetPin )
  101. .AppendAction( SCH_ACTIONS::syncAllSheetsPins );
  102. config.AppendSeparator()
  103. .AppendAction( SCH_ACTIONS::placeSchematicText )
  104. .AppendAction( SCH_ACTIONS::drawTextBox )
  105. .AppendAction( SCH_ACTIONS::drawTable )
  106. .AppendAction( SCH_ACTIONS::drawRectangle )
  107. .AppendAction( SCH_ACTIONS::drawCircle )
  108. .AppendAction( SCH_ACTIONS::drawArc )
  109. .AppendAction( SCH_ACTIONS::drawBezier )
  110. .AppendAction( SCH_ACTIONS::drawLines )
  111. .AppendAction( SCH_ACTIONS::placeImage )
  112. .AppendAction( ACTIONS::deleteTool );
  113. break;
  114. case TOOLBAR_LOC::TOP_MAIN:
  115. if( Kiface().IsSingle() ) // not when under a project mgr
  116. {
  117. config.AppendAction( ACTIONS::doNew );
  118. config.AppendAction( ACTIONS::open );
  119. }
  120. config.AppendAction( ACTIONS::save );
  121. config.AppendSeparator()
  122. .AppendAction( SCH_ACTIONS::schematicSetup );
  123. config.AppendSeparator()
  124. .AppendAction( ACTIONS::pageSettings )
  125. .AppendAction( ACTIONS::print )
  126. .AppendAction( ACTIONS::plot );
  127. config.AppendSeparator()
  128. .AppendAction( ACTIONS::paste );
  129. config.AppendSeparator()
  130. .AppendAction( ACTIONS::undo )
  131. .AppendAction( ACTIONS::redo );
  132. config.AppendSeparator()
  133. .AppendAction( ACTIONS::find )
  134. .AppendAction( ACTIONS::findAndReplace );
  135. config.AppendSeparator()
  136. .AppendAction( ACTIONS::zoomRedraw )
  137. .AppendAction( ACTIONS::zoomInCenter )
  138. .AppendAction( ACTIONS::zoomOutCenter )
  139. .AppendAction( ACTIONS::zoomFitScreen )
  140. .AppendAction( ACTIONS::zoomFitObjects )
  141. .AppendAction( ACTIONS::zoomTool );
  142. config.AppendSeparator()
  143. .AppendAction( SCH_ACTIONS::navigateBack )
  144. .AppendAction( SCH_ACTIONS::navigateUp )
  145. .AppendAction( SCH_ACTIONS::navigateForward );
  146. config.AppendSeparator()
  147. .AppendAction( SCH_ACTIONS::rotateCCW )
  148. .AppendAction( SCH_ACTIONS::rotateCW )
  149. .AppendAction( SCH_ACTIONS::mirrorV )
  150. .AppendAction( SCH_ACTIONS::mirrorH )
  151. .AppendAction( ACTIONS::group )
  152. .AppendAction( ACTIONS::ungroup );
  153. config.AppendSeparator()
  154. .AppendAction( ACTIONS::showSymbolEditor )
  155. .AppendAction( ACTIONS::showSymbolBrowser )
  156. .AppendAction( ACTIONS::showFootprintEditor );
  157. config.AppendSeparator()
  158. .AppendAction( SCH_ACTIONS::annotate )
  159. .AppendAction( SCH_ACTIONS::runERC )
  160. .AppendAction( SCH_ACTIONS::showSimulator )
  161. .AppendAction( SCH_ACTIONS::assignFootprints )
  162. .AppendAction( SCH_ACTIONS::editSymbolFields )
  163. .AppendAction( SCH_ACTIONS::generateBOM );
  164. config.AppendSeparator()
  165. .AppendAction( SCH_ACTIONS::showPcbNew );
  166. // Insert all the IPC plugins here on the toolbar
  167. // TODO (ISM): Move this to individual actions for each script
  168. config.AppendControl( ACTION_TOOLBAR_CONTROLS::ipcScripting );
  169. break;
  170. }
  171. // clang-format on
  172. return config;
  173. }
  174. void SCH_EDIT_FRAME::configureToolbars()
  175. {
  176. SCH_BASE_FRAME::configureToolbars();
  177. // IPC/Scripting plugin control
  178. // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire
  179. // control
  180. auto pluginControlFactory =
  181. [this]( ACTION_TOOLBAR* aToolbar )
  182. {
  183. // Add scripting console and API plugins
  184. bool scriptingAvailable = SCRIPTING::IsWxAvailable();
  185. #ifdef KICAD_IPC_API
  186. bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server &&
  187. !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty();
  188. #else
  189. bool haveApiPlugins = false;
  190. #endif
  191. if( scriptingAvailable || haveApiPlugins )
  192. {
  193. aToolbar->AddScaledSeparator( aToolbar->GetParent() );
  194. if( haveApiPlugins )
  195. AddApiPluginTools( aToolbar );
  196. }
  197. };
  198. RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory );
  199. }