Improve algorithm for calculating net length; use it for netinfo message panel
Fixes https://gitlab.com/kicad/code/kicad/-/issues/4258
This commit is contained in:
parent
6b24abac8f
commit
80728f8d78
|
@ -1676,21 +1676,41 @@ std::tuple<int, double, double> BOARD::GetTrackLength( const TRACK& aTrack ) con
|
||||||
if( TRACK* track = dyn_cast<TRACK*>( item ) )
|
if( TRACK* track = dyn_cast<TRACK*>( item ) )
|
||||||
{
|
{
|
||||||
bool inPad = false;
|
bool inPad = false;
|
||||||
|
double segLen = track->GetLength();
|
||||||
|
|
||||||
for( auto pad_it : connectivity->GetConnectedPads( item ) )
|
for( auto pad_it : connectivity->GetConnectedPads( item ) )
|
||||||
{
|
{
|
||||||
PAD* pad = static_cast<PAD*>( pad_it );
|
PAD* pad = static_cast<PAD*>( pad_it );
|
||||||
|
|
||||||
if( pad->HitTest( track->GetStart(), track->GetWidth() / 2 )
|
bool hitStart = pad->HitTest( track->GetStart(), track->GetWidth() / 2 );
|
||||||
&& pad->HitTest( track->GetEnd(), track->GetWidth() / 2 ) )
|
bool hitEnd = pad->HitTest( track->GetEnd(), track->GetWidth() / 2 );
|
||||||
|
|
||||||
|
if( hitStart && hitEnd )
|
||||||
{
|
{
|
||||||
inPad = true;
|
inPad = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if( hitStart || hitEnd )
|
||||||
|
{
|
||||||
|
VECTOR2I loc;
|
||||||
|
SEG trackSeg( track->GetStart(), track->GetEnd() );
|
||||||
|
|
||||||
|
// We may not collide even if we passed the bounding-box hit test
|
||||||
|
if( pad->GetEffectivePolygon()->Collide( trackSeg, 0, nullptr, &loc ) )
|
||||||
|
{
|
||||||
|
// Part 1: length of the seg to the intersection with the pad poly
|
||||||
|
segLen = hitStart ? ( VECTOR2I( track->GetEnd() ) - loc ).EuclideanNorm() :
|
||||||
|
( VECTOR2I( track->GetStart() ) - loc ).EuclideanNorm();
|
||||||
|
|
||||||
|
// Part 2: length from the interesection to the pad anchor
|
||||||
|
segLen += ( loc - pad->GetPosition() ).EuclideanNorm();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !inPad )
|
if( !inPad )
|
||||||
length += track->GetLength();
|
length += segLen;
|
||||||
}
|
}
|
||||||
else if( PAD* pad = dyn_cast<PAD*>( item ) )
|
else if( PAD* pad = dyn_cast<PAD*>( item ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,18 +82,14 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
|
||||||
if( board )
|
if( board )
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
double lengthNet = 0.0; // This is the length of tracks on pcb
|
TRACK* startTrack = nullptr;
|
||||||
double lengthPadToDie = 0.0; // this is the length of internal ICs connections
|
|
||||||
|
|
||||||
for( FOOTPRINT* footprint : board->Footprints() )
|
for( FOOTPRINT* footprint : board->Footprints() )
|
||||||
{
|
{
|
||||||
for( PAD* pad : footprint->Pads() )
|
for( PAD* pad : footprint->Pads() )
|
||||||
{
|
{
|
||||||
if( pad->GetNetCode() == GetNetCode() )
|
if( pad->GetNetCode() == GetNetCode() )
|
||||||
{
|
|
||||||
count++;
|
count++;
|
||||||
lengthPadToDie += pad->GetPadToDieLength();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,22 +98,25 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
for( TRACK* track : board->Tracks() )
|
for( TRACK* track : board->Tracks() )
|
||||||
|
{
|
||||||
|
if( track->GetNetCode() == GetNetCode() )
|
||||||
{
|
{
|
||||||
if( track->Type() == PCB_VIA_T )
|
if( track->Type() == PCB_VIA_T )
|
||||||
{
|
|
||||||
if( track->GetNetCode() == GetNetCode() )
|
|
||||||
count++;
|
count++;
|
||||||
}
|
else if( !startTrack )
|
||||||
|
startTrack = track;
|
||||||
if( track->Type() == PCB_TRACE_T )
|
|
||||||
{
|
|
||||||
if( track->GetNetCode() == GetNetCode() )
|
|
||||||
lengthNet += track->GetLength();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aList.emplace_back( _( "Vias" ), wxString::Format( "%d", count ) );
|
aList.emplace_back( _( "Vias" ), wxString::Format( "%d", count ) );
|
||||||
|
|
||||||
|
if( startTrack )
|
||||||
|
{
|
||||||
|
double lengthNet = 0.0; // This is the length of tracks on pcb
|
||||||
|
double lengthPadToDie = 0.0; // this is the length of internal ICs connections
|
||||||
|
|
||||||
|
std::tie( count, lengthNet, lengthPadToDie ) = board->GetTrackLength( *startTrack );
|
||||||
|
|
||||||
// Displays the full net length (tracks on pcb + internal ICs connections ):
|
// Displays the full net length (tracks on pcb + internal ICs connections ):
|
||||||
msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet + lengthPadToDie );
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthNet + lengthPadToDie );
|
||||||
aList.emplace_back( _( "Net Length" ), msg );
|
aList.emplace_back( _( "Net Length" ), msg );
|
||||||
|
@ -130,4 +129,5 @@ void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANE
|
||||||
msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
|
msg = MessageTextFromValue( aFrame->GetUserUnits(), lengthPadToDie );
|
||||||
aList.emplace_back( _( "In Package" ), msg );
|
aList.emplace_back( _( "In Package" ), msg );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue