KiCad PCB EDA Suite
cvpcb_control.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) 2014-2016 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  * Copyright (C) 2007-2018 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 <cstdint>
27 
28 #include <view/view.h>
29 #include "cvpcb_actions.h"
30 #include "cvpcb_control.h"
31 
32 #include <class_board.h>
33 
34 #include <hotkeys.h>
35 #include <properties.h>
36 
37 #include <cvpcb_id.h>
38 #include <tool/tool_manager.h>
39 #include <view/view_controls.h>
40 #include <tools/grid_helper.h> // from pcbnew
41 
42 #include <functional>
43 using namespace std::placeholders;
44 
45 
46 // Miscellaneous
47 TOOL_ACTION CVPCB_ACTIONS::resetCoords( "cvpcb.Control.resetCoords",
48  AS_GLOBAL, ' ',//TOOL_ACTION::LegacyHotKey( HK_RESET_LOCAL_COORD ),
49  "", "" );
50 
51 TOOL_ACTION CVPCB_ACTIONS::switchCursor( "cvpcb.Control.switchCursor",
52  AS_GLOBAL, 0,
53  "", "" );
54 
55 TOOL_ACTION CVPCB_ACTIONS::switchUnits( "cvpcb.Control.switchUnits",
56  AS_GLOBAL, 'U',//TOOL_ACTION::LegacyHotKey( HK_SWITCH_UNITS ),
57  "", "" );
58 
59 TOOL_ACTION CVPCB_ACTIONS::no_selectionTool( "cvpcb.Control.no_selectionTool",
60  AS_GLOBAL, ESC,
61  "", "", NULL, AF_ACTIVATE );
62 
63 
66  TOOL_INTERACTIVE( "cvpcb.Control" ), m_frame( NULL )
67 {
68 }
69 
70 
72 {
73 }
74 
75 
77 {
78  m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
79 }
80 
81 
82 // Miscellaneous
84 {
85  auto vcSettings = m_toolMgr->GetCurrentToolVC();
86 
87  // Use either the active tool forced cursor position or the general settings
88  VECTOR2I cursorPos = vcSettings.m_forceCursorPosition ? vcSettings.m_forcedPosition :
90 
91  m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
93 
94  return 0;
95 }
96 
97 
99 {
100  auto& galOpts = m_frame->GetGalDisplayOptions();
101 
102  galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
103  galOpts.NotifyChanged();
104 
105  return 0;
106 }
107 
108 
110 {
111  // TODO should not it be refactored to pcb_frame member function?
112  wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
113 
114  if( m_frame->GetUserUnits() == INCHES )
115  evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM );
116  else
117  evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );
118 
119  m_frame->ProcessEvent( evt );
120 
121  return 0;
122 }
123 
124 
126 {
127  // Miscellaneous
131 }
const KIGFX::VC_SETTINGS & GetCurrentToolVC() const
Returns the view controls settings for the current tool or the general settings if there is no active...
void setTransitions() override
Sets up handlers for various events.
KIGFX::GAL_DISPLAY_OPTIONS & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
Definition: draw_frame.h:946
static TOOL_ACTION resetCoords
Definition: cvpcb_actions.h:55
int SwitchUnits(const TOOL_EVENT &aEvent)
VIEW_CONTROLS class definition.
static TOOL_ACTION no_selectionTool
Tool selection.
Definition: cvpcb_actions.h:50
Class BOARD to handle a board.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:185
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
Pcbnew hotkeys.
int ResetCoords(const TOOL_EVENT &aEvent)
static TOOL_ACTION switchCursor
Definition: cvpcb_actions.h:56
static TOOL_ACTION switchUnits
Definition: cvpcb_actions.h:57
EDA_DRAW_FRAME::OnSelectGrid ID_TB_OPTIONS_SELECT_UNIT_INCH
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
Definition: common.h:160
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
Class TOOL_EVENT.
Definition: tool_event.h:168
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
int SwitchCursor(const TOOL_EVENT &aEvent)
#define ESC
All active tools
Definition: tool_event.h:144
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
virtual void UpdateStatusBar() override
Update the status bar information.
Class TOOL_ACTION.
Definition: tool_action.h:46
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
bool m_fullscreenCursor
Fullscreen crosshair or small cross
bool ProcessEvent(wxEvent &aEvent) override
Function ProcessEvent overrides the default process event handler to implement the auto save feature...
DISPLAY_FOOTPRINTS_FRAME * m_frame
Pointer to the currently used edit/draw frame.
Definition: cvpcb_control.h:61