2020-03-24 01:01:23 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOOL_HOLDER_H
|
|
|
|
#define TOOL_HOLDER_H
|
|
|
|
|
|
|
|
#include <vector>
|
2020-07-27 22:42:23 +00:00
|
|
|
#include <tool/action_manager.h>
|
|
|
|
#include <tool/selection.h>
|
2020-03-24 01:01:23 +00:00
|
|
|
#include <tool/tool_action.h>
|
|
|
|
|
|
|
|
|
|
|
|
class TOOL_MANAGER;
|
|
|
|
class TOOL_DISPATCHER;
|
|
|
|
class ACTIONS;
|
|
|
|
|
|
|
|
|
2020-03-29 19:02:23 +00:00
|
|
|
/*
|
|
|
|
* A mix-in class which allows its owner to hold a set of tools from the tool framework.
|
|
|
|
*
|
|
|
|
* This is just the framework; the owner is responsible for registering individual tools,
|
|
|
|
* creating the dispatcher, etc.
|
|
|
|
*/
|
2020-03-24 01:01:23 +00:00
|
|
|
class TOOLS_HOLDER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TOOLS_HOLDER();
|
|
|
|
|
2020-04-19 00:51:49 +00:00
|
|
|
virtual ~TOOLS_HOLDER() { }
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
/**
|
|
|
|
* Return the MVC controller.
|
|
|
|
*/
|
|
|
|
TOOL_MANAGER* GetToolManager() const { return m_toolManager; }
|
|
|
|
|
2020-07-27 22:42:23 +00:00
|
|
|
/**
|
|
|
|
* Register an action's update conditions with the UI layer to allow the UI to appropriately
|
|
|
|
* display the state of its controls.
|
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @param aAction is the action to register.
|
|
|
|
* @param aConditions are the UI conditions to use for the control states.
|
2020-07-27 22:42:23 +00:00
|
|
|
*/
|
|
|
|
virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
|
|
|
|
const ACTION_CONDITIONS& aConditions )
|
2020-09-26 23:55:59 +00:00
|
|
|
{
|
|
|
|
RegisterUIUpdateHandler( aAction.GetUIId(), aConditions );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Register a UI update handler for the control with ID @c aID.
|
2020-09-26 23:55:59 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @param aID is the control ID to register the handler for.
|
|
|
|
* @param aConditions are the UI conditions to use for the control states.
|
2020-09-26 23:55:59 +00:00
|
|
|
*/
|
|
|
|
virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
|
2020-07-27 22:42:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Unregister a UI handler for an action that was registered using @c RegisterUIUpdateHandler.
|
2020-07-27 22:42:23 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @param aAction is the action to unregister the handler for.
|
2020-07-27 22:42:23 +00:00
|
|
|
*/
|
|
|
|
virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
|
2020-09-26 23:55:59 +00:00
|
|
|
{
|
|
|
|
UnregisterUIUpdateHandler( aAction.GetUIId() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Unregister a UI handler for a given ID that was registered using @c RegisterUIUpdateHandler.
|
2020-09-26 23:55:59 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @param aID is the control ID to unregister the handler for.
|
2020-09-26 23:55:59 +00:00
|
|
|
*/
|
|
|
|
virtual void UnregisterUIUpdateHandler( int aID )
|
2020-07-27 22:42:23 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current selection from the canvas area.
|
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @return the current selection.
|
2020-07-27 22:42:23 +00:00
|
|
|
*/
|
|
|
|
virtual SELECTION& GetCurrentSelection()
|
|
|
|
{
|
|
|
|
return m_dummySelection;
|
|
|
|
}
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* NB: the definition of "tool" is different at the user level.
|
|
|
|
*
|
|
|
|
* The implementation uses a single TOOL_BASE derived class to implement several user
|
|
|
|
* "tools", such as rectangle and circle, or wire and bus. So each user-level tool is
|
|
|
|
* actually a #TOOL_ACTION.
|
2020-03-24 01:01:23 +00:00
|
|
|
*/
|
|
|
|
virtual void PushTool( const std::string& actionName );
|
|
|
|
virtual void PopTool( const std::string& actionName );
|
|
|
|
|
|
|
|
bool ToolStackIsEmpty() { return m_toolStack.empty(); }
|
|
|
|
|
|
|
|
std::string CurrentToolName() const;
|
|
|
|
bool IsCurrentTool( const TOOL_ACTION& aAction ) const;
|
|
|
|
|
|
|
|
virtual void DisplayToolMsg( const wxString& msg ) {};
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Indicate that hotkeys should perform an immediate action even if another tool is
|
2020-03-24 01:01:23 +00:00
|
|
|
* currently active. If false, the first hotkey should select the relevant tool.
|
|
|
|
*/
|
|
|
|
bool GetDoImmediateActions() const { return m_immediateActions; }
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Indicate that a drag should draw a selection rectangle, even when started over an
|
2020-03-24 01:01:23 +00:00
|
|
|
* item.
|
|
|
|
*/
|
|
|
|
bool GetDragSelects() const { return m_dragSelects; }
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Indicate that a move operation should warp the mouse pointer to the origin of the
|
|
|
|
* move object. This improves snapping, but some users are allergic to mouse warping.
|
2020-03-24 01:01:23 +00:00
|
|
|
*/
|
|
|
|
bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification event that some of the common (suite-wide) settings have changed.
|
|
|
|
* Update hotkeys, preferences, etc.
|
|
|
|
*/
|
2020-07-17 20:04:14 +00:00
|
|
|
virtual void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged );
|
2020-03-24 01:01:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Canvas access.
|
|
|
|
*/
|
|
|
|
virtual wxWindow* GetToolCanvas() const = 0;
|
|
|
|
virtual void RefreshCanvas() { }
|
|
|
|
|
|
|
|
virtual wxString ConfigBaseName() { return wxEmptyString; }
|
2020-12-27 00:41:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
TOOL_MANAGER* m_toolManager;
|
|
|
|
ACTIONS* m_actions;
|
|
|
|
TOOL_DISPATCHER* m_toolDispatcher;
|
|
|
|
|
|
|
|
SELECTION m_dummySelection; // Empty dummy selection
|
|
|
|
|
|
|
|
std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
|
|
|
|
// stack of TOOL instances, because somewhat
|
|
|
|
// confusingly most TOOLs implement more than one
|
|
|
|
// user-level tool. A user-level tool actually
|
|
|
|
// equates to an ACTION handler, so this stack
|
|
|
|
// stores ACTION names.
|
|
|
|
|
|
|
|
bool m_immediateActions; // Preference for immediate actions. If false,
|
|
|
|
// the first invocation of a hotkey will just
|
|
|
|
// select the relevant tool rather than executing
|
|
|
|
// the tool's action.
|
|
|
|
bool m_dragSelects; // Prefer selection to dragging.
|
|
|
|
bool m_moveWarpsCursor; // cursor is warped to move/drag origin
|
2020-03-24 01:01:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TOOL_HOLDER_H
|