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>
35 #include <worksheet_dataitem.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 }
virtual BASE_SCREEN * GetScreen()=0
GR_DRAWMODE g_XorMode
Definition: gr_basic.cpp:74
#define GR_KB_ALT
BLOCK_COMMAND_T GetCommand() const
#define MOUSE_MIDDLE
int m_ScreenNumber
Definition: base_screen.h:216
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Definition: base_screen.h:214
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
int GetCurrentCursor() const
Function GetCurrentCursor.
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
const wxString & GetCurrFileName() const
Class PL_EDITOR_FRAME is the main window used in the page layout editor.
void GetAllItems(std::vector< WS_DRAW_ITEM_BASE * > *aList)
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
virtual 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.
#define GR_KB_CTRL
void ClearBlockCommand()
Definition: base_screen.h:501
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...
wxPoint GetMoveVector() const
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
virtual void HandleBlockPlace(wxDC *DC) override
Function HandleBlockPlace handles the block place command.
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...
virtual EDA_DRAW_FRAME * GetParent() const =0
void SetState(BLOCK_STATE_T aState)
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)
virtual 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.
description of graphic items and texts to build a title block
PL_EDITOR_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const TITLE_BLOCK & GetTitleBlock() const override
uint32_t EDA_KEY
Definition: common.h:74
Definition: colors.h:60
#define GR_KB_SHIFT
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:126
#define GR_KB_SHIFTCTRL
void DisplayToolMsg(const wxString &msg)
void SetSheetNumber(int aSheetNumber)
Function SetSheetNumber Set the value of the sheet number, for basic inscriptions.
#define IU_PER_MILS
Definition: plotter.cpp:134
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.
virtual void Window_Zoom(EDA_RECT &Rect)
int m_NumberOfScreens
Definition: base_screen.h:217
classes and function to generate graphics to plt or draw titles blocks and frame references
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
void SetModify()
Definition: base_screen.h:324
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
virtual void SetMouseCaptureCallback(MOUSE_CAPTURE_CALLBACK aMouseCaptureCallback)
COLOR4D g_GhostColor
Global variables definitions.
Definition: common.cpp:57
int GetToolId() const
Definition: draw_frame.h:526
wxPoint GetCrossHairPosition(bool aInvertY=false) const
Return the current cross hair position in logical (drawing) coordinates.
static void ConfigureDrawList(WS_DRAW_ITEM_LIST *aDrawList, PL_EDITOR_SCREEN *aScreen, PL_EDITOR_FRAME *aFrame)
virtual wxString GetScreenDesc() const