2011-11-28 04:32:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <io_mgr.h>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <legacy_plugin.h>
|
2011-11-28 04:32:29 +00:00
|
|
|
#include <kicad_plugin.h>
|
|
|
|
|
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
// Some day plugins might be in separate DLL/DSOs, simply because of numbers of them
|
|
|
|
// and code size. Until then, use the simplest method:
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
// This implementation is one of two which could be done.
|
2011-11-30 07:43:46 +00:00
|
|
|
// The other one would cater to DLL/DSO's. But since it would be nearly
|
2011-11-28 04:32:29 +00:00
|
|
|
// impossible to link a KICAD type DLL/DSO right now without pulling in all
|
2011-11-30 07:43:46 +00:00
|
|
|
// ::Draw() functions, I forgo that option temporarily.
|
2011-11-28 04:32:29 +00:00
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
// Some day it may be possible to have some built in AND some DLL/DSO
|
|
|
|
// plugins coexisting.
|
2011-11-28 04:32:29 +00:00
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
// static LEGACY_PLUGIN kicad_plugin; // a secret
|
2011-11-28 04:32:29 +00:00
|
|
|
//static EAGLE_PLUGIN eagle_plugin;
|
|
|
|
|
|
|
|
PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType )
|
|
|
|
{
|
2011-11-30 07:43:46 +00:00
|
|
|
// This implementation is subject to change, any magic is allowed here.
|
|
|
|
// The public IO_MGR API is the only pertinent public information.
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
switch( aFileType )
|
|
|
|
{
|
2012-04-07 18:05:56 +00:00
|
|
|
case LEGACY:
|
|
|
|
return new LEGACY_PLUGIN();
|
|
|
|
|
2011-12-05 17:22:19 +00:00
|
|
|
case KICAD:
|
|
|
|
return new KICAD_PLUGIN();
|
|
|
|
|
|
|
|
/*
|
|
|
|
case EAGLE:
|
|
|
|
return &eagle_plugin;
|
|
|
|
*/
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IO_MGR::PluginRelease( PLUGIN* aPlugin )
|
|
|
|
{
|
|
|
|
// This function is a place holder for a future point in time where
|
|
|
|
// the plugin is a DLL/DSO. It could do reference counting, and then
|
|
|
|
// unload the DLL/DSO when count goes to zero.
|
2011-12-05 17:22:19 +00:00
|
|
|
|
|
|
|
delete aPlugin;
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
const wxString IO_MGR::ShowType( PCB_FILE_T aFileType )
|
2011-11-28 04:32:29 +00:00
|
|
|
{
|
|
|
|
switch( aFileType )
|
|
|
|
{
|
|
|
|
default:
|
2011-12-02 21:56:47 +00:00
|
|
|
return wxString::Format( _( "Unknown PCB_FILE_T value: %d" ), aFileType );
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
case LEGACY:
|
|
|
|
return wxString( wxT( "KiCad Legacy" ) );
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
case KICAD:
|
|
|
|
return wxString( wxT( "KiCad" ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
const wxString IO_MGR::GetFileExtension( PCB_FILE_T aFileType )
|
|
|
|
{
|
|
|
|
wxString ext = wxEmptyString;
|
|
|
|
PLUGIN* plugin = PluginFind( aFileType );
|
|
|
|
|
|
|
|
if( plugin != NULL )
|
|
|
|
{
|
|
|
|
ext = plugin->GetFileExtension();
|
|
|
|
PluginRelease( plugin );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName,
|
2012-04-07 18:05:56 +00:00
|
|
|
BOARD* aAppendToMe, PROPERTIES* aProperties )
|
2011-11-28 04:32:29 +00:00
|
|
|
{
|
|
|
|
// release the PLUGIN even if an exception is thrown.
|
|
|
|
PLUGIN::RELEASER pi = PluginFind( aFileType );
|
|
|
|
|
|
|
|
if( (PLUGIN*) pi ) // test pi->plugin
|
|
|
|
{
|
|
|
|
return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
|
|
|
|
}
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Plugin type '%s' is not found." ), ShowType( aFileType ).GetData() ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-02 16:57:44 +00:00
|
|
|
void IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
// release the PLUGIN even if an exception is thrown.
|
|
|
|
PLUGIN::RELEASER pi = PluginFind( aFileType );
|
|
|
|
|
|
|
|
if( (PLUGIN*) pi ) // test pi->plugin
|
|
|
|
{
|
|
|
|
pi->Save( aFileName, aBoard, aProperties ); // virtual
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Plugin type '%s' is not found." ), ShowType( aFileType ).GetData() ) );
|
2011-12-02 16:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties )
|
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
|
|
|
|
// e.g. Load() or Save() but not both.
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Plugin %s does not implement the BOARD Load() function." ), PluginName().GetData() ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-02 16:57:44 +00:00
|
|
|
void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, PROPERTIES* aProperties )
|
2011-11-28 04:32:29 +00:00
|
|
|
{
|
|
|
|
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
|
|
|
|
// e.g. Load() or Save() but not both.
|
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Plugin %s does not implement the BOARD Save() function." ), PluginName().GetData() ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|