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 <tool/action_manager.h>
29 #include <tool/selection.h>
30 #include <tool/tool_action.h>
31 
32 
33 class TOOL_MANAGER;
34 class TOOL_DISPATCHER;
35 class ACTIONS;
36 
37 
38 /*
39  * Class TOOLS_HOLDER
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 protected:
51 
52  SELECTION m_dummySelection; // Empty dummy selection
53 
54  std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
55  // stack of TOOL instances, because somewhat
56  // confusingly most TOOLs implement more than one
57  // user-level tool. A user-level tool actually
58  // equates to an ACTION handler, so this stack
59  // stores ACTION names.
60 
61  bool m_immediateActions; // Preference for immediate actions. If false,
62  // the first invocation of a hotkey will just
63  // select the relevant tool rather than executing
64  // the tool's action.
65  bool m_dragSelects; // Prefer selection to dragging.
66  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
67 
68 public:
69  TOOLS_HOLDER();
70 
71  virtual ~TOOLS_HOLDER() { }
72 
77 
85  virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
86  const ACTION_CONDITIONS& aConditions )
87  {
88  RegisterUIUpdateHandler( aAction.GetUIId(), aConditions );
89  }
90 
97  virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
98  {}
99 
105  virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
106  {
107  UnregisterUIUpdateHandler( aAction.GetUIId() );
108  }
109 
115  virtual void UnregisterUIUpdateHandler( int aID )
116  {}
117 
124  {
125  return m_dummySelection;
126  }
127 
133  virtual void PushTool( const std::string& actionName );
134  virtual void PopTool( const std::string& actionName );
135 
136  bool ToolStackIsEmpty() { return m_toolStack.empty(); }
137 
138  std::string CurrentToolName() const;
139  bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
140 
141  virtual void DisplayToolMsg( const wxString& msg ) {};
142 
147  bool GetDoImmediateActions() const { return m_immediateActions; }
148 
153  bool GetDragSelects() const { return m_dragSelects; }
154 
159  bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
160 
165  virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
166 
170  virtual wxWindow* GetToolCanvas() const = 0;
171  virtual void RefreshCanvas() { }
172 
173  virtual wxString ConfigBaseName() { return wxEmptyString; }
174 };
175 
176 #endif // TOOL_HOLDER_H
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual ~TOOLS_HOLDER()
Definition: tools_holder.h:71
int GetUIId() const
Definition: tool_action.h:102
virtual void RefreshCanvas()
Definition: tools_holder.h:171
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:105
virtual void DisplayToolMsg(const wxString &msg)
Definition: tools_holder.h:141
virtual wxString ConfigBaseName()
Definition: tools_holder.h:173
bool m_dragSelects
Definition: tools_holder.h:65
virtual void UnregisterUIUpdateHandler(int aID)
Unregister a UI handler for a given ID that was registered using RegisterUIUpdateHandler.
Definition: tools_holder.h:115
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions)
Register a UI update handler for the control with ID aID.
Definition: tools_holder.h:97
bool m_immediateActions
Definition: tools_holder.h:61
TOOL_MANAGER.
Definition: tool_manager.h:51
virtual wxWindow * GetToolCanvas() const =0
Canvas access.
virtual void PopTool(const std::string &actionName)
ACTIONS * m_actions
Definition: tools_holder.h:49
bool m_moveWarpsCursor
Definition: tools_holder.h:66
SELECTION m_dummySelection
Definition: tools_holder.h:52
bool ToolStackIsEmpty()
Definition: tools_holder.h:136
bool GetDragSelects() const
Indicates that a drag should draw a selection rectangle, even when started over an item.
Definition: tools_holder.h:153
std::string CurrentToolName() const
bool GetDoImmediateActions() const
Indicates that hotkeys should perform an immediate action even if another tool is currently active.
Definition: tools_holder.h:147
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:50
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:123
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:48
std::vector< std::string > m_toolStack
Definition: tools_holder.h:54
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
Represents a single user action.
Definition: tool_action.h:44
bool GetMoveWarpsCursor() const
Indicates that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:159
virtual void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
ACTIONS.
Definition: actions.h:43
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
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:85