From fe7e72538e6a6b28d434990a2a9e2233f25d0745 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 13 Feb 2022 18:15:27 +0000 Subject: [PATCH] Don't force user to be overly pedantic when writing diffpair rules. --- pcbnew/pcb_expr_evaluator.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 02dced4d42..0c2469a5fe 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -795,17 +795,15 @@ static void isCoupledDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) result->SetDeferredEval( [a, b]() -> double { - if( a && b ) - { - NETINFO_ITEM* netinfo = a->GetNet(); - wxString coupledNet, dummy; + NETINFO_ITEM* netinfo = a->GetNet(); + wxString coupledNet; + wxString dummy; - if( netinfo - && DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) - && b->GetNetname() == coupledNet ) - { - return 1.0; - } + if( netinfo + && DRC_ENGINE::MatchDpSuffix( netinfo->GetNetname(), coupledNet, dummy ) + && ( !b || b->GetNetname() == coupledNet ) ) + { + return 1.0; } return 0.0; @@ -815,7 +813,7 @@ static void isCoupledDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) static void inDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) { - LIBEVAL::VALUE* arg = aCtx->Pop(); + LIBEVAL::VALUE* argv = aCtx->Pop(); PCB_EXPR_VAR_REF* vref = static_cast( self ); BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr; LIBEVAL::VALUE* result = aCtx->AllocValue(); @@ -823,7 +821,7 @@ static void inDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) result->Set( 0.0 ); aCtx->Push( result ); - if( !arg ) + if( !argv ) { if( aCtx->HasErrorCallback() ) { @@ -838,21 +836,24 @@ static void inDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) return; result->SetDeferredEval( - [item, arg]() -> double + [item, argv]() -> double { if( item && item->IsConnected() ) { NETINFO_ITEM* netinfo = static_cast( item )->GetNet(); wxString refName = netinfo->GetNetname(); + wxString arg = argv->AsString(); wxString baseName, coupledNet; int polarity = DRC_ENGINE::MatchDpSuffix( refName, coupledNet, baseName ); - if( polarity != 0 - && item->GetBoard()->FindNet( coupledNet ) - && baseName.Matches( arg->AsString() ) ) + if( polarity != 0 && item->GetBoard()->FindNet( coupledNet ) ) { - return 1.0; + if( baseName.Matches( arg ) ) + return 1.0; + + if( baseName.EndsWith( "_" ) && baseName.BeforeLast( '_' ).Matches( arg ) ) + return 1.0; } }