Hook up PNS via command to new rule system.

Fixes https://gitlab.com/kicad/code/kicad/issues/5951
This commit is contained in:
Jeff Young 2020-10-12 00:12:55 +01:00
parent 72f6127e53
commit b92cb5c930
1 changed files with 44 additions and 32 deletions

View File

@ -630,10 +630,9 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
return 0; return 0;
// First see if this is one of the switch layer commands // First see if this is one of the switch layer commands
LSEQ layers = LSET( board()->GetEnabledLayers() & LSET::AllCuMask() ).Seq(); LSEQ layers = LSET( board()->GetEnabledLayers() & LSET::AllCuMask() ).Seq();
int currentLayer = m_router->GetCurrentLayer(); PCB_LAYER_ID currentLayer = (PCB_LAYER_ID) m_router->GetCurrentLayer();
PCB_LAYER_ID targetLayer = UNDEFINED_LAYER;
PCB_LAYER_ID targetLayer = UNDEFINED_LAYER;
if( aEvent.IsAction( &PCB_ACTIONS::layerNext ) ) if( aEvent.IsAction( &PCB_ACTIONS::layerNext ) )
{ {
@ -702,8 +701,8 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
{ {
wxPoint dlgPosition = wxGetMousePosition(); wxPoint dlgPosition = wxGetMousePosition();
targetLayer = frame()->SelectLayer( targetLayer = frame()->SelectLayer( static_cast<PCB_LAYER_ID>( currentLayer ),
static_cast<PCB_LAYER_ID>( currentLayer ), LSET::AllNonCuMask(), dlgPosition ); LSET::AllNonCuMask(), dlgPosition );
// Reset the cursor to the position where the event occured // Reset the cursor to the position where the event occured
controls()->SetCursorPosition( aEvent.HasPosition() ? aEvent.Position() : dlgPosition ); controls()->SetCursorPosition( aEvent.HasPosition() ? aEvent.Position() : dlgPosition );
@ -755,40 +754,34 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
viaType = VIATYPE::THROUGH; viaType = VIATYPE::THROUGH;
} }
std::pair<PCB_LAYER_ID, PCB_LAYER_ID> layerPair;
switch( viaType ) switch( viaType )
{ {
case VIATYPE::THROUGH: case VIATYPE::THROUGH:
sizes.SetViaDiameter( bds.GetCurrentViaSize() ); if( targetLayer == UNDEFINED_LAYER )
sizes.SetViaDrill( bds.GetCurrentViaDrill() );
if( targetLayer != UNDEFINED_LAYER )
{
// go from the current layer to the chosen layer
sizes.AddLayerPair( currentLayer, targetLayer );
}
else
{ {
// use the default layer pair // use the default layer pair
sizes.AddLayerPair( pairTop, pairBottom ); currentLayer = pairTop;
targetLayer = pairBottom;
} }
break; break;
case VIATYPE::MICROVIA: case VIATYPE::MICROVIA:
sizes.SetViaDiameter( bds.GetCurrentMicroViaSize() );
sizes.SetViaDrill( bds.GetCurrentMicroViaDrill() );
wxASSERT_MSG( !selectLayer, wxASSERT_MSG( !selectLayer,
"Unexpected select layer for microvia (microvia layers are implicit)" ); "Unexpected select layer for microvia (microvia layers are implicit)" );
if( currentLayer == F_Cu || currentLayer == In1_Cu ) if( currentLayer == F_Cu || currentLayer == In1_Cu )
{ {
// front-side microvia // front-side microvia
sizes.AddLayerPair( F_Cu, In1_Cu ); currentLayer = F_Cu;
targetLayer = In1_Cu;
} }
else if( currentLayer == B_Cu || currentLayer == layerCount - 2 ) else if( currentLayer == B_Cu || currentLayer == layerCount - 2 )
{ {
// back-side microvia // back-side microvia
sizes.AddLayerPair( B_Cu, layerCount - 2 ); currentLayer = B_Cu,
targetLayer = (PCB_LAYER_ID) ( layerCount - 2 );
} }
else else
{ {
@ -798,27 +791,20 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
break; break;
case VIATYPE::BLIND_BURIED: case VIATYPE::BLIND_BURIED:
sizes.SetViaDiameter( bds.GetCurrentViaSize() ); if( targetLayer == UNDEFINED_LAYER )
sizes.SetViaDrill( bds.GetCurrentViaDrill() );
if( targetLayer != UNDEFINED_LAYER )
{
// go directly to the user specified layer
sizes.AddLayerPair( currentLayer, targetLayer );
}
else
{ {
if( currentLayer == pairTop || currentLayer == pairBottom ) if( currentLayer == pairTop || currentLayer == pairBottom )
{ {
// the current layer is on the defined layer pair, // the current layer is on the defined layer pair,
// swap to the other side // swap to the other side
sizes.AddLayerPair( pairTop, pairBottom ); currentLayer = pairTop;
targetLayer = pairBottom;
} }
else else
{ {
// the current layer is not part of the current layer pair, // the current layer is not part of the current layer pair,
// so fallback and swap to the top layer of the pair by default // so fallback and swap to the top layer of the pair by default
sizes.AddLayerPair( pairTop, currentLayer ); targetLayer = pairTop;
} }
} }
break; break;
@ -828,7 +814,33 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
break; break;
} }
if( bds.UseNetClassVia() || viaType == VIATYPE::MICROVIA )
{
class VIA dummyVia( board() );
dummyVia.SetViaType( viaType );
dummyVia.SetLayerPair( currentLayer, targetLayer );
if( !m_router->GetCurrentNets().empty() )
dummyVia.SetNetCode( m_router->GetCurrentNets()[0] );
DRC_CONSTRAINT constraint;
constraint = bds.m_DRCEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_VIA_DIAMETER,
&dummyVia, nullptr, currentLayer );
sizes.SetViaDiameter( constraint.m_Value.OptThenMin() );
constraint = bds.m_DRCEngine->EvalRulesForItems( DRC_CONSTRAINT_TYPE_HOLE_SIZE,
&dummyVia, nullptr, currentLayer );
sizes.SetViaDrill( constraint.m_Value.OptThenMin() );
}
else
{
sizes.SetViaDiameter( bds.GetCurrentViaSize() );
sizes.SetViaDrill( bds.GetCurrentViaDrill() );
}
sizes.SetViaType( viaType ); sizes.SetViaType( viaType );
sizes.AddLayerPair( currentLayer, targetLayer );
m_router->UpdateSizes( sizes ); m_router->UpdateSizes( sizes );
m_router->ToggleViaPlacement(); m_router->ToggleViaPlacement();