Commit 27c7eb5d authored by Maciej Suminski's avatar Maciej Suminski

The Selection Tool displays information about selected items. ClearSelection() made public.

parent 24a317ce
...@@ -66,7 +66,7 @@ SELECTION_TOOL::~SELECTION_TOOL() ...@@ -66,7 +66,7 @@ SELECTION_TOOL::~SELECTION_TOOL()
void SELECTION_TOOL::Reset() void SELECTION_TOOL::Reset()
{ {
clearSelection(); ClearSelection();
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW // Reinsert the VIEW_GROUP, in case it was removed from the VIEW
getView()->Remove( m_selection.group ); getView()->Remove( m_selection.group );
...@@ -89,7 +89,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -89,7 +89,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
if( evt->IsCancel() ) if( evt->IsCancel() )
{ {
if( !m_selection.Empty() ) // Cancel event deselects items... if( !m_selection.Empty() ) // Cancel event deselects items...
clearSelection(); ClearSelection();
// This tool never exits // This tool never exits
} }
...@@ -98,7 +98,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -98,7 +98,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else if( evt->IsClick( BUT_LEFT ) ) else if( evt->IsClick( BUT_LEFT ) )
{ {
if( !m_additive && m_selection.Size() > 1 ) if( !m_additive && m_selection.Size() > 1 )
clearSelection(); ClearSelection();
selectSingle( evt->Position() ); selectSingle( evt->Position() );
} }
...@@ -132,7 +132,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -132,7 +132,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else else
{ {
// No -> clear the selection list // No -> clear the selection list
clearSelection(); ClearSelection();
} }
} }
} }
...@@ -145,6 +145,28 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) ...@@ -145,6 +145,28 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
} }
void SELECTION_TOOL::ClearSelection()
{
KIGFX::VIEW_GROUP::const_iter it, it_end;
// Restore the initial properties
for( it = m_selection.group->Begin(), it_end = m_selection.group->End(); it != it_end; ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( *it );
item->ViewSetVisible( true );
item->ClearSelected();
}
m_selection.Clear();
getEditFrame<PCB_EDIT_FRAME>()->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 ) void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction )
{ {
assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER
...@@ -155,48 +177,25 @@ void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction ) ...@@ -155,48 +177,25 @@ void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction )
void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem ) void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem )
{ {
if( m_selection.items.find( aItem ) != m_selection.items.end() ) if( isSelected( aItem ) )
{ {
deselectItem( aItem ); deselectItem( aItem );
// If there is nothing selected, disable the context menu
if( m_selection.Empty() )
SetContextMenu( &m_menu, CMENU_OFF );
} }
else else
{ {
if( !m_additive ) if( !m_additive )
clearSelection(); ClearSelection();
// Prevent selection of invisible or inactive items // Prevent selection of invisible or inactive items
if( selectable( aItem ) ) if( selectable( aItem ) )
{
selectItem( aItem ); selectItem( aItem );
// Now the context menu should be enabled
SetContextMenu( &m_menu, CMENU_BUTTON );
}
} }
} }
void SELECTION_TOOL::clearSelection() bool SELECTION_TOOL::isSelected( const BOARD_ITEM* aItem ) const
{ {
KIGFX::VIEW_GROUP::const_iter it, it_end; return ( m_selection.items.find( const_cast<BOARD_ITEM*>( aItem ) ) != m_selection.items.end() );
// Restore the initial properties
for( it = m_selection.group->Begin(), it_end = m_selection.group->End(); it != it_end; ++it )
{
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( *it );
item->ViewSetVisible( true );
item->ClearSelected();
}
m_selection.Clear();
// Do not show the context menu when there is nothing selected
SetContextMenu( &m_menu, CMENU_OFF );
} }
...@@ -214,7 +213,7 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere ) ...@@ -214,7 +213,7 @@ void SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere )
{ {
case 0: case 0:
if( !m_additive ) if( !m_additive )
clearSelection(); ClearSelection();
break; break;
...@@ -308,7 +307,7 @@ bool SELECTION_TOOL::selectMultiple() ...@@ -308,7 +307,7 @@ bool SELECTION_TOOL::selectMultiple()
if( evt->IsDrag( BUT_LEFT ) ) if( evt->IsDrag( BUT_LEFT ) )
{ {
if( !m_additive ) if( !m_additive )
clearSelection(); ClearSelection();
// Start drawing a selection box // Start drawing a selection box
m_selArea->SetOrigin( evt->DragOrigin() ); m_selArea->SetOrigin( evt->DragOrigin() );
...@@ -338,11 +337,10 @@ bool SELECTION_TOOL::selectMultiple() ...@@ -338,11 +337,10 @@ bool SELECTION_TOOL::selectMultiple()
selectItem( item ); selectItem( item );
} }
// Now the context menu should be enabled // Do not display information about selected item,as there is more than one
if( !m_selection.Empty() ) getEditFrame<PCB_EDIT_FRAME>()->SetCurItem( NULL );
SetContextMenu( &m_menu, CMENU_BUTTON );
break; break; // Stop waiting for events
} }
} }
...@@ -413,9 +411,6 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector ) ...@@ -413,9 +411,6 @@ BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector )
// Removes possible brighten mark // Removes possible brighten mark
getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY ); getView()->MarkTargetDirty( KIGFX::TARGET_OVERLAY );
// Restore the original menu
SetContextMenu( &m_menu, CMENU_BUTTON );
return current; return current;
} }
...@@ -542,6 +537,16 @@ void SELECTION_TOOL::selectItem( BOARD_ITEM* aItem ) ...@@ -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 // Add items to the VIEW_GROUP, so they will be displayed on the overlay
selectBase( aItem ); selectBase( aItem );
m_selection.items.insert( 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<PCB_EDIT_FRAME>()->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 ) ...@@ -584,6 +589,13 @@ void SELECTION_TOOL::deselectItem( BOARD_ITEM* aItem )
deselectBase( aItem ); deselectBase( aItem );
m_selection.items.erase( 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<PCB_EDIT_FRAME>()->SetCurItem( NULL );
}
} }
......
...@@ -104,6 +104,12 @@ public: ...@@ -104,6 +104,12 @@ public:
return m_selection; return m_selection;
} }
/**
* Function ClearSelection()
* Clears the current selection.
*/
void ClearSelection();
/** /**
* Function AddAction() * Function AddAction()
* *
...@@ -156,10 +162,13 @@ private: ...@@ -156,10 +162,13 @@ private:
void toggleSelection( BOARD_ITEM* aItem ); void toggleSelection( BOARD_ITEM* aItem );
/** /**
* Function clearSelection() * Function isSelected()
* Clears selections of currently selected items. * 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() * Function selectable()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment