2009-05-24 18:28:36 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* NETINFO_ITEM class, to handle info on nets (netnames, net constraints ...) */
|
|
|
|
/*************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-05-25 11:53:55 +00:00
|
|
|
#include "class_drawpanel.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"
|
|
|
|
|
|
|
|
|
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
|
|
|
/* Constructor */
|
|
|
|
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-06-05 15:57:41 +00:00
|
|
|
m_NbNodes = m_NbLink = m_NbNoconn = 0;
|
2007-08-08 03:50:44 +00:00
|
|
|
m_ForceWidth = 0;
|
2009-06-20 19:09:43 +00:00
|
|
|
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-05-25 11:53:55 +00:00
|
|
|
/* destructor */
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
2009-05-24 18:28:36 +00:00
|
|
|
int NETINFO_ITEM:: ReadDescr( FILE* File, int* LineNum )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*********************************************************/
|
2009-06-05 15:57:41 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de lecture de 1 descr Equipotentielle.
|
2007-08-08 03:50:44 +00:00
|
|
|
* retourne 0 si OK
|
|
|
|
* 1 si lecture incomplete
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-08 03:50:44 +00:00
|
|
|
char Line[1024], Ltmp[1024];
|
|
|
|
int tmp;
|
|
|
|
|
|
|
|
while( GetLine( File, Line, LineNum ) )
|
|
|
|
{
|
|
|
|
if( strnicmp( Line, "$End", 4 ) == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( strncmp( Line, "Na", 2 ) == 0 ) /* Texte */
|
|
|
|
{
|
|
|
|
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) );
|
|
|
|
m_Netname = CONV_FROM_UTF8( Ltmp );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strncmp( Line, "Lw", 2 ) == 0 ) /* Texte */
|
|
|
|
{
|
|
|
|
sscanf( Line + 2, " %d", &tmp );
|
|
|
|
m_ForceWidth = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-14 19:45:05 +00:00
|
|
|
/**************************************/
|
2009-05-24 18:28:36 +00:00
|
|
|
bool NETINFO_ITEM::Save( FILE* aFile ) const
|
2008-12-14 19:45:05 +00:00
|
|
|
/**************************************/
|
2009-06-05 15:57:41 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
/** Note: the old name of class NETINFO_ITEM was EQUIPOT
|
|
|
|
* so in Save (and read) functions, for compatibility, we use EQUIPOT as keyword
|
|
|
|
*/
|
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" );
|
2008-12-14 19:45:05 +00:00
|
|
|
fprintf( aFile, "Na %d \"%s\"\n", GetNet(), CONV_TO_UTF8( m_Netname ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
fprintf( aFile, "St %s\n", "~" );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( m_ForceWidth )
|
|
|
|
fprintf( aFile, "Lw %d\n", m_ForceWidth );
|
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
|
|
|
|
* @param const wxString : the new netname
|
|
|
|
*/
|
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( '/' );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
/** function Draw (TODO)
|
2008-12-14 19:45:05 +00:00
|
|
|
*/
|
2009-05-25 11:53:55 +00:00
|
|
|
void NETINFO_ITEM::Draw( WinEDA_DrawPanel* 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.
|
|
|
|
* Is virtual from EDA_BaseStruct.
|
|
|
|
* @param frame A WinEDA_DrawFrame in which to print status information.
|
|
|
|
*/
|
2009-06-05 15:57:41 +00:00
|
|
|
void NETINFO_ITEM::DisplayInfo( WinEDA_DrawFrame* frame )
|
2009-05-21 14:59:54 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
EDA_BaseStruct* Struct;
|
|
|
|
wxString txt;
|
|
|
|
MODULE* module;
|
|
|
|
D_PAD* pad;
|
2009-06-05 15:57:41 +00:00
|
|
|
double lengthnet = 0;
|
2009-05-21 14:59:54 +00:00
|
|
|
|
|
|
|
frame->MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 1, _( "Net Name" ), GetNetname(), RED );
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), GetNet() );
|
|
|
|
Affiche_1_Parametre( frame, 30, _( "Net Code" ), txt, RED );
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
count = 0;
|
|
|
|
module = ( (WinEDA_BasePcbFrame*) 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() )
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), count );
|
|
|
|
Affiche_1_Parametre( frame, 40, _( "Pads" ), txt, DARKGREEN );
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
count = 0;
|
|
|
|
Struct = ( (WinEDA_BasePcbFrame*) frame )->GetBoard()->m_Track;
|
2009-05-21 14:59:54 +00:00
|
|
|
for( ; Struct != NULL; Struct = Struct->Next() )
|
|
|
|
{
|
|
|
|
if( Struct->Type() == TYPE_VIA )
|
|
|
|
if( ( (SEGVIA*) Struct )->GetNet() == GetNet() )
|
|
|
|
count++;
|
|
|
|
if( Struct->Type() == TYPE_TRACK )
|
|
|
|
if( ( (TRACK*) Struct )->GetNet() == GetNet() )
|
2009-06-05 15:57:41 +00:00
|
|
|
lengthnet += ( (TRACK*) Struct )->GetLength();
|
2009-05-21 14:59:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
txt.Printf( wxT( "%d" ), count );
|
|
|
|
Affiche_1_Parametre( frame, 50, _( "Vias" ), txt, BLUE );
|
|
|
|
|
|
|
|
valeur_param( (int) lengthnet, txt );
|
|
|
|
Affiche_1_Parametre( frame, 60, _( "Net Length" ), txt, RED );
|
|
|
|
}
|
2009-05-25 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************/
|
|
|
|
/* class RATSNEST_ITEM */
|
|
|
|
/***********************/
|
|
|
|
|
2009-06-05 15:57:41 +00:00
|
|
|
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; // lenght of the line (temporary used in some calculations)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 16:07:33 +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
|
|
|
*/
|
|
|
|
void RATSNEST_ITEM::Draw( WinEDA_DrawPanel* panel, wxDC* DC, int aDrawMode, const wxPoint& aOffset )
|
|
|
|
{
|
2009-05-25 16:07:33 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, m_PadStart->m_Pos - aOffset,
|
|
|
|
m_PadEnd->m_Pos - aOffset, 0, g_DesignSettings.m_RatsnestColor );
|
2009-05-25 11:53:55 +00:00
|
|
|
}
|