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.

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