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 {
54 }
55 
56 
58 {
59  wxString msg;
60 
61  switch( m_command )
62  {
63  case BLOCK_IDLE:
64  break;
65 
66  case BLOCK_MOVE: // Move
67  case BLOCK_PRESELECT_MOVE: // Move with preselection list
68  case BLOCK_MOVE_EXACT:
69  msg = _( "Block Move" );
70  break;
71 
72  case BLOCK_DRAG: // Drag
73  msg = _( "Block Drag" );
74  break;
75 
76  case BLOCK_DRAG_ITEM: // Drag
77  msg = _( "Drag item" );
78  break;
79 
80  case BLOCK_DUPLICATE: // Duplicate
81  msg = _( "Block Duplicate" );
82  break;
83 
84  case BLOCK_DELETE: // Delete
85  msg = _( "Block Delete" );
86  break;
87 
88  case BLOCK_COPY: // Copy
89  msg = _( "Block Copy" );
90  break;
91 
92  case BLOCK_PASTE:
93  msg = _( "Block Paste" );
94  break;
95 
96  case BLOCK_ZOOM: // Window Zoom
97  msg = _( "Zoom to selection" );
98  break;
99 
100  case BLOCK_ROTATE: // Rotate 90 deg
101  msg = _( "Block Rotate" );
102  break;
103 
104  case BLOCK_FLIP: // Flip
105  msg = _( "Block Flip" );
106  break;
107 
108  case BLOCK_MIRROR_X:
109  case BLOCK_MIRROR_Y: // mirror
110  msg = _( "Block Mirror" );
111  break;
112 
113  case BLOCK_ABORT:
114  break;
115 
116  default:
117  msg = wxT( "???" );
118  break;
119  }
120 
121  frame->DisplayToolMsg( msg );
122 }
123 
124 
125 void BLOCK_SELECTOR::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
126  GR_DRAWMODE aDrawMode, COLOR4D aColor )
127 {
128  if( !aDC )
129  return;
130 
131  int w = GetWidth();
132  int h = GetHeight();
133 
134  GRSetDrawMode( aDC, aDrawMode );
135 
136  if( w == 0 || h == 0 )
137  GRLine( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
138  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
139  else
140  GRRect( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
141  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
142 }
143 
144 
145 void BLOCK_SELECTOR::InitData( EDA_DRAW_PANEL* aPanel, const wxPoint& startpos )
146 {
148  SetOrigin( startpos );
149  SetSize( wxSize( 0, 0 ) );
152 }
153 
154 
156 {
158 }
159 
160 
162 {
164 }
165 
166 
168 {
169  m_items.PushItem( aItem );
170 }
171 
172 
174 {
175  if( m_command != BLOCK_IDLE )
176  {
179  ClearItemsList();
180  }
181 }
182 
183 
184 void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
185  bool aErase )
186 {
188 
189  block = &aPanel->GetScreen()->m_BlockLocate;
190 
191  block->SetMoveVector( wxPoint( 0, 0 ) );
192 
193  if( aErase && aDC )
194  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
195 
197  block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
198 
199  if( aDC )
200  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
201 
202  if( block->GetState() == STATE_BLOCK_INIT )
203  {
204  if( block->GetWidth() || block->GetHeight() )
205  // 2nd point exists: the rectangle is not surface anywhere
206  block->SetState( STATE_BLOCK_END );
207  }
208 }
209 
210 
211 void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
212 {
213  BASE_SCREEN* screen = aPanel->GetScreen();
214 
215  if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
216  {
217  // Clear block outline.
218  aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
219  aPanel->SetMouseCapture( NULL, NULL );
220  screen->SetCurItem( NULL );
221 
222  // Delete the picked wrapper if this is a picked list.
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:296
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 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:54
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:1076
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:181
int GetBottom() const
int GetRight() const
void GRLine(EDA_RECT *ClipBox, wxDC *DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle)
Definition: gr_basic.cpp:358
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:674
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:508
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:194
The common library.
int GetWidth() const
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
int GetY() 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