2020-09-26 20:43:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-11 21:16:52 +00:00
|
|
|
* Copyright (C) 2004-2022 KiCad Developers.
|
2020-09-26 20:43:51 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
#include <drc/drc_engine.h>
|
|
|
|
#include <drc/drc_item.h>
|
|
|
|
#include <drc/drc_rule.h>
|
|
|
|
#include <drc/drc_test_provider.h>
|
|
|
|
#include <drc/drc_length_report.h>
|
2020-10-02 18:58:12 +00:00
|
|
|
#include <drc/drc_rtree.h>
|
|
|
|
|
|
|
|
#include <geometry/shape_segment.h>
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
#include <connectivity/connectivity_data.h>
|
|
|
|
#include <connectivity/from_to_cache.h>
|
|
|
|
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <view/view_overlay.h>
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Differential pair gap/coupling test.
|
|
|
|
Errors generated:
|
|
|
|
- DRCE_DIFF_PAIR_GAP_OUT_OF_RANGE
|
|
|
|
- DRCE_DIFF_PAIR_UNCOUPLED_LENGTH_TOO_LONG
|
|
|
|
- DRCE_TOO_MANY_VIAS
|
2020-10-25 09:02:07 +00:00
|
|
|
Todo:
|
2020-09-27 15:50:57 +00:00
|
|
|
- arc support.
|
2020-12-11 18:29:52 +00:00
|
|
|
- improve recognition of coupled segments (now anything that's parallel is considered
|
|
|
|
coupled, causing DRC errors on meanders)
|
2020-09-26 20:43:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
class DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING : public DRC_TEST_PROVIDER
|
|
|
|
{
|
|
|
|
public:
|
2020-10-25 09:02:07 +00:00
|
|
|
DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING () :
|
|
|
|
m_board( nullptr )
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-10-25 09:02:07 +00:00
|
|
|
virtual ~DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING()
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Run() override;
|
|
|
|
|
2020-10-25 09:02:07 +00:00
|
|
|
virtual const wxString GetName() const override
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "diff_pair_coupling" );
|
2020-09-26 20:43:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual const wxString GetDescription() const override
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
return wxT( "Tests differential pair coupling" );
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BOARD* m_board;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static bool commonParallelProjection( SEG p, SEG n, SEG &pClip, SEG& nClip )
|
|
|
|
{
|
|
|
|
SEG n_proj_p( p.LineProject( n.A ), p.LineProject( n.B ) );
|
|
|
|
|
|
|
|
int64_t t_a = 0;
|
|
|
|
int64_t t_b = p.TCoef( p.B );
|
|
|
|
|
|
|
|
int64_t tproj_a = p.TCoef( n_proj_p.A );
|
|
|
|
int64_t tproj_b = p.TCoef( n_proj_p.B );
|
|
|
|
|
|
|
|
if( t_b < t_a )
|
|
|
|
std::swap( t_b, t_a );
|
|
|
|
|
|
|
|
if( tproj_b < tproj_a )
|
|
|
|
std::swap( tproj_b, tproj_a );
|
|
|
|
|
|
|
|
if( t_b <= tproj_a )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( t_a >= tproj_b )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int64_t t[4] = { 0, p.TCoef( p.B ), p.TCoef( n_proj_p.A ), p.TCoef( n_proj_p.B ) };
|
|
|
|
std::vector<int64_t> tv( t, t + 4 );
|
|
|
|
std::sort( tv.begin(), tv.end() ); // fixme: awful and disgusting way of finding 2 midpoints
|
|
|
|
|
|
|
|
int64_t pLenSq = p.SquaredLength();
|
|
|
|
|
|
|
|
VECTOR2I dp = p.B - p.A;
|
|
|
|
pClip.A.x = p.A.x + rescale( (int64_t)dp.x, tv[1], pLenSq );
|
|
|
|
pClip.A.y = p.A.y + rescale( (int64_t)dp.y, tv[1], pLenSq );
|
|
|
|
|
|
|
|
pClip.B.x = p.A.x + rescale( (int64_t)dp.x, tv[2], pLenSq );
|
|
|
|
pClip.B.y = p.A.y + rescale( (int64_t)dp.y, tv[2], pLenSq );
|
|
|
|
|
|
|
|
nClip.A = n.LineProject( pClip.A );
|
|
|
|
nClip.B = n.LineProject( pClip.B );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct DIFF_PAIR_KEY
|
2020-12-09 23:12:44 +00:00
|
|
|
{
|
|
|
|
bool operator<( const DIFF_PAIR_KEY& b ) const
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
2020-12-09 23:12:44 +00:00
|
|
|
if( netP < b.netP )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( netP > b.netP )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else // netP == b.netP
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
2020-12-09 23:12:44 +00:00
|
|
|
if( netN < b.netN )
|
2020-09-26 20:43:51 +00:00
|
|
|
return true;
|
2020-12-09 23:12:44 +00:00
|
|
|
else if( netN > b.netN )
|
2020-09-26 20:43:51 +00:00
|
|
|
return false;
|
2020-12-09 23:12:44 +00:00
|
|
|
else
|
|
|
|
return parentRule < b.parentRule;
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
2020-12-09 23:12:44 +00:00
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-12-09 23:12:44 +00:00
|
|
|
int netP, netN;
|
|
|
|
DRC_RULE* parentRule;
|
|
|
|
};
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-12-09 23:12:44 +00:00
|
|
|
struct DIFF_PAIR_COUPLED_SEGMENTS
|
|
|
|
{
|
|
|
|
SEG coupledN;
|
|
|
|
SEG coupledP;
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* parentN;
|
|
|
|
PCB_TRACK* parentP;
|
2020-12-09 23:12:44 +00:00
|
|
|
int computedGap;
|
|
|
|
PCB_LAYER_ID layer;
|
|
|
|
bool couplingOK;
|
|
|
|
|
|
|
|
DIFF_PAIR_COUPLED_SEGMENTS() :
|
|
|
|
parentN( nullptr ),
|
2020-12-11 18:29:52 +00:00
|
|
|
parentP( nullptr ),
|
|
|
|
computedGap( 0 ),
|
|
|
|
layer( UNDEFINED_LAYER ),
|
|
|
|
couplingOK( false )
|
2020-12-09 23:12:44 +00:00
|
|
|
{}
|
|
|
|
};
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-12-09 23:12:44 +00:00
|
|
|
struct DIFF_PAIR_ITEMS
|
|
|
|
{
|
|
|
|
std::set<BOARD_CONNECTED_ITEM*> itemsP, itemsN;
|
|
|
|
std::vector<DIFF_PAIR_COUPLED_SEGMENTS> coupled;
|
|
|
|
int totalCoupled;
|
|
|
|
int totalLengthN;
|
|
|
|
int totalLengthP;
|
|
|
|
};
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-10-02 18:58:12 +00:00
|
|
|
static void extractDiffPairCoupledItems( DIFF_PAIR_ITEMS& aDp, DRC_RTREE& aTree )
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
|
|
|
for( BOARD_CONNECTED_ITEM* itemP : aDp.itemsP )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* sp = dyn_cast<PCB_TRACK*>( itemP );
|
2020-10-06 09:24:19 +00:00
|
|
|
OPT<DIFF_PAIR_COUPLED_SEGMENTS> bestCoupled;
|
|
|
|
int bestGap = std::numeric_limits<int>::max();
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
if( !sp )
|
2020-09-26 20:43:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for ( BOARD_CONNECTED_ITEM* itemN : aDp.itemsN )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* sn = dyn_cast<PCB_TRACK*> ( itemN );
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
if( !sn )
|
2020-09-26 20:43:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( sn->GetLayerSet() & sp->GetLayerSet() ).none() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SEG ssp ( sp->GetStart(), sp->GetEnd() );
|
|
|
|
SEG ssn ( sn->GetStart(), sn->GetEnd() );
|
|
|
|
|
2022-04-11 23:55:54 +00:00
|
|
|
// Segments that are ~ 1 IU in length per side are approximately parallel (tolerance is 1 IU)
|
|
|
|
// with everything and their parallel projection is < 1 IU, leading to bad distance calculations
|
|
|
|
if( ssp.SquaredLength() > 2 && ssn.SquaredLength() > 2 && ssp.ApproxParallel(ssn) )
|
2020-09-26 20:43:51 +00:00
|
|
|
{
|
|
|
|
DIFF_PAIR_COUPLED_SEGMENTS cpair;
|
|
|
|
bool coupled = commonParallelProjection( ssp, ssn, cpair.coupledP, cpair.coupledN );
|
|
|
|
|
|
|
|
if( coupled )
|
|
|
|
{
|
2020-10-06 09:24:19 +00:00
|
|
|
cpair.parentP = sp;
|
|
|
|
cpair.parentN = sn;
|
|
|
|
cpair.layer = sp->GetLayer();
|
2020-10-02 18:58:12 +00:00
|
|
|
|
2020-10-06 09:24:19 +00:00
|
|
|
int gap = (cpair.coupledP.A - cpair.coupledN.A).EuclideanNorm();
|
|
|
|
if( gap < bestGap )
|
2020-10-02 18:58:12 +00:00
|
|
|
{
|
2020-10-06 09:24:19 +00:00
|
|
|
bestGap = gap;
|
|
|
|
bestCoupled = cpair;
|
2020-10-02 18:58:12 +00:00
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
|
|
|
|
if( bestCoupled )
|
|
|
|
{
|
2020-10-27 10:47:44 +00:00
|
|
|
auto excludeSelf =
|
|
|
|
[&] ( BOARD_ITEM *aItem )
|
|
|
|
{
|
|
|
|
if( aItem == bestCoupled->parentN || aItem == bestCoupled->parentP )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
if( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
auto bci = static_cast<BOARD_CONNECTED_ITEM*>( aItem );
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
if( bci->GetNetCode() == bestCoupled->parentN->GetNetCode()
|
|
|
|
|| bci->GetNetCode() == bestCoupled->parentP->GetNetCode() )
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
return true;
|
|
|
|
};
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
SHAPE_SEGMENT checkSegStart( bestCoupled->coupledP.A, bestCoupled->coupledN.A );
|
|
|
|
SHAPE_SEGMENT checkSegEnd( bestCoupled->coupledP.B, bestCoupled->coupledN.B );
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// check if there's anything in between the segments suspected to be coupled. If
|
2020-10-27 10:47:44 +00:00
|
|
|
// there's nothing, assume they are really coupled.
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
if( !aTree.CheckColliding( &checkSegStart, sp->GetLayer(), 0, excludeSelf )
|
|
|
|
&& !aTree.CheckColliding( &checkSegEnd, sp->GetLayer(), 0, excludeSelf ) )
|
|
|
|
{
|
|
|
|
aDp.coupled.push_back( *bestCoupled );
|
|
|
|
}
|
2020-10-06 09:24:19 +00:00
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-09-26 20:43:51 +00:00
|
|
|
bool test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run()
|
|
|
|
{
|
|
|
|
m_board = m_drcEngine->GetBoard();
|
|
|
|
|
2020-10-25 09:02:07 +00:00
|
|
|
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
std::map<DIFF_PAIR_KEY, DIFF_PAIR_ITEMS> dpRuleMatches;
|
|
|
|
|
|
|
|
auto evaluateDpConstraints =
|
|
|
|
[&]( BOARD_ITEM *item ) -> bool
|
|
|
|
{
|
|
|
|
DIFF_PAIR_KEY key;
|
2020-10-10 15:10:04 +00:00
|
|
|
BOARD_CONNECTED_ITEM* citem = static_cast<BOARD_CONNECTED_ITEM*>( item );
|
|
|
|
NETINFO_ITEM* refNet = citem->GetNet();
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-10-10 15:10:04 +00:00
|
|
|
if( refNet && DRC_ENGINE::IsNetADiffPair( m_board, refNet, key.netP, key.netN ) )
|
|
|
|
{
|
2022-03-11 21:16:52 +00:00
|
|
|
drc_dbg( 10, wxT( "eval dp %p\n" ), item );
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2021-01-01 22:29:15 +00:00
|
|
|
const DRC_CONSTRAINT_T constraintsToCheck[] = {
|
2020-11-02 16:20:00 +00:00
|
|
|
DIFF_PAIR_GAP_CONSTRAINT,
|
|
|
|
DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT
|
2020-10-10 15:10:04 +00:00
|
|
|
};
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-10-10 15:10:04 +00:00
|
|
|
for( int i = 0; i < 2; i++ )
|
|
|
|
{
|
2021-02-08 14:53:49 +00:00
|
|
|
auto constraint = m_drcEngine->EvalRules( constraintsToCheck[ i ], item,
|
|
|
|
nullptr, item->GetLayer() );
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
if( constraint.IsNull() || constraint.GetSeverity() == RPT_SEVERITY_IGNORE )
|
2020-10-10 15:10:04 +00:00
|
|
|
continue;
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
drc_dbg( 10, wxT( "cns %d item %p\n" ), constraintsToCheck[i], item );
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-10-10 15:10:04 +00:00
|
|
|
key.parentRule = constraint.GetParentRule();
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
if( refNet->GetNetCode() == key.netN )
|
2020-10-10 15:10:04 +00:00
|
|
|
dpRuleMatches[key].itemsN.insert( citem );
|
|
|
|
else
|
|
|
|
dpRuleMatches[key].itemsP.insert( citem );
|
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
m_board->GetConnectivity()->GetFromToCache()->Rebuild( m_board );
|
|
|
|
|
2021-09-05 15:06:12 +00:00
|
|
|
forEachGeometryItem( { PCB_TRACE_T, PCB_VIA_T, PCB_ARC_T }, LSET::AllCuMask(),
|
|
|
|
evaluateDpConstraints );
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
drc_dbg( 10, wxT( "dp rule matches %d\n" ), (int) dpRuleMatches.size() );
|
2020-10-06 09:24:19 +00:00
|
|
|
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-10-02 18:58:12 +00:00
|
|
|
DRC_RTREE copperTree;
|
|
|
|
|
|
|
|
auto addToTree =
|
|
|
|
[&copperTree]( BOARD_ITEM *item ) -> bool
|
|
|
|
{
|
2021-06-02 13:00:11 +00:00
|
|
|
for( PCB_LAYER_ID layer : item->GetLayerSet().Seq() )
|
|
|
|
{
|
|
|
|
if( IsCopperLayer( layer ) )
|
|
|
|
copperTree.Insert( item, layer );
|
|
|
|
}
|
|
|
|
|
2020-10-02 18:58:12 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-03-09 00:47:37 +00:00
|
|
|
forEachGeometryItem( { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T },
|
2020-10-03 20:40:36 +00:00
|
|
|
LSET::AllCuMask(), addToTree );
|
2020-10-02 18:58:12 +00:00
|
|
|
|
|
|
|
|
2020-09-26 20:43:51 +00:00
|
|
|
reportAux( wxString::Format( _("DPs evaluated:") ) );
|
|
|
|
|
|
|
|
for( auto& it : dpRuleMatches )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM *niP = m_board->GetNetInfo().GetNetItem( it.first.netP );
|
|
|
|
NETINFO_ITEM *niN = m_board->GetNetInfo().GetNetItem( it.first.netN );
|
|
|
|
|
|
|
|
assert( niP );
|
|
|
|
assert( niN );
|
|
|
|
|
|
|
|
wxString nameP = niP->GetNetname();
|
|
|
|
wxString nameN = niN->GetNetname();
|
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
reportAux( wxString::Format( wxT( "Rule '%s', DP: (+) %s - (-) %s" ),
|
|
|
|
it.first.parentRule->m_Name,
|
|
|
|
nameP,
|
|
|
|
nameN ) );
|
2020-09-26 20:43:51 +00:00
|
|
|
|
2020-10-02 18:58:12 +00:00
|
|
|
extractDiffPairCoupledItems( it.second, copperTree );
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
it.second.totalCoupled = 0;
|
|
|
|
it.second.totalLengthN = 0;
|
|
|
|
it.second.totalLengthP = 0;
|
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
drc_dbg(10, wxT( " coupled prims : %d\n" ), (int) it.second.coupled.size() );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2020-12-11 18:29:52 +00:00
|
|
|
OPT<DRC_CONSTRAINT> gapConstraint =
|
|
|
|
it.first.parentRule->FindConstraint( DIFF_PAIR_GAP_CONSTRAINT );
|
|
|
|
OPT<DRC_CONSTRAINT> maxUncoupledConstraint =
|
|
|
|
it.first.parentRule->FindConstraint( DIFF_PAIR_MAX_UNCOUPLED_CONSTRAINT );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( BOARD_CONNECTED_ITEM* item : it.second.itemsN )
|
2020-09-27 15:50:57 +00:00
|
|
|
{
|
|
|
|
// fixme: include vias
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
|
2020-09-27 15:50:57 +00:00
|
|
|
it.second.totalLengthN += track->GetLength();
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( BOARD_CONNECTED_ITEM* item : it.second.itemsP )
|
2020-09-27 15:50:57 +00:00
|
|
|
{
|
|
|
|
// fixme: include vias
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_TRACK* track = dyn_cast<PCB_TRACK*>( item ) )
|
2020-09-27 15:50:57 +00:00
|
|
|
it.second.totalLengthP += track->GetLength();
|
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
|
|
|
|
for( auto& cpair : it.second.coupled )
|
|
|
|
{
|
|
|
|
int length = cpair.coupledN.Length();
|
|
|
|
int gap = cpair.coupledN.Distance( cpair.coupledP );
|
|
|
|
|
|
|
|
gap -= cpair.parentN->GetWidth() / 2;
|
|
|
|
gap -= cpair.parentP->GetWidth() / 2;
|
|
|
|
|
2020-09-27 15:50:57 +00:00
|
|
|
cpair.computedGap = gap;
|
|
|
|
|
2020-10-06 09:24:19 +00:00
|
|
|
auto overlay = m_drcEngine->GetDebugOverlay();
|
|
|
|
|
|
|
|
if( overlay )
|
|
|
|
{
|
|
|
|
overlay->SetIsFill(false);
|
|
|
|
overlay->SetIsStroke(true);
|
|
|
|
overlay->SetStrokeColor( RED );
|
|
|
|
overlay->SetLineWidth( 100000 );
|
|
|
|
overlay->Line( cpair.coupledP );
|
|
|
|
overlay->SetStrokeColor( BLUE );
|
|
|
|
overlay->Line( cpair.coupledN );
|
|
|
|
}
|
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
drc_dbg( 10, wxT( " len %d gap %d l %d\n" ),
|
|
|
|
length,
|
|
|
|
gap,
|
2020-12-11 18:29:52 +00:00
|
|
|
cpair.parentP->GetLayer() );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
if( gapConstraint )
|
|
|
|
{
|
|
|
|
auto val = gapConstraint->GetValue();
|
|
|
|
bool insideRange = true;
|
2021-05-31 14:12:50 +00:00
|
|
|
|
|
|
|
if( val.HasMin() && gap < val.Min() )
|
2020-09-27 15:50:57 +00:00
|
|
|
insideRange = false;
|
2021-05-31 14:12:50 +00:00
|
|
|
|
|
|
|
if( val.HasMax() && gap > val.Max() )
|
2020-09-27 15:50:57 +00:00
|
|
|
insideRange = false;
|
|
|
|
|
|
|
|
cpair.couplingOK = insideRange;
|
|
|
|
}
|
2021-05-31 14:12:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cpair.couplingOK = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cpair.couplingOK )
|
|
|
|
it.second.totalCoupled += length;
|
2020-09-27 15:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int totalLen = std::max( it.second.totalLengthN, it.second.totalLengthP );
|
2022-03-11 21:16:52 +00:00
|
|
|
reportAux( wxString::Format( wxT( " - coupled length: %s, total length: %s" ),
|
2020-12-11 18:29:52 +00:00
|
|
|
MessageTextFromValue( userUnits(), it.second.totalCoupled ),
|
|
|
|
MessageTextFromValue( userUnits(), totalLen ) ) );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
int totalUncoupled = totalLen - it.second.totalCoupled;
|
|
|
|
|
|
|
|
bool uncoupledViolation = false;
|
|
|
|
|
|
|
|
if( maxUncoupledConstraint )
|
|
|
|
{
|
|
|
|
auto val = maxUncoupledConstraint->GetValue();
|
|
|
|
|
|
|
|
if ( val.HasMax() && totalUncoupled > val.Max() )
|
|
|
|
{
|
2020-10-27 10:47:44 +00:00
|
|
|
auto drce = DRC_ITEM::Create( DRCE_DIFF_PAIR_UNCOUPLED_LENGTH_TOO_LONG );
|
|
|
|
|
|
|
|
m_msg = wxString::Format( _( "(%s maximum uncoupled length: %s; actual: %s)" ),
|
|
|
|
maxUncoupledConstraint->GetParentRule()->m_Name,
|
|
|
|
MessageTextFromValue( userUnits(), val.Max() ),
|
|
|
|
MessageTextFromValue( userUnits(), totalUncoupled ) );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
drce->SetErrorMessage( drce->GetErrorText() + wxS( " " ) + m_msg );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2022-04-08 10:37:27 +00:00
|
|
|
auto pit = it.second.itemsP.begin();
|
|
|
|
auto nit = it.second.itemsN.begin();
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2022-04-08 10:37:27 +00:00
|
|
|
drce->AddItem( *pit );
|
|
|
|
drce->AddItem( *nit );
|
|
|
|
|
|
|
|
for( pit++; pit != it.second.itemsP.end(); pit++ )
|
|
|
|
drce->AddItem( *pit );
|
|
|
|
|
|
|
|
for( nit++; nit != it.second.itemsN.end(); nit++ )
|
|
|
|
drce->AddItem( *nit );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
uncoupledViolation = true;
|
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
drce->SetViolatingRule( maxUncoupledConstraint->GetParentRule() );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drce, ( *it.second.itemsP.begin() )->GetPosition(),
|
|
|
|
( *it.second.itemsP.begin() )->GetLayer() );
|
2020-09-27 15:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
if ( gapConstraint && ( uncoupledViolation || !maxUncoupledConstraint ) )
|
2020-09-27 15:50:57 +00:00
|
|
|
{
|
|
|
|
for( auto& cpair : it.second.coupled )
|
|
|
|
{
|
|
|
|
if( !cpair.couplingOK )
|
|
|
|
{
|
|
|
|
auto val = gapConstraint->GetValue();
|
2020-10-27 10:47:44 +00:00
|
|
|
auto drcItem = DRC_ITEM::Create( DRCE_DIFF_PAIR_GAP_OUT_OF_RANGE );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2022-03-11 21:16:52 +00:00
|
|
|
m_msg = drcItem->GetErrorText() + wxT( " (" ) +
|
|
|
|
gapConstraint->GetParentRule()->m_Name + wxS( " " );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
if( val.HasMin() )
|
2020-10-27 10:47:44 +00:00
|
|
|
m_msg += wxString::Format( _( "minimum gap: %s; " ),
|
2020-12-11 18:29:52 +00:00
|
|
|
MessageTextFromValue( userUnits(), val.Min() ) );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
if( val.HasMax() )
|
2020-10-27 10:47:44 +00:00
|
|
|
m_msg += wxString::Format( _( "maximum gap: %s; " ),
|
2020-12-11 18:29:52 +00:00
|
|
|
MessageTextFromValue( userUnits(), val.Max() ) );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
m_msg += wxString::Format( _( "actual: %s)" ),
|
2020-10-02 20:51:24 +00:00
|
|
|
MessageTextFromValue( userUnits(), cpair.computedGap ) );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
2020-10-27 10:47:44 +00:00
|
|
|
drcItem->SetErrorMessage( m_msg );
|
2020-09-27 15:50:57 +00:00
|
|
|
|
|
|
|
drcItem->AddItem( cpair.parentP );
|
|
|
|
drcItem->AddItem( cpair.parentN );
|
|
|
|
|
|
|
|
drcItem->SetViolatingRule( gapConstraint->GetParentRule() );
|
|
|
|
|
2021-12-26 13:47:00 +00:00
|
|
|
reportViolation( drcItem, cpair.parentP->GetPosition(),
|
|
|
|
cpair.parentP->GetLayer() );
|
2020-09-27 15:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-26 20:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reportRuleStatistics();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace detail
|
|
|
|
{
|
|
|
|
static DRC_REGISTER_TEST_PROVIDER<test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING> dummy;
|
2020-10-02 20:51:24 +00:00
|
|
|
}
|