From a2ffb456983a84bf200bcf67e5443d9c8391539d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 25 Mar 2021 00:34:57 +0000 Subject: [PATCH] Update diff pair rule syntax to be clearer. Fixes https://gitlab.com/kicad/code/kicad/issues/8010 --- pcbnew/dialogs/panel_setup_rules_help.md | 16 ++++++---------- pcbnew/drc/drc_engine.cpp | 4 ++-- pcbnew/pcb_expr_evaluator.cpp | 23 +---------------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/pcbnew/dialogs/panel_setup_rules_help.md b/pcbnew/dialogs/panel_setup_rules_help.md index a76b31addc..9b8f26482a 100644 --- a/pcbnew/dialogs/panel_setup_rules_help.md +++ b/pcbnew/dialogs/panel_setup_rules_help.md @@ -110,10 +110,6 @@ True if any part of `A` lies within the given zone's outline. A.isPlated() True if `A` has a hole which is plated. -

- - A.isDiffPair() -True if `A` has a net that is part of a differential pair.

A.inDiffPair('') @@ -122,7 +118,7 @@ True if `A` has net that is part of the specified differential pair. matches items in the `CLK_P` and `CLK_N` nets.

- A.isCoupledDiffPair() + AB.isCoupledDiffPair() True if `A` and `B` are members of the same diff pair.

@@ -191,12 +187,12 @@ For the latter use a `(layer "layer_name")` clause in the rule. (condition "A.Pad_Type == 'Through-hole'")) - # Specify a larger clearance around a particular diff-pair - (rule "dp clearance" - (constraint clearance (min "1.5mm")) - (condition "A.inDiffPair('CLK')")) + # Specify an optimal gap for a particular diff-pair + (rule "dp clock gap" + (constraint diff_pair_gap (opt "0.8mm")) + (condition "A.inDiffPair('CLK') && AB.isCoupledDiffPair()")) # Specify a larger clearance around any diff-pair (rule "dp clearance" (constraint clearance (min "1.5mm")) - (condition "A.isDiffPair() && !A.isCoupledDiffPair()")) + (condition "A.inDiffPair('*') && !AB.isCoupledDiffPair()")) diff --git a/pcbnew/drc/drc_engine.cpp b/pcbnew/drc/drc_engine.cpp index b2c60be9e0..3f7f8f6051 100644 --- a/pcbnew/drc/drc_engine.cpp +++ b/pcbnew/drc/drc_engine.cpp @@ -266,7 +266,7 @@ void DRC_ENGINE::loadImplicitRules() ncName ); netclassRule->m_Implicit = true; - expr = wxString::Format( "A.NetClass == '%s' && A.isDiffPair()", + expr = wxString::Format( "A.NetClass == '%s' && A.inDiffPair('*')", ncName ); netclassRule->m_Condition = new DRC_RULE_CONDITION( expr ); netclassItemSpecificRules.push_back( netclassRule ); @@ -295,7 +295,7 @@ void DRC_ENGINE::loadImplicitRules() ncName ); netclassRule->m_Implicit = true; - expr = wxString::Format( "A.NetClass == '%s' && A.isCoupledDiffPair()", + expr = wxString::Format( "A.NetClass == '%s' && AB.isCoupledDiffPair()", ncName ); netclassRule->m_Condition = new DRC_RULE_CONDITION( expr ); netclassItemSpecificRules.push_back( netclassRule ); diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 75e3691b1f..4b305025d5 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -708,26 +708,6 @@ static void isBlindBuriedVia( LIBEVAL::CONTEXT* aCtx, void* self ) } -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 && item->IsConnected() ) - { - NETINFO_ITEM* netinfo = static_cast( item )->GetNet(); - int dummy_p, dummy_n; - - if( netinfo && DRC_ENGINE::IsNetADiffPair( item->GetBoard(), netinfo, dummy_p, dummy_n ) ) - result->Set( 1.0 ); - } -} - - static void isCoupledDiffPair( LIBEVAL::CONTEXT* aCtx, void* self ) { PCB_EXPR_CONTEXT* context = static_cast( aCtx ); @@ -806,7 +786,6 @@ void PCB_EXPR_BUILTIN_FUNCTIONS::RegisterAllFunctions() RegisterFunc( "isBlindBuriedVia()", isBlindBuriedVia ); RegisterFunc( "memberOf('x')", memberOf ); RegisterFunc( "fromTo('x','y')", exprFromTo ); - RegisterFunc( "isDiffPair()", isDiffPair ); RegisterFunc( "isCoupledDiffPair()", isCoupledDiffPair ); RegisterFunc( "inDiffPair('x')", inDiffPair ); } @@ -964,7 +943,7 @@ std::unique_ptr PCB_EXPR_UCODE::CreateVarRef( const wxString& return nullptr; } - if( aVar == "A" ) + if( aVar == "A" || aVar == "AB" ) vref = std::make_unique( 0 ); else if( aVar == "B" ) vref = std::make_unique( 1 );