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.

1349 lines
45 KiB

5 years ago
5 years ago
12 years ago
5 years ago
12 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2015-2016 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software: you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation, either version 3 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include "tools/convert_tool.h"
  23. #include "tools/drawing_tool.h"
  24. #include "tools/edit_tool.h"
  25. #include "tools/footprint_editor_control.h"
  26. #include "tools/pad_tool.h"
  27. #include "tools/pcb_actions.h"
  28. #include "tools/pcb_control.h"
  29. #include "tools/pcb_picker_tool.h"
  30. #include "tools/placement_tool.h"
  31. #include "tools/pcb_point_editor.h"
  32. #include "tools/pcb_selection_tool.h"
  33. #include "tools/properties_tool.h"
  34. #include <python/scripting/pcb_scripting_tool.h>
  35. #include <3d_viewer/eda_3d_viewer_frame.h>
  36. #include <bitmaps.h>
  37. #include <board.h>
  38. #include <footprint.h>
  39. #include <confirm.h>
  40. #include <footprint_edit_frame.h>
  41. #include <footprint_editor_settings.h>
  42. #include <footprint_info_impl.h>
  43. #include <footprint_tree_pane.h>
  44. #include <fp_lib_table.h>
  45. #include <plugins/kicad/pcb_plugin.h>
  46. #include <kiface_base.h>
  47. #include <kiplatform/app.h>
  48. #include <kiway.h>
  49. #include <macros.h>
  50. #include <pcb_draw_panel_gal.h>
  51. #include <pcb_edit_frame.h>
  52. #include <pcbnew.h>
  53. #include <pcbnew_id.h>
  54. #include <pgm_base.h>
  55. #include <project.h>
  56. #include <settings/settings_manager.h>
  57. #include <tool/action_toolbar.h>
  58. #include <tool/common_control.h>
  59. #include <tool/common_tools.h>
  60. #include <tool/selection.h>
  61. #include <tool/tool_dispatcher.h>
  62. #include <tool/tool_manager.h>
  63. #include <tool/zoom_tool.h>
  64. #include <tools/pcb_editor_conditions.h>
  65. #include <tools/pcb_viewer_tools.h>
  66. #include <tools/group_tool.h>
  67. #include <tools/position_relative_tool.h>
  68. #include <widgets/appearance_controls.h>
  69. #include <widgets/lib_tree.h>
  70. #include <widgets/panel_selection_filter.h>
  71. #include <widgets/pcb_properties_panel.h>
  72. #include <widgets/wx_progress_reporters.h>
  73. #include <wildcards_and_files_ext.h>
  74. #include <wx/filedlg.h>
  75. #include <widgets/wx_aui_utils.h>
  76. BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
  77. EVT_MENU( wxID_CLOSE, FOOTPRINT_EDIT_FRAME::CloseFootprintEditor )
  78. EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::OnExitKiCad )
  79. EVT_SIZE( FOOTPRINT_EDIT_FRAME::OnSize )
  80. EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectZoom )
  81. EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectGrid )
  82. EVT_TOOL( ID_FPEDIT_SAVE_PNG, FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng )
  83. EVT_TOOL( ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnLoadFootprintFromBoard )
  84. EVT_TOOL( ID_ADD_FOOTPRINT_TO_BOARD, FOOTPRINT_EDIT_FRAME::OnSaveFootprintToBoard )
  85. // Horizontal toolbar
  86. EVT_MENU( ID_GRID_SETTINGS, FOOTPRINT_EDIT_FRAME::OnGridSettings )
  87. EVT_COMBOBOX( ID_TOOLBARH_PCB_SELECT_LAYER, FOOTPRINT_EDIT_FRAME::SelectLayer )
  88. // UI update events.
  89. EVT_UPDATE_UI( ID_LOAD_FOOTPRINT_FROM_BOARD,
  90. FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard )
  91. EVT_UPDATE_UI( ID_ADD_FOOTPRINT_TO_BOARD,
  92. FOOTPRINT_EDIT_FRAME::OnUpdateSaveFootprintToBoard )
  93. EVT_UPDATE_UI( ID_TOOLBARH_PCB_SELECT_LAYER, FOOTPRINT_EDIT_FRAME::OnUpdateLayerSelectBox )
  94. // Drop files event
  95. EVT_DROP_FILES( FOOTPRINT_EDIT_FRAME::OnDropFiles )
  96. END_EVENT_TABLE()
  97. FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  98. PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_FOOTPRINT_EDITOR, wxEmptyString,
  99. wxDefaultPosition, wxDefaultSize,
  100. KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() ),
  101. m_show_layer_manager_tools( true )
  102. {
  103. m_showBorderAndTitleBlock = false; // true to show the frame references
  104. m_aboutTitle = _HKI( "KiCad Footprint Editor" );
  105. m_selLayerBox = nullptr;
  106. m_editorSettings = nullptr;
  107. // Give an icon
  108. wxIcon icon;
  109. wxIconBundle icon_bundle;
  110. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit ) );
  111. icon_bundle.AddIcon( icon );
  112. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit_32 ) );
  113. icon_bundle.AddIcon( icon );
  114. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_modedit_16 ) );
  115. icon_bundle.AddIcon( icon );
  116. SetIcons( icon_bundle );
  117. // Create GAL canvas
  118. m_canvasType = loadCanvasTypeSetting();
  119. PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_frameSize,
  120. GetGalDisplayOptions(), m_canvasType );
  121. SetCanvas( drawPanel );
  122. SetBoard( new BOARD() );
  123. // This board will only be used to hold a footprint for editing
  124. GetBoard()->SetBoardUse( BOARD_USE::FPHOLDER );
  125. // In Footprint Editor, the default net clearance is not known (it depends on the actual
  126. // board). So we do not show the default clearance, by setting it to 0. The footprint or
  127. // pad specific clearance will be shown.
  128. GetBoard()->GetDesignSettings().m_NetSettings->m_DefaultNetClass->SetClearance( 0 );
  129. // Don't show the default board solder mask expansion in the footprint editor. Only the
  130. // footprint or pad mask expansions settings should be shown.
  131. GetBoard()->GetDesignSettings().m_SolderMaskExpansion = 0;
  132. // restore the last footprint from the project, if any
  133. restoreLastFootprint();
  134. // Ensure all layers and items are visible:
  135. // In footprint editor, some layers have no meaning or cannot be used, but we show all of
  136. // them, at least to be able to edit a bad layer
  137. GetBoard()->SetVisibleAlls();
  138. GetGalDisplayOptions().m_axesEnabled = true;
  139. // In Footprint Editor, set the default paper size to A4 for plot/print
  140. SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
  141. SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS ) ) );
  142. // Create the manager and dispatcher & route draw panel events to the dispatcher
  143. setupTools();
  144. setupUIConditions();
  145. initLibraryTree();
  146. m_treePane = new FOOTPRINT_TREE_PANE( this );
  147. ReCreateMenuBar();
  148. ReCreateHToolbar();
  149. ReCreateVToolbar();
  150. ReCreateOptToolbar();
  151. m_selectionFilterPanel = new PANEL_SELECTION_FILTER( this );
  152. m_appearancePanel = new APPEARANCE_CONTROLS( this, GetCanvas(), true );
  153. m_propertiesPanel = new PCB_PROPERTIES_PANEL( this, this );
  154. // LoadSettings() *after* creating m_LayersManager, because LoadSettings() initialize
  155. // parameters in m_LayersManager
  156. // NOTE: KifaceSettings() will return PCBNEW_SETTINGS if we started from pcbnew
  157. LoadSettings( GetSettings() );
  158. float proportion = GetFootprintEditorSettings()->m_AuiPanels.properties_splitter_proportion;
  159. m_propertiesPanel->SetSplitterProportion( proportion );
  160. // Must be set after calling LoadSettings() to be sure these parameters are not dependent
  161. // on what is read in stored settings. Enable one internal layer, because footprints
  162. // support keepout areas that can be on internal layers only (therefore on the first internal
  163. // layer). This is needed to handle these keepout in internal layers only.
  164. GetBoard()->SetCopperLayerCount( 3 );
  165. GetBoard()->SetEnabledLayers( GetBoard()->GetEnabledLayers().set( In1_Cu ) );
  166. GetBoard()->SetVisibleLayers( GetBoard()->GetEnabledLayers() );
  167. GetBoard()->SetLayerName( In1_Cu, _( "Inner layers" ) );
  168. SetActiveLayer( F_SilkS );
  169. m_auimgr.SetManagedWindow( this );
  170. CreateInfoBar();
  171. unsigned int auiFlags = wxAUI_MGR_DEFAULT;
  172. #if !defined( _WIN32 )
  173. // Windows cannot redraw the UI fast enough during a live resize and may lead to all kinds
  174. // of graphical glitches
  175. auiFlags |= wxAUI_MGR_LIVE_RESIZE;
  176. #endif
  177. m_auimgr.SetFlags( auiFlags );
  178. // Rows; layers 4 - 6
  179. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" )
  180. .Top().Layer( 6 ) );
  181. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" )
  182. .Bottom().Layer( 6 ) );
  183. // Columns; layers 1 - 3
  184. m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "Footprints" )
  185. .Left().Layer( 4 )
  186. .Caption( _( "Libraries" ) )
  187. .MinSize( 250, -1 ).BestSize( 250, -1 ) );
  188. m_auimgr.AddPane( m_propertiesPanel, EDA_PANE().Name( wxS( "PropertiesManager" ) )
  189. .Left().Layer( 3 ).Caption( _( "Properties" ) )
  190. .PaneBorder( false ).MinSize( 240, -1 ).BestSize( 300, -1 ) );
  191. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" )
  192. .Left().Layer( 2 ) );
  193. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
  194. .Right().Layer(2) );
  195. m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
  196. .Right().Layer( 3 )
  197. .Caption( _( "Appearance" ) ).PaneBorder( false )
  198. .MinSize( 180, -1 ).BestSize( 180, -1 ) );
  199. m_auimgr.AddPane( m_selectionFilterPanel, EDA_PANE().Palette().Name( "SelectionFilter" )
  200. .Right().Layer( 3 ).Position( 2 )
  201. .Caption( _( "Selection Filter" ) ).PaneBorder( false )
  202. .MinSize( 160, -1 ).BestSize( m_selectionFilterPanel->GetBestSize() ) );
  203. // Center
  204. m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" )
  205. .Center() );
  206. m_auimgr.GetPane( "LayersManager" ).Show( m_show_layer_manager_tools );
  207. m_auimgr.GetPane( "SelectionFilter" ).Show( m_show_layer_manager_tools );
  208. m_auimgr.GetPane( "PropertiesManager" ).Show( m_show_properties );
  209. // The selection filter doesn't need to grow in the vertical direction when docked
  210. m_auimgr.GetPane( "SelectionFilter" ).dock_proportion = 0;
  211. m_acceptedExts.emplace( KiCadFootprintLibPathExtension, &ACTIONS::ddAddLibrary );
  212. m_acceptedExts.emplace( KiCadFootprintFileExtension, &PCB_ACTIONS::ddImportFootprint );
  213. DragAcceptFiles( true );
  214. ActivateGalCanvas();
  215. FinishAUIInitialization();
  216. // Apply saved visibility stuff at the end
  217. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  218. wxAuiPaneInfo& treePane = m_auimgr.GetPane( "Footprints" );
  219. wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
  220. // wxAUI hack: force widths by setting MinSize() and then Fixed()
  221. // thanks to ZenJu http://trac.wxwidgets.org/ticket/13180
  222. if( cfg->m_LibWidth > 0 )
  223. {
  224. SetAuiPaneSize( m_auimgr, treePane, cfg->m_LibWidth, -1 );
  225. treePane.MinSize( cfg->m_LibWidth, -1 );
  226. treePane.Fixed();
  227. }
  228. if( cfg->m_AuiPanels.right_panel_width > 0 )
  229. {
  230. SetAuiPaneSize( m_auimgr, layersManager, cfg->m_AuiPanels.right_panel_width, -1 );
  231. layersManager.MinSize( cfg->m_LibWidth, -1 );
  232. layersManager.Fixed();
  233. }
  234. // Apply fixed sizes
  235. m_auimgr.Update();
  236. // Now make them resizable again
  237. treePane.Resizable();
  238. m_auimgr.Update();
  239. // Note: DO NOT call m_auimgr.Update() anywhere after this; it will nuke the sizes
  240. // back to minimum.
  241. treePane.MinSize( 250, -1 );
  242. layersManager.MinSize( 250, -1 );
  243. m_appearancePanel->SetUserLayerPresets( cfg->m_LayerPresets );
  244. m_appearancePanel->ApplyLayerPreset( cfg->m_ActiveLayerPreset );
  245. m_appearancePanel->SetTabIndex( cfg->m_AuiPanels.appearance_panel_tab );
  246. GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false );
  247. UpdateTitle();
  248. setupUnits( GetSettings() );
  249. resolveCanvasType();
  250. // Default shutdown reason until a file is loaded
  251. KIPLATFORM::APP::SetShutdownBlockReason( this, _( "Footprint changes are unsaved" ) );
  252. // Catch unhandled accelerator command characters that were no handled by the library tree
  253. // panel.
  254. Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
  255. Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
  256. // Ensure the window is on top
  257. Raise();
  258. Show( true );
  259. // Register a call to update the toolbar sizes. It can't be done immediately because
  260. // it seems to require some sizes calculated that aren't yet (at least on GTK).
  261. CallAfter(
  262. [&]()
  263. {
  264. // Ensure the controls on the toolbars all are correctly sized
  265. UpdateToolbarControlSizes();
  266. m_treePane->FocusSearchFieldIfExists();
  267. } );
  268. }
  269. FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
  270. {
  271. // Shutdown all running tools
  272. if( m_toolManager )
  273. m_toolManager->ShutdownAllTools();
  274. // save the footprint in the PROJECT
  275. retainLastFootprint();
  276. delete m_selectionFilterPanel;
  277. delete m_appearancePanel;
  278. delete m_treePane;
  279. }
  280. void FOOTPRINT_EDIT_FRAME::UpdateMsgPanel()
  281. {
  282. EDA_DRAW_FRAME::UpdateMsgPanel();
  283. FOOTPRINT* fp = static_cast<FOOTPRINT*>( GetModel() );
  284. if( fp )
  285. {
  286. std::vector<MSG_PANEL_ITEM> msgItems;
  287. fp->GetMsgPanelInfo( this, msgItems );
  288. SetMsgPanel( msgItems );
  289. }
  290. }
  291. bool FOOTPRINT_EDIT_FRAME::IsContentModified() const
  292. {
  293. return GetScreen() && GetScreen()->IsContentModified()
  294. && GetBoard() && GetBoard()->GetFirstFootprint();
  295. }
  296. SELECTION& FOOTPRINT_EDIT_FRAME::GetCurrentSelection()
  297. {
  298. return m_toolManager->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
  299. }
  300. void FOOTPRINT_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
  301. {
  302. // switches currently used canvas (Cairo / OpenGL).
  303. PCB_BASE_FRAME::SwitchCanvas( aCanvasType );
  304. GetCanvas()->GetGAL()->SetAxesEnabled( true );
  305. // The base class method *does not reinit* the layers manager. We must update the layer
  306. // widget to match board visibility states, both layers and render columns, and and some
  307. // settings dependent on the canvas.
  308. UpdateUserInterface();
  309. }
  310. void FOOTPRINT_EDIT_FRAME::HardRedraw()
  311. {
  312. SyncLibraryTree( true );
  313. GetCanvas()->ForceRefresh();
  314. }
  315. void FOOTPRINT_EDIT_FRAME::ToggleSearchTree()
  316. {
  317. wxAuiPaneInfo& treePane = m_auimgr.GetPane( m_treePane );
  318. treePane.Show( !IsSearchTreeShown() );
  319. if( IsSearchTreeShown() )
  320. {
  321. // SetAuiPaneSize also updates m_auimgr
  322. SetAuiPaneSize( m_auimgr, treePane, m_editorSettings->m_LibWidth, -1 );
  323. }
  324. else
  325. {
  326. m_editorSettings->m_LibWidth = m_treePane->GetSize().x;
  327. m_auimgr.Update();
  328. }
  329. }
  330. void FOOTPRINT_EDIT_FRAME::ToggleLayersManager()
  331. {
  332. FOOTPRINT_EDITOR_SETTINGS* settings = GetSettings();
  333. wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
  334. wxAuiPaneInfo& selectionFilter = m_auimgr.GetPane( "SelectionFilter" );
  335. // show auxiliary Vertical layers and visibility manager toolbar
  336. m_show_layer_manager_tools = !m_show_layer_manager_tools;
  337. layersManager.Show( m_show_layer_manager_tools );
  338. selectionFilter.Show( m_show_layer_manager_tools );
  339. if( m_show_layer_manager_tools )
  340. {
  341. SetAuiPaneSize( m_auimgr, layersManager, settings->m_AuiPanels.right_panel_width, -1 );
  342. }
  343. else
  344. {
  345. settings->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
  346. m_auimgr.Update();
  347. }
  348. }
  349. bool FOOTPRINT_EDIT_FRAME::IsSearchTreeShown() const
  350. {
  351. return const_cast<wxAuiManager&>( m_auimgr ).GetPane( m_treePane ).IsShown();
  352. }
  353. BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const
  354. {
  355. return GetBoard()->GetFirstFootprint();
  356. }
  357. LIB_ID FOOTPRINT_EDIT_FRAME::GetTreeFPID() const
  358. {
  359. return m_treePane->GetLibTree()->GetSelectedLibId();
  360. }
  361. LIB_TREE_NODE* FOOTPRINT_EDIT_FRAME::GetCurrentTreeNode() const
  362. {
  363. return m_treePane->GetLibTree()->GetCurrentTreeNode();
  364. }
  365. LIB_ID FOOTPRINT_EDIT_FRAME::GetTargetFPID() const
  366. {
  367. LIB_ID id;
  368. if( IsSearchTreeShown() )
  369. id = GetTreeFPID();
  370. if( id.GetLibNickname().empty() )
  371. id = GetLoadedFPID();
  372. return id;
  373. }
  374. LIB_ID FOOTPRINT_EDIT_FRAME::GetLoadedFPID() const
  375. {
  376. FOOTPRINT* footprint = GetBoard()->GetFirstFootprint();
  377. if( footprint )
  378. return LIB_ID( footprint->GetFPID().GetLibNickname(), m_footprintNameWhenLoaded );
  379. else
  380. return LIB_ID();
  381. }
  382. void FOOTPRINT_EDIT_FRAME::ClearModify()
  383. {
  384. if( GetBoard()->GetFirstFootprint() )
  385. m_footprintNameWhenLoaded = GetBoard()->GetFirstFootprint()->GetFPID().GetLibItemName();
  386. GetScreen()->SetContentModified( false );
  387. }
  388. bool FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard() const
  389. {
  390. // If we've already vetted closing this window, then we have no FP anymore
  391. if( m_isClosing )
  392. return false;
  393. FOOTPRINT* footprint = GetBoard()->GetFirstFootprint();
  394. return ( footprint && footprint->GetLink() != niluuid );
  395. }
  396. void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
  397. {
  398. LIB_ID id = GetLoadedFPID();
  399. if( id.IsValid() )
  400. {
  401. Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_LIB_NICKNAME, id.GetLibNickname() );
  402. Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FP_NAME, id.GetLibItemName() );
  403. }
  404. }
  405. void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
  406. {
  407. const wxString& footprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FP_NAME );
  408. const wxString& libNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_LIB_NICKNAME );
  409. if( libNickname.Length() && footprintName.Length() )
  410. {
  411. LIB_ID id;
  412. id.SetLibNickname( libNickname );
  413. id.SetLibItemName( footprintName );
  414. FOOTPRINT* footprint = loadFootprint( id );
  415. if( footprint )
  416. AddFootprintToBoard( footprint );
  417. }
  418. }
  419. void FOOTPRINT_EDIT_FRAME::AddFootprintToBoard( FOOTPRINT* aFootprint )
  420. {
  421. m_originalFootprintCopy.reset( static_cast<FOOTPRINT*>( aFootprint->Clone() ) );
  422. m_originalFootprintCopy->SetParent( nullptr );
  423. m_footprintNameWhenLoaded = aFootprint->GetFPID().GetLibItemName();
  424. PCB_BASE_EDIT_FRAME::AddFootprintToBoard( aFootprint );
  425. // Ensure item UUIDs are valid
  426. // ("old" footprints can have null uuids that create issues in fp editor)
  427. aFootprint->FixUuids();
  428. if( IsCurrentFPFromBoard() )
  429. {
  430. wxString msg;
  431. msg.Printf( _( "Editing %s from board. Saving will update the board only." ),
  432. aFootprint->GetReference() );
  433. GetInfoBar()->RemoveAllButtons();
  434. GetInfoBar()->AddCloseButton();
  435. GetInfoBar()->ShowMessage( msg, wxICON_INFORMATION );
  436. }
  437. else
  438. {
  439. GetInfoBar()->Dismiss();
  440. }
  441. UpdateMsgPanel();
  442. }
  443. const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
  444. {
  445. return FOOTPRINT_EDIT_FRAME_NAME;
  446. }
  447. BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const
  448. {
  449. return GetBoard()->GetDesignSettings();
  450. }
  451. const PCB_PLOT_PARAMS& FOOTPRINT_EDIT_FRAME::GetPlotSettings() const
  452. {
  453. wxFAIL_MSG( wxT( "Plotting not supported in Footprint Editor" ) );
  454. return PCB_BASE_FRAME::GetPlotSettings();
  455. }
  456. void FOOTPRINT_EDIT_FRAME::SetPlotSettings( const PCB_PLOT_PARAMS& aSettings )
  457. {
  458. wxFAIL_MSG( wxT( "Plotting not supported in Footprint Editor" ) );
  459. }
  460. FOOTPRINT_EDITOR_SETTINGS* FOOTPRINT_EDIT_FRAME::GetSettings()
  461. {
  462. if( !m_editorSettings )
  463. m_editorSettings = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  464. return m_editorSettings;
  465. }
  466. APP_SETTINGS_BASE* FOOTPRINT_EDIT_FRAME::config() const
  467. {
  468. return m_editorSettings ? m_editorSettings
  469. : Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  470. }
  471. void FOOTPRINT_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  472. {
  473. // Get our own settings; aCfg will be the PCBNEW_SETTINGS because we're part of the pcbnew
  474. // compile unit
  475. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  476. if( cfg )
  477. {
  478. PCB_BASE_FRAME::LoadSettings( cfg );
  479. GetDesignSettings() = cfg->m_DesignSettings;
  480. m_displayOptions = cfg->m_Display;
  481. m_show_layer_manager_tools = cfg->m_AuiPanels.show_layer_manager;
  482. m_show_properties = cfg->m_AuiPanels.show_properties;
  483. GetToolManager()->GetTool<PCB_SELECTION_TOOL>()->GetFilter() = cfg->m_SelectionFilter;
  484. m_selectionFilterPanel->SetCheckboxesFromFilter( cfg->m_SelectionFilter );
  485. }
  486. }
  487. void FOOTPRINT_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  488. {
  489. GetGalDisplayOptions().m_axesEnabled = true;
  490. // Get our own settings; aCfg will be the PCBNEW_SETTINGS because we're part of the pcbnew
  491. // compile unit
  492. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  493. if( cfg )
  494. {
  495. PCB_BASE_FRAME::SaveSettings( cfg );
  496. cfg->m_DesignSettings = GetDesignSettings();
  497. cfg->m_Display = m_displayOptions;
  498. cfg->m_LibWidth = m_treePane->GetSize().x;
  499. cfg->m_SelectionFilter = GetToolManager()->GetTool<PCB_SELECTION_TOOL>()->GetFilter();
  500. cfg->m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
  501. cfg->m_ActiveLayerPreset = m_appearancePanel->GetActiveLayerPreset();
  502. cfg->m_AuiPanels.show_layer_manager = m_show_layer_manager_tools;
  503. cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
  504. cfg->m_AuiPanels.appearance_panel_tab = m_appearancePanel->GetTabIndex();
  505. cfg->m_AuiPanels.show_properties = m_show_properties;
  506. cfg->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
  507. cfg->m_AuiPanels.properties_splitter_proportion =
  508. m_propertiesPanel->SplitterProportion();
  509. }
  510. }
  511. EDA_ANGLE FOOTPRINT_EDIT_FRAME::GetRotationAngle() const
  512. {
  513. FOOTPRINT_EDITOR_SETTINGS* cfg = const_cast<FOOTPRINT_EDIT_FRAME*>( this )->GetSettings();
  514. return cfg ? cfg->m_RotationAngle : ANGLE_90;
  515. }
  516. COLOR_SETTINGS* FOOTPRINT_EDIT_FRAME::GetColorSettings( bool aForceRefresh ) const
  517. {
  518. wxString currentTheme = GetFootprintEditorSettings()->m_ColorTheme;
  519. return Pgm().GetSettingsManager().GetColorSettings( currentTheme );
  520. }
  521. MAGNETIC_SETTINGS* FOOTPRINT_EDIT_FRAME::GetMagneticItemsSettings()
  522. {
  523. // Get the actual frame settings for magnetic items
  524. FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings();
  525. wxCHECK( cfg, nullptr );
  526. return &cfg->m_MagneticItems;
  527. }
  528. const BOX2I FOOTPRINT_EDIT_FRAME::GetDocumentExtents( bool aIncludeAllVisible ) const
  529. {
  530. FOOTPRINT* footprint = GetBoard()->GetFirstFootprint();
  531. if( footprint )
  532. {
  533. bool hasGraphicalItem = footprint->Pads().size() || footprint->Zones().size();
  534. if( !hasGraphicalItem )
  535. {
  536. for( const BOARD_ITEM* item : footprint->GraphicalItems() )
  537. {
  538. if( item->Type() == PCB_TEXT_T )
  539. continue;
  540. hasGraphicalItem = true;
  541. break;
  542. }
  543. }
  544. if( hasGraphicalItem )
  545. {
  546. return footprint->GetBoundingBox( false, false );
  547. }
  548. else
  549. {
  550. BOX2I newFootprintBB( { 0, 0 }, { 0, 0 } );
  551. newFootprintBB.Inflate( pcbIUScale.mmToIU( 12 ) );
  552. return newFootprintBB;
  553. }
  554. }
  555. return GetBoardBoundingBox( false );
  556. }
  557. bool FOOTPRINT_EDIT_FRAME::CanCloseFPFromBoard( bool doClose )
  558. {
  559. if( IsContentModified() )
  560. {
  561. wxString footprintName = GetBoard()->GetFirstFootprint()->GetReference();
  562. wxString msg = _( "Save changes to '%s' before closing?" );
  563. if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
  564. [&]() -> bool
  565. {
  566. return SaveFootprint( GetBoard()->GetFirstFootprint() );
  567. } ) )
  568. {
  569. return false;
  570. }
  571. }
  572. if( doClose )
  573. {
  574. GetInfoBar()->ShowMessageFor( wxEmptyString, 1 );
  575. Clear_Pcb( false );
  576. UpdateTitle();
  577. }
  578. return true;
  579. }
  580. bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
  581. {
  582. if( IsContentModified() )
  583. {
  584. // Shutdown blocks must be determined and vetoed as early as possible
  585. if( KIPLATFORM::APP::SupportsShutdownBlockReason() &&
  586. aEvent.GetId() == wxEVT_QUERY_END_SESSION )
  587. {
  588. aEvent.Veto();
  589. return false;
  590. }
  591. wxString footprintName = GetBoard()->GetFirstFootprint()->GetFPID().GetLibItemName();
  592. if( IsCurrentFPFromBoard() )
  593. footprintName = GetBoard()->GetFirstFootprint()->GetReference();
  594. wxString msg = _( "Save changes to '%s' before closing?" );
  595. if( !HandleUnsavedChanges( this, wxString::Format( msg, footprintName ),
  596. [&]() -> bool
  597. {
  598. return SaveFootprint( GetBoard()->GetFirstFootprint() );
  599. } ) )
  600. {
  601. aEvent.Veto();
  602. return false;
  603. }
  604. }
  605. // Save footprint tree column widths
  606. m_adapter->SaveSettings();
  607. return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent );
  608. }
  609. void FOOTPRINT_EDIT_FRAME::doCloseWindow()
  610. {
  611. // No more vetos
  612. GetCanvas()->SetEventDispatcher( nullptr );
  613. GetCanvas()->StopDrawing();
  614. // Do not show the layer manager during closing to avoid flicker
  615. // on some platforms (Windows) that generate useless redraw of items in
  616. // the Layer Manager
  617. m_auimgr.GetPane( wxT( "LayersManager" ) ).Show( false );
  618. m_auimgr.GetPane( wxT( "SelectionFilter" ) ).Show( false );
  619. Clear_Pcb( false );
  620. SETTINGS_MANAGER* mgr = GetSettingsManager();
  621. if( mgr->IsProjectOpen() && wxFileName::IsDirWritable( Prj().GetProjectPath() ) )
  622. {
  623. GFootprintList.WriteCacheToFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
  624. }
  625. mgr->FlushAndRelease( GetSettings() );
  626. }
  627. void FOOTPRINT_EDIT_FRAME::OnExitKiCad( wxCommandEvent& event )
  628. {
  629. Kiway().OnKiCadExit();
  630. }
  631. void FOOTPRINT_EDIT_FRAME::CloseFootprintEditor( wxCommandEvent& Event )
  632. {
  633. Close();
  634. }
  635. void FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard( wxUpdateUIEvent& aEvent )
  636. {
  637. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
  638. aEvent.Enable( frame && frame->GetBoard()->GetFirstFootprint() != nullptr );
  639. }
  640. void FOOTPRINT_EDIT_FRAME::OnUpdateSaveFootprintToBoard( wxUpdateUIEvent& aEvent )
  641. {
  642. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB_EDITOR, false );
  643. FOOTPRINT* editorFootprint = GetBoard()->GetFirstFootprint();
  644. bool canInsert = frame && editorFootprint && editorFootprint->GetLink() == niluuid;
  645. // If the source was deleted, the footprint can inserted but not updated in the board.
  646. if( frame && editorFootprint && editorFootprint->GetLink() != niluuid )
  647. {
  648. BOARD* mainpcb = frame->GetBoard();
  649. canInsert = true;
  650. // search if the source footprint was not deleted:
  651. for( FOOTPRINT* candidate : mainpcb->Footprints() )
  652. {
  653. if( editorFootprint->GetLink() == candidate->m_Uuid )
  654. {
  655. canInsert = false;
  656. break;
  657. }
  658. }
  659. }
  660. aEvent.Enable( canInsert );
  661. }
  662. void FOOTPRINT_EDIT_FRAME::ShowChangedLanguage()
  663. {
  664. // call my base class
  665. PCB_BASE_EDIT_FRAME::ShowChangedLanguage();
  666. // We have 2 panes to update.
  667. // For some obscure reason, the AUI manager hides the first modified pane.
  668. // So force show panes
  669. wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
  670. bool tree_shown = tree_pane_info.IsShown();
  671. tree_pane_info.Caption( _( "Libraries" ) );
  672. wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_appearancePanel );
  673. bool lm_shown = lm_pane_info.IsShown();
  674. lm_pane_info.Caption( _( "Appearance" ) );
  675. wxAuiPaneInfo& sf_pane_info = m_auimgr.GetPane( m_selectionFilterPanel );
  676. sf_pane_info.Caption( _( "Selection Filter" ) );
  677. // update the layer manager
  678. m_appearancePanel->OnLanguageChanged();
  679. m_selectionFilterPanel->OnLanguageChanged();
  680. UpdateUserInterface();
  681. // Now restore the visibility:
  682. lm_pane_info.Show( lm_shown );
  683. tree_pane_info.Show( tree_shown );
  684. m_auimgr.Update();
  685. UpdateTitle();
  686. }
  687. void FOOTPRINT_EDIT_FRAME::OnModify()
  688. {
  689. PCB_BASE_FRAME::OnModify();
  690. Update3DView( true, true );
  691. m_treePane->GetLibTree()->RefreshLibTree();
  692. if( !GetTitle().StartsWith( wxT( "*" ) ) )
  693. UpdateTitle();
  694. }
  695. void FOOTPRINT_EDIT_FRAME::UpdateTitle()
  696. {
  697. wxString title;
  698. LIB_ID fpid = GetLoadedFPID();
  699. FOOTPRINT* footprint = GetBoard()->GetFirstFootprint();
  700. bool writable = true;
  701. if( IsCurrentFPFromBoard() )
  702. {
  703. if( IsContentModified() )
  704. title = wxT( "*" );
  705. title += footprint->GetReference();
  706. title += wxS( " " ) + wxString::Format( _( "[from %s]" ), Prj().GetProjectName()
  707. + wxT( "." )
  708. + PcbFileExtension );
  709. }
  710. else if( fpid.IsValid() )
  711. {
  712. try
  713. {
  714. writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( fpid.GetLibNickname() );
  715. }
  716. catch( const IO_ERROR& )
  717. {
  718. // best efforts...
  719. }
  720. // Note: don't used GetLoadedFPID(); footprint name may have been edited
  721. if( IsContentModified() )
  722. title = wxT( "*" );
  723. title += FROM_UTF8( footprint->GetFPID().Format().c_str() );
  724. if( !writable )
  725. title += wxS( " " ) + _( "[Read Only]" );
  726. }
  727. else if( !fpid.GetLibItemName().empty() )
  728. {
  729. // Note: don't used GetLoadedFPID(); footprint name may have been edited
  730. if( IsContentModified() )
  731. title = wxT( "*" );
  732. title += FROM_UTF8( footprint->GetFPID().GetLibItemName().c_str() );
  733. title += wxS( " " ) + _( "[Unsaved]" );
  734. }
  735. else
  736. {
  737. title = _( "[no footprint loaded]" );
  738. }
  739. title += wxT( " \u2014 " ) + _( "Footprint Editor" );
  740. SetTitle( title );
  741. }
  742. void FOOTPRINT_EDIT_FRAME::UpdateUserInterface()
  743. {
  744. m_appearancePanel->OnBoardChanged();
  745. }
  746. void FOOTPRINT_EDIT_FRAME::UpdateView()
  747. {
  748. GetCanvas()->UpdateColors();
  749. GetCanvas()->DisplayBoard( GetBoard() );
  750. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  751. UpdateTitle();
  752. }
  753. void FOOTPRINT_EDIT_FRAME::initLibraryTree()
  754. {
  755. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  756. WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
  757. if( GFootprintList.GetCount() == 0 )
  758. GFootprintList.ReadCacheFromFile( Prj().GetProjectPath() + wxT( "fp-info-cache" ) );
  759. GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter );
  760. progressReporter.Show( false );
  761. if( GFootprintList.GetErrorCount() )
  762. GFootprintList.DisplayErrors( this );
  763. m_adapter = FP_TREE_SYNCHRONIZING_ADAPTER::Create( this, fpTable );
  764. auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
  765. adapter->AddLibraries( this );
  766. }
  767. void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress )
  768. {
  769. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  770. auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
  771. LIB_ID target = GetTargetFPID();
  772. bool targetSelected = ( target == m_treePane->GetLibTree()->GetSelectedLibId() );
  773. // Sync FOOTPRINT_INFO list to the libraries on disk
  774. if( aProgress )
  775. {
  776. WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
  777. GFootprintList.ReadFootprintFiles( fpTable, nullptr, &progressReporter );
  778. progressReporter.Show( false );
  779. }
  780. else
  781. {
  782. GFootprintList.ReadFootprintFiles( fpTable, nullptr, nullptr );
  783. }
  784. // Sync the LIB_TREE to the FOOTPRINT_INFO list
  785. adapter->Sync( fpTable );
  786. m_treePane->GetLibTree()->Unselect();
  787. m_treePane->GetLibTree()->Regenerate( true );
  788. if( target.IsValid() )
  789. {
  790. if( adapter->FindItem( target ) )
  791. {
  792. if( targetSelected )
  793. m_treePane->GetLibTree()->SelectLibId( target );
  794. else
  795. m_treePane->GetLibTree()->CenterLibId( target );
  796. }
  797. else
  798. {
  799. // Try to focus on parent
  800. target.SetLibItemName( wxEmptyString );
  801. m_treePane->GetLibTree()->CenterLibId( target );
  802. }
  803. }
  804. }
  805. void FOOTPRINT_EDIT_FRAME::RegenerateLibraryTree()
  806. {
  807. LIB_ID target = GetTargetFPID();
  808. m_treePane->GetLibTree()->Regenerate( true );
  809. if( target.IsValid() )
  810. m_treePane->GetLibTree()->CenterLibId( target );
  811. }
  812. void FOOTPRINT_EDIT_FRAME::RefreshLibraryTree()
  813. {
  814. m_treePane->GetLibTree()->RefreshLibTree();
  815. }
  816. void FOOTPRINT_EDIT_FRAME::FocusOnLibID( const LIB_ID& aLibID )
  817. {
  818. m_treePane->GetLibTree()->SelectLibId( aLibID );
  819. }
  820. void FOOTPRINT_EDIT_FRAME::OnDisplayOptionsChanged()
  821. {
  822. m_appearancePanel->UpdateDisplayOptions();
  823. }
  824. void FOOTPRINT_EDIT_FRAME::setupTools()
  825. {
  826. // Create the manager and dispatcher & route draw panel events to the dispatcher
  827. m_toolManager = new TOOL_MANAGER;
  828. m_toolManager->SetEnvironment( GetBoard(), GetCanvas()->GetView(),
  829. GetCanvas()->GetViewControls(), config(), this );
  830. m_actions = new PCB_ACTIONS();
  831. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
  832. GetCanvas()->SetEventDispatcher( m_toolDispatcher );
  833. m_toolManager->RegisterTool( new COMMON_CONTROL );
  834. m_toolManager->RegisterTool( new COMMON_TOOLS );
  835. m_toolManager->RegisterTool( new PCB_SELECTION_TOOL );
  836. m_toolManager->RegisterTool( new ZOOM_TOOL );
  837. m_toolManager->RegisterTool( new EDIT_TOOL );
  838. m_toolManager->RegisterTool( new PAD_TOOL );
  839. m_toolManager->RegisterTool( new DRAWING_TOOL );
  840. m_toolManager->RegisterTool( new PCB_POINT_EDITOR );
  841. m_toolManager->RegisterTool( new PCB_CONTROL ); // copy/paste
  842. m_toolManager->RegisterTool( new FOOTPRINT_EDITOR_CONTROL );
  843. m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
  844. m_toolManager->RegisterTool( new PCB_PICKER_TOOL );
  845. m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
  846. m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS );
  847. m_toolManager->RegisterTool( new GROUP_TOOL );
  848. m_toolManager->RegisterTool( new CONVERT_TOOL );
  849. m_toolManager->RegisterTool( new SCRIPTING_TOOL );
  850. m_toolManager->RegisterTool( new PROPERTIES_TOOL );
  851. for( TOOL_BASE* tool : m_toolManager->Tools() )
  852. {
  853. if( PCB_TOOL_BASE* pcbTool = dynamic_cast<PCB_TOOL_BASE*>( tool ) )
  854. pcbTool->SetIsFootprintEditor( true );
  855. }
  856. m_toolManager->GetTool<PCB_VIEWER_TOOLS>()->SetFootprintFrame( true );
  857. m_toolManager->InitTools();
  858. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  859. // Load or reload wizard plugins in case they changed since the last time the frame opened
  860. // Because the board editor has also a plugin python menu,
  861. // call the PCB_EDIT_FRAME RunAction() if the board editor is running
  862. // Otherwise run the current RunAction().
  863. PCB_EDIT_FRAME* pcbframe = static_cast<PCB_EDIT_FRAME*>( Kiway().Player( FRAME_PCB_EDITOR, false ) );
  864. if( pcbframe )
  865. pcbframe->GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload, true );
  866. else
  867. m_toolManager->RunAction( PCB_ACTIONS::pluginsReload, true );
  868. }
  869. void FOOTPRINT_EDIT_FRAME::setupUIConditions()
  870. {
  871. PCB_BASE_EDIT_FRAME::setupUIConditions();
  872. ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
  873. PCB_EDITOR_CONDITIONS cond( this );
  874. wxASSERT( mgr );
  875. #define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
  876. #define CHECK( x ) ACTION_CONDITIONS().Check( x )
  877. auto haveFootprintCond =
  878. [this]( const SELECTION& )
  879. {
  880. return GetBoard()->GetFirstFootprint() != nullptr;
  881. };
  882. auto footprintTargettedCond =
  883. [this]( const SELECTION& )
  884. {
  885. return !GetTargetFPID().GetLibItemName().empty();
  886. };
  887. mgr->SetConditions( ACTIONS::saveAs, ENABLE( footprintTargettedCond ) );
  888. mgr->SetConditions( ACTIONS::revert, ENABLE( cond.ContentModified() ) );
  889. mgr->SetConditions( ACTIONS::save, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
  890. mgr->SetConditions( ACTIONS::undo, ENABLE( cond.UndoAvailable() ) );
  891. mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
  892. mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
  893. mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
  894. mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );
  895. mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) );
  896. mgr->SetConditions( ACTIONS::milsUnits, CHECK( cond.Units( EDA_UNITS::MILS ) ) );
  897. mgr->SetConditions( ACTIONS::cut, ENABLE( cond.HasItems() ) );
  898. mgr->SetConditions( ACTIONS::copy, ENABLE( cond.HasItems() ) );
  899. mgr->SetConditions( ACTIONS::paste, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  900. mgr->SetConditions( ACTIONS::pasteSpecial, ENABLE( SELECTION_CONDITIONS::Idle && cond.NoActiveTool() ) );
  901. mgr->SetConditions( ACTIONS::doDelete, ENABLE( cond.HasItems() ) );
  902. mgr->SetConditions( ACTIONS::duplicate, ENABLE( cond.HasItems() ) );
  903. mgr->SetConditions( ACTIONS::selectAll, ENABLE( cond.HasItems() ) );
  904. mgr->SetConditions( PCB_ACTIONS::rotateCw, ENABLE( cond.HasItems() ) );
  905. mgr->SetConditions( PCB_ACTIONS::rotateCcw, ENABLE( cond.HasItems() ) );
  906. mgr->SetConditions( PCB_ACTIONS::mirrorH, ENABLE( cond.HasItems() ) );
  907. mgr->SetConditions( PCB_ACTIONS::mirrorV, ENABLE( cond.HasItems() ) );
  908. mgr->SetConditions( PCB_ACTIONS::group, ENABLE( SELECTION_CONDITIONS::MoreThan( 1 ) ) );
  909. mgr->SetConditions( PCB_ACTIONS::ungroup, ENABLE( SELECTION_CONDITIONS::HasType( PCB_GROUP_T ) ) );
  910. mgr->SetConditions( PCB_ACTIONS::padDisplayMode, CHECK( !cond.PadFillDisplay() ) );
  911. mgr->SetConditions( PCB_ACTIONS::textOutlines, CHECK( !cond.TextFillDisplay() ) );
  912. mgr->SetConditions( PCB_ACTIONS::graphicsOutlines, CHECK( !cond.GraphicsFillDisplay() ) );
  913. mgr->SetConditions( ACTIONS::zoomTool, CHECK( cond.CurrentTool( ACTIONS::zoomTool ) ) );
  914. mgr->SetConditions( ACTIONS::selectionTool, CHECK( cond.CurrentTool( ACTIONS::selectionTool ) ) );
  915. auto constrainedDrawingModeCond =
  916. [this]( const SELECTION& )
  917. {
  918. return GetSettings()->m_Use45Limit;
  919. };
  920. auto highContrastCond =
  921. [this]( const SELECTION& )
  922. {
  923. return GetDisplayOptions().m_ContrastModeDisplay != HIGH_CONTRAST_MODE::NORMAL;
  924. };
  925. auto boardFlippedCond =
  926. [this]( const SELECTION& )
  927. {
  928. return GetCanvas()->GetView()->IsMirroredX();
  929. };
  930. auto footprintTreeCond =
  931. [this](const SELECTION& )
  932. {
  933. return IsSearchTreeShown();
  934. };
  935. auto layerManagerCond =
  936. [this]( const SELECTION& )
  937. {
  938. return m_auimgr.GetPane( "LayersManager" ).IsShown();
  939. };
  940. auto propertiesCond =
  941. [this] ( const SELECTION& )
  942. {
  943. return m_auimgr.GetPane( "PropertiesManager" ).IsShown();
  944. };
  945. mgr->SetConditions( PCB_ACTIONS::toggleHV45Mode, CHECK( constrainedDrawingModeCond ) );
  946. mgr->SetConditions( ACTIONS::highContrastMode, CHECK( highContrastCond ) );
  947. mgr->SetConditions( PCB_ACTIONS::flipBoard, CHECK( boardFlippedCond ) );
  948. mgr->SetConditions( ACTIONS::toggleBoundingBoxes, CHECK( cond.BoundingBoxes() ) );
  949. mgr->SetConditions( PCB_ACTIONS::showFootprintTree, CHECK( footprintTreeCond ) );
  950. mgr->SetConditions( PCB_ACTIONS::showLayersManager, CHECK( layerManagerCond ) );
  951. mgr->SetConditions( PCB_ACTIONS::showProperties, CHECK( propertiesCond ) );
  952. mgr->SetConditions( ACTIONS::print, ENABLE( haveFootprintCond ) );
  953. mgr->SetConditions( PCB_ACTIONS::exportFootprint, ENABLE( haveFootprintCond ) );
  954. mgr->SetConditions( PCB_ACTIONS::placeImportedGraphics, ENABLE( haveFootprintCond ) );
  955. mgr->SetConditions( PCB_ACTIONS::footprintProperties, ENABLE( haveFootprintCond ) );
  956. mgr->SetConditions( PCB_ACTIONS::editTextAndGraphics, ENABLE( haveFootprintCond ) );
  957. mgr->SetConditions( PCB_ACTIONS::checkFootprint, ENABLE( haveFootprintCond ) );
  958. mgr->SetConditions( PCB_ACTIONS::repairFootprint, ENABLE( haveFootprintCond ) );
  959. mgr->SetConditions( PCB_ACTIONS::cleanupGraphics, ENABLE( haveFootprintCond ) );
  960. auto isArcKeepCenterMode = [this]( const SELECTION& )
  961. {
  962. return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
  963. };
  964. auto isArcKeepEndpointMode = [this]( const SELECTION& )
  965. {
  966. return GetSettings()->m_ArcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
  967. };
  968. mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepCenter, CHECK( isArcKeepCenterMode ) );
  969. mgr->SetConditions( PCB_ACTIONS::pointEditorArcKeepEndpoint, CHECK( isArcKeepEndpointMode ) );
  970. // Only enable a tool if the part is edtable
  971. #define CURRENT_EDIT_TOOL( action ) mgr->SetConditions( action, \
  972. ACTION_CONDITIONS().Enable( haveFootprintCond ).Check( cond.CurrentTool( action ) ) )
  973. CURRENT_EDIT_TOOL( ACTIONS::deleteTool );
  974. CURRENT_EDIT_TOOL( ACTIONS::measureTool );
  975. CURRENT_EDIT_TOOL( PCB_ACTIONS::placePad );
  976. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLine );
  977. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRectangle );
  978. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCircle );
  979. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawArc );
  980. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawPolygon );
  981. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRuleArea );
  982. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeImage );
  983. CURRENT_EDIT_TOOL( PCB_ACTIONS::placeText );
  984. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawTextBox );
  985. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawAlignedDimension );
  986. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawOrthogonalDimension );
  987. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawCenterDimension );
  988. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawRadialDimension );
  989. CURRENT_EDIT_TOOL( PCB_ACTIONS::drawLeader );
  990. CURRENT_EDIT_TOOL( PCB_ACTIONS::setAnchor );
  991. CURRENT_EDIT_TOOL( PCB_ACTIONS::gridSetOrigin );
  992. #undef CURRENT_EDIT_TOOL
  993. #undef ENABLE
  994. #undef CHECK
  995. }
  996. void FOOTPRINT_EDIT_FRAME::ActivateGalCanvas()
  997. {
  998. PCB_BASE_EDIT_FRAME::ActivateGalCanvas();
  999. // Be sure the axis are enabled
  1000. GetCanvas()->GetGAL()->SetAxesEnabled( true );
  1001. UpdateView();
  1002. // Ensure the m_Layers settings are using the canvas type:
  1003. UpdateUserInterface();
  1004. }
  1005. void FOOTPRINT_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  1006. {
  1007. PCB_BASE_EDIT_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  1008. auto cfg = Pgm().GetSettingsManager().GetAppSettings<FOOTPRINT_EDITOR_SETTINGS>();
  1009. GetGalDisplayOptions().ReadWindowSettings( cfg->m_Window );
  1010. GetBoard()->GetDesignSettings() = cfg->m_DesignSettings;
  1011. GetCanvas()->GetView()->UpdateAllLayersColor();
  1012. GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  1013. GetCanvas()->ForceRefresh();
  1014. UpdateUserInterface();
  1015. if( aEnvVarsChanged )
  1016. SyncLibraryTree( true );
  1017. Layout();
  1018. SendSizeEvent();
  1019. }
  1020. void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
  1021. {
  1022. LIB_ID id = GetLoadedFPID();
  1023. if( id.empty() )
  1024. {
  1025. DisplayErrorMessage( this, _( "No footprint selected." ) );
  1026. return;
  1027. }
  1028. wxFileName fn( id.GetLibItemName() );
  1029. fn.SetExt( wxT( "png" ) );
  1030. wxString projectPath = wxPathOnly( Prj().GetProjectFullName() );
  1031. wxFileDialog dlg( this, _( "Footprint Image File Name" ), projectPath,
  1032. fn.GetFullName(), PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  1033. if( dlg.ShowModal() == wxID_CANCEL || dlg.GetPath().IsEmpty() )
  1034. return;
  1035. // calling wxYield is mandatory under Linux, after closing the file selector dialog
  1036. // to refresh the screen before creating the PNG or JPEG image from screen
  1037. wxYield();
  1038. SaveCanvasImageToFile( this, dlg.GetPath() );
  1039. }