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"
|
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
|
/* Imported functions */
|
|
|
|
|
int BuildComponentsListFromSchematic( ListComponent* List );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
|
/* Local functions*/
|
|
|
|
|
static int TriListEntry(EDA_LibComponentStruct **Objet1, EDA_LibComponentStruct **Objet2);
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
|
|
|
|
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 */
|
2008-05-15 15:59:11 +00:00
|
|
|
|
NbItems = BuildComponentsListFromSchematic(NULL ); // Comptage des composants
|
2007-05-06 16:03:28 +00:00
|
|
|
|
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-05-15 15:59:11 +00:00
|
|
|
|
BuildComponentsListFromSchematic(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-09-19 08:19:15 +00:00
|
|
|
|
ListEntry[ii] = Entry; // = NULL component not found
|
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));
|
|
|
|
|
|
2008-09-19 08:19:15 +00:00
|
|
|
|
/* Save components in file */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
for ( ii = 0; ii < NbItems; ii++ )
|
|
|
|
|
{
|
2008-09-19 08:19:15 +00:00
|
|
|
|
if ( ListEntry[ii] == NULL ) // Not found in lib
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2008-09-18 17:10:54 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ( (ii == 0) || ( ListEntry[ii-1] != ListEntry[ii] ) )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2008-09-19 08:19:15 +00:00
|
|
|
|
if ( ListEntry[ii]->Type == ROOT) // Must be always true, but just in case
|
|
|
|
|
ListEntry[ii]->Save(ArchiveFile);
|
|
|
|
|
if( DocFile )
|
|
|
|
|
ListEntry[ii]->SaveDoc(DocFile);
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|