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.

194 lines
6.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef BASE_EDIT_FRAME_H
  25. #define BASE_EDIT_FRAME_H
  26. #include <pcb_base_frame.h>
  27. class BOARD_ITEM_CONTAINER;
  28. /**
  29. * Common, abstract interface for edit frames.
  30. */
  31. class PCB_BASE_EDIT_FRAME : public PCB_BASE_FRAME
  32. {
  33. public:
  34. PCB_BASE_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
  35. const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize,
  36. long aStyle, const wxString& aFrameName );
  37. virtual ~PCB_BASE_EDIT_FRAME();
  38. /**
  39. * Function GetModel()
  40. * @return the primary data model.
  41. */
  42. virtual BOARD_ITEM_CONTAINER* GetModel() const = 0;
  43. /**
  44. * Function CreateNewLibrary
  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. *
  51. * @return wxString - the newly created library path if library was successfully
  52. * created, else wxEmptyString because user aborted or error.
  53. */
  54. wxString CreateNewLibrary(const wxString& aLibName = wxEmptyString);
  55. /**
  56. * Function AddLibrary
  57. * Add an existing library to either the global or project library table.
  58. * @param aFileName the library to add; a file open dialog will be displayed if empty.
  59. * @return true if successfully added
  60. */
  61. bool AddLibrary(const wxString& aLibName = wxEmptyString);
  62. /**
  63. * Function OnEditItemRequest
  64. * Install the corresponding dialog editor for the given item
  65. * @param aDC = the current device context
  66. * @param aItem = a pointer to the BOARD_ITEM to edit
  67. */
  68. virtual void OnEditItemRequest( BOARD_ITEM* aItem ) = 0;
  69. // Undo buffer handling
  70. /**
  71. * Function SaveCopyInUndoList
  72. * Creates a new entry in undo list of commands.
  73. * add a picker to handle aItemToCopy
  74. * @param aItemToCopy = the board item modified by the command to undo
  75. * @param aTypeCommand = command type (see enum UNDO_REDO_T)
  76. * @param aTransformPoint = the reference point of the transformation, for
  77. * commands like move
  78. */
  79. void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO_T aTypeCommand,
  80. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override;
  81. /**
  82. * Function SaveCopyInUndoList
  83. * Creates a new entry in undo list of commands.
  84. * add a list of pickers to handle a list of items
  85. * @param aItemsList = the list of items modified by the command to undo
  86. * @param aTypeCommand = command type (see enum UNDO_REDO_T)
  87. * @param aTransformPoint = the reference point of the transformation,
  88. * for commands like move
  89. */
  90. void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand,
  91. const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override;
  92. /**
  93. * Function RestoreCopyFromRedoList
  94. * Redo the last edit:
  95. * - Save the current board in Undo list
  96. * - Get an old version of the board from Redo list
  97. * @return none
  98. */
  99. void RestoreCopyFromRedoList( wxCommandEvent& aEvent );
  100. /**
  101. * Function RestoreCopyFromUndoList
  102. * Undo the last edit:
  103. * - Save the current board in Redo list
  104. * - Get an old version of the board from Undo list
  105. * @return none
  106. */
  107. void RestoreCopyFromUndoList( wxCommandEvent& aEvent );
  108. /**
  109. * Performs an undo of the last edit WITHOUT logging a corresponding redo. Used to cancel
  110. * an in-progress operation.
  111. */
  112. void RollbackFromUndo();
  113. /**
  114. * Function PutDataInPreviousState
  115. * Used in undo or redo command.
  116. * Put data pointed by List in the previous state, i.e. the state memorized by List
  117. * @param aList = a PICKED_ITEMS_LIST pointer to the list of items to undo/redo
  118. * @param aRedoCommand = a bool: true for redo, false for undo
  119. * @param aRebuildRatsnet = a bool: true to rebuild ratsnest (normal use), false to just
  120. * retrieve last state (used in abort commands that do not need to rebuild ratsnest)
  121. */
  122. void PutDataInPreviousState( PICKED_ITEMS_LIST* aList,
  123. bool aRedoCommand,
  124. bool aRebuildRatsnet = true );
  125. /**
  126. * Function UndoRedoBlocked
  127. * Checks if the undo and redo operations are currently blocked.
  128. */
  129. bool UndoRedoBlocked() const
  130. {
  131. return m_undoRedoBlocked;
  132. }
  133. /**
  134. * Function UndoRedoBlock
  135. * Enables/disable undo and redo operations.
  136. */
  137. void UndoRedoBlock( bool aBlock = true )
  138. {
  139. m_undoRedoBlocked = aBlock;
  140. }
  141. /**
  142. * Function GetRotationAngle()
  143. * Returns the angle used for rotate operations.
  144. */
  145. int GetRotationAngle() const { return m_rotationAngle; }
  146. /**
  147. * Function SetRotationAngle()
  148. * Sets the angle used for rotate operations.
  149. */
  150. void SetRotationAngle( int aRotationAngle );
  151. void InstallTextOptionsFrame( BOARD_ITEM* aText );
  152. void InstallGraphicItemPropertiesDialog( BOARD_ITEM* aItem );
  153. ///> @copydoc EDA_DRAW_FRAME::UseGalCanvas()
  154. void ActivateGalCanvas() override;
  155. ///> @copydoc PCB_BASE_FRAME::SetBoard()
  156. virtual void SetBoard( BOARD* aBoard ) override;
  157. void OnGridSettings( wxCommandEvent& aEvent ) override;
  158. bool InvokeDialogGrid();
  159. protected:
  160. /// User defined rotation angle (in tenths of a degree).
  161. int m_rotationAngle;
  162. /// Is undo/redo operation currently blocked?
  163. bool m_undoRedoBlocked;
  164. void unitsChangeRefresh() override;
  165. };
  166. #endif