KiCad PCB EDA Suite
block_commande.h
Go to the documentation of this file.
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 
31 #ifndef __INCLUDE__BLOCK_COMMANDE_H__
32 #define __INCLUDE__BLOCK_COMMANDE_H__
33 
34 
35 #include <base_struct.h>
36 #include <undo_redo_container.h>
37 #include <gr_basic.h>
38 #include <eda_rect.h>
39 
40 /* Block state codes. */
41 typedef enum {
48 
49 
50 /* Block command codes. */
51 typedef enum {
61  BLOCK_DRAG_ITEM, // like BLOCK_DRAG, when used to drag a selected component
62  // and not using an area defined by a mouse drag
73 
74 
75 class BLOCK_SELECTOR : public EDA_RECT
76 {
77  BLOCK_STATE_T m_state; //< State (enum BLOCK_STATE_T) of the block.
78  BLOCK_COMMAND_T m_command; //< Command (enum BLOCK_COMMAND_T) operation.
79  PICKED_ITEMS_LIST m_items; //< List of items selected in this block.
80  COLOR4D m_color; //< Block Color (for drawings).
81  wxPoint m_moveVector; //< Move distance to move the block.
82  wxPoint m_lastCursorPosition; //< Last Mouse position in block command
83  //< last cursor position in move commands
84  //< 0,0 in paste command.
85  bool m_appendUndo; //< indicates that at least one undo record
86  //< has been saved and further undo records
87  //< should be appended
88 
89 public:
92 
93  void SetState( BLOCK_STATE_T aState ) { m_state = aState; }
94 
95  BLOCK_STATE_T GetState() const { return m_state; }
96 
97  void SetCommand( BLOCK_COMMAND_T aCommand ) { m_command = aCommand; }
98 
99  BLOCK_COMMAND_T GetCommand() const { return m_command; }
100 
101  void SetColor( COLOR4D aColor ) { m_color = aColor; }
102 
103  COLOR4D GetColor() const { return m_color; }
104 
105  bool AppendUndo() const { return m_appendUndo; }
106 
107  void SetAppendUndo() { m_appendUndo = true; }
108 
115  void SetLastCursorPosition( const wxPoint& aPosition ) { m_lastCursorPosition = aPosition; }
116 
118 
119  void SetMoveVector( const wxPoint& aMoveVector ) { m_moveVector = aMoveVector; }
120 
121  wxPoint GetMoveVector() const { return m_moveVector; }
122 
128  void InitData( EDA_DRAW_PANEL* Panel, const wxPoint& startpos );
129 
134  void SetMessageBlock( EDA_DRAW_FRAME* frame );
135 
136  void Draw( EDA_DRAW_PANEL* aPanel,
137  wxDC* aDC,
138  const wxPoint& aOffset,
139  GR_DRAWMODE aDrawMode,
140  COLOR4D aColor );
141 
147  void PushItem( ITEM_PICKER& aItem );
148 
155 
161  void ClearItemsList();
162 
163  unsigned GetCount() const
164  {
165  return m_items.GetCount();
166  }
167 
169 
170  EDA_ITEM* GetItem( unsigned aIndex )
171  {
172  if( aIndex < m_items.GetCount() )
173  return m_items.GetPickedItem( aIndex );
174 
175  return NULL;
176  }
177 
182  void SetFlags( const STATUS_FLAGS aFlag )
183  {
184  for( unsigned i = 0; i < m_items.GetCount(); i++ )
185  m_items.GetPickedItem( i )->SetFlags( aFlag );
186  }
187 
192  bool IsDragging() const
193  {
194  return m_command == BLOCK_DRAG || m_command == BLOCK_DRAG_ITEM;
195  }
196 
201  inline bool IsIdle() const { return m_command == BLOCK_IDLE; }
202 
208  void Clear();
209 };
210 
211 
216 void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
217 
218 
226 void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
227  bool aErase );
228 
229 
230 #endif /* __INCLUDE__BLOCK_COMMANDE_H__ */
bool AppendUndo() const
BLOCK_COMMAND_T m_command
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor)
void SetMoveVector(const wxPoint &aMoveVector)
void AbortBlockCurrentCommand(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
Function AbortBlockCurrentCommand cancels the current block operation.
void SetMessageBlock(EDA_DRAW_FRAME *frame)
Function SetMessageBlock Displays the type of block command in the status bar of the window...
BLOCK_COMMAND_T
EDA_ITEM * GetItem(unsigned aIndex)
BLOCK_STATE_T
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
void ClearItemsList()
Function ClearItemsList clear only the list of EDA_ITEM pointers, it does NOT delete the EDA_ITEM obj...
void SetState(BLOCK_STATE_T aState)
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes only the list of EDA_ITEM * pointers, AND the data printed b...
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:256
COLOR4D GetColor() const
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
void DrawAndSizingBlockOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function DrawAndSizingBlockOutlines redraws the outlines of the block which shows the search area for...
unsigned STATUS_FLAGS
Definition: base_struct.h:147
void SetFlags(const STATUS_FLAGS aFlag)
Function SetFlags sets a status flag on each item in a block selector.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
unsigned GetCount() const
Function GetCount.
PICKED_ITEMS_LIST m_items
bool IsIdle() const
Function IsIdle returns true if there is currently no block operation in progress.
wxPoint GetLastCursorPosition() const
BLOCK_STATE_T m_state
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
BLOCK_STATE_T GetState() const
size_t i
Definition: json11.cpp:597
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
wxPoint m_lastCursorPosition
void SetColor(COLOR4D aColor)
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
bool IsDragging() const
Function IsDragging returns true if the current block command is a drag operation.
PICKED_ITEMS_LIST & GetItems()
BLOCK_COMMAND_T GetCommand() const
wxPoint m_moveVector
void InitData(EDA_DRAW_PANEL *Panel, const wxPoint &startpos)
Function InitData sets the initial values of a BLOCK_SELECTOR, before starting a block command...
Basic classes for most KiCad items.
void SetLastCursorPosition(const wxPoint &aPosition)
Function SetLastCursorPosition sets the last cursor position to aPosition.
unsigned GetCount() const
void SetCommand(BLOCK_COMMAND_T aCommand)
wxPoint GetMoveVector() const
void Clear()
Function Clear clears the block selector by setting the command to idle, the state to no block...
void PushItem(ITEM_PICKER &aItem)
Function PushItem adds aItem to the list of items.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39