2016-07-06 09:22:56 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2023-04-22 20:17:08 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see change_log.txt for contributors.
|
2016-07-06 09:22:56 +00:00
|
|
|
*
|
|
|
|
* @author Wayne Stambaugh <stambaughw@gmail.com>
|
|
|
|
*
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/filename.h>
|
|
|
|
#include <wx/uri.h>
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <sch_io/sch_io_mgr.h>
|
|
|
|
#include <sch_io/legacy/sch_legacy_plugin.h>
|
|
|
|
#include <sch_io/eagle/sch_eagle_plugin.h>
|
|
|
|
#include <sch_io/kicad/sch_sexpr_plugin.h>
|
|
|
|
|
|
|
|
#include <sch_io/altium/sch_altium_plugin.h>
|
|
|
|
#include <sch_io/cadstar/cadstar_sch_archive_plugin.h>
|
|
|
|
#include <sch_io/easyeda/sch_easyeda_plugin.h>
|
|
|
|
#include <sch_io/easyedapro/sch_easyedapro_plugin.h>
|
|
|
|
#include <sch_io/database/sch_database_plugin.h>
|
|
|
|
#include <sch_io/ltspice/ltspice_sch_plugin.h>
|
|
|
|
#include <sch_io/http_lib/sch_http_lib_plugin.h>
|
2023-04-26 16:14:55 +00:00
|
|
|
#include <common.h> // for ExpandEnvVarSubstitutions
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <kiway_player.h>
|
|
|
|
|
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." )
|
2016-07-06 09:22:56 +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.
|
|
|
|
// 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
|
|
|
|
// ::Draw() functions, I forgo that option temporarily.
|
|
|
|
|
|
|
|
// Some day it may be possible to have some built in AND some DLL/DSO
|
|
|
|
// plugins coexisting.
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
SCH_IO* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
// This implementation is subject to change, any magic is allowed here.
|
|
|
|
// The public SCH_IO_MGR API is the only pertinent public information.
|
|
|
|
|
|
|
|
switch( aFileType )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
case SCH_KICAD: return new SCH_SEXPR_PLUGIN();
|
2023-08-26 19:28:53 +00:00
|
|
|
case SCH_LEGACY: return new SCH_LEGACY_PLUGIN();
|
2021-03-31 21:33:30 +00:00
|
|
|
case SCH_ALTIUM: return new SCH_ALTIUM_PLUGIN();
|
|
|
|
case SCH_CADSTAR_ARCHIVE: return new CADSTAR_SCH_ARCHIVE_PLUGIN();
|
2022-05-29 19:29:32 +00:00
|
|
|
case SCH_DATABASE: return new SCH_DATABASE_PLUGIN();
|
2023-08-26 19:28:53 +00:00
|
|
|
case SCH_EAGLE: return new SCH_EAGLE_PLUGIN();
|
2023-09-06 11:58:39 +00:00
|
|
|
case SCH_EASYEDA: return new SCH_EASYEDA_PLUGIN();
|
|
|
|
case SCH_EASYEDAPRO: return new SCH_EASYEDAPRO_PLUGIN();
|
2023-04-22 20:17:08 +00:00
|
|
|
case SCH_LTSPICE: return new SCH_LTSPICE_PLUGIN();
|
2023-09-19 01:09:21 +00:00
|
|
|
case SCH_HTTP: return new SCH_HTTP_LIB_PLUGIN();
|
2021-03-31 21:33:30 +00:00
|
|
|
default: return nullptr;
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
void SCH_IO_MGR::ReleasePlugin( SCH_IO* aPlugin )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
delete aPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const wxString SCH_IO_MGR::ShowType( SCH_FILE_T aType )
|
|
|
|
{
|
|
|
|
// keep this function in sync with EnumFromStr() relative to the
|
|
|
|
// text spellings. If you change the spellings, you will obsolete
|
|
|
|
// library tables, so don't do change, only additions are ok.
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
case SCH_KICAD: return wxString( wxT( "KiCad" ) );
|
2023-08-26 19:28:53 +00:00
|
|
|
case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
|
2021-03-31 21:33:30 +00:00
|
|
|
case SCH_ALTIUM: return wxString( wxT( "Altium" ) );
|
|
|
|
case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) );
|
2022-05-29 19:29:32 +00:00
|
|
|
case SCH_DATABASE: return wxString( wxT( "Database" ) );
|
2023-08-26 19:28:53 +00:00
|
|
|
case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
|
2023-09-06 11:58:39 +00:00
|
|
|
case SCH_EASYEDA: return wxString( wxT( "EasyEDA (JLCEDA) Std" ) );
|
|
|
|
case SCH_EASYEDAPRO: return wxString( wxT( "EasyEDA (JLCEDA) Pro" ) );
|
2023-08-26 22:02:22 +00:00
|
|
|
case SCH_LTSPICE: return wxString( wxT( "LTspice" ) );
|
2023-09-19 01:09:21 +00:00
|
|
|
case SCH_HTTP: return wxString( wxT( "HTTP" ) );
|
2021-03-31 21:33:30 +00:00
|
|
|
default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
|
|
|
|
aType );
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr( const wxString& aType )
|
|
|
|
{
|
|
|
|
// keep this function in sync with ShowType() relative to the
|
|
|
|
// text spellings. If you change the spellings, you will obsolete
|
|
|
|
// library tables, so don't do change, only additions are ok.
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( aType == wxT( "KiCad" ) )
|
2020-02-13 13:39:52 +00:00
|
|
|
return SCH_KICAD;
|
2023-08-26 19:28:53 +00:00
|
|
|
else if( aType == wxT( "Legacy" ) )
|
|
|
|
return SCH_LEGACY;
|
2020-08-23 19:01:08 +00:00
|
|
|
else if( aType == wxT( "Altium" ) )
|
|
|
|
return SCH_ALTIUM;
|
2020-09-08 19:51:22 +00:00
|
|
|
else if( aType == wxT( "CADSTAR Schematic Archive" ) )
|
2020-09-19 22:05:02 +00:00
|
|
|
return SCH_CADSTAR_ARCHIVE;
|
2022-05-29 19:29:32 +00:00
|
|
|
else if( aType == wxT( "Database" ) )
|
|
|
|
return SCH_DATABASE;
|
2023-08-26 19:28:53 +00:00
|
|
|
else if( aType == wxT( "EAGLE" ) )
|
|
|
|
return SCH_EAGLE;
|
2023-09-06 11:58:39 +00:00
|
|
|
else if( aType == wxT( "EasyEDA (JLCEDA) Std" ) )
|
|
|
|
return SCH_EASYEDA;
|
|
|
|
else if( aType == wxT( "EasyEDA (JLCEDA) Pro" ) )
|
|
|
|
return SCH_EASYEDAPRO;
|
2023-08-26 22:02:22 +00:00
|
|
|
else if( aType == wxT( "LTspice" ) )
|
|
|
|
return SCH_LTSPICE;
|
2023-09-19 01:09:21 +00:00
|
|
|
else if( aType == wxT( "HTTP" ) )
|
|
|
|
return SCH_HTTP;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
|
|
|
// wxASSERT( blow up here )
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
return SCH_FILE_UNKNOWN;
|
2016-07-06 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
bool isKiCad = fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
|
|
|
continue;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
|
|
|
continue;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
2020-02-28 14:03:09 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( !pi )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( pi->CanReadLibrary( aLibPath ) )
|
|
|
|
return fileType;
|
2020-02-28 14:03:09 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
return SCH_IO_MGR::SCH_FILE_UNKNOWN;
|
2020-02-28 14:03:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& aSchematicPath,
|
|
|
|
int aCtl )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
for( const SCH_IO_MGR::SCH_FILE_T& fileType : SCH_IO_MGR::SCH_FILE_T_vector )
|
2016-07-06 09:22:56 +00:00
|
|
|
{
|
2023-08-26 19:28:53 +00:00
|
|
|
bool isKiCad = fileType == SCH_IO_MGR::SCH_KICAD || fileType == SCH_IO_MGR::SCH_LEGACY;
|
2023-02-26 22:37:05 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( ( aCtl & KICTL_KICAD_ONLY ) && !isKiCad )
|
|
|
|
continue;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( ( aCtl & KICTL_NONKICAD_ONLY ) && isKiCad )
|
|
|
|
continue;
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
SCH_IO::SCH_IO_RELEASER pi( SCH_IO_MGR::FindPlugin( fileType ) );
|
2016-07-06 09:22:56 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( !pi )
|
|
|
|
continue;
|
2020-03-16 13:04:50 +00:00
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
if( pi->CanReadSchematicFile( aSchematicPath ) )
|
|
|
|
return fileType;
|
2020-03-16 13:04:50 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 19:28:53 +00:00
|
|
|
return SCH_IO_MGR::SCH_FILE_UNKNOWN;
|
2020-03-16 13:04:50 +00:00
|
|
|
}
|