KiCad PCB EDA Suite
SCH_IO_MGR Class Reference

A factory which returns an instance of a SCH_PLUGIN. More...

#include <sch_io_mgr.h>

Public Member Functions

 DEFINE_ENUM_VECTOR (SCH_FILE_T, { SCH_LEGACY, SCH_KICAD, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_EAGLE, SCH_DATABASE, SCH_FILE_UNKNOWN }) APIEXPORT static SCH_PLUGIN *FindPlugin(SCH_FILE_T aFileType)
 A set of file types that the SCH_IO_MGR knows about, and for which there has been a plugin written. More...
 

Static Public Member Functions

static void ReleasePlugin (SCH_PLUGIN *aPlugin)
 Release a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory. More...
 
static const wxString ShowType (SCH_FILE_T aFileType)
 Return a brief name for a plugin, given aFileType enum. More...
 
static SCH_FILE_T EnumFromStr (const wxString &aFileType)
 Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc. More...
 
static const wxString GetFileExtension (SCH_FILE_T aFileType)
 Return the schematic file extension for aFileType. More...
 
static const wxString GetLibraryFileExtension (SCH_FILE_T aFileType)
 Return the symbol library file extension (if any) for aFileType. More...
 
static SCH_FILE_T GuessPluginTypeFromLibPath (const wxString &aLibPath)
 Return a plugin type given a symbol library using the file extension of aLibPath. More...
 
static SCH_FILE_T GuessPluginTypeFromSchPath (const wxString &aSchematicPath)
 Return a plugin type given a schematic using the file extension of aSchematicPath. More...
 

Detailed Description

A factory which returns an instance of a SCH_PLUGIN.

Definition at line 48 of file sch_io_mgr.h.

Member Function Documentation

◆ DEFINE_ENUM_VECTOR()

SCH_IO_MGR::DEFINE_ENUM_VECTOR ( SCH_FILE_T  ,
{ SCH_LEGACY, SCH_KICAD, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_EAGLE, SCH_DATABASE, SCH_FILE_UNKNOWN }   
)

A set of file types that the SCH_IO_MGR knows about, and for which there has been a plugin written.

Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents.

The returned SCH_PLUGIN, may be reference counted, so please call PluginRelease() when you are done using the returned SCH_PLUGIN. It may or may not be code running from a DLL/DSO.

Parameters
aFileTypeis from #SCH_FILE_T and tells which plugin to find.
Returns
the plugin corresponding to aFileType or NULL if not found. Caller owns the returned object, and must call PluginRelease when done using it.

◆ EnumFromStr()

SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::EnumFromStr ( const wxString &  aFileType)
static

Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.

Definition at line 101 of file sch_io_mgr.cpp.

102{
103 // keep this function in sync with ShowType() relative to the
104 // text spellings. If you change the spellings, you will obsolete
105 // library tables, so don't do change, only additions are ok.
106
107 if( aType == wxT( "Legacy" ) )
108 return SCH_LEGACY;
109 else if( aType == wxT( "KiCad" ) )
110 return SCH_KICAD;
111 else if( aType == wxT( "Altium" ) )
112 return SCH_ALTIUM;
113 else if( aType == wxT( "CADSTAR Schematic Archive" ) )
114 return SCH_CADSTAR_ARCHIVE;
115 else if( aType == wxT( "EAGLE" ) )
116 return SCH_EAGLE;
117 else if( aType == wxT( "Database" ) )
118 return SCH_DATABASE;
119
120 // wxASSERT( blow up here )
121
122 return SCH_FILE_T( -1 );
123}

Referenced by SCH_EDITOR_CONTROL::ExportSymbolsToLibrary(), and SYMBOL_LIB_TABLE_ROW::SetType().

◆ GetFileExtension()

const wxString SCH_IO_MGR::GetFileExtension ( SCH_FILE_T  aFileType)
static

Return the schematic file extension for aFileType.

Parameters
aFileTypeis the #SCH_FILE_T type.
Returns
the file extension for aFileType or an empty string if aFileType is invalid.

Definition at line 126 of file sch_io_mgr.cpp.

127{
128 wxString ext = wxEmptyString;
129 SCH_PLUGIN* plugin = FindPlugin( aFileType );
130
131 if( plugin != nullptr )
132 {
133 ext = plugin->GetFileExtension();
134 ReleasePlugin( plugin );
135 }
136
137 return ext;
138}
static void ReleasePlugin(SCH_PLUGIN *aPlugin)
Release a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory.
Definition: sch_io_mgr.cpp:71
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:155
virtual const wxString GetFileExtension() const =0
Return the file extension for the SCH_PLUGIN.

References SCH_PLUGIN::GetFileExtension(), and ReleasePlugin().

Referenced by SCH_EDIT_FRAME::OnImportProject().

◆ GetLibraryFileExtension()

const wxString SCH_IO_MGR::GetLibraryFileExtension ( SCH_FILE_T  aFileType)
static

Return the symbol library file extension (if any) for aFileType.

Parameters
aFileTypeis the #SCH_FILE_T type.
Returns
the file extension for aFileType or an empty string if aFileType is invalid.

Definition at line 141 of file sch_io_mgr.cpp.

142{
143 wxString ext = wxEmptyString;
144 SCH_PLUGIN* plugin = FindPlugin( aFileType );
145
146 if( plugin != nullptr )
147 {
148 ext = plugin->GetLibraryFileExtension();
149 ReleasePlugin( plugin );
150 }
151
152 return ext;
153}
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.

References SCH_PLUGIN::GetLibraryFileExtension(), and ReleasePlugin().

Referenced by PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), and SYMBOL_LIB_TABLE_GRID::SetValue().

◆ GuessPluginTypeFromLibPath()

SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath ( const wxString &  aLibPath)
static

Return a plugin type given a symbol library using the file extension of aLibPath.

Definition at line 156 of file sch_io_mgr.cpp.

157{
158 SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
159 wxFileName fn( aLibPath );
160
161 if( fn.GetExt() == LegacySymbolLibFileExtension )
162 {
163 ret = SCH_LEGACY;
164 }
165 else if( fn.GetExt() == KiCadSymbolLibFileExtension )
166 {
167 ret = SCH_KICAD;
168 }
169
170 return ret;
171}
const std::string KiCadSymbolLibFileExtension
const std::string LegacySymbolLibFileExtension

References KiCadSymbolLibFileExtension, and LegacySymbolLibFileExtension.

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), SYMBOL_EDIT_FRAME::ExportSymbol(), SYMBOL_EDIT_FRAME::ImportSymbol(), and SYMBOL_EDIT_FRAME::saveLibrary().

◆ GuessPluginTypeFromSchPath()

SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath ( const wxString &  aSchematicPath)
static

Return a plugin type given a schematic using the file extension of aSchematicPath.

Definition at line 174 of file sch_io_mgr.cpp.

175{
176 SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
177 wxFileName fn( aSchematicPath );
178
179 if( fn.GetExt() == LegacySchematicFileExtension )
180 {
181 ret = SCH_LEGACY;
182 }
183 else if( fn.GetExt() == KiCadSchematicFileExtension )
184 {
185 ret = SCH_KICAD;
186 }
187
188 return ret;
189}
const std::string LegacySchematicFileExtension
const std::string KiCadSchematicFileExtension

References KiCadSchematicFileExtension, and LegacySchematicFileExtension.

Referenced by SCH_EDIT_FRAME::LoadSheetFromFile(), SCH_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::saveSchematicFile().

◆ ReleasePlugin()

void SCH_IO_MGR::ReleasePlugin ( SCH_PLUGIN aPlugin)
static

Release a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory.

Parameters
aPluginis the one to be released, and which is no longer usable after calling this.

Definition at line 71 of file sch_io_mgr.cpp.

72{
73 // This function is a place holder for a future point in time where
74 // the plugin is a DLL/DSO. It could do reference counting, and then
75 // unload the DLL/DSO when count goes to zero.
76
77 delete aPlugin;
78}

Referenced by BOOST_AUTO_TEST_CASE(), GetFileExtension(), GetLibraryFileExtension(), SCH_PLUGIN::SCH_PLUGIN_RELEASER::release(), and KI_TEST::SCHEMATIC_TEST_FIXTURE::~SCHEMATIC_TEST_FIXTURE().

◆ ShowType()

const wxString SCH_IO_MGR::ShowType ( SCH_FILE_T  aFileType)
static

Return a brief name for a plugin, given aFileType enum.

Definition at line 81 of file sch_io_mgr.cpp.

82{
83 // keep this function in sync with EnumFromStr() relative to the
84 // text spellings. If you change the spellings, you will obsolete
85 // library tables, so don't do change, only additions are ok.
86
87 switch( aType )
88 {
89 case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
90 case SCH_KICAD: return wxString( wxT( "KiCad" ) );
91 case SCH_ALTIUM: return wxString( wxT( "Altium" ) );
92 case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) );
93 case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
94 case SCH_DATABASE: return wxString( wxT( "Database" ) );
95 default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
96 aType );
97 }
98}
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, and Format().

Referenced by SYMBOL_LIBRARY_MANAGER::addLibrary(), PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), SYMBOL_LIB_TABLE_ROW::GetType(), SYMBOL_EDIT_FRAME::IsSymbolFromLegacyLibrary(), PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), and SYMBOL_LIB_TABLE_GRID::SetValue().


The documentation for this class was generated from the following files: