2011-10-13 19:56:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-13 19:56:32 +00:00
|
|
|
*
|
|
|
|
* 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-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/loadcmp.cpp
|
|
|
|
* @brief Footprints selection and loading functions.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <eda_doc.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <filter_reader.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pcbcommon.h>
|
2013-05-20 14:49:20 +00:00
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <fpid.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
2012-04-17 01:35:43 +00:00
|
|
|
#include <io_mgr.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <module_editor_frame.h>
|
|
|
|
#include <footprint_info.h>
|
|
|
|
#include <dialog_get_component.h>
|
2012-02-09 20:33:38 +00:00
|
|
|
#include <modview_frame.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
static FOOTPRINT_LIST MList;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD( MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* newModule;
|
2011-03-01 19:26:17 +00:00
|
|
|
PCB_BASE_FRAME* parent = (PCB_BASE_FRAME*) GetParent();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-06-14 20:16:47 +00:00
|
|
|
if( ! parent->GetBoard() || ! parent->GetBoard()->m_Modules )
|
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
aModule = SelectFootprint( parent->GetBoard() );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule == NULL )
|
2010-06-14 20:16:47 +00:00
|
|
|
return false;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-09-12 02:14:07 +00:00
|
|
|
SetCurItem( NULL );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-06-14 20:16:47 +00:00
|
|
|
Clear_Pcb( false );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2012-01-14 19:50:32 +00:00
|
|
|
newModule = new MODULE( *aModule );
|
|
|
|
newModule->SetParent( GetBoard() );
|
2013-03-13 18:53:58 +00:00
|
|
|
newModule->SetLink( aModule->GetTimeStamp() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
aModule = newModule;
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
GetBoard()->Add( aModule );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
aModule->ClearFlags();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( wxPoint( 0, 0 ) );
|
2011-12-07 05:28:49 +00:00
|
|
|
PlaceModule( aModule, NULL );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it on FRONT layer,
|
|
|
|
// because this is the default in ModEdit, and in libs
|
2011-12-07 05:28:49 +00:00
|
|
|
if( aModule->GetLayer() != LAYER_N_FRONT )
|
2013-03-13 18:53:58 +00:00
|
|
|
aModule->Flip( aModule->GetPosition() );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it in orientation 0,
|
|
|
|
// because this is the default orientation in ModEdit, and in libs
|
2011-12-07 05:28:49 +00:00
|
|
|
Rotate_Module( NULL, aModule, 0, false );
|
2008-04-17 16:25:29 +00:00
|
|
|
GetScreen()->ClrModify();
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2010-06-14 20:16:47 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
/*
|
|
|
|
* Launch the footprint viewer to select the name of a footprint to load.
|
|
|
|
* return the selected footprint name
|
|
|
|
*/
|
|
|
|
wxString PCB_BASE_FRAME::SelectFootprintFromLibBrowser( void )
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxString fpname;
|
2012-02-09 20:33:38 +00:00
|
|
|
wxSemaphore semaphore( 0, 1 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-09-11 19:03:21 +00:00
|
|
|
// Close the current Lib browser, if opened, and open a new one, in "modal" mode:
|
2012-09-12 09:53:11 +00:00
|
|
|
FOOTPRINT_VIEWER_FRAME * viewer = FOOTPRINT_VIEWER_FRAME::GetActiveFootprintViewer();
|
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
if( viewer )
|
|
|
|
viewer->Destroy();
|
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
viewer = new FOOTPRINT_VIEWER_FRAME( this, m_footprintLibTable, &semaphore,
|
|
|
|
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT );
|
2012-02-09 20:33:38 +00:00
|
|
|
|
|
|
|
// Show the library viewer frame until it is closed
|
|
|
|
while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event
|
|
|
|
{
|
|
|
|
wxYield();
|
|
|
|
wxMilliSleep( 50 );
|
|
|
|
}
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
#if !defined( USE_FP_LIB_TABLE )
|
2013-04-25 16:29:35 +00:00
|
|
|
// Returns the full fp name, i.e. the lib name and th fp name,
|
2013-05-08 20:47:23 +00:00
|
|
|
// separated by a '/' (/ is now an illegal char in fp names)
|
|
|
|
fpname = viewer->GetSelectedLibraryFullName() + wxT( "/" ) + viewer->GetSelectedFootprint();
|
|
|
|
#else
|
|
|
|
fpname = viewer->GetSelectedLibrary() + wxT( ":" ) + viewer->GetSelectedFootprint();
|
|
|
|
#endif
|
2013-04-11 17:40:20 +00:00
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
viewer->Destroy();
|
2012-02-09 20:33:38 +00:00
|
|
|
|
|
|
|
return fpname;
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::LoadModuleFromLibrary( const wxString& aLibrary,
|
|
|
|
FP_LIB_TABLE* aTable,
|
|
|
|
bool aUseFootprintViewer,
|
|
|
|
wxDC* aDC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-09-26 05:29:54 +00:00
|
|
|
MODULE* module = NULL;
|
2013-08-03 05:15:23 +00:00
|
|
|
wxPoint curspos = GetCrossHairPosition();
|
2011-12-07 05:28:49 +00:00
|
|
|
wxString moduleName, keys;
|
2013-04-11 17:40:20 +00:00
|
|
|
wxString libName = aLibrary;
|
2012-04-17 01:35:43 +00:00
|
|
|
bool allowWildSeach = true;
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
static wxArrayString HistoryList;
|
2012-02-09 20:33:38 +00:00
|
|
|
static wxString lastComponentName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
// Ask for a component name or key words
|
2013-05-08 20:47:23 +00:00
|
|
|
DIALOG_GET_COMPONENT dlg( this, HistoryList, _( "Load Module" ), aUseFootprintViewer );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
dlg.SetComponentName( lastComponentName );
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2009-10-16 17:18:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
if( dlg.m_GetExtraFunction )
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
// SelectFootprintFromLibBrowser() returns the "full" footprint name, i.e.
|
|
|
|
// <lib_name>/<footprint name> or FPID format "lib_name:fp_name:rev#"
|
|
|
|
#if !defined( USE_FP_LIB_TABLE )
|
2013-04-11 17:40:20 +00:00
|
|
|
wxString full_fpname = SelectFootprintFromLibBrowser();
|
|
|
|
moduleName = full_fpname.AfterLast( '/' );
|
|
|
|
libName = full_fpname.BeforeLast( '/' );
|
2013-05-08 20:47:23 +00:00
|
|
|
#else
|
2013-05-28 16:54:59 +00:00
|
|
|
moduleName = SelectFootprintFromLibBrowser();
|
2013-05-08 20:47:23 +00:00
|
|
|
#endif
|
2012-02-09 20:33:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
moduleName = dlg.GetComponentName();
|
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
if( moduleName.IsEmpty() ) // Cancel command
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( dlg.IsKeyword() ) // Selection by keywords
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
allowWildSeach = false;
|
2012-02-19 19:53:11 +00:00
|
|
|
keys = moduleName;
|
2013-05-20 14:49:20 +00:00
|
|
|
moduleName = SelectFootprint( this, libName, wxEmptyString, keys, aTable );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( moduleName.IsEmpty() ) // Cancel command
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
else if( moduleName.Contains( wxT( "?" ) )
|
|
|
|
|| moduleName.Contains( wxT( "*" ) ) ) // Selection wild card
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
allowWildSeach = false;
|
2013-05-20 14:49:20 +00:00
|
|
|
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
|
2011-12-22 13:28:11 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2013-05-08 20:47:23 +00:00
|
|
|
return NULL; // Cancel command.
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
#if !defined( USE_FP_LIB_TABLE )
|
2013-04-11 17:40:20 +00:00
|
|
|
module = GetModuleLibrary( libName, moduleName, false );
|
2013-05-28 16:54:59 +00:00
|
|
|
#else
|
|
|
|
FPID fpid;
|
|
|
|
|
2013-09-17 00:52:08 +00:00
|
|
|
wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
|
2013-05-28 16:54:59 +00:00
|
|
|
wxString::Format( wxT( "Could not parse FPID string <%s>." ),
|
|
|
|
GetChars( moduleName ) ) );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
module = loadFootprint( fpid );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "An error occurred attemping to load footprint <%s>.\n\nError: %s" ),
|
|
|
|
fpid.Format().c_str(), GetChars( ioe.errorText ) );
|
|
|
|
}
|
|
|
|
#endif
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !module && allowWildSeach ) // Search with wild card
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
allowWildSeach = false;
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
wxString wildname = wxChar( '*' ) + moduleName + wxChar( '*' );
|
|
|
|
moduleName = wildname;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
moduleName = SelectFootprint( this, libName, moduleName, wxEmptyString, aTable );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2012-04-16 03:18:41 +00:00
|
|
|
return NULL; // Cancel command.
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2013-05-28 16:54:59 +00:00
|
|
|
#if !defined( USE_FP_LIB_TABLE )
|
2013-04-11 17:40:20 +00:00
|
|
|
module = GetModuleLibrary( libName, moduleName, true );
|
2013-05-28 16:54:59 +00:00
|
|
|
#else
|
|
|
|
FPID fpid;
|
|
|
|
|
2013-09-17 00:52:08 +00:00
|
|
|
wxCHECK_MSG( fpid.Parse( moduleName ) < 0, NULL,
|
2013-05-28 16:54:59 +00:00
|
|
|
wxString::Format( wxT( "Could not parse FPID string <%s>." ),
|
|
|
|
GetChars( moduleName ) ) );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
module = loadFootprint( fpid );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
wxLogDebug( wxT( "An error occurred attemping to load footprint <%s>.\n\nError: %s" ),
|
|
|
|
fpid.Format().c_str(), GetChars( ioe.errorText ) );
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 05:15:23 +00:00
|
|
|
SetCrossHairPosition( curspos );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2013-05-28 16:54:59 +00:00
|
|
|
GetBoard()->Add( module, ADD_APPEND );
|
2012-02-09 20:33:38 +00:00
|
|
|
lastComponentName = moduleName;
|
2011-12-07 05:28:49 +00:00
|
|
|
AddHistoryComponentName( HistoryList, moduleName );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-21 13:42:02 +00:00
|
|
|
module->SetFlags( IS_NEW );
|
2013-03-13 18:53:58 +00:00
|
|
|
module->SetLink( 0 );
|
2013-05-08 20:47:23 +00:00
|
|
|
module->SetPosition( curspos );
|
2011-12-12 08:37:05 +00:00
|
|
|
module->SetTimeStamp( GetNewTimeStamp() );
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
|
2012-01-04 19:10:33 +00:00
|
|
|
// Put it on FRONT layer,
|
2012-09-13 12:15:24 +00:00
|
|
|
// (Can be stored flipped if the lib is an archive built from a board)
|
|
|
|
if( module->IsFlipped() )
|
2013-03-13 18:53:58 +00:00
|
|
|
module->Flip( module->GetPosition() );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-09-13 12:15:24 +00:00
|
|
|
// Place it in orientation 0,
|
|
|
|
// even if it is not saved with orientation 0 in lib
|
2012-01-04 19:10:33 +00:00
|
|
|
// (Can happen if the lib is an archive built from a board)
|
|
|
|
Rotate_Module( NULL, module, 0, false );
|
2009-11-14 22:15:22 +00:00
|
|
|
|
|
|
|
RecalculateAllTracksNetcode();
|
2009-06-11 14:26:17 +00:00
|
|
|
|
2012-02-09 20:33:38 +00:00
|
|
|
if( aDC )
|
|
|
|
module->Draw( m_canvas, aDC, GR_OR );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-09-13 12:15:24 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::GetModuleLibrary( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
2013-05-08 20:47:23 +00:00
|
|
|
bool aDisplayError )
|
2012-09-13 12:15:24 +00:00
|
|
|
{
|
|
|
|
if( aLibraryPath.IsEmpty() )
|
|
|
|
return loadFootprintFromLibraries( aFootprintName, aDisplayError );
|
|
|
|
else
|
|
|
|
return loadFootprintFromLibrary( aLibraryPath, aFootprintName, aDisplayError );
|
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::loadFootprintFromLibrary( const wxString& aLibraryPath,
|
2012-10-07 15:37:25 +00:00
|
|
|
const wxString& aFootprintName,
|
2013-05-28 16:54:59 +00:00
|
|
|
bool aDisplayError )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
|
|
|
|
|
|
|
wxString libPath = wxGetApp().FindLibraryPath( aLibraryPath );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE* footprint = pi->FootprintLoad( libPath, aFootprintName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !footprint )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( aDisplayError )
|
2009-06-26 12:52:24 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString msg = wxString::Format(
|
2013-05-08 20:47:23 +00:00
|
|
|
_( "Footprint %s not found in library <%s>." ),
|
2012-04-17 01:35:43 +00:00
|
|
|
aFootprintName.GetData(),
|
|
|
|
libPath.GetData() );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
return NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
SetStatusText( wxEmptyString );
|
|
|
|
return footprint;
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::loadFootprintFromLibraries(
|
|
|
|
const wxString& aFootprintName, bool aDisplayError )
|
|
|
|
{
|
|
|
|
bool showed_error = false;
|
|
|
|
MODULE* footprint = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxFileName fn = wxFileName( wxEmptyString, g_LibraryNames[ii],
|
|
|
|
LegacyFootprintLibPathExtension );
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString libPath = wxGetApp().FindLibraryPath( fn );
|
2011-09-27 20:43:18 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !libPath )
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( aDisplayError && !showed_error )
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "PCB footprint library file <%s> not found in search paths." ),
|
|
|
|
fn.GetFullName().GetData() );
|
2011-07-06 16:40:54 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
showed_error = true;
|
|
|
|
}
|
2013-05-28 16:54:59 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
footprint = pi->FootprintLoad( libPath, aFootprintName );
|
2011-12-07 05:28:49 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( footprint )
|
|
|
|
{
|
|
|
|
SetStatusText( wxEmptyString );
|
|
|
|
return footprint;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !footprint )
|
|
|
|
{
|
|
|
|
if( aDisplayError )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
2013-05-08 20:47:23 +00:00
|
|
|
_( "Footprint %s not found in any library." ),
|
2012-04-17 01:35:43 +00:00
|
|
|
aFootprintName.GetData() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( NULL, msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( this, ioe.errorText );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::loadFootprint( const FPID& aFootprintId )
|
2013-04-25 16:29:35 +00:00
|
|
|
throw( IO_ERROR, PARSE_ERROR )
|
|
|
|
{
|
2013-05-20 14:49:20 +00:00
|
|
|
wxCHECK_MSG( m_footprintLibTable != NULL, NULL,
|
|
|
|
wxT( "Cannot look up FPID in NULL FP_LIB_TABLE." ) );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
wxString libName = FROM_UTF8( aFootprintId.GetLibNickname().c_str() );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
const FP_LIB_TABLE::ROW* row = m_footprintLibTable->FindRow( libName );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
if( row == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "No library named <%s> was found in the footprint library table." ),
|
|
|
|
aFootprintId.GetLibNickname().c_str() );
|
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
wxString footprintName = FROM_UTF8( aFootprintId.GetFootprintName().c_str() );
|
|
|
|
wxString libPath = row->GetFullURI();
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
libPath = FP_LIB_TABLE::ExpandSubstitutions( libPath );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-05-20 14:49:20 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::EnumFromStr( row->GetType() ) ) );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
return pi->FootprintLoad( libPath, footprintName, row->GetProperties() );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
wxString PCB_BASE_FRAME::SelectFootprint( EDA_DRAW_FRAME* aWindow,
|
|
|
|
const wxString& aLibraryFullFilename,
|
|
|
|
const wxString& aMask,
|
2013-05-20 14:49:20 +00:00
|
|
|
const wxString& aKeyWord,
|
|
|
|
FP_LIB_TABLE* aTable )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
static wxString OldName; // Save the name of the last module loaded.
|
|
|
|
wxString CmpName;
|
|
|
|
wxString msg;
|
|
|
|
wxArrayString libraries;
|
2013-05-28 16:54:59 +00:00
|
|
|
FP_LIB_TABLE libTable;
|
2013-05-08 20:47:23 +00:00
|
|
|
std::vector< wxArrayString > rows;
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
#if !defined( USE_FP_LIB_TABLE )
|
2011-02-22 20:59:16 +00:00
|
|
|
if( aLibraryFullFilename.IsEmpty() )
|
2013-05-20 14:49:20 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
libraries = g_LibraryNames;
|
2013-05-28 16:54:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
libraries.Add( aLibraryFullFilename );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( libraries.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
MList.ReadFootprintFiles( libraries );
|
2013-05-20 14:49:20 +00:00
|
|
|
#else
|
2013-05-28 16:54:59 +00:00
|
|
|
wxASSERT( aTable != NULL );
|
2013-05-20 14:49:20 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
if( aLibraryFullFilename.IsEmpty() )
|
|
|
|
{
|
2013-05-20 14:49:20 +00:00
|
|
|
std::vector< wxString > libNames = aTable->GetLogicalLibs();
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < libNames.size(); i++ )
|
|
|
|
{
|
2013-05-28 16:54:59 +00:00
|
|
|
FP_LIB_TABLE::ROW row = *aTable->FindRow( libNames[i] );
|
|
|
|
libTable.InsertRow( row );
|
2013-05-20 14:49:20 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-22 20:59:16 +00:00
|
|
|
else
|
2013-05-20 14:49:20 +00:00
|
|
|
{
|
2013-05-28 16:54:59 +00:00
|
|
|
FP_LIB_TABLE::ROW row = *aTable->FindRow( aLibraryFullFilename );
|
|
|
|
libTable.InsertRow( row );
|
2013-05-20 14:49:20 +00:00
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
if( libTable.IsEmpty() )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
|
|
|
DisplayError( aWindow, _( "No footprint libraries were specified." ) );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-09-22 17:20:46 +00:00
|
|
|
if( !MList.ReadFootprintFiles( libTable ) )
|
|
|
|
{
|
|
|
|
msg.Format( _( "Error occurred attempting to load footprint library <%s>:\n\n" ),
|
|
|
|
GetChars( aLibraryFullFilename ) );
|
|
|
|
|
|
|
|
if( !MList.m_filesNotFound.IsEmpty() )
|
|
|
|
msg += _( "Files not found:\n\n" ) + MList.m_filesNotFound;
|
|
|
|
|
|
|
|
if( !MList.m_filesInvalid.IsEmpty() )
|
|
|
|
msg += _("\n\nFile load errors:\n\n" ) + MList.m_filesInvalid;
|
|
|
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:54:59 +00:00
|
|
|
#endif
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
if( MList.GetCount() == 0 )
|
|
|
|
{
|
|
|
|
wxString tmp;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < libraries.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
tmp += libraries[i] + wxT( "\n" );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
msg.Printf( _( "No footprints could be read from library file(s):\n\n%s\nin any of "
|
|
|
|
"the library search paths. Verify your system is configured properly "
|
|
|
|
"so the footprint libraries can be found." ), GetChars( tmp ) );
|
|
|
|
DisplayError( aWindow, msg );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2011-05-09 19:44:06 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !aKeyWord.IsEmpty() ) // Create a list of modules found by keyword.
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
if( KeyWordOk( aKeyWord, MList.GetItem( ii ).m_KeyWord ) )
|
|
|
|
{
|
|
|
|
wxArrayString cols;
|
|
|
|
cols.Add( MList.GetItem( ii ).GetFootprintName() );
|
|
|
|
cols.Add( MList.GetItem( ii ).GetLibraryName() );
|
|
|
|
rows.push_back( cols );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
else if( !aMask.IsEmpty() ) // Create a list of modules found by pattern
|
2011-05-09 19:44:06 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
wxString& candidate = MList.GetItem( ii ).m_Module;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-05-09 19:44:06 +00:00
|
|
|
if( WildCompareString( aMask, candidate, false ) )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
|
|
|
wxArrayString cols;
|
|
|
|
cols.Add( MList.GetItem( ii ).GetFootprintName() );
|
|
|
|
cols.Add( MList.GetItem( ii ).GetLibraryName() );
|
|
|
|
rows.push_back( cols );
|
|
|
|
}
|
2011-05-09 19:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
else // Create the full list of modules
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
for( unsigned ii = 0; ii < MList.GetCount(); ii++ )
|
2013-05-08 20:47:23 +00:00
|
|
|
{
|
|
|
|
wxArrayString cols;
|
|
|
|
cols.Add( MList.GetItem( ii ).GetFootprintName() );
|
|
|
|
cols.Add( MList.GetItem( ii ).GetLibraryName() );
|
|
|
|
rows.push_back( cols );
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
if( !rows.empty() )
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2013-04-10 07:23:20 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
headers.Add( _( "Module" ) );
|
|
|
|
headers.Add( _( "Library" ) );
|
2013-04-10 07:23:20 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), (int) rows.size() );
|
|
|
|
EDA_LIST_DIALOG dlg( aWindow, msg, headers, rows, OldName, DisplayCmpDoc );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-07-06 16:40:54 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2013-01-10 12:18:43 +00:00
|
|
|
{
|
2011-07-06 16:40:54 +00:00
|
|
|
CmpName = dlg.GetTextSelection();
|
2013-05-08 20:47:23 +00:00
|
|
|
|
|
|
|
#if defined( USE_FP_LIB_TABLE )
|
2013-05-28 16:54:59 +00:00
|
|
|
CmpName = dlg.GetTextSelection( 1 ) + wxT( ":" ) + CmpName;
|
2013-05-08 20:47:23 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
SkipNextLeftButtonReleaseEvent();
|
|
|
|
}
|
2011-07-06 16:40:54 +00:00
|
|
|
else
|
|
|
|
CmpName.Empty();
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-07-06 16:40:54 +00:00
|
|
|
{
|
2013-05-08 20:47:23 +00:00
|
|
|
DisplayError( aWindow, _( "No footprint found." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
CmpName.Empty();
|
2011-07-06 16:40:54 +00:00
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( CmpName != wxEmptyString )
|
|
|
|
OldName = CmpName;
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
wxLogDebug( wxT( "Footprint <%s> was selected." ), GetChars( CmpName ) );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
return CmpName;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
static void DisplayCmpDoc( wxString& Name )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-02-22 20:59:16 +00:00
|
|
|
FOOTPRINT_INFO* module_info = MList.GetModuleInfo( Name );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
if( !module_info )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
Name.Empty();
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
Name = _( "Description: " ) + module_info->m_Doc;
|
|
|
|
Name += _( "\nKey words: " ) + module_info->m_KeyWord;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-05-08 20:47:23 +00:00
|
|
|
MODULE* FOOTPRINT_EDIT_FRAME::SelectFootprint( BOARD* aPcb )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-12-07 05:28:49 +00:00
|
|
|
MODULE* module;
|
2012-04-16 03:18:41 +00:00
|
|
|
static wxString OldName; // Save name of last module selected.
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString CmpName, msg;
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
wxArrayString listnames;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
module = aPcb->m_Modules;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
for( ; module != NULL; module = (MODULE*) module->Next() )
|
2013-03-13 18:53:58 +00:00
|
|
|
listnames.Add( module->GetReference() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
msg.Printf( _( "Modules [%d items]" ), listnames.GetCount() );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2013-05-08 20:47:23 +00:00
|
|
|
headers.Add( _( "Module" ) );
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2013-04-10 07:23:20 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < listnames.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( listnames[i] );
|
|
|
|
itemsToDisplay.push_back( item );
|
2013-04-10 07:23:20 +00:00
|
|
|
}
|
2013-05-08 20:47:23 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, msg, headers, itemsToDisplay, wxEmptyString, NULL, SORT_LIST );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
CmpName = dlg.GetTextSelection();
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
OldName = CmpName;
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
module = aPcb->m_Modules;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
for( ; module != NULL; module = (MODULE*) module->Next() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
if( CmpName == module->GetReference() )
|
2007-08-20 01:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-07 05:28:49 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs( wxCommandEvent& aEvent )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString curLibPath = getLibPath();
|
|
|
|
wxString dstLibPath = CreateNewLibrary();
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
if( !dstLibPath )
|
|
|
|
return; // user aborted in CreateNewLibrary()
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
IO_MGR::PCB_FILE_T dstType = IO_MGR::GuessPluginTypeFromLibPath( dstLibPath );
|
|
|
|
IO_MGR::PCB_FILE_T curType = IO_MGR::GuessPluginTypeFromLibPath( curLibPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
PLUGIN::RELEASER cur( IO_MGR::PluginFind( curType ) );
|
|
|
|
PLUGIN::RELEASER dst( IO_MGR::PluginFind( dstType ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxArrayString mods = cur->FootprintEnumerate( curLibPath );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
for( unsigned i = 0; i < mods.size(); ++i )
|
2012-10-07 15:37:25 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
std::auto_ptr<MODULE> m( cur->FootprintLoad( curLibPath, mods[i] ) );
|
|
|
|
dst->FootprintSave( dstLibPath, m.get() );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
// m is deleted here by auto_ptr.
|
2012-10-07 15:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format(
|
2013-05-08 20:47:23 +00:00
|
|
|
_( "Footprint library <%s> saved as <%s>." ),
|
2012-11-19 16:19:38 +00:00
|
|
|
GetChars( curLibPath ), GetChars( dstLibPath ) );
|
2012-10-07 15:37:25 +00:00
|
|
|
|
|
|
|
DisplayInfoMessage( this, msg );
|
|
|
|
}
|