@ -334,6 +334,10 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
KIGFX : : VIEW_CONTROLS * controls = getViewControls ( ) ;
PCB_BASE_EDIT_FRAME * editFrame = getEditFrame < PCB_BASE_EDIT_FRAME > ( ) ;
VECTOR2I originalCursorPos = controls - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
// Be sure that there is at least one item that we can modify. If nothing was selected before,
// try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
@ -631,6 +635,11 @@ bool EDIT_TOOL::changeTrackWidthOnClick( const PCBNEW_SELECTION& selection )
int EDIT_TOOL : : Properties ( const TOOL_EVENT & aEvent )
{
PCB_BASE_EDIT_FRAME * editFrame = getEditFrame < PCB_BASE_EDIT_FRAME > ( ) ;
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
@ -672,6 +681,11 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
int EDIT_TOOL : : Rotate ( const TOOL_EVENT & aEvent )
{
PCB_BASE_EDIT_FRAME * editFrame = getEditFrame < PCB_BASE_EDIT_FRAME > ( ) ;
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
@ -754,6 +768,12 @@ static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
int EDIT_TOOL : : Mirror ( const TOOL_EVENT & aEvent )
{
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
{ EditToolSelectionFilter ( aCollector , EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ) ; } , nullptr , ! m_dragging ) ;
@ -834,6 +854,12 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
int EDIT_TOOL : : Flip ( const TOOL_EVENT & aEvent )
{
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
{ EditToolSelectionFilter ( aCollector , EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ) ; } , nullptr , ! m_dragging ) ;
@ -881,6 +907,11 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
return 1 ;
std : : vector < BOARD_ITEM * > lockedItems ;
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
// get a copy instead of reference (as we're going to clear the selection before removing items)
PCBNEW_SELECTION selectionCopy ;
@ -990,6 +1021,12 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
int EDIT_TOOL : : MoveExact ( const TOOL_EVENT & aEvent )
{
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
{ EditToolSelectionFilter ( aCollector , EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ) ; } ) ;
@ -1065,6 +1102,11 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
int EDIT_TOOL : : Duplicate ( const TOOL_EVENT & aEvent )
{
bool increment = aEvent . IsAction ( & PCB_ACTIONS : : duplicateIncrement ) ;
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
// Be sure that there is at least one item that we can modify
const auto & selection = m_selectionTool - > RequestSelection (
@ -1142,6 +1184,12 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
int EDIT_TOOL : : CreateArray ( const TOOL_EVENT & aEvent )
{
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const auto & selection = m_selectionTool - > RequestSelection (
[ ] ( const VECTOR2I & aPt , GENERAL_COLLECTOR & aCollector )
{ EditToolSelectionFilter ( aCollector , EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ) ; } ) ;
@ -1306,6 +1354,12 @@ bool EDIT_TOOL::updateModificationPoint( PCBNEW_SELECTION& aSelection )
int EDIT_TOOL : : EditFpInFpEditor ( const TOOL_EVENT & aEvent )
{
VECTOR2I originalCursorPos = getViewControls ( ) - > GetCursorPosition ( ) ;
auto & existing_selection = m_selectionTool - > GetSelection ( ) ;
if ( ! existing_selection . GetBoundingBox ( ) . Contains ( originalCursorPos . x , originalCursorPos . y ) )
m_toolMgr - > RunAction ( PCB_ACTIONS : : selectionClear , true ) ;
const auto & selection = m_selectionTool - > RequestSelection ( FootprintFilter ) ;
if ( selection . Empty ( ) )