KiCad PCB EDA Suite
gerbview/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) 1992-2010 <Jean-Pierre Charras>
5  * Copyright (C) 1992-2010 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 #include <fctsys.h>
32 #include <common.h>
33 #include <class_drawpanel.h>
34 #include <gerbview_frame.h>
35 #include <class_gerber_draw_item.h>
38 
39 // Call back function used in block command
40 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
41  const wxPoint& aPosition, bool erase );
42 
43 
45 {
46  int cmd = 0;
47 
48  switch( key )
49  {
50  default:
51  cmd = key & 0x255;
52  break;
53 
54  case 0:
55  cmd = BLOCK_MOVE;
56  break;
57 
58  case GR_KB_SHIFT:
59  case GR_KB_CTRL:
60  case GR_KB_SHIFTCTRL:
61  case GR_KB_ALT:
62  break;
63 
64  case MOUSE_MIDDLE:
65  cmd = BLOCK_ZOOM;
66  break;
67  }
68 
69  return cmd;
70 }
71 
72 
74 {
75  wxASSERT( m_canvas->IsMouseCaptured() );
76 
78 
79  switch( GetScreen()->m_BlockLocate.GetCommand() )
80  {
81  case BLOCK_MOVE: /* Move */
82  if( m_canvas->IsMouseCaptured() )
83  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
84 
85  Block_Move();
87  break;
88 
89  default:
90  wxFAIL_MSG( wxT("HandleBlockPlace: Unexpected block command") );
91  break;
92  }
93 
94  m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
95  GetScreen()->SetModify();
97 
98  wxASSERT( GetScreen()->m_BlockLocate.GetCount() == 0 );
99 
100  DisplayToolMsg( wxEmptyString );
101 }
102 
103 
105 {
106  bool nextcmd = false;
107  bool zoom_command = false;
108 
109  if( m_canvas->IsMouseCaptured() )
110 
111  switch( GetScreen()->m_BlockLocate.GetCommand() )
112  {
113  case BLOCK_MOVE: /* Move */
115  nextcmd = true;
116  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
118  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
119  break;
120 
121  case BLOCK_ZOOM: /* Window Zoom */
122  zoom_command = true;
123  break;
124 
125  default:
126  wxFAIL_MSG( wxT("HandleBlockEnd: Unexpected block command") );
127  break;
128  }
129 
130  if( ! nextcmd )
131  {
134  false );
135  }
136 
137  if( zoom_command )
138  Window_Zoom( GetScreen()->m_BlockLocate );
139 
140  return nextcmd ;
141 }
142 
143 
144 /* Traces the outline of the block structures of a repositioning move
145  */
146 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon,
147  bool aErase )
148 {
149  BASE_SCREEN* screen = aPanel->GetScreen();
150 
151  COLOR4D Color = COLOR4D( YELLOW );
152 
153  if( aErase )
154  {
155  screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
156 
157  if( screen->m_BlockLocate.GetMoveVector().x|| screen->m_BlockLocate.GetMoveVector().y )
158  {
159  screen->m_BlockLocate.Draw( aPanel,
160  aDC,
161  screen->m_BlockLocate.GetMoveVector(),
162  g_XorMode,
163  Color );
164  }
165  }
166 
167  if( screen->m_BlockLocate.GetState() != STATE_BLOCK_STOP )
168  {
169  const wxPoint& cross_hair = aPanel->GetParent()->GetCrossHairPosition();
170 
172  wxPoint( cross_hair.x - screen->m_BlockLocate.GetRight(),
173  cross_hair.y - screen->m_BlockLocate.GetBottom() ) );
174  }
175 
176  screen->m_BlockLocate.Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, Color );
177 
178  if( screen->m_BlockLocate.GetMoveVector().x || screen->m_BlockLocate.GetMoveVector().y )
179  {
180  screen->m_BlockLocate.Draw( aPanel, aDC,
181  screen->m_BlockLocate.GetMoveVector(),
182  g_XorMode, Color );
183  }
184 }
185 
186 
188 {
189  wxPoint delta;
190  wxPoint oldpos;
191 
192  oldpos = GetCrossHairPosition();
194 
195  SetCrossHairPosition( oldpos );
197  GetScreen()->SetModify();
199 
200  /* Calculate displacement vectors. */
203 
204  for( unsigned layer = 0; layer < images->ImagesMaxCount(); ++layer )
205  {
206  GERBER_FILE_IMAGE* gerber = images->GetGbrImage( layer );
207 
208  if( gerber == NULL ) // Graphic layer not yet used
209  continue;
210 
211  /* Move items in block */
212  for( GERBER_DRAW_ITEM* item = gerber->GetItemsList(); item; item = item->Next() )
213  {
214  GERBER_DRAW_ITEM* gerb_item = item;
215 
216  if( gerb_item->HitTest( GetScreen()->m_BlockLocate ) )
217  gerb_item->MoveAB( delta );
218  }
219  }
220 
221  m_canvas->Refresh( true );
222 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
GERBER_FILE_IMAGE_LIST * GetImagesList()
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
void MoveAB(const wxPoint &aMoveVector)
Function MoveAB move this object.
void Block_Move()
Function Block_Move moves all tracks and segments within the selected block.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
void Draw(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aOffset, GR_DRAWMODE aDrawMode, COLOR4D aColor)
virtual int BlockCommand(EDA_KEY key) override
Function BlockCommand returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to the aKey...
int GetCurrentCursor() const
Function GetCurrentCursor.
void SetMoveVector(const wxPoint &aMoveVector)
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
void ClearBlockCommand()
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
#define GR_KB_ALT
Definition: common.h:65
static const int delta[8][2]
Definition: solve.cpp:112
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)
virtual void HandleBlockPlace(wxDC *DC) override
Function HandleBlockPlace handles the block place command.
virtual BASE_SCREEN * GetScreen() const
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: draw_frame.h:309
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
#define GR_KB_SHIFT
Definition: common.h:66
bool IsMouseCaptured() const
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
GERBER_DRAW_ITEM * Next() const
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
uint32_t EDA_KEY
Definition: common.h:52
GBR_LAYOUT * GetGerberLayout() const
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
int GetBottom() const
int GetRight() const
static void DrawMovingBlockOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool erase)
#define GR_KB_SHIFTCTRL
Definition: common.h:67
void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
virtual bool HandleBlockEnd(wxDC *DC) override
Function HandleBlockEnd( ) handles the end of a block command, It is called at the end of the definit...
void Normalize()
Function Normalize ensures that the height ant width are positive.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
BLOCK_STATE_T GetState() const
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
int GetToolId() const
Definition: draw_frame.h:419
#define MOUSE_MIDDLE
Definition: common.h:68
BASE_SCREEN * GetScreen()
Definition: draw_panel.cpp:188
The common library.
void Window_Zoom(EDA_RECT &Rect)
Compute the zoom factor and the new draw offset to draw the selected area (Rect) in full window scree...
Definition: zoom.cpp:103
BLOCK_COMMAND_T GetCommand() const
bool HitTest(const wxPoint &aRefPos) const override
Function HitTest tests if the given wxPoint is within the bounds of this object.
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Function SetCrossHairPosition sets the screen cross hair position to aPosition in logical (drawing) u...
#define GR_KB_CTRL
Definition: common.h:64
Definition: colors.h:68
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
wxPoint GetMoveVector() const
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39