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.

771 lines
30 KiB

7 years ago
19 years ago
18 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
12 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
7 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.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
  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 <bitmaps.h>
  27. #include <class_board.h>
  28. #include <confirm.h>
  29. #include <dialog_helpers.h>
  30. #include <fctsys.h>
  31. #include <kiface_i.h>
  32. #include <memory>
  33. #include <pcb_edit_frame.h>
  34. #include <pcb_layer_box_selector.h>
  35. #include <pcbnew.h>
  36. #include <pcbnew_id.h>
  37. #include <pcbnew_settings.h>
  38. #include <pgm_base.h>
  39. #include <router/pns_routing_settings.h>
  40. #include <router/router_tool.h>
  41. #include <settings/color_settings.h>
  42. #include <settings/common_settings.h>
  43. #include <tool/action_toolbar.h>
  44. #include <tool/actions.h>
  45. #include <tool/tool_manager.h>
  46. #include <tools/pcb_actions.h>
  47. #include <tools/selection_tool.h>
  48. #include <view/view.h>
  49. #include <wx/wupdlock.h>
  50. extern bool IsWxPythonLoaded();
  51. #define SEL_LAYER_HELP _( \
  52. "Show active layer selections\nand select layer pair for route and place via" )
  53. /* Data to build the layer pair indicator button */
  54. static std::unique_ptr<wxBitmap> LayerPairBitmap;
  55. #define BM_LAYERICON_SIZE 24
  56. static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE] =
  57. {
  58. // 0 = draw pixel with active layer color
  59. // 1 = draw pixel with top layer color (top/bottom layer used inautoroute and place via)
  60. // 2 = draw pixel with bottom layer color
  61. // 3 = draw pixel with via color
  62. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 },
  63. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 },
  64. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
  65. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
  66. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
  67. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  68. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
  69. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0 },
  70. { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 1, 1, 1, 1, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
  71. { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
  72. { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
  73. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 1, 1, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0 },
  74. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  75. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  76. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  77. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  78. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  79. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  80. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  81. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  82. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  83. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  84. };
  85. void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild )
  86. {
  87. int ii, jj;
  88. COLOR4D active_layer_color, top_color, bottom_color, via_color, background_color;
  89. bool change = aForceRebuild;
  90. int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
  91. if( m_prevIconVal.previous_requested_scale != requested_scale )
  92. {
  93. m_prevIconVal.previous_requested_scale = requested_scale;
  94. change = true;
  95. }
  96. active_layer_color = GetColorSettings()->GetColor( GetActiveLayer() );
  97. if( m_prevIconVal.previous_active_layer_color != active_layer_color )
  98. {
  99. m_prevIconVal.previous_active_layer_color = active_layer_color;
  100. change = true;
  101. }
  102. top_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_TOP );
  103. if( m_prevIconVal.previous_Route_Layer_TOP_color != top_color )
  104. {
  105. m_prevIconVal.previous_Route_Layer_TOP_color = top_color;
  106. change = true;
  107. }
  108. bottom_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_BOTTOM );
  109. if( m_prevIconVal.previous_Route_Layer_BOTTOM_color != bottom_color )
  110. {
  111. m_prevIconVal.previous_Route_Layer_BOTTOM_color = bottom_color;
  112. change = true;
  113. }
  114. int via_type = static_cast<int>( GetDesignSettings().m_CurrentViaType );
  115. via_color = GetColorSettings()->GetColor( LAYER_VIAS + via_type );
  116. if( m_prevIconVal.previous_via_color != via_color )
  117. {
  118. m_prevIconVal.previous_via_color = via_color;
  119. change = true;
  120. }
  121. background_color = GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
  122. if( m_prevIconVal.previous_background_color != background_color )
  123. {
  124. m_prevIconVal.previous_background_color = background_color;
  125. change = true;
  126. }
  127. if( change || !LayerPairBitmap )
  128. {
  129. LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
  130. // Draw the icon, with colors according to the active layer and layer pairs for via
  131. // command (change layer)
  132. wxMemoryDC iconDC;
  133. iconDC.SelectObject( *LayerPairBitmap );
  134. wxBrush brush;
  135. wxPen pen;
  136. int buttonColor = -1;
  137. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  138. brush.SetColour( background_color.WithAlpha(1.0).ToColour() );
  139. iconDC.SetBrush( brush );
  140. iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
  141. for( ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
  142. {
  143. for( jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
  144. {
  145. if( s_BitmapLayerIcon[ii][jj] != buttonColor )
  146. {
  147. switch( s_BitmapLayerIcon[ii][jj] )
  148. {
  149. default:
  150. case 0: pen.SetColour( active_layer_color.ToColour() ); break;
  151. case 1: pen.SetColour( top_color.ToColour() ); break;
  152. case 2: pen.SetColour( bottom_color.ToColour() ); break;
  153. case 3: pen.SetColour( via_color.ToColour() ); break;
  154. }
  155. buttonColor = s_BitmapLayerIcon[ii][jj];
  156. iconDC.SetPen( pen );
  157. }
  158. iconDC.DrawPoint( jj, ii );
  159. }
  160. }
  161. // Deselect the bitmap from the DC in order to delete the MemoryDC safely without
  162. // deleting the bitmap
  163. iconDC.SelectObject( wxNullBitmap );
  164. // Scale the bitmap
  165. const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
  166. wxImage image = LayerPairBitmap->ConvertToImage();
  167. // "NEAREST" causes less mixing of colors
  168. image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
  169. wxIMAGE_QUALITY_NEAREST );
  170. LayerPairBitmap = std::make_unique<wxBitmap>( image );
  171. }
  172. if( m_mainToolBar )
  173. {
  174. m_mainToolBar->SetToolBitmap( PCB_ACTIONS::selectLayerPair, *LayerPairBitmap );
  175. m_mainToolBar->Refresh();
  176. }
  177. }
  178. void PCB_EDIT_FRAME::ReCreateHToolbar()
  179. {
  180. // Note:
  181. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  182. // all wxAuiToolBarItems.
  183. // However the wxAuiToolBarItems are not the owners of controls managed by
  184. // them and therefore do not delete them
  185. // So we do not recreate them after clearing the tools.
  186. wxWindowUpdateLocker dummy( this );
  187. if( m_mainToolBar )
  188. m_mainToolBar->ClearToolbar();
  189. else
  190. m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  191. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  192. // Set up toolbar
  193. if( Kiface().IsSingle() )
  194. {
  195. m_mainToolBar->Add( ACTIONS::doNew );
  196. m_mainToolBar->Add( ACTIONS::open );
  197. }
  198. m_mainToolBar->Add( ACTIONS::save );
  199. m_mainToolBar->AddScaledSeparator( this );
  200. m_mainToolBar->Add( PCB_ACTIONS::boardSetup );
  201. m_mainToolBar->AddScaledSeparator( this );
  202. m_mainToolBar->Add( ACTIONS::pageSettings );
  203. m_mainToolBar->Add( ACTIONS::print );
  204. m_mainToolBar->Add( ACTIONS::plot );
  205. m_mainToolBar->AddScaledSeparator( this );
  206. m_mainToolBar->Add( ACTIONS::undo );
  207. m_mainToolBar->Add( ACTIONS::redo );
  208. m_mainToolBar->AddScaledSeparator( this );
  209. m_mainToolBar->Add( ACTIONS::find );
  210. m_mainToolBar->AddScaledSeparator( this );
  211. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  212. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  213. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  214. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  215. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE );
  216. m_mainToolBar->AddScaledSeparator( this );
  217. m_mainToolBar->Add( ACTIONS::showFootprintEditor );
  218. m_mainToolBar->Add( ACTIONS::showFootprintBrowser );
  219. m_mainToolBar->AddScaledSeparator( this );
  220. m_mainToolBar->Add( ACTIONS::updatePcbFromSchematic );
  221. m_mainToolBar->Add( PCB_ACTIONS::runDRC );
  222. m_mainToolBar->AddScaledSeparator( this );
  223. if( m_SelLayerBox == nullptr )
  224. {
  225. m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_PCB_SELECT_LAYER );
  226. m_SelLayerBox->SetBoardFrame( this );
  227. }
  228. ReCreateLayerBox( false );
  229. m_mainToolBar->AddControl( m_SelLayerBox );
  230. m_mainToolBar->Add( PCB_ACTIONS::selectLayerPair );
  231. PrepareLayerIndicator( true ); // Force rebuild of the bitmap with the active layer colors
  232. m_mainToolBar->AddScaledSeparator( this );
  233. m_mainToolBar->Add( PCB_ACTIONS::showEeschema );
  234. // Access to the scripting console
  235. #if defined(KICAD_SCRIPTING_WXPYTHON)
  236. if( IsWxPythonLoaded() )
  237. {
  238. m_mainToolBar->AddScaledSeparator( this );
  239. m_mainToolBar->Add( PCB_ACTIONS::showPythonConsole, ACTION_TOOLBAR::TOGGLE );
  240. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  241. AddActionPluginTools();
  242. #endif
  243. }
  244. #endif
  245. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  246. m_mainToolBar->Realize();
  247. }
  248. void PCB_EDIT_FRAME::ReCreateOptToolbar()
  249. {
  250. // Note:
  251. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  252. // all wxAuiToolBarItems.
  253. // However the wxAuiToolBarItems are not the owners of controls managed by
  254. // them and therefore do not delete them
  255. // So we do not recreate them after clearing the tools.
  256. wxWindowUpdateLocker dummy( this );
  257. if( m_optionsToolBar )
  258. m_optionsToolBar->ClearToolbar();
  259. else
  260. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR,
  261. wxDefaultPosition, wxDefaultSize,
  262. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  263. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  264. m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  265. m_optionsToolBar->Add( ACTIONS::imperialUnits, ACTION_TOOLBAR::TOGGLE );
  266. m_optionsToolBar->Add( ACTIONS::metricUnits, ACTION_TOOLBAR::TOGGLE );
  267. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  268. m_optionsToolBar->AddScaledSeparator( this );
  269. m_optionsToolBar->Add( PCB_ACTIONS::showRatsnest, ACTION_TOOLBAR::TOGGLE );
  270. m_optionsToolBar->Add( PCB_ACTIONS::ratsnestLineMode, ACTION_TOOLBAR::TOGGLE );
  271. m_optionsToolBar->AddScaledSeparator( this );
  272. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayEnable, ACTION_TOOLBAR::TOGGLE );
  273. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayDisable, ACTION_TOOLBAR::TOGGLE );
  274. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayOutlines, ACTION_TOOLBAR::TOGGLE );
  275. m_optionsToolBar->AddScaledSeparator( this );
  276. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  277. m_optionsToolBar->Add( PCB_ACTIONS::viaDisplayMode, ACTION_TOOLBAR::TOGGLE );
  278. m_optionsToolBar->Add( PCB_ACTIONS::trackDisplayMode, ACTION_TOOLBAR::TOGGLE );
  279. m_optionsToolBar->Add( ACTIONS::highContrastMode, ACTION_TOOLBAR::TOGGLE );
  280. // Tools to show/hide toolbars:
  281. m_optionsToolBar->AddScaledSeparator( this );
  282. m_optionsToolBar->Add( PCB_ACTIONS::showLayersManager, ACTION_TOOLBAR::TOGGLE );
  283. m_optionsToolBar->Add( PCB_ACTIONS::showMicrowaveToolbar, ACTION_TOOLBAR::TOGGLE );
  284. m_optionsToolBar->Realize();
  285. }
  286. void PCB_EDIT_FRAME::ReCreateVToolbar()
  287. {
  288. wxWindowUpdateLocker dummy( this );
  289. if( m_drawToolBar )
  290. m_drawToolBar->ClearToolbar();
  291. else
  292. m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  293. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  294. m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  295. m_drawToolBar->Add( PCB_ACTIONS::highlightNetTool, ACTION_TOOLBAR::TOGGLE );
  296. m_drawToolBar->Add( PCB_ACTIONS::localRatsnestTool, ACTION_TOOLBAR::TOGGLE );
  297. m_drawToolBar->AddScaledSeparator( this );
  298. m_drawToolBar->Add( PCB_ACTIONS::placeModule, ACTION_TOOLBAR::TOGGLE );
  299. m_drawToolBar->Add( PCB_ACTIONS::routeSingleTrack, ACTION_TOOLBAR::TOGGLE );
  300. m_drawToolBar->Add( PCB_ACTIONS::drawVia, ACTION_TOOLBAR::TOGGLE );
  301. m_drawToolBar->Add( PCB_ACTIONS::drawZone, ACTION_TOOLBAR::TOGGLE );
  302. m_drawToolBar->Add( PCB_ACTIONS::drawZoneKeepout, ACTION_TOOLBAR::TOGGLE );
  303. m_drawToolBar->AddScaledSeparator( this );
  304. m_drawToolBar->Add( PCB_ACTIONS::drawLine, ACTION_TOOLBAR::TOGGLE );
  305. m_drawToolBar->Add( PCB_ACTIONS::drawRectangle, ACTION_TOOLBAR::TOGGLE );
  306. m_drawToolBar->Add( PCB_ACTIONS::drawCircle, ACTION_TOOLBAR::TOGGLE );
  307. m_drawToolBar->Add( PCB_ACTIONS::drawArc, ACTION_TOOLBAR::TOGGLE );
  308. m_drawToolBar->Add( PCB_ACTIONS::drawPolygon, ACTION_TOOLBAR::TOGGLE );
  309. m_drawToolBar->Add( PCB_ACTIONS::placeText, ACTION_TOOLBAR::TOGGLE );
  310. m_drawToolBar->Add( PCB_ACTIONS::drawDimension, ACTION_TOOLBAR::TOGGLE );
  311. m_drawToolBar->Add( PCB_ACTIONS::placeTarget, ACTION_TOOLBAR::TOGGLE );
  312. m_drawToolBar->Add( ACTIONS::deleteTool, ACTION_TOOLBAR::TOGGLE );
  313. m_drawToolBar->AddScaledSeparator( this );
  314. // TODO: re-insert when we have a multi-select tool button
  315. // m_drawToolBar->Add( PCB_ACTIONS::drillOrigin, ACTION_TOOLBAR::TOGGLE );
  316. m_drawToolBar->Add( PCB_ACTIONS::gridSetOrigin, ACTION_TOOLBAR::TOGGLE );
  317. m_drawToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  318. auto isHighlightMode =
  319. [this]( const SELECTION& aSel )
  320. {
  321. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  322. return tool->GetRouterMode() == PNS::RM_MarkObstacles;
  323. };
  324. auto isShoveMode =
  325. [this]( const SELECTION& aSel )
  326. {
  327. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  328. return tool->GetRouterMode() == PNS::RM_Shove;
  329. };
  330. auto isWalkaroundMode =
  331. [this]( const SELECTION& aSel )
  332. {
  333. ROUTER_TOOL* tool = m_toolManager->GetTool<ROUTER_TOOL>();
  334. return tool->GetRouterMode() == PNS::RM_Walkaround;
  335. };
  336. SELECTION_TOOL* selTool = m_toolManager->GetTool<SELECTION_TOOL>();
  337. CONDITIONAL_MENU* routeMenu = new CONDITIONAL_MENU( false, selTool );
  338. routeMenu->AddCheckItem( PCB_ACTIONS::routerHighlightMode, isHighlightMode );
  339. routeMenu->AddCheckItem( PCB_ACTIONS::routerShoveMode, isShoveMode );
  340. routeMenu->AddCheckItem( PCB_ACTIONS::routerWalkaroundMode, isWalkaroundMode );
  341. routeMenu->AddSeparator();
  342. routeMenu->AddItem( PCB_ACTIONS::routerSettingsDialog, SELECTION_CONDITIONS::ShowAlways );
  343. m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, routeMenu );
  344. CONDITIONAL_MENU* zoneMenu = new CONDITIONAL_MENU( false, selTool );
  345. zoneMenu->AddItem( PCB_ACTIONS::zoneFillAll, SELECTION_CONDITIONS::ShowAlways );
  346. zoneMenu->AddItem( PCB_ACTIONS::zoneUnfillAll, SELECTION_CONDITIONS::ShowAlways );
  347. m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawZone, zoneMenu );
  348. m_drawToolBar->Realize();
  349. }
  350. /* Create the auxiliary vertical right toolbar, showing tools for microwave applications
  351. */
  352. void PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar()
  353. {
  354. wxWindowUpdateLocker dummy(this);
  355. if( m_microWaveToolBar )
  356. m_microWaveToolBar->ClearToolbar();
  357. else
  358. m_microWaveToolBar = new ACTION_TOOLBAR( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition,
  359. wxDefaultSize,
  360. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  361. // Set up toolbar
  362. m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateLine, ACTION_TOOLBAR::TOGGLE );
  363. m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateGap, ACTION_TOOLBAR::TOGGLE );
  364. m_microWaveToolBar->AddScaledSeparator( this );
  365. m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateStub, ACTION_TOOLBAR::TOGGLE );
  366. m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateStubArc, ACTION_TOOLBAR::TOGGLE );
  367. m_microWaveToolBar->Add( PCB_ACTIONS::microwaveCreateFunctionShape, ACTION_TOOLBAR::TOGGLE );
  368. m_microWaveToolBar->Realize();
  369. }
  370. void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
  371. {
  372. wxWindowUpdateLocker dummy( this );
  373. if( m_auxiliaryToolBar )
  374. {
  375. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  376. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  377. UpdateGridSelectBox();
  378. // combobox sizes can have changed: apply new best sizes
  379. wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
  380. item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
  381. item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
  382. item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
  383. m_auxiliaryToolBar->Realize();
  384. m_auimgr.Update();
  385. return;
  386. }
  387. m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR,
  388. wxDefaultPosition, wxDefaultSize,
  389. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  390. /* Set up toolbar items */
  391. // Creates box to display and choose tracks widths:
  392. if( m_SelTrackWidthBox == nullptr )
  393. m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
  394. wxDefaultPosition, wxDefaultSize, 0, NULL );
  395. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  396. m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
  397. // Creates box to display and choose vias diameters:
  398. if( m_SelViaSizeBox == nullptr )
  399. m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_VIA_SIZE,
  400. wxDefaultPosition, wxDefaultSize, 0, NULL );
  401. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  402. m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
  403. m_auxiliaryToolBar->AddScaledSeparator( this );
  404. // Creates box to display and choose strategy to handle tracks an vias sizes:
  405. m_auxiliaryToolBar->AddTool( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, wxEmptyString,
  406. KiScaledBitmap( auto_track_width_xpm, this ),
  407. _( "Auto track width: when starting on an existing track "
  408. "use its width\notherwise, use current width setting" ),
  409. wxITEM_CHECK );
  410. // Add the box to display and select the current grid size:
  411. m_auxiliaryToolBar->AddScaledSeparator( this );
  412. if( m_gridSelectBox == nullptr )
  413. m_gridSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_GRID_SELECT,
  414. wxDefaultPosition, wxDefaultSize, 0, NULL );
  415. UpdateGridSelectBox();
  416. m_auxiliaryToolBar->AddControl( m_gridSelectBox );
  417. // Add the box to display and select the current Zoom
  418. m_auxiliaryToolBar->AddScaledSeparator( this );
  419. if( m_zoomSelectBox == nullptr )
  420. m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_ZOOM_SELECT,
  421. wxDefaultPosition, wxDefaultSize, 0, NULL );
  422. UpdateZoomSelectBox();
  423. m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
  424. // after adding the buttons to the toolbar, must call Realize()
  425. m_auxiliaryToolBar->Realize();
  426. }
  427. void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, bool aEdit )
  428. {
  429. if( aTrackWidthSelectBox == NULL )
  430. return;
  431. wxString msg;
  432. bool mmFirst = GetUserUnits() != EDA_UNITS::INCHES;
  433. aTrackWidthSelectBox->Clear();
  434. for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
  435. {
  436. int size = GetDesignSettings().m_TrackWidthList[ii];
  437. double valueMils = To_User_Unit( EDA_UNITS::INCHES, size ) * 1000;
  438. double value_mm = To_User_Unit( EDA_UNITS::MILLIMETRES, size );
  439. if( mmFirst )
  440. msg.Printf( _( "Track: %.3f mm (%.2f mils)" ), value_mm, valueMils );
  441. else
  442. msg.Printf( _( "Track: %.2f mils (%.3f mm)" ), valueMils, value_mm );
  443. // Mark the netclass track width value (the first in list)
  444. if( ii == 0 )
  445. msg << wxT( " *" );
  446. aTrackWidthSelectBox->Append( msg );
  447. }
  448. if( aEdit )
  449. {
  450. aTrackWidthSelectBox->Append( wxT( "---" ) );
  451. aTrackWidthSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  452. }
  453. if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
  454. GetDesignSettings().SetTrackWidthIndex( 0 );
  455. aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  456. }
  457. void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool aEdit )
  458. {
  459. if( aViaSizeSelectBox == NULL )
  460. return;
  461. aViaSizeSelectBox->Clear();
  462. bool mmFirst = GetUserUnits() != EDA_UNITS::INCHES;
  463. for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
  464. {
  465. VIA_DIMENSION viaDimension = GetDesignSettings().m_ViasDimensionsList[ii];
  466. wxString msg, mmStr, milsStr;
  467. double diam = To_User_Unit( EDA_UNITS::MILLIMETRES, viaDimension.m_Diameter );
  468. double hole = To_User_Unit( EDA_UNITS::MILLIMETRES, viaDimension.m_Drill );
  469. if( hole > 0 )
  470. mmStr.Printf( _( "%.2f / %.2f mm" ), diam, hole );
  471. else
  472. mmStr.Printf( _( "%.2f mm" ), diam );
  473. diam = To_User_Unit( EDA_UNITS::INCHES, viaDimension.m_Diameter ) * 1000;
  474. hole = To_User_Unit( EDA_UNITS::INCHES, viaDimension.m_Drill ) * 1000;
  475. if( hole > 0 )
  476. milsStr.Printf( _( "%.1f / %.1f mils" ), diam, hole );
  477. else
  478. milsStr.Printf( _( "%.1f mils" ), diam );
  479. msg.Printf( _( "Via: %s (%s)" ), mmFirst ? mmStr : milsStr, mmFirst ? milsStr : mmStr );
  480. // Mark the netclass via size value (the first in list)
  481. if( ii == 0 )
  482. msg << wxT( " *" );
  483. aViaSizeSelectBox->Append( msg );
  484. }
  485. if( aEdit )
  486. {
  487. aViaSizeSelectBox->Append( wxT( "---" ) );
  488. aViaSizeSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  489. }
  490. if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
  491. GetDesignSettings().SetViaSizeIndex( 0 );
  492. aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  493. }
  494. void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
  495. {
  496. if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
  497. return;
  498. m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
  499. m_SelLayerBox->Resync();
  500. if( aForceResizeToolbar )
  501. {
  502. // the layer box can have its size changed
  503. // Update the aui manager, to take in account the new size
  504. m_auimgr.Update();
  505. }
  506. }
  507. void PCB_EDIT_FRAME::ToggleLayersManager()
  508. {
  509. // show auxiliary Vertical layers and visibility manager toolbar
  510. m_show_layer_manager_tools = !m_show_layer_manager_tools;
  511. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  512. m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
  513. m_auimgr.Update();
  514. }
  515. void PCB_EDIT_FRAME::ToggleMicrowaveToolbar()
  516. {
  517. m_show_microwave_tools = !m_show_microwave_tools;
  518. m_auimgr.GetPane( "MicrowaveToolbar" ).Show( m_show_microwave_tools );
  519. m_auimgr.Update();
  520. }
  521. void PCB_EDIT_FRAME::OnUpdateSelectTrackWidth( wxUpdateUIEvent& aEvent )
  522. {
  523. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_TRACK_WIDTH )
  524. {
  525. if( m_SelTrackWidthBox->GetSelection() != (int) GetDesignSettings().GetTrackWidthIndex() )
  526. m_SelTrackWidthBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  527. }
  528. }
  529. void PCB_EDIT_FRAME::OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent )
  530. {
  531. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_VIA_SIZE )
  532. {
  533. if( m_SelViaSizeBox->GetSelection() != (int) GetDesignSettings().GetViaSizeIndex() )
  534. m_SelViaSizeBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  535. }
  536. }
  537. void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
  538. {
  539. m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
  540. }
  541. bool PCB_EDIT_FRAME::LayerManagerShown()
  542. {
  543. return m_auimgr.GetPane( "LayersManager" ).IsShown();
  544. }
  545. bool PCB_EDIT_FRAME::MicrowaveToolbarShown()
  546. {
  547. return m_auimgr.GetPane( "MicrowaveToolbar" ).IsShown();
  548. }
  549. void PCB_EDIT_FRAME::SyncToolbars()
  550. {
  551. #define TOGGLE_TOOL( toolbar, tool ) toolbar->Toggle( tool, IsCurrentTool( tool ) )
  552. if( !m_mainToolBar || !m_optionsToolBar || !m_drawToolBar || !m_microWaveToolBar )
  553. return;
  554. auto& opts = GetDisplayOptions();
  555. KIGFX::GAL_DISPLAY_OPTIONS& galOpts = GetGalDisplayOptions();
  556. int zoneMode = opts.m_DisplayZonesMode;
  557. m_mainToolBar->Toggle( ACTIONS::save, IsContentModified() );
  558. m_mainToolBar->Toggle( ACTIONS::undo, GetScreen() && GetScreen()->GetUndoCommandCount() > 0 );
  559. m_mainToolBar->Toggle( ACTIONS::redo, GetScreen() && GetScreen()->GetRedoCommandCount() > 0 );
  560. TOGGLE_TOOL( m_mainToolBar, ACTIONS::zoomTool );
  561. #if defined(KICAD_SCRIPTING_WXPYTHON)
  562. if( IsWxPythonLoaded() )
  563. {
  564. wxMiniFrame* console = (wxMiniFrame *) PCB_EDIT_FRAME::findPythonConsole();
  565. m_mainToolBar->Toggle( PCB_ACTIONS::showPythonConsole, console && console->IsShown() );
  566. }
  567. #endif
  568. m_mainToolBar->Refresh();
  569. PrepareLayerIndicator();
  570. m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() );
  571. m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES );
  572. m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES );
  573. m_optionsToolBar->Toggle( ACTIONS::togglePolarCoords, GetShowPolarCoords() );
  574. m_optionsToolBar->Toggle( ACTIONS::toggleCursorStyle, galOpts.m_fullscreenCursor );
  575. m_optionsToolBar->Toggle( PCB_ACTIONS::showRatsnest, opts.m_ShowGlobalRatsnest );
  576. m_optionsToolBar->Toggle( PCB_ACTIONS::ratsnestLineMode, opts.m_DisplayRatsnestLinesCurved );
  577. m_optionsToolBar->Toggle( PCB_ACTIONS::showLayersManager, LayerManagerShown() );
  578. m_optionsToolBar->Toggle( PCB_ACTIONS::showMicrowaveToolbar, MicrowaveToolbarShown() );
  579. m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayEnable, zoneMode == 0 );
  580. m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayDisable, zoneMode == 1 );
  581. m_optionsToolBar->Toggle( PCB_ACTIONS::zoneDisplayOutlines, zoneMode == 2 );
  582. m_optionsToolBar->Toggle( PCB_ACTIONS::trackDisplayMode, !opts.m_DisplayPcbTrackFill );
  583. m_optionsToolBar->Toggle( PCB_ACTIONS::viaDisplayMode, !opts.m_DisplayViaFill );
  584. m_optionsToolBar->Toggle( PCB_ACTIONS::padDisplayMode, !opts.m_DisplayPadFill );
  585. m_optionsToolBar->Toggle( ACTIONS::highContrastMode, opts.m_ContrastModeDisplay );
  586. m_optionsToolBar->Refresh();
  587. TOGGLE_TOOL( m_drawToolBar, ACTIONS::selectionTool );
  588. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::highlightNetTool );
  589. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::localRatsnestTool );
  590. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeModule );
  591. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::routeSingleTrack );
  592. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawVia );
  593. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZone );
  594. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawZoneKeepout );
  595. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawLine );
  596. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawRectangle );
  597. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawCircle );
  598. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawArc );
  599. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawPolygon );
  600. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeText );
  601. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drawDimension );
  602. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::placeTarget );
  603. TOGGLE_TOOL( m_drawToolBar, ACTIONS::deleteTool );
  604. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::drillOrigin );
  605. TOGGLE_TOOL( m_drawToolBar, PCB_ACTIONS::gridSetOrigin );
  606. TOGGLE_TOOL( m_drawToolBar, ACTIONS::measureTool );
  607. m_drawToolBar->Refresh();
  608. TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateLine );
  609. TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateGap );
  610. TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStub );
  611. TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateStubArc );
  612. TOGGLE_TOOL( m_microWaveToolBar, PCB_ACTIONS::microwaveCreateFunctionShape );
  613. m_microWaveToolBar->Refresh();
  614. }