KiCad PCB EDA Suite
tools_holder.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) 2020 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef TOOL_HOLDER_H
25 #define TOOL_HOLDER_H
26 
27 #include <vector>
28 #include <view/view_controls.h>
29 #include <tool/action_manager.h>
30 #include <tool/selection.h>
31 #include <tool/tool_action.h>
32 
33 
34 class TOOL_MANAGER;
35 class TOOL_DISPATCHER;
36 class ACTIONS;
37 
38 
39 /*
40  * A mix-in class which allows its owner to hold a set of tools from the tool framework.
41  *
42  * This is just the framework; the owner is responsible for registering individual tools,
43  * creating the dispatcher, etc.
44  */
46 {
47 public:
48  TOOLS_HOLDER();
49 
50  virtual ~TOOLS_HOLDER() { }
51 
56 
64  virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
65  const ACTION_CONDITIONS& aConditions )
66  {
67  RegisterUIUpdateHandler( aAction.GetUIId(), aConditions );
68  }
69 
76  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
77  {}
78 
84  virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
85  {
87  }
88 
94  virtual void UnregisterUIUpdateHandler( int aID )
95  {}
96 
103  {
104  return m_dummySelection;
105  }
106 
114  virtual void PushTool( const std::string& actionName );
115  virtual void PopTool( const std::string& actionName );
116 
117  bool ToolStackIsEmpty() { return m_toolStack.empty(); }
118 
119  std::string CurrentToolName() const;
120  bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
121 
122  virtual void DisplayToolMsg( const wxString& msg ) {};
123 
128  bool GetDoImmediateActions() const { return m_immediateActions; }
129 
135 
140  bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
141 
146  virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
147 
151  virtual wxWindow* GetToolCanvas() const = 0;
152  virtual void RefreshCanvas() { }
153 
154  virtual wxString ConfigBaseName() { return wxEmptyString; }
155 
156 protected:
160 
161  SELECTION m_dummySelection; // Empty dummy selection
162 
163  std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
164  // stack of TOOL instances, because somewhat
165  // confusingly most TOOLs implement more than one
166  // user-level tool. A user-level tool actually
167  // equates to an ACTION handler, so this stack
168  // stores ACTION names.
169 
170  bool m_immediateActions; // Preference for immediate actions. If false,
171  // the first invocation of a hotkey will just
172  // select the relevant tool rather than executing
173  // the tool's action.
174  MOUSE_DRAG_ACTION m_dragAction; // DRAG_ANY/DRAG_SELECTED/SELECT.
175 
176  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
177 };
178 
179 #endif // TOOL_HOLDER_H
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual ~TOOLS_HOLDER()
Definition: tools_holder.h:50
int GetUIId() const
Definition: tool_action.h:112
virtual void RefreshCanvas()
Definition: tools_holder.h:152
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual void UnregisterUIUpdateHandler(const TOOL_ACTION &aAction)
Unregister a UI handler for an action that was registered using RegisterUIUpdateHandler.
Definition: tools_holder.h:84
virtual void DisplayToolMsg(const wxString &msg)
Definition: tools_holder.h:122
virtual wxString ConfigBaseName()
Definition: tools_holder.h:154
virtual void UnregisterUIUpdateHandler(int aID)
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
Definition: tools_holder.h:94
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions)
Register a UI update handler for the control with ID aID.
Definition: tools_holder.h:76
bool m_immediateActions
Definition: tools_holder.h:170
Master controller class:
Definition: tool_manager.h:52
MOUSE_DRAG_ACTION
MOUSE_DRAG_ACTION GetDragAction() const
Indicates whether a drag should draw a selection rectangle or drag selected (or unselected) objects.
Definition: tools_holder.h:134
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
virtual void PopTool(const std::string &actionName)
ACTIONS * m_actions
Definition: tools_holder.h:158
bool m_moveWarpsCursor
Definition: tools_holder.h:176
SELECTION m_dummySelection
Definition: tools_holder.h:161
bool ToolStackIsEmpty()
Definition: tools_holder.h:117
std::string CurrentToolName() const
MOUSE_DRAG_ACTION m_dragAction
Definition: tools_holder.h:174
bool GetDoImmediateActions() const
Indicate that hotkeys should perform an immediate action even if another tool is currently active.
Definition: tools_holder.h:128
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:159
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:102
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:157
std::vector< std::string > m_toolStack
Definition: tools_holder.h:163
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
Represent a single user action.
Definition: tool_action.h:49
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:140
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
Gather all the actions that are shared by tools.
Definition: actions.h:43
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
virtual void RegisterUIUpdateHandler(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Register an action's update conditions with the UI layer to allow the UI to appropriately display the...
Definition: tools_holder.h:64