KiCad PCB EDA Suite
common/legacy_wx/block.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 <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_FLIP: // Flip
101  msg = _( "Block Flip" );
102  break;
103 
104  case BLOCK_ABORT:
105  break;
106 
107  default:
108  msg = wxT( "???" );
109  break;
110  }
111 
112  frame->DisplayToolMsg( msg );
113 }
114 
115 
116 void BLOCK_SELECTOR::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
117  GR_DRAWMODE aDrawMode, COLOR4D aColor )
118 {
119  if( !aDC )
120  return;
121 
122  int w = GetWidth();
123  int h = GetHeight();
124 
125  GRSetDrawMode( aDC, aDrawMode );
126 
127  if( w == 0 || h == 0 )
128  GRLine( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
129  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
130  else
131  GRRect( aPanel->GetClipBox(), aDC, GetX() + aOffset.x, GetY() + aOffset.y,
132  GetRight() + aOffset.x, GetBottom() + aOffset.y, 0, aColor );
133 }
134 
135 
136 void BLOCK_SELECTOR::InitData( EDA_DRAW_PANEL* aPanel, const wxPoint& startpos )
137 {
139  SetOrigin( startpos );
140  SetSize( wxSize( 0, 0 ) );
143 }
144 
145 
147 {
149 }
150 
151 
153 {
155 }
156 
157 
159 {
160  m_items.PushItem( aItem );
161 }
162 
163 
165 {
166  if( m_command != BLOCK_IDLE )
167  {
170  ClearItemsList();
171  }
172 }
173 
174 
175 void DrawAndSizingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
176  bool aErase )
177 {
179 
180  block->SetMoveVector( wxPoint( 0, 0 ) );
181 
182  if( aErase && aDC ) // Erase current outline
183  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
184 
186  block->SetEnd( aPanel->GetParent()->GetCrossHairPosition() );
187 
188  if( aDC ) // Draw new outline
189  block->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, block->GetColor() );
190 
191  if( block->GetState() == STATE_BLOCK_INIT )
192  {
193  if( block->GetWidth() || block->GetHeight() )
194  // 2nd point exists: the rectangle is not surface anywhere
195  block->SetState( STATE_BLOCK_END );
196  }
197 }
198 
199 
200 void AbortBlockCurrentCommand( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
201 {
202  BASE_SCREEN* screen = aPanel->GetScreen();
203 
204  if( aPanel->IsMouseCaptured() ) // Erase current drawing on screen
205  {
206  // Clear block outline.
207  aPanel->CallMouseCapture( aDC, wxDefaultPosition, false );
208  aPanel->SetMouseCapture( NULL, NULL );
209  screen->SetCurItem( NULL );
210 
211  // Delete the picked wrapper if this is a picked list.
212  screen->m_BlockLocate.ClearItemsList();
213  }
214 
217  aPanel->GetParent()->HandleBlockEnd( aDC );
218 
220  aPanel->GetParent()->DisplayToolMsg( wxEmptyString );
221  aPanel->SetCursor( (wxStockCursor) aPanel->GetCurrentCursor() );
222 }
virtual BASE_SCREEN * GetScreen()=0
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:74
void SetCurItem(EDA_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
Definition: base_screen.h:231
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void GRSetDrawMode(wxDC *DC, GR_DRAWMODE draw_mode)
Definition: gr_basic.cpp:223
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
Definition: eda_rect.h:118
void SetOrigin(const wxPoint &pos)
Definition: eda_rect.h:124
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
virtual EDA_RECT * GetClipBox()
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...
The base class for create windows for drawing purpose.
Definition: draw_frame.h:78
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...
virtual EDA_DRAW_FRAME * GetParent() const =0
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:1003
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:37
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
void SetEnd(int x, int y)
Definition: eda_rect.h:134
virtual 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 AbortBlockCurrentCommand(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
Function AbortBlockCurrentCommand cancels the current block operation.
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
int GetBottom() const
Definition: eda_rect.h:122
int GetRight() const
Definition: eda_rect.h:119
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:285
Definition: solve.cpp:178
virtual bool HandleBlockEnd(wxDC *DC)
Handle the "end" of a block command, i.e.
PICKED_ITEMS_LIST m_items
This file is part of the common library.
void SetSize(const wxSize &size)
Definition: eda_rect.h:126
BLOCK_STATE_T m_state
void DisplayToolMsg(const wxString &msg)
BLOCK_STATE_T GetState() const
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetX() const
Definition: eda_rect.h:109
The common library.
int GetWidth() const
Definition: eda_rect.h:117
void ClearItemsList()
Function ClearItemsList deletes only the list of pickers, NOT the picked data itself.
int GetY() const
Definition: eda_rect.h:110
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.
BASE_SCREEN class implementation.
void SetLastCursorPosition(const wxPoint &aPosition)
Function SetLastCursorPosition sets the last cursor position to aPosition.
wxPoint GetCrossHairPosition(bool aInvertY=false) const
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