KiCad PCB EDA Suite
controller.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <fctsys.h>
27 #include <gr_basic.h>
28 #include <sch_draw_panel.h>
29 #include <eda_dde.h>
30 #include <sch_edit_frame.h>
31 #include <menus_helpers.h>
32 #include <msgpanel.h>
33 #include <bitmaps.h>
34 
35 #include <eeschema_id.h>
36 #include <general.h>
37 #include <hotkeys.h>
38 #include <lib_edit_frame.h>
39 #include <viewlib_frame.h>
40 #include <lib_draw_item.h>
41 #include <lib_pin.h>
42 #include <sch_sheet.h>
43 #include <sch_sheet_path.h>
44 #include <sch_marker.h>
45 #include <sch_component.h>
46 #include <sch_view.h>
47 
48 bool LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey )
49 {
50  // Filter out the 'fake' mouse motion after a keyboard movement
51  if( !aHotKey && m_movingCursorWithKeyboard )
52  {
54  return false;
55  }
56 
57  // when moving mouse, use the "magnetic" grid, unless the shift+ctrl keys is pressed
58  // for next cursor position
59  // ( shift or ctrl key down are PAN command with mouse wheel)
60  bool snapToGrid = true;
61 
62  if( !aHotKey && wxGetKeyState( WXK_SHIFT ) && wxGetKeyState( WXK_CONTROL ) )
63  snapToGrid = false;
64 
65  // Cursor is left off grid only if no block in progress
66  if( GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK )
67  snapToGrid = true;
68 
69  wxPoint pos = aPosition;
70  bool keyHandled = GeneralControlKeyMovement( aHotKey, &pos, snapToGrid );
71 
73  m_canvas->CrossHairOff( aDC );
74  else
75  m_canvas->CrossHairOn( aDC );
76 
77  GetGalCanvas()->GetViewControls()->SetSnapping( snapToGrid );
78  SetCrossHairPosition( pos, snapToGrid );
79 
80  if( m_canvas->IsMouseCaptured() )
81  m_canvas->CallMouseCapture( aDC, aPosition, true );
82 
83  if( aHotKey && OnHotKey( aDC, aHotKey, aPosition, NULL ) )
84  keyHandled = true;
85 
86  // Make sure current-part highlighting doesn't get lost in seleciton highlighting
88 
90 
91  return keyHandled;
92 }
93 
Definition of the SCH_SHEET class for Eeschema.
DDE server & client.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Function GetViewControls() Returns a pointer to the VIEW_CONTROLS instance used in the panel.
bool OnHotKey(wxDC *aDC, int aHotKey, const wxPoint &aPosition, EDA_ITEM *aItem=NULL) override
void ClearSearchTreeSelection()
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:935
SCH_MARKER class definition.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool GeneralControl(wxDC *aDC, const wxPoint &aPosition, EDA_KEY aHotKey=0) override
Perform application specific control using aDC at aPosition in logical units.
Definition: controller.cpp:48
Pcbnew hotkeys.
bool GeneralControlKeyMovement(int aHotKey, wxPoint *aPos, bool aSnapToGrid)
Handle the common part of GeneralControl dedicated to global cursor keys (i.e.
virtual void CrossHairOn(wxDC *DC=nullptr)
virtual void CallMouseCapture(wxDC *aDC, const wxPoint &aPosition, bool aErase)
Function CallMouseCapture calls the mouse capture callback.
virtual void CrossHairOff(wxDC *DC=nullptr)
uint32_t EDA_KEY
Definition: common.h:74
void UpdateStatusBar() override
Update the status bar information.
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
Definition the SCH_COMPONENT class for Eeschema.
Definition of class LIB_EDIT_FRAME.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
void SetCrossHairPosition(const wxPoint &aPosition, bool aSnapToGrid=true)
Set the screen cross hair position to aPosition in logical (drawing) units.
Message panel definition file.
int GetState(int type) const
Definition: base_struct.h:240
bool m_movingCursorWithKeyboard
One-shot to avoid a recursive mouse event during hotkey movement.
Definition: draw_frame.h:176
int GetToolId() const
Definition: draw_frame.h:526