kicad/eeschema/netlist.cpp

1245 lines
40 KiB
C++
Raw Normal View History

2007-09-20 21:06:49 +00:00
/***********************************/
/* Module de calcul de la Netliste */
/***********************************/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
2007-09-20 21:06:49 +00:00
#include "netlist.h" /* Definitions generales liees au calcul de netliste */
2007-05-06 16:03:28 +00:00
#include "protos.h"
//#define NETLIST_DEBUG
2007-05-06 16:03:28 +00:00
/* Routines locales */
static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus );
static void SheetLabelConnect( ObjetNetListStruct* SheetLabel );
2007-09-20 21:06:49 +00:00
static int ListeObjetConnection( WinEDA_SchematicFrame* frame,
DrawSheetPath* sheetlist,
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* ObjNet );
static int ConvertBusToMembers( ObjetNetListStruct* ObjNet );
static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus,
2007-09-20 21:06:49 +00:00
int start );
static void SegmentToPointConnect( ObjetNetListStruct* Jonction, int IsBus,
int start );
static void LabelConnect( ObjetNetListStruct* Label );
2007-09-20 21:06:49 +00:00
static int TriNetCode( const void* o1, const void* o2 );
static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems );
static void SetUnconnectedFlag( ObjetNetListStruct* ObjNet, int NbItems );
static int TriBySheet( const void* o1, const void* o2 );
2007-05-06 16:03:28 +00:00
/* Variable locales */
static int FirstNumWireBus, LastNumWireBus, RootBusNameLength;
static int LastNetCode, LastBusNetCode;
static int s_PassNumber;
2007-09-21 04:40:12 +00:00
#if defined(DEBUG)
#include <iostream>
2007-09-21 04:40:12 +00:00
const char* ShowType( NetObjetType aType )
{
const char* ret;
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
switch( aType )
{
case NET_SEGMENT: ret = "segment"; break;
case NET_BUS: ret = "bus"; break;
case NET_JONCTION: ret = "junction"; break;
case NET_LABEL: ret = "label"; break;
case NET_HIERLABEL: ret = "hierlabel"; break;
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL: ret = "glabel"; break;
2007-09-21 04:40:12 +00:00
case NET_BUSLABELMEMBER: ret = "buslblmember"; break;
case NET_HIERBUSLABELMEMBER: ret = "hierbuslblmember"; break;
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER: ret = "gbuslblmember"; break;
2007-09-21 04:40:12 +00:00
case NET_SHEETBUSLABELMEMBER: ret = "sbuslblmember"; break;
case NET_SHEETLABEL: ret = "sheetlabel"; break;
case NET_PINLABEL: ret = "pinlabel"; break;
case NET_PIN: ret = "pin"; break;
case NET_NOCONNECT: ret = "noconnect"; break;
default: ret = "??"; break;
}
return ret;
}
void ObjetNetListStruct::Show( std::ostream& out, int ndx )
{
2008-03-20 01:50:21 +00:00
wxString path = m_SheetList.PathHumanReadable();
out << "<netItem ndx=\"" << ndx << '"' <<
2007-09-21 04:40:12 +00:00
" type=\"" << ShowType(m_Type) << '"' <<
2007-10-13 06:18:44 +00:00
" netCode=\"" << GetNet() << '"' <<
" sheet=\"" << CONV_TO_UTF8(path) << '"' <<
2007-09-21 04:40:12 +00:00
">\n";
out << " <start " << m_Start << "/> <end " << m_End << "/>\n";
if( m_Label )
out << " <label>" << m_Label->mb_str() << "</label>\n";
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
if( m_Comp )
m_Comp->Show( 1, out );
2007-09-21 13:23:51 +00:00
else
out << " m_Comp==NULL\n";
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
out << "</netItem>\n";
}
void dumpNetTable()
{
for( int i=0; i<g_NbrObjNet; ++i )
{
g_TabObjNet[i].Show( std::cout, i );
}
}
#endif
2007-05-06 16:03:28 +00:00
/***********************************************************************/
2007-09-20 21:06:49 +00:00
void FreeTabNetList( ObjetNetListStruct* TabNetItems, int NbrNetItems )
2007-05-06 16:03:28 +00:00
/***********************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*
2007-09-20 21:06:49 +00:00
* Routine de liberation memoire des tableaux utilises pour le calcul
* de la netliste
* TabNetItems = pointeur sur le tableau principal (liste des items )
* NbrNetItems = nombre d'elements
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int i;
/* Liberation memoire des strings du champ Label reserve par ConvertBusToMembers */
for( i = 0; i < NbrNetItems; i++ )
{
switch( TabNetItems[i].m_Type )
{
case NET_PIN:
case NET_SHEETLABEL:
case NET_SEGMENT:
case NET_JONCTION:
case NET_BUS:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_PINLABEL:
case NET_NOCONNECT:
break;
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
case NET_SHEETBUSLABELMEMBER:
case NET_BUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
SAFE_DELETE( TabNetItems[i].m_Label );
//see the note in ConvertBustToMembers
2007-09-20 21:06:49 +00:00
break;
}
}
MyFree( TabNetItems );
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*****************************************************/
2007-09-20 21:06:49 +00:00
void* WinEDA_SchematicFrame::BuildNetListBase()
2007-05-06 16:03:28 +00:00
/*****************************************************/
/* Routine qui construit le tableau des elements connectes du projet
2007-09-20 21:06:49 +00:00
* met a jour:
* g_TabObjNet
* g_NbrObjNet
*/
2007-05-06 16:03:28 +00:00
{
int NetNumber;
2007-09-20 21:06:49 +00:00
int i, istart, NetCode;
2008-03-20 01:50:21 +00:00
DrawSheetPath* sheet;
2007-09-20 21:06:49 +00:00
wxString msg;
wxBusyCursor Busy;
NetNumber = 1;
s_PassNumber = 0;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
MsgPanel->EraseMsgBox();
Affiche_1_Parametre( this, 1, _( "List" ), wxEmptyString, LIGHTRED );
/* Build the sheet (not screen) list (flattened)*/
EDA_SheetList SheetListList( NULL );
2008-03-20 01:50:21 +00:00
i=0;
2007-09-20 21:06:49 +00:00
/* 1ere passe : Comptage du nombre d'objet de Net */
g_NbrObjNet = 0;
g_TabObjNet = NULL; /* Init pour le 1er passage dans ListeObjetConnection */
/* count nelist items */
2008-02-26 19:19:54 +00:00
g_RootSheet->m_AssociatedScreen->SetModify();
for( sheet = SheetListList.GetFirst(); sheet != NULL; sheet = SheetListList.GetNext() )
2007-09-20 21:06:49 +00:00
{
g_NbrObjNet += ListeObjetConnection( this, sheet, NULL );
2007-09-20 21:06:49 +00:00
}
if( g_NbrObjNet == 0 )
{
DisplayError( this, _( "No component" ), 20 );
return NULL;
}
i = sizeof(ObjetNetListStruct) * g_NbrObjNet;
g_TabObjNet = (ObjetNetListStruct*) MyZMalloc( i );
if( g_TabObjNet == NULL )
return NULL;
/* 2eme passe : Remplissage des champs des structures des objets de Net */
2008-03-20 01:50:21 +00:00
/* second pass: fill the fields of the structures in the Net */
2007-09-20 21:06:49 +00:00
s_PassNumber++;
Affiche_1_Parametre( this, 1, _( "List" ), wxEmptyString, RED );
2008-03-20 01:50:21 +00:00
sheet = SheetListList.GetFirst();
for( ObjetNetListStruct* tabObjNet = g_TabObjNet;
sheet != NULL; sheet = SheetListList.GetNext() )
2007-09-20 21:06:49 +00:00
{
tabObjNet += ListeObjetConnection( this, sheet, tabObjNet );
2007-09-20 21:06:49 +00:00
}
Affiche_1_Parametre( this, -1, _( "List" ), _( "Done" ), RED );
2007-09-20 21:06:49 +00:00
msg.Printf( wxT( "%d" ), g_NbrObjNet );
Affiche_1_Parametre( this, 8, _( "NbItems" ), msg, GREEN );
/* Recherche des connections pour les Segments et les Pins */
/* Tri du Tableau des objets de Net par Sheet */
qsort( g_TabObjNet, g_NbrObjNet, sizeof(ObjetNetListStruct), TriBySheet );
Affiche_1_Parametre( this, 18, _( "Conn" ), wxEmptyString, CYAN );
sheet = &(g_TabObjNet[0].m_SheetList);
2007-09-20 21:06:49 +00:00
LastNetCode = LastBusNetCode = 1;
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
for( i = istart = 0; i<g_NbrObjNet; i++ )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
if( g_TabObjNet[i].m_SheetList != *sheet )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
sheet = &(g_TabObjNet[i].m_SheetList);
2007-09-21 04:40:12 +00:00
istart = i;
2007-09-20 21:06:49 +00:00
}
switch( g_TabObjNet[i].m_Type )
{
case NET_PIN:
case NET_PINLABEL:
case NET_SHEETLABEL:
case NET_NOCONNECT:
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() != 0 )
break; /* Deja connecte */
2007-09-20 21:06:49 +00:00
case NET_SEGMENT:
/* Controle des connexions type point a point ( Sans BUS ) */
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
g_TabObjNet[i].SetNet( LastNetCode );
2007-09-20 21:06:49 +00:00
LastNetCode++;
}
PointToPointConnect( g_TabObjNet + i, 0, istart );
break;
case NET_JONCTION:
/* Controle des jonction , hors BUS */
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
g_TabObjNet[i].SetNet( LastNetCode );
2007-09-20 21:06:49 +00:00
LastNetCode++;
}
SegmentToPointConnect( g_TabObjNet + i, 0, istart );
/* Controle des jonction , sur BUS */
if( g_TabObjNet[i].m_BusNetCode == 0 )
{
g_TabObjNet[i].m_BusNetCode = LastBusNetCode;
LastBusNetCode++;
}
SegmentToPointConnect( g_TabObjNet + i, ISBUS, istart );
break;
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
/* Controle des connexions type jonction ( Sans BUS ) */
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
g_TabObjNet[i].SetNet( LastNetCode );
2007-09-20 21:06:49 +00:00
LastNetCode++;
}
SegmentToPointConnect( g_TabObjNet + i, 0, istart );
break;
case NET_SHEETBUSLABELMEMBER:
if( g_TabObjNet[i].m_BusNetCode != 0 )
break; /* Deja connecte */
case NET_BUS:
/* Controle des connexions type point a point mode BUS */
if( g_TabObjNet[i].m_BusNetCode == 0 )
{
g_TabObjNet[i].m_BusNetCode = LastBusNetCode;
LastBusNetCode++;
}
PointToPointConnect( g_TabObjNet + i, ISBUS, istart );
break;
case NET_BUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
/* Controle des connexions semblables a des sur BUS */
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
g_TabObjNet[i].m_BusNetCode = LastBusNetCode;
LastBusNetCode++;
}
SegmentToPointConnect( g_TabObjNet + i, ISBUS, istart );
break;
}
}
2008-03-20 01:50:21 +00:00
#if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet local\n\n";
2007-09-21 04:40:12 +00:00
dumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
2007-09-21 04:40:12 +00:00
Affiche_1_Parametre( this, 18, _( "Conn" ), _( "Done" ), CYAN );
2007-09-20 21:06:49 +00:00
/* Mise a jour des NetCodes des Bus Labels connectes par les Bus */
ConnectBusLabels( g_TabObjNet, g_NbrObjNet );
Affiche_1_Parametre( this, 26, _( "Labels" ), wxEmptyString, CYAN );
/* Connections des groupes d'objets par labels identiques */
2007-09-21 04:40:12 +00:00
for( i = 0; i<g_NbrObjNet; i++ )
2007-09-20 21:06:49 +00:00
{
switch( g_TabObjNet[i].m_Type )
{
case NET_PIN:
case NET_SHEETLABEL:
case NET_SEGMENT:
case NET_JONCTION:
case NET_BUS:
case NET_NOCONNECT:
break;
case NET_LABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_PINLABEL:
case NET_BUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
LabelConnect( g_TabObjNet + i );
2007-09-20 21:06:49 +00:00
break;
case NET_SHEETBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_HIERLABEL:
case NET_HIERBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
break;
}
}
#if defined(NETLIST_DEBUG) && defined(DEBUG)
std::cout << "\n\nafter sheet global\n\n";
2007-09-21 04:40:12 +00:00
dumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
Affiche_1_Parametre( this, 26, _( "Labels" ), _( "Done" ), CYAN );
2007-09-20 21:06:49 +00:00
/* Connexion des hierarchies */
Affiche_1_Parametre( this, 36, _( "Hierar." ), wxEmptyString, LIGHTRED );
2007-09-21 04:40:12 +00:00
for( i = 0; i<g_NbrObjNet; i++ )
2007-09-20 21:06:49 +00:00
{
2007-09-21 04:40:12 +00:00
if( g_TabObjNet[i].m_Type == NET_SHEETLABEL
|| g_TabObjNet[i].m_Type == NET_SHEETBUSLABELMEMBER )
SheetLabelConnect( g_TabObjNet + i );
2007-09-20 21:06:49 +00:00
}
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
/* Tri du Tableau des objets de Net par NetCode */
qsort( g_TabObjNet, g_NbrObjNet, sizeof(ObjetNetListStruct), TriNetCode );
2008-03-20 01:50:21 +00:00
#if defined(NETLIST_DEBUG) && defined(DEBUG)
2007-09-21 04:40:12 +00:00
std::cout << "after qsort()\n";
dumpNetTable();
2008-03-20 01:50:21 +00:00
#endif
Affiche_1_Parametre( this, 36, _( "Hierar." ), _( "Done" ), RED );
2007-09-20 21:06:49 +00:00
/* Compression des numeros de NetCode a des valeurs consecutives */
Affiche_1_Parametre( this, 46, _( "Sorting" ), wxEmptyString, GREEN );
LastNetCode = NetCode = 0;
for( i = 0; i < g_NbrObjNet; i++ )
{
2007-10-13 06:18:44 +00:00
if( g_TabObjNet[i].GetNet() != LastNetCode )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
NetCode++;
2007-10-13 06:18:44 +00:00
LastNetCode = g_TabObjNet[i].GetNet();
2007-09-20 21:06:49 +00:00
}
2007-10-13 06:18:44 +00:00
g_TabObjNet[i].SetNet( NetCode );
2007-09-20 21:06:49 +00:00
}
Affiche_1_Parametre( this, 46, _( "Sorting" ), _( "Done" ), GREEN );
2007-09-20 21:06:49 +00:00
/* Affectation du m_FlagOfConnection en fonction de connection ou non */
SetUnconnectedFlag( g_TabObjNet, g_NbrObjNet );
return (void*) g_TabObjNet;
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*************************************************************
2007-09-20 21:06:49 +00:00
* Routine qui connecte les sous feuilles par les sheetLabels *
**************************************************************/
static void SheetLabelConnect( ObjetNetListStruct* SheetLabel )
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int i;
ObjetNetListStruct* ObjetNet;
2007-10-13 06:18:44 +00:00
if( SheetLabel->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
return;
/* Calcul du numero de sous feuille correspondante au sheetlabel */
/* Comparaison du SheetLabel avec les GLABELS de la sous feuille
* pour regroupement des NetCodes */
for( i = 0, ObjetNet = g_TabObjNet; i < g_NbrObjNet; i++ )
{
2008-03-20 01:50:21 +00:00
if( ObjetNet[i].m_SheetList != SheetLabel->m_SheetListInclude )
continue; //use SheetInclude, not the sheet!!
if( (ObjetNet[i].m_Type != NET_HIERLABEL )
&& (ObjetNet[i].m_Type != NET_HIERBUSLABELMEMBER ) )
2007-09-20 21:06:49 +00:00
continue;
2008-03-20 01:50:21 +00:00
2007-10-13 06:18:44 +00:00
if( ObjetNet[i].GetNet() == SheetLabel->GetNet() )
2008-03-20 01:50:21 +00:00
continue; //already connected.
2007-09-20 21:06:49 +00:00
if( ObjetNet[i].m_Label->CmpNoCase( *SheetLabel->m_Label ) != 0 )
continue; //different names.
2007-09-20 21:06:49 +00:00
/* Propagation du Netcode a tous les Objets de meme NetCode */
2007-10-13 06:18:44 +00:00
if( ObjetNet[i].GetNet() )
PropageNetCode( ObjetNet[i].GetNet(), SheetLabel->GetNet(), 0 );
2007-09-20 21:06:49 +00:00
else
2007-10-13 06:18:44 +00:00
ObjetNet[i].SetNet( SheetLabel->GetNet() );
2007-09-20 21:06:49 +00:00
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
static int ListeObjetConnection( WinEDA_SchematicFrame* frame, DrawSheetPath* sheetlist,
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* ObjNet )
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine generant la liste des objets relatifs aux connection
2007-09-20 21:06:49 +00:00
* entree:
2008-03-20 01:50:21 +00:00
* sheetlist: pointer to a sheetlist.
2007-09-20 21:06:49 +00:00
* ObjNet:
* si NULL: la routine compte seulement le nombre des objets
* sinon: pointe le tableau a remplir
*/
2007-05-06 16:03:28 +00:00
{
int ii, NbrItem = 0;
2007-09-20 21:06:49 +00:00
EDA_BaseStruct* DrawList;
2008-03-20 01:50:21 +00:00
SCH_COMPONENT* DrawLibItem;
2007-09-20 21:06:49 +00:00
int TransMat[2][2], PartX, PartY, x2, y2;
EDA_LibComponentStruct* Entry;
LibEDA_BaseStruct* DEntry;
2008-04-15 19:38:19 +00:00
Hierarchical_PIN_Sheet_Struct* SheetLabel;
2008-03-20 01:50:21 +00:00
DrawSheetPath list;
DrawList = sheetlist->LastScreen()->EEDrawList;
2007-09-20 21:06:49 +00:00
for( ; DrawList; DrawList = DrawList->Pnext )
{
2008-03-20 01:50:21 +00:00
if( ObjNet ){
ObjNet[NbrItem].m_SheetList = *sheetlist;
ObjNet[NbrItem].m_SheetListInclude = *sheetlist;
//used for DrawSheetLabels
}
2007-09-20 21:06:49 +00:00
switch( DrawList->Type() )
{
case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (EDA_DrawLineStruct*) DrawList )
if( ObjNet )
{
if( (STRUCT->GetLayer() != LAYER_BUS)
&& (STRUCT->GetLayer() != LAYER_WIRE) )
2007-09-20 21:06:49 +00:00
break;
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Start = STRUCT->m_Start;
ObjNet[NbrItem].m_End = STRUCT->m_End;
2008-03-20 01:50:21 +00:00
if( STRUCT->GetLayer() == LAYER_BUS )
2007-09-20 21:06:49 +00:00
{
ObjNet[NbrItem].m_Type = NET_BUS;
}
else /* Cas des WIRE */
{
ObjNet[NbrItem].m_Type = NET_SEGMENT;
}
}
NbrItem++;
break;
case DRAW_JUNCTION_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (DrawJunctionStruct*) DrawList )
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_JONCTION;
ObjNet[NbrItem].m_Start = STRUCT->m_Pos;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
}
NbrItem++;
break;
case DRAW_NOCONNECT_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (DrawNoConnectStruct*) DrawList )
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_NOCONNECT;
ObjNet[NbrItem].m_Start = STRUCT->m_Pos;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
}
NbrItem++;
break;
2008-03-20 01:50:21 +00:00
case TYPE_SCH_LABEL:
2007-09-20 21:06:49 +00:00
#undef STRUCT
2008-03-20 01:50:21 +00:00
#define STRUCT ( (SCH_LABEL*) DrawList )
2007-09-20 21:06:49 +00:00
ii = IsBusLabel( STRUCT->m_Text );
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_LABEL;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( STRUCT->m_Layer == LAYER_GLOBLABEL )
ObjNet[NbrItem].m_Type = NET_GLOBLABEL;
2008-03-20 01:50:21 +00:00
if( STRUCT->m_Layer == LAYER_HIERLABEL )
ObjNet[NbrItem].m_Type = NET_HIERLABEL;
2007-09-20 21:06:49 +00:00
ObjNet[NbrItem].m_Label = &STRUCT->m_Text;
ObjNet[NbrItem].m_Start = STRUCT->m_Pos;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( ObjNet + NbrItem );
}
NbrItem += ii + 1;
break;
2008-03-20 01:50:21 +00:00
case TYPE_SCH_GLOBALLABEL:
case TYPE_SCH_HIERLABEL:
2007-09-20 21:06:49 +00:00
#undef STRUCT
2008-03-20 01:50:21 +00:00
#define STRUCT ( (SCH_LABEL*) DrawList )
2007-09-20 21:06:49 +00:00
ii = IsBusLabel( STRUCT->m_Text );
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = STRUCT;
ObjNet[NbrItem].m_Type = NET_LABEL;
2008-03-20 01:50:21 +00:00
if( STRUCT->m_Layer == LAYER_GLOBLABEL ) //this is not the simplest way of doing it
2008-03-20 01:50:21 +00:00
ObjNet[NbrItem].m_Type = NET_GLOBLABEL;// (look at the case statement above).
if( STRUCT->m_Layer == LAYER_HIERLABEL )
ObjNet[NbrItem].m_Type = NET_HIERLABEL;
2007-09-20 21:06:49 +00:00
ObjNet[NbrItem].m_Label = &STRUCT->m_Text;
ObjNet[NbrItem].m_Start = STRUCT->m_Pos;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( ObjNet + NbrItem );
}
NbrItem += ii + 1;
break;
2008-03-20 01:50:21 +00:00
case TYPE_SCH_COMPONENT:
DrawLibItem = (SCH_COMPONENT*) DrawList;
2007-09-20 21:06:49 +00:00
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
2008-03-20 01:50:21 +00:00
PartX = DrawLibItem->m_Pos.x;
2007-09-20 21:06:49 +00:00
PartY = DrawLibItem->m_Pos.y;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
Entry = FindLibPart( DrawLibItem->m_ChipName, wxEmptyString, FIND_ROOT );
if( Entry == NULL )
break;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( Entry->m_Drawings == NULL )
break;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
DEntry = Entry->m_Drawings;
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
for( ; DEntry; DEntry = DEntry->Next() )
2007-09-20 21:06:49 +00:00
{
LibDrawPin* Pin = (LibDrawPin*) DEntry;
if( DEntry->Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( DEntry->m_Unit
&& (DEntry->m_Unit != DrawLibItem->m_Multi) )
continue;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( DEntry->m_Convert
&& (DEntry->m_Convert != DrawLibItem->m_Convert) )
continue;
x2 = PartX + TransMat[0][0] * Pin->m_Pos.x
+ TransMat[0][1] * Pin->m_Pos.y;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
y2 = PartY + TransMat[1][0] * Pin->m_Pos.x
+ TransMat[1][1] * Pin->m_Pos.y;
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = DEntry;
2008-03-20 01:50:21 +00:00
ObjNet[NbrItem].m_SheetList = *sheetlist;
2007-09-20 21:06:49 +00:00
ObjNet[NbrItem].m_Type = NET_PIN;
ObjNet[NbrItem].m_Link = DrawLibItem;
ObjNet[NbrItem].m_ElectricalType = Pin->m_PinType;
ObjNet[NbrItem].m_PinNum = Pin->m_PinNum;
ObjNet[NbrItem].m_Label = &Pin->m_PinName;
ObjNet[NbrItem].m_Start.x = x2;
ObjNet[NbrItem].m_Start.y = y2;
2007-09-21 04:40:12 +00:00
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
2007-09-20 21:06:49 +00:00
}
NbrItem++;
if( ( (int) Pin->m_PinType == (int) PIN_POWER_IN )
&& ( Pin->m_Attributs & PINNOTDRAW ) )
2008-03-20 01:50:21 +00:00
{
2007-09-20 21:06:49 +00:00
/* Il y a un PIN_LABEL Associe */
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = NULL;
2008-03-20 01:50:21 +00:00
ObjNet[NbrItem].m_SheetList = *sheetlist;
2007-09-20 21:06:49 +00:00
ObjNet[NbrItem].m_Type = NET_PINLABEL;
ObjNet[NbrItem].m_Label = &Pin->m_PinName;
ObjNet[NbrItem].m_Start.x = x2;
ObjNet[NbrItem].m_Start.y = y2;
2007-09-21 04:40:12 +00:00
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
2007-09-20 21:06:49 +00:00
}
NbrItem++;
}
}
break;
case DRAW_PICK_ITEM_STRUCT_TYPE:
case DRAW_POLYLINE_STRUCT_TYPE:
case DRAW_BUSENTRY_STRUCT_TYPE:
case DRAW_MARKER_STRUCT_TYPE:
2008-03-20 01:50:21 +00:00
case TYPE_SCH_TEXT:
2007-09-20 21:06:49 +00:00
break;
case DRAW_SHEET_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (DrawSheetStruct*) DrawList )
2008-03-20 01:50:21 +00:00
list = *sheetlist;
list.Push(STRUCT);
2007-09-20 21:06:49 +00:00
SheetLabel = STRUCT->m_Label;
for( ; SheetLabel != NULL;
2008-04-15 19:38:19 +00:00
SheetLabel = (Hierarchical_PIN_Sheet_Struct*) SheetLabel->Pnext )
2007-09-20 21:06:49 +00:00
{
ii = IsBusLabel( SheetLabel->m_Text );
if( ObjNet )
{
ObjNet[NbrItem].m_Comp = SheetLabel;
2008-03-20 01:50:21 +00:00
ObjNet[NbrItem].m_SheetList = *sheetlist;
ObjNet[NbrItem].m_Link = DrawList;
ObjNet[NbrItem].m_Type = NET_SHEETLABEL;
2007-09-20 21:06:49 +00:00
ObjNet[NbrItem].m_ElectricalType = SheetLabel->m_Shape;
ObjNet[NbrItem].m_Label = &SheetLabel->m_Text;
ObjNet[NbrItem].m_SheetListInclude = list;
ObjNet[NbrItem].m_Start = SheetLabel->m_Pos;
ObjNet[NbrItem].m_End = ObjNet[NbrItem].m_Start;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
/* Si c'est un Bus, eclatement en Label */
if( ii )
ConvertBusToMembers( ObjNet + NbrItem );
}
NbrItem += ii + 1;
}
break;
2008-04-15 19:38:19 +00:00
case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE:
2007-09-20 21:06:49 +00:00
DisplayError( frame, wxT( "Netlist: Type DRAW_SHEETLABEL inattendu" ) );
break;
default:
{
wxString msg;
msg.Printf( wxT( "Netlist: unexpected type struct %d" ),
DrawList->Type() );
DisplayError( frame, msg );
break;
}
}
}
return NbrItem;
2007-05-06 16:03:28 +00:00
}
/************************************************************************/
2007-09-20 21:06:49 +00:00
static void ConnectBusLabels( ObjetNetListStruct* Label, int NbItems )
2007-05-06 16:03:28 +00:00
/************************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine qui analyse les labels type xxBUSLABELMEMBER
2007-09-20 21:06:49 +00:00
* Propage les Netcodes entre labels correspondants ( c'est a dire lorsque
* leur numero de membre est identique) lorsqu'ils sont connectes
* globalement par leur BusNetCode
* Utilise et met a jour la variable LastNetCode
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* LabelInTst, * Lim;
Lim = Label + NbItems;
for( ; Label < Lim; Label++ )
{
if( (Label->m_Type == NET_SHEETBUSLABELMEMBER)
|| (Label->m_Type == NET_BUSLABELMEMBER)
|| (Label->m_Type == NET_HIERBUSLABELMEMBER) )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
if( Label->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
Label->SetNet( LastNetCode );
2007-09-20 21:06:49 +00:00
LastNetCode++;
}
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
for( LabelInTst = Label + 1; LabelInTst < Lim; LabelInTst++ )
{
if( (LabelInTst->m_Type == NET_SHEETBUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_BUSLABELMEMBER)
|| (LabelInTst->m_Type == NET_HIERBUSLABELMEMBER) )
2007-09-20 21:06:49 +00:00
{
if( LabelInTst->m_BusNetCode != Label->m_BusNetCode )
continue;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
if( LabelInTst->m_Member != Label->m_Member )
continue;
2008-03-20 01:50:21 +00:00
2007-10-13 06:18:44 +00:00
if( LabelInTst->GetNet() == 0 )
LabelInTst->SetNet( Label->GetNet() );
2007-09-20 21:06:49 +00:00
else
2007-10-13 06:18:44 +00:00
PropageNetCode( LabelInTst->GetNet(), Label->GetNet(), 0 );
2007-09-20 21:06:49 +00:00
}
}
}
}
2007-05-06 16:03:28 +00:00
}
/**************************************************/
2007-09-20 21:06:49 +00:00
int IsBusLabel( const wxString& LabelDrawList )
2007-05-06 16:03:28 +00:00
/**************************************************/
/* Routine qui verifie si le Label a une notation de type Bus
2007-09-20 21:06:49 +00:00
* Retourne 0 si non
* nombre de membres si oui
* met a jour FirstNumWireBus, LastNumWireBus et RootBusNameLength
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
unsigned Num;
int ii;
wxString BufLine;
long tmp;
bool error = FALSE;
/* Search for '[' because a bus label is like "busname[nn..mm]" */
ii = LabelDrawList.Find( '[' );
if( ii < 0 )
return 0;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
Num = (unsigned) ii;
FirstNumWireBus = LastNumWireBus = 9;
RootBusNameLength = Num;
Num++;
while( LabelDrawList[Num] != '.' && Num < LabelDrawList.Len() )
{
BufLine.Append( LabelDrawList[Num] );
Num++;
}
if( !BufLine.ToLong( &tmp ) )
error = TRUE;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
FirstNumWireBus = tmp;
while( LabelDrawList[Num] == '.' && Num < LabelDrawList.Len() )
Num++;
BufLine.Empty();
while( LabelDrawList[Num] != ']' && Num < LabelDrawList.Len() )
{
BufLine.Append( LabelDrawList[Num] );
Num++;
}
if( !BufLine.ToLong( &tmp ) )
error = TRUE;;
LastNumWireBus = tmp;
if( FirstNumWireBus < 0 )
FirstNumWireBus = 0;
if( LastNumWireBus < 0 )
LastNumWireBus = 0;
if( FirstNumWireBus > LastNumWireBus )
{
EXCHG( FirstNumWireBus, LastNumWireBus );
}
if( error && (s_PassNumber == 0) )
{
wxString msg = _( "Bad Bus Label: " ) + LabelDrawList;
DisplayError( NULL, msg );
}
return LastNumWireBus - FirstNumWireBus + 1;
2007-05-06 16:03:28 +00:00
}
/***************************************************************/
2007-09-20 21:06:49 +00:00
static int ConvertBusToMembers( ObjetNetListStruct* BusLabel )
2007-05-06 16:03:28 +00:00
/***************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine qui eclate un label type Bus en autant de Label qu'il contient de membres,
2007-09-20 21:06:49 +00:00
* et qui cree les structures avec le type NET_GLOBBUSLABELMEMBER, NET_BUSLABELMEMBER
* ou NET_SHEETBUSLABELMEMBER
* entree = pointeur sur l'ObjetNetListStruct initialise corresp au buslabel
* suppose que FirstNumWireBus, LastNumWireBus et RootBusNameLength sont a jour
* modifie l'ObjetNetListStruct de base et remplit les suivants
* m_Label is a pointer to a new wxString
* m_Label must be deallocated by the user (only for a NET_GLOBBUSLABELMEMBER,
* NET_BUSLABELMEMBER or a NET_SHEETBUSLABELMEMBER object type)
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int NumItem, BusMember;
wxString BufLine;
if( BusLabel->m_Type == NET_HIERLABEL )
BusLabel->m_Type = NET_HIERBUSLABELMEMBER;
2008-03-20 01:50:21 +00:00
else if( BusLabel->m_Type == NET_GLOBLABEL )
BusLabel->m_Type = NET_GLOBBUSLABELMEMBER;
2007-09-20 21:06:49 +00:00
else if( BusLabel->m_Type == NET_SHEETLABEL )
BusLabel->m_Type = NET_SHEETBUSLABELMEMBER;
else
BusLabel->m_Type = NET_BUSLABELMEMBER;
/* Convertion du BusLabel en la racine du Label + le numero du fil */
BufLine = BusLabel->m_Label->Left( RootBusNameLength );
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
BusMember = FirstNumWireBus;
BufLine << BusMember;
BusLabel->m_Label = new wxString( BufLine );
BusLabel->m_Member = BusMember;
NumItem = 1;
for( BusMember++; BusMember <= LastNumWireBus; BusMember++ )
{
*(BusLabel + 1) = *BusLabel; //copy constructor.
2008-03-20 01:50:21 +00:00
BusLabel++;
2007-09-21 04:40:12 +00:00
NumItem++;
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
/* Convertion du BusLabel en la racine du Label + le numero du fil */
BufLine = BusLabel->m_Label->Left( RootBusNameLength );
BufLine << BusMember;
BusLabel->m_Label = new wxString( BufLine );
BusLabel->m_Member = BusMember;
}
return NumItem;
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/**********************************************************************/
static void PropageNetCode( int OldNetCode, int NewNetCode, int IsBus )
/**********************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* PropageNetCode propage le netcode NewNetCode sur tous les elements
2007-09-20 21:06:49 +00:00
* appartenant a l'ancien netcode OldNetCode
* Si IsBus == 0; c'est le membre NetCode qui est propage
* Si IsBus != 0; c'est le membre BusNetCode qui est propage
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int jj;
ObjetNetListStruct* Objet = g_TabObjNet;
if( OldNetCode == NewNetCode )
return;
#if defined(NETLIST_DEBUG) && defined(DEBUG)
2008-03-20 01:50:21 +00:00
printf("replacing net %d with %d\n", OldNetCode,NewNetCode);
#endif
2007-09-20 21:06:49 +00:00
if( IsBus == 0 ) /* Propagation du NetCode */
{
for( jj = 0; jj < g_NbrObjNet; jj++, Objet++ )
{
2007-10-13 06:18:44 +00:00
if( Objet->GetNet() == OldNetCode )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
Objet->SetNet( NewNetCode );
2007-09-20 21:06:49 +00:00
}
}
}
else /* Propagation du BusNetCode */
{
for( jj = 0; jj < g_NbrObjNet; jj++, Objet++ )
{
if( Objet->m_BusNetCode == OldNetCode )
{
Objet->m_BusNetCode = NewNetCode;
}
}
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/***************************************************************************/
2007-09-20 21:06:49 +00:00
static void PointToPointConnect( ObjetNetListStruct* Ref, int IsBus, int start )
2007-05-06 16:03:28 +00:00
/***************************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine qui verifie si l'element *Ref est connecte a
2007-09-20 21:06:49 +00:00
* d'autres elements de la liste des objets du schema, selon le mode Point
* a point ( Extremites superposees )
2008-03-20 01:50:21 +00:00
*
2007-09-20 21:06:49 +00:00
* si IsBus:
* la connexion ne met en jeu que des elements type bus
* ( BUS ou BUSLABEL ou JONCTION )
* sinon
* la connexion ne met en jeu que des elements type non bus
* ( autres que BUS ou BUSLABEL )
2008-03-20 01:50:21 +00:00
*
2007-09-20 21:06:49 +00:00
* L'objet Ref doit avoir un NetCode valide.
2008-03-20 01:50:21 +00:00
*
* La liste des objets est supposee classe par SheetPath Croissants,
2007-09-20 21:06:49 +00:00
* et la recherche se fait a partir de l'element start, 1er element
* de la feuille de schema
* ( il ne peut y avoir connexion physique entre elements de differentes sheets)
*/
2007-05-06 16:03:28 +00:00
{
2007-09-21 04:40:12 +00:00
int i, netCode;
ObjetNetListStruct* netTable = g_TabObjNet;
2007-09-20 21:06:49 +00:00
if( IsBus == 0 ) /* Objets autres que BUS et BUSLABELS */
{
2007-10-13 06:18:44 +00:00
netCode = Ref->GetNet();
2007-09-20 21:06:49 +00:00
for( i = start; i < g_NbrObjNet; i++ )
{
2008-03-20 01:50:21 +00:00
if( netTable[i].m_SheetList != Ref->m_SheetList ) //used to be > (why?)
continue;
2008-03-20 01:50:21 +00:00
2007-09-21 04:40:12 +00:00
switch( netTable[i].m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_SEGMENT:
case NET_PIN:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_JONCTION:
case NET_NOCONNECT:
2007-09-21 04:40:12 +00:00
if( Ref->m_Start == netTable[i].m_Start
2008-03-20 01:50:21 +00:00
|| Ref->m_Start == netTable[i].m_End
2007-09-21 04:40:12 +00:00
|| Ref->m_End == netTable[i].m_Start
|| Ref->m_End == netTable[i].m_End )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
if( netTable[i].GetNet() == 0 )
netTable[i].SetNet( netCode );
2007-09-20 21:06:49 +00:00
else
2007-10-13 06:18:44 +00:00
PropageNetCode( netTable[i].GetNet(), netCode, 0 );
2007-09-20 21:06:49 +00:00
}
break;
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
break;
}
}
}
2008-03-20 01:50:21 +00:00
2007-09-20 21:06:49 +00:00
else /* Objets type BUS et BUSLABELS ( et JONCTIONS )*/
{
2007-09-21 04:40:12 +00:00
netCode = Ref->m_BusNetCode;
for( i = start; i<g_NbrObjNet; i++ )
2007-09-20 21:06:49 +00:00
{
if( netTable[i].m_SheetList != Ref->m_SheetList )
continue;
2007-09-20 21:06:49 +00:00
2007-09-21 04:40:12 +00:00
switch( netTable[i].m_Type )
2007-09-20 21:06:49 +00:00
{
case NET_SEGMENT:
case NET_PIN:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_NOCONNECT:
break;
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
case NET_JONCTION:
2007-09-21 04:40:12 +00:00
if( Ref->m_Start == netTable[i].m_Start
2008-03-20 01:50:21 +00:00
|| Ref->m_Start == netTable[i].m_End
2007-09-21 04:40:12 +00:00
|| Ref->m_End == netTable[i].m_Start
|| Ref->m_End == netTable[i].m_End )
2007-09-20 21:06:49 +00:00
{
2007-09-21 04:40:12 +00:00
if( netTable[i].m_BusNetCode == 0 )
netTable[i].m_BusNetCode = netCode;
2007-09-20 21:06:49 +00:00
else
2007-09-21 04:40:12 +00:00
PropageNetCode( netTable[i].m_BusNetCode, netCode, 1 );
2007-09-20 21:06:49 +00:00
}
break;
}
}
}
2007-05-06 16:03:28 +00:00
}
/**************************************************************/
2007-09-20 21:06:49 +00:00
static void SegmentToPointConnect( ObjetNetListStruct* Jonction,
int IsBus, int start )
2007-05-06 16:03:28 +00:00
/***************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*
2007-09-20 21:06:49 +00:00
* Routine qui recherche si un point (jonction) est connecte a des segments,
* et regroupe les NetCodes des objets connectes a la jonction.
* Le point de jonction doit avoir un netcode valide
* La liste des objets est supposee classe par NumSheet Croissants,
* et la recherche se fait a partir de l'element start, 1er element
* de la feuille de schema
* ( il ne peut y avoir connexion physique entre elements de differentes sheets)
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
int i;
ObjetNetListStruct* Segment = g_TabObjNet;
for( i = start; i < g_NbrObjNet; i++ )
{
if( Segment[i].m_SheetList != Jonction->m_SheetList )
continue;
2007-09-20 21:06:49 +00:00
if( IsBus == 0 )
{
if( Segment[i].m_Type != NET_SEGMENT )
continue;
}
else
{
if( Segment[i].m_Type != NET_BUS )
continue;
}
if( SegmentIntersect( Segment[i].m_Start.x, Segment[i].m_Start.y,
Segment[i].m_End.x, Segment[i].m_End.y,
Jonction->m_Start.x, Jonction->m_Start.y ) )
{
/* Propagation du Netcode a tous les Objets de meme NetCode */
if( IsBus == 0 )
{
2007-10-13 06:18:44 +00:00
if( Segment[i].GetNet() )
PropageNetCode( Segment[i].GetNet(),
Jonction->GetNet(), IsBus );
2007-09-20 21:06:49 +00:00
else
2007-10-13 06:18:44 +00:00
Segment[i].SetNet( Jonction->GetNet() );
2007-09-20 21:06:49 +00:00
}
else
{
if( Segment[i].m_BusNetCode )
PropageNetCode( Segment[i].m_BusNetCode,
Jonction->m_BusNetCode, IsBus );
else
Segment[i].m_BusNetCode = Jonction->m_BusNetCode;
}
}
}
2007-05-06 16:03:28 +00:00
}
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/*****************************************************************
2007-09-21 04:40:12 +00:00
* Function which connects the groups of object which have the same label
2007-09-20 21:06:49 +00:00
*******************************************************************/
static void LabelConnect( ObjetNetListStruct* LabelRef )
2007-05-06 16:03:28 +00:00
{
2007-10-13 06:18:44 +00:00
if( LabelRef->GetNet() == 0 )
2007-09-20 21:06:49 +00:00
return;
2007-09-21 04:40:12 +00:00
ObjetNetListStruct* netTable = g_TabObjNet;
2007-09-20 21:06:49 +00:00
2007-09-21 04:40:12 +00:00
for( int i=0; i<g_NbrObjNet; i++ )
2007-09-20 21:06:49 +00:00
{
2007-10-13 06:18:44 +00:00
if( netTable[i].GetNet() == LabelRef->GetNet() )
2007-09-20 21:06:49 +00:00
continue;
2008-03-20 01:50:21 +00:00
if( netTable[i].m_SheetList != LabelRef->m_SheetList )
2007-09-20 21:06:49 +00:00
{
2008-03-20 01:50:21 +00:00
if( (netTable[i].m_Type != NET_PINLABEL
&& netTable[i].m_Type != NET_GLOBLABEL
&& netTable[i].m_Type != NET_GLOBBUSLABELMEMBER) )
continue;
if( (netTable[i].m_Type == NET_GLOBLABEL
|| netTable[i].m_Type == NET_GLOBBUSLABELMEMBER)
&& netTable[i].m_Type != LabelRef->m_Type)
//global labels only connect other global labels.
2007-09-20 21:06:49 +00:00
continue;
}
2008-03-20 01:50:21 +00:00
//regular labels are sheet-local;
//NET_HIERLABEL are used to connect sheets.
//NET_LABEL is sheet-local (***)
//NET_GLOBLABEL is global.
if( netTable[i].m_Type == NET_LABEL
2007-09-21 04:40:12 +00:00
|| netTable[i].m_Type == NET_GLOBLABEL
2008-03-20 01:50:21 +00:00
|| netTable[i].m_Type == NET_HIERLABEL
2007-09-21 04:40:12 +00:00
|| netTable[i].m_Type == NET_BUSLABELMEMBER
|| netTable[i].m_Type == NET_GLOBBUSLABELMEMBER
2008-03-20 01:50:21 +00:00
|| netTable[i].m_Type == NET_HIERBUSLABELMEMBER
2007-09-21 04:40:12 +00:00
|| netTable[i].m_Type == NET_PINLABEL )
2007-09-20 21:06:49 +00:00
{
2007-09-21 04:40:12 +00:00
if( netTable[i].m_Label->CmpNoCase( *LabelRef->m_Label ) != 0 )
2007-09-20 21:06:49 +00:00
continue;
2008-03-20 01:50:21 +00:00
// Propagation du Netcode a tous les Objets de meme NetCode
2007-10-13 06:18:44 +00:00
if( netTable[i].GetNet() )
PropageNetCode( netTable[i].GetNet(), LabelRef->GetNet(), 0 );
2007-09-20 21:06:49 +00:00
else
2007-10-13 06:18:44 +00:00
netTable[i].SetNet( LabelRef->GetNet() );
2007-09-20 21:06:49 +00:00
}
}
2007-05-06 16:03:28 +00:00
}
/****************************************************************************/
2007-09-20 21:06:49 +00:00
static int TriNetCode( const void* o1, const void* o2 )
2007-05-06 16:03:28 +00:00
/****************************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine de comparaison pour le tri par NetCode croissant
2007-09-20 21:06:49 +00:00
* du tableau des elements connectes ( TabPinSort ) par qsort()
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* Objet1 = (ObjetNetListStruct*) o1;
ObjetNetListStruct* Objet2 = (ObjetNetListStruct*) o2;
2008-03-20 01:50:21 +00:00
2007-10-13 06:18:44 +00:00
return Objet1->GetNet() - Objet2->GetNet();
2007-05-06 16:03:28 +00:00
}
/*****************************************************************************/
2007-09-20 21:06:49 +00:00
static int TriBySheet( const void* o1, const void* o2 )
2007-05-06 16:03:28 +00:00
/*****************************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine de comparaison pour le tri par NumSheet
2007-09-20 21:06:49 +00:00
* du tableau des elements connectes ( TabPinSort ) par qsort() */
2007-05-06 16:03:28 +00:00
{
2008-03-20 01:50:21 +00:00
ObjetNetListStruct* Objet1 = (ObjetNetListStruct*) o1;
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* Objet2 = (ObjetNetListStruct*) o2;
2008-03-20 01:50:21 +00:00
return Objet1->m_SheetList.Cmp(Objet2->m_SheetList);
2007-05-06 16:03:28 +00:00
}
/**********************************************************************/
2007-09-20 21:06:49 +00:00
static void SetUnconnectedFlag( ObjetNetListStruct* ListObj, int NbItems )
2007-05-06 16:03:28 +00:00
/**********************************************************************/
2007-09-20 21:06:49 +00:00
2007-05-06 16:03:28 +00:00
/* Routine positionnant le membre .FlagNoConnect des elements de
2007-09-20 21:06:49 +00:00
* la liste des objets netliste, tries par ordre de NetCode
*/
2007-05-06 16:03:28 +00:00
{
2007-09-20 21:06:49 +00:00
ObjetNetListStruct* NetItemRef, * NetItemTst, * ItemPtr;
ObjetNetListStruct* NetStart, * NetEnd, * Lim;
int Nb;
IsConnectType StateFlag;
NetStart = NetEnd = ListObj;
NetItemRef = NetStart;
2008-03-20 01:50:21 +00:00
Nb = 0;
2007-09-20 21:06:49 +00:00
StateFlag = UNCONNECT;
Lim = ListObj + NbItems;
for( ; NetItemRef < Lim; NetItemRef++ )
{
if( NetItemRef->m_Type == NET_NOCONNECT )
2008-01-05 17:30:56 +00:00
if( StateFlag != PAD_CONNECT )
2007-09-20 21:06:49 +00:00
StateFlag = NOCONNECT;
/* Analyse du net en cours */
NetItemTst = NetItemRef + 1;
if( (NetItemTst >= Lim)
2007-10-13 06:18:44 +00:00
|| (NetItemRef->GetNet() != NetItemTst->GetNet()) )
2008-03-20 01:50:21 +00:00
{
2007-09-20 21:06:49 +00:00
/* Net analyse: mise a jour de m_FlagOfConnection */
NetEnd = NetItemTst;
for( ItemPtr = NetStart; ItemPtr < NetEnd; ItemPtr++ )
{
ItemPtr->m_FlagOfConnection = StateFlag;
}
if( NetItemTst >= Lim )
return;
/* Start Analyse Nouveau Net */
StateFlag = UNCONNECT;
NetStart = NetItemTst;
continue;
}
for( ; ; NetItemTst++ )
{
if( (NetItemTst >= Lim)
2007-10-13 06:18:44 +00:00
|| (NetItemRef->GetNet() != NetItemTst->GetNet()) )
2007-09-20 21:06:49 +00:00
break;
switch( NetItemTst->m_Type )
{
case NET_SEGMENT:
case NET_LABEL:
case NET_HIERLABEL:
2008-03-20 01:50:21 +00:00
case NET_GLOBLABEL:
2007-09-20 21:06:49 +00:00
case NET_SHEETLABEL:
case NET_PINLABEL:
case NET_BUS:
case NET_BUSLABELMEMBER:
case NET_SHEETBUSLABELMEMBER:
case NET_HIERBUSLABELMEMBER:
2008-03-20 01:50:21 +00:00
case NET_GLOBBUSLABELMEMBER:
2007-09-20 21:06:49 +00:00
case NET_JONCTION:
break;
case NET_PIN:
if( NetItemRef->m_Type == NET_PIN )
2008-01-05 17:30:56 +00:00
StateFlag = PAD_CONNECT;
2007-09-20 21:06:49 +00:00
break;
case NET_NOCONNECT:
2008-01-05 17:30:56 +00:00
if( StateFlag != PAD_CONNECT )
2007-09-20 21:06:49 +00:00
StateFlag = NOCONNECT;
break;
}
}
}
2007-05-06 16:03:28 +00:00
}