Commit 94cc845b authored by Maciej Suminski's avatar Maciej Suminski

Added AF_ACTIVATE flag for TOOL_ACTIONs.

Reworked the way of processing events in TOOL_MANAGER class.
Added GetCommandStr() for TOOL_EVENT class.
parent 34fbde42
......@@ -495,15 +495,7 @@ bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
{
// Check if there is a hotkey associated
if( m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() ) )
return false; // hotkey event was handled so it does not go any further
}
else if( aEvent.Action() == TA_ACTIVATE )
{
// Check if the tool name conforms to the the used tool name format
assert( std::count( aEvent.m_commandStr->begin(), aEvent.m_commandStr->end(), '.' ) == 1 );
dispatchActivation( aEvent );
// do not return false, as the event has to go on to the destined tool
return false; // hotkey event was handled so it does not go any further
}
return true;
......@@ -512,41 +504,23 @@ bool TOOL_MANAGER::dispatchStandardEvents( TOOL_EVENT& aEvent )
bool TOOL_MANAGER::dispatchActivation( TOOL_EVENT& aEvent )
{
std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr );
if( tool != m_toolNameIndex.end() )
if( aEvent.IsActivate() )
{
runTool( tool->second->theTool );
return true;
std::map<std::string, TOOL_STATE*>::iterator tool = m_toolNameIndex.find( *aEvent.m_commandStr );
if( tool != m_toolNameIndex.end() )
{
runTool( tool->second->theTool );
return true;
}
}
return false;
}
void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
void TOOL_MANAGER::dispatchContextMenu( TOOL_EVENT& aEvent )
{
if( !aState->Pop() ) // if there are no other contexts saved on the stack
{
// find the tool and deactivate it
std::deque<TOOL_ID>::iterator tool = std::find( m_activeTools.begin(), m_activeTools.end(),
aState->theTool->GetId() );
if( tool != m_activeTools.end() )
m_activeTools.erase( tool );
}
}
bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
{
// Early dispatch of events destined for the TOOL_MANAGER
if( !dispatchStandardEvents( aEvent ) )
return false;
dispatchInternal( aEvent );
// popup menu handling
BOOST_FOREACH( TOOL_ID toolId, m_activeTools )
{
TOOL_STATE* st = m_toolIdIndex[toolId];
......@@ -577,6 +551,32 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
break;
}
}
}
void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
{
if( !aState->Pop() ) // if there are no other contexts saved on the stack
{
// find the tool and deactivate it
std::deque<TOOL_ID>::iterator tool = std::find( m_activeTools.begin(), m_activeTools.end(),
aState->theTool->GetId() );
if( tool != m_activeTools.end() )
m_activeTools.erase( tool );
}
}
bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
{
// Early dispatch of events destined for the TOOL_MANAGER
if( !dispatchStandardEvents( aEvent ) )
return false;
dispatchInternal( aEvent );
dispatchActivation( aEvent );
dispatchContextMenu( aEvent );
if( m_view->IsDirty() )
{
......
......@@ -29,7 +29,6 @@
#include <string>
#include <cassert>
#include <tool/tool_base.h>
#include <tool/tool_manager.h>
/**
......@@ -47,10 +46,10 @@ class TOOL_ACTION
public:
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
int aDefaultHotKey = 0, const std::string& aMenuItem = std::string( "" ),
const std::string& aMenuDesc = std::string( "" ) ) :
const std::string& aMenuDesc = std::string( "" ), TOOL_ACTION_FLAGS aFlags = AF_NONE ) :
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ),
m_menuDescription( aMenuDesc ), m_id( -1 )
m_menuDescription( aMenuDesc ), m_id( -1 ), m_flags( aFlags )
{
TOOL_MANAGER::GetActionList().push_back( this );
}
......@@ -190,8 +189,7 @@ public:
*/
bool IsActivation() const
{
// Tool activation events are of format appName.toolName
return std::count( m_name.begin(), m_name.end(), '.' ) == 1;
return m_flags & AF_ACTIVATE;
}
private:
......@@ -200,7 +198,7 @@ private:
/// Name of the action (convention is: app.[tool.]action.name)
std::string m_name;
/// Scope of the action (ie. the event that is issued after activation).
/// Scope of the action (i.e. the event that is issued after activation).
TOOL_ACTION_SCOPE m_scope;
/// Default hot key that activates the action.
......@@ -221,6 +219,9 @@ private:
/// Unique ID for fast matching. Assigned by ACTION_MANAGER.
int m_id;
/// Action flags
TOOL_ACTION_FLAGS m_flags;
/// Origin of the action
// const TOOL_BASE* m_origin;
......
......@@ -126,6 +126,13 @@ enum TOOL_ACTION_SCOPE
AS_GLOBAL ///> Global action (toolbar/main menu event, global shortcut)
};
/// Flags for tool actions
enum TOOL_ACTION_FLAGS
{
AF_NONE = 0,
AF_ACTIVATE = 1 ///> Action activates a tool
};
/// Defines when a context menu is opened.
enum CONTEXT_MENU_TRIGGER
{
......@@ -268,6 +275,11 @@ public:
return m_actions == TA_CANCEL_TOOL;
}
bool IsActivate() const
{
return m_actions == TA_ACTIVATE;
}
///> Returns information about key modifiers state (Ctrl, Alt, etc.)
int Modifier( int aMask = MD_MODIFIER_MASK ) const
{
......@@ -334,11 +346,16 @@ public:
*/
bool IsAction( const TOOL_ACTION* aAction ) const;
boost::optional<int> GetCommandId()
boost::optional<int> GetCommandId() const
{
return m_commandId;
}
boost::optional<std::string> GetCommandStr() const
{
return m_commandStr;
}
private:
friend class TOOL_MANAGER;
......
......@@ -274,6 +274,10 @@ private:
struct TOOL_STATE;
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;
/**
* Function dispatchInternal
* Passes an event at first to the active tools, then to all others.
*/
void dispatchInternal( TOOL_EVENT& aEvent );
/**
......@@ -292,6 +296,12 @@ private:
*/
bool dispatchActivation( TOOL_EVENT& aEvent );
/**
* Function dispatchContextMenu()
* Handles context menu related events.
*/
void dispatchContextMenu( TOOL_EVENT& aEvent );
/**
* Function invokeTool()
* Invokes a tool by sending a proper event (in contrary to runTool, which makes the tool run
......
......@@ -480,8 +480,7 @@ void ROUTER_TOOL::updateEndItem( TOOL_EVENT& aEvent )
VECTOR2I p = getView()->ToWorld( ctls->GetMousePosition() );
VECTOR2I cp = ctls->GetCursorPosition();
int layer;
bool snapEnabled = !aEvent.Modifier(MD_SHIFT);
bool snapEnabled = !aEvent.Modifier( MD_SHIFT );
m_router->EnableSnapping ( snapEnabled );
......@@ -554,7 +553,7 @@ void ROUTER_TOOL::performRouting()
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
break;
else if( evt->Action() == TA_UNDO_REDO )
{
......@@ -663,7 +662,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
m_needsSync = false;
}
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
break; // Finish
else if( evt->Action() == TA_UNDO_REDO )
m_needsSync = true;
......@@ -677,10 +676,11 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
performDragging();
else
performRouting();
} else if ( evt->IsAction( &ACT_Drag ) )
}
else if ( evt->IsAction( &ACT_Drag ) )
performDragging();
handleCommonEvents(*evt);
handleCommonEvents( *evt );
}
// Restore the default settings
......@@ -715,7 +715,7 @@ void ROUTER_TOOL::performDragging()
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
break;
else if( evt->Action() == TA_UNDO_REDO )
{
......
......@@ -29,7 +29,7 @@
// Selection tool actions
TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
AS_GLOBAL, 0, "", "", AF_ACTIVATE ); // No description, it is not supposed to be shown anywhere
TOOL_ACTION COMMON_ACTIONS::selectionSingle( "pcbnew.InteractiveSelection.Single",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
......@@ -41,7 +41,7 @@ TOOL_ACTION COMMON_ACTIONS::selectionClear( "pcbnew.InteractiveSelection.Clear",
// Edit tool actions
TOOL_ACTION COMMON_ACTIONS::editActivate( "pcbnew.InteractiveEdit",
AS_GLOBAL, 'M',
"Move", "Moves the selected item(s)" );
"Move", "Moves the selected item(s)", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::rotate( "pcbnew.InteractiveEdit.rotate",
AS_GLOBAL, 'R',
......@@ -63,50 +63,43 @@ TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties",
// Drawing tool actions
TOOL_ACTION COMMON_ACTIONS::drawLine( "pcbnew.InteractiveDrawing.line",
AS_GLOBAL, 0,
"Draw a line", "Draw a line" );
"Draw a line", "Draw a line", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::drawCircle( "pcbnew.InteractiveDrawing.circle",
AS_GLOBAL, 0,
"Draw a circle", "Draw a circle" );
"Draw a circle", "Draw a circle", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::drawArc( "pcbnew.InteractiveDrawing.arc",
AS_GLOBAL, 0,
"Draw an arc", "Draw an arc" );
"Draw an arc", "Draw an arc", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::placeTextModule( "pcbnew.InteractiveDrawing.textPcb",
AS_GLOBAL, 0,
"Add a text", "Add a text" );
"Add a text", "Add a text", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::placeTextPcb( "pcbnew.InteractiveDrawing.textModule",
AS_GLOBAL, 0,
"Add a text", "Add a text" );
"Add a text", "Add a text", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::drawDimension( "pcbnew.InteractiveDrawing.dimension",
AS_GLOBAL, 0,
"Add a dimension", "Add a dimension" );
"Add a dimension", "Add a dimension", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::drawZone( "pcbnew.InteractiveDrawing.zone",
AS_GLOBAL, 0,
"Add a filled zone", "Add a filled zone" );
"Add a filled zone", "Add a filled zone", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::drawKeepout( "pcbnew.InteractiveDrawing.keepout",
AS_GLOBAL, 0,
"Add a keepout area", "Add a keepout area" );
"Add a keepout area", "Add a keepout area", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::placeTarget( "pcbnew.InteractiveDrawing.placeTarget",
AS_GLOBAL, 0,
"Add layer alignment target", "Add layer alignment target" );
"Add layer alignment target", "Add layer alignment target", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::placeModule( "pcbnew.InteractiveDrawing.placeModule",
AS_GLOBAL, 'O',
"Add modules", "Add modules" );
TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter",
AS_GLOBAL, 'X',
"Run push & shove router", "Run push & shove router" );
TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
"Add modules", "Add modules", AF_ACTIVATE );
// View Controls
......@@ -268,6 +261,13 @@ TOOL_ACTION COMMON_ACTIONS::showHelp( "pcbnew.Control.showHelp",
AS_GLOBAL, '?',
"", "" );
TOOL_ACTION COMMON_ACTIONS::routerActivate( "pcbnew.InteractiveRouter",
AS_GLOBAL, 'X',
"Run push & shove router", "Run push & shove router", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::pointEditorUpdate( "pcbnew.PointEditor.update",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId )
{
......
......@@ -123,7 +123,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{
cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( step != SET_ORIGIN ) // start from the beginning
{
......@@ -135,6 +135,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( evt->IsKeyPressed() && step != SET_ORIGIN )
......@@ -301,7 +304,7 @@ int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( text )
{
......@@ -315,6 +318,9 @@ int DRAWING_TOOL::PlaceTextModule( TOOL_EVENT& aEvent )
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( text && evt->Category() == TC_COMMAND )
......@@ -406,7 +412,7 @@ int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( text )
{
......@@ -420,6 +426,9 @@ int DRAWING_TOOL::PlaceTextPcb( TOOL_EVENT& aEvent )
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( text && evt->Category() == TC_COMMAND )
......@@ -520,7 +529,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( step != SET_ORIGIN ) // start from the beginning
{
......@@ -532,6 +541,9 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( evt->IsKeyPressed() && step != SET_ORIGIN )
......@@ -707,7 +719,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
{
cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
break;
else if( evt->IsKeyPressed() )
......@@ -783,7 +795,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
{
VECTOR2I cursorPos = m_controls->GetCursorPosition();
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( module )
{
......@@ -796,6 +808,9 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
}
else
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( module && evt->Category() == TC_COMMAND )
......@@ -915,7 +930,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
updatePreview = true;
}
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( !graphic )
break;
......@@ -927,6 +942,9 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
graphic = NULL;
m_controls->SetAutoPan( false );
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( graphic && evt->IsKeyPressed() )
......@@ -1093,7 +1111,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
updatePreview = true;
}
if( evt->IsCancel() )
if( evt->IsCancel() || evt->IsActivate() )
{
if( numPoints > 0 ) // cancel the current zone
{
......@@ -1114,6 +1132,9 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
}
else // there is no zone currently drawn - just stop the tool
break;
if( evt->IsActivate() ) // now finish unconditionally
break;
}
else if( evt->IsClick( BUT_LEFT ) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment