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.

997 lines
33 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
* 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
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
17 years ago
12 years ago
12 years ago
12 years ago
12 years ago
* 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
  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-2016 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. /**
  27. * @file moduleframe.cpp
  28. * @brief Footprint (module) editor main window.
  29. */
  30. #include <fctsys.h>
  31. #include <pgm_base.h>
  32. #include <kiway.h>
  33. #include <project.h>
  34. #include <kicad_plugin.h>
  35. #include <class_drawpanel.h>
  36. #include <pcb_draw_panel_gal.h>
  37. #include <confirm.h>
  38. #include <wxPcbStruct.h>
  39. #include <dialog_helpers.h>
  40. #include <3d_viewer/eda_3d_viewer.h>
  41. #include <msgpanel.h>
  42. #include <fp_lib_table.h>
  43. #include <bitmaps.h>
  44. #include <gal/graphics_abstraction_layer.h>
  45. #include <class_board.h>
  46. #include <class_module.h>
  47. #include <pcbnew.h>
  48. #include <pcbnew_id.h>
  49. #include <hotkeys.h>
  50. #include <dialogs/dialog_modedit_display_options.h>
  51. #include <dialog_hotkeys_editor.h>
  52. #include <module_editor_frame.h>
  53. #include <modview_frame.h>
  54. #include <wildcards_and_files_ext.h>
  55. #include <class_pcb_layer_widget.h>
  56. #include <invoke_pcb_dialog.h>
  57. #include <tool/tool_manager.h>
  58. #include <tool/common_tools.h>
  59. #include <tool/tool_dispatcher.h>
  60. #include "tools/selection_tool.h"
  61. #include "tools/zoom_tool.h"
  62. #include "tools/edit_tool.h"
  63. #include "tools/drawing_tool.h"
  64. #include "tools/point_editor.h"
  65. #include "tools/pcbnew_control.h"
  66. #include "tools/module_editor_tools.h"
  67. #include "tools/placement_tool.h"
  68. #include "tools/picker_tool.h"
  69. #include "tools/pad_tool.h"
  70. #include "tools/pcb_actions.h"
  71. BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
  72. EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START, ID_POPUP_PCB_ITEM_SELECTION_END,
  73. PCB_BASE_FRAME::ProcessItemSelection )
  74. EVT_CLOSE( FOOTPRINT_EDIT_FRAME::OnCloseWindow )
  75. EVT_MENU( wxID_EXIT, FOOTPRINT_EDIT_FRAME::CloseModuleEditor )
  76. EVT_SIZE( FOOTPRINT_EDIT_FRAME::OnSize )
  77. EVT_CHOICE( ID_ON_ZOOM_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectZoom )
  78. EVT_CHOICE( ID_ON_GRID_SELECT, FOOTPRINT_EDIT_FRAME::OnSelectGrid )
  79. EVT_TOOL( ID_MODEDIT_SELECT_CURRENT_LIB, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  80. EVT_TOOL( ID_MODEDIT_SAVE_LIBRARY_AS, FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs )
  81. EVT_TOOL( ID_MODEDIT_SAVE_LIBMODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  82. EVT_TOOL( ID_OPEN_MODULE_VIEWER, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  83. EVT_TOOL( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  84. EVT_TOOL( ID_MODEDIT_NEW_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  85. EVT_TOOL( ID_MODEDIT_NEW_MODULE_FROM_WIZARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  86. EVT_TOOL( ID_MODEDIT_IMPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  87. EVT_TOOL( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  88. EVT_TOOL( ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART,
  89. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  90. EVT_TOOL( ID_MODEDIT_SHEET_SET, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  91. EVT_TOOL( ID_GEN_IMPORT_DXF_FILE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  92. EVT_TOOL( wxID_PRINT, FOOTPRINT_EDIT_FRAME::ToPrinter )
  93. EVT_TOOL( ID_MODEDIT_LOAD_MODULE, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  94. EVT_TOOL( ID_MODEDIT_CHECK, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  95. EVT_TOOL( ID_MODEDIT_PAD_SETTINGS, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  96. EVT_TOOL( ID_MODEDIT_LOAD_MODULE_FROM_BOARD, FOOTPRINT_EDIT_FRAME::LoadModuleFromBoard )
  97. EVT_TOOL( ID_MODEDIT_INSERT_MODULE_IN_BOARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  98. EVT_TOOL( ID_MODEDIT_UPDATE_MODULE_IN_BOARD, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  99. EVT_TOOL( ID_MODEDIT_EDIT_MODULE_PROPERTIES, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  100. EVT_TOOL( wxID_UNDO, FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList )
  101. EVT_TOOL( wxID_REDO, FOOTPRINT_EDIT_FRAME::RestoreCopyFromRedoList )
  102. // Vertical tool bar button click event handler.
  103. EVT_TOOL( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  104. EVT_TOOL( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  105. EVT_TOOL_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL,
  106. FOOTPRINT_EDIT_FRAME::OnVerticalToolbar )
  107. // Options Toolbar (ID_TB_OPTIONS_SHOW_PADS_SKETCH id is managed in PCB_BASE_FRAME)
  108. EVT_TOOL( ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, FOOTPRINT_EDIT_FRAME::OnSelectOptionToolbar )
  109. EVT_TOOL( ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH, FOOTPRINT_EDIT_FRAME::OnSelectOptionToolbar )
  110. EVT_TOOL( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE, FOOTPRINT_EDIT_FRAME::OnSelectOptionToolbar )
  111. // Preferences and option menus
  112. EVT_MENU( ID_PREFERENCES_HOTKEY_EXPORT_CONFIG,
  113. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  114. EVT_MENU( ID_PREFERENCES_HOTKEY_IMPORT_CONFIG,
  115. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  116. EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_EDITOR,
  117. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  118. EVT_MENU( ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST,
  119. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  120. EVT_MENU( ID_PCB_LIB_WIZARD,
  121. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  122. EVT_MENU( ID_PCB_LIB_TABLE_EDIT,
  123. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  124. EVT_MENU( wxID_PREFERENCES,
  125. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  126. EVT_MENU( ID_PCB_DISPLAY_OPTIONS_SETUP,
  127. FOOTPRINT_EDIT_FRAME::ProcessPreferences )
  128. EVT_MENU( ID_PREFERENCES_CONFIGURE_PATHS, FOOTPRINT_EDIT_FRAME::OnConfigurePaths )
  129. // popup commands
  130. EVT_MENU_RANGE( ID_POPUP_PCB_START_RANGE, ID_POPUP_PCB_END_RANGE,
  131. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  132. EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
  133. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  134. EVT_MENU( ID_POPUP_MODEDIT_EDIT_BODY_ITEM,
  135. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  136. EVT_MENU( ID_POPUP_MODEDIT_EDIT_WIDTH_ALL_EDGE,
  137. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  138. EVT_MENU( ID_POPUP_MODEDIT_EDIT_LAYER_ALL_EDGE,
  139. FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  140. EVT_MENU( ID_POPUP_MODEDIT_ENTER_EDGE_WIDTH, 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_DRAWINGS_WIDTHS_SETUP, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  146. EVT_MENU( ID_PCB_PAD_SETUP, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  147. EVT_MENU( ID_PCB_USER_GRID_SETUP, FOOTPRINT_EDIT_FRAME::Process_Special_Functions )
  148. // Menu Help
  149. EVT_MENU( wxID_HELP, EDA_DRAW_FRAME::GetKicadHelp )
  150. EVT_MENU( wxID_INDEX, EDA_DRAW_FRAME::GetKicadHelp )
  151. EVT_MENU( ID_HELP_GET_INVOLVED, EDA_DRAW_FRAME::GetKicadContribute )
  152. EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::GetKicadAbout )
  153. // Menu 3D Frame
  154. EVT_MENU( ID_MENU_PCB_SHOW_3D_FRAME, FOOTPRINT_EDIT_FRAME::Show3D_Frame )
  155. // Switching canvases
  156. EVT_MENU( ID_MENU_CANVAS_LEGACY, PCB_BASE_FRAME::SwitchCanvas )
  157. EVT_MENU( ID_MENU_CANVAS_CAIRO, PCB_BASE_FRAME::SwitchCanvas )
  158. EVT_MENU( ID_MENU_CANVAS_OPENGL, PCB_BASE_FRAME::SwitchCanvas )
  159. // UI update events.
  160. EVT_UPDATE_UI( ID_MODEDIT_DELETE_PART, FOOTPRINT_EDIT_FRAME::OnUpdateLibSelected )
  161. EVT_UPDATE_UI( ID_MODEDIT_SELECT_CURRENT_LIB, FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib )
  162. EVT_UPDATE_UI( ID_MODEDIT_EXPORT_PART, FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  163. EVT_UPDATE_UI( ID_MODEDIT_CREATE_NEW_LIB_AND_SAVE_CURRENT_PART,
  164. FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  165. EVT_UPDATE_UI( ID_MODEDIT_SAVE_LIBMODULE, FOOTPRINT_EDIT_FRAME::OnUpdateLibAndModuleSelected )
  166. EVT_UPDATE_UI( ID_MODEDIT_LOAD_MODULE_FROM_BOARD,
  167. FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard )
  168. EVT_UPDATE_UI( ID_MODEDIT_INSERT_MODULE_IN_BOARD,
  169. FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard )
  170. EVT_UPDATE_UI( ID_MODEDIT_UPDATE_MODULE_IN_BOARD,
  171. FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard )
  172. EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar )
  173. EVT_UPDATE_UI( ID_ZOOM_SELECTION, FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar )
  174. EVT_UPDATE_UI_RANGE( ID_MODEDIT_PAD_TOOL, ID_MODEDIT_MEASUREMENT_TOOL,
  175. FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar )
  176. // Option toolbar:
  177. EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH,
  178. FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar )
  179. EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH,
  180. FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar )
  181. EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE,
  182. FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar )
  183. EVT_UPDATE_UI( ID_GEN_IMPORT_DXF_FILE,
  184. FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected )
  185. END_EVENT_TABLE()
  186. #define FOOTPRINT_EDIT_FRAME_NAME wxT( "ModEditFrame" )
  187. FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  188. PCB_BASE_EDIT_FRAME( aKiway, aParent, FRAME_PCB_MODULE_EDITOR, wxEmptyString,
  189. wxDefaultPosition, wxDefaultSize,
  190. KICAD_DEFAULT_DRAWFRAME_STYLE, GetFootprintEditorFrameName() )
  191. {
  192. m_showBorderAndTitleBlock = false; // true to show the frame references
  193. m_showAxis = true; // true to show X and Y axis on screen
  194. m_showGridAxis = true; // show the grid origin axis
  195. m_hotkeysDescrList = g_Module_Editor_Hokeys_Descr;
  196. // Give an icon
  197. wxIcon icon;
  198. icon.CopyFromBitmap( KiBitmap( icon_modedit_xpm ) );
  199. SetIcon( icon );
  200. // Show a title (frame title + footprint name):
  201. updateTitle();
  202. // Create GAL canvas
  203. PCB_BASE_FRAME* parentFrame = static_cast<PCB_BASE_FRAME*>( Kiway().Player( FRAME_PCB, true ) );
  204. PCB_DRAW_PANEL_GAL* drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize,
  205. GetGalDisplayOptions(),
  206. parentFrame->GetGalCanvas()->GetBackend() );
  207. SetGalCanvas( drawPanel );
  208. SetBoard( new BOARD() );
  209. // In modedit, the default net clearance is not known.
  210. // (it depends on the actual board)
  211. // So we do not show the default clearance, by setting it to 0
  212. // The footprint or pad specific clearance will be shown
  213. GetBoard()->GetDesignSettings().GetDefault()->SetClearance( 0 );
  214. // Don't show the default board solder mask clearance in the footprint editor. Only the
  215. // footprint or pad clearance setting should be shown if it is not 0.
  216. GetBoard()->GetDesignSettings().m_SolderMaskMargin = 0;
  217. // restore the last footprint from the project, if any
  218. restoreLastFootprint();
  219. // Ensure all layers and items are visible:
  220. // In footprint editor, some layers have no meaning or
  221. // cannot be used, but we show all of them, at least to be able
  222. // to edit a bad layer
  223. GetBoard()->SetVisibleAlls();
  224. wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
  225. m_Layers = new PCB_LAYER_WIDGET( this, GetCanvas(), font.GetPointSize(), true );
  226. LoadSettings( config() );
  227. SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
  228. GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax );
  229. GetScreen()->SetCurItem( NULL );
  230. GetScreen()->AddGrid( m_UserGridSize, m_UserGridUnit, ID_POPUP_GRID_USER );
  231. GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId );
  232. // In modedit, set the default paper size to A4:
  233. // this should be OK for all footprint to plot/print
  234. SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) );
  235. SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
  236. ReCreateMenuBar();
  237. ReCreateHToolbar();
  238. ReCreateAuxiliaryToolbar();
  239. ReCreateVToolbar();
  240. ReCreateOptToolbar();
  241. if( m_canvas )
  242. m_canvas->SetEnableBlockCommands( true );
  243. m_auimgr.SetManagedWindow( this );
  244. EDA_PANEINFO horiz;
  245. horiz.HorizontalToolbarPane();
  246. EDA_PANEINFO vert;
  247. vert.VerticalToolbarPane();
  248. EDA_PANEINFO mesg_pane;
  249. mesg_pane.MessageToolbarPane();
  250. // Create a wxAuiPaneInfo for the Layers Manager, not derived from the template.
  251. // LAYER_WIDGET is floatable, but initially docked at far right
  252. EDA_PANEINFO lyrs;
  253. lyrs.LayersToolbarPane();
  254. lyrs.MinSize( m_Layers->GetBestSize() ); // updated in ReFillLayerWidget
  255. lyrs.BestSize( m_Layers->GetBestSize() );
  256. lyrs.Caption( _( "Visibles" ) );
  257. m_auimgr.AddPane( m_mainToolBar,
  258. wxAuiPaneInfo( horiz ).Name( "m_mainToolBar" ).Top(). Row( 0 ) );
  259. m_auimgr.AddPane( m_auxiliaryToolBar,
  260. wxAuiPaneInfo( horiz ).Name( "m_auxiliaryToolBar" ).Top().Row( 1 ) );
  261. // The main right vertical toolbar
  262. m_auimgr.AddPane( m_drawToolBar,
  263. wxAuiPaneInfo( vert ).Name( "m_VToolBar" ).Right().Layer(1) );
  264. // Add the layer manager ( most right side of pcbframe )
  265. m_auimgr.AddPane( m_Layers, lyrs.Name( "m_LayersManagerToolBar" ).Right().Layer( 2 ) );
  266. // Layers manager is visible
  267. m_auimgr.GetPane( "m_LayersManagerToolBar" ).Show( true );
  268. // The left vertical toolbar (fast acces to display options)
  269. m_auimgr.AddPane( m_optionsToolBar,
  270. wxAuiPaneInfo( vert ).Name( "m_optionsToolBar" ). Left().Layer(1) );
  271. m_auimgr.AddPane( m_canvas,
  272. wxAuiPaneInfo().Name( "DrawFrame" ).CentrePane() );
  273. m_auimgr.AddPane( (wxWindow*) GetGalCanvas(),
  274. wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() );
  275. m_auimgr.AddPane( m_messagePanel,
  276. wxAuiPaneInfo( mesg_pane ).Name( "MsgPanel" ).Bottom().Layer(10) );
  277. // Create the manager and dispatcher & route draw panel events to the dispatcher
  278. setupTools();
  279. GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
  280. UseGalCanvas( parentFrame->IsGalCanvasActive() );
  281. if( m_auimgr.GetPane( "m_LayersManagerToolBar" ).IsShown() )
  282. {
  283. m_Layers->ReFill();
  284. m_Layers->ReFillRender();
  285. GetScreen()->m_Active_Layer = F_SilkS;
  286. m_Layers->SelectLayer( F_SilkS );
  287. m_Layers->OnLayerSelected();
  288. }
  289. m_auimgr.Update();
  290. Raise(); // On some window managers, this is needed
  291. Show( true );
  292. Zoom_Automatique( false );
  293. }
  294. FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
  295. {
  296. // save the footprint in the PROJECT
  297. retainLastFootprint();
  298. delete m_Layers;
  299. }
  300. BOARD_ITEM_CONTAINER* FOOTPRINT_EDIT_FRAME::GetModel() const
  301. {
  302. return GetBoard()->m_Modules;
  303. }
  304. const wxString FOOTPRINT_EDIT_FRAME::getLibPath()
  305. {
  306. try
  307. {
  308. const wxString& nickname = GetCurrentLib();
  309. const FP_LIB_TABLE_ROW* row = Prj().PcbFootprintLibs()->FindRow( nickname );
  310. return row->GetFullURI( true );
  311. }
  312. catch( const IO_ERROR& )
  313. {
  314. return wxEmptyString;
  315. }
  316. }
  317. const wxString FOOTPRINT_EDIT_FRAME::GetCurrentLib() const
  318. {
  319. return Prj().GetRString( PROJECT::PCB_LIB_NICKNAME );
  320. };
  321. void FOOTPRINT_EDIT_FRAME::retainLastFootprint()
  322. {
  323. PCB_IO pcb_io;
  324. MODULE* module = GetBoard()->m_Modules;
  325. if( module )
  326. {
  327. pcb_io.Format( module );
  328. wxString pretty = FROM_UTF8( pcb_io.GetStringOutput( true ).c_str() );
  329. // save the footprint in the RSTRING facility.
  330. Prj().SetRString( PROJECT::PCB_FOOTPRINT, pretty );
  331. }
  332. }
  333. void FOOTPRINT_EDIT_FRAME::restoreLastFootprint()
  334. {
  335. wxString pretty = Prj().GetRString( PROJECT::PCB_FOOTPRINT );
  336. if( !!pretty )
  337. {
  338. PCB_IO pcb_io;
  339. MODULE* module = NULL;
  340. try
  341. {
  342. module = (MODULE*) pcb_io.Parse( pretty );
  343. }
  344. catch( const PARSE_ERROR& )
  345. {
  346. // unlikely to be a problem, since we produced the pretty string.
  347. wxLogError( "PARSE_ERROR" );
  348. }
  349. catch( const IO_ERROR& )
  350. {
  351. // unlikely to be a problem, since we produced the pretty string.
  352. wxLogError( "IO_ERROR" );
  353. }
  354. if( module )
  355. {
  356. // assumes BOARD is empty.
  357. wxASSERT( GetBoard()->m_Modules == NULL );
  358. // no idea, its monkey see monkey do. I would encapsulate this into
  359. // a member function if its actually necessary.
  360. module->SetParent( GetBoard() );
  361. module->SetLink( 0 );
  362. GetBoard()->Add( module );
  363. }
  364. }
  365. }
  366. const wxChar* FOOTPRINT_EDIT_FRAME::GetFootprintEditorFrameName()
  367. {
  368. return FOOTPRINT_EDIT_FRAME_NAME;
  369. }
  370. BOARD_DESIGN_SETTINGS& FOOTPRINT_EDIT_FRAME::GetDesignSettings() const
  371. {
  372. return GetBoard()->GetDesignSettings();
  373. }
  374. void FOOTPRINT_EDIT_FRAME::SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings )
  375. {
  376. GetBoard()->SetDesignSettings( aSettings );
  377. }
  378. const PCB_PLOT_PARAMS& FOOTPRINT_EDIT_FRAME::GetPlotSettings() const
  379. {
  380. // get the settings from the parent editor, not our BOARD.
  381. // @todo(DICK) change the routing to some default or the board directly, parent may not exist
  382. PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB, true );
  383. wxASSERT( parentFrame );
  384. return parentFrame->GetPlotSettings();
  385. }
  386. void FOOTPRINT_EDIT_FRAME::SetPlotSettings( const PCB_PLOT_PARAMS& aSettings )
  387. {
  388. // set the settings into parent editor, not our BOARD.
  389. // @todo(DICK) change the routing to some default or the board directly, parent may not exist
  390. PCB_BASE_FRAME* parentFrame = (PCB_BASE_FRAME*) Kiway().Player( FRAME_PCB, true );
  391. wxASSERT( parentFrame );
  392. parentFrame->SetPlotSettings( aSettings );
  393. }
  394. void FOOTPRINT_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg )
  395. {
  396. PCB_BASE_FRAME::LoadSettings( aCfg );
  397. wxConfigLoadSetups( aCfg, GetConfigurationSettings() );
  398. // Ensure some params are valid
  399. BOARD_DESIGN_SETTINGS& settings = GetDesignSettings();
  400. // Usually, graphic items are drawn on F_SilkS or F_Fab layer
  401. // Force these layers if not default
  402. if( ( settings.m_RefDefaultlayer != F_SilkS ) && ( settings.m_RefDefaultlayer != F_Fab ) )
  403. settings.m_RefDefaultlayer = F_SilkS;
  404. if( ( settings.m_ValueDefaultlayer != F_SilkS ) && ( settings.m_ValueDefaultlayer != F_Fab ) )
  405. settings.m_ValueDefaultlayer = F_Fab;
  406. }
  407. void FOOTPRINT_EDIT_FRAME::SaveSettings( wxConfigBase* aCfg )
  408. {
  409. PCB_BASE_FRAME::SaveSettings( aCfg );
  410. wxConfigSaveSetups( aCfg, GetConfigurationSettings() );
  411. }
  412. void FOOTPRINT_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
  413. {
  414. if( GetScreen()->IsModify() )
  415. {
  416. int ii = DisplayExitDialog( this, _( "Save the changes to the footprint before closing?" ) );
  417. switch( ii )
  418. {
  419. case wxID_NO:
  420. break;
  421. case wxID_YES:
  422. // code from FOOTPRINT_EDIT_FRAME::Process_Special_Functions,
  423. // at case ID_MODEDIT_SAVE_LIBMODULE
  424. if( GetBoard()->m_Modules && GetCurrentLib().size() )
  425. {
  426. if( SaveFootprintInLibrary( GetCurrentLib(), GetBoard()->m_Modules, true, true ) )
  427. {
  428. // save was correct
  429. GetScreen()->ClrModify();
  430. break;
  431. }
  432. }
  433. else
  434. {
  435. DisplayError( this, _( "Library is not set, the footprint could not be saved." ) );
  436. }
  437. // fall through: cancel the close because of an error
  438. case wxID_CANCEL:
  439. Event.Veto();
  440. return;
  441. }
  442. }
  443. if( IsGalCanvasActive() )
  444. GetGalCanvas()->StopDrawing();
  445. //close the editor
  446. Destroy();
  447. }
  448. void FOOTPRINT_EDIT_FRAME::CloseModuleEditor( wxCommandEvent& Event )
  449. {
  450. Close();
  451. }
  452. void FOOTPRINT_EDIT_FRAME::OnUpdateVerticalToolbar( wxUpdateUIEvent& aEvent )
  453. {
  454. aEvent.Enable( GetBoard()->m_Modules != NULL );
  455. if( aEvent.GetEventObject() == m_drawToolBar )
  456. aEvent.Check( GetToolId() == aEvent.GetId() );
  457. }
  458. void FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar( wxUpdateUIEvent& aEvent )
  459. {
  460. int id = aEvent.GetId();
  461. DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
  462. bool state = false;
  463. switch( id )
  464. {
  465. case ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH:
  466. state = displ_opts->m_DisplayModTextFill == SKETCH;
  467. break;
  468. case ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH:
  469. state = displ_opts->m_DisplayModEdgeFill == SKETCH;
  470. break;
  471. case ID_TB_OPTIONS_SHOW_HIGH_CONTRAST_MODE:
  472. state = displ_opts->m_ContrastModeDisplay;
  473. break;
  474. default:
  475. wxMessageBox( "FOOTPRINT_EDIT_FRAME::OnUpdateOptionsToolbar error" );
  476. break;
  477. }
  478. aEvent.Check( state );
  479. }
  480. void FOOTPRINT_EDIT_FRAME::OnUpdateLibSelected( wxUpdateUIEvent& aEvent )
  481. {
  482. bool enable = getLibPath() != wxEmptyString;
  483. aEvent.Enable( enable );
  484. GetMenuBar()->Enable( ID_MODEDIT_SAVE_LIBRARY_AS, enable );
  485. }
  486. void FOOTPRINT_EDIT_FRAME::OnUpdateModuleSelected( wxUpdateUIEvent& aEvent )
  487. {
  488. aEvent.Enable( GetBoard()->m_Modules != NULL );
  489. }
  490. void FOOTPRINT_EDIT_FRAME::OnUpdateLibAndModuleSelected( wxUpdateUIEvent& aEvent )
  491. {
  492. aEvent.Enable( getLibPath() != wxEmptyString && GetBoard()->m_Modules != NULL );
  493. }
  494. void FOOTPRINT_EDIT_FRAME::OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent )
  495. {
  496. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  497. aEvent.Enable( frame && frame->GetBoard()->m_Modules != NULL );
  498. }
  499. void FOOTPRINT_EDIT_FRAME::OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent )
  500. {
  501. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  502. MODULE* module_in_edit = GetBoard()->m_Modules;
  503. bool canInsert = frame && module_in_edit && !module_in_edit->GetLink();
  504. // If the source was deleted, the module can inserted but not updated in the board.
  505. if( frame && module_in_edit && module_in_edit->GetLink() ) // this is not a new module
  506. {
  507. BOARD* mainpcb = frame->GetBoard();
  508. MODULE* source_module = mainpcb->m_Modules;
  509. // search if the source module was not deleted:
  510. for( ; source_module != NULL; source_module = source_module->Next() )
  511. {
  512. if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
  513. break;
  514. }
  515. canInsert = ( source_module == NULL );
  516. }
  517. aEvent.Enable( canInsert );
  518. }
  519. void FOOTPRINT_EDIT_FRAME::OnUpdateReplaceModuleInBoard( wxUpdateUIEvent& aEvent )
  520. {
  521. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*) Kiway().Player( FRAME_PCB, false );
  522. MODULE* module_in_edit = GetBoard()->m_Modules;
  523. bool canReplace = frame && module_in_edit && module_in_edit->GetLink();
  524. if( canReplace ) // this is not a new module, but verify if the source is still on board
  525. {
  526. BOARD* mainpcb = frame->GetBoard();
  527. MODULE* source_module = mainpcb->m_Modules;
  528. // search if the source module was not deleted:
  529. for( ; source_module != NULL; source_module = source_module->Next() )
  530. {
  531. if( module_in_edit->GetLink() == source_module->GetTimeStamp() )
  532. break;
  533. }
  534. canReplace = ( source_module != NULL );
  535. }
  536. aEvent.Enable( canReplace );
  537. }
  538. void FOOTPRINT_EDIT_FRAME::OnUpdateSelectCurrentLib( wxUpdateUIEvent& aEvent )
  539. {
  540. FP_LIB_TABLE* fptbl = Prj().PcbFootprintLibs();
  541. aEvent.Enable( fptbl && !fptbl->IsEmpty() );
  542. }
  543. void FOOTPRINT_EDIT_FRAME::Show3D_Frame( wxCommandEvent& event )
  544. {
  545. EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
  546. if( draw3DFrame )
  547. {
  548. // Raising the window does not show the window on Windows if iconized.
  549. // This should work on any platform.
  550. if( draw3DFrame->IsIconized() )
  551. draw3DFrame->Iconize( false );
  552. draw3DFrame->Raise();
  553. // Raising the window does not set the focus on Linux. This should work on any platform.
  554. if( wxWindow::FindFocus() != draw3DFrame )
  555. draw3DFrame->SetFocus();
  556. return;
  557. }
  558. draw3DFrame = new EDA_3D_VIEWER( &Kiway(), this, _( "3D Viewer" ) );
  559. draw3DFrame->Raise(); // Needed with some Window Managers
  560. draw3DFrame->Show( true );
  561. }
  562. bool FOOTPRINT_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
  563. {
  564. bool eventHandled = true;
  565. // Filter out the 'fake' mouse motion after a keyboard movement
  566. if( !aHotKey && m_movingCursorWithKeyboard )
  567. {
  568. m_movingCursorWithKeyboard = false;
  569. return false;
  570. }
  571. // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed
  572. // for next cursor position
  573. // ( shift or ctrl key down are PAN command with mouse wheel)
  574. bool snapToGrid = true;
  575. if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
  576. snapToGrid = false;
  577. wxPoint oldpos = GetCrossHairPosition();
  578. wxPoint pos = aPosition;
  579. GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
  580. SetCrossHairPosition( pos, snapToGrid );
  581. RefreshCrossHair( oldpos, aPosition, aDC );
  582. if( aHotKey )
  583. {
  584. eventHandled = OnHotKey( aDC, aHotKey, aPosition );
  585. }
  586. UpdateStatusBar();
  587. return eventHandled;
  588. }
  589. void FOOTPRINT_EDIT_FRAME::OnModify()
  590. {
  591. PCB_BASE_FRAME::OnModify();
  592. EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
  593. if( draw3DFrame )
  594. draw3DFrame->ReloadRequest();
  595. }
  596. void FOOTPRINT_EDIT_FRAME::updateTitle()
  597. {
  598. wxString nickname = GetCurrentLib();
  599. wxString nickname_display = _( "no active library" );
  600. bool writable = true;
  601. if( !!nickname )
  602. {
  603. try
  604. {
  605. writable = Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname );
  606. nickname_display = nickname;
  607. }
  608. catch( const IO_ERROR& )
  609. {
  610. // user may be bewildered as to why after selecting a library it is not showing up
  611. // in the title, we could show an error message, but that should have been done at time
  612. // of libary selection UI.
  613. }
  614. }
  615. wxString path_display;
  616. if( nickname.size() )
  617. {
  618. FP_LIB_TABLE* libtable = Prj().PcbFootprintLibs();
  619. const FP_LIB_TABLE_ROW* row = libtable->FindRow( nickname );
  620. if( row )
  621. path_display = L" \u2014 " + row->GetFullURI( true );
  622. }
  623. wxString title;
  624. title.Printf( _( "Footprint Editor" ) + L" \u2014 %s%s%s",
  625. nickname_display,
  626. writable ? wxString( wxEmptyString ) : _( " [Read Only]" ),
  627. path_display );
  628. SetTitle( title );
  629. }
  630. void FOOTPRINT_EDIT_FRAME::updateView()
  631. {
  632. static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() );
  633. m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
  634. m_toolManager->RunAction( ACTIONS::zoomFitScreen, true );
  635. }
  636. bool FOOTPRINT_EDIT_FRAME::IsGridVisible() const
  637. {
  638. return IsElementVisible( LAYER_GRID );
  639. }
  640. void FOOTPRINT_EDIT_FRAME::SetGridVisibility(bool aVisible)
  641. {
  642. SetElementVisibility( LAYER_GRID, aVisible );
  643. }
  644. bool FOOTPRINT_EDIT_FRAME::IsElementVisible( GAL_LAYER_ID aElement ) const
  645. {
  646. return GetBoard()->IsElementVisible( aElement );
  647. }
  648. void FOOTPRINT_EDIT_FRAME::SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState )
  649. {
  650. GetGalCanvas()->GetView()->SetLayerVisible( aElement , aNewState );
  651. GetBoard()->SetElementVisibility( aElement, aNewState );
  652. m_Layers->SetRenderState( aElement, aNewState );
  653. }
  654. void FOOTPRINT_EDIT_FRAME::ProcessPreferences( wxCommandEvent& event )
  655. {
  656. int id = event.GetId();
  657. switch( id )
  658. {
  659. // Hotkey IDs
  660. case ID_PREFERENCES_HOTKEY_EXPORT_CONFIG:
  661. ExportHotkeyConfigToFile( g_Module_Editor_Hokeys_Descr, "pcbnew" );
  662. break;
  663. case ID_PREFERENCES_HOTKEY_IMPORT_CONFIG:
  664. ImportHotkeyConfigFromFile( g_Module_Editor_Hokeys_Descr, "pcbnew" );
  665. break;
  666. case ID_PREFERENCES_HOTKEY_SHOW_EDITOR:
  667. InstallHotkeyFrame( this, g_Module_Editor_Hokeys_Descr );
  668. break;
  669. case ID_PREFERENCES_HOTKEY_SHOW_CURRENT_LIST:
  670. // Display current hotkey list for the footprint editor.
  671. DisplayHotkeyList( this, g_Module_Editor_Hokeys_Descr );
  672. break;
  673. case ID_PCB_LIB_WIZARD:
  674. case ID_PCB_LIB_TABLE_EDIT:
  675. {
  676. bool tableChanged = false;
  677. int r = 0;
  678. if( id == ID_PCB_LIB_TABLE_EDIT )
  679. r = InvokePcbLibTableEditor( this, &GFootprintTable, Prj().PcbFootprintLibs() );
  680. else
  681. r = InvokeFootprintWizard( this, &GFootprintTable, Prj().PcbFootprintLibs() );
  682. if( r & 1 )
  683. {
  684. try
  685. {
  686. FILE_OUTPUTFORMATTER sf( FP_LIB_TABLE::GetGlobalTableFileName() );
  687. GFootprintTable.Format( &sf, 0 );
  688. tableChanged = true;
  689. }
  690. catch( const IO_ERROR& ioe )
  691. {
  692. wxString msg = wxString::Format( _(
  693. "Error occurred saving the global footprint library "
  694. "table:\n\n%s" ),
  695. GetChars( ioe.What().GetData() )
  696. );
  697. wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
  698. }
  699. }
  700. if( r & 2 )
  701. {
  702. wxString tblName = Prj().FootprintLibTblName();
  703. try
  704. {
  705. Prj().PcbFootprintLibs()->Save( tblName );
  706. tableChanged = true;
  707. }
  708. catch( const IO_ERROR& ioe )
  709. {
  710. wxString msg = wxString::Format( _(
  711. "Error occurred saving project specific footprint library "
  712. "table:\n\n%s" ),
  713. GetChars( ioe.What() )
  714. );
  715. wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
  716. }
  717. }
  718. FOOTPRINT_VIEWER_FRAME* viewer;
  719. viewer = (FOOTPRINT_VIEWER_FRAME*)Kiway().Player( FRAME_PCB_MODULE_VIEWER, false );
  720. if( tableChanged && viewer != NULL )
  721. viewer->ReCreateLibraryList();
  722. }
  723. break;
  724. case wxID_PREFERENCES:
  725. InvokeFPEditorPrefsDlg( this );
  726. break;
  727. case ID_PCB_DISPLAY_OPTIONS_SETUP:
  728. DIALOG_MODEDIT_DISPLAY_OPTIONS::Invoke( *this );
  729. break;
  730. default:
  731. DisplayError( this, "FOOTPRINT_EDIT_FRAME::ProcessPreferences error" );
  732. }
  733. }
  734. void FOOTPRINT_EDIT_FRAME::OnConfigurePaths( wxCommandEvent& aEvent )
  735. {
  736. Pgm().ConfigurePaths( this );
  737. }
  738. void FOOTPRINT_EDIT_FRAME::setupTools()
  739. {
  740. PCB_DRAW_PANEL_GAL* drawPanel = static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() );
  741. // Create the manager and dispatcher & route draw panel events to the dispatcher
  742. m_toolManager = new TOOL_MANAGER;
  743. m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(),
  744. drawPanel->GetViewControls(), this );
  745. m_actions = new PCB_ACTIONS();
  746. m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
  747. drawPanel->SetEventDispatcher( m_toolDispatcher );
  748. m_toolManager->RegisterTool( new COMMON_TOOLS );
  749. m_toolManager->RegisterTool( new SELECTION_TOOL );
  750. m_toolManager->RegisterTool( new ZOOM_TOOL );
  751. m_toolManager->RegisterTool( new EDIT_TOOL );
  752. m_toolManager->RegisterTool( new PAD_TOOL );
  753. m_toolManager->RegisterTool( new DRAWING_TOOL );
  754. m_toolManager->RegisterTool( new POINT_EDITOR );
  755. m_toolManager->RegisterTool( new PCBNEW_CONTROL );
  756. m_toolManager->RegisterTool( new MODULE_EDITOR_TOOLS );
  757. m_toolManager->RegisterTool( new PLACEMENT_TOOL );
  758. m_toolManager->RegisterTool( new PICKER_TOOL );
  759. m_toolManager->GetTool<PAD_TOOL>()->SetEditModules( true );
  760. m_toolManager->GetTool<SELECTION_TOOL>()->SetEditModules( true );
  761. m_toolManager->GetTool<EDIT_TOOL>()->SetEditModules( true );
  762. m_toolManager->GetTool<DRAWING_TOOL>()->SetEditModules( true );
  763. m_toolManager->InitTools();
  764. m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" );
  765. }
  766. void FOOTPRINT_EDIT_FRAME::UseGalCanvas( bool aEnable )
  767. {
  768. PCB_BASE_EDIT_FRAME::UseGalCanvas( aEnable );
  769. if( aEnable )
  770. {
  771. // Be sure the axis are enabled:
  772. GetGalCanvas()->GetGAL()->SetAxesEnabled( true );
  773. updateView();
  774. }
  775. }