2007-06-05 12:10:51 +00:00
|
|
|
|
/**********************/
|
|
|
|
|
/* CVPCB: autosel.cpp */
|
|
|
|
|
/**********************/
|
|
|
|
|
|
|
|
|
|
/* Routines de selection automatique des modules */
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "confirm.h"
|
|
|
|
|
#include "gestfich.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "cvpcb.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "protos.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "cvstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
#define QUOTE '\''
|
|
|
|
|
|
|
|
|
|
class AUTOMODULE
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
int m_Type;
|
|
|
|
|
AUTOMODULE * Pnext;
|
|
|
|
|
wxString m_Name;
|
|
|
|
|
wxString m_LibName;
|
|
|
|
|
wxString m_Library;
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
|
AUTOMODULE() { m_Type = 0; Pnext = NULL; }
|
2007-06-05 12:10:51 +00:00
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* routines locales : */
|
|
|
|
|
static int auto_select(WinEDA_CvpcbFrame * frame, STORECMP * Cmp, AUTOMODULE * BaseListeMod);
|
|
|
|
|
static void auto_associe(WinEDA_CvpcbFrame * frame);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
void WinEDA_CvpcbFrame::AssocieModule(wxCommandEvent& event)
|
|
|
|
|
/*************************************************************/
|
|
|
|
|
/* Fonction liee au boutton "Auto"
|
|
|
|
|
Lance l'association automatique modules/composants
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
auto_associe(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
|
static void auto_associe(WinEDA_CvpcbFrame * frame)
|
|
|
|
|
/**************************************************/
|
|
|
|
|
{
|
|
|
|
|
unsigned ii, j, k;
|
|
|
|
|
wxString EquivFileName, msg;
|
|
|
|
|
char Line[1024];
|
|
|
|
|
FILE *fichierstf ; /* sert en lecture des differents fichiers *.STF */
|
|
|
|
|
AUTOMODULE * ItemModule,* NextMod;
|
|
|
|
|
AUTOMODULE * BaseListeMod = NULL;
|
2009-02-21 15:12:26 +00:00
|
|
|
|
STORECMP * Component;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
int nb_correspondances = 0;
|
|
|
|
|
|
|
|
|
|
if( nbcomp <= 0 ) return;
|
|
|
|
|
|
|
|
|
|
/* recherche des equivalences a travers les fichiers possibles */
|
|
|
|
|
for( ii= 0 ; ii < g_ListName_Equ.GetCount(); ii++)
|
|
|
|
|
{
|
|
|
|
|
/* Calcul du nom complet avec son chemin */
|
|
|
|
|
EquivFileName = MakeFileName(g_RealLibDirBuffer,g_ListName_Equ[ii],g_EquivExtBuffer);
|
|
|
|
|
|
|
|
|
|
if ( (fichierstf = wxFopen(EquivFileName, wxT("rt"))) == 0)
|
|
|
|
|
{
|
|
|
|
|
msg.Printf( _("Library: <%s> not found"),EquivFileName.GetData());
|
|
|
|
|
DisplayError(frame, msg,10);
|
|
|
|
|
continue ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* lecture fichier n */
|
|
|
|
|
while ( fgets(Line,79,fichierstf) != 0 )
|
|
|
|
|
{
|
|
|
|
|
/* elimination des lignes vides */
|
|
|
|
|
for (j = 0 ; j < 40 ; j++ )
|
2009-02-21 15:12:26 +00:00
|
|
|
|
{
|
2007-06-05 12:10:51 +00:00
|
|
|
|
if (Line[j] == 0 ) goto fin_de_while ;
|
|
|
|
|
if (Line[j] == QUOTE ) break ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemModule = new AUTOMODULE();
|
|
|
|
|
ItemModule->Pnext = BaseListeMod;
|
|
|
|
|
BaseListeMod = ItemModule;
|
2009-02-21 15:12:26 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/* stockage du composant ( 'namecmp' 'namelib')
|
|
|
|
|
name et namelib */
|
|
|
|
|
for ( j++ ; j < 40 ; j++, k++)
|
|
|
|
|
{
|
|
|
|
|
if ( Line[j] == QUOTE) break ;
|
|
|
|
|
ItemModule->m_Name.Append(Line[j]);
|
|
|
|
|
}
|
|
|
|
|
j++ ;
|
|
|
|
|
for ( ; j < 80 ; ) if (Line[j++] == QUOTE) break ;
|
|
|
|
|
for (; ; j++)
|
|
|
|
|
{
|
|
|
|
|
if (Line[j] == QUOTE) break ;
|
|
|
|
|
ItemModule->m_LibName.Append(Line[j]);
|
|
|
|
|
}
|
|
|
|
|
nb_correspondances++ ;
|
|
|
|
|
fin_de_while:;
|
|
|
|
|
}
|
|
|
|
|
fclose(fichierstf) ;
|
|
|
|
|
|
|
|
|
|
/* Affichage Statistiques */
|
|
|
|
|
msg.Printf(_("%d equivalences"),nb_correspondances);
|
|
|
|
|
frame->SetStatusText(msg, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-21 15:12:26 +00:00
|
|
|
|
Component = g_BaseListeCmp;
|
|
|
|
|
for ( ii = 0; Component != NULL; Component = Component->Pnext, ii++ )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
|
|
|
|
frame->m_ListCmp->SetSelection(ii,TRUE);
|
2009-02-21 15:12:26 +00:00
|
|
|
|
if( Component->m_Module.IsEmpty() )
|
|
|
|
|
auto_select(frame, Component, BaseListeMod);
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Liberation memoire */
|
|
|
|
|
for( ItemModule = BaseListeMod; ItemModule != NULL; ItemModule = NextMod)
|
|
|
|
|
{
|
|
|
|
|
NextMod = ItemModule->Pnext; delete ItemModule;
|
|
|
|
|
}
|
|
|
|
|
BaseListeMod = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
|
|
|
|
static int auto_select(WinEDA_CvpcbFrame * frame, STORECMP * Cmp,
|
|
|
|
|
AUTOMODULE * BaseListeMod)
|
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
|
|
/* associe automatiquement composant et Module
|
|
|
|
|
Retourne;
|
|
|
|
|
0 si OK
|
|
|
|
|
1 si module specifie non trouve en liste librairie
|
|
|
|
|
2 si pas de module specifie dans la liste des equivalences
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
AUTOMODULE * ItemModule;
|
|
|
|
|
STOREMOD * Module;
|
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
|
|
/* examen de la liste des correspondances */
|
|
|
|
|
ItemModule = BaseListeMod;
|
|
|
|
|
for ( ; ItemModule != NULL; ItemModule = ItemModule->Pnext )
|
|
|
|
|
{
|
|
|
|
|
if ( ItemModule->m_Name.CmpNoCase(Cmp->m_Valeur) != 0) continue;
|
|
|
|
|
|
|
|
|
|
/* Correspondance trouvee, recherche nom module dans la liste des
|
|
|
|
|
modules disponibles en librairie */
|
|
|
|
|
Module= g_BaseListePkg;
|
|
|
|
|
for ( ;Module != NULL; Module = Module->Pnext )
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if( ItemModule->m_LibName.CmpNoCase(Module->m_Module) == 0 )
|
|
|
|
|
{ /* empreinte trouv<75>e */
|
|
|
|
|
frame->SetNewPkg(Module->m_Module);
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
msg.Printf(
|
|
|
|
|
_("Component %s: Footprint %s not found in libraries"),
|
|
|
|
|
Cmp->m_Valeur.GetData(), ItemModule->m_LibName.GetData());
|
|
|
|
|
DisplayError(frame, msg, 10);
|
|
|
|
|
return( 2 );
|
|
|
|
|
}
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|