Factor an EDIT_TOOL selection routine
Also add some commentary to other EDIT_TOOL selection functions.
This commit is contained in:
parent
45b60b1bb0
commit
fb6de689b9
|
@ -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>();
|
||||
MODULE* mod = uniqueHoverSelection<MODULE>();
|
||||
|
||||
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>();
|
||||
MODULE* mod = uniqueHoverSelection<MODULE>();
|
||||
|
||||
if( !mod )
|
||||
return 0;
|
||||
|
|
|
@ -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<class T> 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<class T>
|
||||
T* uniqueSelected()
|
||||
{
|
||||
const SELECTION& selection = m_selectionTool->GetSelection();
|
||||
|
||||
|
@ -169,6 +188,28 @@ private:
|
|||
return dyn_cast<T*>( 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<class T>
|
||||
T* uniqueHoverSelection( bool aSanitize = true )
|
||||
{
|
||||
if( !hoverSelection( aSanitize ) )
|
||||
return nullptr;
|
||||
|
||||
T* item = uniqueSelected<T>();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
std::unique_ptr<BOARD_COMMIT> m_commit;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue