From ad9916a93d7e5a76435dbf7f9cad8ec34d17dd36 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 20 Nov 2018 20:10:46 -0800 Subject: [PATCH] ratsnest: Fix state issue switching in local tool The ratsnest layer needs to be always enabled in GAL rather than taken from the board settings. This also adds a finalize handler to the picker tool that allows a picker-caller to perform a specific action when the picker tool exits. In this case, we use it to clear the local ratsnest selections back to the default. Fixes: lp:1800301 * https://bugs.launchpad.net/kicad/+bug/1800301 (cherry picked from commit c0d9b9ab81f15d0610bd24829060632ff388205d) --- pcbnew/pcb_draw_panel_gal.cpp | 1 + pcbnew/tools/pcb_editor_control.cpp | 7 ++++++- pcbnew/tools/picker_tool.cpp | 20 ++++++++++++++++++++ pcbnew/tools/picker_tool.h | 22 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 9c4cda332e..8e44b5ff2a 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -337,6 +337,7 @@ void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard ) m_view->SetLayerVisible( LAYER_VIAS_HOLES, true ); m_view->SetLayerVisible( LAYER_GP_OVERLAY, true ); m_view->SetLayerVisible( LAYER_SELECT_OVERLAY, true ); + m_view->SetLayerVisible( LAYER_RATSNEST, true ); } diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index eb02ae84dc..fb52f61cb8 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -1104,7 +1104,6 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECT } } - aToolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); return true; } @@ -1120,6 +1119,12 @@ int PCB_EDITOR_CONTROL::ShowLocalRatsnest( const TOOL_EVENT& aEvent ) m_frame->SetToolID( ID_PCB_SHOW_1_RATSNEST_BUTT, wxCURSOR_PENCIL, _( "Pick Components for Local Ratsnest" ) ); picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, _1 ) ); + picker->SetFinalizeHandler( [ board ]( int aCondition ){ + auto vis = board->IsElementVisible( LAYER_RATSNEST ); + for( auto mod : board->Modules() ) + for( auto pad : mod->Pads() ) + pad->SetLocalRatsnestVisible( vis ); + } ); picker->SetSnapping( false ); picker->Activate(); Wait(); diff --git a/pcbnew/tools/picker_tool.cpp b/pcbnew/tools/picker_tool.cpp index d0f35e3436..e8d356fd26 100644 --- a/pcbnew/tools/picker_tool.cpp +++ b/pcbnew/tools/picker_tool.cpp @@ -44,6 +44,8 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); GRID_HELPER grid( frame() ); + int finalize_state = WAIT_CANCEL; + setControls(); while( OPT_TOOL_EVENT evt = Wait() ) @@ -69,12 +71,16 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) catch( std::exception& e ) { std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl; + finalize_state = EXCEPTION_CANCEL; break; } } if( !getNext ) + { + finalize_state = CLICK_CANCEL; break; + } else setControls(); } @@ -93,6 +99,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) } } + finalize_state = EVT_CANCEL; break; } @@ -103,6 +110,18 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) m_toolMgr->PassEvent(); } + if( m_finalizeHandler ) + { + try + { + (*m_finalizeHandler)( finalize_state ); + } + catch( std::exception& e ) + { + std::cerr << "PICKER_TOOL finalize handler error: " << e.what() << std::endl; + } + } + reset(); controls->ForceCursorPosition( false ); getEditFrame()->SetNoToolSelected(); @@ -128,6 +147,7 @@ void PICKER_TOOL::reset() m_picked = NULLOPT; m_clickHandler = NULLOPT; m_cancelHandler = NULLOPT; + m_finalizeHandler = NULLOPT; } diff --git a/pcbnew/tools/picker_tool.h b/pcbnew/tools/picker_tool.h index 8909062aa5..25b6ec8849 100644 --- a/pcbnew/tools/picker_tool.h +++ b/pcbnew/tools/picker_tool.h @@ -40,6 +40,15 @@ public: ///> Event handler types. typedef std::function CLICK_HANDLER; typedef std::function CANCEL_HANDLER; + typedef std::function FINALIZE_HANDLER; + + enum pickerEndState + { + WAIT_CANCEL, + CLICK_CANCEL, + EVT_CANCEL, + EXCEPTION_CANCEL + }; ///> @copydoc TOOL_INTERACTIVE::Reset() void Reset( RESET_REASON aReason ) override {} @@ -98,6 +107,16 @@ public: m_cancelHandler = aHandler; } + /** + * Function SetFinalizeHandler() + * Sets a handler for the finalize event. Takes the state of the exit from the Main loop + */ + inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) + { + assert( !m_finalizeHandler ); + m_finalizeHandler = aHandler; + } + ///> @copydoc TOOL_INTERACTIVE::setTransitions(); void setTransitions() override; @@ -118,6 +137,9 @@ private: ///> Picked point (if any). OPT m_picked; + ///> Optional finalize state handler. + OPT m_finalizeHandler; + ///> Reinitializes tool to its initial state. void reset();