Apply selectable logic to delete tool.
Fixes: lp:1838191 * https://bugs.launchpad.net/kicad/+bug/1838191
This commit is contained in:
parent
c03535343c
commit
987642eb8c
|
@ -526,6 +526,7 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
|||
[this] ( const VECTOR2D& aPos )
|
||||
{
|
||||
BOARD* board = m_frame->GetBoard();
|
||||
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
||||
GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
|
||||
GENERAL_COLLECTOR collector;
|
||||
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
||||
|
@ -535,11 +536,20 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
|||
else
|
||||
collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, (wxPoint) aPos, guide );
|
||||
|
||||
// Remove unselectable items
|
||||
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
||||
{
|
||||
if( !selectionTool->Selectable( collector[ i ] ) )
|
||||
collector.Remove( i );
|
||||
}
|
||||
|
||||
if( collector.GetCount() > 1 )
|
||||
selectionTool->GuessSelectionCandidates( collector, aPos );
|
||||
|
||||
BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
||||
|
||||
if( m_pickerItem != item )
|
||||
{
|
||||
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
||||
|
||||
if( m_pickerItem )
|
||||
selectionTool->UnbrightenItem( m_pickerItem );
|
||||
|
|
|
@ -400,7 +400,7 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
|
|||
// Remove unselectable items
|
||||
for( int i = collector.GetCount() - 1; i >= 0; --i )
|
||||
{
|
||||
if( !selectable( collector[i] ) || ( aOnDrag && collector[i]->IsLocked() ) )
|
||||
if( !Selectable( collector[ i ] ) || ( aOnDrag && collector[i]->IsLocked() ) )
|
||||
collector.Remove( i );
|
||||
}
|
||||
|
||||
|
@ -414,7 +414,7 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
|
|||
// Apply some ugly heuristics to avoid disambiguation menus whenever possible
|
||||
if( collector.GetCount() > 1 && !m_skip_heuristics )
|
||||
{
|
||||
guessSelectionCandidates( collector, aWhere );
|
||||
GuessSelectionCandidates( collector, aWhere );
|
||||
}
|
||||
|
||||
// If still more than one item we're going to have to ask the user.
|
||||
|
@ -542,7 +542,7 @@ bool SELECTION_TOOL::selectMultiple()
|
|||
{
|
||||
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
|
||||
|
||||
if( !item || !selectable( item ) )
|
||||
if( !item || !Selectable( item ) )
|
||||
continue;
|
||||
|
||||
if( item->HitTest( selectionRect, windowSelection ) )
|
||||
|
@ -1426,7 +1426,7 @@ BOARD_ITEM* SELECTION_TOOL::pickSmallestComponent( GENERAL_COLLECTOR* aCollector
|
|||
}
|
||||
|
||||
|
||||
bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly ) const
|
||||
bool SELECTION_TOOL::Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly ) const
|
||||
{
|
||||
// Is high contrast mode enabled?
|
||||
bool highContrast = getView()->GetPainter()->GetSettings()->GetHighContrast();
|
||||
|
@ -1535,13 +1535,13 @@ bool SELECTION_TOOL::selectable( const BOARD_ITEM* aItem, bool checkVisibilityOn
|
|||
|
||||
for( auto item : module->GraphicalItems() )
|
||||
{
|
||||
if( selectable( item, true ) )
|
||||
if( Selectable( item, true ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
for( auto pad : module->Pads() )
|
||||
{
|
||||
if( selectable( pad, true ) )
|
||||
if( Selectable( pad, true ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1884,7 +1884,7 @@ double calcRatio( double a, double b )
|
|||
// We currently check for pads and text mostly covering a footprint, but we don’t check for
|
||||
// smaller footprints mostly covering a larger footprint.
|
||||
//
|
||||
void SELECTION_TOOL::guessSelectionCandidates( GENERAL_COLLECTOR& aCollector,
|
||||
void SELECTION_TOOL::GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector,
|
||||
const VECTOR2I& aWhere ) const
|
||||
{
|
||||
std::set<BOARD_ITEM*> preferred;
|
||||
|
|
|
@ -123,10 +123,21 @@ public:
|
|||
void UnbrightenItem( BOARD_ITEM* aItem );
|
||||
|
||||
/**
|
||||
* Rebuilds the selection from the EDA_ITEMs' selection flags. Commonly called after
|
||||
* rolling back an undo state to make sure there aren't any stale pointers.
|
||||
* Function selectable()
|
||||
* Checks conditions for an item to be selected.
|
||||
*
|
||||
* @return True if the item fulfills conditions to be selected.
|
||||
*/
|
||||
void RebuildSelection();
|
||||
bool Selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
|
||||
|
||||
/**
|
||||
* Function guessSelectionCandidates()
|
||||
* Tries to guess best selection candidates in case multiple items are clicked, by doing
|
||||
* some brain-dead heuristics.
|
||||
* @param aCollector is the collector that has a list of items to be queried.
|
||||
* @param aWhere is the selection point to consider
|
||||
*/
|
||||
void GuessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
|
||||
|
||||
/**
|
||||
* Function SelectionMenu()
|
||||
|
@ -137,6 +148,12 @@ public:
|
|||
*/
|
||||
int SelectionMenu( const TOOL_EVENT& aEvent );
|
||||
|
||||
/**
|
||||
* Rebuilds the selection from the EDA_ITEMs' selection flags. Commonly called after
|
||||
* rolling back an undo state to make sure there aren't any stale pointers.
|
||||
*/
|
||||
void RebuildSelection();
|
||||
|
||||
///> Sets up handlers for various events.
|
||||
void setTransitions() override;
|
||||
|
||||
|
@ -261,14 +278,6 @@ private:
|
|||
*/
|
||||
BOARD_ITEM* pickSmallestComponent( GENERAL_COLLECTOR* aCollector );
|
||||
|
||||
/**
|
||||
* Function selectable()
|
||||
* Checks conditions for an item to be selected.
|
||||
*
|
||||
* @return True if the item fulfills conditions to be selected.
|
||||
*/
|
||||
bool selectable( const BOARD_ITEM* aItem, bool checkVisibilityOnly = false ) const;
|
||||
|
||||
/**
|
||||
* Function select()
|
||||
* Takes necessary action mark an item as selected.
|
||||
|
@ -311,15 +320,6 @@ private:
|
|||
*/
|
||||
bool selectionContains( const VECTOR2I& aPoint ) const;
|
||||
|
||||
/**
|
||||
* Function guessSelectionCandidates()
|
||||
* Tries to guess best selection candidates in case multiple items are clicked, by
|
||||
* doing some braindead heuristics.
|
||||
* @param aCollector is the collector that has a list of items to be queried.
|
||||
* @param aWhere is the selection point to consider
|
||||
*/
|
||||
void guessSelectionCandidates( GENERAL_COLLECTOR& aCollector, const VECTOR2I& aWhere ) const;
|
||||
|
||||
/**
|
||||
* Event handler to update the selection VIEW_ITEM.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue