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.

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