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 c0d9b9ab81
)
This commit is contained in:
parent
ae6989f3a1
commit
ad9916a93d
|
@ -337,6 +337,7 @@ void PCB_DRAW_PANEL_GAL::SyncLayersVisibility( const BOARD* aBoard )
|
||||||
m_view->SetLayerVisible( LAYER_VIAS_HOLES, true );
|
m_view->SetLayerVisible( LAYER_VIAS_HOLES, true );
|
||||||
m_view->SetLayerVisible( LAYER_GP_OVERLAY, true );
|
m_view->SetLayerVisible( LAYER_GP_OVERLAY, true );
|
||||||
m_view->SetLayerVisible( LAYER_SELECT_OVERLAY, true );
|
m_view->SetLayerVisible( LAYER_SELECT_OVERLAY, true );
|
||||||
|
m_view->SetLayerVisible( LAYER_RATSNEST, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1104,7 +1104,6 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aToolMgr->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
|
|
||||||
return true;
|
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" ) );
|
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->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->SetSnapping( false );
|
||||||
picker->Activate();
|
picker->Activate();
|
||||||
Wait();
|
Wait();
|
||||||
|
|
|
@ -44,6 +44,8 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||||
GRID_HELPER grid( frame() );
|
GRID_HELPER grid( frame() );
|
||||||
|
int finalize_state = WAIT_CANCEL;
|
||||||
|
|
||||||
setControls();
|
setControls();
|
||||||
|
|
||||||
while( OPT_TOOL_EVENT evt = Wait() )
|
while( OPT_TOOL_EVENT evt = Wait() )
|
||||||
|
@ -69,12 +71,16 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl;
|
std::cerr << "PICKER_TOOL click handler error: " << e.what() << std::endl;
|
||||||
|
finalize_state = EXCEPTION_CANCEL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !getNext )
|
if( !getNext )
|
||||||
|
{
|
||||||
|
finalize_state = CLICK_CANCEL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
setControls();
|
setControls();
|
||||||
}
|
}
|
||||||
|
@ -93,6 +99,7 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finalize_state = EVT_CANCEL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,6 +110,18 @@ int PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
m_toolMgr->PassEvent();
|
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();
|
reset();
|
||||||
controls->ForceCursorPosition( false );
|
controls->ForceCursorPosition( false );
|
||||||
getEditFrame<PCB_BASE_FRAME>()->SetNoToolSelected();
|
getEditFrame<PCB_BASE_FRAME>()->SetNoToolSelected();
|
||||||
|
@ -128,6 +147,7 @@ void PICKER_TOOL::reset()
|
||||||
m_picked = NULLOPT;
|
m_picked = NULLOPT;
|
||||||
m_clickHandler = NULLOPT;
|
m_clickHandler = NULLOPT;
|
||||||
m_cancelHandler = NULLOPT;
|
m_cancelHandler = NULLOPT;
|
||||||
|
m_finalizeHandler = NULLOPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,15 @@ public:
|
||||||
///> Event handler types.
|
///> Event handler types.
|
||||||
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
||||||
typedef std::function<void(void)> CANCEL_HANDLER;
|
typedef std::function<void(void)> CANCEL_HANDLER;
|
||||||
|
typedef std::function<void(const int&)> FINALIZE_HANDLER;
|
||||||
|
|
||||||
|
enum pickerEndState
|
||||||
|
{
|
||||||
|
WAIT_CANCEL,
|
||||||
|
CLICK_CANCEL,
|
||||||
|
EVT_CANCEL,
|
||||||
|
EXCEPTION_CANCEL
|
||||||
|
};
|
||||||
|
|
||||||
///> @copydoc TOOL_INTERACTIVE::Reset()
|
///> @copydoc TOOL_INTERACTIVE::Reset()
|
||||||
void Reset( RESET_REASON aReason ) override {}
|
void Reset( RESET_REASON aReason ) override {}
|
||||||
|
@ -98,6 +107,16 @@ public:
|
||||||
m_cancelHandler = aHandler;
|
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();
|
///> @copydoc TOOL_INTERACTIVE::setTransitions();
|
||||||
void setTransitions() override;
|
void setTransitions() override;
|
||||||
|
|
||||||
|
@ -118,6 +137,9 @@ private:
|
||||||
///> Picked point (if any).
|
///> Picked point (if any).
|
||||||
OPT<VECTOR2D> m_picked;
|
OPT<VECTOR2D> m_picked;
|
||||||
|
|
||||||
|
///> Optional finalize state handler.
|
||||||
|
OPT<FINALIZE_HANDLER> m_finalizeHandler;
|
||||||
|
|
||||||
///> Reinitializes tool to its initial state.
|
///> Reinitializes tool to its initial state.
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue