kicad/pcbnew/class_netinfo_item.cpp

203 lines
6.0 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>
* Copyright (C) 1992-2012 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
*/
#include <fctsys.h>
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxBasePcbFrame.h>
#include <common.h>
#include <kicad_string.h>
#include <pcbnew.h>
#include <colors_selection.h>
#include <richio.h>
#include <macros.h>
#include <msgpanel.h>
#include <base_units.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
2007-08-08 03:50:44 +00:00
/*********************************************************/
/* class NETINFO_ITEM: handle data relative to a given net */
2007-08-08 03:50:44 +00:00
/*********************************************************/
2012-05-20 13:14:46 +00:00
NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent, const wxString& aNetName, int aNetCode )
{
2012-05-20 13:14:46 +00:00
SetNet( aNetCode );
2012-05-21 18:50:46 +00:00
if( aNetName.size() )
SetNetname( aNetName );
m_parent = aParent;
m_NbNodes = 0;
m_NbLink = 0;
m_NbNoconn = 0;
m_Flag = 0;
m_RatsnestStartIdx = 0; // Starting point of ratsnests of this net in a
// general buffer of ratsnest
m_RatsnestEndIdx = 0; // Ending point of ratsnests of this net
2012-05-21 18:50:46 +00:00
m_NetClassName = NETCLASS::Default;
2009-08-17 02:59:38 +00:00
m_NetClass = 0;
}
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
/**
* Function SetNetname
2010-12-29 17:47:32 +00:00
* @param aNetname : the new netname
*/
void NETINFO_ITEM::SetNetname( const wxString& aNetname )
{
m_Netname = aNetname;
m_ShortNetname = m_Netname.AfterLast( '/' );
}
/**
* Function Draw (TODO)
*/
void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
GR_DRAWMODE aDrawMode,
const wxPoint& aOffset )
{
2007-10-30 21:30:58 +00:00
}
2007-08-09 01:41:30 +00:00
void NETINFO_ITEM::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
2009-05-21 14:59:54 +00:00
{
int count;
EDA_ITEM* Struct;
wxString txt;
MODULE* module;
D_PAD* pad;
double lengthnet = 0; // This is the lenght of tracks on pcb
double lengthPadToDie = 0; // this is the lenght of internal ICs connections
2009-05-21 14:59:54 +00:00
aList.push_back( MSG_PANEL_ITEM( _( "Net Name" ), GetNetname(), RED ) );
2009-05-21 14:59:54 +00:00
txt.Printf( wxT( "%d" ), GetNet() );
aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), txt, RED ) );
2009-05-21 14:59:54 +00:00
count = 0;
module = m_parent->GetBoard()->m_Modules;
2009-05-21 14:59:54 +00:00
for( ; module != 0; module = module->Next() )
{
for( pad = module->Pads(); pad != 0; pad = pad->Next() )
2009-05-21 14:59:54 +00:00
{
if( pad->GetNet() == GetNet() )
{
2009-05-21 14:59:54 +00:00
count++;
lengthPadToDie += pad->GetPadToDieLength();
}
2009-05-21 14:59:54 +00:00
}
}
txt.Printf( wxT( "%d" ), count );
aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
2009-05-21 14:59:54 +00:00
count = 0;
Struct = m_parent->GetBoard()->m_Track;
2009-05-21 14:59:54 +00:00
for( ; Struct != NULL; Struct = Struct->Next() )
{
if( Struct->Type() == PCB_VIA_T )
{
2009-05-21 14:59:54 +00:00
if( ( (SEGVIA*) Struct )->GetNet() == GetNet() )
count++;
}
if( Struct->Type() == PCB_TRACE_T )
{
2009-05-21 14:59:54 +00:00
if( ( (TRACK*) Struct )->GetNet() == GetNet() )
lengthnet += ( (TRACK*) Struct )->GetLength();
}
2009-05-21 14:59:54 +00:00
}
txt.Printf( wxT( "%d" ), count );
aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, BLUE ) );
2009-05-21 14:59:54 +00:00
// Displays the full net length (tracks on pcb + internal ICs connections ):
txt = ::CoordinateToString( lengthnet + lengthPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "Net Length:" ), txt, RED ) );
// Displays the net length of tracks only:
txt = ::CoordinateToString( lengthnet );
aList.push_back( MSG_PANEL_ITEM( _( "On Board" ), txt, RED ) );
// Displays the net length of internal ICs connections (wires inside ICs):
txt = ::CoordinateToString( lengthPadToDie );
aList.push_back( MSG_PANEL_ITEM( _( "In Package" ), txt, RED ) );
2009-05-21 14:59:54 +00:00
}
/***********************/
/* class RATSNEST_ITEM */
/***********************/
RATSNEST_ITEM::RATSNEST_ITEM()
{
m_NetCode = 0; // netcode ( = 1.. n , 0 is the value used for not
// connected items)
m_Status = 0; // state
m_PadStart = NULL; // pointer to the starting pad
m_PadEnd = NULL; // pointer to ending pad
m_Lenght = 0; // length of the line (temporary used in some
// calculations)
}
/**
* Function Draw
* Draws a line (a ratsnest) from the starting pad to the ending pad
*/
void RATSNEST_ITEM::Draw( EDA_DRAW_PANEL* panel,
wxDC* DC,
GR_DRAWMODE aDrawMode,
const wxPoint& aOffset )
{
GRSetDrawMode( DC, aDrawMode );
EDA_COLOR_T color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
2012-02-19 04:02:19 +00:00
GRLine( panel->GetClipBox(), DC,
m_PadStart->GetPosition() - aOffset,
m_PadEnd->GetPosition() - aOffset, 0, color );
}