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.

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