2011-11-11 20:10:24 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file libarch.cpp
|
|
|
|
* @brief Module for generation of component archive files.
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <class_sch_screen.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <sch_item_struct.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <netlist.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::CreateArchiveLibrary( const wxString& aFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-11 20:10:24 +00:00
|
|
|
wxString msg;
|
|
|
|
LIB_COMPONENT* libComponent;
|
2009-09-18 14:56:05 +00:00
|
|
|
CMP_LIBRARY* libCache;
|
2011-11-11 20:10:24 +00:00
|
|
|
SCH_SCREENS screens;
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
libCache = new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, aFileName );
|
2009-09-18 14:56:05 +00:00
|
|
|
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
|
|
|
*/
|
2011-11-11 20:10:24 +00:00
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2011-11-11 20:10:24 +00:00
|
|
|
for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2011-11-11 20:10:24 +00:00
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
2008-12-10 16:49:53 +00:00
|
|
|
continue;
|
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
2010-03-03 15:56:08 +00:00
|
|
|
// If not already saved in the new cache, put it:
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
if( libCache->FindEntry( component->GetLibName()) == NULL )
|
2010-03-03 15:56:08 +00:00
|
|
|
{
|
2011-11-11 20:10:24 +00:00
|
|
|
libComponent = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-11-11 20:10:24 +00:00
|
|
|
if( libComponent ) // if NULL : component not found, cannot be stored
|
|
|
|
libCache->AddComponent( libComponent );
|
2010-03-03 15:56:08 +00:00
|
|
|
}
|
2008-09-18 17:10:54 +00:00
|
|
|
}
|
2008-12-10 16:49:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
try
|
2011-11-11 20:10:24 +00:00
|
|
|
{
|
2012-10-25 15:41:20 +00:00
|
|
|
FILE_OUTPUTFORMATTER formatter( aFileName );
|
2011-11-11 20:10:24 +00:00
|
|
|
|
2012-10-25 15:41:20 +00:00
|
|
|
if( !libCache->Save( formatter ) )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "An error occurred attempting to save component library <%s>." ),
|
|
|
|
GetChars( aFileName ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... /* IO_ERROR ioe */ )
|
2008-12-10 16:49:53 +00:00
|
|
|
{
|
2012-10-25 15:41:20 +00:00
|
|
|
msg = wxT( "Failed to create component library file " ) + aFileName;
|
2011-11-11 20:10:24 +00:00
|
|
|
DisplayError( this, 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
|
|
|
}
|