From 24a317ce28aa552e239d71590b2360279e900240 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 3 Dec 2013 17:11:22 +0100 Subject: [PATCH] The Selection Tool is always active. Removed entries for toolbar menu and hotkeys for the tool. --- common/tool/tool_dispatcher.cpp | 5 ----- common/tool/tool_manager.cpp | 5 +++-- pcbnew/menubar_pcbframe.cpp | 5 ----- pcbnew/pcbframe.cpp | 2 -- pcbnew/pcbnew_id.h | 1 - pcbnew/tools/common_actions.cpp | 3 +-- pcbnew/tools/common_actions.h | 6 +++--- pcbnew/tools/pcb_tools.cpp | 7 ++++++- pcbnew/tools/selection_tool.cpp | 27 +++++++++++++++------------ pcbnew/tools/selection_tool.h | 4 ++++ 10 files changed, 32 insertions(+), 33 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 35cefd81a2..6fb5d5f500 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -280,11 +280,6 @@ void TOOL_DISPATCHER::DispatchWxCommand( const wxCommandEvent& aEvent ) toolName = "pcbnew.InteractiveRouter"; activateTool = true; break; - - case ID_SELECTION_TOOL: - toolName = "pcbnew.InteractiveSelection"; - activateTool = true; - break; } // do nothing if the legacy view is active diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 9e56e61545..695203f447 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -97,7 +97,7 @@ struct TOOL_MANAGER::TOOL_STATE TOOL_MANAGER::TOOL_MANAGER() : - m_model( NULL ), m_view( NULL ) + m_model( NULL ), m_view( NULL ), m_viewControls( NULL ), m_editFrame( NULL ) { m_actionMgr = new ACTION_MANAGER( this ); } @@ -476,7 +476,8 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent ) if( m_view->IsDirty() ) { PCB_EDIT_FRAME* f = static_cast( GetEditFrame() ); - f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER. + if( f->IsGalCanvasActive() ) + f->GetGalCanvas()->Refresh(); // fixme: ugly hack, provide a method in TOOL_DISPATCHER. } return false; diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index 766b563833..9db3c5e309 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -310,11 +310,6 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() editMenu->AppendSeparator(); - AddMenuItem( editMenu, ID_SELECTION_TOOL, - _( "Select Tool" ), - _( "Interactive selection and drag&drop tool." ), - KiBitmap( tools_xpm ) ); - AddMenuItem( editMenu, ID_PNS_ROUTER_TOOL, _( "Interactive router" ), _( "Interactive router drag&drop tool." ), diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index b6a2a2c2d5..963581d197 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -121,8 +121,6 @@ BEGIN_EVENT_TABLE( PCB_EDIT_FRAME, PCB_BASE_FRAME ) // menu Config /* Tom's hacks start */ - EVT_MENU ( ID_SELECTION_TOOL, PCB_EDIT_FRAME::onGenericCommand ) - EVT_TOOL ( ID_SELECTION_TOOL, PCB_EDIT_FRAME::onGenericCommand ) EVT_MENU ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) EVT_TOOL ( ID_PNS_ROUTER_TOOL, PCB_EDIT_FRAME::onGenericCommand ) /* Tom's hacks end */ diff --git a/pcbnew/pcbnew_id.h b/pcbnew/pcbnew_id.h index 1a03a3764c..d5a836b93a 100644 --- a/pcbnew/pcbnew_id.h +++ b/pcbnew/pcbnew_id.h @@ -370,7 +370,6 @@ enum pcbnew_ids ID_FOOTPRINT_WIZARD_SELECT_WIZARD, ID_FOOTPRINT_WIZARD_EXPORT_TO_BOARD, - ID_SELECTION_TOOL, ID_PNS_ROUTER_TOOL }; diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 12aa52cb8f..7a7aef37b1 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -27,8 +27,7 @@ // Selection tool actions TOOL_ACTION COMMON_ACTIONS::selectionActivate( "pcbnew.InteractiveSelection", - AS_GLOBAL, 'S', - "Selection tool", "Allows to select items" ); + AS_GLOBAL, 0, "", "" ); // No description, it is not supposed to be shown anywhere // Edit tool actions TOOL_ACTION COMMON_ACTIONS::editActivate( "pcbnew.InteractiveEdit", diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 5e8bbd7efc..ae12439870 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -35,12 +35,12 @@ class COMMON_ACTIONS { public: - /// Activation of the move tool - static TOOL_ACTION editActivate; - /// Activation of the selection tool static TOOL_ACTION selectionActivate; + /// Activation of the edit tool + static TOOL_ACTION editActivate; + /// Rotation of selected objects static TOOL_ACTION rotate; diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index f6903f6420..db347e8c4b 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -48,7 +48,6 @@ void PCB_EDIT_FRAME::setupTools() // Register tool actions m_toolManager->RegisterAction( &COMMON_ACTIONS::editActivate ); - m_toolManager->RegisterAction( &COMMON_ACTIONS::selectionActivate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::rotate ); m_toolManager->RegisterAction( &COMMON_ACTIONS::flip ); m_toolManager->RegisterAction( &COMMON_ACTIONS::properties ); @@ -57,6 +56,12 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new SELECTION_TOOL ); m_toolManager->RegisterTool( new ROUTER_TOOL ); m_toolManager->RegisterTool( new EDIT_TOOL ); + + m_toolManager->SetEnvironment( NULL, m_galCanvas->GetView(), + m_galCanvas->GetViewControls(), this ); + + // Run the selection tool, it is supposed to be always active + m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); } diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index b175e85b09..918fb8f2aa 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -66,6 +66,8 @@ SELECTION_TOOL::~SELECTION_TOOL() void SELECTION_TOOL::Reset() { + clearSelection(); + // Reinsert the VIEW_GROUP, in case it was removed from the VIEW getView()->Remove( m_selection.group ); getView()->Add( m_selection.group ); @@ -77,12 +79,6 @@ void SELECTION_TOOL::Reset() int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) { - KIGFX::VIEW* view = getView(); - - assert( getModel( PCB_T ) != NULL ); - - view->Add( m_selection.group ); - // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { @@ -94,8 +90,8 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) { if( !m_selection.Empty() ) // Cancel event deselects items... clearSelection(); - else // ...unless there is nothing selected - break; // then exit the tool + + // This tool never exits } // single click? Select single object @@ -142,8 +138,8 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent ) } } - m_selection.group->Clear(); - view->Remove( m_selection.group ); + // This tool is supposed to be active forever + assert( false ); return 0; } @@ -188,6 +184,7 @@ 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( *it ); @@ -196,8 +193,7 @@ void SELECTION_TOOL::clearSelection() item->ClearSelected(); } - m_selection.group->Clear(); - m_selection.items.clear(); + m_selection.Clear(); // Do not show the context menu when there is nothing selected SetContextMenu( &m_menu, CMENU_OFF ); @@ -609,3 +605,10 @@ bool SELECTION_TOOL::containsSelected( const VECTOR2I& aPoint ) const return false; } + + +void SELECTION_TOOL::SELECTION::Clear() +{ + items.clear(); + group->Clear(); +} diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 6b3d62ba28..40806c3b94 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -78,6 +78,10 @@ public: { return items.size(); } + + /// Clears both the VIEW_GROUP and set of selected items. Please note that it does not + /// change properties of selected items (e.g. selection flag). + void Clear(); }; /// @copydoc TOOL_INTERACTIVE::Reset()