2007-05-06 16:03:28 +00:00
|
|
|
|
/**************************************************************/
|
|
|
|
|
/* libarch.cc */
|
|
|
|
|
/* Module de generation du fichier d'archivage des composants */
|
|
|
|
|
/**************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "libcmp.h"
|
|
|
|
|
#include "general.h"
|
|
|
|
|
#include "netlist.h"
|
|
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
/* fonctions exportees */
|
|
|
|
|
|
|
|
|
|
/* fonctions locales */
|
|
|
|
|
static int TriListEntry(EDA_LibComponentStruct **Objet1,
|
|
|
|
|
EDA_LibComponentStruct **Objet2);
|
|
|
|
|
|
|
|
|
|
/* Variable locales */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
|
bool LibArchive(wxWindow * frame, const wxString & ArchFullFileName)
|
|
|
|
|
/*******************************************************************/
|
|
|
|
|
/*
|
2008-02-12 21:12:46 +00:00
|
|
|
|
Creation du fichier librairie contenant tous les composants utilis<EFBFBD>s dans
|
2007-05-06 16:03:28 +00:00
|
|
|
|
le projet en cours
|
2008-02-12 21:12:46 +00:00
|
|
|
|
retourne TRUE si fichier cr<EFBFBD><EFBFBD>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
wxString DocFileName, msg;
|
|
|
|
|
char Line[256];
|
|
|
|
|
FILE *ArchiveFile, *DocFile;
|
2008-02-12 21:12:46 +00:00
|
|
|
|
ListComponent * List;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
EDA_LibComponentStruct ** ListEntry, *Entry;
|
|
|
|
|
int ii, NbItems;
|
|
|
|
|
const wxChar * Text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Creation de la liste des elements */
|
|
|
|
|
NbItems = GenListeCmp(NULL ); // Comptage des composants
|
|
|
|
|
if ( NbItems == 0 ) return FALSE;
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
List = (ListComponent *) MyZMalloc( NbItems * sizeof( ListComponent ) );
|
|
|
|
|
if (List == NULL ) return FALSE;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
/* Calcul de la liste des composants */
|
2008-02-12 21:12:46 +00:00
|
|
|
|
GenListeCmp(List);
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
/* Calcul de la liste des Entrees de librairie
|
|
|
|
|
et Remplacement des alias par les composants "Root" */
|
|
|
|
|
ListEntry = (EDA_LibComponentStruct ** )
|
|
|
|
|
MyZMalloc( NbItems * sizeof(EDA_LibComponentStruct *) );
|
|
|
|
|
if (ListEntry == NULL ) return FALSE;
|
|
|
|
|
|
|
|
|
|
for ( ii = 0; ii < NbItems; ii++ )
|
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
|
Text = List[ii].m_Comp->m_ChipName.GetData();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
Entry = FindLibPart(Text, wxEmptyString, FIND_ROOT);
|
2008-02-12 21:12:46 +00:00
|
|
|
|
ListEntry[ii] = Entry; // = NULL si Composant non trouv<75> en librairie
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
MyFree(List);
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
qsort( ListEntry, NbItems, sizeof(EDA_LibComponentStruct *),
|
|
|
|
|
(int(*)(const void*, const void*))TriListEntry);
|
|
|
|
|
|
|
|
|
|
/* mise a jour extension fichier doc associe */
|
|
|
|
|
DocFileName = ArchFullFileName;
|
|
|
|
|
ChangeFileNameExt(DocFileName, wxT(".bck"));
|
|
|
|
|
|
|
|
|
|
if ((ArchiveFile = wxFopen(ArchFullFileName, wxT("wt"))) == NULL)
|
|
|
|
|
{
|
|
|
|
|
MyFree(ListEntry);
|
|
|
|
|
msg = _("Failed to create archive lib file ") + ArchFullFileName;
|
|
|
|
|
DisplayError(frame, msg);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((DocFile = wxFopen(DocFileName, wxT("wt"))) == NULL)
|
|
|
|
|
{
|
|
|
|
|
msg = _("Failed to create doc lib file ") + DocFileName;
|
|
|
|
|
DisplayError(frame, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf(ArchiveFile,"%s %s\n#\n", LIBFILE_IDENT,DateAndTime(Line));
|
|
|
|
|
if( DocFile)
|
|
|
|
|
fprintf(DocFile,"%s %s\n", DOCFILE_IDENT, DateAndTime(Line));
|
|
|
|
|
|
|
|
|
|
/* Generation des elements */
|
|
|
|
|
for ( ii = 0; ii < NbItems; ii++ )
|
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
|
if ( ListEntry[ii] == NULL ) // Composant non trouv<75> en librairie
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( ii == 0 )
|
|
|
|
|
{
|
|
|
|
|
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
|
|
|
|
|
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
|
|
|
|
|
}
|
|
|
|
|
else if ( ListEntry[ii-1] != ListEntry[ii] )
|
|
|
|
|
{
|
|
|
|
|
WriteOneLibEntry(frame, ArchiveFile, ListEntry[ii]);
|
|
|
|
|
if( DocFile ) WriteOneDocLibEntry(DocFile, ListEntry[ii]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Generation fin de fichier */
|
|
|
|
|
fprintf(ArchiveFile,"#\n#EndLibrary\n");
|
|
|
|
|
fclose(ArchiveFile);
|
|
|
|
|
|
|
|
|
|
if( DocFile )
|
|
|
|
|
{
|
|
|
|
|
fprintf(DocFile,"#\n#End Doc Library\n");
|
|
|
|
|
fclose(DocFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MyFree(ListEntry);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
static int TriListEntry(EDA_LibComponentStruct **Objet1,
|
|
|
|
|
EDA_LibComponentStruct **Objet2)
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
/* Routine de comparaison pour le tri du Tableau par qsort()
|
|
|
|
|
Les composants sont tries par LibName
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
int ii;
|
|
|
|
|
const wxString * Text1, *Text2;
|
|
|
|
|
|
|
|
|
|
if( (*Objet1 == NULL) && (*Objet2 == NULL ) ) return(0);
|
|
|
|
|
if( *Objet1 == NULL) return(-1);
|
|
|
|
|
if( *Objet2 == NULL) return(1);
|
|
|
|
|
|
|
|
|
|
Text1 = &(*Objet1)->m_Name.m_Text;
|
|
|
|
|
Text2 = &(*Objet2)->m_Name.m_Text;
|
|
|
|
|
|
|
|
|
|
ii = Text1->CmpNoCase(* Text2);
|
|
|
|
|
return(ii);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|