KiCad PCB EDA Suite
SCH_IO_MGR Class Reference

SCH_IO_MGR is 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_EAGLE, }) 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...
 
static SCH_SHEETLoad (SCH_FILE_T aFileType, const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
 Load the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function on it using the arguments passed to this function. More...
 
static void Save (SCH_FILE_T aFileType, const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
 Write either a full aSchematic to a storage file in a format that this implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file. More...
 

Detailed Description

SCH_IO_MGR is a factory which returns an instance of a SCH_PLUGIN.

Definition at line 45 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_EAGLE, }   
)

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

103 {
104  // keep this function in sync with ShowType() relative to the
105  // text spellings. If you change the spellings, you will obsolete
106  // library tables, so don't do change, only additions are ok.
107 
108  if( aType == wxT( "Legacy" ) )
109  return SCH_LEGACY;
110  else if( aType == wxT( "KiCad" ) )
111  return SCH_KICAD;
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 != NULL )
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:201
#define NULL
virtual const wxString GetFileExtension() const =0
Returns 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(), NULL, and ReleasePlugin().

◆ 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 != NULL )
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:201
#define NULL
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(), NULL, and ReleasePlugin().

Referenced by PANEL_SYM_LIB_TABLE::browseLibrariesHandler().

◆ 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_LEGACY; // default guess, unless detected otherwise.
154  wxFileName fn( aLibPath );
155 
156  if( fn.GetExt() == SchematicLibraryFileExtension )
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 SchematicLibraryFileExtension
const std::string KiCadSymbolLibFileExtension

References KiCadSymbolLibFileExtension, and SchematicLibraryFileExtension.

◆ 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_LEGACY; // 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::SaveEEFile().

◆ Load()

SCH_SHEET * SCH_IO_MGR::Load ( SCH_FILE_T  aFileType,
const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
static

Load the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function on it using the arguments passed to this function.

After the SCH_PLUGIN->Load() function returns, the SCH_PLUGIN is Released() as part of this call.

Parameters
aFileTypeis the #SCH_FILE_T of file to load.
aFileNameis the name of the file to load.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aAppendToMeis an existing SCH_SHEET to append to, use NULL if a new SCH_SHEET load is wanted.
aPropertiesis an associative array that allows the caller to pass additional tuning parameters to the SCH_PLUGIN.
Returns
the loaded schematic which the caller owns. This is never NULL because exception thrown if an error occurs.
Exceptions
IO_ERRORif the SCH_PLUGIN cannot be found, file cannot be found or file cannot be loaded.

Definition at line 187 of file sch_io_mgr.cpp.

189 {
190  // release the SCH_PLUGIN even if an exception is thrown.
191  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
192 
193  if( (SCH_PLUGIN*) pi ) // test pi->plugin
194  {
195  return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual
196  }
197 
198  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
199 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:79
virtual SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:50
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:34
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:201
#define THROW_IO_ERROR(msg)
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:516
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References FMT_NOTFOUND, Format(), SCH_PLUGIN::Load(), ShowType(), and THROW_IO_ERROR.

◆ 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 GetFileExtension(), GetLibraryFileExtension(), and SCH_PLUGIN::SCH_PLUGIN_RELEASER::release().

◆ Save()

void SCH_IO_MGR::Save ( SCH_FILE_T  aFileType,
const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
static

Write either a full aSchematic to a storage file in a format that this implementation knows about, or it can be used to write a portion of aSchematic to a special kind of export file.

Parameters
aFileTypeis the #SCH_FILE_T of file to save.
aFileNameis the name of a file to save to on disk.
aSchematicis the SCH_SCREEN document (data tree) to save or export to disk.
aKiwayis the KIWAY object used to access the component libraries loaded by the project.
aPropertiesis an associative array that can be used to tell the saver how to save the file, because it can take any number of additional named tuning arguments that the plugin is known to support. The caller continues to own this object (plugin may not delete it), and plugins should expect it to be optionally NULL.
Exceptions
IO_ERRORif there is a problem saving or exporting.

Definition at line 202 of file sch_io_mgr.cpp.

204 {
205  // release the SCH_PLUGIN even if an exception is thrown.
206  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
207 
208  if( (SCH_PLUGIN*) pi ) // test pi->plugin
209  {
210  pi->Save( aFileName, aSchematic, aKiway, aProperties ); // virtual
211  return;
212  }
213 
214  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
215 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:79
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:34
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:201
#define THROW_IO_ERROR(msg)
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:516
virtual void Save(const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:58
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205

References FMT_NOTFOUND, Format(), SCH_PLUGIN::Save(), ShowType(), and THROW_IO_ERROR.

◆ 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  default:
88  return wxString::Format( _( "Unknown SCH_FILE_T value: %d" ), aType );
89 
90  case SCH_LEGACY:
91  return wxString( wxT( "Legacy" ) );
92 
93  case SCH_KICAD:
94  return wxString( wxT( "KiCad" ) );
95 
96  case SCH_EAGLE:
97  return wxString( wxT( "EAGLE" ) );
98  }
99 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33

References _, and Format().

Referenced by LIB_MANAGER::addLibrary(), PANEL_SYM_LIB_TABLE::browseLibrariesHandler(), DIALOG_SYMBOL_REMAP::createProjectSymbolLibTable(), SYMBOL_LIB_TABLE_ROW::GetType(), Load(), PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE(), and Save().


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