kicad/pcbnew/netinfo_item.cpp

165 lines
5.3 KiB
C++
Raw Normal View History

/**
* @brief NETINFO_ITEM class, to handle info on nets: netnames, net constraints
*/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
2021-07-19 23:56:05 +00:00
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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 2
* 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, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
2018-01-29 15:39:40 +00:00
#include <pcb_base_frame.h>
#include <string_utils.h>
#include <widgets/msgpanel.h>
#include <base_units.h>
#include <board.h>
#include <board_design_settings.h>
#include <connectivity/connectivity_data.h>
#include <footprint.h>
2021-06-11 21:07:02 +00:00
#include <pcb_track.h>
#include <pad.h>
NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCode ) :
2020-12-08 12:28:26 +00:00
BOARD_ITEM( aParent, PCB_NETINFO_T ),
m_netCode( aNetCode ),
m_netname( aNetName ),
2020-12-08 17:28:03 +00:00
m_shortNetname( m_netname.AfterLast( '/' ) ),
m_displayNetname( UnescapeString( m_shortNetname ) ),
2020-12-08 17:28:03 +00:00
m_isCurrent( true )
{
m_parent = aParent;
if( aParent )
m_netClass = aParent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
else
2022-02-04 22:44:59 +00:00
m_netClass = std::make_shared<NETCLASS>( wxT( "<invalid>" ) );
2009-08-17 02:59:38 +00:00
}
2007-08-08 03:50:44 +00:00
NETINFO_ITEM::~NETINFO_ITEM()
{
2009-08-17 02:59:38 +00:00
// m_NetClass is not owned by me.
}
2007-08-08 03:50:44 +00:00
void NETINFO_ITEM::Clear()
{
wxCHECK( m_parent, /* void */ );
m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
}
void NETINFO_ITEM::SetNetClass( const std::shared_ptr<NETCLASS>& aNetClass )
{
wxCHECK( m_parent, /* void */ );
if( aNetClass )
m_netClass = aNetClass;
else
m_netClass = m_parent->GetDesignSettings().m_NetSettings->m_DefaultNetClass;
}
void NETINFO_ITEM::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
2009-05-21 14:59:54 +00:00
{
wxString msg;
2009-05-21 14:59:54 +00:00
aList.emplace_back( _( "Net Name" ), UnescapeString( GetNetname() ) );
2009-05-21 14:59:54 +00:00
2022-02-04 22:44:59 +00:00
aList.emplace_back( _( "Net Code" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
2009-05-21 14:59:54 +00:00
// Warning: for netcode == NETINFO_LIST::ORPHANED, the parent or the board can be NULL
2021-07-19 23:56:05 +00:00
BOARD * board = m_parent ? m_parent->GetBoard() : nullptr;
if( board )
2009-05-21 14:59:54 +00:00
{
2021-06-11 21:07:02 +00:00
int count = 0;
PCB_TRACK* startTrack = nullptr;
for( FOOTPRINT* footprint : board->Footprints() )
2009-05-21 14:59:54 +00:00
{
for( PAD* pad : footprint->Pads() )
{
2020-12-08 13:02:08 +00:00
if( pad->GetNetCode() == GetNetCode() )
count++;
}
2009-05-21 14:59:54 +00:00
}
2022-02-04 22:44:59 +00:00
aList.emplace_back( _( "Pads" ), wxString::Format( wxT( "%d" ), count ) );
2009-05-21 14:59:54 +00:00
count = 0;
2021-06-11 21:07:02 +00:00
for( PCB_TRACK* track : board->Tracks() )
{
if( track->GetNetCode() == GetNetCode() )
{
if( track->Type() == PCB_VIA_T )
count++;
else if( !startTrack )
startTrack = track;
}
}
2009-05-21 14:59:54 +00:00
2022-02-04 22:44:59 +00:00
aList.emplace_back( _( "Vias" ), wxString::Format( wxT( "%d" ), count ) );
2009-05-21 14:59:54 +00:00
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 ):
2022-09-19 09:25:20 +00:00
aList.emplace_back( _( "Net Length" ),
aFrame->MessageTextFromValue( lengthNet + lengthPadToDie ) );
// Displays the net length of tracks only:
2022-09-19 09:25:20 +00:00
aList.emplace_back( _( "On Board" ), aFrame->MessageTextFromValue( lengthNet ) );
// Displays the net length of internal ICs connections (wires inside ICs):
2022-09-19 09:25:20 +00:00
aList.emplace_back( _( "In Package" ), aFrame->MessageTextFromValue( lengthPadToDie ) );
}
}
}
bool NETINFO_ITEM::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
{
return BOARD_ITEM::Matches( GetNetname(), aSearchData );
}
2022-08-31 09:15:42 +00:00
const BOX2I NETINFO_ITEM::GetBoundingBox() const
{
std::shared_ptr<CONNECTIVITY_DATA> conn = GetBoard()->GetConnectivity();
2022-08-31 09:15:42 +00:00
BOX2I bbox;
for( BOARD_ITEM* item : conn->GetNetItems( m_netCode, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
PCB_ZONE_T, PCB_PAD_T } ) )
{
bbox.Merge( item->GetBoundingBox() );
}
return bbox;
}