2008-12-10 16:49:53 +00:00
|
|
|
/**************************************************************/
|
|
|
|
/* libarch.cc */
|
|
|
|
/* Module de generation du fichier d'archivage des composants */
|
|
|
|
/**************************************************************/
|
|
|
|
#include <algorithm> // to use sort vector
|
|
|
|
#include <vector>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2008-05-15 15:59:11 +00:00
|
|
|
/* Local functions*/
|
2008-12-12 21:30:07 +00:00
|
|
|
static bool SortCmpByName( const EDA_LibComponentStruct* Objet1,
|
2008-12-10 16:49:53 +00:00
|
|
|
const EDA_LibComponentStruct* Objet2 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
2008-12-10 16:49:53 +00:00
|
|
|
bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
/*******************************************************************/
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2008-12-10 16:49:53 +00:00
|
|
|
* Creates a library that contains all components used in the whole hierarchy
|
|
|
|
* return true if success
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-10 16:49:53 +00:00
|
|
|
wxString DocFileName, msg;
|
|
|
|
char Line[256];
|
|
|
|
FILE* ArchiveFile, * DocFile;
|
|
|
|
EDA_LibComponentStruct* Entry;
|
|
|
|
|
|
|
|
std::vector <EDA_LibComponentStruct*> ListEntry;
|
|
|
|
|
2008-12-12 21:30:07 +00:00
|
|
|
EDA_ScreenList ScreenList;
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2008-12-10 18:00:15 +00:00
|
|
|
/* examine all screens (not scheets) used and build the list of components found in lib
|
2008-12-12 21:30:07 +00:00
|
|
|
* complex hierarchies are not a problem because we just want to know used components in libraries
|
2008-12-10 18:00:15 +00:00
|
|
|
*/
|
2008-12-12 21:30:07 +00:00
|
|
|
for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
|
|
|
for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() )
|
|
|
|
{
|
|
|
|
if( SchItem->Type() != TYPE_SCH_COMPONENT )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) SchItem;
|
|
|
|
Entry = FindLibPart( DrawLibItem->m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
|
|
|
|
if( Entry ) // if NULL : component not found
|
|
|
|
ListEntry.push_back( Entry );
|
2008-09-18 17:10:54 +00:00
|
|
|
}
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 21:30:07 +00:00
|
|
|
// Sort components (libraries entries) by name
|
|
|
|
// (they are components name in library, not in schematic) :
|
|
|
|
sort( ListEntry.begin(), ListEntry.end(), SortCmpByName );
|
2008-12-10 16:49:53 +00:00
|
|
|
|
|
|
|
/* calculate the file name for the associated doc file */
|
|
|
|
DocFileName = ArchFullFileName;
|
|
|
|
ChangeFileNameExt( DocFileName, DOC_EXT );
|
|
|
|
|
|
|
|
if( ( ArchiveFile = wxFopen( ArchFullFileName, wxT( "wt" ) ) ) == NULL )
|
|
|
|
{
|
|
|
|
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 ) );
|
|
|
|
|
|
|
|
/* Save components in file */
|
|
|
|
for( unsigned ii = 0; ii < ListEntry.size(); ii++ )
|
|
|
|
{
|
|
|
|
if( (ii == 0) || ( ListEntry[ii - 1] != ListEntry[ii] ) )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
fprintf( ArchiveFile, "#\n#EndLibrary\n" );
|
|
|
|
fclose( ArchiveFile );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
if( DocFile )
|
|
|
|
{
|
|
|
|
fprintf( DocFile, "#\n#End Doc Library\n" );
|
|
|
|
fclose( DocFile );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
return TRUE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/***********************************************************************************************/
|
2008-12-12 21:30:07 +00:00
|
|
|
bool SortCmpByName( const EDA_LibComponentStruct* Objet1, const EDA_LibComponentStruct* Objet2 )
|
2008-12-10 16:49:53 +00:00
|
|
|
/***********************************************************************************************/
|
|
|
|
|
|
|
|
/* Compare function for sort()
|
|
|
|
* lib components are sorted by name
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
ii = Objet1->m_Name.m_Text.CmpNoCase( Objet2->m_Name.m_Text );
|
|
|
|
return ii < 0;
|
|
|
|
}
|