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.

375 lines
12 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
* 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef FOOTPRINT_EDIT_FRAME_H
  20. #define FOOTPRINT_EDIT_FRAME_H
  21. #include <pcb_base_frame.h>
  22. #include <pcb_base_edit_frame.h>
  23. #include <io_mgr.h>
  24. #include <config_params.h>
  25. #include <fp_tree_synchronizing_adapter.h>
  26. class PCB_LAYER_BOX_SELECTOR;
  27. class FP_LIB_TABLE;
  28. class EDGE_MODULE;
  29. class FOOTPRINT_TREE_PANE;
  30. class LIB_MANAGER;
  31. class FOOTPRINT_EDITOR_SETTINGS;
  32. namespace PCB { struct IFACE; } // A KIFACE_I coded in pcbnew.c
  33. class FOOTPRINT_EDIT_FRAME : public PCB_BASE_EDIT_FRAME
  34. {
  35. friend struct PCB::IFACE;
  36. FOOTPRINT_TREE_PANE* m_treePane;
  37. LIB_TREE_MODEL_ADAPTER::PTR m_adapter;
  38. std::unique_ptr<MODULE> m_revertModule;
  39. wxString m_footprintNameWhenLoaded;
  40. int m_defaultLibWidth;
  41. public:
  42. ~FOOTPRINT_EDIT_FRAME();
  43. /**
  44. * Function GetFootprintEditorFrameName (static)
  45. * @return the frame name used when creating the frame
  46. * used to get a reference to this frame, if exists
  47. */
  48. static const wxChar* GetFootprintEditorFrameName();
  49. ///> @copydoc PCB_BASE_EDIT_FRAME::GetModel()
  50. BOARD_ITEM_CONTAINER* GetModel() const override;
  51. /**
  52. * Get if any footprints or libraries have been modified but not saved.
  53. *
  54. * @return true if the any changes have not been saved
  55. */
  56. bool IsContentModified() override;
  57. bool IsCurrentFPFromBoard() const;
  58. FOOTPRINT_EDITOR_SETTINGS* GetSettings();
  59. BOARD_DESIGN_SETTINGS& GetDesignSettings() const override;
  60. void SetDesignSettings( const BOARD_DESIGN_SETTINGS& aSettings ) override;
  61. const PCB_PLOT_PARAMS& GetPlotSettings() const override;
  62. void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings ) override;
  63. void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
  64. void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
  65. const BOX2I GetDocumentExtents() const override;
  66. void OnCloseWindow( wxCloseEvent& Event ) override;
  67. void CloseModuleEditor( wxCommandEvent& Event );
  68. void OnExitKiCad( wxCommandEvent& aEvent );
  69. /**
  70. * switches currently used canvas (Cairo / OpenGL).
  71. * It also reinit the layers manager that slightly changes with canvases
  72. */
  73. void SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) override;
  74. /**
  75. * Update the layer manager and other widgets from the board setup
  76. * (layer and items visibility, colors ...)
  77. */
  78. void UpdateUserInterface();
  79. void Process_Special_Functions( wxCommandEvent& event );
  80. /**
  81. * Refresh the library tree and redraw the window
  82. */
  83. void HardRedraw() override;
  84. /**
  85. * Create the main horizontal toolbar for the footprint editor.
  86. */
  87. void ReCreateHToolbar() override;
  88. void ReCreateVToolbar() override;
  89. void ReCreateOptToolbar() override;
  90. /**
  91. * @brief (Re)Create the menubar for the module editor frame
  92. */
  93. void ReCreateMenuBar() override;
  94. /**
  95. * Re create the layer Box by clearing the old list, and building
  96. * le new one, from the new layers names and cole layers
  97. * @param aForceResizeToolbar = true to resize the parent toolbar
  98. * false if not needed (mainly in parent toolbar creation,
  99. * or when the layers names are not modified)
  100. */
  101. void ReCreateLayerBox( bool aForceResizeToolbar = true );
  102. void OnUpdateLayerSelectBox( wxUpdateUIEvent& aEvent );
  103. // The Tool Framework initalization, for GAL mode
  104. void setupTools();
  105. void OnSaveFootprintAsPng( wxCommandEvent& event );
  106. bool IsSearchTreeShown();
  107. void ToggleSearchTree();
  108. /**
  109. * Save a library to a new name and/or library type.
  110. *
  111. * @note Saving as a new library type requires the plug-in to support saving libraries
  112. * @see PLUGIN::FootprintSave and PLUGIN::FootprintLibCreate
  113. */
  114. bool SaveLibraryAs( const wxString& aLibraryPath );
  115. void OnUpdateModuleSelected( wxUpdateUIEvent& aEvent );
  116. void OnUpdateLoadModuleFromBoard( wxUpdateUIEvent& aEvent );
  117. void OnUpdateInsertModuleInBoard( wxUpdateUIEvent& aEvent );
  118. ///> @copydoc PCB_BASE_EDIT_FRAME::OnEditItemRequest()
  119. void OnEditItemRequest( BOARD_ITEM* aItem ) override;
  120. /**
  121. * Called from the main toolbar to load a footprint from board mainly to edit it.
  122. */
  123. void LoadModuleFromBoard( wxCommandEvent& event );
  124. void LoadModuleFromLibrary( LIB_ID aFPID );
  125. /**
  126. * Returns the adapter object that provides the stored data.
  127. */
  128. LIB_TREE_MODEL_ADAPTER::PTR& GetLibTreeAdapter() { return m_adapter; }
  129. /**
  130. * Save in an existing library a given footprint.
  131. *
  132. * @param aModule = the given footprint
  133. * @return : true if OK, false if abort
  134. */
  135. bool SaveFootprint( MODULE* aModule );
  136. bool SaveFootprintAs( MODULE* aModule );
  137. bool SaveFootprintToBoard( bool aAddNew );
  138. bool SaveFootprintInLibrary( MODULE* aModule, const wxString& aLibraryName );
  139. bool RevertFootprint();
  140. /**
  141. * Must be called after a footprint change
  142. * in order to set the "modify" flag of the current screen
  143. * and prepare, if needed the refresh of the 3D frame showing the footprint
  144. * do not forget to call the basic OnModify function to update auxiliary info
  145. */
  146. void OnModify() override;
  147. // BOARD handling
  148. /**
  149. * Delete all and reinitialize the current board.
  150. *
  151. * @param aQuery = true to prompt user for confirmation, false to initialize silently
  152. */
  153. bool Clear_Pcb( bool aQuery );
  154. /// Return the LIB_ID of the part or library selected in the footprint tree.
  155. LIB_ID GetTreeFPID() const;
  156. LIB_TREE_NODE* GetCurrentTreeNode() const;
  157. /// Return the LIB_ID of the part being edited.
  158. LIB_ID GetLoadedFPID() const;
  159. /// Return the LIB_ID of the part selected in the footprint tree, or the loaded part if
  160. /// there is no selection in the tree.
  161. LIB_ID GetTargetFPID() const;
  162. // importing / exporting Footprint
  163. /**
  164. * Create a file containing only one footprint.
  165. *
  166. * Used to export a footprint
  167. * Exported files have the standard ext .emp
  168. * This is the same format as .mod files but restricted to only one footprint
  169. * So Create a new lib (which will contains one module) and export a footprint
  170. * is basically the same thing
  171. * @param aModule = the module to export
  172. */
  173. void Export_Module( MODULE* aModule );
  174. /**
  175. * Read a file containing only one footprint.
  176. *
  177. * Used to import (after exporting) a footprint
  178. * Exported files have the standard ext .emp
  179. * This is the same format as .mod files but restricted to only one footprint
  180. * The import function can also read gpcb footprint file, in Newlib format
  181. * (One footprint per file, Newlib files have no special ext.)
  182. */
  183. MODULE* Import_Module( const wxString& aName = wxT("") );
  184. /**
  185. * Load in Modedit a footprint from the main board.
  186. *
  187. * @param Module = the module to load. If NULL, a module reference will we asked to user
  188. * @return true if a module isloaded, false otherwise.
  189. */
  190. bool Load_Module_From_BOARD( MODULE* Module );
  191. /**
  192. * Display the list of modules currently existing on the BOARD.
  193. *
  194. * @return a pointer to a module if this module is selected or NULL otherwise
  195. * @param aPcb = the board from modules can be loaded
  196. */
  197. MODULE* SelectFootprintFromBoard( BOARD* aPcb );
  198. // functions to edit footprint edges
  199. /**
  200. * Delete the given module from its library.
  201. */
  202. bool DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aConfirm );
  203. /**
  204. * Test whether a given element category is visible.
  205. *
  206. * @param aElement is from the enum by the same name
  207. * @return bool - true if the element is visible.
  208. * @see enum PCB_LAYER_ID
  209. */
  210. bool IsElementVisible( GAL_LAYER_ID aElement ) const;
  211. /**
  212. * Function SetElementVisibility
  213. * changes the visibility of an element category
  214. * @param aElement is from the enum by the same name
  215. * @param aNewState = The new visibility state of the element category
  216. * @see enum PCB_LAYER_ID
  217. */
  218. void SetElementVisibility( GAL_LAYER_ID aElement, bool aNewState );
  219. /**
  220. * @return the color of the grid
  221. */
  222. COLOR4D GetGridColor() override;
  223. ///> @copydoc PCB_BASE_FRAME::SetActiveLayer()
  224. void SetActiveLayer( PCB_LAYER_ID aLayer ) override;
  225. ///> @copydoc PCB_BASE_FRAME::OnUpdateLayerAlpha()
  226. void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) override;
  227. ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
  228. void ActivateGalCanvas() override;
  229. /**
  230. * Load a KiCad board (.kicad_pcb) from \a aFileName.
  231. *
  232. * @param aFileSet - hold the BOARD file to load, a vector of one element.
  233. * @param aCtl - KICTL_ bits, one to indicate that an append of the board file
  234. * aFileName to the currently loaded file is desired.
  235. * @see #KIWAY_PLAYER for bit defines.
  236. * @return bool - false if file load fails, otherwise true.
  237. */
  238. bool OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl = 0 ) override;
  239. /**
  240. * Override from PCB_BASE_EDIT_FRAME which adds a module to the editor's dummy board,
  241. * NOT to the user's PCB.
  242. */
  243. void AddModuleToBoard( MODULE* module ) override;
  244. /**
  245. * Allows Modedit to install its preferences panel into the preferences dialog.
  246. */
  247. void InstallPreferences( PAGED_DIALOG* aParent, PANEL_HOTKEYS_EDITOR* aHotkeysPanel ) override;
  248. void ReFillLayerWidget();
  249. /**
  250. * Update visible items after a language change.
  251. */
  252. void ShowChangedLanguage() override;
  253. /**
  254. * Called after the preferences dialog is run.
  255. */
  256. void CommonSettingsChanged( bool aEnvVarsChanged ) override;
  257. /**
  258. * Synchronize the footprint library tree to the current state of the footprint library
  259. * table.
  260. * @param aProgress
  261. */
  262. void SyncLibraryTree( bool aProgress );
  263. /**
  264. * Filter, sort, and redisplay the library tree. Does NOT synchronize it with libraries
  265. * in disk.
  266. */
  267. void RegenerateLibraryTree();
  268. void FocusOnLibID( const LIB_ID& aLibID );
  269. void KiwayMailIn( KIWAY_EXPRESS& mail ) override;
  270. void SyncToolbars() override;
  271. DECLARE_EVENT_TABLE()
  272. protected:
  273. /// protected so only friend PCB::IFACE::CreateWindow() can act as sole factory.
  274. FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE aBackend );
  275. PCB_LAYER_BOX_SELECTOR* m_selLayerBox; // a combo box to display and select active layer
  276. FOOTPRINT_EDITOR_SETTINGS* m_settings;
  277. /**
  278. * Make sure the footprint info list is loaded (with a progress dialog) and then initialize
  279. * the footprint library tree.
  280. */
  281. void initLibraryTree();
  282. /**
  283. * Updates window title according to getLibNickName().
  284. */
  285. void updateTitle();
  286. /// Reloads displayed items and sets view.
  287. void updateView();
  288. void restoreLastFootprint();
  289. void retainLastFootprint();
  290. /**
  291. * Run the Footprint Properties dialog and handle changes made in it.
  292. */
  293. void editFootprintProperties( MODULE* aFootprint );
  294. };
  295. #endif // FOOTPRINT_EDIT_FRAME_H