KiCad PCB EDA Suite
pagelayout_editor/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) 2016 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 #include <fctsys.h>
31 #include <common.h>
32 #include <class_drawpanel.h>
33 #include <pl_editor_frame.h>
36 
37 
38 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
39  bool erase );
40 
41 static void DrawMovingItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC );
42 
43 static void ConfigureDrawList( WS_DRAW_ITEM_LIST* aDrawList,
44  PL_EDITOR_SCREEN* aScreen, PL_EDITOR_FRAME* aFrame );
45 
46 
47 static void ConfigureDrawList( WS_DRAW_ITEM_LIST* aDrawList,
48  PL_EDITOR_SCREEN* aScreen, PL_EDITOR_FRAME* aFrame )
49 {
50  aDrawList->SetPenSize( 0 );
51  aDrawList->SetMilsToIUfactor( IU_PER_MILS );
52  aDrawList->SetSheetNumber( aScreen->m_ScreenNumber );
53  aDrawList->SetSheetCount( aScreen->m_NumberOfScreens );
54  aDrawList->SetFileName( aFrame->GetCurrFileName() );
55  aDrawList->SetSheetName( aFrame->GetScreenDesc() );
56  aDrawList->BuildWorkSheetGraphicList( aFrame->GetPageSettings(),
57  aFrame->GetTitleBlock(), RED, RED );
58 }
59 
60 
62 {
63  int cmd = 0;
64 
65  switch( key )
66  {
67  default:
68  cmd = key & 0x255;
69  break;
70 
71  case 0:
72  cmd = BLOCK_MOVE;
73  break;
74 
75  case GR_KB_SHIFT:
76  case GR_KB_CTRL:
77  case GR_KB_SHIFTCTRL:
78  case GR_KB_ALT:
79  break;
80 
81  case MOUSE_MIDDLE:
82  cmd = BLOCK_ZOOM;
83  break;
84  }
85 
86  return cmd;
87 }
88 
89 
91 {
92  wxASSERT( m_canvas->IsMouseCaptured() );
93 
95 
96  switch( GetScreen()->m_BlockLocate.GetCommand() )
97  {
98  case BLOCK_MOVE: /* Move */
99  if( m_canvas->IsMouseCaptured() )
100  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
101 
102  Block_Move( DC );
104  break;
105 
106  default:
107  wxFAIL_MSG( wxT("HandleBlockPlace: Unexpected block command") );
108  break;
109  }
110 
111  m_canvas->EndMouseCapture( GetToolId(), m_canvas->GetCurrentCursor(), wxEmptyString, false );
112  GetScreen()->SetModify();
114 
115  wxASSERT( GetScreen()->m_BlockLocate.GetCount() == 0 );
116 
117  DisplayToolMsg( wxEmptyString );
118 }
119 
120 
122 {
123  bool nextcmd = false;
124  bool zoom_command = false;
125 
126  if( m_canvas->IsMouseCaptured() )
127 
128  switch( GetScreen()->m_BlockLocate.GetCommand() )
129  {
130  case BLOCK_MOVE: /* Move */
132  nextcmd = true;
133  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
135  m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
136  break;
137 
138  case BLOCK_ZOOM: /* Window Zoom */
139  zoom_command = true;
140  break;
141 
142  default:
143  break;
144  }
145 
146  if( ! nextcmd )
147  {
150  false );
151  }
152 
153  if( zoom_command )
154  Window_Zoom( GetScreen()->m_BlockLocate );
155 
156  return nextcmd ;
157 }
158 
159 
160 static void DrawMovingItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC )
161 {
162  auto screen = static_cast<PL_EDITOR_SCREEN*>( aPanel->GetScreen() );
163  auto frame = static_cast<PL_EDITOR_FRAME*>( aPanel->GetParent() );
164 
165  // Get items
166  std::vector<WS_DRAW_ITEM_BASE*> items;
167  WS_DRAW_ITEM_LIST drawList;
168  ConfigureDrawList( &drawList, screen, frame );
169  drawList.GetAllItems( &items );
170 
171  // Draw items
172  for( auto item: items )
173  {
174  if( item->HitTest( screen->m_BlockLocate ) )
175  {
176  item->DrawWsItem( NULL, aDC, screen->m_BlockLocate.GetMoveVector(),
178  }
179  }
180 }
181 
182 
183 /* Traces the outline of the block structures of a repositioning move
184  */
185 static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon,
186  bool aErase )
187 {
188  auto screen = aPanel->GetScreen();
189  auto block = &screen->m_BlockLocate;
190 
191  if( aErase )
192  {
193  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
194  DrawMovingItems( aPanel, aDC );
195  }
196 
197  block->SetMoveVector( aPanel->GetParent()->GetCrossHairPosition() - block->GetLastCursorPosition() );
198  block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
199  DrawMovingItems( aPanel, aDC );
200 }
201 
202 
204 {
205  auto screen = static_cast<PL_EDITOR_SCREEN*>( GetScreen() );
206 
207  wxPoint delta;
208  wxPoint oldpos;
209 
210  oldpos = GetCrossHairPosition();
212 
213  SetCrossHairPosition( oldpos );
215  GetScreen()->SetModify();
217 
218  // Calculate displacement vectors.
220 
221  // Get the items
222  std::vector<WS_DRAW_ITEM_BASE*> items;
223  WS_DRAW_ITEM_LIST drawList;
224  ConfigureDrawList( &drawList, screen, this );
225  drawList.GetAllItems( &items );
226 
227  // Move items in block
229  for( auto item: items )
230  {
231  if( item->HitTest( screen->m_BlockLocate ) )
232  {
233  auto data_item = item->GetParent();
234  data_item->MoveToUi( data_item->GetStartPosUi() + delta );
235  }
236  }
237 
238  m_canvas->Refresh( true );
239 }
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:51
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
static void DrawMovingItems(EDA_DRAW_PANEL *aPanel, wxDC *aDC)
void SetPenSize(int aPenSize)
Function SetPenSize Set the default pen size to draw/plot lines and texts.
const PAGE_INFO & GetPageSettings() const override
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
int GetCurrentCursor() const
Function GetCurrentCursor.
void GetAllItems(std::vector< WS_DRAW_ITEM_BASE * > *aList)
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void EndMouseCapture(int aId=-1, int aCursorId=-1, const wxString &aTitle=wxEmptyString, bool aCallEndFunc=true)
Function EndMouseCapture ends mouse a capture.
void Block_Move(wxDC *DC)
Function Block_Move moves all items within the selected block.
description of graphic items and texts to build a title block
void ClearBlockCommand()
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock, COLOR4D aColor, COLOR4D aAltColor)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
virtual void HandleBlockPlace(wxDC *DC) override
Function HandleBlockPlace handles the block place command.
#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...
virtual int BlockCommand(EDA_KEY key) override
Function BlockCommand returns the block command (BLOCK_MOVE, BLOCK_COPY...) corresponding to the aKey...
void SetState(BLOCK_STATE_T aState)
virtual wxString GetScreenDesc() const
Definition: worksheet.cpp:120
void SetSheetCount(int aSheetCount)
Function SetSheetCount Set the value of the count of sheets, for basic inscriptions.
static void DrawMovingBlockOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, const wxPoint &aPosition, bool erase)
#define GR_KB_SHIFT
Definition: common.h:66
bool IsMouseCaptured() const
void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units ( mils) to draw/plot units...
PL_EDITOR_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
const TITLE_BLOCK & GetTitleBlock() const override
uint32_t EDA_KEY
Definition: common.h:52
Definition: colors.h:60
EDA_DRAW_FRAME * GetParent() const
Definition: draw_panel.cpp:175
#define GR_KB_SHIFTCTRL
Definition: common.h:67
void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
Definition: solve.cpp:178
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
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
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.
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 SaveCopyInUndoList()
Save a copy of the description (in a S expr string) for Undo/redo commands.
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
classes and function to generate graphics to plt or draw titles blocks and frame references ...
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
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Function GetCrossHairPosition return the current cross hair position in logical (drawing) coordinates...
const wxString & GetCurrFileName() const
COLOR4D g_GhostColor
Draw color for moving objects.
Definition: common.cpp:57
wxPoint GetMoveVector() const
static void ConfigureDrawList(WS_DRAW_ITEM_LIST *aDrawList, PL_EDITOR_SCREEN *aScreen, PL_EDITOR_FRAME *aFrame)