diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 918fb8f2aa..9538f27c4b 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -66,7 +66,7 @@ SELECTION_TOOL::~SELECTION_TOOL() void SELECTION_TOOL::Reset() { - clearSelection(); + ClearSelection(); // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); @@ -89,7 +89,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) if( evt->IsCancel() ) { if( !m_selection.Empty() ) // Cancel event deselects items... - clearSelection(); + ClearSelection(); // This tool never exits } @@ -98,7 +98,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) else if( evt->IsClick( BUT_LEFT ) ) { if( !m_additive && m_selection.Size() > 1 ) - clearSelection(); + ClearSelection(); selectSingle( evt->Position() ); } @@ -132,7 +132,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) else { // No -> clear the selection list - clearSelection(); + ClearSelection(); } } } @@ -145,42 +145,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) } -void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction ) -{ - assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER - - m_menu.Add( aAction ); -} - - -void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) -{ - if( m_selection.items.find( aItem ) != m_selection.items.end() ) - { - deselectItem( aItem ); - - // If there is nothing selected, disable the context menu - if( m_selection.Empty() ) - SetContextMenu( &m_menu, CMENU_OFF ); - } - else - { - if( !m_additive ) - clearSelection(); - - // Prevent selection of invisible or inactive items - if( selectable( aItem ) ) - { - selectItem( aItem ); - - // Now the context menu should be enabled - SetContextMenu( &m_menu, CMENU_BUTTON ); - } - } -} - - -void SELECTION_TOOL::clearSelection() +void SELECTION_TOOL::ClearSelection() { KIGFX::VIEW_GROUP::const_iter it, it_end; @@ -195,11 +160,45 @@ void SELECTION_TOOL::clearSelection() m_selection.Clear(); + getEditFrame()->SetCurItem( NULL ); + // Do not show the context menu when there is nothing selected SetContextMenu( &m_menu, CMENU_OFF ); } +void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction ) +{ + assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER + + m_menu.Add( aAction ); +} + + +void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) +{ + if( isSelected( aItem ) ) + { + deselectItem( aItem ); + } + else + { + if( !m_additive ) + ClearSelection(); + + // Prevent selection of invisible or inactive items + if( selectable( aItem ) ) + selectItem( aItem ); + } +} + + +bool SELECTION_TOOL::isSelected( const BOARD_ITEM* aItem ) const +{ + return ( m_selection.items.find( const_cast( aItem ) ) != m_selection.items.end() ); +} + + void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) { BOARD* pcb = getModel( PCB_T ); @@ -214,7 +213,7 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) { case 0: if( !m_additive ) - clearSelection(); + ClearSelection(); break; @@ -308,7 +307,7 @@ bool SELECTION_TOOL::selectMultiple() if( evt->IsDrag( BUT_LEFT ) ) { if( !m_additive ) - clearSelection(); + ClearSelection(); // Start drawing a selection box m_selArea->SetOrigin( evt->DragOrigin() ); @@ -338,11 +337,10 @@ bool SELECTION_TOOL::selectMultiple() selectItem( item ); } - // Now the context menu should be enabled - if( !m_selection.Empty() ) - SetContextMenu( &m_menu, CMENU_BUTTON ); + // Do not display information about selected item,as there is more than one + getEditFrame()->SetCurItem( NULL ); - break; + break; // Stop waiting for events } } @@ -413,9 +411,6 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) // Removes possible brighten mark getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); - // Restore the original menu - SetContextMenu( &m_menu, CMENU_BUTTON ); - return current; } @@ -542,6 +537,16 @@ void SELECTION_TOOL::selectItem( BOARD_ITEM* aItem ) // Add items to the VIEW_GROUP, so they will be displayed on the overlay selectBase( aItem ); m_selection.items.insert( aItem ); + + // It is enough to do it only for the first selected item + if( m_selection.items.size() == 1 ) + { + // Set as the current item, so the information about selection is displayed + getEditFrame()->SetCurItem( aItem, true ); + + // Now the context menu should be enabled + SetContextMenu( &m_menu, CMENU_BUTTON ); + } } @@ -584,6 +589,13 @@ void SELECTION_TOOL::deselectItem( BOARD_ITEM* aItem ) deselectBase( aItem ); m_selection.items.erase( aItem ); + + // If there is nothing selected, disable the context menu + if( m_selection.Empty() ) + { + SetContextMenu( &m_menu, CMENU_OFF ); + getEditFrame()->SetCurItem( NULL ); + } } diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 40806c3b94..fa6ed0f545 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -104,6 +104,12 @@ public: return m_selection; } + /** + * Function ClearSelection() + * Clears the current selection. + */ + void ClearSelection(); + /** * Function AddAction() * @@ -156,10 +162,13 @@ private: void toggleSelection( BOARD_ITEM* aItem ); /** - * Function clearSelection() - * Clears selections of currently selected items. + * Function isSelected() + * Tests if an item is currently selected. + * + * @param aItem is the item to be checked. + * @return True if the item is selected, false otherwise. */ - void clearSelection(); + bool isSelected( const BOARD_ITEM* aItem ) const; /** * Function selectable()