KiCad PCB EDA Suite
block_commande.cpp
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 
30 #include <fctsys.h>
31 #include <gr_basic.h>
32 #include <draw_frame.h>
33 #include <common.h>
34 #include <macros.h>
35 #include <base_struct.h>
36 #include <class_base_screen.h>
37 #include <class_drawpanel.h>
38 #include <confirm.h>
39 #include <block_commande.h>
40 
41 
43  EDA_RECT()
44 {
45  m_state = STATE_NO_BLOCK; // State (enum BLOCK_STATE_T) of block.
46  m_command = BLOCK_IDLE; // Type (enum BLOCK_COMMAND_T) of operation.
47  m_color = BROWN;
48 }
49 
50 
52 {
53 }
54 
55 
57 {
58  wxString msg;
59 
60  switch( m_command )
61  {
62  case BLOCK_IDLE:
63  break;
64 
65  case BLOCK_MOVE: // Move
66  case BLOCK_PRESELECT_MOVE: // Move with preselection list
67  case BLOCK_MOVE_EXACT:
68  msg = _( "Block Move" );
69  break;
70 
71  case BLOCK_DRAG: // Drag
72  msg = _( "Block Drag" );
73  break;
74 
75  case BLOCK_DRAG_ITEM: // Drag
76  msg = _( "Drag item" );
77  break;
78 
79  case BLOCK_COPY: // Copy
80  msg = _( "Block Copy" );
81  break;
82 
83  case BLOCK_DELETE: // Delete
84  msg = _( "Block Delete" );
85  break;
86 
87  case BLOCK_SAVE: // Save
88  msg = _( "Block Save" );
89  break;
90 
91  case BLOCK_PASTE:
92  msg = _( "Block Paste" );
93  break;
94 
95  case BLOCK_ZOOM: // Window Zoom
96  msg = _( "Zoom to selection" );
97  break;
98 
99  case BLOCK_ROTATE: // Rotate 90 deg
100  msg = _( "Block Rotate" );
101  break;
102 
103  case BLOCK_FLIP: // Flip
104  msg = _( "Block Flip" );
105  break;
106 
107  case BLOCK_MIRROR_X:
108  case BLOCK_MIRROR_Y: // mirror
109  msg = _( "Block Mirror" );
110  break;
111 
112  case BLOCK_ABORT:
113  break;
114 
115  default:
116  msg = wxT( "???" );
117  break;
118  }
119 
120  frame->DisplayToolMsg( msg );
121 }
122 
123 
124 void BLOCK_SELECTOR::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
125  GR_DRAWMODE aDrawMode, COLOR4D aColor )
126 {
127  if( !aDC )
128  return;
129 
130  int w = GetWidth();
131  int h = GetHeight();
132 
133  GRSetDrawMode( aDC, aDrawMode );
134 
135  if( w == 0 || h == 0 )
136  GRLine( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
137  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
138  else
139  GRRect( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
140  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
141 }
142 
143 
144 void BLOCK_SELECTOR::InitData( EDA_DRAW_PANEL* aPanel, const wxPoint& startpos )
145 {
147  SetOrigin( startpos );
148  SetSize( wxSize( 0, 0 ) );
151 }
152 
153 
155 {
157 }
158 
159 
161 {
163 }
164 
165 
167 {
168  m_items.PushItem( aItem );
169 }
170 
171 
173 {
174  if( m_command != BLOCK_IDLE )
175  {
178  ClearItemsList();
179  }
180 }
181 
182 
183 void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
184  bool aErase )
185 {
187 
188  block = &aPanel->GetScreen()->m_BlockLocate;
189 
190  block->SetMoveVector( wxPoint( 0, 0 ) );
191 
192  if( aErase && aDC )
193  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
194 
196  block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
197 
198  if( aDC )
199  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
200 
201  if( block->GetState() == STATE_BLOCK_INIT )
202  {
203  if( block->GetWidth() || block->GetHeight() )
204  // 2nd point exists: the rectangle is not surface anywhere
205  block->SetState( STATE_BLOCK_END );
206  }
207 }
208 
209 
210 void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
211 {
212  BASE_SCREEN* screen = aPanel->GetScreen();
213 
214  if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
215  {
216  // Clear block outline.
217  aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
218  aPanel->SetMouseCapture( NULL, NULL );
219  screen->SetCurItem( NULL );
220 
221  // Delete the picked wrapper if this is a picked list.
222  if( screen->m_BlockLocate.GetCommand() != BLOCK_PASTE )
223  screen->m_BlockLocate.ClearItemsList();
224  }
225 
228  aPanel->GetParent()->HandleBlockEnd( aDC );
229 
231  aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
232  aPanel->SetCursor( (wxStockCursor) aPanel->GetCurrentCursor() );
233 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:290
BLOCK_COMMAND_T m_command
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor)
This file is part of the common library.
int GetCurrentCursor() const
Function GetCurrentCursor.
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color)
Definition: gr_basic.cpp:352
void SetMoveVector(const wxPoint &aMoveVector)
void SetMessageBlock(EDA_DRAW_FRAME *frame)
Function SetMessageBlock Displays the type of block command in the status bar of the window...
int GetHeight() const
void SetOrigin(const wxPoint &pos)
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
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...
Class EDA_DRAW_FRAME is the base class for create windows for drawing purpose.
Definition: draw_frame.h:53
This file contains miscellaneous commonly used macros and functions.
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 GRRect(EDA_RECT *aClipBox, wxDC *aDC, int x1, int y1, int x2, int y2, COLOR4D aColor)
Definition: gr_basic.cpp:1077
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes only the list of EDA_ITEM * pointers, AND the data printed b...
COLOR4D GetColor() const
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
bool IsMouseCaptured() const
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
void SetEnd(int x, int y)
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
EDA_RECT * GetClipBox()
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
int GetBottom() const
int GetRight() const
Definition: solve.cpp:178
void AbortBlockCurrentCommand(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
Function AbortBlockCurrentCommand cancels the current block operation.
virtual bool HandleBlockEnd(wxDC *DC)
Function HandleBlockEnd( ) Handle the "end" of a block command, i.e.
Definition: draw_frame.cpp:663
PICKED_ITEMS_LIST m_items
This file is part of the common library.
void SetSize(const wxSize &size)
BLOCK_STATE_T m_state
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
BASE_SCREEN class implementation.
BLOCK_STATE_T GetState() const
Class EDA_RECT handles the component boundary box.
int GetX() const
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
The common library.
int GetWidth() const
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
int GetY() const
BLOCK_COMMAND_T GetCommand() const
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 SetMouseCapture(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback, END_MOUSE_CAPTURE_CALLBACK aEndMouseCaptureCallback)
Function SetMouseCapture sets the mouse capture and end mouse capture callbacks to aMouseCaptureCallb...
void SetLastCursorPosition(const wxPoint &aPosition)
Function SetLastCursorPosition sets the last cursor position to aPosition.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
void SetCommand(BLOCK_COMMAND_T aCommand)
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
Definition: colors.h:62