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.

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