2009-05-24 18:28:36 +00:00
|
|
|
/*************************************************************************/
|
2009-11-12 15:43:38 +00:00
|
|
|
/* NETINFO_ITEM class, to handle info on nets (netnames, net constraints */
|
2009-05-24 18:28:36 +00:00
|
|
|
/*************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "gr_basic.h"
|
2009-05-25 11:53:55 +00:00
|
|
|
#include "class_drawpanel.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "wxBasePcbFrame.h"
|
2009-05-21 14:59:54 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "kicad_string.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "pcbnew.h"
|
2010-01-29 20:36:12 +00:00
|
|
|
#include "colors_selection.h"
|
2011-01-14 17:43:30 +00:00
|
|
|
#include "richio.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
|
|
|
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
#include "class_track.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
/*********************************************************/
|
2009-05-25 11:53:55 +00:00
|
|
|
/* class NETINFO_ITEM: handle data relative to a given net */
|
2007-08-08 03:50:44 +00:00
|
|
|
/*********************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM::NETINFO_ITEM( BOARD_ITEM* aParent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
SetNet( 0 );
|
2009-11-12 15:43:38 +00:00
|
|
|
m_NbNodes = 0;
|
|
|
|
m_NbLink = 0;
|
2009-07-18 11:44:19 +00:00
|
|
|
m_NbNoconn = 0;
|
2009-11-12 15:43:38 +00:00
|
|
|
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
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-08-17 02:59:38 +00:00
|
|
|
m_NetClassName = NETCLASS::Default;
|
|
|
|
|
|
|
|
m_NetClass = 0;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM::~NETINFO_ITEM()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-08-17 02:59:38 +00:00
|
|
|
// m_NetClass is not owned by me.
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
/* Read NETINFO_ITEM from file.
|
|
|
|
* Returns 0 if OK
|
|
|
|
* 1 if incomplete reading
|
2007-08-08 03:50:44 +00:00
|
|
|
*/
|
2011-01-14 17:43:30 +00:00
|
|
|
int NETINFO_ITEM::ReadDescr( LINE_READER* aReader )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
char* Line;
|
|
|
|
char Ltmp[1024];
|
|
|
|
int tmp;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
while( aReader->ReadLine() )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
Line = aReader->Line();
|
2007-08-08 03:50:44 +00:00
|
|
|
if( strnicmp( Line, "$End", 4 ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
2009-11-12 15:43:38 +00:00
|
|
|
if( strncmp( Line, "Na", 2 ) == 0 )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
sscanf( Line + 2, " %d", &tmp );
|
2007-10-13 06:18:44 +00:00
|
|
|
SetNet( tmp );
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
ReadDelimitedText( Ltmp, Line + 2, sizeof(Ltmp) );
|
2011-02-28 18:36:19 +00:00
|
|
|
m_Netname = FROM_UTF8( Ltmp );
|
2007-08-08 03:50:44 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
/** Note: the old name of class NETINFO_ITEM was EQUIPOT
|
2009-11-12 15:43:38 +00:00
|
|
|
* so in Save (and read) functions, for compatibility, we use EQUIPOT as
|
|
|
|
* keyword
|
2009-05-24 18:28:36 +00:00
|
|
|
*/
|
2009-11-12 15:43:38 +00:00
|
|
|
bool NETINFO_ITEM::Save( FILE* aFile ) const
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
bool success = false;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "$EQUIPOT\n" );
|
2011-03-25 20:07:27 +00:00
|
|
|
fprintf( aFile, "Na %d %s\n", GetNet(), EscapedUTF8( m_Netname ).c_str() );
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "St %s\n", "~" );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
if( fprintf( aFile, "$EndEQUIPOT\n" ) != sizeof("$EndEQUIPOT\n") - 1 )
|
2007-10-30 21:30:58 +00:00
|
|
|
goto out;
|
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
success = true;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
|
|
|
out:
|
2008-12-14 19:45:05 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
/**
|
|
|
|
* Function SetNetname
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aNetname : the new netname
|
2008-12-14 19:45:05 +00:00
|
|
|
*/
|
2009-06-05 15:57:41 +00:00
|
|
|
void NETINFO_ITEM::SetNetname( const wxString& aNetname )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
|
|
|
m_Netname = aNetname;
|
|
|
|
m_ShortNetname = m_Netname.AfterLast( '/' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Draw (TODO)
|
2008-12-14 19:45:05 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void NETINFO_ITEM::Draw( EDA_DRAW_PANEL* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
int aDrawMode,
|
|
|
|
const wxPoint& aOffset )
|
2008-12-14 19:45:05 +00:00
|
|
|
{
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2007-08-09 01:41:30 +00:00
|
|
|
|
2009-05-21 14:59:54 +00:00
|
|
|
/**
|
|
|
|
* Function DisplayInfo
|
|
|
|
* has knowledge about the frame and how and where to put status information
|
|
|
|
* about this object into the frame's message panel.
|
2010-12-08 20:12:46 +00:00
|
|
|
* Is virtual from EDA_ITEM.
|
2011-01-21 19:30:59 +00:00
|
|
|
* @param frame A EDA_DRAW_FRAME in which to print status information.
|
2009-05-21 14:59:54 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void NETINFO_ITEM::DisplayInfo( EDA_DRAW_FRAME* frame )
|
2009-05-21 14:59:54 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
int count;
|
|
|
|
EDA_ITEM* Struct;
|
|
|
|
wxString txt;
|
|
|
|
MODULE* module;
|
|
|
|
D_PAD* pad;
|
2011-07-20 05:57:06 +00:00
|
|
|
double lengthnet = 0; // This is the lenght of tracks on pcb
|
|
|
|
double lengthdie = 0; // this is the lenght of internal ICs connections
|
2009-05-21 14:59:54 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->ClearMsgPanel();
|
2009-05-21 14:59:54 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Net Name" ), GetNetname(), RED );
|
2009-05-21 14:59:54 +00:00
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), GetNet() );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Net Code" ), txt, RED );
|
2009-05-21 14:59:54 +00:00
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
count = 0;
|
2011-03-01 19:26:17 +00:00
|
|
|
module = ( (PCB_BASE_FRAME*) frame )->GetBoard()->m_Modules;
|
2009-05-21 14:59:54 +00:00
|
|
|
for( ; module != 0; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( pad = module->m_Pads; pad != 0; pad = pad->Next() )
|
|
|
|
{
|
|
|
|
if( pad->GetNet() == GetNet() )
|
2011-06-30 06:02:07 +00:00
|
|
|
{
|
2009-05-21 14:59:54 +00:00
|
|
|
count++;
|
2011-06-30 06:02:07 +00:00
|
|
|
lengthdie += pad->m_LengthDie;
|
|
|
|
}
|
2009-05-21 14:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), count );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Pads" ), txt, DARKGREEN );
|
2009-05-21 14:59:54 +00:00
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
count = 0;
|
2011-03-01 19:26:17 +00:00
|
|
|
Struct = ( (PCB_BASE_FRAME*) frame )->GetBoard()->m_Track;
|
2011-10-01 19:24:27 +00:00
|
|
|
|
2009-05-21 14:59:54 +00:00
|
|
|
for( ; Struct != NULL; Struct = Struct->Next() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( Struct->Type() == PCB_VIA_T )
|
|
|
|
{
|
2009-05-21 14:59:54 +00:00
|
|
|
if( ( (SEGVIA*) Struct )->GetNet() == GetNet() )
|
|
|
|
count++;
|
2011-10-01 19:24:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Struct->Type() == PCB_TRACE_T )
|
|
|
|
{
|
2009-05-21 14:59:54 +00:00
|
|
|
if( ( (TRACK*) Struct )->GetNet() == GetNet() )
|
2009-06-05 15:57:41 +00:00
|
|
|
lengthnet += ( (TRACK*) Struct )->GetLength();
|
2011-10-01 19:24:27 +00:00
|
|
|
}
|
2009-05-21 14:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), count );
|
2009-10-16 17:18:23 +00:00
|
|
|
frame->AppendMsgPanel( _( "Vias" ), txt, BLUE );
|
2009-05-21 14:59:54 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
// Displays the full net lenght (tracks on pcb + internal ICs connections ):
|
|
|
|
txt = frame->CoordinateToString( lengthnet + lengthdie );
|
2011-06-30 06:02:07 +00:00
|
|
|
frame->AppendMsgPanel( _( "Net Length:" ), txt, RED );
|
|
|
|
|
2011-07-20 05:57:06 +00:00
|
|
|
// Displays the net lenght of tracks only:
|
2011-08-20 14:46:48 +00:00
|
|
|
txt = frame->CoordinateToString( lengthnet );
|
|
|
|
frame->AppendMsgPanel( _( "On Board" ), txt, RED );
|
2011-06-30 06:02:07 +00:00
|
|
|
|
2011-07-20 05:57:06 +00:00
|
|
|
// Displays the net lenght of internal ICs connections (wires inside ICs):
|
2011-08-20 14:46:48 +00:00
|
|
|
txt = frame->CoordinateToString( lengthdie );
|
|
|
|
frame->AppendMsgPanel( _( "On Die" ), txt, RED );
|
2011-06-30 06:02:07 +00:00
|
|
|
|
2009-05-21 14:59:54 +00:00
|
|
|
}
|
2009-05-25 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* class RATSNEST_ITEM */
|
|
|
|
/***********************/
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
RATSNEST_ITEM::RATSNEST_ITEM()
|
|
|
|
{
|
2009-11-12 15:43:38 +00:00
|
|
|
m_NetCode = 0; // netcode ( = 1.. n , 0 is the value used for not
|
|
|
|
// connected items)
|
2009-06-05 15:57:41 +00:00
|
|
|
m_Status = 0; // state
|
|
|
|
m_PadStart = NULL; // pointer to the starting pad
|
|
|
|
m_PadEnd = NULL; // pointer to ending pad
|
2009-11-12 15:43:38 +00:00
|
|
|
m_Lenght = 0; // length of the line (temporary used in some
|
|
|
|
// calculations)
|
2009-06-05 15:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
2009-05-25 14:14:54 +00:00
|
|
|
* Draws a line (a ratsnest) from the starting pad to the ending pad
|
2009-05-25 11:53:55 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void RATSNEST_ITEM::Draw( EDA_DRAW_PANEL* panel,
|
|
|
|
wxDC* DC,
|
|
|
|
int aDrawMode,
|
|
|
|
const wxPoint& aOffset )
|
2009-05-25 11:53:55 +00:00
|
|
|
{
|
2010-01-21 20:36:48 +00:00
|
|
|
GRSetDrawMode( DC, aDrawMode );
|
2010-01-29 20:36:12 +00:00
|
|
|
int color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
|
2009-05-25 16:07:33 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, m_PadStart->m_Pos - aOffset,
|
2010-01-29 20:36:12 +00:00
|
|
|
m_PadEnd->m_Pos - aOffset, 0, color );
|
2009-05-25 11:53:55 +00:00
|
|
|
}
|