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.

745 lines
26 KiB

7 years ago
3 years ago
10 months 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
10 months ago
10 months ago
10 months ago
10 months ago
19 years ago
10 months ago
10 months ago
10 months 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, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright The 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 <string>
  28. #include <advanced_config.h>
  29. #include <api/api_plugin_manager.h>
  30. #include <bitmaps.h>
  31. #include <board.h>
  32. #include <board_design_settings.h>
  33. #include <kiface_base.h>
  34. #include <kiplatform/ui.h>
  35. #include <macros.h>
  36. #include <pcb_edit_frame.h>
  37. #include <pcb_layer_box_selector.h>
  38. #include <pcbnew_id.h>
  39. #include <pcbnew_settings.h>
  40. #include <pgm_base.h>
  41. #include <router/pns_routing_settings.h>
  42. #include <router/router_tool.h>
  43. #include <settings/color_settings.h>
  44. #include <tool/action_toolbar.h>
  45. #include <tool/actions.h>
  46. #include <tool/common_tools.h>
  47. #include <tool/tool_manager.h>
  48. #include <tools/pcb_actions.h>
  49. #include <tools/pcb_selection_tool.h>
  50. #include <widgets/appearance_controls.h>
  51. #include <widgets/pcb_design_block_pane.h>
  52. #include <widgets/layer_box_selector.h>
  53. #include <widgets/layer_presentation.h>
  54. #include <widgets/pcb_properties_panel.h>
  55. #include <widgets/net_inspector_panel.h>
  56. #include <widgets/pcb_search_pane.h>
  57. #include <widgets/wx_aui_utils.h>
  58. #include <wx/wupdlock.h>
  59. #include <wx/combobox.h>
  60. #include <toolbars_pcb_editor.h>
  61. #include <settings/settings_manager.h>
  62. #include "../scripting/python_scripting.h"
  63. /* Data to build the layer pair indicator button */
  64. static std::unique_ptr<wxBitmap> LayerPairBitmap;
  65. void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild )
  66. {
  67. COLOR4D top_color, bottom_color, background_color;
  68. bool change = aForceRebuild;
  69. int requested_scale = KiIconScale( this );
  70. if( m_prevIconVal.previous_requested_scale != requested_scale )
  71. {
  72. m_prevIconVal.previous_requested_scale = requested_scale;
  73. change = true;
  74. }
  75. top_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_TOP );
  76. if( m_prevIconVal.previous_Route_Layer_TOP_color != top_color )
  77. {
  78. m_prevIconVal.previous_Route_Layer_TOP_color = top_color;
  79. change = true;
  80. }
  81. bottom_color = GetColorSettings()->GetColor( GetScreen()->m_Route_Layer_BOTTOM );
  82. if( m_prevIconVal.previous_Route_Layer_BOTTOM_color != bottom_color )
  83. {
  84. m_prevIconVal.previous_Route_Layer_BOTTOM_color = bottom_color;
  85. change = true;
  86. }
  87. background_color = GetColorSettings()->GetColor( LAYER_PCB_BACKGROUND );
  88. if( m_prevIconVal.previous_background_color != background_color )
  89. {
  90. m_prevIconVal.previous_background_color = background_color;
  91. change = true;
  92. }
  93. if( change || !LayerPairBitmap )
  94. {
  95. const int scale = ( requested_scale <= 0 ) ? KiIconScale( this ) : requested_scale;
  96. LayerPairBitmap = LAYER_PRESENTATION::CreateLayerPairIcon( background_color, top_color,
  97. bottom_color, scale );
  98. if( m_tbTopAux )
  99. {
  100. m_tbTopAux->SetToolBitmap( PCB_ACTIONS::selectLayerPair, *LayerPairBitmap );
  101. m_tbTopAux->Refresh();
  102. }
  103. }
  104. }
  105. ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::trackWidth( "control.PCBTrackWidth", _( "Track width selector" ),
  106. _( "Control to select the track width" ) );
  107. ACTION_TOOLBAR_CONTROL PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter( "control.PCBViaDia", _( "Via diameter selector" ),
  108. _( "Control to select the via diameter" ) );
  109. std::optional<TOOLBAR_CONFIGURATION> PCB_EDIT_TOOLBAR_SETTINGS::DefaultToolbarConfig( TOOLBAR_LOC aToolbar )
  110. {
  111. TOOLBAR_CONFIGURATION config;
  112. // clang-format off
  113. switch( aToolbar )
  114. {
  115. case TOOLBAR_LOC::LEFT:
  116. config.AppendAction( ACTIONS::toggleGrid )
  117. .AppendAction( ACTIONS::toggleGridOverrides )
  118. .AppendAction( PCB_ACTIONS::togglePolarCoords )
  119. .AppendAction( ACTIONS::inchesUnits )
  120. .AppendAction( ACTIONS::milsUnits )
  121. .AppendAction( ACTIONS::millimetersUnits )
  122. .AppendAction( ACTIONS::toggleCursorStyle );
  123. config.AppendSeparator()
  124. .AppendAction( PCB_ACTIONS::toggleHV45Mode );
  125. config.AppendSeparator()
  126. .AppendAction( PCB_ACTIONS::showRatsnest )
  127. .AppendAction( PCB_ACTIONS::ratsnestLineMode );
  128. config.AppendSeparator()
  129. .AppendAction( ACTIONS::highContrastMode )
  130. .AppendAction( PCB_ACTIONS::toggleNetHighlight );
  131. config.AppendSeparator()
  132. .AppendAction( PCB_ACTIONS::zoneDisplayFilled )
  133. .AppendAction( PCB_ACTIONS::zoneDisplayOutline );
  134. if( ADVANCED_CFG::GetCfg().m_ExtraZoneDisplayModes )
  135. {
  136. config.AppendAction( PCB_ACTIONS::zoneDisplayFractured );
  137. config.AppendAction( PCB_ACTIONS::zoneDisplayTriangulated );
  138. }
  139. config.AppendSeparator()
  140. .AppendAction( PCB_ACTIONS::padDisplayMode )
  141. .AppendAction( PCB_ACTIONS::viaDisplayMode )
  142. .AppendAction( PCB_ACTIONS::trackDisplayMode );
  143. if( ADVANCED_CFG::GetCfg().m_DrawBoundingBoxes )
  144. config.AppendAction( ACTIONS::toggleBoundingBoxes );
  145. // Tools to show/hide toolbars:
  146. config.AppendSeparator()
  147. .AppendAction( PCB_ACTIONS::showLayersManager )
  148. .AppendAction( ACTIONS::showProperties );
  149. /* TODO (ISM): Support context menus in toolbars
  150. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  151. std::unique_ptr<ACTION_MENU> gridMenu = std::make_unique<ACTION_MENU>( false, selTool );
  152. gridMenu->Add( ACTIONS::gridProperties );
  153. gridMenu->Add( ACTIONS::gridOrigin );
  154. m_tbLeft->AddToolContextMenu( ACTIONS::toggleGrid, std::move( gridMenu ) );
  155. */
  156. break;
  157. case TOOLBAR_LOC::RIGHT:
  158. config.AppendAction( ACTIONS::selectionTool )
  159. .AppendAction( PCB_ACTIONS::localRatsnestTool );
  160. config.AppendSeparator()
  161. .AppendAction( PCB_ACTIONS::placeFootprint )
  162. .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track routing tools" ) )
  163. .AddAction( PCB_ACTIONS::routeSingleTrack )
  164. .AddAction( PCB_ACTIONS::routeDiffPair ) )
  165. .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Track tuning tools" ) )
  166. .AddAction( PCB_ACTIONS::tuneSingleTrack )
  167. .AddAction( PCB_ACTIONS::tuneDiffPair )
  168. .AddAction( PCB_ACTIONS::tuneSkew ) )
  169. .AppendAction( PCB_ACTIONS::drawVia )
  170. .AppendAction( PCB_ACTIONS::drawZone )
  171. .AppendAction( PCB_ACTIONS::drawRuleArea );
  172. config.AppendSeparator()
  173. .AppendAction( PCB_ACTIONS::drawLine )
  174. .AppendAction( PCB_ACTIONS::drawArc )
  175. .AppendAction( PCB_ACTIONS::drawRectangle )
  176. .AppendAction( PCB_ACTIONS::drawCircle )
  177. .AppendAction( PCB_ACTIONS::drawPolygon )
  178. .AppendAction( PCB_ACTIONS::drawBezier )
  179. .AppendAction( PCB_ACTIONS::placeReferenceImage )
  180. .AppendAction( PCB_ACTIONS::placeText )
  181. .AppendAction( PCB_ACTIONS::drawTextBox )
  182. .AppendAction( PCB_ACTIONS::drawTable )
  183. .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "Dimension objects" ) )
  184. .AddAction( PCB_ACTIONS::drawOrthogonalDimension )
  185. .AddAction( PCB_ACTIONS::drawAlignedDimension )
  186. .AddAction( PCB_ACTIONS::drawCenterDimension )
  187. .AddAction( PCB_ACTIONS::drawRadialDimension )
  188. .AddAction( PCB_ACTIONS::drawLeader ) )
  189. .AppendAction( ACTIONS::deleteTool );
  190. config.AppendSeparator()
  191. .AppendGroup( TOOLBAR_GROUP_CONFIG( _( "PCB origins" ) )
  192. .AddAction( ACTIONS::gridSetOrigin )
  193. .AddAction( PCB_ACTIONS::drillOrigin ) )
  194. .AppendAction( ACTIONS::measureTool );
  195. /* TODO (ISM): Support context menus
  196. PCB_SELECTION_TOOL* selTool = m_toolManager->GetTool<PCB_SELECTION_TOOL>();
  197. auto makeArcMenu = [&]()
  198. {
  199. std::unique_ptr<ACTION_MENU> arcMenu = std::make_unique<ACTION_MENU>( false, selTool );
  200. arcMenu->Add( PCB_ACTIONS::pointEditorArcKeepCenter, ACTION_MENU::CHECK );
  201. arcMenu->Add( PCB_ACTIONS::pointEditorArcKeepEndpoint, ACTION_MENU::CHECK );
  202. return arcMenu;
  203. };
  204. m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawArc, makeArcMenu() );
  205. auto makeRouteMenu = [&]()
  206. {
  207. std::unique_ptr<ACTION_MENU> routeMenu = std::make_unique<ACTION_MENU>( false, selTool );
  208. routeMenu->Add( PCB_ACTIONS::routerHighlightMode, ACTION_MENU::CHECK );
  209. routeMenu->Add( PCB_ACTIONS::routerShoveMode, ACTION_MENU::CHECK );
  210. routeMenu->Add( PCB_ACTIONS::routerWalkaroundMode, ACTION_MENU::CHECK );
  211. routeMenu->AppendSeparator();
  212. routeMenu->Add( PCB_ACTIONS::routerSettingsDialog );
  213. return routeMenu;
  214. };
  215. m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeSingleTrack, makeRouteMenu() );
  216. m_tbRight->AddToolContextMenu( PCB_ACTIONS::routeDiffPair, makeRouteMenu() );
  217. std::unique_ptr<ACTION_MENU> zoneMenu = std::make_unique<ACTION_MENU>( false, selTool );
  218. zoneMenu->Add( PCB_ACTIONS::zoneFillAll );
  219. zoneMenu->Add( PCB_ACTIONS::zoneUnfillAll );
  220. m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawZone, std::move( zoneMenu ) );
  221. std::unique_ptr<ACTION_MENU> lineMenu = std::make_unique<ACTION_MENU>( false, selTool );
  222. m_tbRight->AddToolContextMenu( PCB_ACTIONS::drawLine, std::move( lineMenu ) );
  223. */
  224. break;
  225. case TOOLBAR_LOC::TOP_MAIN:
  226. if( Kiface().IsSingle() )
  227. {
  228. config.AppendAction( ACTIONS::doNew );
  229. config.AppendAction( ACTIONS::open );
  230. }
  231. config.AppendAction( ACTIONS::save );
  232. config.AppendSeparator()
  233. .AppendAction( PCB_ACTIONS::boardSetup );
  234. config.AppendSeparator()
  235. .AppendAction( ACTIONS::pageSettings )
  236. .AppendAction( ACTIONS::print )
  237. .AppendAction( ACTIONS::plot );
  238. config.AppendSeparator()
  239. .AppendAction( ACTIONS::undo )
  240. .AppendAction( ACTIONS::redo );
  241. config.AppendSeparator()
  242. .AppendAction( ACTIONS::find );
  243. config.AppendSeparator()
  244. .AppendAction( ACTIONS::zoomRedraw )
  245. .AppendAction( ACTIONS::zoomInCenter )
  246. .AppendAction( ACTIONS::zoomOutCenter )
  247. .AppendAction( ACTIONS::zoomFitScreen )
  248. .AppendAction( ACTIONS::zoomFitObjects )
  249. .AppendAction( ACTIONS::zoomTool );
  250. config.AppendSeparator()
  251. .AppendAction( PCB_ACTIONS::rotateCcw )
  252. .AppendAction( PCB_ACTIONS::rotateCw )
  253. .AppendAction( PCB_ACTIONS::mirrorV )
  254. .AppendAction( PCB_ACTIONS::mirrorH )
  255. .AppendAction( ACTIONS::group )
  256. .AppendAction( ACTIONS::ungroup )
  257. .AppendAction( PCB_ACTIONS::lock )
  258. .AppendAction( PCB_ACTIONS::unlock );
  259. config.AppendSeparator()
  260. .AppendAction( ACTIONS::showFootprintEditor )
  261. .AppendAction( ACTIONS::showFootprintBrowser )
  262. .AppendAction( ACTIONS::show3DViewer );
  263. config.AppendSeparator();
  264. if( !Kiface().IsSingle() )
  265. config.AppendAction( ACTIONS::updatePcbFromSchematic );
  266. else
  267. config.AppendAction( PCB_ACTIONS::importNetlist );
  268. config.AppendAction( PCB_ACTIONS::runDRC );
  269. config.AppendSeparator()
  270. .AppendAction( PCB_ACTIONS::showEeschema );
  271. config.AppendControl( ACTION_TOOLBAR_CONTROLS::ipcScripting );
  272. break;
  273. case TOOLBAR_LOC::TOP_AUX:
  274. config.AppendControl( PCB_ACTION_TOOLBAR_CONTROLS::trackWidth )
  275. .AppendAction( PCB_ACTIONS::autoTrackWidth );
  276. config.AppendSeparator()
  277. .AppendControl( PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter );
  278. config.AppendSeparator()
  279. .AppendControl( ACTION_TOOLBAR_CONTROLS::layerSelector )
  280. .AppendAction( PCB_ACTIONS::selectLayerPair );
  281. config.AppendSeparator()
  282. .AppendControl( ACTION_TOOLBAR_CONTROLS::gridSelect );
  283. config.AppendSeparator()
  284. .AppendControl( ACTION_TOOLBAR_CONTROLS::zoomSelect );
  285. break;
  286. }
  287. // clang-format on
  288. return config;
  289. }
  290. void PCB_EDIT_FRAME::configureToolbars()
  291. {
  292. PCB_BASE_EDIT_FRAME::configureToolbars();
  293. // Box to display and choose track widths
  294. auto trackWidthSelectorFactory =
  295. [this]( ACTION_TOOLBAR* aToolbar )
  296. {
  297. if( !m_SelTrackWidthBox )
  298. {
  299. m_SelTrackWidthBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_TRACK_WIDTH,
  300. wxDefaultPosition, wxDefaultSize, 0, nullptr );
  301. }
  302. m_SelTrackWidthBox->SetToolTip( _( "Select the default width for new tracks. Note that this "
  303. "width can be overridden by the board minimum width, or by "
  304. "the width of an existing track if the 'Use Existing Track "
  305. "Width' feature is enabled." ) );
  306. UpdateTrackWidthSelectBox( m_SelTrackWidthBox, true, true );
  307. aToolbar->Add( m_SelTrackWidthBox );
  308. };
  309. RegisterCustomToolbarControlFactory( PCB_ACTION_TOOLBAR_CONTROLS::trackWidth, trackWidthSelectorFactory );
  310. // Box to display and choose vias diameters
  311. auto viaDiaSelectorFactory =
  312. [this]( ACTION_TOOLBAR* aToolbar )
  313. {
  314. if( !m_SelViaSizeBox )
  315. {
  316. m_SelViaSizeBox = new wxChoice( aToolbar, ID_AUX_TOOLBAR_PCB_VIA_SIZE,
  317. wxDefaultPosition, wxDefaultSize, 0, nullptr );
  318. }
  319. UpdateViaSizeSelectBox( m_SelViaSizeBox, true, true );
  320. aToolbar->Add( m_SelViaSizeBox );
  321. };
  322. RegisterCustomToolbarControlFactory( PCB_ACTION_TOOLBAR_CONTROLS::viaDiameter, viaDiaSelectorFactory );
  323. // IPC/Scripting plugin control
  324. // TODO (ISM): Clean this up to make IPC actions just normal tool actions to get rid of this entire
  325. // control
  326. auto pluginControlFactory =
  327. [this]( ACTION_TOOLBAR* aToolbar )
  328. {
  329. // Add scripting console and API plugins
  330. bool scriptingAvailable = SCRIPTING::IsWxAvailable();
  331. #ifdef KICAD_IPC_API
  332. bool haveApiPlugins = Pgm().GetCommonSettings()->m_Api.enable_server &&
  333. !Pgm().GetPluginManager().GetActionsForScope( PluginActionScope() ).empty();
  334. #else
  335. bool haveApiPlugins = false;
  336. #endif
  337. if( scriptingAvailable || haveApiPlugins )
  338. {
  339. aToolbar->AddScaledSeparator( aToolbar->GetParent() );
  340. if( scriptingAvailable )
  341. {
  342. aToolbar->Add( PCB_ACTIONS::showPythonConsole );
  343. addActionPluginTools( aToolbar );
  344. }
  345. if( haveApiPlugins )
  346. AddApiPluginTools( aToolbar );
  347. }
  348. };
  349. RegisterCustomToolbarControlFactory( ACTION_TOOLBAR_CONTROLS::ipcScripting, pluginControlFactory );
  350. }
  351. static wxString ComboBoxUnits( EDA_UNITS aUnits, double aValue, bool aIncludeLabel = true )
  352. {
  353. wxString text;
  354. const wxChar* format;
  355. switch( aUnits )
  356. {
  357. default:
  358. wxASSERT_MSG( false, wxT( "Invalid unit" ) );
  359. KI_FALLTHROUGH;
  360. case EDA_UNITS::UNSCALED: format = wxT( "%.0f" ); break;
  361. case EDA_UNITS::MM: format = wxT( "%.3f" ); break;
  362. case EDA_UNITS::MILS: format = wxT( "%.2f" ); break;
  363. case EDA_UNITS::INCH: format = wxT( "%.5f" ); break;
  364. }
  365. text.Printf( format, EDA_UNIT_UTILS::UI::ToUserUnit( pcbIUScale, aUnits, aValue ) );
  366. if( aIncludeLabel )
  367. text += EDA_UNIT_UTILS::GetText( aUnits, EDA_DATA_TYPE::DISTANCE );
  368. return text;
  369. }
  370. void PCB_EDIT_FRAME::UpdateTrackWidthSelectBox( wxChoice* aTrackWidthSelectBox, bool aShowNetclass,
  371. bool aShowEdit )
  372. {
  373. if( aTrackWidthSelectBox == nullptr )
  374. return;
  375. EDA_UNITS primaryUnit;
  376. EDA_UNITS secondaryUnit;
  377. GetUnitPair( primaryUnit, secondaryUnit );
  378. wxString msg;
  379. aTrackWidthSelectBox->Clear();
  380. if( aShowNetclass )
  381. aTrackWidthSelectBox->Append( _( "Track: use netclass width" ) );
  382. for( unsigned ii = 1; ii < GetDesignSettings().m_TrackWidthList.size(); ii++ )
  383. {
  384. int size = GetDesignSettings().m_TrackWidthList[ii];
  385. msg.Printf( _( "Track: %s (%s)" ), ComboBoxUnits( primaryUnit, size ),
  386. ComboBoxUnits( secondaryUnit, size ) );
  387. aTrackWidthSelectBox->Append( msg );
  388. }
  389. if( aShowEdit )
  390. {
  391. aTrackWidthSelectBox->Append( wxT( "---" ) );
  392. aTrackWidthSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  393. }
  394. if( GetDesignSettings().GetTrackWidthIndex() >= GetDesignSettings().m_TrackWidthList.size() )
  395. GetDesignSettings().SetTrackWidthIndex( 0 );
  396. aTrackWidthSelectBox->SetSelection( GetDesignSettings().GetTrackWidthIndex() );
  397. }
  398. void PCB_EDIT_FRAME::UpdateViaSizeSelectBox( wxChoice* aViaSizeSelectBox, bool aShowNetclass,
  399. bool aShowEdit )
  400. {
  401. if( aViaSizeSelectBox == nullptr )
  402. return;
  403. aViaSizeSelectBox->Clear();
  404. COMMON_TOOLS* cmnTool = m_toolManager->GetTool<COMMON_TOOLS>();
  405. EDA_UNITS primaryUnit = GetUserUnits();
  406. EDA_UNITS secondaryUnit = EDA_UNITS::MILS;
  407. if( EDA_UNIT_UTILS::IsImperialUnit( primaryUnit ) )
  408. secondaryUnit = cmnTool ? cmnTool->GetLastMetricUnits() : EDA_UNITS::MM;
  409. else
  410. secondaryUnit = cmnTool ? cmnTool->GetLastImperialUnits() : EDA_UNITS::MILS;
  411. if( aShowNetclass )
  412. aViaSizeSelectBox->Append( _( "Via: use netclass sizes" ) );
  413. for( unsigned ii = 1; ii < GetDesignSettings().m_ViasDimensionsList.size(); ii++ )
  414. {
  415. VIA_DIMENSION viaDimension = GetDesignSettings().m_ViasDimensionsList[ii];
  416. wxString msg, priStr, secStr;
  417. double diam = viaDimension.m_Diameter;
  418. double hole = viaDimension.m_Drill;
  419. if( hole > 0 )
  420. {
  421. priStr = ComboBoxUnits( primaryUnit, diam, false ) + wxT( " / " )
  422. + ComboBoxUnits( primaryUnit, hole, true );
  423. secStr = ComboBoxUnits( secondaryUnit, diam, false ) + wxT( " / " )
  424. + ComboBoxUnits( secondaryUnit, hole, true );
  425. }
  426. else
  427. {
  428. priStr = ComboBoxUnits( primaryUnit, diam, true );
  429. secStr = ComboBoxUnits( secondaryUnit, diam, true );
  430. }
  431. msg.Printf( _( "Via: %s (%s)" ), priStr, secStr );
  432. aViaSizeSelectBox->Append( msg );
  433. }
  434. if( aShowEdit )
  435. {
  436. aViaSizeSelectBox->Append( wxT( "---" ) );
  437. aViaSizeSelectBox->Append( _( "Edit Pre-defined Sizes..." ) );
  438. }
  439. if( GetDesignSettings().GetViaSizeIndex() >= GetDesignSettings().m_ViasDimensionsList.size() )
  440. GetDesignSettings().SetViaSizeIndex( 0 );
  441. aViaSizeSelectBox->SetSelection( GetDesignSettings().GetViaSizeIndex() );
  442. }
  443. void PCB_EDIT_FRAME::ReCreateLayerBox( bool aForceResizeToolbar )
  444. {
  445. if( m_SelLayerBox == nullptr || m_tbTopAux == nullptr )
  446. return;
  447. m_SelLayerBox->SetToolTip( _( "+/- to switch" ) );
  448. m_SelLayerBox->Resync();
  449. if( aForceResizeToolbar )
  450. UpdateToolbarControlSizes();
  451. }
  452. void PCB_EDIT_FRAME::ToggleLayersManager()
  453. {
  454. PCBNEW_SETTINGS* settings = GetPcbNewSettings();
  455. wxAuiPaneInfo& layersManager = m_auimgr.GetPane( AppearancePanelName() );
  456. wxAuiPaneInfo& selectionFilter = m_auimgr.GetPane( "SelectionFilter" );
  457. // show auxiliary Vertical layers and visibility manager toolbar
  458. m_show_layer_manager_tools = layersManager.IsShown();
  459. m_show_layer_manager_tools = !m_show_layer_manager_tools;
  460. layersManager.Show( m_show_layer_manager_tools );
  461. selectionFilter.Show( m_show_layer_manager_tools );
  462. if( m_show_layer_manager_tools )
  463. {
  464. SetAuiPaneSize( m_auimgr, layersManager, settings->m_AuiPanels.right_panel_width, -1 );
  465. }
  466. else
  467. {
  468. settings->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
  469. m_auimgr.Update();
  470. }
  471. }
  472. void PCB_EDIT_FRAME::ToggleNetInspector()
  473. {
  474. PCBNEW_SETTINGS* settings = GetPcbNewSettings();
  475. wxAuiPaneInfo& netInspectorPanel = m_auimgr.GetPane( NetInspectorPanelName() );
  476. m_show_net_inspector = netInspectorPanel.IsShown();
  477. m_show_net_inspector = !m_show_net_inspector;
  478. netInspectorPanel.Show( m_show_net_inspector );
  479. if( m_show_net_inspector )
  480. {
  481. SetAuiPaneSize( m_auimgr, netInspectorPanel, settings->m_AuiPanels.net_inspector_width,
  482. -1 );
  483. m_netInspectorPanel->OnShowPanel();
  484. }
  485. else
  486. {
  487. m_netInspectorPanel->SaveSettings();
  488. settings->m_AuiPanels.net_inspector_width = m_netInspectorPanel->GetSize().x;
  489. m_auimgr.Update();
  490. }
  491. }
  492. void PCB_EDIT_FRAME::ToggleSearch()
  493. {
  494. PCBNEW_SETTINGS* settings = GetPcbNewSettings();
  495. // Ensure m_show_search is up to date (the pane can be closed outside the menu)
  496. m_show_search = m_auimgr.GetPane( SearchPaneName() ).IsShown();
  497. m_show_search = !m_show_search;
  498. wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
  499. searchPaneInfo.Show( m_show_search );
  500. if( m_show_search )
  501. {
  502. searchPaneInfo.Direction( settings->m_AuiPanels.search_panel_dock_direction );
  503. if( settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_TOP
  504. || settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_BOTTOM )
  505. {
  506. SetAuiPaneSize( m_auimgr, searchPaneInfo,
  507. -1, settings->m_AuiPanels.search_panel_height );
  508. }
  509. else if( settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_LEFT
  510. || settings->m_AuiPanels.search_panel_dock_direction == wxAUI_DOCK_RIGHT )
  511. {
  512. SetAuiPaneSize( m_auimgr, searchPaneInfo,
  513. settings->m_AuiPanels.search_panel_width, -1 );
  514. }
  515. m_searchPane->FocusSearch();
  516. m_searchPane->RefreshSearch();
  517. }
  518. else
  519. {
  520. settings->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
  521. settings->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
  522. settings->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
  523. m_auimgr.Update();
  524. GetCanvas()->SetFocus();
  525. }
  526. }
  527. void PCB_EDIT_FRAME::OnUpdateSelectTrackWidth( wxUpdateUIEvent& aEvent )
  528. {
  529. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_TRACK_WIDTH )
  530. {
  531. BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
  532. int sel;
  533. if( bds.UseCustomTrackViaSize() )
  534. sel = wxNOT_FOUND;
  535. else
  536. sel = bds.GetTrackWidthIndex();
  537. if( m_SelTrackWidthBox->GetSelection() != sel )
  538. m_SelTrackWidthBox->SetSelection( sel );
  539. }
  540. }
  541. void PCB_EDIT_FRAME::OnUpdateSelectViaSize( wxUpdateUIEvent& aEvent )
  542. {
  543. if( aEvent.GetId() == ID_AUX_TOOLBAR_PCB_VIA_SIZE )
  544. {
  545. BOARD_DESIGN_SETTINGS& bds = GetDesignSettings();
  546. int sel = 0;
  547. if( bds.UseCustomTrackViaSize() )
  548. sel = wxNOT_FOUND;
  549. else
  550. sel = bds.GetViaSizeIndex();
  551. if( m_SelViaSizeBox->GetSelection() != sel )
  552. m_SelViaSizeBox->SetSelection( sel );
  553. }
  554. }
  555. void PCB_EDIT_FRAME::ToggleLibraryTree()
  556. {
  557. PCBNEW_SETTINGS* cfg = GetPcbNewSettings();
  558. wxCHECK( cfg, /* void */ );
  559. wxAuiPaneInfo& db_library_pane = m_auimgr.GetPane( DesignBlocksPaneName() );
  560. db_library_pane.Show( !db_library_pane.IsShown() );
  561. if( db_library_pane.IsShown() )
  562. {
  563. if( db_library_pane.IsFloating() )
  564. {
  565. db_library_pane.FloatingSize( cfg->m_AuiPanels.design_blocks_panel_float_width,
  566. cfg->m_AuiPanels.design_blocks_panel_float_height );
  567. m_auimgr.Update();
  568. }
  569. else if( cfg->m_AuiPanels.design_blocks_panel_docked_width > 0 )
  570. {
  571. // SetAuiPaneSize also updates m_auimgr
  572. SetAuiPaneSize( m_auimgr, db_library_pane, cfg->m_AuiPanels.design_blocks_panel_docked_width, -1 );
  573. }
  574. }
  575. else
  576. {
  577. if( db_library_pane.IsFloating() )
  578. {
  579. cfg->m_AuiPanels.design_blocks_panel_float_width = db_library_pane.floating_size.x;
  580. cfg->m_AuiPanels.design_blocks_panel_float_height = db_library_pane.floating_size.y;
  581. }
  582. else
  583. {
  584. cfg->m_AuiPanels.design_blocks_panel_docked_width = m_designBlocksPane->GetSize().x;
  585. }
  586. m_auimgr.Update();
  587. }
  588. }