2011-11-28 04:32:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-04-17 14:54:48 +00:00
|
|
|
* Copyright (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2023-08-13 02:26:06 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-28 04:32:29 +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
|
|
|
|
*/
|
|
|
|
|
2012-11-19 16:19:38 +00:00
|
|
|
#include <wx/filename.h>
|
2013-09-23 15:19:39 +00:00
|
|
|
#include <wx/uri.h>
|
2011-11-28 04:32:29 +00:00
|
|
|
|
2020-04-03 23:22:24 +00:00
|
|
|
#include <config.h>
|
2023-08-12 14:37:02 +00:00
|
|
|
#include <kiway_player.h>
|
|
|
|
#include <io_mgr.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2020-10-03 20:48:58 +00:00
|
|
|
#include <plugins/eagle/eagle_plugin.h>
|
2020-10-04 12:35:04 +00:00
|
|
|
#include <plugins/geda/gpcb_plugin.h>
|
2021-11-25 12:22:40 +00:00
|
|
|
#include <plugins/kicad/pcb_plugin.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <plugins/legacy/legacy_plugin.h>
|
2020-10-05 18:10:13 +00:00
|
|
|
#include <plugins/pcad/pcad_plugin.h>
|
2020-08-23 19:01:08 +00:00
|
|
|
#include <plugins/altium/altium_circuit_maker_plugin.h>
|
|
|
|
#include <plugins/altium/altium_circuit_studio_plugin.h>
|
|
|
|
#include <plugins/altium/altium_designer_plugin.h>
|
2023-06-16 00:41:56 +00:00
|
|
|
#include <plugins/altium/solidworks_pcb_plugin.h>
|
2020-08-29 18:09:48 +00:00
|
|
|
#include <plugins/cadstar/cadstar_pcb_archive_plugin.h>
|
2020-07-01 22:30:40 +00:00
|
|
|
#include <plugins/fabmaster/fabmaster_plugin.h>
|
2023-09-06 11:58:39 +00:00
|
|
|
#include <plugins/easyeda/pcb_easyeda_plugin.h>
|
|
|
|
#include <plugins/easyedapro/pcb_easyedapro_plugin.h>
|
2023-06-12 18:12:39 +00:00
|
|
|
#include <plugins/ipc2581/ipc2581_plugin.h>
|
2011-11-28 04:32:29 +00:00
|
|
|
|
2017-12-15 11:37:46 +00:00
|
|
|
#define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
|
|
|
|
#define FMT_NOTFOUND _( "Plugin type \"%s\" is not found." )
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-11-28 04:32:29 +00:00
|
|
|
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.
|
|
|
|
|
2017-10-30 23:21:16 +00:00
|
|
|
return PLUGIN_REGISTRY::Instance()->Create( aFileType );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-17 15:12:17 +00:00
|
|
|
const wxString IO_MGR::ShowType( PCB_FILE_T aType )
|
2011-11-28 04:32:29 +00:00
|
|
|
{
|
2017-10-30 23:21:16 +00:00
|
|
|
const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2017-10-30 23:21:16 +00:00
|
|
|
for( const auto& plugin : plugins )
|
|
|
|
{
|
|
|
|
if ( plugin.m_type == aType )
|
|
|
|
{
|
|
|
|
return plugin.m_name;
|
|
|
|
}
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
2017-10-30 23:21:16 +00:00
|
|
|
|
2018-03-03 20:07:59 +00:00
|
|
|
return wxString::Format( _( "UNKNOWN (%d)" ), aType );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-17 15:12:17 +00:00
|
|
|
IO_MGR::PCB_FILE_T IO_MGR::EnumFromStr( const wxString& aType )
|
|
|
|
{
|
2017-10-30 23:21:16 +00:00
|
|
|
const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
|
2012-10-17 15:12:17 +00:00
|
|
|
|
2017-10-30 23:21:16 +00:00
|
|
|
for( const auto& plugin : plugins )
|
|
|
|
{
|
|
|
|
if ( plugin.m_name == aType )
|
|
|
|
{
|
|
|
|
return plugin.m_type;
|
|
|
|
}
|
|
|
|
}
|
2012-10-17 15:12:17 +00:00
|
|
|
|
|
|
|
return PCB_FILE_T( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-12 14:37:02 +00:00
|
|
|
// The KIWAY_PLAYER::OpenProjectFiles() API knows nothing about plugins, so
|
|
|
|
// determine how to load the BOARD here
|
|
|
|
IO_MGR::PCB_FILE_T IO_MGR::FindPluginTypeFromBoardPath( const wxString& aFileName, int aCtl )
|
|
|
|
{
|
|
|
|
const auto& plugins = IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
|
|
|
|
|
|
|
|
for( const auto& plugin : plugins )
|
|
|
|
{
|
|
|
|
bool isKiCad = plugin.m_type == IO_MGR::KICAD_SEXP || plugin.m_type == IO_MGR::LEGACY;
|
|
|
|
|
|
|
|
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PLUGIN::RELEASER pi( plugin.m_createFunc() );
|
|
|
|
|
|
|
|
if( pi->CanReadBoard( aFileName ) )
|
|
|
|
return plugin.m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IO_MGR::FILE_TYPE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl )
|
2012-11-19 16:19:38 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
const auto& plugins = IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
|
2012-11-19 16:19:38 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
for( const auto& plugin : plugins )
|
2023-08-28 20:44:10 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
bool isKiCad = plugin.m_type == IO_MGR::KICAD_SEXP || plugin.m_type == IO_MGR::LEGACY;
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
PLUGIN::RELEASER pi( plugin.m_createFunc() );
|
|
|
|
|
|
|
|
if( pi->CanReadFootprintLib( aLibPath ) )
|
|
|
|
return plugin.m_type;
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
return IO_MGR::FILE_TYPE_NONE;
|
2012-11-19 16:19:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:40:13 +00:00
|
|
|
BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aAppendToMe,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
|
2021-06-23 22:53:08 +00:00
|
|
|
PROGRESS_REPORTER* aProgressReporter )
|
2011-11-28 04:32:29 +00:00
|
|
|
{
|
|
|
|
// release the PLUGIN even if an exception is thrown.
|
2013-10-05 10:34:55 +00:00
|
|
|
PLUGIN::RELEASER pi( PluginFind( aFileType ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
|
|
|
|
if( (PLUGIN*) pi ) // test pi->plugin
|
|
|
|
{
|
2023-08-13 02:11:58 +00:00
|
|
|
return pi->LoadBoard( aFileName, aAppendToMe, aProperties, aProject, aProgressReporter );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
|
2011-11-28 04:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-18 15:40:13 +00:00
|
|
|
void IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties )
|
2011-12-02 16:57:44 +00:00
|
|
|
{
|
|
|
|
// release the PLUGIN even if an exception is thrown.
|
2013-10-05 10:34:55 +00:00
|
|
|
PLUGIN::RELEASER pi( PluginFind( aFileType ) );
|
2011-12-02 16:57:44 +00:00
|
|
|
|
|
|
|
if( (PLUGIN*) pi ) // test pi->plugin
|
|
|
|
{
|
2023-08-13 02:11:58 +00:00
|
|
|
pi->SaveBoard( aFileName, aBoard, aProperties ); // virtual
|
2011-12-02 16:57:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
|
2011-12-02 16:57:44 +00:00
|
|
|
}
|
2017-11-04 20:00:42 +00:00
|
|
|
|
2018-03-03 20:07:59 +00:00
|
|
|
// These text strings are "truth" for identifying the plugins. If you change the spellings,
|
|
|
|
// you will obsolete library tables, so don't do it. Additions are OK.
|
2023-08-05 13:37:20 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
// clang-format off
|
2023-08-05 13:37:20 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerKicadPlugin(
|
|
|
|
IO_MGR::KICAD_SEXP,
|
2023-08-13 02:26:06 +00:00
|
|
|
wxT( "KiCad" ),
|
2023-08-05 13:37:20 +00:00
|
|
|
[]() -> PLUGIN* { return new PCB_PLUGIN; } );
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerLegacyPlugin(
|
|
|
|
IO_MGR::LEGACY,
|
|
|
|
wxT( "Legacy" ),
|
|
|
|
[]() -> PLUGIN* { return new LEGACY_PLUGIN; } );
|
2023-08-05 13:37:20 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
// Keep non-KiCad plugins in alphabetical order
|
2023-08-05 13:37:20 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerAltiumCircuitMakerPlugin(
|
|
|
|
IO_MGR::ALTIUM_CIRCUIT_MAKER,
|
|
|
|
wxT( "Altium Circuit Maker" ),
|
|
|
|
[]() -> PLUGIN* { return new ALTIUM_CIRCUIT_MAKER_PLUGIN; } );
|
2023-08-05 13:37:20 +00:00
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerAltiumCircuitStudioPlugin(
|
|
|
|
IO_MGR::ALTIUM_CIRCUIT_STUDIO,
|
2020-04-03 23:22:24 +00:00
|
|
|
wxT( "Altium Circuit Studio" ),
|
|
|
|
[]() -> PLUGIN* { return new ALTIUM_CIRCUIT_STUDIO_PLUGIN; } );
|
2023-08-05 13:37:20 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerAltiumDesignerPlugin(
|
|
|
|
IO_MGR::ALTIUM_DESIGNER,
|
|
|
|
wxT( "Altium Designer" ),
|
|
|
|
[]() -> PLUGIN* { return new ALTIUM_DESIGNER_PLUGIN; } );
|
2023-08-05 13:37:20 +00:00
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerCadstarArchivePlugin(
|
|
|
|
IO_MGR::CADSTAR_PCB_ARCHIVE,
|
|
|
|
wxT( "CADSTAR PCB Archive" ),
|
|
|
|
[]() -> PLUGIN* { return new CADSTAR_PCB_ARCHIVE_PLUGIN; } );
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerEaglePlugin(
|
|
|
|
IO_MGR::EAGLE,
|
|
|
|
wxT( "Eagle" ),
|
|
|
|
[]() -> PLUGIN* { return new EAGLE_PLUGIN; } );
|
|
|
|
|
2023-09-06 11:58:39 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerEasyEDAPlugin(
|
|
|
|
IO_MGR::EASYEDA,
|
|
|
|
wxT( "EasyEDA / JLCEDA Std" ),
|
|
|
|
[]() -> PLUGIN* { return new EASYEDA_PLUGIN; });
|
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerEasyEDAProPlugin(
|
|
|
|
IO_MGR::EASYEDAPRO,
|
|
|
|
wxT( "EasyEDA / JLCEDA Pro" ),
|
|
|
|
[]() -> PLUGIN* { return new EASYEDAPRO_PLUGIN; });
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
static IO_MGR::REGISTER_PLUGIN registerFabmasterPlugin(
|
|
|
|
IO_MGR::FABMASTER,
|
|
|
|
wxT( "Fabmaster" ),
|
|
|
|
[]() -> PLUGIN* { return new FABMASTER_PLUGIN; } );
|
2023-08-05 13:37:20 +00:00
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerGPCBPlugin(
|
|
|
|
IO_MGR::GEDA_PCB,
|
2023-08-13 02:26:06 +00:00
|
|
|
wxT( "GEDA/Pcb" ),
|
2023-08-05 13:37:20 +00:00
|
|
|
[]() -> PLUGIN* { return new GPCB_PLUGIN; } );
|
2023-08-13 02:26:06 +00:00
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerPcadPlugin(
|
|
|
|
IO_MGR::PCAD,
|
|
|
|
wxT( "P-Cad" ),
|
|
|
|
[]() -> PLUGIN* { return new PCAD_PLUGIN; } );
|
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerSolidworksPCBPlugin(
|
|
|
|
IO_MGR::SOLIDWORKS_PCB,
|
|
|
|
wxT( "Solidworks PCB" ),
|
|
|
|
[]() -> PLUGIN* { return new SOLIDWORKS_PCB_PLUGIN; } );
|
2023-06-12 18:12:39 +00:00
|
|
|
|
|
|
|
static IO_MGR::REGISTER_PLUGIN registerIPC2581Plugin(
|
|
|
|
IO_MGR::IPC2581,
|
|
|
|
wxT( "IPC-2581" ),
|
|
|
|
[]() -> PLUGIN* { return new IPC2581_PLUGIN; } );
|
2023-08-13 02:26:06 +00:00
|
|
|
// clang-format on
|