KiCad PCB EDA Suite
picker_tool.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) 2015 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 
25 #include "picker_tool.h"
26 #include "pcb_actions.h"
27 
28 #include <wxPcbStruct.h>
29 #include <view/view_controls.h>
30 #include <tool/tool_manager.h>
31 
32 TOOL_ACTION PCB_ACTIONS::pickerTool( "pcbnew.Picker", AS_GLOBAL, 0, "", "", NULL, AF_ACTIVATE );
33 
34 
36  : TOOL_INTERACTIVE( "pcbnew.Picker" )
37 {
38  reset();
39 }
40 
41 
42 int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
43 {
45 
46  assert( !m_picking );
47  m_picking = true;
48  m_picked = boost::none;
49 
50  setControls();
51 
52  while( OPT_TOOL_EVENT evt = Wait() )
53  {
54  if( evt->IsClick( BUT_LEFT ) )
55  {
56  bool getNext = false;
57  m_picked = controls->GetCursorPosition();
58 
59  if( m_clickHandler )
60  {
61  try
62  {
63  getNext = (*m_clickHandler)( *m_picked );
64  }
65  catch( std::exception& e )
66  {
67  std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl;
68  break;
69  }
70  }
71 
72  if( !getNext )
73  break;
74  else
75  setControls();
76  }
77 
78  else if( evt->IsCancel() || evt->IsActivate() )
79  break;
80 
81  else
83  }
84 
85  reset();
86  getEditFrame<PCB_BASE_FRAME>()->SetNoToolSelected();
87 
88  return 0;
89 }
90 
91 
93 {
95 }
96 
97 
99 {
100  m_cursorSnapping = true;
101  m_cursorVisible = true;
102  m_cursorCapture = false;
103  m_autoPanning = false;
104 
105  m_picking = false;
106  m_clickHandler = boost::none;
107 }
108 
109 
111 {
113 
114  controls->ShowCursor( m_cursorVisible );
115  controls->SetSnapping( m_cursorSnapping );
116  controls->CaptureCursor( m_cursorCapture );
117  controls->SetAutoPan( m_autoPanning );
118 }
boost::optional< CLICK_HANDLER > m_clickHandler
Optional mouse click event handler.
Definition: picker_tool.h:112
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
bool m_picking
Activity status.
Definition: picker_tool.h:118
bool m_autoPanning
Definition: picker_tool.h:109
int Main(const TOOL_EVENT &aEvent)
Main event loop.
Definition: picker_tool.cpp:42
VIEW_CONTROLS class definition.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool m_cursorSnapping
Definition: picker_tool.h:106
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool m_cursorVisible
Definition: picker_tool.h:107
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
void PassEvent()
Allows a tool to pass the already handled event to the next tool on the stack.
Definition: tool_manager.h:336
bool m_cursorCapture
Definition: picker_tool.h:108
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
static TOOL_ACTION pickerTool
Definition: pcb_actions.h:347
Class TOOL_EVENT.
Definition: tool_event.h:162
void reset()
Reinitializes tool to its initial state.
Definition: picker_tool.cpp:98
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
Definition: view_controls.h:94
boost::optional< VECTOR2D > m_picked
Picked point (if any).
Definition: picker_tool.h:115
void setControls()
Applies the requested VIEW_CONTROLS settings.
All active tools
Definition: tool_event.h:138
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
Class TOOL_ACTION.
Definition: tool_action.h:46
void SetTransitions() override
>
Definition: picker_tool.cpp:92