KiCad PCB EDA Suite
SCH_IO_MGR Class Reference

Class 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_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 file extension for aFileType. More...
 
static SCH_FILE_T GuessPluginTypeFromLibPath (const wxString &aLibPath)
 Return a plugin type given a footprint library's libPath. 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

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

Definition at line 46 of file sch_io_mgr.h.

Member Function Documentation

SCH_IO_MGR::DEFINE_ENUM_VECTOR ( SCH_FILE_T  ,
{SCH_LEGACY, 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.
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 96 of file sch_io_mgr.cpp.

Referenced by SYMBOL_LIB_TABLE_ROW::SetType().

97 {
98  // keep this function in sync with ShowType() relative to the
99  // text spellings. If you change the spellings, you will obsolete
100  // library tables, so don't do change, only additions are ok.
101 
102  if( aType == wxT( "Legacy" ) )
103  return SCH_LEGACY;
104  else if( aType == wxT( "EAGLE" ) )
105  return SCH_EAGLE;
106 
107  // wxASSERT( blow up here )
108 
109  return SCH_FILE_T( -1 );
110 }
const wxString SCH_IO_MGR::GetFileExtension ( SCH_FILE_T  aFileType)
static

Return the 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 113 of file sch_io_mgr.cpp.

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

114 {
115  wxString ext = wxEmptyString;
116  SCH_PLUGIN* plugin = FindPlugin( aFileType );
117 
118  if( plugin != NULL )
119  {
120  ext = plugin->GetFileExtension();
121  ReleasePlugin( plugin );
122  }
123 
124  return ext;
125 }
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:188
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:66
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath ( const wxString &  aLibPath)
static

Return a plugin type given a footprint library's libPath.

Definition at line 128 of file sch_io_mgr.cpp.

References SchematicFileExtension.

129 {
130  SCH_FILE_T ret = SCH_LEGACY; // default guess, unless detected otherwise.
131  wxFileName fn( aLibPath );
132 
133  if( fn.GetExt() == SchematicFileExtension )
134  {
135  ret = SCH_LEGACY;
136  }
137 
138  return ret;
139 }
const wxString SchematicFileExtension
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 142 of file sch_io_mgr.cpp.

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

144 {
145  // release the SCH_PLUGIN even if an exception is thrown.
146  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
147 
148  if( (SCH_PLUGIN*) pi ) // test pi->plugin
149  {
150  return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual
151  }
152 
153  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
154 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:33
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:188
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:523
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 THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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 66 of file sch_io_mgr.cpp.

Referenced by GetFileExtension(), and SCH_PLUGIN::SCH_PLUGIN_RELEASER::release().

67 {
68  // This function is a place holder for a future point in time where
69  // the plugin is a DLL/DSO. It could do reference counting, and then
70  // unload the DLL/DSO when count goes to zero.
71 
72  delete aPlugin;
73 }
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 157 of file sch_io_mgr.cpp.

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

159 {
160  // release the SCH_PLUGIN even if an exception is thrown.
161  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
162 
163  if( (SCH_PLUGIN*) pi ) // test pi->plugin
164  {
165  pi->Save( aFileName, aSchematic, aKiway, aProperties ); // virtual
166  return;
167  }
168 
169  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
170 }
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:33
Base class that schematic file and library loading and saving plugins should derive from...
Definition: sch_io_mgr.h:188
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:523
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 THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
const wxString SCH_IO_MGR::ShowType ( SCH_FILE_T  aFileType)
static

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

Definition at line 76 of file sch_io_mgr.cpp.

References Format().

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

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

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