2007-08-20 19:33:15 +00:00
|
|
|
/************************************/
|
|
|
|
/* PCBNEW: traitement des netlistes */
|
|
|
|
/************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
/* Fichier NETLIST.CPP */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Fonction de lecture de la netliste pour:
|
|
|
|
* - Chargement modules et nouvelles connexions
|
|
|
|
* - Test des modules (modules manquants ou en trop
|
|
|
|
* - Recalcul du chevelu
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Remarque importante:
|
|
|
|
* Lors de la lecture de la netliste pour Chargement modules
|
|
|
|
* et nouvelles connexions, l'identification des modules peut se faire selon
|
|
|
|
* 2 criteres:
|
|
|
|
* - la reference (U2, R5 ..): c'est le mode normal
|
|
|
|
* - le Time Stamp (Signature Temporelle), a utiliser apres reannotation
|
|
|
|
* d'un schema, donc apres modification des references sans pourtant
|
|
|
|
* avoir reellement modifie le schema
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "autorout.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
#define TESTONLY 1 /* ctes utilisees lors de l'appel a */
|
2008-03-22 18:08:44 +00:00
|
|
|
#define READMODULE 0 /* ReadPcbNetlist() */
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Structures locales */
|
|
|
|
class MODULEtoLOAD : public EDA_BaseStruct
|
|
|
|
{
|
|
|
|
public:
|
2007-08-20 19:33:15 +00:00
|
|
|
wxString m_LibName;
|
|
|
|
wxString m_CmpName;
|
2008-02-19 00:28:42 +00:00
|
|
|
wxString m_Path;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2008-02-19 00:28:42 +00:00
|
|
|
MODULEtoLOAD( const wxString& libname,
|
|
|
|
const wxString& cmpname,
|
2008-03-22 18:08:44 +00:00
|
|
|
int timestamp,
|
|
|
|
const wxString& path );
|
2007-09-01 12:00:30 +00:00
|
|
|
~MODULEtoLOAD() { };
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
MODULEtoLOAD* Next() const { return (MODULEtoLOAD*) Pnext; }
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Fonctions locales : */
|
2008-03-22 18:08:44 +00:00
|
|
|
static void SortListModulesToLoadByLibname( int NbModules );
|
|
|
|
static void TestFor_Duplicate_Missing_And_Extra_Footprints( wxWindow* frame,
|
|
|
|
const wxString& NetlistFullFilename,
|
|
|
|
BOARD* Pcb );
|
|
|
|
static int BuildFootprintsListFromNetlistFile( const wxString& aNetlistFullFilename,
|
|
|
|
wxArrayString& aBufName );
|
|
|
|
static bool OpenNetlistFile( const wxString& aFullFileName );
|
|
|
|
static void AddToList( const wxString& NameLibCmp,
|
|
|
|
const wxString& NameCmp,
|
|
|
|
int TimeStamp,
|
|
|
|
const wxString& path );
|
|
|
|
static int SetPadNetName( wxWindow* aFrame, char* Text, MODULE* Module );
|
|
|
|
static void ReadPcbNetlist( WinEDA_PcbFrame* aFrame,
|
|
|
|
const wxString& aNetlistFullFilename,
|
|
|
|
const wxString& aCmpFullFileName,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
bool aChangeFootprint,
|
|
|
|
bool aDeleteBadTracks,
|
|
|
|
bool aDeleteExtraFootprints,
|
|
|
|
bool aSelect_By_Timestamp,
|
|
|
|
bool aVerbose );
|
|
|
|
static int ReadListeModules( const wxString& CmpFullFileName,
|
|
|
|
const wxString* RefCmp,
|
|
|
|
long TimeStamp,
|
|
|
|
wxString& NameModule );
|
|
|
|
static MODULE* ReadNetModule( WinEDA_PcbFrame* aFrame,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
const wxString& CmpFullFileName,
|
|
|
|
char* Text,
|
|
|
|
int* UseFichCmp,
|
|
|
|
int TstOnly,
|
|
|
|
bool Select_By_Timestamp,
|
|
|
|
bool aChangeFootprint );
|
|
|
|
static void LoadListeModules( WinEDA_PcbFrame* aPcbFrame, wxDC* DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Variables locales */
|
2007-08-20 19:33:15 +00:00
|
|
|
static int s_NbNewModules;
|
|
|
|
static MODULEtoLOAD* s_ModuleToLoad_List;
|
|
|
|
FILE* source;
|
|
|
|
static int DisplayWarningCount;
|
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
/* class WinEDA_NetlistFrame */
|
|
|
|
/*****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "dialog_netlist.cpp"
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
void WinEDA_PcbFrame::InstallNetlistFrame( wxDC* DC, const wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Setup the default netlist file name according to the board file name */
|
|
|
|
wxString default_netfilename = GetScreen()->m_FileName;
|
|
|
|
|
|
|
|
ChangeFileNameExt( default_netfilename, NetExtBuffer );
|
|
|
|
|
|
|
|
WinEDA_NetlistFrame* frame = new WinEDA_NetlistFrame( this, DC, default_netfilename );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
frame->ShowModal(); frame->Destroy();
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/************************************************************************/
|
|
|
|
bool OpenNetlistFile( const wxString& aFullFileName )
|
|
|
|
/************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2007-08-20 19:33:15 +00:00
|
|
|
* routine de selection et d'ouverture du fichier Netlist
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aFullFileName.IsEmpty() )
|
|
|
|
return FALSE; /* No filename: exit */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
source = wxFopen( aFullFileName, wxT( "rt" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
if( source == 0 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Netlist file %s not found" ), aFullFileName.GetData() );
|
|
|
|
DisplayError( NULL, msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
return TRUE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/*******************************************************************************/
|
|
|
|
void ReadPcbNetlist( WinEDA_PcbFrame* aFrame,
|
|
|
|
const wxString& aNetlistFullFilename,
|
|
|
|
const wxString& aCmpFullFileName,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
bool aChangeFootprint,
|
|
|
|
bool aDeleteBadTracks,
|
|
|
|
bool aDeleteExtraFootprints,
|
|
|
|
bool aSelect_By_Timestamp,
|
|
|
|
bool aVerbose )
|
|
|
|
/********************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* mise a jour des empreintes :
|
2007-08-20 19:33:15 +00:00
|
|
|
* corrige les Net Names, les textes, les "TIME STAMP"
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Analyse les lignes:
|
|
|
|
# EESchema Netlist Version 1.0 generee le 18/5/2005-12:30:22
|
|
|
|
* (
|
|
|
|
* ( 40C08647 $noname R20 4,7K {Lib=R}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 MODB_1 )
|
|
|
|
* )
|
|
|
|
* ( 40C0863F $noname R18 4,7_k {Lib=R}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 MODA_1 )
|
|
|
|
* )
|
|
|
|
* }
|
|
|
|
#End
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
int LineNum, State, Comment;
|
|
|
|
MODULE* Module = NULL;
|
|
|
|
D_PAD* PtPad;
|
2008-02-19 00:28:42 +00:00
|
|
|
char Line[256];
|
|
|
|
char* Text;
|
2007-08-20 19:33:15 +00:00
|
|
|
int UseFichCmp = 1;
|
|
|
|
wxString msg;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aVerbose )
|
2007-08-20 19:33:15 +00:00
|
|
|
DisplayWarningCount = 8;
|
|
|
|
else
|
|
|
|
DisplayWarningCount = 0;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( !OpenNetlistFile( aNetlistFullFilename ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
msg = _( "Read Netlist " ) + aNetlistFullFilename;
|
|
|
|
if( aMessageWindow )
|
|
|
|
aMessageWindow->AppendText( msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
aFrame->GetScreen()->SetModify();
|
2008-03-22 18:08:44 +00:00
|
|
|
aFrame->m_Pcb->m_Status_Pcb = 0; State = 0; LineNum = 0; Comment = 0;
|
2007-08-20 19:33:15 +00:00
|
|
|
s_NbNewModules = 0;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
wxBusyCursor dummy; // Shows an hourglass while calculating
|
|
|
|
|
|
|
|
/* First read of the netlist: Build the list of footprints to load (new footprints)
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
while( GetLine( source, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
Text = StrPurge( Line );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( Comment ) /* Comments in progress */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
Comment = 0;
|
|
|
|
}
|
2008-03-22 18:08:44 +00:00
|
|
|
if( *Text == '{' ) /* Start Comment */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
Comment = 1;
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *Text == '(' )
|
|
|
|
State++;
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( *Text == ')' )
|
|
|
|
State--;
|
|
|
|
|
|
|
|
if( State == 2 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = ReadNetModule( aFrame,
|
|
|
|
aMessageWindow,
|
|
|
|
aCmpFullFileName,
|
|
|
|
Text,
|
|
|
|
&UseFichCmp,
|
|
|
|
TESTONLY,
|
|
|
|
aSelect_By_Timestamp,
|
|
|
|
aChangeFootprint );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( State >= 3 ) /* la ligne de description d'un pad est ici non analysee */
|
|
|
|
{
|
|
|
|
State--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Load new footprints */
|
2007-08-20 19:33:15 +00:00
|
|
|
if( s_NbNewModules )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
LoadListeModules( aFrame, NULL );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
// Free module list:
|
|
|
|
MODULEtoLOAD* item, * next_item;
|
|
|
|
for( item = s_ModuleToLoad_List; item != NULL; item = next_item )
|
|
|
|
{
|
|
|
|
next_item = item->Next();
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_ModuleToLoad_List = NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Second read , All footprints are on board, one must update the schematic info (pad netnames) */
|
2007-08-20 19:33:15 +00:00
|
|
|
fseek( source, 0, SEEK_SET ); LineNum = 0;
|
|
|
|
while( GetLine( source, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
Text = StrPurge( Line );
|
|
|
|
|
|
|
|
if( Comment ) /* Commentaires en cours */
|
|
|
|
{
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
Comment = 0;
|
|
|
|
}
|
|
|
|
if( *Text == '{' ) /* Commentaires */
|
|
|
|
{
|
|
|
|
Comment = 1;
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *Text == '(' )
|
|
|
|
State++;
|
|
|
|
if( *Text == ')' )
|
|
|
|
State--;
|
|
|
|
|
|
|
|
if( State == 2 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = ReadNetModule( aFrame,
|
|
|
|
aMessageWindow,
|
|
|
|
aCmpFullFileName,
|
|
|
|
Text,
|
|
|
|
&UseFichCmp,
|
|
|
|
READMODULE,
|
|
|
|
aSelect_By_Timestamp,
|
|
|
|
aChangeFootprint );
|
2007-08-20 19:33:15 +00:00
|
|
|
if( Module == NULL )
|
|
|
|
{ /* empreinte non trouvee dans la netliste */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else /* Raz netnames sur pads */
|
|
|
|
{
|
|
|
|
PtPad = Module->m_Pads;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; PtPad != NULL; PtPad = (D_PAD*) PtPad->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
PtPad->SetNetname( wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( State >= 3 )
|
|
|
|
{
|
|
|
|
if( Module )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
SetPadNetName( NULL, Text, Module );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
State--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
// Delete footprints not found in netlist:
|
|
|
|
if ( aDeleteExtraFootprints )
|
|
|
|
{
|
|
|
|
wxArrayString ModuleListFromNetlist;
|
|
|
|
/* Build list of modules in the netlist */
|
|
|
|
int NbModulesNetListe = BuildFootprintsListFromNetlistFile( aNetlistFullFilename, ModuleListFromNetlist );
|
|
|
|
if( NbModulesNetListe )
|
|
|
|
{
|
|
|
|
MODULE * NextModule;
|
|
|
|
Module = aFrame->m_Pcb->m_Modules;
|
|
|
|
bool ask_for_confirmation = true;
|
|
|
|
for( ; Module != NULL; Module = NextModule )
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
NextModule = Module->Next();
|
|
|
|
if ( (Module->m_ModuleStatus & MODULE_is_LOCKED) )
|
|
|
|
continue;
|
|
|
|
for( ii = 0; ii < NbModulesNetListe; ii++ )
|
|
|
|
{
|
|
|
|
if( Module->m_Reference->m_Text.CmpNoCase(
|
|
|
|
ModuleListFromNetlist[ii] ) == 0 )
|
|
|
|
{
|
|
|
|
break; /* Module trouve en netliste */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == NbModulesNetListe ) /* Module not found in netlist */
|
|
|
|
{
|
|
|
|
if ( ask_for_confirmation )
|
|
|
|
{
|
|
|
|
ask_for_confirmation = false;
|
|
|
|
if ( ! IsOK( NULL, _("Ok to delete footprints not in netlist ?") ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aFrame->Delete_Module( Module, NULL, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Rebuild the connectivity */
|
|
|
|
aFrame->Compile_Ratsnest( NULL, TRUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aFrame->m_Pcb->m_Track )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aDeleteBadTracks ) // Remove erroneous tracks
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
Netliste_Controle_piste( aFrame, NULL, TRUE );
|
|
|
|
aFrame->Compile_Ratsnest( NULL, TRUE );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
aFrame->DrawPanel->Refresh();
|
|
|
|
aFrame->m_Pcb->Display_Infos( aFrame );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
MODULE* ReadNetModule( WinEDA_PcbFrame* aFrame,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
const wxString& aCmpFullFileName,
|
|
|
|
char* Text,
|
|
|
|
int* UseFichCmp,
|
|
|
|
int TstOnly,
|
|
|
|
bool aSelect_By_Timestamp,
|
|
|
|
bool aChangeFootprint )
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/* charge la description d'une empreinte, netliste type PCBNEW
|
2007-08-20 19:33:15 +00:00
|
|
|
* et met a jour le module correspondant
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Si TstOnly == 0 si le module n'existe pas, il est charge
|
|
|
|
* Si TstOnly != 0 si le module n'existe pas, il est ajoute a la liste des
|
|
|
|
* modules a charger
|
|
|
|
* Text contient la premiere ligne de la description
|
|
|
|
* UseFichCmp est un flag
|
|
|
|
* si != 0, le fichier des composants .CMP sera utilise
|
|
|
|
* est remis a 0 si le fichier n'existe pas
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Analyse les lignes type:
|
|
|
|
* ( 40C08647 $noname R20 4,7K {Lib=R}
|
|
|
|
* ( 1 VCC )
|
|
|
|
* ( 2 MODB_1 )
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULE* Module;
|
|
|
|
char* text;
|
|
|
|
wxString TextTimeStamp;
|
|
|
|
wxString TextNameLibMod;
|
|
|
|
wxString TextValeur;
|
|
|
|
wxString TextCmpName;
|
|
|
|
wxString NameLibCmp;
|
|
|
|
unsigned long TimeStamp = 0;
|
|
|
|
int Error = 0;
|
|
|
|
char Line[1024];
|
|
|
|
bool Found;
|
|
|
|
|
|
|
|
strcpy( Line, Text );
|
|
|
|
|
|
|
|
TextValeur = wxT( "~" );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( Line, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
else
|
|
|
|
TextTimeStamp = CONV_FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
else
|
|
|
|
TextNameLibMod = CONV_FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
else
|
|
|
|
TextCmpName = CONV_FROM_UTF8( text );
|
2008-02-19 00:28:42 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = -1;
|
|
|
|
else
|
|
|
|
TextValeur = CONV_FROM_UTF8( text );
|
|
|
|
|
|
|
|
if( Error > 0 )
|
|
|
|
return NULL;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString LocalTimeStamp = TextTimeStamp.AfterLast( '/' );
|
2008-02-12 21:12:46 +00:00
|
|
|
LocalTimeStamp.ToULong( &TimeStamp, 16 );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
/* Tst si composant deja charge */
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = aFrame->m_Pcb->m_Modules;
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULE* NextModule;
|
|
|
|
for( Found = FALSE; Module != NULL; Module = NextModule )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
NextModule = Module->Next();
|
|
|
|
if( aSelect_By_Timestamp ) /* Reconnaissance par signature temporelle */
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
//if( TimeStamp == Module->m_TimeStamp )
|
2008-03-22 18:08:44 +00:00
|
|
|
if( TextTimeStamp.CmpNoCase( Module->m_Path ) )
|
2008-02-19 00:28:42 +00:00
|
|
|
Found = TRUE;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else /* Reconnaissance par Reference */
|
|
|
|
{
|
|
|
|
if( TextCmpName.CmpNoCase( Module->m_Reference->m_Text ) == 0 )
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
|
|
|
if( Found ) // Test si module (m_LibRef) et module specifie en netlist concordent
|
|
|
|
{
|
|
|
|
if( TstOnly != TESTONLY )
|
|
|
|
{
|
|
|
|
NameLibCmp = TextNameLibMod;
|
|
|
|
if( *UseFichCmp )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aSelect_By_Timestamp )
|
2007-08-20 19:33:15 +00:00
|
|
|
{ /* Reconnaissance par signature temporelle */
|
2008-03-22 18:08:44 +00:00
|
|
|
*UseFichCmp = ReadListeModules( aCmpFullFileName,
|
|
|
|
NULL,
|
|
|
|
TimeStamp,
|
|
|
|
NameLibCmp );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else /* Reconnaissance par Reference */
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
*UseFichCmp = ReadListeModules( aCmpFullFileName,
|
|
|
|
&TextCmpName,
|
|
|
|
0l,
|
|
|
|
NameLibCmp );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if( Module->m_LibRef.CmpNoCase( NameLibCmp ) != 0 )
|
|
|
|
{ // Module Mismatch: Current module and module specified in netlist are diff.
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aChangeFootprint )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
MODULE* NewModule =
|
2008-03-22 18:08:44 +00:00
|
|
|
aFrame->Get_Librairie_Module( NULL, wxEmptyString, NameLibCmp, TRUE );
|
|
|
|
if( NewModule ) /* Nouveau module trouve : changement de module */
|
|
|
|
Module = aFrame->Exchange_Module( NULL, Module, NewModule );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg;
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aMessageWindow )
|
|
|
|
{
|
|
|
|
msg.Printf(
|
|
|
|
_( "Cmp %s: Mismatch! module is [%s] and netlist said [%s]\n" ),
|
|
|
|
TextCmpName.GetData(), Module->m_LibRef.GetData(),
|
|
|
|
NameLibCmp.GetData() );
|
|
|
|
aMessageWindow->AppendText( msg );
|
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
if( DisplayWarningCount > 0 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
DisplayError( NULL, msg, 2 );
|
2007-08-20 19:33:15 +00:00
|
|
|
DisplayWarningCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Module == NULL ) /* Module a charger */
|
|
|
|
{
|
|
|
|
NameLibCmp = TextNameLibMod;
|
|
|
|
|
|
|
|
if( *UseFichCmp )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aSelect_By_Timestamp == 1 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{ /* Reconnaissance par signature temporelle */
|
2008-03-22 18:08:44 +00:00
|
|
|
*UseFichCmp = ReadListeModules( aCmpFullFileName, NULL, TimeStamp, NameLibCmp );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else /* Reconnaissance par Reference */
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
*UseFichCmp = ReadListeModules( aCmpFullFileName, &TextCmpName, 0l, NameLibCmp );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if( TstOnly == TESTONLY )
|
2008-02-19 00:28:42 +00:00
|
|
|
AddToList( NameLibCmp, TextCmpName, TimeStamp, TextTimeStamp );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aMessageWindow && (DisplayWarningCount> 0) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Component [%s] not found" ), TextCmpName.GetData() );
|
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
|
|
|
DisplayError( NULL, msg, 2 );
|
2007-08-20 19:33:15 +00:00
|
|
|
DisplayWarningCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL; /* Le module n'avait pas pu etre charge */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mise a jour des reperes ( nom et ref "Time Stamp") si module charge */
|
|
|
|
Module->m_Reference->m_Text = TextCmpName;
|
|
|
|
Module->m_Value->m_Text = TextValeur;
|
|
|
|
Module->m_TimeStamp = TimeStamp;
|
2008-02-19 00:28:42 +00:00
|
|
|
Module->m_Path = TextTimeStamp;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
#if defined (DEBUG)
|
|
|
|
printf( "in ReadNetModule() m_Path = %s\n",
|
|
|
|
CONV_TO_UTF8( Module->m_Path ) );
|
2008-02-19 00:28:42 +00:00
|
|
|
#endif
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
return Module; /* composant trouve */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
int SetPadNetName( wxWindow* frame, char* Text, MODULE* Module )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/** Function SetPadNetName
|
|
|
|
* Update a pad netname in a given footprint
|
|
|
|
* @param Text = Text from netlist (format: (pad = net) )
|
|
|
|
* @param Module = the given footprint
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
char* TextPinName, * TextNetName;
|
|
|
|
int Error = 0;
|
|
|
|
bool trouve;
|
|
|
|
char Line[256];
|
|
|
|
wxString Msg;
|
|
|
|
|
|
|
|
if( Module == NULL )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
strcpy( Line, Text );
|
|
|
|
|
|
|
|
if( ( TextPinName = strtok( Line, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
if( ( TextNetName = strtok( NULL, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
if( Error )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* recherche du pad */
|
|
|
|
pad = Module->m_Pads; trouve = FALSE;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pad != NULL; pad = (D_PAD*) pad->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( strnicmp( TextPinName, pad->m_Padname, 4 ) == 0 )
|
|
|
|
{ /* trouve */
|
|
|
|
trouve = TRUE;
|
|
|
|
if( *TextNetName != '?' )
|
2008-12-14 19:45:05 +00:00
|
|
|
pad->SetNetname( CONV_FROM_UTF8( TextNetName ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
else
|
2008-12-14 19:45:05 +00:00
|
|
|
pad->SetNetname( wxEmptyString);
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !trouve && (DisplayWarningCount > 0) )
|
|
|
|
{
|
|
|
|
wxString pin_name = CONV_FROM_UTF8( TextPinName );
|
|
|
|
Msg.Printf( _( "Module [%s]: Pad [%s] not found" ),
|
2008-03-22 18:08:44 +00:00
|
|
|
Module->m_Reference->m_Text.GetData(), pin_name.GetData() );
|
|
|
|
DisplayError( frame, Msg, 1 );
|
2007-08-20 19:33:15 +00:00
|
|
|
DisplayWarningCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trouve;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
MODULE* WinEDA_PcbFrame::ListAndSelectModuleName( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* liste les noms des modules du PCB
|
2007-08-20 19:33:15 +00:00
|
|
|
* Retourne:
|
|
|
|
* un pointeur sur le module selectionne
|
|
|
|
* NULL si pas de selection
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
int ii, jj, nb_empr;
|
|
|
|
MODULE* Module;
|
|
|
|
WinEDAListBox* ListBox;
|
|
|
|
const wxChar** ListNames = NULL;
|
|
|
|
|
|
|
|
if( m_Pcb->m_Modules == NULL )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "No Modules" ) ); return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calcul du nombre des modules */
|
|
|
|
nb_empr = 0; Module = (MODULE*) m_Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
nb_empr++;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
ListNames = (const wxChar**) MyZMalloc( (nb_empr + 1) * sizeof(wxChar*) );
|
2007-08-20 19:33:15 +00:00
|
|
|
Module = (MODULE*) m_Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ii = 0; Module != NULL; Module = (MODULE*) Module->Next(), ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
ListNames[ii] = Module->m_Reference->m_Text.GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
ListBox = new WinEDAListBox( this, _( "Components" ),
|
2008-03-22 18:08:44 +00:00
|
|
|
ListNames, wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
ii = ListBox->ShowModal(); ListBox->Destroy();
|
|
|
|
|
|
|
|
|
|
|
|
if( ii < 0 ) /* Pas de selection */
|
|
|
|
{
|
|
|
|
Module = NULL;
|
|
|
|
}
|
|
|
|
else /* Recherche du module selectionne */
|
|
|
|
{
|
|
|
|
Module = (MODULE*) m_Pcb->m_Modules;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( jj = 0; Module != NULL; Module = (MODULE*) Module->Next(), jj++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( Module->m_Reference->m_Text.Cmp( ListNames[ii] ) == 0 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free( ListNames );
|
|
|
|
return Module;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/*****************************************************************************************/
|
|
|
|
void TestFor_Duplicate_Missing_And_Extra_Footprints( wxWindow* aFrame,
|
|
|
|
const wxString& aNetlistFullFilename,
|
|
|
|
BOARD* aPcb )
|
|
|
|
/******************************************************************************************/
|
|
|
|
|
|
|
|
/** Function TestFor_Duplicate_Missing_And_Extra_Footprints
|
|
|
|
* Build a list from the given board and netlist :
|
|
|
|
* 1 - for duplicate footprints on board
|
|
|
|
* 2 - for missing footprints
|
|
|
|
* 3 - for footprints not in netlist
|
|
|
|
* @param aFrame = current active frame
|
|
|
|
* @param aNetlistFullFilename = the given netlist
|
|
|
|
* @param aPcb = the given board
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
#define MAX_LEN_TXT 32
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
int ii;
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULE* Module, * pt_aux;
|
|
|
|
int NbModulesNetListe, nberr = 0;
|
|
|
|
WinEDA_TextFrame* List;
|
|
|
|
wxArrayString ModuleListFromNetlist;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aPcb->m_Modules == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
DisplayInfo( aFrame, _( "No modules" ), 10 ); return;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Construction de la liste des references des modules de la netliste */
|
2008-03-22 18:08:44 +00:00
|
|
|
NbModulesNetListe = BuildFootprintsListFromNetlistFile( aNetlistFullFilename, ModuleListFromNetlist );
|
2007-08-20 19:33:15 +00:00
|
|
|
if( NbModulesNetListe < 0 )
|
2008-03-22 18:08:44 +00:00
|
|
|
return; /* File not found */
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
if( NbModulesNetListe == 0 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
DisplayError( aFrame, _( "No modules in NetList" ), 10 ); return;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
List = new WinEDA_TextFrame( aFrame, _( "Check Modules" ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
/* recherche des doubles */
|
|
|
|
List->Append( _( "Duplicates" ) );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = aPcb->m_Modules;
|
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
pt_aux = Module->Next();
|
|
|
|
for( ; pt_aux != NULL; pt_aux = pt_aux->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( Module->m_Reference->m_Text.CmpNoCase( pt_aux->m_Reference->m_Text ) == 0 )
|
|
|
|
{
|
|
|
|
List->Append( Module->m_Reference->m_Text );
|
|
|
|
nberr++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recherche des manquants par rapport a la netliste*/
|
|
|
|
List->Append( _( "Lack:" ) );
|
|
|
|
|
|
|
|
for( ii = 0; ii < NbModulesNetListe; ii++ )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = (MODULE*) aPcb->m_Modules;
|
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
|
|
|
if( Module->m_Reference->m_Text.CmpNoCase(
|
|
|
|
ModuleListFromNetlist[ii] ) == 0 )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Module == NULL ) // Module missing, not found in board
|
|
|
|
{
|
|
|
|
List->Append( ModuleListFromNetlist[ii] );
|
|
|
|
nberr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* recherche des modules supplementaires (i.e. Non en Netliste) */
|
|
|
|
List->Append( _( "Not in Netlist:" ) );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = (MODULE*) aPcb->m_Modules;
|
2007-08-20 19:33:15 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
|
|
|
{
|
|
|
|
for( ii = 0; ii < NbModulesNetListe; ii++ )
|
|
|
|
{
|
|
|
|
if( Module->m_Reference->m_Text.CmpNoCase(
|
|
|
|
ModuleListFromNetlist[ii] ) == 0 )
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
break; /* Module trouve en netliste */
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ii == NbModulesNetListe ) /* Module not found in netlist */
|
|
|
|
{
|
|
|
|
List->Append( Module->m_Reference->m_Text );
|
|
|
|
nberr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List->ShowModal(); List->Destroy();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/***************************************************************************************/
|
|
|
|
int BuildFootprintsListFromNetlistFile( const wxString& aNetlistFullFilename, wxArrayString& aBufName )
|
|
|
|
/***************************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/** Function BuildFootprintsListFromNetlistFile
|
|
|
|
* Fill BufName with footprints names read from the netlist.
|
|
|
|
* @param aNetlistFullFilename = netlist file name
|
|
|
|
* @param BufName = wxArrayString to fill with footprint names
|
|
|
|
* @return Footprint count, or -1 if netlist file cannot opened
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
int textlen;
|
|
|
|
int nb_modules_lus;
|
|
|
|
int State, LineNum, Comment;
|
|
|
|
char Line[1024], * Text, * LibModName;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( !OpenNetlistFile( aNetlistFullFilename ) )
|
2007-08-20 19:33:15 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
State = 0; LineNum = 0; Comment = 0;
|
|
|
|
nb_modules_lus = 0;
|
|
|
|
textlen = MAX_LEN_TXT;
|
|
|
|
|
|
|
|
while( GetLine( source, Line, &LineNum ) )
|
|
|
|
{
|
|
|
|
Text = StrPurge( Line );
|
|
|
|
if( Comment ) /* Commentaires en cours */
|
|
|
|
{
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
Comment = 0;
|
|
|
|
}
|
|
|
|
if( *Text == '{' ) /* Commentaires */
|
|
|
|
{
|
|
|
|
Comment = 1;
|
|
|
|
if( ( Text = strchr( Text, '}' ) ) == NULL )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( *Text == '(' )
|
|
|
|
State++;
|
|
|
|
if( *Text == ')' )
|
|
|
|
State--;
|
|
|
|
|
|
|
|
if( State == 2 )
|
|
|
|
{
|
|
|
|
int Error = 0;
|
|
|
|
if( strtok( Line, " ()\t\n" ) == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
Error = 1; /* TimeStamp */
|
2007-08-20 19:33:15 +00:00
|
|
|
if( ( LibModName = strtok( NULL, " ()\t\n" ) ) == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
Error = 1; /* nom Lib */
|
2007-08-20 19:33:15 +00:00
|
|
|
/* Lecture du nom (reference) du composant: */
|
|
|
|
if( ( Text = strtok( NULL, " ()\t\n" ) ) == NULL )
|
|
|
|
Error = 1;
|
|
|
|
nb_modules_lus++;
|
2008-03-22 18:08:44 +00:00
|
|
|
aBufName.Add( CONV_FROM_UTF8( Text ) );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( State >= 3 )
|
|
|
|
{
|
|
|
|
State--; /* Lecture 1 ligne relative au Pad */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( source );
|
|
|
|
return nb_modules_lus;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
int ReadListeModules( const wxString& CmpFullFileName, const wxString* RefCmp, long TimeStamp,
|
|
|
|
wxString& NameModule )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Lit le fichier .CMP donnant l'equivalence Modules / Composants
|
|
|
|
* Retourne:
|
|
|
|
* Si ce fichier existe:
|
|
|
|
* 1 et le nom module dans NameModule
|
|
|
|
* -1 si module non trouve en fichier
|
|
|
|
* sinon 0;
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* parametres d'appel:
|
|
|
|
* RefCmp (NULL si selection par TimeStamp)
|
|
|
|
* TimeStamp (signature temporelle si elle existe, NULL sinon)
|
|
|
|
* pointeur sur le buffer recevant le nom du module
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Exemple de fichier:
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* Cmp-Mod V01 Genere par PcbNew le 29/10/2003-13:11:6
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* BeginCmp
|
|
|
|
* TimeStamp = 322D3011;
|
|
|
|
* Reference = BUS1;
|
|
|
|
* ValeurCmp = BUSPC;
|
|
|
|
* IdModule = BUS_PC;
|
|
|
|
* EndCmp
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
* BeginCmp
|
|
|
|
* TimeStamp = 32307DE2;
|
|
|
|
* Reference = C1;
|
|
|
|
* ValeurCmp = 47uF;
|
|
|
|
* IdModule = CP6;
|
|
|
|
* EndCmp
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
wxString refcurrcmp, idmod;
|
|
|
|
char ia[1024];
|
|
|
|
int timestamp;
|
|
|
|
char* ptcar;
|
|
|
|
FILE* FichCmp;
|
|
|
|
|
|
|
|
if( (RefCmp == NULL) && (TimeStamp == 0) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
FichCmp = wxFopen( CmpFullFileName, wxT( "rt" ) );
|
|
|
|
if( FichCmp == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "File <%s> not found, use Netlist for lib module selection" ),
|
2008-03-22 18:08:44 +00:00
|
|
|
CmpFullFileName.GetData() );
|
|
|
|
DisplayError( NULL, msg, 20 );
|
2007-08-20 19:33:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( fgets( ia, sizeof(ia), FichCmp ) != NULL )
|
|
|
|
{
|
|
|
|
if( strnicmp( ia, "BeginCmp", 8 ) != 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Ici une description de 1 composant commence */
|
|
|
|
refcurrcmp.Empty();
|
|
|
|
idmod.Empty();
|
|
|
|
timestamp = -1;
|
|
|
|
while( fgets( ia, sizeof(ia), FichCmp ) != NULL )
|
|
|
|
{
|
|
|
|
if( strnicmp( ia, "EndCmp", 6 ) == 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( strnicmp( ia, "Reference =", 11 ) == 0 )
|
|
|
|
{
|
|
|
|
ptcar = ia + 11;
|
|
|
|
ptcar = strtok( ptcar, " =;\t\n" );
|
|
|
|
if( ptcar )
|
|
|
|
refcurrcmp = CONV_FROM_UTF8( ptcar );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strnicmp( ia, "IdModule =", 11 ) == 0 )
|
|
|
|
{
|
|
|
|
ptcar = ia + 11;
|
|
|
|
ptcar = strtok( ptcar, " =;\t\n" );
|
|
|
|
if( ptcar )
|
|
|
|
idmod = CONV_FROM_UTF8( ptcar );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( strnicmp( ia, "TimeStamp =", 11 ) == 0 )
|
|
|
|
{
|
|
|
|
ptcar = ia + 11;
|
|
|
|
ptcar = strtok( ptcar, " =;\t\n" );
|
|
|
|
if( ptcar )
|
|
|
|
sscanf( ptcar, "%X", ×tamp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fin lecture 1 descr composant */
|
|
|
|
|
|
|
|
/* Test du Composant lu en fichier: est-il le bon */
|
|
|
|
if( RefCmp )
|
|
|
|
{
|
|
|
|
if( RefCmp->CmpNoCase( refcurrcmp ) == 0 )
|
|
|
|
{
|
|
|
|
fclose( FichCmp );
|
|
|
|
NameModule = idmod;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( TimeStamp != -1 )
|
|
|
|
{
|
|
|
|
if( TimeStamp == timestamp )
|
|
|
|
{
|
|
|
|
fclose( FichCmp );
|
|
|
|
NameModule = idmod;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose( FichCmp );
|
|
|
|
return -1;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
void AddToList( const wxString& NameLibCmp, const wxString& CmpName,
|
|
|
|
int TimeStamp, const wxString& path )
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Fontion copiant en memoire de travail les caracteristiques
|
2007-08-20 19:33:15 +00:00
|
|
|
* des nouveaux modules
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULEtoLOAD* NewMod;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
NewMod = new MODULEtoLOAD( NameLibCmp, CmpName, TimeStamp, path );
|
2008-11-24 06:53:43 +00:00
|
|
|
NewMod->SetNext( s_ModuleToLoad_List );
|
2007-08-20 19:33:15 +00:00
|
|
|
s_ModuleToLoad_List = NewMod;
|
|
|
|
s_NbNewModules++;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************/
|
2008-03-22 18:08:44 +00:00
|
|
|
void LoadListeModules( WinEDA_PcbFrame* aPcbFrame, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de chargement des nouveaux modules en une seule lecture des
|
2007-08-20 19:33:15 +00:00
|
|
|
* librairies
|
|
|
|
* Si un module vient d'etre charge il est duplique, ce qui evite une lecture
|
|
|
|
* inutile de la librairie
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULEtoLOAD* ref, * cmp;
|
|
|
|
int ii;
|
|
|
|
MODULE* Module = NULL;
|
2008-04-17 16:25:29 +00:00
|
|
|
wxPoint OldPos = aPcbFrame->GetScreen()->m_Curseur;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
if( s_NbNewModules == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SortListModulesToLoadByLibname( s_NbNewModules );
|
|
|
|
ref = cmp = s_ModuleToLoad_List;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
// Calculate the footprint "best" position:
|
|
|
|
if( aPcbFrame->SetBoardBoundaryBoxFromEdgesOnly() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
aPcbFrame->GetScreen()->m_Curseur.x = aPcbFrame->m_Pcb->m_BoundaryBox.GetRight() +
|
2008-03-22 18:08:44 +00:00
|
|
|
5000;
|
2008-04-17 16:25:29 +00:00
|
|
|
aPcbFrame->GetScreen()->m_Curseur.y = aPcbFrame->m_Pcb->m_BoundaryBox.GetBottom() +
|
2008-03-22 18:08:44 +00:00
|
|
|
10000;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-17 16:25:29 +00:00
|
|
|
aPcbFrame->GetScreen()->m_Curseur = wxPoint( 0, 0 );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( ii = 0; ii < s_NbNewModules; ii++, cmp = cmp->Next() )
|
|
|
|
{
|
|
|
|
if( (ii == 0) || ( ref->m_LibName != cmp->m_LibName) )
|
2008-12-06 08:21:54 +00:00
|
|
|
{
|
|
|
|
/* New footprint : must be loaded from a library */
|
2008-03-22 18:08:44 +00:00
|
|
|
Module = aPcbFrame->Get_Librairie_Module( NULL, wxEmptyString, cmp->m_LibName, FALSE );
|
2007-08-20 19:33:15 +00:00
|
|
|
ref = cmp;
|
|
|
|
if( Module == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Component [%s]: footprint <%s> not found" ),
|
2008-03-22 18:08:44 +00:00
|
|
|
cmp->m_CmpName.GetData(), cmp->m_LibName.GetData() );
|
|
|
|
DisplayError( NULL, msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-03-22 18:08:44 +00:00
|
|
|
aPcbFrame->Place_Module( Module, DC );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Update schematic links : reference "Time Stamp" and schematic hierarchical path */
|
2007-08-20 19:33:15 +00:00
|
|
|
Module->m_Reference->m_Text = cmp->m_CmpName;
|
|
|
|
Module->m_TimeStamp = cmp->m_TimeStamp;
|
2008-02-19 00:28:42 +00:00
|
|
|
Module->m_Path = cmp->m_Path;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
/* Footprint already loaded from a library, duplicate it (faster) */
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULE* newmodule;
|
|
|
|
if( Module == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
continue; /* module non existant en libr */
|
2008-12-06 08:21:54 +00:00
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
newmodule = new MODULE( aPcbFrame->m_Pcb );
|
2007-08-20 19:33:15 +00:00
|
|
|
newmodule->Copy( Module );
|
2008-12-06 08:21:54 +00:00
|
|
|
|
|
|
|
aPcbFrame->m_Pcb->Add( newmodule, ADD_APPEND );
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
Module = newmodule;
|
|
|
|
Module->m_Reference->m_Text = cmp->m_CmpName;
|
|
|
|
Module->m_TimeStamp = cmp->m_TimeStamp;
|
2008-02-19 00:28:42 +00:00
|
|
|
Module->m_Path = cmp->m_Path;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
aPcbFrame->GetScreen()->m_Curseur = OldPos;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine utilisee par qsort pour le tri des modules a charger
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
|
|
|
static int SortByLibName( MODULEtoLOAD** ref, MODULEtoLOAD** cmp )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
int ii = (*ref)->m_LibName.CmpNoCase( (*cmp)->m_LibName );
|
|
|
|
|
|
|
|
return ii;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
void SortListModulesToLoadByLibname( int NbModules )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Rearrage la liste des modules List par ordre alphabetique des noms lib des modules
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULEtoLOAD** base_list, * item;
|
|
|
|
int ii;
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
base_list = (MODULEtoLOAD**) MyMalloc( NbModules * sizeof(MODULEtoLOAD*) );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
for( ii = 0, item = s_ModuleToLoad_List; ii < NbModules; ii++ )
|
|
|
|
{
|
|
|
|
base_list[ii] = item;
|
|
|
|
item = item->Next();
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
qsort( base_list, NbModules, sizeof(MODULEtoLOAD*),
|
|
|
|
( int( * ) ( const void*, const void* ) )SortByLibName );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
// Reconstruction du chainage:
|
|
|
|
s_ModuleToLoad_List = *base_list;
|
|
|
|
for( ii = 0; ii < NbModules - 1; ii++ )
|
|
|
|
{
|
|
|
|
item = base_list[ii];
|
2008-11-24 06:53:43 +00:00
|
|
|
item->SetNext( base_list[ii + 1] );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dernier item: Pnext = NULL:
|
|
|
|
item = base_list[ii];
|
2008-11-24 06:53:43 +00:00
|
|
|
item->SetNext( NULL );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
free( base_list );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2007-08-20 19:33:15 +00:00
|
|
|
MODULEtoLOAD::MODULEtoLOAD( const wxString& libname, const wxString& cmpname,
|
2008-02-12 21:12:46 +00:00
|
|
|
int timestamp, const wxString& path ) : EDA_BaseStruct( TYPE_NOT_INIT )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2007-08-20 19:33:15 +00:00
|
|
|
m_LibName = libname;
|
|
|
|
m_CmpName = cmpname;
|
|
|
|
m_TimeStamp = timestamp;
|
2008-03-22 18:08:44 +00:00
|
|
|
m_Path = path;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|