pcbnew: Centralize selection clearing

Also adds check for items before getting BBox.

Fixes: lp:1832601
* https://bugs.launchpad.net/kicad/+bug/1832601
This commit is contained in:
Seth Hillbrand 2019-06-12 07:35:33 -07:00
parent fac3e2d662
commit 0571ff6ce2
3 changed files with 24 additions and 45 deletions

View File

@ -334,10 +334,8 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
VECTOR2I originalCursorPos = controls->GetCursorPosition(); VECTOR2I originalCursorPos = controls->GetCursorPosition();
auto& existing_selection = m_selectionTool->GetSelection();
if( !existing_selection.GetBoundingBox().Contains( originalCursorPos.x, originalCursorPos.y ) ) m_selectionTool->ClearIfOutside( getViewControls()->GetCursorPosition() );
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, // 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) // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
@ -636,10 +634,8 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
{ {
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition();
auto& existing_selection = m_selectionTool->GetSelection();
if( !existing_selection.GetBoundingBox().Contains( originalCursorPos.x, originalCursorPos.y ) ) m_selectionTool->ClearIfOutside( getViewControls()->GetCursorPosition() );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
const auto& selection = m_selectionTool->RequestSelection( const auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -681,11 +677,8 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
{ {
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>(); 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_selectionTool->ClearIfOutside( getViewControls()->GetCursorPosition() );
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
auto& selection = m_selectionTool->RequestSelection( auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -768,11 +761,7 @@ static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
{ {
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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( auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -854,11 +843,7 @@ int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
{ {
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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( auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -907,11 +892,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
return 1; return 1;
std::vector<BOARD_ITEM*> lockedItems; std::vector<BOARD_ITEM*> lockedItems;
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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) // get a copy instead of reference (as we're going to clear the selection before removing items)
PCBNEW_SELECTION selectionCopy; PCBNEW_SELECTION selectionCopy;
@ -1021,11 +1002,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
{ {
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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 auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -1102,11 +1079,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
{ {
bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement ); bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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 // Be sure that there is at least one item that we can modify
const auto& selection = m_selectionTool->RequestSelection( const auto& selection = m_selectionTool->RequestSelection(
@ -1184,11 +1157,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent ) int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
{ {
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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 auto& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
@ -1354,11 +1323,7 @@ bool EDIT_TOOL::updateModificationPoint( PCBNEW_SELECTION& aSelection )
int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent ) int EDIT_TOOL::EditFpInFpEditor( const TOOL_EVENT& aEvent )
{ {
VECTOR2I originalCursorPos = getViewControls()->GetCursorPosition(); m_selectionTool->ClearIfOutside( 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 ); const auto& selection = m_selectionTool->RequestSelection( FootprintFilter );

View File

@ -386,6 +386,13 @@ PCBNEW_SELECTION& SELECTION_TOOL::GetSelection()
} }
void SELECTION_TOOL::ClearIfOutside( const VECTOR2I& aPt )
{
if( !m_selection.Empty() && !m_selection.GetBoundingBox().Contains( aPt.x, aPt.y ) )
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
}
PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, PCBNEW_SELECTION& SELECTION_TOOL::RequestSelection( CLIENT_SELECTION_FILTER aClientFilter,
std::vector<BOARD_ITEM*>* aFiltered, bool aConfirmLockedItems ) std::vector<BOARD_ITEM*>* aFiltered, bool aConfirmLockedItems )
{ {

View File

@ -97,6 +97,13 @@ public:
PCBNEW_SELECTION& RequestSelection( CLIENT_SELECTION_FILTER aClientFilter, PCBNEW_SELECTION& RequestSelection( CLIENT_SELECTION_FILTER aClientFilter,
std::vector<BOARD_ITEM*>* aFiltered = nullptr, bool aConfirmLockedItems = false ); std::vector<BOARD_ITEM*>* aFiltered = nullptr, bool aConfirmLockedItems = false );
/**
* Clears the selection if the selection Bounding Box doesn't fall within the given point
*
* @param aPt Point to check -- This is inclusive of the edge.
*/
void ClearIfOutside( const VECTOR2I& aPt );
///> Checks if the user has agreed to modify locked items for the given selection. ///> Checks if the user has agreed to modify locked items for the given selection.
SELECTION_LOCK_FLAGS CheckLock(); SELECTION_LOCK_FLAGS CheckLock();