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 <fctsys.h>
29 #include <common.h>
30 #include <tool/action_manager.h>
31 #include <tool/selection.h>
32 #include <tool/tool_action.h>
33 
34 
35 class TOOL_MANAGER;
36 class TOOL_DISPATCHER;
37 class ACTIONS;
38 
39 
40 /*
41  * Class TOOLS_HOLDER
42  * A mix-in class which allows its owner to hold a set of tools from the tool framework.
43  *
44  * This is just the framework; the owner is responsible for registering individual tools,
45  * creating the dispatcher, etc.
46  */
48 {
49 protected:
53 
54  SELECTION m_dummySelection; // Empty dummy selection
55 
56  std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
57  // stack of TOOL instances, because somewhat
58  // confusingly most TOOLs implement more than one
59  // user-level tool. A user-level tool actually
60  // equates to an ACTION handler, so this stack
61  // stores ACTION names.
62 
63  bool m_immediateActions; // Preference for immediate actions. If false,
64  // the first invocation of a hotkey will just
65  // select the relevant tool rather than executing
66  // the tool's action.
67  bool m_dragSelects; // Prefer selection to dragging.
68  bool m_moveWarpsCursor; // cursor is warped to move/drag origin
69 
70 public:
71  TOOLS_HOLDER();
72 
73  virtual ~TOOLS_HOLDER() { }
74 
79 
87  virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
88  const ACTION_CONDITIONS& aConditions )
89  {}
90 
96  virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
97  {}
98 
105  {
106  return m_dummySelection;
107  }
108 
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 
134  bool GetDragSelects() const { return m_dragSelects; }
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 
157 #endif // TOOL_HOLDER_H
bool IsCurrentTool(const TOOL_ACTION &aAction) const
virtual ~TOOLS_HOLDER()
Definition: tools_holder.h:73
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:96
virtual void DisplayToolMsg(const wxString &msg)
Definition: tools_holder.h:122
virtual wxString ConfigBaseName()
Definition: tools_holder.h:154
bool m_dragSelects
Definition: tools_holder.h:67
bool m_immediateActions
Definition: tools_holder.h:63
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:51
bool m_moveWarpsCursor
Definition: tools_holder.h:68
SELECTION m_dummySelection
Definition: tools_holder.h:54
bool ToolStackIsEmpty()
Definition: tools_holder.h:117
bool GetDragSelects() const
Indicates that a drag should draw a selection rectangle, even when started over an item.
Definition: tools_holder.h:134
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:128
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:52
virtual SELECTION & GetCurrentSelection()
Get the current selection from the canvas area.
Definition: tools_holder.h:104
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:50
std::vector< std::string > m_toolStack
Definition: tools_holder.h:56
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
The common library.
bool GetMoveWarpsCursor() const
Indicates 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.
ACTIONS.
Definition: actions.h:43
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
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:87