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.

768 lines
28 KiB

7 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
12 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 <memory>
  27. #include <bitmaps.h>
  28. #include <board.h>
  29. #include <dialog_helpers.h>
  30. #include <kiface_i.h>
  31. #include <macros.h>
  32. #include <pcb_edit_frame.h>
  33. #include <pcb_layer_box_selector.h>
  34. #include <pcbnew_id.h>
  35. #include <pcbnew_settings.h>
  36. #include <pgm_base.h>
  37. #include <router/pns_routing_settings.h>
  38. #include <router/router_tool.h>
  39. #include <settings/color_settings.h>
  40. #include <tool/action_toolbar.h>
  41. #include <tool/actions.h>
  42. #include <tool/common_tools.h>
  43. #include <tool/tool_manager.h>
  44. #include <tools/pcb_actions.h>
  45. #include <tools/pcb_selection_tool.h>
  46. #include <wx/wupdlock.h>
  47. #if defined(KICAD_SCRIPTING) || defined(KICAD_SCRIPTING_WXPYTHON)
  48. #include <python_scripting.h>
  49. #endif
  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 white
  56. // 1 = draw pixel with black
  57. // 2 = draw pixel with top layer from router pair
  58. // 3 = draw pixel with bottom layer from router pair
  59. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3 },
  60. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3 },
  61. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3 },
  62. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3 },
  63. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3 },
  64. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3 },
  65. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3 },
  66. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3 },
  67. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  68. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  69. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  70. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  71. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  72. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  73. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  74. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  75. { 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  76. { 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  77. { 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  78. { 2, 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  79. { 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  80. { 2, 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  81. { 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  82. { 2, 2, 2, 2, 2, 0, 1, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
  83. };
  84. static COLOR4D ICON_WHITE { 0.86, 0.86, 0.86, 1.0 };
  85. static COLOR4D ICON_BLACK { 0.28, 0.28, 0.28, 1.0 };
  86. void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild )
  87. {
  88. int ii, jj;
  89. COLOR4D top_color, bottom_color, background_color;
  90. bool change = aForceRebuild;
  91. int requested_scale = Pgm().GetCommonSettings()->m_Appearance.icon_scale;
  92. if( m_prevIconVal.previous_requested_scale != requested_scale )
  93. {
  94. m_prevIconVal.previous_requested_scale = requested_scale;
  95. change = true;
  96. }
  97. top_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_TOP );
  98. if( m_prevIconVal.previous_Route_Layer_TOP_color != top_color )
  99. {
  100. m_prevIconVal.previous_Route_Layer_TOP_color = top_color;
  101. change = true;
  102. }
  103. bottom_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_BOTTOM );
  104. if( m_prevIconVal.previous_Route_Layer_BOTTOM_color != bottom_color )
  105. {
  106. m_prevIconVal.previous_Route_Layer_BOTTOM_color = bottom_color;
  107. change = true;
  108. }
  109. background_color = GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
  110. if( m_prevIconVal.previous_background_color != background_color )
  111. {
  112. m_prevIconVal.previous_background_color = background_color;
  113. change = true;
  114. }
  115. if( change || !LayerPairBitmap )
  116. {
  117. LayerPairBitmap = std::make_unique<wxBitmap>( 24, 24 );
  118. // Draw the icon, with colors according to the router's layer pair
  119. wxMemoryDC iconDC;
  120. iconDC.SelectObject( *LayerPairBitmap );
  121. wxBrush brush;
  122. wxPen pen;
  123. int buttonColor = -1;
  124. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  125. brush.SetColour( background_color.WithAlpha(1.0).ToColour() );
  126. iconDC.SetBrush( brush );
  127. iconDC.DrawRectangle( 0, 0, BM_LAYERICON_SIZE, BM_LAYERICON_SIZE );
  128. for( ii = 0; ii < BM_LAYERICON_SIZE; ii++ )
  129. {
  130. for( jj = 0; jj < BM_LAYERICON_SIZE; jj++ )
  131. {
  132. if( s_BitmapLayerIcon[ii][jj] != buttonColor )
  133. {
  134. switch( s_BitmapLayerIcon[ii][jj] )
  135. {
  136. default:
  137. case 0: pen.SetColour( ICON_WHITE.ToColour() ); break;
  138. case 1: pen.SetColour( ICON_BLACK.ToColour() ); break;
  139. case 2: pen.SetColour( top_color.ToColour() ); break;
  140. case 3: pen.SetColour( bottom_color.ToColour() ); break;
  141. }
  142. buttonColor = s_BitmapLayerIcon[ii][jj];
  143. iconDC.SetPen( pen );
  144. }
  145. iconDC.DrawPoint( jj, ii );
  146. }
  147. }
  148. // Deselect the bitmap from the DC in order to delete the MemoryDC safely without
  149. // deleting the bitmap
  150. iconDC.SelectObject( wxNullBitmap );
  151. // Scale the bitmap
  152. const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
  153. wxImage image = LayerPairBitmap->ConvertToImage();
  154. // "NEAREST" causes less mixing of colors
  155. image.Rescale( scale * image.GetWidth() / 4, scale * image.GetHeight() / 4,
  156. wxIMAGE_QUALITY_NEAREST );
  157. LayerPairBitmap = std::make_unique<wxBitmap>( image );
  158. if( m_mainToolBar )
  159. {
  160. m_mainToolBar->SetToolBitmap( PCB_ACTIONS::selectLayerPair, *LayerPairBitmap );
  161. m_mainToolBar->Refresh();
  162. }
  163. }
  164. }
  165. void PCB_EDIT_FRAME::ReCreateHToolbar()
  166. {
  167. // Note:
  168. // To rebuild the aui toolbar, the more easy way is to clear ( calling m_mainToolBar.Clear() )
  169. // all wxAuiToolBarItems.
  170. // However the wxAuiToolBarItems are not the owners of controls managed by
  171. // them and therefore do not delete them
  172. // So we do not recreate them after clearing the tools.
  173. wxWindowUpdateLocker dummy( this );
  174. if( m_mainToolBar )
  175. {
  176. m_mainToolBar->ClearToolbar();
  177. }
  178. else
  179. {
  180. m_mainToolBar = new ACTION_TOOLBAR( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  181. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT | wxAUI_TB_HORIZONTAL );
  182. m_mainToolBar->SetAuiManager( &m_auimgr );
  183. // The layer indicator is special, so we register a callback directly that will regenerate the
  184. // bitmap instead of using the conditions system
  185. auto layerIndicatorUpdate =
  186. [this] ( wxUpdateUIEvent& )
  187. {
  188. PrepareLayerIndicator();
  189. };
  190. Bind( wxEVT_UPDATE_UI, layerIndicatorUpdate, PCB_ACTIONS::selectLayerPair.GetUIId() );
  191. }
  192. // Set up toolbar
  193. if( Kiface().IsSingle() )
  194. {
  195. m_mainToolBar->Add( ACTIONS::doNew );
  196. m_mainToolBar->Add( ACTIONS::open );
  197. }
  198. m_mainToolBar->Add( ACTIONS::save );
  199. m_mainToolBar->AddScaledSeparator( this );
  200. m_mainToolBar->Add( PCB_ACTIONS::boardSetup );
  201. m_mainToolBar->AddScaledSeparator( this );
  202. m_mainToolBar->Add( ACTIONS::pageSettings );
  203. m_mainToolBar->Add( ACTIONS::print );
  204. m_mainToolBar->Add( ACTIONS::plot );
  205. m_mainToolBar->AddScaledSeparator( this );
  206. m_mainToolBar->Add( ACTIONS::undo );
  207. m_mainToolBar->Add( ACTIONS::redo );
  208. m_mainToolBar->AddScaledSeparator( this );
  209. m_mainToolBar->Add( ACTIONS::find );
  210. m_mainToolBar->AddScaledSeparator( this );
  211. m_mainToolBar->Add( ACTIONS::zoomRedraw );
  212. m_mainToolBar->Add( ACTIONS::zoomInCenter );
  213. m_mainToolBar->Add( ACTIONS::zoomOutCenter );
  214. m_mainToolBar->Add( ACTIONS::zoomFitScreen );
  215. m_mainToolBar->Add( ACTIONS::zoomFitObjects );
  216. m_mainToolBar->Add( ACTIONS::zoomTool, ACTION_TOOLBAR::TOGGLE, ACTION_TOOLBAR::CANCEL );
  217. m_mainToolBar->AddScaledSeparator( this );
  218. m_mainToolBar->Add( PCB_ACTIONS::rotateCcw );
  219. m_mainToolBar->Add( PCB_ACTIONS::rotateCw );
  220. m_mainToolBar->Add( PCB_ACTIONS::group );
  221. m_mainToolBar->Add( PCB_ACTIONS::ungroup );
  222. m_mainToolBar->Add( PCB_ACTIONS::lock );
  223. m_mainToolBar->Add( PCB_ACTIONS::unlock );
  224. m_mainToolBar->AddScaledSeparator( this );
  225. m_mainToolBar->Add( ACTIONS::showFootprintEditor );
  226. m_mainToolBar->Add( ACTIONS::showFootprintBrowser );
  227. m_mainToolBar->AddScaledSeparator( this );
  228. if( !Kiface().IsSingle() )
  229. {
  230. m_mainToolBar->Add( ACTIONS::updatePcbFromSchematic );
  231. }
  232. else
  233. {
  234. m_mainToolBar->Add( PCB_ACTIONS::importNetlist );
  235. }
  236. m_mainToolBar->Add( PCB_ACTIONS::runDRC );
  237. m_mainToolBar->AddScaledSeparator( this );
  238. if( m_SelLayerBox == nullptr )
  239. {
  240. m_SelLayerBox = new PCB_LAYER_BOX_SELECTOR( m_mainToolBar, ID_TOOLBARH_PCB_SELECT_LAYER );
  241. m_SelLayerBox->SetBoardFrame( this );
  242. }
  243. ReCreateLayerBox( false );
  244. m_mainToolBar->AddControl( m_SelLayerBox );
  245. m_mainToolBar->Add( PCB_ACTIONS::selectLayerPair );
  246. PrepareLayerIndicator( true ); // Force rebuild of the bitmap with the active layer colors
  247. m_mainToolBar->AddScaledSeparator( this );
  248. m_mainToolBar->Add( PCB_ACTIONS::showEeschema );
  249. // Access to the scripting console
  250. #if defined(KICAD_SCRIPTING_WXPYTHON)
  251. if( IsWxPythonLoaded() )
  252. {
  253. m_mainToolBar->AddScaledSeparator( this );
  254. m_mainToolBar->Add( PCB_ACTIONS::showPythonConsole, ACTION_TOOLBAR::TOGGLE );
  255. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  256. AddActionPluginTools();
  257. #endif
  258. }
  259. #endif
  260. // after adding the buttons to the toolbar, must call Realize() to reflect the changes
  261. m_mainToolBar->KiRealize();
  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. {
  274. m_optionsToolBar->ClearToolbar();
  275. }
  276. else
  277. {
  278. m_optionsToolBar = new ACTION_TOOLBAR( this, ID_OPT_TOOLBAR,
  279. wxDefaultPosition, wxDefaultSize,
  280. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  281. m_optionsToolBar->SetAuiManager( &m_auimgr );
  282. }
  283. m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
  284. m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
  285. m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
  286. m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );
  287. m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE );
  288. m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE );
  289. m_optionsToolBar->AddScaledSeparator( this );
  290. m_optionsToolBar->Add( PCB_ACTIONS::showRatsnest, ACTION_TOOLBAR::TOGGLE );
  291. m_optionsToolBar->Add( PCB_ACTIONS::ratsnestLineMode, ACTION_TOOLBAR::TOGGLE );
  292. m_optionsToolBar->AddScaledSeparator( this );
  293. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayEnable, ACTION_TOOLBAR::TOGGLE );
  294. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayDisable, ACTION_TOOLBAR::TOGGLE );
  295. m_optionsToolBar->Add( PCB_ACTIONS::zoneDisplayOutlines, ACTION_TOOLBAR::TOGGLE );
  296. m_optionsToolBar->AddScaledSeparator( this );
  297. m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE );
  298. m_optionsToolBar->Add( PCB_ACTIONS::viaDisplayMode, ACTION_TOOLBAR::TOGGLE );
  299. m_optionsToolBar->Add( PCB_ACTIONS::trackDisplayMode, ACTION_TOOLBAR::TOGGLE );
  300. m_optionsToolBar->Add( ACTIONS::highContrastMode, ACTION_TOOLBAR::TOGGLE );
  301. // Tools to show/hide toolbars:
  302. m_optionsToolBar->AddScaledSeparator( this );
  303. m_optionsToolBar->Add( PCB_ACTIONS::showLayersManager, ACTION_TOOLBAR::TOGGLE );
  304. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  305. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  306. gridMenu->Add( ACTIONS::gridProperties );
  307. m_optionsToolBar->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  308. m_optionsToolBar->KiRealize();
  309. }
  310. void PCB_EDIT_FRAME::ReCreateVToolbar()
  311. {
  312. wxWindowUpdateLocker dummy( this );
  313. if( m_drawToolBar )
  314. {
  315. m_drawToolBar->ClearToolbar();
  316. }
  317. else
  318. {
  319. m_drawToolBar = new ACTION_TOOLBAR( this, ID_V_TOOLBAR, wxDefaultPosition, wxDefaultSize,
  320. KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
  321. m_drawToolBar->SetAuiManager( &m_auimgr );
  322. }
  323. // Groups contained on this toolbar
  324. static ACTION_GROUP* dimensionGroup = nullptr;
  325. static ACTION_GROUP* originGroup = nullptr;
  326. static ACTION_GROUP* routingGroup = nullptr;
  327. static ACTION_GROUP* microwaveGroup = nullptr;
  328. if( !dimensionGroup )
  329. {
  330. dimensionGroup = new ACTION_GROUP( "group.pcbDimensions",
  331. { &PCB_ACTIONS::drawAlignedDimension,
  332. &PCB_ACTIONS::drawOrthogonalDimension,
  333. &PCB_ACTIONS::drawCenterDimension,
  334. &PCB_ACTIONS::drawLeader } );
  335. }
  336. if( !originGroup )
  337. {
  338. originGroup = new ACTION_GROUP( "group.pcbOrigins",
  339. { &PCB_ACTIONS::drillOrigin,
  340. &PCB_ACTIONS::gridSetOrigin } );
  341. }
  342. if( !routingGroup )
  343. {
  344. routingGroup = new ACTION_GROUP( "group.pcbRouting",
  345. { &PCB_ACTIONS::routeSingleTrack,
  346. &PCB_ACTIONS::routeDiffPair } );
  347. }
  348. if( !microwaveGroup )
  349. {
  350. microwaveGroup = new ACTION_GROUP( "group.pcbMicrowave",
  351. { &PCB_ACTIONS::microwaveCreateLine,
  352. &PCB_ACTIONS::microwaveCreateGap,
  353. &PCB_ACTIONS::microwaveCreateStub,
  354. &PCB_ACTIONS::microwaveCreateStubArc,
  355. &PCB_ACTIONS::microwaveCreateFunctionShape } );
  356. }
  357. m_drawToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE );
  358. m_drawToolBar->Add( PCB_ACTIONS::highlightNetTool, ACTION_TOOLBAR::TOGGLE );
  359. m_drawToolBar->Add( PCB_ACTIONS::localRatsnestTool, ACTION_TOOLBAR::TOGGLE );
  360. m_drawToolBar->AddScaledSeparator( this );
  361. m_drawToolBar->Add( PCB_ACTIONS::placeFootprint, ACTION_TOOLBAR::TOGGLE );
  362. m_drawToolBar->AddGroup( routingGroup, ACTION_TOOLBAR::TOGGLE );
  363. m_drawToolBar->Add( PCB_ACTIONS::drawVia, ACTION_TOOLBAR::TOGGLE );
  364. m_drawToolBar->AddGroup( microwaveGroup, ACTION_TOOLBAR::TOGGLE );
  365. m_drawToolBar->Add( PCB_ACTIONS::drawZone, ACTION_TOOLBAR::TOGGLE );
  366. m_drawToolBar->Add( PCB_ACTIONS::drawRuleArea, ACTION_TOOLBAR::TOGGLE );
  367. m_drawToolBar->AddScaledSeparator( this );
  368. m_drawToolBar->Add( PCB_ACTIONS::drawLine, ACTION_TOOLBAR::TOGGLE );
  369. m_drawToolBar->Add( PCB_ACTIONS::drawArc, ACTION_TOOLBAR::TOGGLE );
  370. m_drawToolBar->Add( PCB_ACTIONS::drawRectangle, ACTION_TOOLBAR::TOGGLE );
  371. m_drawToolBar->Add( PCB_ACTIONS::drawCircle, ACTION_TOOLBAR::TOGGLE );
  372. m_drawToolBar->Add( PCB_ACTIONS::drawPolygon, ACTION_TOOLBAR::TOGGLE );
  373. m_drawToolBar->Add( PCB_ACTIONS::placeText, ACTION_TOOLBAR::TOGGLE );
  374. m_drawToolBar->AddGroup( dimensionGroup, ACTION_TOOLBAR::TOGGLE );
  375. m_drawToolBar->Add( PCB_ACTIONS::placeTarget, ACTION_TOOLBAR::TOGGLE );
  376. m_drawToolBar->Add( ACTIONS::deleteTool, ACTION_TOOLBAR::TOGGLE );
  377. m_drawToolBar->AddScaledSeparator( this );
  378. m_drawToolBar->AddGroup( originGroup, ACTION_TOOLBAR::TOGGLE );
  379. m_drawToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE );
  380. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  381. std::unique_ptr<ACTION_MENU> routeMenu = std::make_unique<ACTION_MENU>( false, selTool );
  382. routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK );
  383. routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK );
  384. routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK );
  385. routeMenu->AppendSeparator();
  386. routeMenu->Add( PCB_ACTIONS::routerSettingsDialog );
  387. m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, std::move( routeMenu ) );
  388. std::unique_ptr<ACTION_MENU> zoneMenu = std::make_unique<ACTION_MENU>( false, selTool );
  389. zoneMenu->Add( PCB_ACTIONS::zoneFillAll );
  390. zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll );
  391. m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawZone, std::move( zoneMenu ) );
  392. std::unique_ptr<ACTION_MENU> lineMenu = std::make_unique<ACTION_MENU>( false, selTool );
  393. lineMenu->Add( PCB_ACTIONS::toggleLine45degMode, ACTION_MENU::CHECK );
  394. m_drawToolBar->AddToolContextMenu( PCB_ACTIONS::drawLine, std::move( lineMenu ) );
  395. m_drawToolBar->KiRealize();
  396. }
  397. void PCB_EDIT_FRAME::ReCreateAuxiliaryToolbar()
  398. {
  399. wxWindowUpdateLocker dummy( this );
  400. if( m_auxiliaryToolBar )
  401. {
  402. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  403. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  404. UpdateGridSelectBox();
  405. // combobox sizes can have changed: apply new best sizes
  406. wxAuiToolBarItem* item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_TRACK_WIDTH );
  407. item->SetMinSize( m_SelTrackWidthBox->GetBestSize() );
  408. item = m_auxiliaryToolBar->FindTool( ID_AUX_TOOLBAR_PCB_VIA_SIZE );
  409. item->SetMinSize( m_SelViaSizeBox->GetBestSize() );
  410. m_auxiliaryToolBar->KiRealize();
  411. m_auimgr.Update();
  412. return;
  413. }
  414. m_auxiliaryToolBar = new ACTION_TOOLBAR( this, ID_AUX_TOOLBAR,
  415. wxDefaultPosition, wxDefaultSize,
  416. KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
  417. /* Set up toolbar items */
  418. // Creates box to display and choose tracks widths:
  419. if( m_SelTrackWidthBox == nullptr )
  420. m_SelTrackWidthBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
  421. wxDefaultPosition, wxDefaultSize, 0, NULL );
  422. UpdateTrackWidthSelectBox( m_SelTrackWidthBox );
  423. m_auxiliaryToolBar->AddControl( m_SelTrackWidthBox );
  424. // Creates box to display and choose vias diameters:
  425. if( m_SelViaSizeBox == nullptr )
  426. m_SelViaSizeBox = new wxChoice( m_auxiliaryToolBar, ID_AUX_TOOLBAR_PCB_VIA_SIZE,
  427. wxDefaultPosition, wxDefaultSize, 0, NULL );
  428. UpdateViaSizeSelectBox( m_SelViaSizeBox );
  429. m_auxiliaryToolBar->AddControl( m_SelViaSizeBox );
  430. m_auxiliaryToolBar->AddScaledSeparator( this );
  431. // Creates box to display and choose strategy to handle tracks an vias sizes:
  432. m_auxiliaryToolBar->AddTool( ID_AUX_TOOLBAR_PCB_SELECT_AUTO_WIDTH, wxEmptyString,
  433. KiScaledBitmap( BITMAPS::auto_track_width, this ),
  434. _( "When routing from an existing track use its width instead "
  435. "of the current width setting" ),
  436. wxITEM_CHECK );
  437. // Add the box to display and select the current grid size:
  438. m_auxiliaryToolBar->AddScaledSeparator( this );
  439. if( m_gridSelectBox == nullptr )
  440. m_gridSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_GRID_SELECT,
  441. wxDefaultPosition, wxDefaultSize, 0, NULL );
  442. UpdateGridSelectBox();
  443. m_auxiliaryToolBar->AddControl( m_gridSelectBox );
  444. // Add the box to display and select the current Zoom
  445. m_auxiliaryToolBar->AddScaledSeparator( this );
  446. if( m_zoomSelectBox == nullptr )
  447. m_zoomSelectBox = new wxChoice( m_auxiliaryToolBar, ID_ON_ZOOM_SELECT,
  448. wxDefaultPosition, wxDefaultSize, 0, NULL );
  449. UpdateZoomSelectBox();
  450. m_auxiliaryToolBar->AddControl( m_zoomSelectBox );
  451. // after adding the buttons to the toolbar, must call Realize()
  452. m_auxiliaryToolBar->KiRealize();
  453. }
  454. static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLabel = true )
  455. {
  456. wxString text;
  457. const wxChar* format;
  458. switch( aUnits )
  459. {
  460. default: wxASSERT_MSG( false, "Invalid unit" ); KI_FALLTHROUGH;
  461. case EDA_UNITS::UNSCALED: format = wxT( "%.0f" ); break;
  462. case EDA_UNITS::MILLIMETRES: format = wxT( "%.3f" ); break;
  463. case EDA_UNITS::MILS: format = wxT( "%.2f" ); break;
  464. case EDA_UNITS::INCHES: format = wxT( "%.5f" ); break;
  465. }
  466. text.Printf( format, To_User_Unit( aUnits, aValue ) );
  467. if( aIncludeLabel )
  468. {
  469. text += " ";
  470. text += GetAbbreviatedUnitsLabel( aUnits, EDA_DATA_TYPE::DISTANCE );
  471. }
  472. return text;
  473. }
  474. void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, bool aEdit )
  475. {
  476. if( aTrackWidthSelectBox == NULL )
  477. return;
  478. EDA_UNITS primaryUnit;
  479. EDA_UNITS secondaryUnit;
  480. GetUnitPair( primaryUnit, secondaryUnit );
  481. wxString msg;
  482. aTrackWidthSelectBox->Clear();
  483. aTrackWidthSelectBox->Append( _( "Track: use netclass width" ) );
  484. for( unsigned ii = 1; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
  485. {
  486. int size = GetDesignSettings().m_TrackWidthList[ii];
  487. msg.Printf( _( "Track: %s (%s)" ), ComboBoxUnits( primaryUnit, size ),
  488. ComboBoxUnits( secondaryUnit, size ) );
  489. aTrackWidthSelectBox->Append( msg );
  490. }
  491. if( aEdit )
  492. {
  493. aTrackWidthSelectBox->Append( wxT( "---" ) );
  494. aTrackWidthSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  495. }
  496. if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
  497. GetDesignSettings().SetTrackWidthIndex( 0 );
  498. aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  499. }
  500. void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool aEdit )
  501. {
  502. if( aViaSizeSelectBox == NULL )
  503. return;
  504. aViaSizeSelectBox->Clear();
  505. COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
  506. EDA_UNITS primaryUnit = GetUserUnits();
  507. EDA_UNITS secondaryUnit = EDA_UNITS::MILS;
  508. if( EDA_UNIT_UTILS::IsImperialUnit( primaryUnit ) )
  509. {
  510. if( cmnTool )
  511. secondaryUnit = cmnTool->GetLastMetricUnits();
  512. else
  513. secondaryUnit = EDA_UNITS::MILLIMETRES;
  514. }
  515. else
  516. {
  517. if( cmnTool )
  518. secondaryUnit = cmnTool->GetLastImperialUnits();
  519. else
  520. secondaryUnit = EDA_UNITS::MILS;
  521. }
  522. aViaSizeSelectBox->Append( _( "Via: use netclass sizes" ) );
  523. for( unsigned ii = 1; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
  524. {
  525. VIA_DIMENSION viaDimension = GetDesignSettings().m_ViasDimensionsList[ii];
  526. wxString msg, priStr, secStr;
  527. double diam = viaDimension.m_Diameter;
  528. double hole = viaDimension.m_Drill;
  529. if( hole > 0 )
  530. {
  531. priStr = ComboBoxUnits( primaryUnit, diam, false ) + " / "
  532. + ComboBoxUnits( primaryUnit, hole, true );
  533. secStr = ComboBoxUnits( secondaryUnit, diam, false ) + " / "
  534. + ComboBoxUnits( secondaryUnit, hole, true );
  535. }
  536. else
  537. {
  538. priStr = ComboBoxUnits( primaryUnit, diam, true );
  539. secStr = ComboBoxUnits( secondaryUnit, diam, true );
  540. }
  541. msg.Printf( _( "Via: %s (%s)" ), priStr, secStr );
  542. aViaSizeSelectBox->Append( msg );
  543. }
  544. if( aEdit )
  545. {
  546. aViaSizeSelectBox->Append( wxT( "---" ) );
  547. aViaSizeSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  548. }
  549. if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
  550. GetDesignSettings().SetViaSizeIndex( 0 );
  551. aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  552. }
  553. void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
  554. {
  555. if( m_SelLayerBox == NULL || m_mainToolBar == NULL )
  556. return;
  557. m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
  558. m_SelLayerBox->Resync();
  559. if( aForceResizeToolbar )
  560. {
  561. // the layer box can have its size changed
  562. // Update the aui manager, to take in account the new size
  563. m_auimgr.Update();
  564. }
  565. }
  566. void PCB_EDIT_FRAME::ToggleLayersManager()
  567. {
  568. // show auxiliary Vertical layers and visibility manager toolbar
  569. m_show_layer_manager_tools = !m_show_layer_manager_tools;
  570. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  571. m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
  572. m_auimgr.Update();
  573. }
  574. void PCB_EDIT_FRAME::OnUpdateSelectTrackWidth( wxUpdateUIEvent& aEvent )
  575. {
  576. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_TRACK_WIDTH )
  577. {
  578. BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
  579. int sel;
  580. if( bds.UseCustomTrackViaSize() )
  581. sel = wxNOT_FOUND;
  582. else
  583. sel = bds.GetTrackWidthIndex();
  584. if( m_SelTrackWidthBox->GetSelection() != sel )
  585. m_SelTrackWidthBox->SetSelection( sel );
  586. }
  587. }
  588. void PCB_EDIT_FRAME::OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent )
  589. {
  590. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_VIA_SIZE )
  591. {
  592. BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
  593. int sel = 0;
  594. if( bds.UseCustomTrackViaSize() )
  595. sel = wxNOT_FOUND;
  596. else
  597. sel = bds.GetViaSizeIndex();
  598. if( m_SelViaSizeBox->GetSelection() != sel )
  599. m_SelViaSizeBox->SetSelection( sel );
  600. }
  601. }
  602. void PCB_EDIT_FRAME::OnUpdateSelectAutoWidth( wxUpdateUIEvent& aEvent )
  603. {
  604. BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
  605. aEvent.Check( bds.m_UseConnectedTrackWidth && !bds.UseCustomTrackViaSize() );
  606. }
  607. void PCB_EDIT_FRAME::OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent )
  608. {
  609. if( m_SelLayerBox->GetLayerSelection() != GetActiveLayer() )
  610. m_SelLayerBox->SetLayerSelection( GetActiveLayer() );
  611. }