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_KICAD, SCH_EAGLE,})
 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 APIEXPORT SCH_PLUGINFindPlugin (SCH_FILE_T aFileType)
 Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents. More...
 
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_KICAD, SCH_EAGLE,}   
)

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

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.

Referenced by SYMBOL_LIB_TABLE_ROW::SetType().

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( "EAGLE" ) )
107  return SCH_EAGLE;
108 
109  // wxASSERT( blow up here )
110 
111  return SCH_FILE_T( -1 );
112 }
SCH_PLUGIN * SCH_IO_MGR::FindPlugin ( SCH_FILE_T  aFileType)
static

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.

Definition at line 49 of file sch_io_mgr.cpp.

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

50 {
51  // This implementation is subject to change, any magic is allowed here.
52  // The public SCH_IO_MGR API is the only pertinent public information.
53 
54  switch( aFileType )
55  {
56  case SCH_LEGACY:
57  return new SCH_LEGACY_PLUGIN();
58  case SCH_EAGLE:
59  return new SCH_EAGLE_PLUGIN();
60  case SCH_KICAD:
61  return NULL;
62  }
63 
64  return NULL;
65 }
Class SCH_EAGLE_PLUGIN is a SCH_PLUGIN derivation for loading 6.x+ Eagle schematic files...
Class SCH_LEGACY_PLUGIN.
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 115 of file sch_io_mgr.cpp.

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

116 {
117  wxString ext = wxEmptyString;
118  SCH_PLUGIN* plugin = FindPlugin( aFileType );
119 
120  if( plugin != NULL )
121  {
122  ext = plugin->GetFileExtension();
123  ReleasePlugin( plugin );
124  }
125 
126  return ext;
127 }
static APIEXPORT SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents...
Definition: sch_io_mgr.cpp:49
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:68
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 130 of file sch_io_mgr.cpp.

References SchematicFileWildcard.

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

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

146 {
147  // release the SCH_PLUGIN even if an exception is thrown.
148  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
149 
150  if( (SCH_PLUGIN*) pi ) // test pi->plugin
151  {
152  return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual
153  }
154 
155  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
156 }
static APIEXPORT SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents...
Definition: sch_io_mgr.cpp:49
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:78
#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:513
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 68 of file sch_io_mgr.cpp.

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

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

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

161 {
162  // release the SCH_PLUGIN even if an exception is thrown.
163  SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) );
164 
165  if( (SCH_PLUGIN*) pi ) // test pi->plugin
166  {
167  pi->Save( aFileName, aSchematic, aKiway, aProperties ); // virtual
168  return;
169  }
170 
171  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
172 }
static APIEXPORT SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents...
Definition: sch_io_mgr.cpp:49
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:78
#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:513
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 78 of file sch_io_mgr.cpp.

References Format().

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

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