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.

255 lines
8.9 KiB

5 years ago
5 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  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. #ifndef BASE_EDIT_FRAME_H
  27. #define BASE_EDIT_FRAME_H
  28. #include <pcb_base_frame.h>
  29. class APPEARANCE_CONTROLS;
  30. class BOARD_ITEM_CONTAINER;
  31. class PANEL_SELECTION_FILTER;
  32. class PROPERTIES_PANEL;
  33. /**
  34. * Common, abstract interface for edit frames.
  35. */
  36. class PCB_BASE_EDIT_FRAME : public PCB_BASE_FRAME
  37. {
  38. public:
  39. PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
  40. const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
  41. long aStyle, const wxString& aFrameName );
  42. virtual ~PCB_BASE_EDIT_FRAME();
  43. bool TryBefore( wxEvent& aEvent ) override;
  44. void doCloseWindow() override;
  45. /**
  46. * If a library name is given, creates a new footprint library in the project folder
  47. * with the given name. If no library name is given it prompts user for a library path,
  48. * then creates a new footprint library at that location.
  49. * If library exists, user is warned about that, and is given a chance
  50. * to abort the new creation, and in that case existing library is first deleted.
  51. *
  52. * @param aProposedName is the initial path and filename shown in the file chooser dialog.
  53. * @return The newly created library path if library was successfully created, else
  54. * wxEmptyString because user aborted or error.
  55. */
  56. wxString CreateNewLibrary( const wxString& aLibName = wxEmptyString,
  57. const wxString& aProposedName = wxEmptyString );
  58. wxString CreateNewProjectLibrary( const wxString& aLibName = wxEmptyString,
  59. const wxString& aProposedName = wxEmptyString );
  60. /**
  61. * Add an existing library to either the global or project library table.
  62. *
  63. * @param aFileName the library to add; a file open dialog will be displayed if empty.
  64. * @return true if successfully added.
  65. */
  66. bool AddLibrary( const wxString& aLibName = wxEmptyString, FP_LIB_TABLE* aTable = nullptr );
  67. /**
  68. * Install the corresponding dialog editor for the given item.
  69. *
  70. * @param aDC the current device context.
  71. * @param aItem a pointer to the BOARD_ITEM to edit.
  72. */
  73. virtual void OnEditItemRequest( BOARD_ITEM* aItem ) = 0;
  74. /**
  75. * Create a new entry in undo list of commands.
  76. *
  77. * Add a picker to handle \a aItemToCopy.
  78. *
  79. * @param aItemToCopy the board item modified by the command to undo.
  80. * @param aTypeCommand command type (see enum UNDO_REDO).
  81. */
  82. void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand ) override;
  83. /**
  84. * Create a new entry in undo list of commands.
  85. *
  86. * Add a list of pickers to handle a list of items.
  87. *
  88. * @param aItemsList the list of items modified by the command to undo.
  89. * @param aCommandType command type (see enum UNDO_REDO).
  90. */
  91. void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO aCommandType ) override;
  92. /**
  93. * As SaveCopyInUndoList, but appends the changes to the last undo item on the stack.
  94. */
  95. void AppendCopyToUndoList( const PICKED_ITEMS_LIST& aItemsList,
  96. UNDO_REDO aCommandType ) override;
  97. /**
  98. * Redo the last edit:
  99. * - Save the current board in Undo list
  100. * - Get an old version of the board from Redo list
  101. */
  102. void RestoreCopyFromRedoList( wxCommandEvent& aEvent );
  103. /**
  104. * Undo the last edit:
  105. * - Save the current board in Redo list
  106. * - Get an old version of the board from Undo list
  107. */
  108. void RestoreCopyFromUndoList( wxCommandEvent& aEvent );
  109. /**
  110. * Perform an undo of the last edit **without** logging a corresponding redo. Used to cancel
  111. * an in-progress operation.
  112. */
  113. void RollbackFromUndo();
  114. /**
  115. * Used in undo or redo command.
  116. *
  117. * Put data pointed by List in the previous state, i.e. the state memorized by \a aList.
  118. *
  119. * @param aList a PICKED_ITEMS_LIST pointer to the list of items to undo/redo.
  120. */
  121. void PutDataInPreviousState( PICKED_ITEMS_LIST* aList );
  122. /**
  123. * Check if the undo and redo operations are currently blocked.
  124. */
  125. bool UndoRedoBlocked() const
  126. {
  127. return m_undoRedoBlocked;
  128. }
  129. /**
  130. * Enable/disable undo and redo operations.
  131. */
  132. void UndoRedoBlock( bool aBlock = true )
  133. {
  134. m_undoRedoBlocked = aBlock;
  135. }
  136. /**
  137. * Override this function in the PCB_BASE_EDIT_FRAME to refill the layer widget
  138. *
  139. * @param aVisible true if the grid must be shown.
  140. */
  141. void SetGridVisibility( bool aVisible ) override;
  142. void SetObjectVisible( GAL_LAYER_ID aLayer, bool aVisible = true );
  143. /**
  144. * Return the angle used for rotate operations.
  145. */
  146. virtual EDA_ANGLE GetRotationAngle() const;
  147. /**
  148. * Set the angle used for rotate operations.
  149. */
  150. //void SetRotationAngle( EDA_ANGLE aRotationAngle );
  151. void ShowBitmapPropertiesDialog( BOARD_ITEM* aBitmap );
  152. void ShowTextPropertiesDialog( BOARD_ITEM* aText );
  153. int ShowTextBoxPropertiesDialog( BOARD_ITEM* aText );
  154. void ShowGraphicItemPropertiesDialog( BOARD_ITEM* aItem );
  155. ///< @copydoc EDA_DRAW_FRAME::UseGalCanvas()
  156. void ActivateGalCanvas() override;
  157. ///< @copydoc PCB_BASE_FRAME::SetBoard()
  158. virtual void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr ) override;
  159. COLOR_SETTINGS* GetColorSettings( bool aForceRefresh = false ) const override;
  160. /* full undo redo management : */
  161. // use EDA_BASE_FRAME::ClearUndoRedoList()
  162. // use EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
  163. // use EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
  164. /**
  165. * Free the undo or redo list from List element.
  166. *
  167. * Wrappers are deleted. Data pointed by wrappers are deleted if not in use in schematic
  168. * i.e. when they are copy of a schematic item or they are no more in use (DELETED).
  169. * Items are removed from the beginning of the list so this function can be called to
  170. * remove old commands.
  171. *
  172. * @param whichList the #UNDO_REDO_CONTAINER to clear.
  173. * @param aItemCount the count of items to remove. < 0 for all items.
  174. */
  175. void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
  176. /**
  177. * Return the absolute path to the design rules file for the currently-loaded board.
  178. *
  179. * @note There is no guarantee that this file actually exists and can be opened! It only
  180. * makes sense from PcbNew but is needed in #PCB_BASE_EDIT_FRAME::SetBoard.
  181. */
  182. wxString GetDesignRulesPath();
  183. APPEARANCE_CONTROLS* GetAppearancePanel() { return m_appearancePanel; }
  184. PROPERTIES_PANEL* GetPropertiesPanel() { return m_propertiesPanel; }
  185. void UpdateProperties();
  186. protected:
  187. /**
  188. * Prompts a user to select global or project library tables
  189. *
  190. * @return Pointer to library table selected or nullptr if none selected/canceled
  191. */
  192. FP_LIB_TABLE* selectLibTable( bool aOptional = false );
  193. /**
  194. * Create a new library in the given table (presumed to be either the global or project
  195. * library table).
  196. */
  197. wxString createNewLibrary( const wxString& aLibName, const wxString& aProposedName,
  198. FP_LIB_TABLE* aTable );
  199. void handleActivateEvent( wxActivateEvent& aEvent ) override;
  200. void saveCopyInUndoList( PICKED_ITEMS_LIST* commandToUndo, const PICKED_ITEMS_LIST& aItemsList,
  201. UNDO_REDO aCommandType );
  202. void unitsChangeRefresh() override;
  203. protected:
  204. bool m_undoRedoBlocked;
  205. PANEL_SELECTION_FILTER* m_selectionFilterPanel;
  206. APPEARANCE_CONTROLS* m_appearancePanel;
  207. PROPERTIES_PANEL* m_propertiesPanel;
  208. /// Panel with Layers and Object Inspector tabs
  209. wxAuiNotebook* m_tabbedPanel;
  210. };
  211. #endif