kicad/pcbnew/pcb_io/pcb_io_mgr.cpp

261 lines
8.7 KiB
C++
Raw Normal View History

/*
* 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>
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.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 <wx/filename.h>
#include <wx/uri.h>
#include <config.h>
#include <kiway_player.h>
#include <wildcards_and_files_ext.h>
#include <pcb_io/pcb_io_mgr.h>
2023-12-24 01:21:58 +00:00
#include <pcb_io/eagle/pcb_io_eagle.h>
#include <pcb_io/geda/pcb_io_geda.h>
#include <pcb_io/kicad_sexpr/pcb_io_kicad_sexpr.h>
#include <pcb_io/kicad_legacy/pcb_io_kicad_legacy.h>
#include <pcb_io/pcad/pcb_io_pcad.h>
#include <pcb_io/altium/pcb_io_altium_circuit_maker.h>
#include <pcb_io/altium/pcb_io_altium_circuit_studio.h>
#include <pcb_io/altium/pcb_io_altium_designer.h>
#include <pcb_io/altium/pcb_io_solidworks.h>
#include <pcb_io/cadstar/pcb_io_cadstar_archive.h>
#include <pcb_io/fabmaster/pcb_io_fabmaster.h>
#include <pcb_io/easyeda/pcb_io_easyeda_plugin.h>
#include <pcb_io/easyedapro/pcb_io_easyedapro.h>
#include <pcb_io/ipc2581/pcb_io_ipc2581.h>
#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:
// 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
// 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-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-30 07:43:46 +00:00
PCB_IO* PCB_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.
return PLUGIN_REGISTRY::Instance()->Create( aFileType );
}
const wxString PCB_IO_MGR::ShowType( PCB_FILE_T aType )
{
const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
for( const auto& plugin : plugins )
{
if ( plugin.m_type == aType )
{
return plugin.m_name;
}
}
return wxString::Format( _( "UNKNOWN (%d)" ), aType );
}
PCB_IO_MGR::PCB_FILE_T PCB_IO_MGR::EnumFromStr( const wxString& aType )
2012-10-17 15:12:17 +00:00
{
const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
2012-10-17 15:12:17 +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 );
}
// The KIWAY_PLAYER::OpenProjectFiles() API knows nothing about plugins, so
// determine how to load the BOARD here
PCB_IO_MGR::PCB_FILE_T PCB_IO_MGR::FindPluginTypeFromBoardPath( const wxString& aFileName, int aCtl )
{
const auto& plugins = PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
for( const auto& plugin : plugins )
{
bool isKiCad = plugin.m_type == PCB_IO_MGR::KICAD_SEXP || plugin.m_type == PCB_IO_MGR::LEGACY;
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
continue;
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
continue;
IO_RELEASER<PCB_IO> pi( plugin.m_createFunc() );
if( pi->CanReadBoard( aFileName ) )
return plugin.m_type;
}
return PCB_IO_MGR::FILE_TYPE_NONE;
}
PCB_IO_MGR::PCB_FILE_T PCB_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl )
{
const auto& plugins = PCB_IO_MGR::PLUGIN_REGISTRY::Instance()->AllPlugins();
for( const auto& plugin : plugins )
{
bool isKiCad = plugin.m_type == PCB_IO_MGR::KICAD_SEXP || plugin.m_type == PCB_IO_MGR::LEGACY;
2013-09-21 07:30:23 +00:00
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
continue;
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
continue;
IO_RELEASER<PCB_IO> pi( plugin.m_createFunc() );
2023-12-27 00:25:41 +00:00
if( pi->CanReadLibrary( aLibPath ) )
return plugin.m_type;
}
return PCB_IO_MGR::FILE_TYPE_NONE;
}
BOARD* PCB_IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aAppendToMe,
const STRING_UTF8_MAP* aProperties, PROJECT* aProject,
PROGRESS_REPORTER* aProgressReporter )
{
IO_RELEASER<PCB_IO> pi( PluginFind( aFileType ) );
if( pi ) // test pi->plugin
{
pi->SetProgressReporter( aProgressReporter );
return pi->LoadBoard( aFileName, aAppendToMe, aProperties, aProject );
}
2012-04-16 03:18:41 +00:00
THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
}
void PCB_IO_MGR::Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard,
const STRING_UTF8_MAP* aProperties )
2011-12-02 16:57:44 +00:00
{
IO_RELEASER<PCB_IO> pi( PluginFind( aFileType ) );
2011-12-02 16:57:44 +00:00
if( pi )
2011-12-02 16:57:44 +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
}
// 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.
// clang-format off
static PCB_IO_MGR::REGISTER_PLUGIN registerKicadPlugin(
PCB_IO_MGR::KICAD_SEXP,
wxT( "KiCad" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_KICAD_SEXPR; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerLegacyPlugin(
PCB_IO_MGR::LEGACY,
wxT( "Legacy" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_KICAD_LEGACY; } );
// Keep non-KiCad plugins in alphabetical order
static PCB_IO_MGR::REGISTER_PLUGIN registerAltiumCircuitMakerPlugin(
PCB_IO_MGR::ALTIUM_CIRCUIT_MAKER,
wxT( "Altium Circuit Maker" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_ALTIUM_CIRCUIT_MAKER; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerAltiumCircuitStudioPlugin(
PCB_IO_MGR::ALTIUM_CIRCUIT_STUDIO,
wxT( "Altium Circuit Studio" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_ALTIUM_CIRCUIT_STUDIO; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerAltiumDesignerPlugin(
PCB_IO_MGR::ALTIUM_DESIGNER,
wxT( "Altium Designer" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_ALTIUM_DESIGNER; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerCadstarArchivePlugin(
PCB_IO_MGR::CADSTAR_PCB_ARCHIVE,
wxT( "CADSTAR PCB Archive" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_CADSTAR_ARCHIVE; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerEaglePlugin(
PCB_IO_MGR::EAGLE,
wxT( "Eagle" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_EAGLE; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerEasyEDAPlugin(
PCB_IO_MGR::EASYEDA,
wxT( "EasyEDA / JLCEDA Std" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_EASYEDA; });
static PCB_IO_MGR::REGISTER_PLUGIN registerEasyEDAProPlugin(
PCB_IO_MGR::EASYEDAPRO,
wxT( "EasyEDA / JLCEDA Pro" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_EASYEDAPRO; });
static PCB_IO_MGR::REGISTER_PLUGIN registerFabmasterPlugin(
PCB_IO_MGR::FABMASTER,
wxT( "Fabmaster" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_FABMASTER; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerGPCBPlugin(
PCB_IO_MGR::GEDA_PCB,
wxT( "GEDA/Pcb" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_GEDA; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerPcadPlugin(
PCB_IO_MGR::PCAD,
wxT( "P-Cad" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_PCAD; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerSolidworksPCBPlugin(
PCB_IO_MGR::SOLIDWORKS_PCB,
wxT( "Solidworks PCB" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_SOLIDWORKS; } );
static PCB_IO_MGR::REGISTER_PLUGIN registerIPC2581Plugin(
PCB_IO_MGR::IPC2581,
wxT( "IPC-2581" ),
2023-12-24 01:21:58 +00:00
[]() -> PCB_IO* { return new PCB_IO_IPC2581; } );
// clang-format on