diff --git a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp index 7be28e9f8e..24d7dd848b 100644 --- a/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp +++ b/pcbnew/drc/drc_test_provider_diff_pair_coupling.cpp @@ -150,7 +150,7 @@ static int matchDpSuffix( const wxString& aNetName, wxString& aComplementNet, } -static int isNetADiffPair( BOARD* aBoard, int aNet, int& aNetP, int& aNetN ) +int DRC_ENGINE::IsNetADiffPair( BOARD* aBoard, int aNet, int& aNetP, int& aNetN ) { wxString refName = aBoard->FindNet( aNet )->GetNetname(); wxString dummy, coupledNetName; @@ -370,7 +370,7 @@ bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run() auto citem = static_cast( item ); int refNet = citem->GetNetCode(); - if( !isNetADiffPair( m_board, refNet, key.netP, key.netN ) ) // not our business + if( !DRC_ENGINE::IsNetADiffPair( m_board, refNet, key.netP, key.netN ) ) // not our business return true; drc_dbg(10, "eval dp %p\n", item ); diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 5ade2a29b6..3d2354835b 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -34,6 +34,7 @@ #include #include +#include bool exprFromTo( LIBEVAL::CONTEXT* aCtx, void* self ) @@ -59,20 +60,12 @@ bool exprFromTo( LIBEVAL::CONTEXT* aCtx, void* self ) return true; } - int r =0 ; - if( ftCache->IsOnFromToPath( static_cast( item ), argFrom->AsString(), argTo->AsString() ) ) { result->Set(1.0); - r = 1; - } - /*printf("isonfromto %p %s %s -> %d\n", static_cast( item ), - (const char *)argFrom->AsString(), - (const char *)argTo->AsString(), r );*/ - return true; } @@ -330,9 +323,29 @@ static void isBlindBuriedVia( LIBEVAL::CONTEXT* aCtx, void* self ) { result->Set ( 1.0 ); } - } + +static void isDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) +{ + PCB_EXPR_VAR_REF* vref = static_cast( self ); + BOARD_ITEM* item = vref ? vref->GetObject( aCtx ) : nullptr; + LIBEVAL::VALUE* result = aCtx->AllocValue(); + + result->Set( 0.0 ); + aCtx->Push( result ); + + if( item->IsConnected() ) + { + int net = static_cast( item )->GetNetCode(); + int net_p, net_n; + + if( DRC_ENGINE::IsNetADiffPair( item->GetBoard(), net, net_p, net_n ) ) + result->Set( 1.0 ); + } +} + + PCB_EXPR_BUILTIN_FUNCTIONS::PCB_EXPR_BUILTIN_FUNCTIONS() { RegisterAllFunctions(); @@ -350,7 +363,7 @@ void PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions() RegisterFunc( "isBlindBuriedVia()", isBlindBuriedVia ); RegisterFunc( "memberOf('x')", memberOf ); RegisterFunc( "fromTo('x','y')", exprFromTo ); - //RegisterFunc( "isDiffPair()", exprFromTo ); + RegisterFunc( "isDiffPair()", isDiffPair ); }