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.

828 lines
33 KiB

7 years ago
8 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
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
16 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
7 years ago
7 years ago
7 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-2018 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. /**
  27. * @file tool_pcb_editor.cpp
  28. * @brief PCB editor toolbars build/rebuild functions
  29. */
  30. #include <fctsys.h>
  31. #include <kiface_i.h>
  32. #include <help_common_strings.h>
  33. #include <dialog_helpers.h>
  34. #include <pcb_edit_frame.h>
  35. #include <class_drawpanel.h>
  36. #include <confirm.h>
  37. #include <bitmaps.h>
  38. #include <class_board.h>
  39. #include <pcbnew.h>
  40. #include <pcbnew_id.h>
  41. #include <hotkeys.h>
  42. #include <pcb_layer_box_selector.h>
  43. #include <view/view.h>
  44. #include <wx/wupdlock.h>
  45. #include <memory>
  46. #include <pgm_base.h>
  47. extern bool IsWxPythonLoaded();
  48. #define SEL_LAYER_HELP _( \
  49. "Show active layer selections\nand select layer pair for route and place via" )
  50. /* Data to build the layer pair indicator button */
  51. static std::unique_ptr<wxBitmap> LayerPairBitmap;
  52. #define BM_LAYERICON_SIZE 24
  53. static const char s_BitmapLayerIcon[BM_LAYERICON_SIZE][BM_LAYERICON_SIZE] =
  54. {
  55. // 0 = draw pixel with active layer color
  56. // 1 = draw pixel with top layer color (top/bottom layer used inautoroute and place via)
  57. // 2 = draw pixel with bottom layer color
  58. // 3 = draw pixel with via color
  59. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0 },
  60. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0 },
  61. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0 },
  62. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
  63. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
  64. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  65. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
  66. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 0, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 0, 0 },
  67. { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 0, 1, 1, 1, 1, 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. { 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 1, 1, 1, 1, 0, 3, 3, 2, 2, 2, 2, 2, 2, 2 },
  70. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 1, 1, 0, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0 },
  71. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
  72. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 3, 3, 3, 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. { 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. };
  82. void PCB_EDIT_FRAME::PrepareLayerIndicator()
  83. {
  84. int ii, jj;
  85. COLOR4D active_layer_color, Route_Layer_TOP_color,
  86. Route_Layer_BOTTOM_color, via_color, background_color;
  87. bool change = false;
  88. static int previous_requested_scale;
  89. static COLOR4D previous_active_layer_color, previous_Route_Layer_TOP_color,
  90. previous_Route_Layer_BOTTOM_color, previous_via_color,
  91. previous_background_color;
  92. int requested_scale;
  93. Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
  94. if( requested_scale != previous_requested_scale )
  95. {
  96. previous_requested_scale = requested_scale;
  97. change = true;
  98. }
  99. active_layer_color = Settings().Colors().GetLayerColor(GetActiveLayer());
  100. if( previous_active_layer_color != active_layer_color )
  101. {
  102. previous_active_layer_color = active_layer_color;
  103. change = true;
  104. }
  105. Route_Layer_TOP_color =
  106. Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_TOP );
  107. if( previous_Route_Layer_TOP_color != Route_Layer_TOP_color )
  108. {
  109. previous_Route_Layer_TOP_color = Route_Layer_TOP_color;
  110. change = true;
  111. }
  112. Route_Layer_BOTTOM_color =
  113. Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
  114. if( previous_Route_Layer_BOTTOM_color != Route_Layer_BOTTOM_color )
  115. {
  116. previous_Route_Layer_BOTTOM_color = Route_Layer_BOTTOM_color;
  117. change = true;
  118. }
  119. int via_type = GetDesignSettings().m_CurrentViaType;
  120. via_color = Settings().Colors().GetItemColor( LAYER_VIAS + via_type );
  121. if( previous_via_color != via_color )
  122. {
  123. previous_via_color = via_color;
  124. change = true;
  125. }
  126. background_color = Settings().Colors().GetItemColor( LAYER_PCB_BACKGROUND );
  127. if( previous_background_color != background_color )
  128. {
  129. previous_background_color = background_color;
  130. change = true;
  131. }
  132. if( !change && LayerPairBitmap )
  133. return;
  134. LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
  135. /* Draw the icon, with colors according to the active layer and layer
  136. * pairs for via command (change layer)
  137. */
  138. wxMemoryDC iconDC;
  139. iconDC.SelectObject( *LayerPairBitmap );
  140. wxBrush brush;
  141. wxPen pen;
  142. int buttonColor = -1;
  143. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  144. brush.SetColour( background_color.WithAlpha(1.0).ToColour() );
  145. iconDC.SetBrush( brush );
  146. iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
  147. for( ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
  148. {
  149. for( jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
  150. {
  151. if( s_BitmapLayerIcon[ii][jj] != buttonColor )
  152. {
  153. switch( s_BitmapLayerIcon[ii][jj] )
  154. {
  155. default:
  156. case 0:
  157. pen.SetColour( active_layer_color.ToColour() );
  158. break;
  159. case 1:
  160. pen.SetColour( Route_Layer_TOP_color.ToColour() );
  161. break;
  162. case 2:
  163. pen.SetColour( Route_Layer_BOTTOM_color.ToColour() );
  164. break;
  165. case 3:
  166. pen.SetColour( via_color.ToColour() );
  167. break;
  168. }
  169. buttonColor = s_BitmapLayerIcon[ii][jj];
  170. iconDC.SetPen( pen );
  171. }
  172. iconDC.DrawPoint( jj, ii );
  173. }
  174. }
  175. /* Deselect the Tool Bitmap from DC,
  176. * in order to delete the MemoryDC safely without deleting the bitmap */
  177. iconDC.SelectObject( wxNullBitmap );
  178. // Scale the bitmap
  179. const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
  180. wxImage image = LayerPairBitmap->ConvertToImage();
  181. // "NEAREST" causes less mixing of colors
  182. image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
  183. wxIMAGE_QUALITY_NEAREST );
  184. LayerPairBitmap = std::make_unique<wxBitmap>( image );
  185. if( m_mainToolBar )
  186. {
  187. m_mainToolBar->SetToolBitmap( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, *LayerPairBitmap );
  188. m_mainToolBar->Refresh();
  189. }
  190. }
  191. void PCB_EDIT_FRAME::ReCreateHToolbar()
  192. {
  193. wxString msg;
  194. wxWindowUpdateLocker dummy( this );
  195. if( m_mainToolBar )
  196. m_mainToolBar->Clear();
  197. else
  198. m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  199. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  200. #define ADD_TOOL( id, xpm, tooltip ) \
  201. m_mainToolBar->AddTool( id, wxEmptyString, KiScaledBitmap( xpm, this ), tooltip );
  202. // Set up toolbar
  203. if( Kiface().IsSingle() )
  204. {
  205. ADD_TOOL( ID_NEW_BOARD, new_board_xpm, _( "New board" ) );
  206. ADD_TOOL( ID_LOAD_FILE, open_brd_file_xpm, _( "Open existing board" ) );
  207. }
  208. ADD_TOOL( ID_SAVE_BOARD, save_xpm, _( "Save board" ) );
  209. KiScaledSeparator( m_mainToolBar, this );
  210. ADD_TOOL( ID_BOARD_SETUP_DIALOG, options_board_xpm, _( "Board setup" ) );
  211. KiScaledSeparator( m_mainToolBar, this );
  212. ADD_TOOL( ID_SHEET_SET, sheetset_xpm, _( "Page settings for paper size and texts" ) );
  213. ADD_TOOL( wxID_PRINT, print_button_xpm, _( "Print board" ) );
  214. ADD_TOOL( ID_GEN_PLOT, plot_xpm, _( "Plot (HPGL, PostScript, or GERBER format)" ) );
  215. KiScaledSeparator( m_mainToolBar, this );
  216. msg = AddHotkeyName( HELP_UNDO, g_Board_Editor_Hotkeys_Descr, HK_UNDO, IS_COMMENT );
  217. ADD_TOOL( wxID_UNDO, undo_xpm, msg );
  218. msg = AddHotkeyName( HELP_REDO, g_Board_Editor_Hotkeys_Descr, HK_REDO, IS_COMMENT );
  219. ADD_TOOL( wxID_REDO, redo_xpm, msg );
  220. KiScaledSeparator( m_mainToolBar, this );
  221. msg = AddHotkeyName( HELP_FIND, g_Board_Editor_Hotkeys_Descr, HK_FIND_ITEM, IS_COMMENT );
  222. ADD_TOOL( ID_FIND_ITEMS, find_xpm, msg );
  223. KiScaledSeparator( m_mainToolBar, this );
  224. msg = AddHotkeyName( HELP_ZOOM_REDRAW, g_Board_Editor_Hotkeys_Descr, HK_ZOOM_REDRAW, IS_COMMENT );
  225. ADD_TOOL( ID_ZOOM_REDRAW, zoom_redraw_xpm, msg );
  226. msg = AddHotkeyName( HELP_ZOOM_IN, g_Board_Editor_Hotkeys_Descr, HK_ZOOM_IN, IS_COMMENT );
  227. ADD_TOOL( ID_ZOOM_IN, zoom_in_xpm, msg );
  228. msg = AddHotkeyName( HELP_ZOOM_OUT, g_Board_Editor_Hotkeys_Descr, HK_ZOOM_OUT, IS_COMMENT );
  229. ADD_TOOL( ID_ZOOM_OUT, zoom_out_xpm, msg );
  230. msg = AddHotkeyName( HELP_ZOOM_FIT, g_Board_Editor_Hotkeys_Descr, HK_ZOOM_AUTO, IS_COMMENT );
  231. ADD_TOOL( ID_ZOOM_PAGE, zoom_fit_in_page_xpm, msg );
  232. m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
  233. _( "Zoom to selection" ), wxITEM_CHECK );
  234. KiScaledSeparator( m_mainToolBar, this );
  235. ADD_TOOL( ID_OPEN_MODULE_EDITOR, module_editor_xpm, _( "Open footprint editor" ) );
  236. ADD_TOOL( ID_OPEN_MODULE_VIEWER, modview_icon_xpm, _( "Open footprint viewer" ) );
  237. KiScaledSeparator( m_mainToolBar, this );
  238. ADD_TOOL( ID_GET_NETLIST, netlist_xpm, _( "Read netlist" ) );
  239. ADD_TOOL( ID_UPDATE_PCB_FROM_SCH, update_pcb_from_sch_xpm, _( "Update PCB from schematic" ) );
  240. ADD_TOOL( ID_DRC_CONTROL, erc_xpm, _( "Perform design rules check" ) );
  241. KiScaledSeparator( m_mainToolBar, this );
  242. if( m_SelLayerBox == NULL )
  243. {
  244. m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_PCB_SELECT_LAYER );
  245. m_SelLayerBox->SetBoardFrame( this );
  246. }
  247. ReCreateLayerBox( false );
  248. m_mainToolBar->AddControl( m_SelLayerBox );
  249. PrepareLayerIndicator(); // Initialize the bitmap with the active layer colors
  250. m_mainToolBar->AddTool( ID_AUX_TOOLBAR_PCB_SELECT_LAYER_PAIR, wxEmptyString, *LayerPairBitmap,
  251. SEL_LAYER_HELP );
  252. KiScaledSeparator( m_mainToolBar, this );
  253. ADD_TOOL( ID_RUN_EESCHEMA, eeschema_xpm, _( "Open schematic in Eeschema" ) );
  254. // Access to the scripting console
  255. #if defined(KICAD_SCRIPTING_WXPYTHON)
  256. if( IsWxPythonLoaded() )
  257. {
  258. KiScaledSeparator( m_mainToolBar, this );
  259. m_mainToolBar->AddTool( ID_TOOLBARH_PCB_SCRIPTING_CONSOLE, wxEmptyString,
  260. KiScaledBitmap( py_script_xpm, this ),
  261. _( "Show/Hide the Python Scripting console" ), wxITEM_CHECK );
  262. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  263. AddActionPluginTools();
  264. #endif
  265. }
  266. #endif
  267. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  268. m_mainToolBar->Realize();
  269. #undef ADD_TOOL
  270. }
  271. void PCB_EDIT_FRAME::ReCreateOptToolbar()
  272. {
  273. wxWindowUpdateLocker dummy( this );
  274. if( m_optionsToolBar )
  275. m_optionsToolBar->Clear();
  276. else
  277. m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  278. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  279. m_optionsToolBar->AddTool( ID_TB_OPTIONS_DRC_OFF, wxEmptyString, KiScaledBitmap( drc_off_xpm, this ),
  280. _( "Enable design rule checking" ), wxITEM_CHECK );
  281. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiScaledBitmap( grid_xpm, this ),
  282. _( "Hide grid" ), wxITEM_CHECK );
  283. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
  284. KiScaledBitmap( polar_coord_xpm, this ),
  285. _( "Display polar coordinates" ), wxITEM_CHECK );
  286. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
  287. KiScaledBitmap( unit_inch_xpm, this ),
  288. _( "Set units to inches" ), wxITEM_CHECK );
  289. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
  290. KiScaledBitmap( unit_mm_xpm, this ),
  291. _( "Set units to millimeters" ), wxITEM_CHECK );
  292. #ifndef __APPLE__
  293. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
  294. KiScaledBitmap( cursor_shape_xpm, this ),
  295. _( "Change cursor shape" ), wxITEM_CHECK );
  296. #else
  297. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
  298. KiScaledBitmap( cursor_shape_xpm, this ),
  299. _( "Change cursor shape (not supported in Legacy Toolset)" ),
  300. wxITEM_CHECK );
  301. #endif
  302. KiScaledSeparator( m_optionsToolBar, this );
  303. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_RATSNEST, wxEmptyString,
  304. KiScaledBitmap( general_ratsnest_xpm, this ),
  305. _( "Show board ratsnest" ), wxITEM_CHECK );
  306. KiScaledSeparator( m_optionsToolBar, this );
  307. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES, wxEmptyString, KiScaledBitmap( show_zone_xpm, this ),
  308. _( "Show filled areas in zones" ), wxITEM_CHECK );
  309. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES_DISABLE, wxEmptyString,
  310. KiScaledBitmap( show_zone_disable_xpm, this ),
  311. _( "Do not show filled areas in zones" ) , wxITEM_CHECK );
  312. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY, wxEmptyString,
  313. KiScaledBitmap( show_zone_outline_only_xpm, this ),
  314. _( "Show outlines of filled areas only in zones" ), wxITEM_CHECK );
  315. KiScaledSeparator( m_optionsToolBar, this );
  316. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString,
  317. KiScaledBitmap( pad_sketch_xpm, this ),
  318. _( "Show pads in outline mode" ), wxITEM_CHECK );
  319. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_VIAS_SKETCH, wxEmptyString,
  320. KiScaledBitmap( via_sketch_xpm, this ),
  321. _( "Show vias in outline mode" ), wxITEM_CHECK );
  322. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_TRACKS_SKETCH, wxEmptyString,
  323. KiScaledBitmap( showtrack_xpm, this ),
  324. _( "Show tracks in outline mode" ),
  325. wxITEM_CHECK );
  326. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE, wxEmptyString,
  327. KiScaledBitmap( contrast_mode_xpm, this ),
  328. _( "Enable high contrast display mode" ),
  329. wxITEM_CHECK );
  330. // Tools to show/hide toolbars:
  331. KiScaledSeparator( m_optionsToolBar, this );
  332. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_MANAGE_LAYERS_VERTICAL_TOOLBAR,
  333. wxEmptyString,
  334. KiScaledBitmap( layers_manager_xpm, this ),
  335. HELP_SHOW_HIDE_LAYERMANAGER,
  336. wxITEM_CHECK );
  337. m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE,
  338. wxEmptyString,
  339. KiScaledBitmap( mw_toolbar_xpm, this ),
  340. HELP_SHOW_HIDE_MICROWAVE_TOOLS,
  341. wxITEM_CHECK );
  342. KiScaledSeparator( m_optionsToolBar, this );
  343. m_optionsToolBar->Realize();
  344. }
  345. void PCB_EDIT_FRAME::ReCreateVToolbar()
  346. {
  347. wxWindowUpdateLocker dummy( this );
  348. if( m_drawToolBar )
  349. m_drawToolBar->Clear();
  350. else
  351. m_drawToolBar = new wxAuiToolBar( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  352. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  353. // Set up toolbar
  354. m_drawToolBar->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString, KiScaledBitmap( cursor_xpm, this ),
  355. _( "Select item" ), wxITEM_CHECK );
  356. KiScaledSeparator( m_drawToolBar, this );
  357. m_drawToolBar->AddTool( ID_PCB_HIGHLIGHT_BUTT, wxEmptyString, KiScaledBitmap( net_highlight_xpm, this ),
  358. _( "Highlight net" ), wxITEM_CHECK );
  359. m_drawToolBar->AddTool( ID_PCB_SHOW_1_RATSNEST_BUTT, wxEmptyString,
  360. KiScaledBitmap( tool_ratsnest_xpm, this ),
  361. _( "Display local ratsnest" ), wxITEM_CHECK );
  362. KiScaledSeparator( m_drawToolBar, this );
  363. m_drawToolBar->AddTool( ID_PCB_MODULE_BUTT, wxEmptyString, KiScaledBitmap( module_xpm, this ),
  364. _( "Add footprints" ), wxITEM_CHECK );
  365. m_drawToolBar->AddTool( ID_TRACK_BUTT, wxEmptyString, KiScaledBitmap( add_tracks_xpm, this ),
  366. _( "Route tracks" ), wxITEM_CHECK );
  367. m_drawToolBar->AddTool( ID_PCB_DRAW_VIA_BUTT, wxEmptyString, KiScaledBitmap( add_via_xpm, this ),
  368. _( "Add vias" ), wxITEM_CHECK );
  369. m_drawToolBar->AddTool( ID_PCB_ZONES_BUTT, wxEmptyString, KiScaledBitmap( add_zone_xpm, this ),
  370. _( "Add filled zones" ), wxITEM_CHECK );
  371. m_drawToolBar->AddTool( ID_PCB_KEEPOUT_AREA_BUTT, wxEmptyString,
  372. KiScaledBitmap( add_keepout_area_xpm, this ),
  373. _( "Add keepout areas" ), wxITEM_CHECK );
  374. KiScaledSeparator( m_drawToolBar, this );
  375. m_drawToolBar->AddTool( ID_PCB_ADD_LINE_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_segments_xpm, this ),
  376. _( "Add graphic lines" ), wxITEM_CHECK );
  377. m_drawToolBar->AddTool( ID_PCB_CIRCLE_BUTT, wxEmptyString, KiScaledBitmap( add_circle_xpm, this ),
  378. _( "Add graphic circle" ), wxITEM_CHECK );
  379. m_drawToolBar->AddTool( ID_PCB_ARC_BUTT, wxEmptyString, KiScaledBitmap( add_arc_xpm, this ),
  380. _( "Add graphic arc" ), wxITEM_CHECK );
  381. m_drawToolBar->AddTool( ID_PCB_ADD_POLYGON_BUTT, wxEmptyString, KiScaledBitmap( add_graphical_polygon_xpm, this ),
  382. _( "Add graphic polygon" ), wxITEM_CHECK );
  383. m_drawToolBar->AddTool( ID_PCB_ADD_TEXT_BUTT, wxEmptyString, KiScaledBitmap( text_xpm, this ),
  384. _( "Add text on copper layers or graphic text" ), wxITEM_CHECK );
  385. KiScaledSeparator( m_drawToolBar, this );
  386. m_drawToolBar->AddTool( ID_PCB_DIMENSION_BUTT, wxEmptyString, KiScaledBitmap( add_dimension_xpm, this ),
  387. _( "Add dimension" ), wxITEM_CHECK );
  388. m_drawToolBar->AddTool( ID_PCB_TARGET_BUTT, wxEmptyString, KiScaledBitmap( add_pcb_target_xpm, this ),
  389. _( "Add layer alignment target" ), wxITEM_CHECK );
  390. KiScaledSeparator( m_drawToolBar, this );
  391. m_drawToolBar->AddTool( ID_PCB_DELETE_ITEM_BUTT, wxEmptyString, KiScaledBitmap( delete_xpm, this ),
  392. _( "Delete items" ), wxITEM_CHECK );
  393. KiScaledSeparator( m_drawToolBar, this );
  394. m_drawToolBar->AddTool( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxEmptyString,
  395. KiScaledBitmap( pcb_offset_xpm, this ),
  396. _( "Place the auxiliary axis origin for some plot file formats,\n"
  397. "and for drill and place files" ),
  398. wxITEM_CHECK );
  399. m_drawToolBar->AddTool( ID_PCB_PLACE_GRID_COORD_BUTT, wxEmptyString,
  400. KiScaledBitmap( grid_select_axis_xpm, this ),
  401. _( "Set the origin point for the grid" ),
  402. wxITEM_CHECK );
  403. m_drawToolBar->AddTool( ID_PCB_MEASUREMENT_TOOL, wxEmptyString,
  404. KiScaledBitmap( measurement_xpm, this ),
  405. _( "Measure distance" ),
  406. wxITEM_CHECK );
  407. m_drawToolBar->Realize();
  408. }
  409. /* Create the auxiliary vertical right toolbar, showing tools for microwave applications
  410. */
  411. void PCB_EDIT_FRAME::ReCreateMicrowaveVToolbar()
  412. {
  413. wxWindowUpdateLocker dummy(this);
  414. if( m_microWaveToolBar )
  415. m_microWaveToolBar->Clear();
  416. else
  417. m_microWaveToolBar = new wxAuiToolBar( this, ID_MICROWAVE_V_TOOLBAR, wxDefaultPosition,
  418. wxDefaultSize,
  419. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  420. // Set up toolbar
  421. m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_SELF_CMD, wxEmptyString,
  422. KiScaledBitmap( mw_add_line_xpm, this ),
  423. _( "Create line of specified length for microwave applications" ),
  424. wxITEM_CHECK );
  425. m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_GAP_CMD, wxEmptyString,
  426. KiScaledBitmap( mw_add_gap_xpm, this ),
  427. _( "Create gap of specified length for microwave applications" ),
  428. wxITEM_CHECK );
  429. KiScaledSeparator( m_microWaveToolBar, this );
  430. m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_CMD, wxEmptyString,
  431. KiScaledBitmap( mw_add_stub_xpm, this ),
  432. _( "Create stub of specified length for microwave applications" ),
  433. wxITEM_CHECK );
  434. m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_STUB_ARC_CMD, wxEmptyString,
  435. KiScaledBitmap( mw_add_stub_arc_xpm, this ),
  436. _( "Create stub (arc) of specified length for microwave applications" ),
  437. wxITEM_CHECK );
  438. m_microWaveToolBar->AddTool( ID_PCB_MUWAVE_TOOL_FUNCTION_SHAPE_CMD, wxEmptyString,
  439. KiScaledBitmap( mw_add_shape_xpm, this ),
  440. _( "Create a polynomial shape for microwave applications" ),
  441. wxITEM_CHECK );
  442. m_microWaveToolBar->Realize();
  443. }
  444. void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
  445. {
  446. wxWindowUpdateLocker dummy( this );
  447. if( m_auxiliaryToolBar )
  448. {
  449. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  450. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  451. // combobox sizes can have changed: apply new best sizes
  452. wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
  453. item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
  454. item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
  455. item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
  456. m_auxiliaryToolBar->Realize();
  457. m_auimgr.Update();
  458. return;
  459. }
  460. m_auxiliaryToolBar = new wxAuiToolBar( this, ID_AUX_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  461. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  462. /* Set up toolbar items */
  463. // Creates box to display and choose tracks widths:
  464. m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar,
  465. ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
  466. wxDefaultPosition, wxDefaultSize,
  467. 0, NULL );
  468. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  469. m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
  470. // Creates box to display and choose vias diameters:
  471. m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar,
  472. ID_AUX_TOOLBAR_PCB_VIA_SIZE,
  473. wxDefaultPosition, wxDefaultSize,
  474. 0, NULL );
  475. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  476. m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
  477. KiScaledSeparator( m_auxiliaryToolBar, this );
  478. // Creates box to display and choose strategy to handle tracks an vias sizes:
  479. m_auxiliaryToolBar->AddTool( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH,
  480. wxEmptyString,
  481. KiScaledBitmap( auto_track_width_xpm, this ),
  482. _( "Auto track width: when starting on an existing track "
  483. "use its width\notherwise, use current width setting" ),
  484. wxITEM_CHECK );
  485. // Add the box to display and select the current grid size:
  486. KiScaledSeparator( m_auxiliaryToolBar, this );
  487. m_gridSelectBox = new wxChoice( m_auxiliaryToolBar,
  488. ID_ON_GRID_SELECT,
  489. wxDefaultPosition, wxDefaultSize,
  490. 0, NULL );
  491. UpdateGridSelectBox();
  492. m_auxiliaryToolBar->AddControl( m_gridSelectBox );
  493. // Add the box to display and select the current Zoom
  494. KiScaledSeparator( m_auxiliaryToolBar, this );
  495. m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar,
  496. ID_ON_ZOOM_SELECT,
  497. wxDefaultPosition, wxDefaultSize,
  498. 0, NULL );
  499. updateZoomSelectBox();
  500. m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
  501. // after adding the buttons to the toolbar, must call Realize()
  502. m_auxiliaryToolBar->Realize();
  503. }
  504. void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox )
  505. {
  506. if( aTrackWidthSelectBox == NULL )
  507. return;
  508. wxString msg;
  509. bool mmFirst = GetUserUnits() != INCHES;
  510. aTrackWidthSelectBox->Clear();
  511. for( unsigned ii = 0; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
  512. {
  513. int size = GetDesignSettings().m_TrackWidthList[ii];
  514. double valueMils = To_User_Unit( INCHES, size ) * 1000;
  515. double value_mm = To_User_Unit( MILLIMETRES, size );
  516. if( mmFirst )
  517. msg.Printf( _( "Track: %.3f mm (%.2f mils)" ),
  518. value_mm, valueMils );
  519. else
  520. msg.Printf( _( "Track: %.2f mils (%.3f mm)" ),
  521. valueMils, value_mm );
  522. // Mark the netclass track width value (the first in list)
  523. if( ii == 0 )
  524. msg << wxT( " *" );
  525. aTrackWidthSelectBox->Append( msg );
  526. }
  527. aTrackWidthSelectBox->Append( wxT( "---" ) );
  528. aTrackWidthSelectBox->Append( _( "Edit pre-defined sizes..." ) );
  529. if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
  530. GetDesignSettings().SetTrackWidthIndex( 0 );
  531. aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  532. }
  533. void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox )
  534. {
  535. if( aViaSizeSelectBox == NULL )
  536. return;
  537. aViaSizeSelectBox->Clear();
  538. bool mmFirst = GetUserUnits() != INCHES;
  539. for( unsigned ii = 0; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
  540. {
  541. VIA_DIMENSION viaDimension = GetDesignSettings().m_ViasDimensionsList[ii];
  542. wxString msg, mmStr, milsStr;
  543. double diam = To_User_Unit( MILLIMETRES, viaDimension.m_Diameter );
  544. double hole = To_User_Unit( MILLIMETRES, viaDimension.m_Drill );
  545. if( hole > 0 )
  546. mmStr.Printf( _( "%.2f / %.2f mm" ), diam, hole );
  547. else
  548. mmStr.Printf( _( "%.2f mm" ), diam );
  549. diam = To_User_Unit( INCHES, viaDimension.m_Diameter ) * 1000;
  550. hole = To_User_Unit( INCHES, viaDimension.m_Drill ) * 1000;
  551. if( hole > 0 )
  552. milsStr.Printf( _( "%.1f / %.1f mils" ), diam, hole );
  553. else
  554. milsStr.Printf( _( "%.1f mils" ), diam );
  555. msg.Printf( _( "Via: %s (%s)" ), mmFirst ? mmStr : milsStr, mmFirst ? milsStr : mmStr );
  556. // Mark the netclass via size value (the first in list)
  557. if( ii == 0 )
  558. msg << wxT( " *" );
  559. aViaSizeSelectBox->Append( msg );
  560. }
  561. aViaSizeSelectBox->Append( wxT( "---" ) );
  562. aViaSizeSelectBox->Append( _( "Edit pre-defined sizes..." ) );
  563. if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
  564. GetDesignSettings().SetViaSizeIndex( 0 );
  565. aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  566. }
  567. void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
  568. {
  569. if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
  570. return;
  571. m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
  572. m_SelLayerBox->m_hotkeys = g_Board_Editor_Hotkeys_Descr;
  573. m_SelLayerBox->Resync();
  574. if( aForceResizeToolbar )
  575. {
  576. // the layer box can have its size changed
  577. // Update the aui manager, to take in account the new size
  578. m_auimgr.Update();
  579. }
  580. }
  581. void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
  582. {
  583. int id = event.GetId();
  584. bool state = event.IsChecked();
  585. auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
  586. switch( id )
  587. {
  588. case ID_TB_OPTIONS_DRC_OFF:
  589. Settings().m_legacyDrcOn = !state;
  590. if( GetToolId() == ID_TRACK_BUTT )
  591. {
  592. if( Settings().m_legacyDrcOn )
  593. m_canvas->SetCursor( wxCURSOR_PENCIL );
  594. else
  595. m_canvas->SetCursor( wxCURSOR_QUESTION_ARROW );
  596. }
  597. break;
  598. case ID_TB_OPTIONS_SHOW_RATSNEST:
  599. SetElementVisibility( LAYER_RATSNEST, state );
  600. PCB_BASE_FRAME::OnModify();
  601. Compile_Ratsnest( NULL, true );
  602. if( IsGalCanvasActive() )
  603. {
  604. // keep the ratsnest layer enabled in view, so it shows up when an item is dragged
  605. auto view = GetGalCanvas()->GetView();
  606. view->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  607. view->SetLayerVisible( LAYER_RATSNEST, true );
  608. }
  609. m_canvas->Refresh();
  610. break;
  611. case ID_TB_OPTIONS_SHOW_ZONES:
  612. displ_opts->m_DisplayZonesMode = 0;
  613. m_canvas->Refresh();
  614. break;
  615. case ID_TB_OPTIONS_SHOW_ZONES_DISABLE:
  616. displ_opts->m_DisplayZonesMode = 1;
  617. m_canvas->Refresh();
  618. break;
  619. case ID_TB_OPTIONS_SHOW_ZONES_OUTLINES_ONLY:
  620. displ_opts->m_DisplayZonesMode = 2;
  621. m_canvas->Refresh();
  622. break;
  623. case ID_TB_OPTIONS_SHOW_VIAS_SKETCH:
  624. displ_opts->m_DisplayViaFill = !state;
  625. m_canvas->Refresh();
  626. break;
  627. case ID_TB_OPTIONS_SHOW_TRACKS_SKETCH:
  628. displ_opts->m_DisplayPcbTrackFill = !state;
  629. m_canvas->Refresh();
  630. break;
  631. case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
  632. {
  633. displ_opts->m_ContrastModeDisplay = state;
  634. m_canvas->Refresh();
  635. break;
  636. }
  637. case ID_TB_OPTIONS_SHOW_EXTRA_VERTICAL_TOOLBAR_MICROWAVE:
  638. m_show_microwave_tools = state;
  639. m_auimgr.GetPane( "MicrowaveToolbar" ).Show( m_show_microwave_tools );
  640. m_auimgr.Update();
  641. break;
  642. case ID_TB_OPTIONS_SHOW_MANAGE_LAYERS_VERTICAL_TOOLBAR:
  643. // show auxiliary Vertical layers and visibility manager toolbar
  644. m_show_layer_manager_tools = state;
  645. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  646. m_auimgr.Update();
  647. break;
  648. default:
  649. DisplayErrorMessage( this, "Invalid toolbar option",
  650. "PCB_EDIT_FRAME::OnSelectOptionToolbar error \n (event not handled!)" );
  651. break;
  652. }
  653. }