2009-11-04 20:46:53 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* libarch.cpp */
|
|
|
|
/* Module for generation of component archive files. */
|
|
|
|
/*****************************************************/
|
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"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "sch_item_struct.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "netlist.h"
|
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2009-09-18 14:56:05 +00:00
|
|
|
* Creates a library that contains all components used in the schematic.
|
|
|
|
*
|
2008-12-10 16:49:53 +00:00
|
|
|
* return true if success
|
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString msg;
|
|
|
|
LIB_COMPONENT* Entry;
|
|
|
|
CMP_LIBRARY* libCache;
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS ScreenList;
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
libCache = new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, ArchFullFileName );
|
|
|
|
libCache->SetCache();
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* examine all screens (not sheets) used and build the list of components
|
2009-09-18 14:56:05 +00:00
|
|
|
* found in lib complex hierarchies are not a problem because we just want
|
|
|
|
* to know used components in libraries
|
2008-12-10 18:00:15 +00:00
|
|
|
*/
|
2009-09-18 14:56:05 +00:00
|
|
|
for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen != NULL;
|
|
|
|
screen = ScreenList.GetNext() )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
for( SCH_ITEM* SchItem = screen->GetDrawItems(); SchItem; SchItem = SchItem->Next() )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( SchItem->Type() != SCH_COMPONENT_T )
|
2008-12-10 16:49:53 +00:00
|
|
|
continue;
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) SchItem;
|
2010-03-03 15:56:08 +00:00
|
|
|
// If not already saved in the new cache, put it:
|
2010-12-14 15:56:30 +00:00
|
|
|
if( libCache->FindEntry( component->GetLibName()) == NULL )
|
2010-03-03 15:56:08 +00:00
|
|
|
{
|
2010-12-14 15:56:30 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2010-03-03 15:56:08 +00:00
|
|
|
if( Entry ) // if NULL : component not found, cannot be stored
|
|
|
|
libCache->AddComponent( Entry );
|
|
|
|
}
|
2008-09-18 17:10:54 +00:00
|
|
|
}
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
if( !libCache->Save( ArchFullFileName ) )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
msg.Printf( _( "An error occurred attempting to save component \
|
2009-10-16 17:18:23 +00:00
|
|
|
library <%s>." ), GetChars( ArchFullFileName ) );
|
2008-12-10 16:49:53 +00:00
|
|
|
DisplayError( frame, msg );
|
2009-09-18 14:56:05 +00:00
|
|
|
return false;
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
return true;
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|