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.

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