From 0c1a87ca56afe47099bc1d04c25758455181ed2e Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Fri, 21 Nov 2014 11:50:13 +0100 Subject: [PATCH] selection_tool: Added SelectItem and UnselectItem actions. --- pcbnew/tools/common_actions.cpp | 8 ++++++ pcbnew/tools/common_actions.h | 6 ++++ pcbnew/tools/selection_tool.cpp | 51 +++++++++++++++++++++++++++++++-- pcbnew/tools/selection_tool.h | 6 ++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 7d39c44310..456a0219af 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -36,6 +36,14 @@ TOOL_ACTION COMMON_ACTIONS::selectionCursor( "pcbnew.InteractiveSelection.Cursor AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere +TOOL_ACTION COMMON_ACTIONS::selectItem( "pcbnew.InteractiveSelection.SelectItem", + AS_GLOBAL, 0, + "", "" ); // No description, it is not supposed to be shown anywhere + +TOOL_ACTION COMMON_ACTIONS::unselectItem( "pcbnew.InteractiveSelection.UnselectItem", + AS_GLOBAL, 0, + "", "" ); // No description, it is not supposed to be shown anywhere + TOOL_ACTION COMMON_ACTIONS::selectionClear( "pcbnew.InteractiveSelection.Clear", AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 0489c6f101..366f4440dd 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -46,6 +46,12 @@ public: /// Clears the current selection static TOOL_ACTION selectionClear; + /// Selects an item (specified as the event parameter). + static TOOL_ACTION selectItem; + + /// Unselects an item (specified as the event parameter). + static TOOL_ACTION unselectItem; + // Edit Tool /// Activation of the edit tool static TOOL_ACTION editActivate; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index e4903f2d9d..df5709aae5 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -187,6 +187,16 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) findMove( *evt ); } + else if( evt->IsAction( &COMMON_ACTIONS::selectItem ) ) + { + SelectItem( *evt ); + } + + else if( evt->IsAction( &COMMON_ACTIONS::unselectItem ) ) + { + UnselectItem( *evt ); + } + else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO || evt->IsAction( &COMMON_ACTIONS::selectionClear ) ) { @@ -397,6 +407,8 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() ); Go( &SELECTION_TOOL::CursorSelection, COMMON_ACTIONS::selectionCursor.MakeEvent() ); Go( &SELECTION_TOOL::ClearSelection, COMMON_ACTIONS::selectionClear.MakeEvent() ); + Go( &SELECTION_TOOL::SelectItem, COMMON_ACTIONS::selectItem.MakeEvent() ); + Go( &SELECTION_TOOL::UnselectItem, COMMON_ACTIONS::unselectItem.MakeEvent() ); Go( &SELECTION_TOOL::find, COMMON_ACTIONS::find.MakeEvent() ); Go( &SELECTION_TOOL::findMove, COMMON_ACTIONS::findMove.MakeEvent() ); } @@ -461,6 +473,43 @@ int SELECTION_TOOL::ClearSelection( TOOL_EVENT& aEvent ) return 0; } +int SELECTION_TOOL::SelectItem( TOOL_EVENT& aEvent ) +{ + // Check if there is an item to be selected + BOARD_ITEM* item = static_cast( aEvent.Parameter() ); + + if( item ) + { + select( item ); + + // Inform other potentially interested tools + TOOL_EVENT select( SelectedEvent ); + m_toolMgr->ProcessEvent( select ); + } + + setTransitions(); + + return 0; +} + +int SELECTION_TOOL::UnselectItem( TOOL_EVENT& aEvent ) +{ + // Check if there is an item to be selected + BOARD_ITEM* item = static_cast( aEvent.Parameter() ); + + if( item ) + { + unselect( item ); + + // Inform other potentially interested tools + TOOL_EVENT unselect( UnselectedEvent ); + m_toolMgr->ProcessEvent( unselect ); + } + + setTransitions(); + + return 0; +} void SELECTION_TOOL::findCallback( BOARD_ITEM* aItem ) { @@ -525,8 +574,6 @@ void SELECTION_TOOL::clearSelection() // Inform other potentially interested tools TOOL_EVENT clearEvent( ClearedEvent ); m_toolMgr->ProcessEvent( clearEvent ); - - return; } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 11b1d57df6..89cb40b4ec 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -157,6 +157,12 @@ public: ///> Clear current selection event handler. int ClearSelection( TOOL_EVENT& aEvent ); + ///> Item selection event handler. + int SelectItem( TOOL_EVENT& aEvent ); + + ///> Item unselection event handler. + int UnselectItem( TOOL_EVENT& aEvent ); + ///> Event sent after an item is selected. const TOOL_EVENT SelectedEvent;