Fix state issue in router's switch layer handling.

Fixes https://gitlab.com/kicad/code/kicad/issues/7590
This commit is contained in:
Jeff Young 2021-04-01 18:09:22 +01:00
parent e1a3a8338c
commit f88d39b4f0
2 changed files with 28 additions and 14 deletions

View File

@ -161,7 +161,8 @@ static const TOOL_ACTION ACT_SwitchRounding( "pcbnew.InteractiveRouter.SwitchRou
ROUTER_TOOL::ROUTER_TOOL() : ROUTER_TOOL::ROUTER_TOOL() :
TOOL_BASE( "pcbnew.InteractiveRouter" ) TOOL_BASE( "pcbnew.InteractiveRouter" ),
m_lastTargetLayer( UNDEFINED_LAYER )
{ {
} }
@ -416,6 +417,8 @@ ROUTER_TOOL::~ROUTER_TOOL()
bool ROUTER_TOOL::Init() bool ROUTER_TOOL::Init()
{ {
m_lastTargetLayer = UNDEFINED_LAYER;
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>(); PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
wxASSERT( frame ); wxASSERT( frame );
@ -476,6 +479,8 @@ bool ROUTER_TOOL::Init()
void ROUTER_TOOL::Reset( RESET_REASON aReason ) void ROUTER_TOOL::Reset( RESET_REASON aReason )
{ {
m_lastTargetLayer = UNDEFINED_LAYER;
if( aReason == RUN ) if( aReason == RUN )
TOOL_BASE::Reset( aReason ); TOOL_BASE::Reset( aReason );
} }
@ -597,6 +602,7 @@ void ROUTER_TOOL::switchLayerOnViaPlacement()
newLayer = m_router->Sizes().GetLayerTop(); newLayer = m_router->Sizes().GetLayerTop();
m_router->SwitchLayer( *newLayer ); m_router->SwitchLayer( *newLayer );
m_lastTargetLayer = *newLayer;
frame()->SetActiveLayer( ToLAYER_ID( *newLayer ) ); frame()->SetActiveLayer( ToLAYER_ID( *newLayer ) );
} }
@ -719,7 +725,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
for( size_t i = 0; i < layers.size(); i++ ) for( size_t i = 0; i < layers.size(); i++ )
{ {
if( layers[i] == currentLayer ) if( layers[i] == m_lastTargetLayer )
{ {
idx = i; idx = i;
break; break;
@ -735,7 +741,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
for( size_t i = 0; i < layers.size(); i++ ) for( size_t i = 0; i < layers.size(); i++ )
{ {
if( layers[i] == currentLayer ) if( layers[i] == m_lastTargetLayer )
{ {
idx = i; idx = i;
break; break;
@ -748,19 +754,21 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
else else
{ {
targetLayer = getTargetLayerFromEvent( aEvent ); targetLayer = getTargetLayerFromEvent( aEvent );
if( targetLayer != UNDEFINED_LAYER )
{
if( targetLayer == currentLayer )
return 0;
}
} }
if( !aForceVia && m_router && m_router->SwitchLayer( targetLayer ) ) if( targetLayer != UNDEFINED_LAYER )
{ {
updateEndItem( aEvent ); m_lastTargetLayer = targetLayer;
m_router->Move( m_endSnapPoint, m_endItem ); // refresh
return 0; if( targetLayer == currentLayer )
return 0;
if( !aForceVia && m_router && m_router->SwitchLayer( targetLayer ) )
{
updateEndItem( aEvent );
m_router->Move( m_endSnapPoint, m_endItem ); // refresh
return 0;
}
} }
BOARD_DESIGN_SETTINGS& bds = board()->GetDesignSettings(); BOARD_DESIGN_SETTINGS& bds = board()->GetDesignSettings();
@ -967,7 +975,11 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
sizes.AddLayerPair( currentLayer, targetLayer ); sizes.AddLayerPair( currentLayer, targetLayer );
m_router->UpdateSizes( sizes ); m_router->UpdateSizes( sizes );
m_router->ToggleViaPlacement();
if( !m_router->IsPlacingVia() )
m_router->ToggleViaPlacement();
m_lastTargetLayer = targetLayer;
if( m_router->RoutingInProgress() ) if( m_router->RoutingInProgress() )
updateEndItem( aEvent ); updateEndItem( aEvent );

View File

@ -76,6 +76,8 @@ private:
private: private:
std::shared_ptr<ACTION_MENU> m_diffPairMenu; std::shared_ptr<ACTION_MENU> m_diffPairMenu;
std::shared_ptr<ACTION_MENU> m_trackViaMenu; std::shared_ptr<ACTION_MENU> m_trackViaMenu;
int m_lastTargetLayer;
}; };
#endif #endif