Commit a6dac245 authored by Maciej Suminski's avatar Maciej Suminski

Removed TOOL_ACTIONs: selectionSingle, selectionClear. SELECTION_TOOL methods...

Removed TOOL_ACTIONs: selectionSingle, selectionClear. SELECTION_TOOL methods are called directly instead.
parent dfc052d5
......@@ -40,6 +40,7 @@
#include <tool/context_menu.h>
#include <tools/common_actions.h>
#include <tools/selection_tool.h>
#include <ratsnest_data.h>
......@@ -636,7 +637,7 @@ int ROUTER_TOOL::Main( TOOL_EVENT& aEvent )
BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings();
// Deselect all items
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
getEditFrame<PCB_EDIT_FRAME>()->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL,
_( "Interactive Router" ) );
......
......@@ -31,11 +31,6 @@
TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
TOOL_ACTION COMMON_ACTIONS::selectionSingle( "pcbnew.InteractiveSelection.Single",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
TOOL_ACTION COMMON_ACTIONS::selectionClear( "pcbnew.InteractiveSelection.Clear",
AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere
// Edit tool actions
TOOL_ACTION COMMON_ACTIONS::editActivate( "pcbnew.InteractiveEdit",
......
......@@ -37,12 +37,6 @@ public:
/// Activation of the selection tool
static TOOL_ACTION selectionActivate;
/// Select a single item under the cursor position
static TOOL_ACTION selectionSingle;
/// Clears the current selection
static TOOL_ACTION selectionClear;
// Edit Tool
/// Activation of the edit tool
static TOOL_ACTION editActivate;
......
......@@ -38,6 +38,7 @@
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <router/direction.h>
#include "selection_tool.h"
#include <class_board.h>
#include <class_drawsegment.h>
......@@ -102,7 +103,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
......@@ -288,7 +289,7 @@ int DRAWING_TOOL::PlaceText( TOOL_EVENT& aEvent )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
m_controls->SetAutoPan( true );
......@@ -394,7 +395,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
......@@ -590,7 +591,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
m_view->Add( &preview );
preview.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->SetSnapping( true );
m_controls->SetAutoPan( true );
......@@ -665,7 +666,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
m_controls->SetAutoPan( true );
......@@ -776,7 +777,7 @@ int DRAWING_TOOL::drawSegment( int aShape, bool aContinous )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
......@@ -952,7 +953,7 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
KIGFX::VIEW_GROUP preview( m_view );
m_view->Add( &preview );
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_toolMgr->GetTool<SELECTION_TOOL>()->ClearSelection();
m_controls->ShowCursor( true );
m_controls->SetSnapping( true );
......
......@@ -48,7 +48,7 @@ EDIT_TOOL::EDIT_TOOL() :
bool EDIT_TOOL::Init()
{
// Find the selection tool, so they can cooperate
m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
m_selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
if( !m_selectionTool )
{
......@@ -198,7 +198,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent )
}
if( unselect )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
ratsnest->ClearSimple();
......@@ -252,7 +252,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
std::vector<PICKED_ITEMS_LIST*>& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList;
// Some of properties dialogs alter pointers, so we should deselect them
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
STATUS_FLAGS flags = item->GetFlags();
item->ClearFlags();
......@@ -279,7 +279,7 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent )
}
if( unselect )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
setTransitions();
......@@ -332,7 +332,7 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
if( unselect )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
setTransitions();
......@@ -386,7 +386,7 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
if( unselect )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate );
setTransitions();
......@@ -411,7 +411,7 @@ int EDIT_TOOL::Remove( TOOL_EVENT& aEvent )
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
// As we are about to remove items, they have to be removed from the selection first
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear );
m_selectionTool->ClearSelection();
// Save them
for( unsigned int i = 0; i < selectedItems.GetCount(); ++i )
......@@ -529,7 +529,7 @@ wxPoint EDIT_TOOL::getModificationPoint( const SELECTION_TOOL::SELECTION& aSelec
bool EDIT_TOOL::makeSelection( const SELECTION_TOOL::SELECTION& aSelection )
{
if( aSelection.Empty() ) // Try to find an item that could be modified
m_toolMgr->RunAction( COMMON_ACTIONS::selectionSingle );
m_selectionTool->SelectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
return !aSelection.Empty();
}
......
......@@ -77,7 +77,7 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
m_selection.clear();
else
// Restore previous properties of selected items and remove them from containers
clearSelection();
ClearSelection();
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
getView()->Remove( m_selection.group );
......@@ -97,16 +97,9 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
// become the new selection (discarding previously selected items)
m_additive = evt->Modifier( MD_SHIFT );
if( evt->IsAction( &COMMON_ACTIONS::selectionSingle ) )
if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO )
{
// GetMousePosition() is used, as it is independent of snapping settings
selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
}
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO ||
evt->IsAction( &COMMON_ACTIONS::selectionClear ) )
{
clearSelection();
ClearSelection();
}
// single click? Select single object
......@@ -119,9 +112,9 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else
{
if( !m_additive )
clearSelection();
ClearSelection();
selectSingle( evt->Position() );
SelectSingle( evt->Position() );
}
}
......@@ -129,7 +122,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else if( evt->IsClick( BUT_RIGHT ) )
{
if( m_selection.Empty() )
selectSingle( evt->Position() );
SelectSingle( evt->Position() );
if( !m_selection.Empty() )
SetContextMenu( &m_menu, CMENU_NOW );
......@@ -139,7 +132,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else if( evt->IsDblClick( BUT_LEFT ) )
{
if( m_selection.Empty() )
selectSingle( evt->Position() );
SelectSingle( evt->Position() );
m_toolMgr->RunAction( COMMON_ACTIONS::properties );
}
......@@ -154,7 +147,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else if( m_selection.Empty() )
{
// There is nothing selected, so try to select something
if( !selectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) )
if( !SelectSingle( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) )
{
// If nothings has been selected or user wants to select more
// draw the selection box
......@@ -177,7 +170,7 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
else
{
// No -> clear the selection list
clearSelection();
ClearSelection();
}
}
}
......@@ -190,58 +183,21 @@ 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( aItem->IsSelected() )
{
deselect( aItem );
// Inform other potentially interested tools
TOOL_EVENT deselectEvent( DeselectedEvent );
m_toolMgr->ProcessEvent( deselectEvent );
}
else
{
if( !m_additive )
clearSelection();
// Prevent selection of invisible or inactive items
if( selectable( aItem ) )
{
select( aItem );
// Inform other potentially interested tools
TOOL_EVENT selectEvent( SelectedEvent );
m_toolMgr->ProcessEvent( selectEvent );
}
}
}
bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation )
bool SELECTION_TOOL::SelectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation )
{
BOARD* pcb = getModel<BOARD>();
BOARD_ITEM* item;
GENERAL_COLLECTORS_GUIDE guide = getEditFrame<PCB_EDIT_FRAME>()->GetCollectorsGuide();
GENERAL_COLLECTOR collector;
const KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_LINE_T, EOT }; // preferred types
collector.Collect( pcb, GENERAL_COLLECTOR::AllBoardItems,
collector.Collect( getModel<BOARD>(), GENERAL_COLLECTOR::AllBoardItems,
wxPoint( aWhere.x, aWhere.y ), guide );
switch( collector.GetCount() )
{
case 0:
if( !m_additive )
clearSelection();
ClearSelection();
return false;
......@@ -293,6 +249,70 @@ bool SELECTION_TOOL::selectSingle( const VECTOR2I& aWhere, bool aAllowDisambigua
}
void SELECTION_TOOL::ClearSelection()
{
if( m_selection.Empty() )
return;
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 );
// Inform other potentially interested tools
TOOL_EVENT clearEvent( ClearedEvent );
m_toolMgr->ProcessEvent( clearEvent );
}
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( aItem->IsSelected() )
{
deselect( aItem );
// Inform other potentially interested tools
TOOL_EVENT deselectEvent( DeselectedEvent );
m_toolMgr->ProcessEvent( deselectEvent );
}
else
{
if( !m_additive )
ClearSelection();
// Prevent selection of invisible or inactive items
if( selectable( aItem ) )
{
select( aItem );
// Inform other potentially interested tools
TOOL_EVENT selectEvent( SelectedEvent );
m_toolMgr->ProcessEvent( selectEvent );
}
}
}
bool SELECTION_TOOL::selectMultiple()
{
bool cancelled = false; // Was the tool cancelled while it was running?
......@@ -313,7 +333,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() );
......@@ -368,34 +388,6 @@ bool SELECTION_TOOL::selectMultiple()
}
void SELECTION_TOOL::clearSelection()
{
if( m_selection.Empty() )
return;
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 );
// Inform other potentially interested tools
TOOL_EVENT clearEvent( ClearedEvent );
m_toolMgr->ProcessEvent( clearEvent );
}
BOARD_ITEM* SELECTION_TOOL::disambiguationMenu( GENERAL_COLLECTOR* aCollector )
{
BOARD_ITEM* current = NULL;
......
......@@ -113,6 +113,24 @@ public:
return m_selection;
}
/**
* Function SelectSingle()
* Selects an item pointed by the parameter aWhere. If there is more than one item at that
* place, there is a menu displayed that allows to choose the item.
*
* @param aWhere is the place where the item should be selected.
* @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then
* a menu is shown, otherise function finishes without selecting anything.
* @return True if an item was selected, false otherwise.
*/
bool SelectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation = true );
/**
* Function ClearSelection()
* Clears the current selection.
*/
void ClearSelection();
/**
* Function AddMenuItem()
*
......@@ -131,32 +149,14 @@ public:
const TOOL_EVENT ClearedEvent;
private:
/**
* Function selectSingle()
* Selects an item pointed by the parameter aWhere. If there is more than one item at that
* place, there is a menu displayed that allows to choose the item.
*
* @param aWhere is the place where the item should be selected.
* @param aAllowDisambiguation decides what to do in case of disambiguation. If true, then
* a menu is shown, otherise function finishes without selecting anything.
* @return True if an item was selected, false otherwise.
*/
bool selectSingle( const VECTOR2I& aWhere, bool aAllowDisambiguation = true );
/**
* Function selectMultiple()
* Handles drawing a selection box that allows to select many items at the same time.
*
* @return true if the function was cancelled (ie. CancelEvent was received).
* @return true if the function was cancelled (i.e. CancelEvent was received).
*/
bool selectMultiple();
/**
* Function ClearSelection()
* Clears the current selection.
*/
void clearSelection();
/**
* Function disambiguationMenu()
* Handles the menu that allows to select one of many items in case there is more than one
......
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