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>
|
|
|
|
#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-04-17 01:35:43 +00:00
|
|
|
#include <legacy_plugin.h> // temporarily, for LoadMODULE()
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
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-09-30 18:15:37 +00:00
|
|
|
static const wxString ModExportFileWildcard( _( "KiCad foot print export files (*.emp)|*.emp" ) );
|
2011-10-13 18:37:43 +00:00
|
|
|
static const wxString ModImportFileWildcard( _( "GPcb foot print files (*)|*" ) );
|
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-04-17 01:35:43 +00:00
|
|
|
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
|
|
|
|
2011-10-13 18:37:43 +00:00
|
|
|
wxString importWildCard = ModExportFileWildcard + wxT("|") + ModImportFileWildcard;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileDialog dlg( this, _( "Import Footprint Module" ),
|
2012-04-17 01:35:43 +00:00
|
|
|
lastOpenedPathForLoading, wxEmptyString,
|
2011-10-13 18:37:43 +00:00
|
|
|
importWildCard, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-10-30 21:30:58 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
FILE* file = wxFopen( dlg.GetPath(), wxT( "rt" ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( file == NULL )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2009-10-13 09:00:46 +00:00
|
|
|
msg.Printf( _( "File <%s> 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-04-17 01:35:43 +00:00
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
FILE_LINE_READER fileReader( file, dlg.GetPath() );
|
|
|
|
|
|
|
|
FILTER_READER reader( fileReader );
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Read header and test file type
|
2011-01-14 17:43:30 +00:00
|
|
|
reader.ReadLine();
|
2012-04-17 01:35:43 +00:00
|
|
|
char* line = reader.Line();
|
|
|
|
|
|
|
|
bool footprint_Is_GPCB_Format = false;
|
2011-08-26 17:01:17 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( strnicmp( line, FOOTPRINT_LIBRARY_HEADER, FOOTPRINT_LIBRARY_HEADER_CNT ) != 0 )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( strnicmp( line, "Element", 7 ) == 0 )
|
2011-08-26 17:01:17 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
footprint_Is_GPCB_Format = true;
|
2011-08-26 17:01:17 +00:00
|
|
|
}
|
2008-04-17 16:25:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "Not a module file" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Read file: Search the description starting line (skip lib header)
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !footprint_Is_GPCB_Format )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2011-01-14 17:43:30 +00:00
|
|
|
while( reader.ReadLine() )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
if( strnicmp( line, "$MODULE", 7 ) == 0 )
|
2008-04-17 16:25:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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-04-17 01:35:43 +00:00
|
|
|
if( footprint_Is_GPCB_Format )
|
2008-04-17 16:25:29 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
// @todo GEDA plugin
|
|
|
|
module = new MODULE( GetBoard() );
|
2009-04-05 20:49:15 +00:00
|
|
|
module->Read_GPCB_Descr( dlg.GetPath() );
|
2008-04-17 16:25:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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-04-17 01:35:43 +00:00
|
|
|
LEGACY_PLUGIN* lp = (LEGACY_PLUGIN*)(PLUGIN*)pi;
|
|
|
|
|
|
|
|
lp->SetReader( &reader );
|
|
|
|
|
|
|
|
module = lp->LoadMODULE();
|
|
|
|
}
|
|
|
|
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 :
|
2009-04-17 08:51:02 +00:00
|
|
|
module->DisplayInfo( this );
|
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
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Export_Module( MODULE* aModule, bool aCreateSysLib )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn;
|
|
|
|
wxString msg, path, title, wildcard;
|
2012-04-17 01:35:43 +00:00
|
|
|
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 );
|
2012-03-08 17:47:23 +00:00
|
|
|
fn.SetExt( aCreateSysLib ? FootprintLibFileExtension : ModExportFileExtension );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aCreateSysLib )
|
2009-04-14 16:45:22 +00:00
|
|
|
path = wxGetApp().ReturnLastVisitedLibraryPath();
|
2012-04-17 01:35:43 +00:00
|
|
|
else if( config )
|
|
|
|
config->Read( EXPORT_IMPORT_LASTPATH_KEY, &path );
|
2008-03-12 11:49:16 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
title = aCreateSysLib ? _( "Create New Library" ) : _( "Export Module" );
|
2012-03-08 17:47:23 +00:00
|
|
|
wildcard = aCreateSysLib ? FootprintLibFileWildcard : ModExportFileWildcard;
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
fn.SetPath( path );
|
|
|
|
|
2012-03-08 17:47:23 +00:00
|
|
|
wxFileDialog dlg( this, msg, fn.GetPath(), fn.GetFullName(),
|
|
|
|
wxGetTranslation( wildcard ),
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
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();
|
2009-04-14 16:45:22 +00:00
|
|
|
wxGetApp().SaveLastVisitedLibraryPath( fn.GetPath() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !aCreateSysLib && 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-05-15 13:58:55 +00:00
|
|
|
wxString libPath = fn.GetFullPath();
|
2009-11-04 19:08:08 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// @todo : hard code this as IO_MGR::KICAD plugin, what would be the reason to "export"
|
|
|
|
// any other single footprint type, with clipboard support coming?
|
|
|
|
// Use IO_MGR::LEGACY for now, until the IO_MGR::KICAD plugin is ready.
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2012-05-15 13:58:55 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// try to delete the library whether it exists or not, quietly.
|
|
|
|
pi->FootprintLibDelete( libPath );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
// Ignore this, it will often happen and is not an error because
|
|
|
|
// the library may not exist. If library was in a read only directory,
|
|
|
|
// it will still exist as we get to the FootprintLibCreate() below.
|
|
|
|
}
|
|
|
|
|
|
|
|
pi->FootprintLibCreate( libPath );
|
|
|
|
pi->FootprintSave( libPath, aModule );
|
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-05-15 13:58:55 +00:00
|
|
|
msg.Printf( _( "Module exported in file <%s>" ), libPath.GetData() );
|
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-04-17 01:35:43 +00:00
|
|
|
void FOOTPRINT_EDIT_FRAME::Delete_Module_In_Library( const wxString& aLibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString footprintName = Select_1_Module_From_List( this, aLibName, wxEmptyString, wxEmptyString );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( footprintName == wxEmptyString )
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Confirmation
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString msg = wxString::Format( _( "Ok to delete module '%s' in library '%s'" ),
|
|
|
|
footprintName.GetData(), aLibName.GetData() );
|
2011-01-16 05:11:17 +00:00
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
if( !IsOK( this, msg ) )
|
|
|
|
return;
|
|
|
|
|
2012-04-16 03:18:41 +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 ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
pi->FootprintDelete( aLibName, 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 );
|
2007-10-30 21:30:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
msg.Printf( _( "Component '%s' deleted from library '%s'" ),
|
|
|
|
footprintName.GetData(), aLibName.GetData() );
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
SetStatusText( msg );
|
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
|
|
|
{
|
2011-09-26 20:32:56 +00:00
|
|
|
DisplayInfoMessage( this, _( "No modules to archive!" ) );
|
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
|
|
|
{
|
2009-04-14 16:45:22 +00:00
|
|
|
wxFileDialog dlg( this, _( "Library" ), path,
|
2012-03-08 17:47:23 +00:00
|
|
|
wxEmptyString,
|
|
|
|
wxGetTranslation( FootprintLibFileWildcard ),
|
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
|
|
|
{
|
|
|
|
wxString msg;
|
2012-04-17 01:35:43 +00:00
|
|
|
msg.Printf( _( "Library %s exists, OK to replace ?" ), 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
bool PCB_BASE_FRAME::Save_Module_In_Library( const wxString& aLibName,
|
|
|
|
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;
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
aModule->DisplayInfo( this );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !wxFileExists( aLibName ) )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString msg = wxString::Format( _( "Library <%s> not found." ),
|
|
|
|
aLibName.GetData() );
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
2011-02-22 20:59:16 +00:00
|
|
|
return false;
|
2007-10-30 21:30:58 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
if( !IsWritable( aLibName ) )
|
2011-08-26 17:01:17 +00:00
|
|
|
return false;
|
|
|
|
|
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-04-17 01:35:43 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Name:" ), _( "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-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-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-04-17 01:35:43 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
module_exists = pi->FootprintLoad( aLibName, 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 )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "Footprint '%s' already exists in library '%s'" ),
|
|
|
|
footprintName.GetData(), aLibName.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-04-17 01:35:43 +00:00
|
|
|
// this always overwrites any existing footprint
|
|
|
|
pi->FootprintSave( aLibName, 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
|
|
|
|
|
|
|
wxString msg = wxString::Format( fmt, footprintName.GetData(), aLibName.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
|
|
|
{
|
2007-10-30 21:30:58 +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
|
|
|
{
|
2010-07-20 18:11:34 +00:00
|
|
|
wxTextEntryDialog dlg( this, _( "Module Reference:" ),
|
2011-08-26 17:01:17 +00:00
|
|
|
_( "Module Creation" ), moduleName );
|
|
|
|
|
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( ) )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, _( "No reference, aborted" ) );
|
|
|
|
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
|
2009-01-05 05:21:35 +00:00
|
|
|
Module = new MODULE( GetBoard() );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
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
|
|
|
// Update parameters: position, timestamp ...
|
2011-02-11 20:48:13 +00:00
|
|
|
newpos = GetScreen()->GetCrossHairPosition();
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->SetPosition( newpos );
|
|
|
|
Module->m_LastEdit_Time = time( NULL );
|
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update its name in lib
|
2010-07-20 18:11:34 +00:00
|
|
|
Module->m_LibRef = moduleName;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-02-02 07:23:00 +00:00
|
|
|
// Update reference:
|
2010-07-20 18:11:34 +00:00
|
|
|
Module->m_Reference->m_Text = moduleName;
|
2012-02-02 17:45:37 +00:00
|
|
|
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
|
2007-10-30 21:30:58 +00:00
|
|
|
Module->m_Value->m_Text = wxT( "VAL**" );
|
2012-02-02 17:45:37 +00:00
|
|
|
Module->m_Value->SetThickness( GetDesignSettings().m_ModuleTextWidth );
|
|
|
|
Module->m_Value->SetSize( GetDesignSettings().m_ModuleTextSize );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2009-01-15 08:12:03 +00:00
|
|
|
Module->SetPosition( wxPoint( 0, 0 ) );
|
2008-11-10 20:45:24 +00:00
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
Module->DisplayInfo( this );
|
2007-10-30 21:30:58 +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-08-26 17:01:17 +00:00
|
|
|
wxString msg;
|
|
|
|
|
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
|
|
|
|
2011-09-27 20:43:18 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Select Active Library:" ), g_LibraryNames, m_CurrentLib );
|
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(),
|
|
|
|
FootprintLibFileExtension );
|
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() )
|
|
|
|
{
|
|
|
|
m_CurrentLib = dlg.GetTextSelection();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.Printf( _( "The footprint library <%s> could not be found in any of the search paths." ),
|
|
|
|
GetChars( dlg.GetTextSelection() ) );
|
|
|
|
DisplayError( this, msg );
|
|
|
|
m_CurrentLib.Empty();
|
|
|
|
}
|
2011-08-08 15:44:43 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
UpdateTitle();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-26 20:32:56 +00:00
|
|
|
int FOOTPRINT_EDIT_FRAME::CreateLibrary( const wxString& aLibName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-08-26 17:01:17 +00:00
|
|
|
wxFileName fileName = aLibName;
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( fileName.FileExists() )
|
2007-10-30 21:30:58 +00:00
|
|
|
{
|
2012-04-17 01:35:43 +00:00
|
|
|
wxString msg = wxString::Format(
|
|
|
|
_( "Library <%s> already exists." ),
|
|
|
|
aLibName.GetData() );
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-26 17:01:17 +00:00
|
|
|
if( !IsWritable( fileName ) )
|
|
|
|
return 0;
|
|
|
|
|
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 ) );
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
pi->FootprintLibCreate( aLibName );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR ioe )
|
|
|
|
{
|
|
|
|
DisplayError( this, ioe.errorText );
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
return 1; // remember how many times we succeeded
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2012-04-17 01:35:43 +00:00
|
|
|
|