Implement isCoupledDiffPair() DRC rule function.

Fixes https://gitlab.com/kicad/code/kicad/issues/7975
This commit is contained in:
Jeff Young 2021-03-20 23:03:34 +00:00
parent 44e2151ade
commit fe196771d8
3 changed files with 32 additions and 4 deletions

View File

@ -119,7 +119,12 @@ True if `A` has a net that is part of a differential pair.
A.inDiffPair('<net_name>')
True if `A` has net that is part of the specified differential pair.
`<net_name>` is the base name of the differential pair. For example, `inDiffPair('CLK')`
matches items in the `CLK_P` and `CLK_N` nets.<br>
matches items in the `CLK_P` and `CLK_N` nets.
<br><br>
A.isCoupledDiffPair()
True if `A` and `B` are members of the same diff pair.
<br><br>
A.memberOf('<group_name>')
True if `A` is a member of the given group. Includes nested membership.

View File

@ -295,9 +295,7 @@ void DRC_ENGINE::loadImplicitRules()
ncName );
netclassRule->m_Implicit = true;
expr = wxString::Format( "A.NetClass == '%s' && A.isDiffPair() "
"&& B.NetClass == '%s' && B.isDiffPair()",
ncName,
expr = wxString::Format( "A.NetClass == '%s' && A.isCoupledDiffPair()",
ncName );
netclassRule->m_Condition = new DRC_RULE_CONDITION( expr );
netclassItemSpecificRules.push_back( netclassRule );

View File

@ -728,6 +728,30 @@ static void isDiffPair( LIBEVAL::CONTEXT* aCtx, void* self )
}
static void isCoupledDiffPair( LIBEVAL::CONTEXT* aCtx, void* self )
{
PCB_EXPR_CONTEXT* context = static_cast<PCB_EXPR_CONTEXT*>( aCtx );
BOARD_CONNECTED_ITEM* a = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 0 ) );
BOARD_CONNECTED_ITEM* b = dynamic_cast<BOARD_CONNECTED_ITEM*>( context->GetItem( 1 ) );
LIBEVAL::VALUE* result = aCtx->AllocValue();
result->Set( 0.0 );
aCtx->Push( result );
if( a && b )
{
NETINFO_ITEM* netinfo = a->GetNet();
wxString coupledNet, dummy;
if( netinfo && DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) != 0 )
{
if( b->GetNetname() == coupledNet )
result->Set( 1.0 );
}
}
}
static void inDiffPair( LIBEVAL::CONTEXT* aCtx, void* self )
{
LIBEVAL::VALUE* arg = aCtx->Pop();
@ -783,6 +807,7 @@ void PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions()
RegisterFunc( "memberOf('x')", memberOf );
RegisterFunc( "fromTo('x','y')", exprFromTo );
RegisterFunc( "isDiffPair()", isDiffPair );
RegisterFunc( "isCoupledDiffPair()", isCoupledDiffPair );
RegisterFunc( "inDiffPair('x')", inDiffPair );
}