From ac7bdfc7f6d9bb5f8dc9c91ba5e4aebb081f1249 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 13 Oct 2014 15:25:16 +0200 Subject: [PATCH] pcbnew: Fixed 'Find Item' (GAL canvas). --- pcbnew/tools/common_actions.cpp | 7 +++++++ pcbnew/tools/common_actions.h | 3 +++ pcbnew/tools/selection_tool.cpp | 30 ++++++++++++++++++++++++++++++ pcbnew/tools/selection_tool.h | 6 ++++++ 4 files changed, 46 insertions(+) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 15ce48f1ae..1efb778a7f 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -40,6 +40,10 @@ TOOL_ACTION COMMON_ACTIONS::selectionClear( "pcbnew.InteractiveSelection.Clear", AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere +TOOL_ACTION COMMON_ACTIONS::find( "pcbnew.InteractiveSelection.Find", + AS_GLOBAL, 0, + "Find an item", "Searches the document for an item" ); + TOOL_ACTION COMMON_ACTIONS::findMove( "pcbnew.InteractiveSelection.FindMove", AS_GLOBAL, 'T'); @@ -489,6 +493,9 @@ boost::optional COMMON_ACTIONS::TranslateLegacyId( int aId ) case ID_TB_OPTIONS_SELECT_CURSOR: return COMMON_ACTIONS::switchCursor.MakeEvent(); + case ID_FIND_ITEMS: + return COMMON_ACTIONS::find.MakeEvent(); + case ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST: return COMMON_ACTIONS::findMove.MakeEvent(); diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index b2e354622a..399dc3934c 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -217,6 +217,9 @@ public: static TOOL_ACTION showHelp; static TOOL_ACTION toBeDone; + /// Find an item + static TOOL_ACTION find; + /// Find an item and start moving static TOOL_ACTION findMove; diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index be2e0b2c5f..8b6eac6b42 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -176,6 +177,11 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) ); } + else if( evt->IsAction( &COMMON_ACTIONS::find ) ) + { + find( *evt ); + } + else if( evt->IsAction( &COMMON_ACTIONS::findMove ) ) { findMove( *evt ); @@ -391,6 +397,7 @@ void SELECTION_TOOL::setTransitions() Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() ); Go( &SELECTION_TOOL::SingleSelection, COMMON_ACTIONS::selectionSingle.MakeEvent() ); Go( &SELECTION_TOOL::ClearSelection, COMMON_ACTIONS::selectionClear.MakeEvent() ); + Go( &SELECTION_TOOL::find, COMMON_ACTIONS::find.MakeEvent() ); Go( &SELECTION_TOOL::findMove, COMMON_ACTIONS::findMove.MakeEvent() ); } @@ -455,6 +462,29 @@ int SELECTION_TOOL::ClearSelection( TOOL_EVENT& aEvent ) } +void SELECTION_TOOL::findCallback( BOARD_ITEM* aItem ) +{ + clearSelection(); + + if( aItem ) + toggleSelection( aItem ); + + m_frame->GetGalCanvas()->ForceRefresh(); +} + + +int SELECTION_TOOL::find( TOOL_EVENT& aEvent ) +{ + DIALOG_FIND dlg( m_frame ); + dlg.EnableWarp( false ); + dlg.SetCallback( boost::bind( &SELECTION_TOOL::findCallback, this, _1 ) ); + dlg.ShowModal(); + setTransitions(); + + return 0; +} + + int SELECTION_TOOL::findMove( TOOL_EVENT& aEvent ) { MODULE* module = m_frame->GetModuleByName(); diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 43744db529..70e18cd7bd 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -187,6 +187,12 @@ private: */ bool selectMultiple(); + ///> Find dialog callback. + void findCallback( BOARD_ITEM* aItem ); + + ///> Find an item. + int find( TOOL_EVENT& aEvent ); + ///> Find an item and start moving. int findMove( TOOL_EVENT& aEvent );