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 #include <tool/tool_menu.h>
31 #include <tool/tool_event.h>
32 #include <tool/tool_base.h>
33 
34 class ACTION_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 
58  TOOL_MENU& GetToolMenu() { return m_menu; }
59 
68 
75  void RunMainStack( std::function<void()> aFunc );
76 
83  template <class T>
84  void Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
85  const TOOL_EVENT_LIST& aConditions = TOOL_EVENT( TC_ANY, TA_ANY ) );
86 
93  TOOL_EVENT* Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) );
94 
96  /*template <class Parameters, class ReturnValue>
97  bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
98  ReturnValue& returnValue );
99 
100  template <class Parameters, class ReturnValue>
101  bool InvokeWindow( const std::string& aWindowName, const Parameters& parameters,
102  ReturnValue& returnValue );
103 
104  template <class T>
105  void Yield( const T& returnValue );*/
106 
107 protected:
109 
110 private:
115  virtual void setTransitions() = 0;
116 
120  void resetTransitions();
121 
122  void goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIST& aConditions );
123 
124  friend class TOOL_MANAGER;
125 };
126 
127 // hide TOOL_MANAGER implementation
128 template <class T>
129 void TOOL_INTERACTIVE::Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
130  const TOOL_EVENT_LIST& aConditions )
131 {
132  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
133 
134  goInternal( sptr, aConditions );
135 }
136 
137 #endif
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Class ACTION_MENU.
Definition: action_menu.h:43
void RunMainStack(std::function< void()> aFunc)
Function RunMainStack()
Class TOOL_MENU.
Definition: tool_menu.h:47
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
TOOL_MENU & GetToolMenu()
void SetContextMenu(ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
Function SetContextMenu()
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
Class TOOL_MANAGER.
Definition: tool_manager.h:50
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
void resetTransitions()
Clears the current transition map and restores the default one created by setTransitions().
Class TOOL_EVENT_LIST.
Definition: tool_event.h:556
CONTEXT_MENU_TRIGGER
Defines when a context menu is opened.
Definition: tool_event.h:156
Class TOOL_EVENT.
Definition: tool_event.h:168
virtual ~TOOL_INTERACTIVE()
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
virtual void setTransitions()=0
This method is meant to be overridden in order to specify handlers for events.
Class TOOL_BASE.
Definition: tool_base.h:67
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
void Activate()
Function Activate() Runs the tool.