KiCad PCB EDA Suite
tool_interactive.h
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) 2013 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * Copyright (C) 2016 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 #ifndef __TOOL_INTERACTIVE_H
27 #define __TOOL_INTERACTIVE_H
28 
29 #include <string>
30 
31 #include <tool/tool_event.h>
32 #include <tool/tool_base.h>
33 
34 class CONTEXT_MENU;
35 
37 {
38 public:
43  TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName );
44 
49  TOOL_INTERACTIVE( const std::string& aName );
50  virtual ~TOOL_INTERACTIVE();
51 
56  void Activate();
57 
66 
73  void RunMainStack( std::function<void()> aFunc );
74 
81  template <class T>
82  void Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
83  const TOOL_EVENT_LIST& aConditions = TOOL_EVENT( TC_ANY, TA_ANY ) );
84 
91  OPT_TOOL_EVENT Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) );
92 
94  /*template <class Parameters, class ReturnValue>
95  bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
96  ReturnValue& returnValue );
97 
98  template <class Parameters, class ReturnValue>
99  bool InvokeWindow( const std::string& aWindowName, const Parameters& parameters,
100  ReturnValue& returnValue );
101 
102  template <class T>
103  void Yield( const T& returnValue );*/
104 
105 protected:
106  /* helper functions for constructing events for Wait() and Go() with less typing */
107  const TOOL_EVENT evActivate( std::string aToolName = "" );
108  const TOOL_EVENT evCommand( int aCommandId = -1 );
109  const TOOL_EVENT evCommand( std::string aCommandStr = "" );
110  const TOOL_EVENT evMotion();
111  const TOOL_EVENT evClick( int aButton = BUT_ANY );
112  const TOOL_EVENT evDrag( int aButton = BUT_ANY );
113  const TOOL_EVENT evButtonUp( int aButton = BUT_ANY );
114  const TOOL_EVENT evButtonDown(int aButton = BUT_ANY );
115 
116 private:
117  void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions );
118 };
119 
120 // hide TOOL_MANAGER implementation
121 template <class T>
122 void TOOL_INTERACTIVE::Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
123  const TOOL_EVENT_LIST& aConditions )
124 {
125  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
126 
127  goInternal( sptr, aConditions );
128 }
129 
130 #endif
T
enum T contains all this lexer's tokens.
Class CONTEXT_MENU.
Definition: context_menu.h:44
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
const TOOL_EVENT evButtonDown(int aButton=BUT_ANY)
const TOOL_EVENT evMotion()
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:57
Class TOOL_EVENT_LIST.
Definition: tool_event.h:468
const TOOL_EVENT evActivate(std::string aToolName="")
functions below are not yet implemented - their interface may change
const TOOL_EVENT evClick(int aButton=BUT_ANY)
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition: tool_event.h:150
Class TOOL_EVENT.
Definition: tool_event.h:162
virtual ~TOOL_INTERACTIVE()
void SetContextMenu(CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:59
const TOOL_EVENT evCommand(int aCommandId=-1)
const TOOL_EVENT evDrag(int aButton=BUT_ANY)
Class TOOL_BASE.
Definition: tool_base.h:68
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
void Activate()
Function Activate() Runs the tool.
const TOOL_EVENT evButtonUp(int aButton=BUT_ANY)