diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index c69bb4ff62..8fd5b36c25 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -642,6 +642,7 @@ void TOOL_MANAGER::finishTool( TOOL_STATE* aState ) } aState->theTool->SetTransitions(); + m_viewControls->Reset(); } diff --git a/common/view/view_controls.cpp b/common/view/view_controls.cpp index e0dbdfc666..850cf0ba1b 100644 --- a/common/view/view_controls.cpp +++ b/common/view/view_controls.cpp @@ -35,3 +35,13 @@ void VIEW_CONTROLS::ShowCursor( bool aEnabled ) m_view->GetGAL()->SetCursorEnabled( aEnabled ); } + +void VIEW_CONTROLS::Reset() +{ + SetSnapping( false ); + SetAutoPan( false ); + ForceCursorPosition( false ); + ShowCursor( false ); + CaptureCursor( false ); + SetGrabMouse( false ); +} diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 65f16d4ab3..3484a1530c 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -316,12 +316,12 @@ void WX_VIEW_CONTROLS::onScroll( wxScrollWinEvent& aEvent ) void WX_VIEW_CONTROLS::SetGrabMouse( bool aEnabled ) { - VIEW_CONTROLS::SetGrabMouse( aEnabled ); - - if( aEnabled ) + if( aEnabled && !m_grabMouse ) m_parentPanel->CaptureMouse(); - else + else if( !aEnabled && m_grabMouse ) m_parentPanel->ReleaseMouse(); + + VIEW_CONTROLS::SetGrabMouse( aEnabled ); } diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 60b4f6d2f9..ddff54e477 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -200,6 +200,12 @@ public: */ virtual void CenterOnCursor() const = 0; + /** + * Function Reset() + * Restores the default VIEW_CONTROLS settings. + */ + virtual void Reset(); + protected: /// Pointer to controlled VIEW. VIEW* m_view; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index d721de8d6e..382fb70666 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -665,9 +665,6 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) handleCommonEvents( *evt ); } - // Restore the default settings - m_ctls->SetAutoPan( false ); - m_ctls->ShowCursor( false ); frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); // Store routing settings till the next invocation @@ -799,7 +796,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) } ctls->SetAutoPan( false ); - ctls->ForceCursorPosition( false ); ctls->ShowCursor( false ); return 0; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 467772752c..4acd7cbe20 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -158,8 +158,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY; controls->ShowCursor( true ); - //controls->SetSnapping( true ); - controls->ForceCursorPosition( false ); // cumulative translation wxPoint totalMovement( 0, 0 ); @@ -340,9 +338,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) ratsnest->Recalculate(); controls->ShowCursor( false ); - //controls->SetSnapping( false ); controls->SetAutoPan( false ); - controls->ForceCursorPosition( false ); return 0; } diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 9772a34dcd..9ff589b938 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -638,12 +638,15 @@ static bool setDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, int PCB_EDITOR_CONTROL::DrillOrigin( const TOOL_EVENT& aEvent ) { + Activate(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust zero" ) ); picker->SetClickHandler( boost::bind( setDrillOrigin, getView(), m_frame, m_placeOrigin, _1 ) ); picker->Activate(); + Wait(); return 0; } @@ -691,12 +694,16 @@ int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent ) int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent ) { + Activate(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_PENCIL, _( "Highlight net" ) ); picker->SetClickHandler( boost::bind( highlightNet, m_toolMgr, _1 ) ); + picker->SetSnapping( false ); picker->Activate(); + Wait(); return 0; } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 89eb99912b..9545533e08 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -639,6 +639,8 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) } else { + Activate(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); @@ -646,6 +648,7 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) ); picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, m_gridOrigin, _1 ) ); picker->Activate(); + Wait(); } return 0; @@ -718,8 +721,8 @@ static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) if( IsOK( aToolMgr->GetEditFrame(), _( "Are you sure you want to delete item?" ) ) ) aToolMgr->RunAction( COMMON_ACTIONS::remove, true ); - - aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + else + aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); return true; } @@ -727,6 +730,8 @@ static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition ) int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) { + Activate(); + PICKER_TOOL* picker = m_toolMgr->GetTool(); assert( picker ); @@ -735,6 +740,7 @@ int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent ) picker->SetSnapping( false ); picker->SetClickHandler( boost::bind( deleteItem, m_toolMgr, _1 ) ); picker->Activate(); + Wait(); return 0; } diff --git a/pcbnew/tools/picker_tool.cpp b/pcbnew/tools/picker_tool.cpp index 541e9f30f2..574f317aef 100644 --- a/pcbnew/tools/picker_tool.cpp +++ b/pcbnew/tools/picker_tool.cpp @@ -42,11 +42,9 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) assert( !m_picking ); m_picking = true; - m_picked = boost::optional(); + m_picked = boost::none; - controls->ShowCursor( m_cursorVisible ); - controls->SetSnapping( m_cursorSnapping ); - controls->SetAutoPan( m_autoPanning ); + setControls(); while( OPT_TOOL_EVENT evt = Wait() ) { @@ -60,6 +58,8 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) if( !getNext ) break; + else + setControls(); } else if( evt->IsCancel() || evt->IsActivate() ) @@ -67,10 +67,6 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } reset(); - - controls->SetAutoPan( false ); - controls->SetSnapping( false ); - controls->ShowCursor( false ); getEditFrame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); return 0; @@ -90,5 +86,15 @@ void PICKER_TOOL::reset() m_autoPanning = true; m_picking = false; - m_clickHandler = boost::optional(); + m_clickHandler = boost::none; +} + + +void PICKER_TOOL::setControls() +{ + KIGFX::VIEW_CONTROLS* controls = getViewControls(); + + controls->ShowCursor( m_cursorVisible ); + controls->SetSnapping( m_cursorSnapping ); + controls->SetAutoPan( m_autoPanning ); } diff --git a/pcbnew/tools/picker_tool.h b/pcbnew/tools/picker_tool.h index a4df24f476..ea4f5cf700 100644 --- a/pcbnew/tools/picker_tool.h +++ b/pcbnew/tools/picker_tool.h @@ -112,6 +112,9 @@ private: ///> Reinitializes tool to its initial state. void reset(); + + ///> Applies the requested VIEW_CONTROLS settings. + void setControls(); }; #endif /* PICKER_TOOL_H */ diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 9e8451adb6..99b6915db8 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -352,7 +352,6 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) controls->ShowCursor( false ); controls->SetAutoPan( false ); controls->SetSnapping( false ); - controls->ForceCursorPosition( false ); } return 0;