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.

234 lines
8.5 KiB

  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 KiCad Developers, see AUTHORS.txt for contributors.
  6. * @author Maciej Suminski <maciej.suminski@cern.ch>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #ifndef BASE_EDIT_FRAME_H
  26. #define BASE_EDIT_FRAME_H
  27. #include <pcb_base_frame.h>
  28. class APPEARANCE_CONTROLS;
  29. class BOARD_ITEM_CONTAINER;
  30. class PCB_LAYER_WIDGET;
  31. class PANEL_SELECTION_FILTER;
  32. /**
  33. * Common, abstract interface for edit frames.
  34. */
  35. class PCB_BASE_EDIT_FRAME : public PCB_BASE_FRAME
  36. {
  37. public:
  38. PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
  39. const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
  40. long aStyle, const wxString& aFrameName );
  41. virtual ~PCB_BASE_EDIT_FRAME();
  42. bool TryBefore( wxEvent& aEvent ) override;
  43. void doCloseWindow() override;
  44. /**
  45. * If a library name is given, creates a new footprint library in the project folder
  46. * with the given name. If no library name is given it prompts user for a library path,
  47. * then creates a new footprint library at that location.
  48. * If library exists, user is warned about that, and is given a chance
  49. * to abort the new creation, and in that case existing library is first deleted.
  50. * @param aProposedName is the inital path and filename shown in the file chooser dialog
  51. *
  52. * @return wxString - the newly created library path if library was successfully
  53. * created, else wxEmptyString because user aborted or error.
  54. */
  55. wxString CreateNewLibrary( const wxString& aLibName = wxEmptyString,
  56. const wxString& aProposedName = wxEmptyString );
  57. /**
  58. * Function AddLibrary
  59. * Add an existing library to either the global or project library table.
  60. * @param aFileName the library to add; a file open dialog will be displayed if empty.
  61. * @return true if successfully added
  62. */
  63. bool AddLibrary(const wxString& aLibName = wxEmptyString);
  64. /**
  65. * Function OnEditItemRequest
  66. * Install the corresponding dialog editor for the given item
  67. * @param aDC = the current device context
  68. * @param aItem = a pointer to the BOARD_ITEM to edit
  69. */
  70. virtual void OnEditItemRequest( BOARD_ITEM* aItem ) = 0;
  71. // Undo buffer handling
  72. /**
  73. * Function SaveCopyInUndoList
  74. * Creates a new entry in undo list of commands.
  75. * add a picker to handle aItemToCopy
  76. * @param aItemToCopy = the board item modified by the command to undo
  77. * @param aTypeCommand = command type (see enum UNDO_REDO_T)
  78. * @param aTransformPoint = the reference point of the transformation, for
  79. * commands like move
  80. */
  81. void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO_T aTypeCommand,
  82. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override;
  83. /**
  84. * Function SaveCopyInUndoList
  85. * Creates a new entry in undo list of commands.
  86. * add a list of pickers to handle a list of items
  87. * @param aItemsList = the list of items modified by the command to undo
  88. * @param aTypeCommand = command type (see enum UNDO_REDO_T)
  89. * @param aTransformPoint = the reference point of the transformation,
  90. * for commands like move
  91. */
  92. void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand,
  93. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override;
  94. /**
  95. * Function RestoreCopyFromRedoList
  96. * Redo the last edit:
  97. * - Save the current board in Undo list
  98. * - Get an old version of the board from Redo list
  99. * @return none
  100. */
  101. void RestoreCopyFromRedoList( wxCommandEvent& aEvent );
  102. /**
  103. * Function RestoreCopyFromUndoList
  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. * @return none
  108. */
  109. void RestoreCopyFromUndoList( wxCommandEvent& aEvent );
  110. /**
  111. * Performs an undo of the last edit WITHOUT logging a corresponding redo. Used to cancel
  112. * an in-progress operation.
  113. */
  114. void RollbackFromUndo();
  115. /**
  116. * Function PutDataInPreviousState
  117. * Used in undo or redo command.
  118. * Put data pointed by List in the previous state, i.e. the state memorized by List
  119. * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo
  120. * @param aRedoCommand = a bool: true for redo, false for undo
  121. * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false to just
  122. * retrieve last state (used in abort commands that do not need to rebuild ratsnest)
  123. */
  124. void PutDataInPreviousState( PICKED_ITEMS_LIST* aList,
  125. bool aRedoCommand,
  126. bool aRebuildRatsnet = true );
  127. /**
  128. * Function UndoRedoBlocked
  129. * Checks if the undo and redo operations are currently blocked.
  130. */
  131. bool UndoRedoBlocked() const
  132. {
  133. return m_undoRedoBlocked;
  134. }
  135. /**
  136. * Function UndoRedoBlock
  137. * Enables/disable undo and redo operations.
  138. */
  139. void UndoRedoBlock( bool aBlock = true )
  140. {
  141. m_undoRedoBlocked = aBlock;
  142. }
  143. /**
  144. * Function SetGridVisibility()
  145. *
  146. * Override this function in the PCB_BASE_EDIT_FRAME to refill the layer widget
  147. *
  148. * @param aVisible = true if the grid must be shown
  149. */
  150. void SetGridVisibility( bool aVisible ) override;
  151. /**
  152. * Function GetRotationAngle()
  153. * Returns the angle used for rotate operations.
  154. */
  155. int GetRotationAngle() const { return m_rotationAngle; }
  156. /**
  157. * Function SetRotationAngle()
  158. * Sets the angle used for rotate operations.
  159. */
  160. void SetRotationAngle( int aRotationAngle );
  161. void InstallTextOptionsFrame( BOARD_ITEM* aText );
  162. void InstallGraphicItemPropertiesDialog( BOARD_ITEM* aItem );
  163. ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
  164. void ActivateGalCanvas() override;
  165. ///> @copydoc PCB_BASE_FRAME::SetBoard()
  166. virtual void SetBoard( BOARD* aBoard ) override;
  167. COLOR_SETTINGS* GetColorSettings() override;
  168. /* full undo redo management : */
  169. // use EDA_BASE_FRAME::ClearUndoRedoList()
  170. // use EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aItem )
  171. // use EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aItem )
  172. /**
  173. * Function ClearUndoORRedoList
  174. * free the undo or redo list from List element
  175. * Wrappers are deleted.
  176. * datas pointed by wrappers are deleted if not in use in schematic
  177. * i.e. when they are copy of a schematic item or they are no more in use
  178. * (DELETED)
  179. * @param whichList = the UNDO_REDO_CONTAINER to clear
  180. * @param aItemCount = the count of items to remove. < 0 for all items
  181. * items are removed from the beginning of the list.
  182. * So this function can be called to remove old commands
  183. */
  184. void ClearUndoORRedoList( UNDO_REDO_LIST whichList, int aItemCount = -1 ) override;
  185. protected:
  186. /// User defined rotation angle (in tenths of a degree).
  187. int m_rotationAngle;
  188. /// Is undo/redo operation currently blocked?
  189. bool m_undoRedoBlocked;
  190. void unitsChangeRefresh() override;
  191. /// Layer manager. It is the responsibility of the child frames to instantiate this
  192. PCB_LAYER_WIDGET* m_Layers;
  193. /// AUI panel for changing the selection tool filter controls
  194. PANEL_SELECTION_FILTER* m_selectionFilterPanel;
  195. /// AUI panel for controlling layer and object visibility and appearance
  196. APPEARANCE_CONTROLS* m_appearancePanel;
  197. };
  198. #endif