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.

262 lines
9.1 KiB

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