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.

1102 lines
36 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
17 years ago
12 years ago
12 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-2018 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. /**
  23. * @file moduleframe.cpp
  24. * @brief Footprint (module) editor main window.
  25. */
  26. #include <fctsys.h>
  27. #include <kiface_i.h>
  28. #include <kiway.h>
  29. #include <project.h>
  30. #include <kicad_plugin.h>
  31. #include <class_drawpanel.h>
  32. #include <pcb_draw_panel_gal.h>
  33. #include <confirm.h>
  34. #include <pcb_edit_frame.h>
  35. #include <dialog_helpers.h>
  36. #include <3d_viewer/eda_3d_viewer.h>
  37. #include <msgpanel.h>
  38. #include <fp_lib_table.h>
  39. #include <bitmaps.h>
  40. #include <gal/graphics_abstraction_layer.h>
  41. #include <eda_dockart.h>
  42. #include <class_board.h>
  43. #include <class_module.h>
  44. #include <pcbnew.h>
  45. #include <pcbnew_id.h>
  46. #include <hotkeys.h>
  47. #include <footprint_edit_frame.h>
  48. #include <footprint_viewer_frame.h>
  49. #include <wildcards_and_files_ext.h>
  50. #include <pcb_layer_widget.h>
  51. #include <invoke_pcb_dialog.h>
  52. #include <tool/tool_manager.h>
  53. #include <tool/common_tools.h>
  54. #include <tool/tool_dispatcher.h>
  55. #include <tool/zoom_tool.h>
  56. #include <footprint_tree_pane.h>
  57. #include <widgets/lib_tree.h>
  58. #include <fp_lib_table.h>
  59. #include <footprint_info_impl.h>
  60. #include <widgets/paged_dialog.h>
  61. #include <dialogs/panel_modedit_settings.h>
  62. #include <dialogs/panel_modedit_defaults.h>
  63. #include <dialogs/panel_modedit_display_options.h>
  64. #include <dialog_configure_paths.h>
  65. #include <tools/position_relative_tool.h>
  66. #include <widgets/progress_reporter.h>
  67. #include "tools/selection_tool.h"
  68. #include "tools/edit_tool.h"
  69. #include "tools/drawing_tool.h"
  70. #include "tools/point_editor.h"
  71. #include "tools/pcbnew_control.h"
  72. #include "tools/footprint_editor_tools.h"
  73. #include "tools/placement_tool.h"
  74. #include "tools/picker_tool.h"
  75. #include "tools/pad_tool.h"
  76. #include "tools/pcb_actions.h"
  77. BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
  78. EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START, ID_POPUP_PCB_ITEM_SELECTION_END,
  79. PCB_BASE_FRAME::ProcessItemSelection )
  80. EVT_CLOSE( FOOTPRINT_EDIT_FRAME::OnCloseWindow )
  81. EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::CloseModuleEditor )
  82. EVT_SIZE( FOOTPRINT_EDIT_FRAME::OnSize )
  83. EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectZoom )
  84. EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectGrid )
  85. EVT_TOOL( ID_MODEDIT_SAVE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  86. EVT_TOOL( ID_MODEDIT_SAVE_AS, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  87. EVT_TOOL( ID_MODEDIT_REVERT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  88. EVT_TOOL( ID_OPEN_MODULE_VIEWER, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  89. EVT_TOOL( ID_MODEDIT_SAVE_PNG, FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng )
  90. EVT_TOOL( ID_MODEDIT_CUT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  91. EVT_TOOL( ID_MODEDIT_COPY_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  92. EVT_TOOL( ID_MODEDIT_PASTE_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  93. EVT_TOOL( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  94. EVT_TOOL( ID_MODEDIT_NEW_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  95. EVT_TOOL( ID_MODEDIT_NEW_MODULE_FROM_WIZARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  96. EVT_TOOL( ID_MODEDIT_IMPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  97. EVT_TOOL( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  98. EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  99. EVT_TOOL( ID_MODEDIT_ADD_LIBRARY, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  100. EVT_TOOL( ID_MODEDIT_SHEET_SET, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  101. EVT_TOOL( ID_GEN_IMPORT_GRAPHICS_FILE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  102. EVT_TOOL( wxID_PRINT, FOOTPRINT_EDIT_FRAME::ToPrinter )
  103. EVT_TOOL( ID_MODEDIT_EDIT_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  104. EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  105. EVT_TOOL( ID_MODEDIT_PAD_SETTINGS, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  106. EVT_TOOL( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard )
  107. EVT_TOOL( ID_MODEDIT_INSERT_MODULE_IN_BOARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  108. EVT_TOOL( ID_MODEDIT_EDIT_MODULE_PROPERTIES, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  109. EVT_TOOL( wxID_UNDO, FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList )
  110. EVT_TOOL( wxID_REDO, FOOTPRINT_EDIT_FRAME::RestoreCopyFromRedoList )
  111. // Vertical tool bar button click event handler.
  112. EVT_TOOL( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  113. EVT_TOOL( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  114. EVT_TOOL_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL,
  115. FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  116. // Options Toolbar
  117. // ID_TB_OPTIONS_SHOW_PADS_SKETCH id is managed in PCB_BASE_FRAME
  118. // ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH id is managed in PCB_BASE_FRAME
  119. // ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH id is managed in PCB_BASE_FRAME
  120. EVT_TOOL( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE, FOOTPRINT_EDIT_FRAME::OnSelectOptionToolbar )
  121. EVT_TOOL( ID_MODEDIT_SHOW_HIDE_SEARCH_TREE, FOOTPRINT_EDIT_FRAME::OnToggleSearchTree )
  122. // Preferences and option menus
  123. EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
  124. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  125. EVT_MENU( ID_PCB_LIB_TABLE_EDIT,
  126. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  127. EVT_MENU( wxID_PREFERENCES,
  128. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  129. EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, FOOTPRINT_EDIT_FRAME::OnConfigurePaths )
  130. // popup commands
  131. EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE,
  132. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  133. EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
  134. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  135. EVT_MENU( ID_POPUP_MODEDIT_EDIT_BODY_ITEM,
  136. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  137. EVT_MENU( ID_POPUP_MODEDIT_EDIT_WIDTH_ALL_EDGE,
  138. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  139. EVT_MENU( ID_POPUP_MODEDIT_EDIT_LAYER_ALL_EDGE,
  140. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  141. // Module transformations
  142. EVT_MENU( ID_MODEDIT_MODULE_ROTATE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  143. EVT_MENU( ID_MODEDIT_MODULE_MIRROR, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  144. EVT_MENU( ID_MODEDIT_MODULE_MOVE_EXACT, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  145. EVT_MENU( ID_PCB_USER_GRID_SETUP, FOOTPRINT_EDIT_FRAME::OnGridSettings )
  146. // Menu Help
  147. EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
  148. EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
  149. EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
  150. EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
  151. // Menu 3D Frame
  152. EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, FOOTPRINT_EDIT_FRAME::Show3D_Frame )
  153. // Switching canvases
  154. EVT_MENU( ID_MENU_CANVAS_LEGACY, FOOTPRINT_EDIT_FRAME::OnSwitchCanvas )
  155. EVT_MENU( ID_MENU_CANVAS_CAIRO, FOOTPRINT_EDIT_FRAME::OnSwitchCanvas )
  156. EVT_MENU( ID_MENU_CANVAS_OPENGL, FOOTPRINT_EDIT_FRAME::OnSwitchCanvas )
  157. // UI update events.
  158. EVT_UPDATE_UI( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::OnUpdateSaveAs )
  159. EVT_UPDATE_UI( ID_MODEDIT_SAVE, FOOTPRINT_EDIT_FRAME::OnUpdateSave )
  160. EVT_UPDATE_UI( ID_MODEDIT_SAVE_AS, FOOTPRINT_EDIT_FRAME::OnUpdateSaveAs )
  161. EVT_UPDATE_UI( ID_MODEDIT_REVERT_PART, FOOTPRINT_EDIT_FRAME::OnUpdateSave )
  162. EVT_UPDATE_UI( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::OnUpdateModuleTargeted )
  163. EVT_UPDATE_UI( ID_MODEDIT_LOAD_MODULE_FROM_BOARD,
  164. FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard )
  165. EVT_UPDATE_UI( ID_MODEDIT_INSERT_MODULE_IN_BOARD,
  166. FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard )
  167. EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool )
  168. EVT_UPDATE_UI( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool )
  169. EVT_UPDATE_UI_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL,
  170. FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar )
  171. EVT_UPDATE_UI( ID_MODEDIT_EDIT_MODULE_PROPERTIES, FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  172. EVT_UPDATE_UI( ID_MODEDIT_PAD_SETTINGS, FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  173. // Option toolbar:
  174. EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
  175. FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar )
  176. EVT_UPDATE_UI( ID_MODEDIT_SHOW_HIDE_SEARCH_TREE,
  177. FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar )
  178. EVT_UPDATE_UI( ID_GEN_IMPORT_GRAPHICS_FILE, FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  179. END_EVENT_TABLE()
  180. FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent,
  181. EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend ) :
  182. PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_MODULE_EDITOR, wxEmptyString,
  183. wxDefaultPosition, wxDefaultSize,
  184. KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
  185. {
  186. m_showBorderAndTitleBlock = false; // true to show the frame references
  187. m_showAxis = true; // true to show X and Y axis on screen
  188. m_showGridAxis = true; // show the grid origin axis
  189. m_hotkeysDescrList = g_Module_Editor_Hotkeys_Descr;
  190. m_FrameSize = ConvertDialogToPixels( wxSize( 500, 350 ) ); // default in case of no prefs
  191. m_canvasType = aBackend;
  192. // Give an icon
  193. wxIcon icon;
  194. icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
  195. SetIcon( icon );
  196. // Create GAL canvas
  197. if( aBackend == EDA_DRAW_PANEL_GAL::GAL_TYPE_UNKNOWN )
  198. m_canvasType = LoadCanvasTypeSetting();
  199. else
  200. m_canvasType = aBackend;
  201. PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
  202. GetGalDisplayOptions(), m_canvasType );
  203. SetGalCanvas( drawPanel );
  204. SetBoard( new BOARD() );
  205. // In modedit, the default net clearance is not known.
  206. // (it depends on the actual board)
  207. // So we do not show the default clearance, by setting it to 0
  208. // The footprint or pad specific clearance will be shown
  209. GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
  210. // Don't show the default board solder mask clearance in the footprint editor. Only the
  211. // footprint or pad clearance setting should be shown if it is not 0.
  212. GetBoard()->GetDesignSettings().m_SolderMaskMargin = 0;
  213. // restore the last footprint from the project, if any
  214. restoreLastFootprint();
  215. // Ensure all layers and items are visible:
  216. // In footprint editor, some layers have no meaning or
  217. // cannot be used, but we show all of them, at least to be able
  218. // to edit a bad layer
  219. GetBoard()->SetVisibleAlls();
  220. // However the "no net" mark on pads is useless, because there is
  221. // no net in footprint editor: make it non visible
  222. GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false );
  223. m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), true );
  224. // LoadSettings() *after* creating m_LayersManager, because LoadSettings()
  225. // initialize parameters in m_LayersManager
  226. LoadSettings( config() );
  227. GetGalDisplayOptions().m_axesEnabled = true;
  228. SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
  229. GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
  230. GetScreen()->SetCurItem( NULL );
  231. GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS_T::UNSCALED_UNITS, ID_POPUP_GRID_USER );
  232. GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
  233. // In modedit, set the default paper size to A4:
  234. // this should be OK for all footprint to plot/print
  235. SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
  236. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  237. initLibraryTree();
  238. m_treePane = new FOOTPRINT_TREE_PANE( this );
  239. // ReCreateMenuBar(); // UseGalCanvas() will do this for us.
  240. ReCreateHToolbar();
  241. ReCreateVToolbar();
  242. ReCreateOptToolbar();
  243. m_Layers->ReFill();
  244. m_Layers->ReFillRender();
  245. GetScreen()->m_Active_Layer = F_SilkS;
  246. m_Layers->SelectLayer( F_SilkS );
  247. m_Layers->OnLayerSelected();
  248. if( m_canvas )
  249. m_canvas->SetEnableBlockCommands( true );
  250. m_auimgr.SetManagedWindow( this );
  251. m_auimgr.SetArtProvider( new EDA_DOCKART( this ) );
  252. // Horizontal items; layers 4 - 6
  253. m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
  254. m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) );
  255. // Vertical items; layers 1 - 3
  256. m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) );
  257. m_auimgr.AddPane( m_treePane, EDA_PANE().Palette().Name( "Footprints" ).Left().Layer(1)
  258. .Caption( _( "Libraries" ) ).MinSize( 250, 400 ) );
  259. m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ).Right().Layer(1) );
  260. m_auimgr.AddPane( m_Layers, EDA_PANE().Palette().Name( "LayersManager" ).Right().Layer(3)
  261. .Caption( _( "Layers Manager" ) ).PaneBorder( false )
  262. .MinSize( 80, -1 ).BestSize( m_Layers->GetBestSize() ) );
  263. m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
  264. m_auimgr.AddPane( GetGalCanvas(), EDA_PANE().Canvas().Name( "DrawFrameGal" ).Center().Hide() );
  265. // Create the manager and dispatcher & route draw panel events to the dispatcher
  266. setupTools();
  267. GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
  268. UseGalCanvas( m_canvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
  269. m_auimgr.Update();
  270. updateTitle();
  271. Raise(); // On some window managers, this is needed
  272. Show( true );
  273. Zoom_Automatique( false );
  274. }
  275. FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
  276. {
  277. // save the footprint in the PROJECT
  278. retainLastFootprint();
  279. delete m_Layers;
  280. }
  281. void FOOTPRINT_EDIT_FRAME::OnSwitchCanvas( wxCommandEvent& aEvent )
  282. {
  283. // switches currently used canvas (default / Cairo / OpenGL).
  284. PCB_BASE_FRAME::OnSwitchCanvas( aEvent );
  285. // The base class method *does not reinit* the layers manager.
  286. // We must upate the layer widget to match board visibility states,
  287. // both layers and render columns, and and some settings dependent on the canvas.
  288. UpdateUserInterface();
  289. }
  290. void FOOTPRINT_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event )
  291. {
  292. auto& treePane = m_auimgr.GetPane( m_treePane );
  293. treePane.Show( !IsSearchTreeShown() );
  294. m_auimgr.Update();
  295. }
  296. bool FOOTPRINT_EDIT_FRAME::IsSearchTreeShown()
  297. {
  298. return m_auimgr.GetPane( m_treePane ).IsShown();
  299. }
  300. BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const
  301. {
  302. return GetBoard()->m_Modules;
  303. }
  304. LIB_ID FOOTPRINT_EDIT_FRAME::getTargetFPID() const
  305. {
  306. LIB_ID id = m_treePane->GetLibTree()->GetSelectedLibId();
  307. wxString nickname = id.GetLibNickname();
  308. if( nickname.IsEmpty() )
  309. return GetLoadedFPID();
  310. return id;
  311. }
  312. LIB_ID FOOTPRINT_EDIT_FRAME::GetLoadedFPID() const
  313. {
  314. MODULE* module = GetBoard()->m_Modules;
  315. if( module )
  316. return LIB_ID( module->GetFPID().GetLibNickname(), m_footprintNameWhenLoaded );
  317. else
  318. return LIB_ID();
  319. }
  320. bool FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard() const
  321. {
  322. MODULE* module = GetBoard()->m_Modules;
  323. return ( module && module->GetLink() > 0 );
  324. }
  325. void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
  326. {
  327. LIB_ID id = GetLoadedFPID();
  328. if( id.IsValid() )
  329. {
  330. Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME, id.GetLibNickname() );
  331. Prj().SetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME, id.GetLibItemName() );
  332. }
  333. }
  334. void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
  335. {
  336. const wxString& curFootprintName = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_FPNAME );
  337. const wxString& curNickname = Prj().GetRString( PROJECT::PCB_FOOTPRINT_EDITOR_NICKNAME );
  338. if( curNickname.Length() && curFootprintName.Length() )
  339. {
  340. LIB_ID id;
  341. id.SetLibNickname( curNickname );
  342. id.SetLibItemName( curFootprintName );
  343. MODULE* module = loadFootprint( id );
  344. if( module )
  345. AddModuleToBoard( module );
  346. }
  347. }
  348. void FOOTPRINT_EDIT_FRAME::AddModuleToBoard( MODULE* aFootprint )
  349. {
  350. m_revertModule.reset( (MODULE*) aFootprint->Clone() );
  351. m_footprintNameWhenLoaded = aFootprint->GetFPID().GetLibItemName();
  352. // Pads are always editable in Footprint Editor
  353. aFootprint->SetPadsLocked( false );
  354. PCB_BASE_EDIT_FRAME::AddModuleToBoard( aFootprint );
  355. }
  356. const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
  357. {
  358. return FOOTPRINT_EDIT_FRAME_NAME;
  359. }
  360. BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const
  361. {
  362. return GetBoard()->GetDesignSettings();
  363. }
  364. void FOOTPRINT_EDIT_FRAME::SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings )
  365. {
  366. GetBoard()->SetDesignSettings( aSettings );
  367. }
  368. const PCB_PLOT_PARAMS& FOOTPRINT_EDIT_FRAME::GetPlotSettings() const
  369. {
  370. // get the settings from the parent editor, not our BOARD.
  371. // @todo(DICK) change the routing to some default or the board directly, parent may not exist
  372. PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB, true );
  373. wxASSERT( parentFrame );
  374. return parentFrame->GetPlotSettings();
  375. }
  376. void FOOTPRINT_EDIT_FRAME::SetPlotSettings( const PCB_PLOT_PARAMS& aSettings )
  377. {
  378. // set the settings into parent editor, not our BOARD.
  379. // @todo(DICK) change the routing to some default or the board directly, parent may not exist
  380. PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB, true );
  381. wxASSERT( parentFrame );
  382. parentFrame->SetPlotSettings( aSettings );
  383. }
  384. void FOOTPRINT_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
  385. {
  386. PCB_BASE_FRAME::LoadSettings( aCfg );
  387. wxConfigLoadSetups( aCfg, GetConfigurationSettings() );
  388. m_configSettings.Load( aCfg ); // mainly, load the color config
  389. // Ensure some params are valid
  390. BOARD_DESIGN_SETTINGS& settings = GetDesignSettings();
  391. // Usually, graphic items are drawn on F_SilkS or F_Fab layer
  392. // Force these layers if not default
  393. if( ( settings.m_RefDefaultlayer != F_SilkS ) && ( settings.m_RefDefaultlayer != F_Fab ) )
  394. settings.m_RefDefaultlayer = F_SilkS;
  395. if( ( settings.m_ValueDefaultlayer != F_SilkS ) && ( settings.m_ValueDefaultlayer != F_Fab ) )
  396. settings.m_ValueDefaultlayer = F_Fab;
  397. }
  398. void FOOTPRINT_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
  399. {
  400. m_configSettings.Save( aCfg );
  401. PCB_BASE_FRAME::SaveSettings( aCfg );
  402. wxConfigSaveSetups( aCfg, GetConfigurationSettings() );
  403. }
  404. double FOOTPRINT_EDIT_FRAME::BestZoom()
  405. {
  406. EDA_RECT ibbbox = GetBoardBoundingBox();
  407. double sizeX = (double) ibbbox.GetWidth();
  408. double sizeY = (double) ibbbox.GetHeight();
  409. wxPoint centre = ibbbox.Centre();
  410. // Reserve a 20% margin around "board" bounding box.
  411. double margin_scale_factor = 1.2;
  412. return bestZoom( sizeX, sizeY, margin_scale_factor, centre );
  413. }
  414. void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
  415. {
  416. if( GetScreen()->IsModify() && GetBoard()->m_Modules )
  417. {
  418. if( !HandleUnsavedChanges( this, _( "Save changes to footprint before closing?" ),
  419. [&]()->bool { return SaveFootprint( GetBoard()->m_Modules ); } ) )
  420. {
  421. Event.Veto();
  422. return;
  423. }
  424. }
  425. if( IsGalCanvasActive() )
  426. {
  427. GetGalCanvas()->SetEventDispatcher( NULL );
  428. GetGalCanvas()->StopDrawing();
  429. }
  430. // Do not show the layer manager during closing to avoid flicker
  431. // on some platforms (Windows) that generate useless redraw of items in
  432. // the Layer Manger
  433. m_auimgr.GetPane( "LayersManager" ).Show( false );
  434. Clear_Pcb( false );
  435. //close the editor
  436. Destroy();
  437. }
  438. void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
  439. {
  440. Close();
  441. }
  442. void FOOTPRINT_EDIT_FRAME::OnUpdateSelectTool( wxUpdateUIEvent& aEvent )
  443. {
  444. if( aEvent.GetEventObject() == m_drawToolBar || aEvent.GetEventObject() == m_mainToolBar )
  445. aEvent.Check( GetToolId() == aEvent.GetId() );
  446. }
  447. void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent )
  448. {
  449. aEvent.Enable( GetBoard()->m_Modules != NULL );
  450. if( aEvent.GetEventObject() == m_drawToolBar )
  451. aEvent.Check( GetToolId() == aEvent.GetId() );
  452. }
  453. void FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar( wxUpdateUIEvent& aEvent )
  454. {
  455. int id = aEvent.GetId();
  456. auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
  457. bool state = false;
  458. switch( id )
  459. {
  460. case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
  461. state = displ_opts->m_ContrastModeDisplay;
  462. break;
  463. case ID_MODEDIT_SHOW_HIDE_SEARCH_TREE:
  464. state = IsSearchTreeShown();
  465. break;
  466. default:
  467. wxMessageBox( "FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar error" );
  468. break;
  469. }
  470. aEvent.Check( state );
  471. }
  472. void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent )
  473. {
  474. aEvent.Enable( GetBoard()->m_Modules != NULL );
  475. }
  476. void FOOTPRINT_EDIT_FRAME::OnUpdateModuleTargeted( wxUpdateUIEvent& aEvent )
  477. {
  478. aEvent.Enable( getTargetFPID().IsValid() );
  479. }
  480. void FOOTPRINT_EDIT_FRAME::OnUpdateSave( wxUpdateUIEvent& aEvent )
  481. {
  482. aEvent.Enable( GetBoard()->m_Modules && GetScreen()->IsModify() );
  483. }
  484. void FOOTPRINT_EDIT_FRAME::OnUpdateSaveAs( wxUpdateUIEvent& aEvent )
  485. {
  486. LIB_ID libId = getTargetFPID();
  487. const wxString& libName = libId.GetLibNickname();
  488. const wxString& partName = libId.GetLibItemName();
  489. aEvent.Enable( !libName.IsEmpty() || !partName.IsEmpty() );
  490. }
  491. void FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent )
  492. {
  493. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  494. aEvent.Enable( frame && frame->GetBoard()->m_Modules != NULL );
  495. }
  496. void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent )
  497. {
  498. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  499. MODULE* module_in_edit = GetBoard()->m_Modules;
  500. bool canInsert = frame && module_in_edit && !module_in_edit->GetLink();
  501. // If the source was deleted, the module can inserted but not updated in the board.
  502. if( frame && module_in_edit && module_in_edit->GetLink() ) // this is not a new module
  503. {
  504. BOARD* mainpcb = frame->GetBoard();
  505. MODULE* source_module = mainpcb->m_Modules;
  506. // search if the source module was not deleted:
  507. for( ; source_module != NULL; source_module = source_module->Next() )
  508. {
  509. if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
  510. break;
  511. }
  512. canInsert = ( source_module == NULL );
  513. }
  514. aEvent.Enable( canInsert );
  515. }
  516. void FOOTPRINT_EDIT_FRAME::ReFillLayerWidget()
  517. {
  518. m_Layers->Freeze();
  519. m_Layers->ReFill();
  520. m_Layers->Thaw();
  521. wxAuiPaneInfo& lyrs = m_auimgr.GetPane( m_Layers );
  522. wxSize bestz = m_Layers->GetBestSize();
  523. lyrs.MinSize( bestz );
  524. lyrs.BestSize( bestz );
  525. lyrs.FloatingSize( bestz );
  526. if( lyrs.IsDocked() )
  527. m_auimgr.Update();
  528. else
  529. m_Layers->SetSize( bestz );
  530. }
  531. void FOOTPRINT_EDIT_FRAME::ShowChangedLanguage()
  532. {
  533. // call my base class
  534. PCB_BASE_EDIT_FRAME::ShowChangedLanguage();
  535. // We have 2 panes to update.
  536. // For some obscure reason, the AUI manager hides the first modified pane.
  537. // So force show panes
  538. wxAuiPaneInfo& tree_pane_info = m_auimgr.GetPane( m_treePane );
  539. bool tree_shown = tree_pane_info.IsShown();
  540. tree_pane_info.Caption( _( "Libraries" ) );
  541. wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_Layers );
  542. bool lm_shown = lm_pane_info.IsShown();
  543. lm_pane_info.Caption( _( "Layers Manager" ) );
  544. // update the layer manager
  545. m_Layers->SetLayersManagerTabsText();
  546. UpdateUserInterface();
  547. // Now restore the visibility:
  548. lm_pane_info.Show( lm_shown );
  549. tree_pane_info.Show( tree_shown );
  550. m_auimgr.Update();
  551. }
  552. void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event )
  553. {
  554. bool forceRecreateIfNotOwner = true;
  555. CreateAndShow3D_Frame( forceRecreateIfNotOwner );
  556. }
  557. bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
  558. {
  559. // Filter out the 'fake' mouse motion after a keyboard movement
  560. if( !aHotKey && m_movingCursorWithKeyboard )
  561. {
  562. m_movingCursorWithKeyboard = false;
  563. return false;
  564. }
  565. // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed
  566. // for next cursor position
  567. // ( shift or ctrl key down are PAN command with mouse wheel)
  568. bool snapToGrid = true;
  569. if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
  570. snapToGrid = false;
  571. wxPoint oldpos = GetCrossHairPosition();
  572. wxPoint pos = aPosition;
  573. bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
  574. SetCrossHairPosition( pos, snapToGrid );
  575. RefreshCrossHair( oldpos, aPosition, aDC );
  576. if( aHotKey && OnHotKey( aDC, aHotKey, aPosition ) )
  577. {
  578. keyHandled = true;
  579. }
  580. UpdateStatusBar();
  581. return keyHandled;
  582. }
  583. void FOOTPRINT_EDIT_FRAME::OnModify()
  584. {
  585. PCB_BASE_FRAME::OnModify();
  586. Update3DView();
  587. m_treePane->GetLibTree()->Refresh();
  588. }
  589. void FOOTPRINT_EDIT_FRAME::updateTitle()
  590. {
  591. wxString title = _( "Footprint Editor" );
  592. LIB_ID fpid = GetLoadedFPID();
  593. bool writable = true;
  594. if( IsCurrentFPFromBoard() )
  595. {
  596. title += wxString::Format( wxT( " \u2014 %s [from %s.%s]" ),
  597. GetBoard()->m_Modules->GetReference(),
  598. Prj().GetProjectName(), PcbFileExtension );
  599. }
  600. else if( fpid.IsValid() )
  601. {
  602. try
  603. {
  604. writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( fpid.GetLibNickname() );
  605. }
  606. catch( const IO_ERROR& )
  607. {
  608. // best efforts...
  609. }
  610. // Note: don't used GetLoadedFPID(); footprint name may have been edited
  611. title += wxString::Format( wxT( " \u2014 %s %s" ),
  612. FROM_UTF8( GetBoard()->m_Modules->GetFPID().Format().c_str() ),
  613. writable ? wxString( wxEmptyString ) : _( "[Read Only]" ) );
  614. }
  615. else if( !fpid.GetLibItemName().empty() )
  616. {
  617. // Note: don't used GetLoadedFPID(); footprint name may have been edited
  618. title += wxString::Format( wxT( " \u2014 %s %s" ),
  619. FROM_UTF8( GetBoard()->m_Modules->GetFPID().GetLibItemName().c_str() ),
  620. _( "[Unsaved]" ) );
  621. }
  622. SetTitle( title );
  623. }
  624. void FOOTPRINT_EDIT_FRAME::UpdateUserInterface()
  625. {
  626. // Update the layer manager and other widgets from the board setup
  627. // (layer and items visibility, colors ...)
  628. // Update the layer manager
  629. m_Layers->Freeze();
  630. ReFillLayerWidget();
  631. m_Layers->ReFillRender();
  632. // update the layer widget to match board visibility states.
  633. m_Layers->SyncLayerVisibilities();
  634. static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( m_Pcb );
  635. m_Layers->SelectLayer( GetActiveLayer() );
  636. m_Layers->OnLayerSelected();
  637. m_Layers->Thaw();
  638. }
  639. void FOOTPRINT_EDIT_FRAME::updateView()
  640. {
  641. auto dp = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
  642. dp->UseColorScheme( &Settings().Colors() );
  643. dp->DisplayBoard( GetBoard() );
  644. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  645. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  646. updateTitle();
  647. }
  648. void FOOTPRINT_EDIT_FRAME::initLibraryTree()
  649. {
  650. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  651. WX_PROGRESS_REPORTER progressReporter( this, _( "Loading Footprint Libraries" ), 2 );
  652. GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
  653. progressReporter.Show( false );
  654. if( GFootprintList.GetErrorCount() )
  655. GFootprintList.DisplayErrors( this );
  656. m_adapter = FP_TREE_SYNCHRONIZING_ADAPTER::Create( this, fpTable );
  657. auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
  658. adapter->AddLibraries();
  659. }
  660. void FOOTPRINT_EDIT_FRAME::SyncLibraryTree( bool aProgress )
  661. {
  662. FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs();
  663. auto adapter = static_cast<FP_TREE_SYNCHRONIZING_ADAPTER*>( m_adapter.get() );
  664. LIB_ID target = getTargetFPID();
  665. bool targetSelected = ( target == m_treePane->GetLibTree()->GetSelectedLibId() );
  666. // Sync FOOTPRINT_INFO list to the libraries on disk
  667. if( aProgress )
  668. {
  669. WX_PROGRESS_REPORTER progressReporter( this, _( "Updating Footprint Libraries" ), 2 );
  670. GFootprintList.ReadFootprintFiles( fpTable, NULL, &progressReporter );
  671. progressReporter.Show( false );
  672. }
  673. else
  674. {
  675. GFootprintList.ReadFootprintFiles( fpTable, NULL, NULL );
  676. }
  677. // Sync the LIB_TREE to the FOOTPRINT_INFO list
  678. adapter->Sync();
  679. m_treePane->GetLibTree()->Unselect();
  680. m_treePane->Regenerate();
  681. if( target.IsValid() )
  682. {
  683. if( adapter->FindItem( target ) )
  684. {
  685. if( targetSelected )
  686. m_treePane->GetLibTree()->SelectLibId( target );
  687. else
  688. m_treePane->GetLibTree()->CenterLibId( target );
  689. }
  690. else
  691. {
  692. // Try to focus on parent
  693. target.SetLibItemName( wxEmptyString );
  694. m_treePane->GetLibTree()->CenterLibId( target );
  695. }
  696. }
  697. }
  698. bool FOOTPRINT_EDIT_FRAME::IsGridVisible() const
  699. {
  700. return IsElementVisible( LAYER_GRID );
  701. }
  702. void FOOTPRINT_EDIT_FRAME::SetGridVisibility(bool aVisible)
  703. {
  704. SetElementVisibility( LAYER_GRID, aVisible );
  705. }
  706. bool FOOTPRINT_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
  707. {
  708. return GetBoard()->IsElementVisible( aElement );
  709. }
  710. void FOOTPRINT_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
  711. {
  712. GetGalCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
  713. GetBoard()->SetElementVisibility( aElement, aNewState );
  714. m_Layers->SetRenderState( aElement, aNewState );
  715. }
  716. void FOOTPRINT_EDIT_FRAME::OnUpdateLayerAlpha( wxUpdateUIEvent & )
  717. {
  718. m_Layers->SyncLayerAlphaIndicators();
  719. }
  720. void FOOTPRINT_EDIT_FRAME::ProcessPreferences( wxCommandEvent& event )
  721. {
  722. int id = event.GetId();
  723. switch( id )
  724. {
  725. // Hotkey IDs
  726. case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
  727. // Display current hotkey list for the footprint editor.
  728. DisplayHotkeyList( this, g_Module_Editor_Hotkeys_Descr );
  729. break;
  730. case ID_PCB_LIB_TABLE_EDIT:
  731. InvokePcbLibTableEditor( &Kiway(), this );
  732. break;
  733. case wxID_PREFERENCES:
  734. ShowPreferences( g_Pcbnew_Editor_Hotkeys_Descr, g_Module_Editor_Hotkeys_Descr,
  735. wxT( "pcbnew" ) );
  736. break;
  737. default:
  738. DisplayError( this, "FOOTPRINT_EDIT_FRAME::ProcessPreferences error" );
  739. }
  740. }
  741. void FOOTPRINT_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent )
  742. {
  743. wxTreebook* book = aParent->GetTreebook();
  744. book->AddPage( new PANEL_MODEDIT_SETTINGS( this, aParent ), _( "Footprint Editor" ) );
  745. book->AddSubPage( new PANEL_MODEDIT_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
  746. book->AddSubPage( new PANEL_MODEDIT_DEFAULTS( this, aParent ), _( "Default Values" ) );
  747. }
  748. void FOOTPRINT_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
  749. {
  750. DIALOG_CONFIGURE_PATHS dlg( this, Prj().Get3DCacheManager()->GetResolver() );
  751. dlg.ShowModal();
  752. }
  753. void FOOTPRINT_EDIT_FRAME::setupTools()
  754. {
  755. PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
  756. // Create the manager and dispatcher & route draw panel events to the dispatcher
  757. m_toolManager = new TOOL_MANAGER;
  758. m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
  759. drawPanel->GetViewControls(), this );
  760. m_actions = new PCB_ACTIONS();
  761. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  762. drawPanel->SetEventDispatcher( m_toolDispatcher );
  763. m_toolManager->RegisterTool( new COMMON_TOOLS );
  764. m_toolManager->RegisterTool( new SELECTION_TOOL );
  765. m_toolManager->RegisterTool( new ZOOM_TOOL );
  766. m_toolManager->RegisterTool( new EDIT_TOOL );
  767. m_toolManager->RegisterTool( new PAD_TOOL );
  768. m_toolManager->RegisterTool( new DRAWING_TOOL );
  769. m_toolManager->RegisterTool( new POINT_EDITOR );
  770. m_toolManager->RegisterTool( new PCBNEW_CONTROL );
  771. m_toolManager->RegisterTool( new MODULE_EDITOR_TOOLS );
  772. m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL );
  773. m_toolManager->RegisterTool( new PICKER_TOOL );
  774. m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL );
  775. m_toolManager->GetTool<PAD_TOOL>()->SetEditModules( true );
  776. m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
  777. m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
  778. m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
  779. m_toolManager->InitTools();
  780. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  781. }
  782. void FOOTPRINT_EDIT_FRAME::UseGalCanvas( bool aEnable )
  783. {
  784. PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
  785. if( aEnable )
  786. {
  787. // Be sure the axis are enabled:
  788. GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
  789. updateView();
  790. }
  791. ReCreateMenuBar();
  792. // Ensure the m_Layers settings are using the canvas type:
  793. UpdateUserInterface();
  794. }
  795. void FOOTPRINT_EDIT_FRAME::CommonSettingsChanged()
  796. {
  797. PCB_BASE_EDIT_FRAME::CommonSettingsChanged();
  798. Layout();
  799. SendSizeEvent();
  800. }
  801. void FOOTPRINT_EDIT_FRAME::UpdateMsgPanel()
  802. {
  803. // If a item is currently selected, displays the item info.
  804. // If nothing selected, display the current footprint info
  805. BOARD_ITEM* item = GetScreen()->GetCurItem();
  806. if( !item )
  807. item = GetBoard()->m_Modules;
  808. MSG_PANEL_ITEMS items;
  809. if( item )
  810. {
  811. item->GetMsgPanelInfo( m_UserUnits, items );
  812. SetMsgPanel( items );
  813. }
  814. else
  815. ClearMsgPanel();
  816. }
  817. void FOOTPRINT_EDIT_FRAME::OnSaveFootprintAsPng( wxCommandEvent& event )
  818. {
  819. wxString fullFileName;
  820. LIB_ID id = GetLoadedFPID();
  821. if( id.empty() )
  822. {
  823. wxMessageBox( _( "No footprint selected." ) );
  824. return;
  825. }
  826. wxFileName fn( id.GetLibItemName() );
  827. fn.SetExt( "png" );
  828. wxString projectPath = wxPathOnly( Prj().GetProjectFullName() );
  829. wxFileDialog dlg( this, _( "Footprint Image File Name" ), projectPath,
  830. fn.GetFullName(), PngFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  831. if( dlg.ShowModal() == wxID_CANCEL || dlg.GetPath().IsEmpty() )
  832. return;
  833. // calling wxYield is mandatory under Linux, after closing the file selector dialog
  834. // to refresh the screen before creating the PNG or JPEG image from screen
  835. wxYield();
  836. saveCanvasImageToFile( dlg.GetPath() );
  837. }