2012-12-28 20:52:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 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-09-26 20:32:56 +00:00
|
|
|
/**
|
|
|
|
* @file librairi.cpp
|
|
|
|
* @brief Manage module (footprint) libraries.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2012-10-22 20:41:26 +00:00
|
|
|
#include <wx/ffile.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <filter_reader.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
#include <macros.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <module_editor_frame.h>
|
2012-03-08 17:47:23 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2012-10-22 20:41:26 +00:00
|
|
|
#include <kicad_plugin.h>
|
|
|
|
#include <legacy_plugin.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
// unique, "file local" translations:
|
|
|
|
|
|
|
|
#define FMT_OK_OVERWRITE _( "Library '%s' exists, OK to replace ?" )
|
|
|
|
#define FMT_CREATE_LIB _( "Create New Library" )
|
|
|
|
#define FMT_OK_DELETE _( "Ok to delete module '%s' in library '%s'" )
|
|
|
|
#define FMT_IMPORT_MODULE _( "Import Footprint Module" )
|
|
|
|
#define FMT_FILE_NOT_FOUND _( "File '%s' not found" )
|
|
|
|
#define FMT_NOT_MODULE _( "Not a module file" )
|
|
|
|
#define FMT_MOD_NOT_FOUND _( "Unable to find or load footprint '%s' from lib path '%s'" )
|
|
|
|
#define FMT_BAD_PATH _( "Unable to find or load footprint from path '%s'" )
|
|
|
|
#define FMT_BAD_PATHS _( "The footprint library '%s' could not be found in any of the search paths." )
|
|
|
|
#define FMT_LIB_READ_ONLY _( "Library '%s' is read only, not writable" )
|
|
|
|
|
|
|
|
#define FMT_EXPORT_MODULE _( "Export Module" )
|
|
|
|
#define FMT_SAVE_MODULE _( "Save Module" )
|
|
|
|
#define FMT_MOD_REF _( "Module Reference:" )
|
|
|
|
#define FMT_EXPORTED _( "Module exported to file '%s'" )
|
|
|
|
#define FMT_MOD_DELETED _( "Component '%s' deleted from library '%s'" )
|
|
|
|
#define FMT_MOD_CREATE _( "Module Creation" )
|
|
|
|
|
|
|
|
#define FMT_NO_MODULES _( "No modules to archive!" )
|
|
|
|
#define FMT_LIBRARY _( "Library" ) // window title
|
|
|
|
#define FMT_MOD_EXISTS _( "Footprint '%s' already exists in library '%s'" )
|
|
|
|
#define FMT_NO_REF_ABORTED _( "No reference, aborted" )
|
|
|
|
#define FMT_SELECT_LIB _( "Select Active Library:" )
|
|
|
|
|
|
|
|
|
|
|
|
static const wxString ModExportFileWildcard( _( "KiCad foot print export files (*.emp)|*.emp" ) );
|
|
|
|
static const wxString ModImportFileWildcard( _( "GPcb foot print files (*)|*" ) );
|
|
|
|
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
#define BACKUP_EXT wxT( "bak" )
|
2009-04-05 20:49:15 +00:00
|
|
|
#define FILETMP_EXT wxT( "$$$" )
|
2009-01-15 08:12:03 +00:00
|
|
|
#define EXPORT_IMPORT_LASTPATH_KEY wxT( "import_last_path" )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
const wxString ModExportFileExtension( wxT( "emp" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
MODULE* FOOTPRINT_EDIT_FRAME::Import_Module()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
// use the clipboard for this in the future?
|
2009-01-15 08:12:03 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
// Some day it might be useful save the last library type selected aong with the path.
|
|
|
|
static int lastFilterIndex = 0;
|
|
|
|
wxString lastOpenedPathForLoading;
|
|
|
|
wxConfig* config = wxGetApp().GetSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( config )
|
|
|
|
config->Read( EXPORT_IMPORT_LASTPATH_KEY, &lastOpenedPathForLoading );
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString wildCard;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wildCard << wxGetTranslation( KiCadFootprintLibFileWildcard ) << wxChar( '|' )
|
2012-12-28 20:52:12 +00:00
|
|
|
<< wxGetTranslation( ModExportFileWildcard ) << wxChar( '|' )
|
|
|
|
<< wxGetTranslation( ModImportFileWildcard ) << wxChar( '|' )
|
|
|
|
<< wxGetTranslation( GedaPcbFootprintLibFileWildcard );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
wxFileDialog dlg( this, FMT_IMPORT_MODULE,
|
2012-04-17 01:35:43 +00:00
|
|
|
lastOpenedPathForLoading, wxEmptyString,
|
2012-11-19 16:19:38 +00:00
|
|
|
wildCard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2012-12-28 20:52:12 +00:00
|
|
|
dlg.SetFilterIndex( lastFilterIndex );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
lastFilterIndex = dlg.GetFilterIndex();
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
FILE* fp = wxFopen( dlg.GetPath(), wxT( "rt" ) );
|
2012-12-28 20:52:12 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
if( !fp )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_FILE_NOT_FOUND, GetChars( dlg.GetPath() ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( config ) // Save file path
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
lastOpenedPathForLoading = wxPathOnly( dlg.GetPath() );
|
|
|
|
config->Write( EXPORT_IMPORT_LASTPATH_KEY, lastOpenedPathForLoading );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
wxString moduleName;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
bool isGeda = false;
|
|
|
|
bool isLegacy = false;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
{
|
2012-12-28 20:52:12 +00:00
|
|
|
FILE_LINE_READER freader( fp, dlg.GetPath() ); // I own fp, and will close it.
|
|
|
|
WHITESPACE_FILTER_READER reader( freader ); // skip blank lines
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
reader.ReadLine();
|
|
|
|
char* line = reader.Line();
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
if( !strnicmp( line, "(module", 7 ) )
|
|
|
|
{
|
|
|
|
// isKicad = true;
|
|
|
|
}
|
|
|
|
else if( !strnicmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) )
|
|
|
|
{
|
|
|
|
isLegacy = true;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
while( reader.ReadLine() )
|
|
|
|
{
|
|
|
|
if( !strnicmp( line, "$MODULE", 7 ) )
|
|
|
|
{
|
|
|
|
moduleName = FROM_UTF8( StrPurge( line + sizeof( "$MODULE" ) -1 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !strnicmp( line, "Element", 7 ) )
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2012-10-22 20:41:26 +00:00
|
|
|
isGeda = true;
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
else
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
DisplayError( this, FMT_NOT_MODULE );
|
2008-04-17 16:25:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
// fp is closed here by ~FILE_LINE_READER()
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE* module;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
if( isGeda )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2012-12-28 20:52:12 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
wxFileName fn = dlg.GetPath();
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::GEDA_PCB ) );
|
|
|
|
|
|
|
|
moduleName = fn.GetName();
|
|
|
|
module = pi->FootprintLoad( fn.GetPath(), moduleName );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-12-28 20:52:12 +00:00
|
|
|
if( !module )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
|
|
|
FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( fn.GetPath() ) );
|
|
|
|
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2012-10-22 20:41:26 +00:00
|
|
|
else if( isLegacy )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
module = pi->FootprintLoad( dlg.GetPath(), moduleName );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
if( !module )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
2012-11-19 16:19:38 +00:00
|
|
|
FMT_MOD_NOT_FOUND, GetChars( moduleName ), GetChars( dlg.GetPath() ) );
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // if( isKicad )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// This technique was chosen to create an example of how reading
|
|
|
|
// the s-expression format from clipboard could be done.
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
wxString fcontents;
|
2012-11-14 07:15:59 +00:00
|
|
|
PCB_IO pcb_io;
|
2012-10-23 17:20:22 +00:00
|
|
|
wxFFile f( dlg.GetPath() );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
|
|
|
if( !f.IsOpened() )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) );
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
f.ReadAll( &fcontents );
|
|
|
|
|
|
|
|
module = dynamic_cast<MODULE*>( pcb_io.Parse( fcontents ) );
|
|
|
|
|
|
|
|
if( !module )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_BAD_PATH, GetChars( dlg.GetPath() ) );
|
|
|
|
|
2012-10-22 20:41:26 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Insert footprint in list
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->Add( module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Display info :
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2011-09-16 14:13:02 +00:00
|
|
|
PlaceModule( module, NULL );
|
2009-01-05 05:21:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxConfig* config = wxGetApp().GetSettings();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aModule == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
fn.SetName( aModule->m_LibRef );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString wildcard = wxGetTranslation( KiCadFootprintLibFileWildcard );
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
fn.SetExt( KiCadFootprintFileExtension );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
if( config )
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
|
|
|
|
fn.SetPath( path );
|
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxFileDialog dlg( this, FMT_EXPORT_MODULE, fn.GetPath(), fn.GetFullName(),
|
|
|
|
wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
fn = dlg.GetPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
if( config ) // Save file path
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
|
|
|
{
|
2012-10-22 20:41:26 +00:00
|
|
|
// Export as *.kicad_pcb format, using a strategy which is specifically chosen
|
|
|
|
// as an example on how it could also be used to send it to the system clipboard.
|
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
PCB_IO pcb_io( CTL_FOR_LIBRARY );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
|
|
|
/* This module should *already* be "normalized" in a way such that
|
|
|
|
orientation is zero, etc., since it came from module editor.
|
|
|
|
|
|
|
|
module->SetTimeStamp( 0 );
|
|
|
|
module->SetParent( 0 );
|
|
|
|
module->SetOrientation( 0 );
|
|
|
|
*/
|
|
|
|
|
|
|
|
pcb_io.Format( aModule );
|
|
|
|
|
|
|
|
FILE* fp = wxFopen( dlg.GetPath(), wxT( "wt" ) );
|
|
|
|
fprintf( fp, "%s", pcb_io.GetStringOutput( false ).c_str() );
|
|
|
|
fclose( fp );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return;
|
|
|
|
}
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_EXPORTED, GetChars( dlg.GetPath() ) );
|
2009-04-17 08:51:02 +00:00
|
|
|
DisplayInfoMessage( this, msg );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
bool FOOTPRINT_EDIT_FRAME::SaveCurrentModule( const wxString* aLibPath )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString libPath = aLibPath ? *aLibPath : getLibPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
IO_MGR::PCB_FILE_T piType = IO_MGR::GuessPluginTypeFromLibPath( libPath );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
|
|
|
|
|
|
|
pi->FootprintSave( libPath, GetBoard()->m_Modules );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FOOTPRINT_EDIT_FRAME::CreateNewLibrary()
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
wxConfig* config = wxGetApp().GetSettings();
|
|
|
|
|
|
|
|
if( config )
|
|
|
|
{
|
|
|
|
wxString path;
|
|
|
|
config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
|
|
|
|
fn.SetPath( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString wildcard;
|
|
|
|
|
|
|
|
wildcard << wxGetTranslation( LegacyFootprintLibPathWildcard ) << wxChar('|')
|
|
|
|
<< wxGetTranslation( KiCadFootprintLibPathWildcard );
|
|
|
|
|
|
|
|
// prompt user for libPath and PLUGIN (library) type
|
|
|
|
wxFileDialog dlg( this, FMT_CREATE_LIB, fn.GetPath(), wxEmptyString,
|
|
|
|
wildcard,
|
|
|
|
wxFD_SAVE
|
|
|
|
// | wxFD_OVERWRITE_PROMPT overwrite is tested below
|
|
|
|
// after file extension has been added.
|
|
|
|
);
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
|
|
|
|
|
|
|
if( config ) // Save file path without filename, save user typing.
|
|
|
|
{
|
|
|
|
config->Write( EXPORT_IMPORT_LASTPATH_KEY, fn.GetPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// wildcard's filter index has legacy in position 0.
|
|
|
|
IO_MGR::PCB_FILE_T piType = ( dlg.GetFilterIndex() == 0 ) ? IO_MGR::LEGACY : IO_MGR::KICAD;
|
|
|
|
|
|
|
|
// wxFileDialog does not supply nor enforce the file extension, add it here.
|
|
|
|
if( piType == IO_MGR::LEGACY )
|
|
|
|
{
|
|
|
|
fn.SetExt( LegacyFootprintLibPathExtension );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fn.SetExt( KiCadFootprintLibPathExtension );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString libPath = fn.GetFullPath();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( piType ) );
|
|
|
|
|
|
|
|
bool writable = false;
|
|
|
|
bool exists = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
writable = pi->IsFootprintLibWritable( libPath );
|
|
|
|
exists = true; // no exception was thrown, lib must exist.
|
|
|
|
}
|
|
|
|
catch( IO_ERROR )
|
|
|
|
{
|
|
|
|
// ignore, original values of 'writable' and 'exists' are accurate.
|
|
|
|
}
|
|
|
|
|
|
|
|
if( exists )
|
|
|
|
{
|
|
|
|
if( !writable )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( FMT_LIB_READ_ONLY, GetChars( libPath ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( FMT_OK_OVERWRITE, GetChars( libPath ) );
|
|
|
|
|
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
pi->FootprintLibDelete( libPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pi->FootprintLibCreate( libPath );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
return libPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary()
|
|
|
|
{
|
|
|
|
wxString libPath = getLibPath();
|
|
|
|
wxString footprintName = Select_1_Module_From_List( this, libPath,
|
|
|
|
wxEmptyString, wxEmptyString );
|
|
|
|
|
|
|
|
if( !footprintName )
|
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Confirmation
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_OK_DELETE, footprintName.GetData(), libPath.GetData() );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
2012-11-19 16:19:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( libPath );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
try
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
pi->FootprintDelete( libPath, footprintName );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2012-04-16 03:18:41 +00:00
|
|
|
catch( IO_ERROR ioe )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-16 03:18:41 +00:00
|
|
|
DisplayError( NULL, ioe.errorText );
|
2012-11-19 16:19:38 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
msg.Printf( FMT_MOD_DELETED, footprintName.GetData(), libPath.GetData() );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2012-11-19 16:19:38 +00:00
|
|
|
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-06 19:00:59 +00:00
|
|
|
/* Save modules in a library:
|
|
|
|
* param aNewModulesOnly:
|
|
|
|
* true : save modules not already existing in this lib
|
|
|
|
* false: save all modules
|
|
|
|
*/
|
|
|
|
void PCB_EDIT_FRAME::ArchiveModulesOnBoard( const wxString& aLibName, bool aNewModulesOnly )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-01-06 19:00:59 +00:00
|
|
|
wxString fileName = aLibName;
|
|
|
|
wxString path;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
DisplayInfoMessage( this, FMT_NO_MODULES );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetApp().ReturnLastVisitedLibraryPath();
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !aLibName )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxFileDialog dlg( this, FMT_LIBRARY, path,
|
2012-03-08 17:47:23 +00:00
|
|
|
wxEmptyString,
|
2012-11-19 16:19:38 +00:00
|
|
|
wxGetTranslation( LegacyFootprintLibPathWildcard ),
|
2012-01-06 20:32:19 +00:00
|
|
|
wxFD_SAVE );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-04-15 19:53:41 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
fileName = dlg.GetPath();
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 22:15:22 +00:00
|
|
|
wxFileName fn( fileName );
|
2009-04-14 16:45:22 +00:00
|
|
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
2012-04-17 01:35:43 +00:00
|
|
|
bool lib_exists = wxFileExists( fileName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !aNewModulesOnly && lib_exists )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_OK_OVERWRITE, GetChars( fileName ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetAbortRequest( false );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// Delete old library if we're replacing it entirely.
|
|
|
|
if( lib_exists && !aNewModulesOnly )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
pi->FootprintLibDelete( fileName );
|
|
|
|
lib_exists = false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !lib_exists )
|
|
|
|
{
|
|
|
|
pi->FootprintLibCreate( fileName );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !aNewModulesOnly )
|
|
|
|
{
|
|
|
|
for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() )
|
|
|
|
{
|
|
|
|
pi->FootprintSave( fileName, m );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( MODULE* m = GetBoard()->m_Modules; m; m = m->Next() )
|
|
|
|
{
|
|
|
|
if( !Save_Module_In_Library( fileName, m, false, false ) )
|
|
|
|
break;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// Check for request to stop backup (ESCAPE key actuated)
|
|
|
|
if( m_canvas->GetAbortRequest() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibPath,
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* aModule,
|
|
|
|
bool aOverwrite,
|
|
|
|
bool aDisplayDialog )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-07-05 12:46:14 +00:00
|
|
|
if( aModule == NULL )
|
|
|
|
return false;
|
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( aModule );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// Ask what to use as the footprint name in the library
|
|
|
|
wxString footprintName = aModule->GetLibRef();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Name:" ), FMT_SAVE_MODULE, footprintName );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2012-04-17 01:35:43 +00:00
|
|
|
return false; // canceled by user
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
footprintName = dlg.GetValue();
|
|
|
|
footprintName.Trim( true );
|
|
|
|
footprintName.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( footprintName.IsEmpty() )
|
2011-07-08 07:12:28 +00:00
|
|
|
return false;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-12-10 11:18:42 +00:00
|
|
|
if( ! MODULE::IsLibNameValid( footprintName ) )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _("Error:\none of invalid chars <%s> found\nin <%s>" ),
|
|
|
|
MODULE::ReturnStringLibNameInvalidChars( true ),
|
|
|
|
GetChars( footprintName ) );
|
|
|
|
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
aModule->SetLibRef( footprintName );
|
2011-07-08 07:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure this footprint has a libname
|
2012-04-17 01:35:43 +00:00
|
|
|
if( footprintName.IsEmpty() )
|
2011-07-08 07:12:28 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
footprintName = wxT("noname");
|
|
|
|
aModule->SetLibRef( footprintName );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
IO_MGR::PCB_FILE_T pluginType = IO_MGR::GuessPluginTypeFromLibPath( aLibPath );
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
MODULE* module_exists = NULL;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
module_exists = pi->FootprintLoad( aLibPath, footprintName );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( module_exists )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
delete module_exists;
|
2011-07-08 07:12:28 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
// an existing footprint is found in current lib
|
|
|
|
if( aDisplayDialog )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_MOD_EXISTS,
|
|
|
|
footprintName.GetData(), aLibPath.GetData() );
|
2011-07-08 07:12:28 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
SetStatusText( msg );
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !aOverwrite )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
// Do not save the given footprint: an old one exists
|
|
|
|
return true;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
// this always overwrites any existing footprint, but should yell on its
|
|
|
|
// own if the library or footprint is not writable.
|
|
|
|
pi->FootprintSave( aLibPath, aModule );
|
2011-10-16 08:02:36 +00:00
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
catch( IO_ERROR ioe )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
DisplayError( this, ioe.errorText );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
if( aDisplayDialog )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2011-10-16 08:02:36 +00:00
|
|
|
wxString fmt = module_exists ?
|
|
|
|
_( "Component [%s] replaced in <%s>" ) :
|
|
|
|
_( "Component [%s] added in <%s>" );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibPath.GetData() );
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-02-22 20:59:16 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_BASE_FRAME::Create_1_Module( const wxString& aModuleName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
MODULE* module;
|
2010-07-20 18:11:34 +00:00
|
|
|
wxString moduleName;
|
2007-10-30 21:30:58 +00:00
|
|
|
wxPoint newpos;
|
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName = aModuleName;
|
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Ask for the new module reference
|
2010-07-20 18:11:34 +00:00
|
|
|
if( moduleName.IsEmpty() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxTextEntryDialog dlg( this, FMT_MOD_REF, FMT_MOD_CREATE, moduleName );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL; //Aborted by user
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-21 08:15:54 +00:00
|
|
|
moduleName = dlg.GetValue();
|
2010-07-20 18:11:34 +00:00
|
|
|
}
|
2011-09-26 20:32:56 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
moduleName.Trim( true );
|
|
|
|
moduleName.Trim( false );
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2010-07-20 18:11:34 +00:00
|
|
|
if( moduleName.IsEmpty( ) )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
DisplayInfoMessage( this, FMT_NO_REF_ABORTED );
|
2010-07-20 18:11:34 +00:00
|
|
|
return NULL;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
// Creates the new module and add it to the head of the linked list of modules
|
2012-11-19 16:19:38 +00:00
|
|
|
module = new MODULE( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
GetBoard()->Add( module );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update parameters: position, timestamp ...
|
2011-02-11 20:48:13 +00:00
|
|
|
newpos = GetScreen()->GetCrossHairPosition();
|
2012-11-19 16:19:38 +00:00
|
|
|
module->SetPosition( newpos );
|
|
|
|
module->SetLastEditTime();
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update its name in lib
|
2012-11-19 16:19:38 +00:00
|
|
|
module->m_LibRef = moduleName;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update reference:
|
2012-11-19 16:19:38 +00:00
|
|
|
module->m_Reference->m_Text = moduleName;
|
|
|
|
module->m_Reference->SetThickness( GetDesignSettings().m_ModuleTextWidth );
|
|
|
|
module->m_Reference->SetSize( GetDesignSettings().m_ModuleTextSize );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Set the value field to a default value
|
2012-11-19 16:19:38 +00:00
|
|
|
module->m_Value->m_Text = wxT( "VAL**" );
|
|
|
|
module->m_Value->SetThickness( GetDesignSettings().m_ModuleTextWidth );
|
|
|
|
module->m_Value->SetSize( GetDesignSettings().m_ModuleTextSize );
|
|
|
|
module->SetPosition( wxPoint( 0, 0 ) );
|
2008-11-10 20:45:24 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( module );
|
2012-11-19 16:19:38 +00:00
|
|
|
return module;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Select_Active_Library()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-09-27 20:43:18 +00:00
|
|
|
if( g_LibraryNames.GetCount() == 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, FMT_SELECT_LIB, g_LibraryNames, getLibNickName() );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-03-08 17:47:23 +00:00
|
|
|
wxFileName fileName = wxFileName( wxEmptyString, dlg.GetTextSelection(),
|
2012-11-19 16:19:38 +00:00
|
|
|
LegacyFootprintLibPathExtension );
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
fileName = wxGetApp().FindLibraryPath( fileName );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( fileName.IsOk() && fileName.FileExists() )
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
setLibNickName( fileName.GetName() );
|
|
|
|
setLibPath( fileName.GetFullPath() );
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-19 16:19:38 +00:00
|
|
|
wxString msg = wxString::Format( FMT_BAD_PATHS, GetChars( dlg.GetTextSelection() ) );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
DisplayError( this, msg );
|
2011-08-08 15:44:43 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
setLibNickName( wxEmptyString );
|
|
|
|
setLibPath( wxEmptyString );
|
2012-04-17 01:35:43 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
updateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2012-11-19 16:19:38 +00:00
|
|
|
|