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
This commit is contained in:
parent
daf4985a60
commit
c0d9b9ab81
|
@ -334,6 +334,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,9 +1104,6 @@ static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto frame = static_cast<PCB_BASE_FRAME*>(aToolMgr->GetEditFrame());
|
|
||||||
static_cast<PCB_DRAW_PANEL_GAL*>( frame->GetGalCanvas() )->RedrawRatsnest();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1122,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();
|
||||||
|
|
|
@ -70,6 +70,7 @@ 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;
|
||||||
|
|
||||||
assert( !m_picking );
|
assert( !m_picking );
|
||||||
m_picking = true;
|
m_picking = true;
|
||||||
|
@ -98,23 +99,40 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
|
else if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
|
||||||
|
{
|
||||||
|
finalize_state = EVT_CANCEL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
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();
|
||||||
|
@ -138,6 +156,7 @@ void PICKER_TOOL::reset()
|
||||||
|
|
||||||
m_picking = false;
|
m_picking = false;
|
||||||
m_clickHandler = NULLOPT;
|
m_clickHandler = NULLOPT;
|
||||||
|
m_finalizeHandler = NULLOPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,19 @@ public:
|
||||||
PICKER_TOOL();
|
PICKER_TOOL();
|
||||||
~PICKER_TOOL() {}
|
~PICKER_TOOL() {}
|
||||||
|
|
||||||
|
enum pickerEndState
|
||||||
|
{
|
||||||
|
WAIT_CANCEL,
|
||||||
|
CLICK_CANCEL,
|
||||||
|
EVT_CANCEL,
|
||||||
|
EXCEPTION_CANCEL
|
||||||
|
};
|
||||||
|
|
||||||
///> Mouse event click handler type.
|
///> Mouse event click handler type.
|
||||||
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
|
||||||
|
|
||||||
|
typedef std::function<void(const int&)> FINALIZE_HANDLER;
|
||||||
|
|
||||||
/// @copydoc TOOL_INTERACTIVE::Init()
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
||||||
bool Init() override;
|
bool Init() override;
|
||||||
|
|
||||||
|
@ -100,6 +110,16 @@ public:
|
||||||
m_clickHandler = aHandler;
|
m_clickHandler = 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;
|
||||||
|
|
||||||
|
@ -116,6 +136,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;
|
||||||
|
|
||||||
///> Activity status.
|
///> Activity status.
|
||||||
bool m_picking;
|
bool m_picking;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue