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/selection.h>
30 #include <tool/tool_action.h>
31 
32 struct ACTION_CONDITIONS;
33 
34 class ACTIONS;
35 class TOOL_DISPATCHER;
36 class TOOL_MANAGER;
37 
38 /*
39  * A mix-in class which allows its owner to hold a set of tools from the tool framework.
40  *
41  * This is just the framework; the owner is responsible for registering individual tools,
42  * creating the dispatcher, etc.
43  */
45 {
46 public:
47  TOOLS_HOLDER();
48 
49  virtual ~TOOLS_HOLDER() { }
50 
55 
63  virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
64  const ACTION_CONDITIONS& aConditions )
65  {
66  RegisterUIUpdateHandler( aAction.GetUIId(), aConditions );
67  }
68 
75  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
76  {}
77 
83  virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
84  {
86  }
87 
93  virtual void UnregisterUIUpdateHandler( int aID )
94  {}
95 
102  {
103  return m_dummySelection;
104  }
105 
113  virtual void PushTool( const std::string& actionName );
114  virtual void PopTool( const std::string& actionName );
115 
116  bool ToolStackIsEmpty() { return m_toolStack.empty(); }
117 
118  std::string CurrentToolName() const;
119  bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
120 
121  virtual void DisplayToolMsg( const wxString& msg ) {};
122 
123  virtual void ShowChangedLanguage();
124 
129  bool GetDoImmediateActions() const { return m_immediateActions; }
130 
136 
141  bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
142 
147  virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
148 
152  virtual wxWindow* GetToolCanvas() const = 0;
153  virtual void RefreshCanvas() { }
154 
155  virtual wxString ConfigBaseName() { return wxEmptyString; }
156 
157 protected:
161 
162  SELECTION m_dummySelection; // Empty dummy selection
163 
164  std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
165  // stack of TOOL instances, because somewhat
166  // confusingly most TOOLs implement more than one
167  // user-level tool. A user-level tool actually
168  // equates to an ACTION handler, so this stack
169  // stores ACTION names.
170 
171  bool m_immediateActions; // Preference for immediate actions. If false,
172  // the first invocation of a hotkey will just
173  // select the relevant tool rather than executing
174  // the tool's action.
175  MOUSE_DRAG_ACTION m_dragAction; // DRAG_ANY/DRAG_SELECTED/SELECT.
176 
177  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
178 };
179 
180 #endif // TOOL_HOLDER_H
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual ~TOOLS_HOLDER()
Definition: tools_holder.h:49
int GetUIId() const
Definition: tool_action.h:130
virtual void RefreshCanvas()
Definition: tools_holder.h:153
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:83
virtual void DisplayToolMsg(const wxString &msg)
Definition: tools_holder.h:121
virtual wxString ConfigBaseName()
Definition: tools_holder.h:155
virtual void ShowChangedLanguage()
virtual void UnregisterUIUpdateHandler(int aID)
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
Definition: tools_holder.h:93
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions)
Register a UI update handler for the control with ID aID.
Definition: tools_holder.h:75
bool m_immediateActions
Definition: tools_holder.h:171
Master controller class:
Definition: tool_manager.h:54
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:135
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
virtual void PopTool(const std::string &actionName)
ACTIONS * m_actions
Definition: tools_holder.h:159
bool m_moveWarpsCursor
Definition: tools_holder.h:177
SELECTION m_dummySelection
Definition: tools_holder.h:162
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
std::string CurrentToolName() const
MOUSE_DRAG_ACTION m_dragAction
Definition: tools_holder.h:175
bool GetDoImmediateActions() const
Indicate that hotkeys should perform an immediate action even if another tool is currently active.
Definition: tools_holder.h:129
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:160
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:101
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
std::vector< std::string > m_toolStack
Definition: tools_holder.h:164
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:67
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:141
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:40
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
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:63