25#include <wx/filename.h>
56#define FMT_UNIMPLEMENTED _( "Plugin '%s' does not implement the '%s' function." )
57#define FMT_NOTFOUND _( "Plugin type '%s' is not found." )
73SCH_IO* SCH_IO_MGR::FindPlugin( SCH_FILE_T aFileType )
98 default:
return nullptr;
111 case SCH_KICAD:
return wxString( wxT(
"KiCad" ) );
112 case SCH_LEGACY:
return wxString( wxT(
"Legacy" ) );
113 case SCH_ALTIUM:
return wxString( wxT(
"Altium" ) );
114 case SCH_CADSTAR_ARCHIVE:
return wxString( wxT(
"CADSTAR Schematic Archive" ) );
115 case SCH_DATABASE:
return wxString( wxT(
"Database" ) );
116 case SCH_EAGLE:
return wxString( wxT(
"EAGLE" ) );
117 case SCH_EASYEDA:
return wxString( wxT(
"EasyEDA (JLCEDA) Std" ) );
118 case SCH_EASYEDAPRO:
return wxString( wxT(
"EasyEDA (JLCEDA) Pro" ) );
119 case SCH_EASYEDAPRO_V3:
return wxString( wxT(
"EasyEDA (JLCEDA) Pro v3" ) );
120 case SCH_GEDA:
return wxString( wxT(
"gEDA / Lepton EDA" ) );
121 case SCH_LTSPICE:
return wxString( wxT(
"LTspice" ) );
122 case SCH_HTTP:
return wxString( wxT(
"HTTP" ) );
123 case SCH_PADS:
return wxString( wxT(
"PADS Logic" ) );
124 case SCH_DIPTRACE:
return wxString( wxT(
"DipTrace" ) );
125 case SCH_PCAD:
return wxString( wxT(
"P-CAD" ) );
126 case SCH_ORCAD:
return wxString( wxT(
"OrCAD" ) );
127 case SCH_EASYPC:
return wxString( wxT(
"Easy-PC" ) );
128 case SCH_TARGET3001:
return wxString( wxT(
"TARGET 3001!" ) );
130 default:
return wxString::Format(
_(
"Unknown SCH_FILE_T value: %d" ), aFileType );
141 if( aType == wxT(
"KiCad" ) )
143 else if( aType == wxT(
"Legacy" ) )
145 else if( aType == wxT(
"Altium" ) )
147 else if( aType == wxT(
"CADSTAR Schematic Archive" ) )
148 return SCH_CADSTAR_ARCHIVE;
149 else if( aType == wxT(
"Database" ) )
151 else if( aType == wxT(
"EAGLE" ) )
153 else if( aType == wxT(
"EasyEDA (JLCEDA) Std" ) )
155 else if( aType == wxT(
"EasyEDA (JLCEDA) Pro" ) )
156 return SCH_EASYEDAPRO;
157 else if( aType == wxT(
"EasyEDA (JLCEDA) Pro v3" ) )
158 return SCH_EASYEDAPRO_V3;
159 else if( aType == wxT(
"gEDA / Lepton EDA" ) )
161 else if( aType == wxT(
"LTspice" ) )
163 else if( aType == wxT(
"HTTP" ) )
165 else if( aType == wxT(
"PADS Logic" ) )
167 else if( aType == wxT(
"DipTrace" ) )
169 else if( aType == wxT(
"P-CAD" ) )
171 else if( aType == wxT(
"OrCAD" ) )
173 else if( aType == wxT(
"Easy-PC" ) )
175 else if( aType == wxT(
"TARGET 3001!" ) )
176 return SCH_TARGET3001;
178 return SCH_NESTED_TABLE;
180 return SCH_FILE_UNKNOWN;
188 if( parser.
Parse( aLibPath.ToStdString() ).has_value() )
189 return SCH_NESTED_TABLE;
191 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
193 bool isKiCad =
fileType == SCH_IO_MGR::SCH_KICAD ||
fileType == SCH_IO_MGR::SCH_LEGACY;
212 if( pi->SCH_IO::CanReadLibrary( aLibPath ) )
219 if( pi->CanReadLibrary( aLibPath ) )
224 return SCH_IO_MGR::SCH_FILE_UNKNOWN;
230 for(
const SCH_IO_MGR::SCH_FILE_T&
fileType : SCH_IO_MGR::SCH_FILE_T_vector )
232 bool isKiCad =
fileType == SCH_IO_MGR::SCH_KICAD ||
fileType == SCH_IO_MGR::SCH_LEGACY;
245 if( pi->CanReadSchematicFile( aSchematicPath ) )
249 return SCH_IO_MGR::SCH_FILE_UNKNOWN;
254 const wxString& aNewFilepath,
REPORTER* aReporter )
256 auto report = [&](
const wxString& aMessage,
SEVERITY aSeverity )
259 aReporter->
Report( aMessage, aSeverity );
264 if( oldFileType == SCH_IO_MGR::SCH_FILE_UNKNOWN )
272 if( oldFileType == SCH_IO_MGR::SCH_NESTED_TABLE )
278 if( oldFileType == SCH_IO_MGR::SCH_HTTP || oldFileType == SCH_IO_MGR::SCH_DATABASE )
284 if( !oldFilePI || !kicadPI )
288 oldFilePI->SetReporter( aReporter );
290 std::vector<LIB_SYMBOL*> symbols;
291 std::vector<std::unique_ptr<LIB_SYMBOL>> newSymbols;
292 std::map<LIB_SYMBOL*, LIB_SYMBOL*> symbolMap;
294 report( wxString::Format(
_(
"Loading symbol library '%s'" ), aOldFilePath ),
RPT_SEVERITY_ACTION );
298 oldFilePI->EnumerateSymbolLib( symbols, aOldFilePath, aOldFileProps );
303 if( symbol->IsDerived() )
308 newSymbols.push_back( std::make_unique<LIB_SYMBOL>( *symbol ) );
309 symbolMap[symbol] = newSymbols.back().get();
315 if( !symbol->IsDerived() )
320 newSymbols.push_back( std::make_unique<LIB_SYMBOL>( *symbol ) );
321 newSymbols.back()->SetParent( symbolMap[ symbol->GetParent().lock().get() ] );
325 kicadPI->SaveLibrary( aNewFilepath );
329 report( wxString::Format(
_(
"Library '%s' Convert err: \"%s\"" ), aOldFilePath, io_err.
What() ),
333 catch(
const std::exception& e )
335 report( wxString::Format(
_(
"Error loading library '%s': %s" ), aOldFilePath, e.what() ),
RPT_SEVERITY_ERROR );
340 report( wxString::Format(
_(
"Error loading library '%s': unknown error" ), aOldFilePath ),
347 for( std::unique_ptr<LIB_SYMBOL>& symbol : newSymbols )
349 const wxString symbolName = symbol->GetName();
353 kicadPI->SaveSymbol( aNewFilepath, std::move( symbol ) );
357 report( wxString::Format(
_(
"Error saving symbol '%s': %s" ), symbolName, io_err.
What() ),
361 catch(
const std::exception& e )
363 report( wxString::Format(
_(
"Error saving symbol '%s': %s" ), symbolName, e.what() ),
369 report( wxString::Format(
_(
"Error saving symbol '%s': unknown error" ), symbolName ),
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
tl::expected< LIBRARY_TABLE_IR, LIBRARY_PARSE_ERROR > Parse(const std::filesystem::path &aPath)
static const wxString TABLE_TYPE_NAME
Define a library symbol object.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
A SCH_IO derivation for loading DipTrace schematic files (.dch).
A SCH_IO derivation for loading Eagle schematic files.
Imports Number One Systems Easy-PC and RS DesignSpark PCB schematics (.sch), projects (....
A SCH_IO derivation for loading gEDA/gschem schematic files (.sch).
A KiCad HTTP library provides both symbol and footprint metadata, so there are "shim" plugins on both...
A SCH_IO derivation for loading schematic files created before the new s-expression file format.
A SCH_IO derivation for loading schematic files using the new s-expression file format.
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilepath, REPORTER *aReporter=nullptr)
Convert a schematic symbol library to the latest KiCad format.
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the file type from the corresponding plugin type name: "kicad", "legacy", etc.
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath, int aCtl=0)
Return a plugin type given a schematic using the file extension of aSchematicPath.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
A SCH_IO derivation for loading OrCAD Capture schematic designs (.dsn).
A SCH_IO derivation for loading PADS Logic schematic files.
A SCH_IO derivation for loading P-CAD 2006 ASCII schematic files (.SCH).
Imports the schematic part of a TARGET 3001!
Base class that schematic file and library loading and saving plugins should derive from.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
#define KICTL_CREATE
caller thinks requested project files may not exist.
#define KICTL_KICAD_ONLY
chosen file is from KiCad according to user
#define KICTL_NONKICAD_ONLY
chosen file is non-KiCad according to user
MODEL3D_FORMAT_TYPE fileType(const char *aFileName)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Definition of file extensions used in Kicad.