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();