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_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 47 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_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 98 of file sch_io_mgr.cpp.

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

Referenced by 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 121 of file sch_io_mgr.cpp.

122 {
123  wxString ext = wxEmptyString;
124  SCH_PLUGIN* plugin = FindPlugin( aFileType );
125 
126  if( plugin != nullptr )
127  {
128  ext = plugin->GetFileExtension();
129  ReleasePlugin( plugin );
130  }
131 
132  return ext;
133 }
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:152
virtual const wxString GetFileExtension() const =0
Return the file extension for the SCH_PLUGIN.
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:69

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 136 of file sch_io_mgr.cpp.

137 {
138  wxString ext = wxEmptyString;
139  SCH_PLUGIN* plugin = FindPlugin( aFileType );
140 
141  if( plugin != nullptr )
142  {
143  ext = plugin->GetLibraryFileExtension();
144  ReleasePlugin( plugin );
145  }
146 
147  return ext;
148 }
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:152
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:69

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 151 of file sch_io_mgr.cpp.

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

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 169 of file sch_io_mgr.cpp.

170 {
171  SCH_FILE_T ret = SCH_KICAD; // default guess, unless detected otherwise.
172  wxFileName fn( aSchematicPath );
173 
174  if( fn.GetExt() == LegacySchematicFileExtension )
175  {
176  ret = SCH_LEGACY;
177  }
178  else if( fn.GetExt() == KiCadSchematicFileExtension )
179  {
180  ret = SCH_KICAD;
181  }
182 
183  return ret;
184 }
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 69 of file sch_io_mgr.cpp.

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

Referenced by BOOST_AUTO_TEST_CASE(), GetFileExtension(), GetLibraryFileExtension(), SCH_PLUGIN::SCH_PLUGIN_RELEASER::release(), and TEST_NETLISTS_FIXTURE::~TEST_NETLISTS_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 79 of file sch_io_mgr.cpp.

80 {
81  // keep this function in sync with EnumFromStr() relative to the
82  // text spellings. If you change the spellings, you will obsolete
83  // library tables, so don't do change, only additions are ok.
84 
85  switch( aType )
86  {
87  case SCH_LEGACY: return wxString( wxT( "Legacy" ) );
88  case SCH_KICAD: return wxString( wxT( "KiCad" ) );
89  case SCH_ALTIUM: return wxString( wxT( "Altium" ) );
90  case SCH_CADSTAR_ARCHIVE: return wxString( wxT( "CADSTAR Schematic Archive" ) );
91  case SCH_EAGLE: return wxString( wxT( "EAGLE" ) );
92  default: return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ),
93  aType );
94  }
95 }
#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: