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 Types

enum  SCH_FILE_T { SCH_LEGACY, SCH_KICAD }
 Enum SCH_FILE_T is 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 SCH_PLUGINFindPlugin (SCH_FILE_T aFileType)
 Function FindPlugin returns a SCH_PLUGIN which the caller can use to import, export, save, or load design documents. More...
 
static void ReleasePlugin (SCH_PLUGIN *aPlugin)
 Function PluginRelease releases 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)
 Function ShowType returns a brief name for a plugin, given aFileType enum. More...
 
static SCH_FILE_T EnumFromStr (const wxString &aFileType)
 Function EnumFromStr returns the SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc. More...
 
static const wxString GetFileExtension (SCH_FILE_T aFileType)
 Function GetFileExtension returns the file extension for aFileType. More...
 
static SCH_FILE_T GuessPluginTypeFromLibPath (const wxString &aLibPath)
 Function GuessPluginTypeFromLibPath returns 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)
 Function Load finds 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)
 Function Save will 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 44 of file sch_io_mgr.h.

Member Enumeration Documentation

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

Enumerator
SCH_LEGACY 

Legacy Eeschema file formats prior to s-expression.

SCH_KICAD 

The s-expression version of the schematic file formats.

Definition at line 53 of file sch_io_mgr.h.

54  {
55  SCH_LEGACY,
56  SCH_KICAD,
57  // Add your schematic type here.
58 
59  // ALTIUM,
60  // etc.
61  };
Legacy Eeschema file formats prior to s-expression.
Definition: sch_io_mgr.h:55
The s-expression version of the schematic file formats.
Definition: sch_io_mgr.h:56

Member Function Documentation

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

Function EnumFromStr returns the SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.

Definition at line 92 of file sch_io_mgr.cpp.

References SCH_LEGACY.

Referenced by SYMBOL_LIB_TABLE_ROW::SetType().

93 {
94  // keep this function in sync with ShowType() relative to the
95  // text spellings. If you change the spellings, you will obsolete
96  // library tables, so don't do change, only additions are ok.
97 
98  if( aType == wxT( "Legacy" ) )
99  return SCH_LEGACY;
100 
101  // wxASSERT( blow up here )
102 
103  return SCH_FILE_T( -1 );
104 }
Legacy Eeschema file formats prior to s-expression.
Definition: sch_io_mgr.h:55
SCH_FILE_T
Enum SCH_FILE_T is a set of file types that the SCH_IO_MGR knows about, and for which there has been ...
Definition: sch_io_mgr.h:53
SCH_PLUGIN * SCH_IO_MGR::FindPlugin ( SCH_FILE_T  aFileType)
static

Function FindPlugin returns 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
SCH_PLUGIN* - the plugin corresponding to aFileType or NULL if not found. Caller owns the returned object, and must call PluginRelease when done using it.

Definition at line 48 of file sch_io_mgr.cpp.

References SCH_KICAD, and SCH_LEGACY.

Referenced by SYMBOL_LIB_TABLE::FindRow(), GetFileExtension(), Load(), SCH_EDIT_FRAME::OpenProjectFiles(), PART_LIB::PART_LIB(), Save(), SCH_EDIT_FRAME::SaveEEFile(), and PART_LIB::SetPluginType().

49 {
50  // This implementation is subject to change, any magic is allowed here.
51  // The public SCH_IO_MGR API is the only pertinent public information.
52 
53  switch( aFileType )
54  {
55  case SCH_LEGACY:
56  return new SCH_LEGACY_PLUGIN();
57  case SCH_KICAD:
58  return NULL;
59  }
60 
61  return NULL;
62 }
Legacy Eeschema file formats prior to s-expression.
Definition: sch_io_mgr.h:55
The s-expression version of the schematic file formats.
Definition: sch_io_mgr.h:56
Class SCH_LEGACY_PLUGIN.
const wxString SCH_IO_MGR::GetFileExtension ( SCH_FILE_T  aFileType)
static

Function GetFileExtension returns the file extension for aFileType.

Parameters
aFileTypeThe SCH_FILE_T type.
Returns
A wxString object containing the file extension for aFileType or an empty string if aFileType is invalid.

Definition at line 107 of file sch_io_mgr.cpp.

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

108 {
109  wxString ext = wxEmptyString;
110  SCH_PLUGIN* plugin = FindPlugin( aFileType );
111 
112  if( plugin != NULL )
113  {
114  ext = plugin->GetFileExtension();
115  ReleasePlugin( plugin );
116  }
117 
118  return ext;
119 }
static SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Function FindPlugin returns a SCH_PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: sch_io_mgr.cpp:48
Class SCH_PLUGIN is a base class that SCHEMATIC loading and saving plugins should derive from...
Definition: sch_io_mgr.h:187
virtual const wxString GetFileExtension() const =0
Function GetFileExtension returns the file extension for the SCH_PLUGIN.
static void ReleasePlugin(SCH_PLUGIN *aPlugin)
Function PluginRelease releases a SCH_PLUGIN back to the system, and may cause it to be unloaded from...
Definition: sch_io_mgr.cpp:65
SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromLibPath ( const wxString &  aLibPath)
static

Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath.

Definition at line 122 of file sch_io_mgr.cpp.

References SCH_LEGACY, and SchematicFileWildcard.

123 {
124  SCH_FILE_T ret = SCH_LEGACY; // default guess, unless detected otherwise.
125  wxFileName fn( aLibPath );
126 
127  if( fn.GetExt() == SchematicFileWildcard )
128  {
129  ret = SCH_LEGACY;
130  }
131 
132  return ret;
133 }
Legacy Eeschema file formats prior to s-expression.
Definition: sch_io_mgr.h:55
const wxString SchematicFileWildcard
SCH_FILE_T
Enum SCH_FILE_T is a set of file types that the SCH_IO_MGR knows about, and for which there has been ...
Definition: sch_io_mgr.h:53
SCH_SHEET * SCH_IO_MGR::Load ( SCH_FILE_T  aFileType,
const wxString &  aFileName,
KIWAY aKiway,
SCH_SHEET aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
static

Function Load finds 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 #SCHEMATIC to append to, use NULL if a new #SCHEMATIC load is wanted.
aPropertiesis an associative array that allows the caller to pass additional tuning parameters to the SCH_PLUGIN.
Returns
SCHEMATIC* - caller owns it, never NULL because exception thrown if error.
Exceptions
IO_ERRORif the SCH_PLUGIN cannot be found, file cannot be found, or file cannot be loaded.

Definition at line 136 of file sch_io_mgr.cpp.

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

138 {
139  // release the SCH_PLUGIN even if an exception is thrown.
140  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
141 
142  if( (SCH_PLUGIN*) pi ) // test pi->plugin
143  {
144  return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual
145  }
146 
147  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
148 }
static SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Function FindPlugin returns a SCH_PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: sch_io_mgr.cpp:48
static const wxString ShowType(SCH_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:75
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:32
Class SCH_PLUGIN is a base class that SCHEMATIC loading and saving plugins should derive from...
Definition: sch_io_mgr.h:187
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
Class SCH_PLUGIN_RELEASER.
Definition: sch_io_mgr.h:524
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
void SCH_IO_MGR::ReleasePlugin ( SCH_PLUGIN aPlugin)
static

Function PluginRelease releases 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 65 of file sch_io_mgr.cpp.

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

66 {
67  // This function is a place holder for a future point in time where
68  // the plugin is a DLL/DSO. It could do reference counting, and then
69  // unload the DLL/DSO when count goes to zero.
70 
71  delete aPlugin;
72 }
void SCH_IO_MGR::Save ( SCH_FILE_T  aFileType,
const wxString &  aFileName,
SCH_SCREEN aSchematic,
KIWAY aKiway,
const PROPERTIES aProperties = NULL 
)
static

Function Save will 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 SCHEMATIC document (data tree) to save or export to disk.
aSchematicis the in memory document tree from which to extract information when writing to aFileName. The caller continues to own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
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 151 of file sch_io_mgr.cpp.

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

153 {
154  // release the SCH_PLUGIN even if an exception is thrown.
155  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
156 
157  if( (SCH_PLUGIN*) pi ) // test pi->plugin
158  {
159  pi->Save( aFileName, aSchematic, aKiway, aProperties ); // virtual
160  return;
161  }
162 
163  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
164 }
static SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Function FindPlugin returns a SCH_PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: sch_io_mgr.cpp:48
static const wxString ShowType(SCH_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:75
#define FMT_NOTFOUND
Definition: sch_io_mgr.cpp:32
Class SCH_PLUGIN is a base class that SCHEMATIC loading and saving plugins should derive from...
Definition: sch_io_mgr.h:187
#define THROW_IO_ERROR(x)
Definition: utf8.cpp:60
Class SCH_PLUGIN_RELEASER.
Definition: sch_io_mgr.h:524
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
const wxString SCH_IO_MGR::ShowType ( SCH_FILE_T  aFileType)
static

Function ShowType returns a brief name for a plugin, given aFileType enum.

Definition at line 75 of file sch_io_mgr.cpp.

References Format(), and SCH_LEGACY.

Referenced by SYMBOL_LIB_TABLE_ROW::GetType(), Load(), and Save().

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