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.

209 lines
6.3 KiB

15 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
  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. /**
  25. * This file is part of the common library.
  26. * @file block_commande.h
  27. * @see common.h
  28. */
  29. #ifndef __INCLUDE__BLOCK_COMMANDE_H__
  30. #define __INCLUDE__BLOCK_COMMANDE_H__
  31. #include <base_struct.h>
  32. #include <class_undoredo_container.h>
  33. #include <gr_basic.h>
  34. /* Block state codes. */
  35. typedef enum {
  36. STATE_NO_BLOCK,
  37. STATE_BLOCK_INIT,
  38. STATE_BLOCK_END,
  39. STATE_BLOCK_MOVE,
  40. STATE_BLOCK_STOP
  41. } BLOCK_STATE_T;
  42. /* Block command codes. */
  43. typedef enum {
  44. BLOCK_IDLE,
  45. BLOCK_MOVE,
  46. BLOCK_COPY,
  47. BLOCK_SAVE,
  48. BLOCK_DELETE,
  49. BLOCK_PASTE,
  50. BLOCK_DRAG,
  51. BLOCK_DRAG_ITEM, // like BLOCK_DRAG, when used to drag a selected component
  52. // and not using an area defined by a mouse drag
  53. BLOCK_ROTATE,
  54. BLOCK_FLIP,
  55. BLOCK_ZOOM,
  56. BLOCK_ABORT,
  57. BLOCK_PRESELECT_MOVE,
  58. BLOCK_SELECT_ITEMS_ONLY,
  59. BLOCK_MIRROR_X,
  60. BLOCK_MIRROR_Y
  61. } BLOCK_COMMAND_T;
  62. class BLOCK_SELECTOR : public EDA_RECT
  63. {
  64. BLOCK_STATE_T m_state; //< State (enum BLOCK_STATE_T) of the block.
  65. BLOCK_COMMAND_T m_command; //< Command (enum BLOCK_COMMAND_T) operation.
  66. PICKED_ITEMS_LIST m_items; //< List of items selected in this block.
  67. EDA_COLOR_T m_color; //< Block Color (for drawings).
  68. wxPoint m_moveVector; //< Move distance to move the block.
  69. wxPoint m_lastCursorPosition; //< Last Mouse position in block command
  70. //< last cursor position in move commands
  71. //< 0,0 in paste command.
  72. public:
  73. BLOCK_SELECTOR();
  74. ~BLOCK_SELECTOR();
  75. void SetState( BLOCK_STATE_T aState ) { m_state = aState; }
  76. BLOCK_STATE_T GetState() const { return m_state; }
  77. void SetCommand( BLOCK_COMMAND_T aCommand ) { m_command = aCommand; }
  78. BLOCK_COMMAND_T GetCommand() const { return m_command; }
  79. void SetColor( EDA_COLOR_T aColor ) { m_color = aColor; }
  80. EDA_COLOR_T GetColor() const { return m_color; }
  81. /**
  82. * Function SetLastCursorPosition
  83. * sets the last cursor position to \a aPosition.
  84. *
  85. * @param aPosition The current cursor position.
  86. */
  87. void SetLastCursorPosition( const wxPoint& aPosition ) { m_lastCursorPosition = aPosition; }
  88. wxPoint GetLastCursorPosition() const { return m_lastCursorPosition; }
  89. void SetMoveVector( const wxPoint& aMoveVector ) { m_moveVector = aMoveVector; }
  90. wxPoint GetMoveVector() const { return m_moveVector; }
  91. /**
  92. * Function InitData
  93. * sets the initial values of a BLOCK_SELECTOR, before starting a block
  94. * command
  95. */
  96. void InitData( EDA_DRAW_PANEL* Panel, const wxPoint& startpos );
  97. /**
  98. * Function SetMessageBlock
  99. * Displays the type of block command in the status bar of the window
  100. */
  101. void SetMessageBlock( EDA_DRAW_FRAME* frame );
  102. void Draw( EDA_DRAW_PANEL* aPanel,
  103. wxDC* aDC,
  104. const wxPoint& aOffset,
  105. GR_DRAWMODE aDrawMode,
  106. EDA_COLOR_T aColor );
  107. /**
  108. * Function PushItem
  109. * adds \a aItem to the list of items.
  110. * @param aItem = an ITEM_PICKER to add to the list
  111. */
  112. void PushItem( ITEM_PICKER& aItem );
  113. /**
  114. * Function ClearListAndDeleteItems
  115. * deletes only the list of EDA_ITEM * pointers, AND the data printed
  116. * by m_Item
  117. */
  118. void ClearListAndDeleteItems();
  119. /**
  120. * Function ClearItemsList
  121. * clear only the list of #EDA_ITEM pointers, it does _NOT_ delete the #EDA_ITEM object
  122. * itself
  123. */
  124. void ClearItemsList();
  125. unsigned GetCount() const
  126. {
  127. return m_items.GetCount();
  128. }
  129. PICKED_ITEMS_LIST& GetItems() { return m_items; }
  130. EDA_ITEM* GetItem( unsigned aIndex )
  131. {
  132. if( aIndex < m_items.GetCount() )
  133. return m_items.GetPickedItem( aIndex );
  134. return NULL;
  135. }
  136. /**
  137. * Function IsDragging
  138. * returns true if the current block command is a drag operation.
  139. */
  140. bool IsDragging() const
  141. {
  142. return m_command == BLOCK_DRAG || m_command == BLOCK_DRAG_ITEM;
  143. }
  144. /**
  145. * Function IsIdle
  146. * returns true if there is currently no block operation in progress.
  147. */
  148. inline bool IsIdle() const { return m_command == BLOCK_IDLE; }
  149. /**
  150. * Function Clear
  151. * clears the block selector by setting the command to idle, the state to no block,
  152. * and clears the selected item list.
  153. */
  154. void Clear();
  155. };
  156. /**
  157. * Function AbortBlockCurrentCommand
  158. * cancels the current block operation.
  159. */
  160. void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
  161. /**
  162. * Function DrawAndSizingBlockOutlines
  163. * redraws the outlines of the block which shows the search area for block commands.
  164. *
  165. * The first point of the rectangle showing the area is initialized by InitBlockLocateDatas().
  166. * The other point of the rectangle is the mouse cursor position.
  167. */
  168. void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
  169. bool aErase );
  170. #endif /* __INCLUDE__BLOCK_COMMANDE_H__ */