diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index d2af325680..651ea5bab7 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -783,10 +783,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) int EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent ) { - if( !hoverSelection() ) - return 0; - - MODULE* mod = uniqueSelected(); + MODULE* mod = uniqueHoverSelection(); if( !mod ) return 0; @@ -895,10 +892,7 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent ) SELECTION& selection = m_selectionTool->GetSelection(); bool unselect = selection.Empty(); - if( !hoverSelection() ) - return 0; - - MODULE* mod = uniqueSelected(); + MODULE* mod = uniqueHoverSelection(); if( !mod ) return 0; diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 52310d1868..93adf2a1aa 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -150,15 +150,34 @@ private: ///> selected items. wxPoint getModificationPoint( const SELECTION& aSelection ); - ///> If there are no items currently selected, it tries to choose the item that is under - ///> the cursor or displays a disambiguation menu if there are multiple items. - bool hoverSelection( bool aSanitize = true ); - int editFootprintInFpEditor( const TOOL_EVENT& aEvent ); bool invokeInlineRouter(); - template T* uniqueSelected() + /** + * Function hoverSelection() + * + * If there are no items currently selected, it tries to choose the + * item that is under he cursor or displays a disambiguation menu + * if there are multiple items. + * + * @param aSanitize sanitize selection using SanitizeSelection() + * @return true if the eventual selection contains any items, or + * false if it fails to select any items. + */ + bool hoverSelection( bool aSanitize = true ); + + /** + * Function uniqueSelected() + * + * Get a single selected item of a certain type + * + * @tparam T type of item to select + * @return pointer to the item (of type T), or nullptr if there isn't + * a single selected item, or it's not of the right type. + */ + template + T* uniqueSelected() { const SELECTION& selection = m_selectionTool->GetSelection(); @@ -169,6 +188,28 @@ private: return dyn_cast( item ); } + /** + * Function uniqueHoverSelection() + * + * Get a single unique selection of an item, either from the + * current selection, or from the items under cursor via + * hoverSelection() + * + * @tparam T type of item to select + * @return pointer to a selected item, or nullptr if none could + * be found. + */ + template + T* uniqueHoverSelection( bool aSanitize = true ) + { + if( !hoverSelection( aSanitize ) ) + return nullptr; + + T* item = uniqueSelected(); + + return item; + } + std::unique_ptr m_commit; };