KiCad PCB EDA Suite
IO_MGR Class Reference

Class IO_MGR is a factory which returns an instance of a PLUGIN. More...

#include <io_mgr.h>

Classes

class  PLUGIN_REGISTRY
 Class PLUGIN_REGISTRY Holds a list of available plugins, created using a singleton REGISTER_PLUGIN object. More...
 
struct  REGISTER_PLUGIN
 Class REGISTER_PLUGIN Registers a plugin. More...
 

Public Types

enum  PCB_FILE_T {
  LEGACY, KICAD_SEXP, EAGLE, PCAD,
  GEDA_PCB, GITHUB, FILE_TYPE_NONE
}
 Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a plugin written. More...
 

Static Public Member Functions

static PLUGINPluginFind (PCB_FILE_T aFileType)
 Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents. More...
 
static void PluginRelease (PLUGIN *aPlugin)
 Function PluginRelease releases a PLUGIN back to the system, and may cause it to be unloaded from memory. More...
 
static const wxString ShowType (PCB_FILE_T aFileType)
 Function ShowType returns a brief name for a plugin, given aFileType enum. More...
 
static PCB_FILE_T EnumFromStr (const wxString &aFileType)
 Function EnumFromStr returns the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc. More...
 
static const wxString GetFileExtension (PCB_FILE_T aFileType)
 Function GetFileExtension returns the file extension for aFileType. More...
 
static PCB_FILE_T GuessPluginTypeFromLibPath (const wxString &aLibPath)
 Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath. More...
 
static BOARDLoad (PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
 Function Load finds the requested PLUGIN and if found, calls the PLUGIN->Load(..) funtion on it using the arguments passed to this function. More...
 
static void Save (PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
 Function Save will write either a full aBoard to a storage file in a format that this implementation knows about, or it can be used to write a portion of aBoard to a special kind of export file. More...
 

Detailed Description

Class IO_MGR is a factory which returns an instance of a PLUGIN.

Definition at line 43 of file io_mgr.h.

Member Enumeration Documentation

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

Enumerator
LEGACY 

Legacy Pcbnew file formats prior to s-expression.

KICAD_SEXP 

S-expression Pcbnew file format.

EAGLE 
PCAD 
GEDA_PCB 

Geda PCB file formats.

GITHUB 

Read only http://github.com repo holding pretty footprints.

FILE_TYPE_NONE 

Definition at line 52 of file io_mgr.h.

53  {
54  LEGACY,
55  KICAD_SEXP,
56  EAGLE,
57  PCAD,
58  GEDA_PCB,
59  GITHUB,
60 
61  // add your type here.
62 
63  // ALTIUM,
64  // etc.
65 
67  };
Geda PCB file formats.
Definition: io_mgr.h:58
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:59
S-expression Pcbnew file format.
Definition: io_mgr.h:55

Member Function Documentation

IO_MGR::PCB_FILE_T IO_MGR::EnumFromStr ( const wxString &  aFileType)
static

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

Definition at line 93 of file io_mgr.cpp.

References IO_MGR::PLUGIN_REGISTRY::AllPlugins(), and IO_MGR::PLUGIN_REGISTRY::Instance().

Referenced by DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), and FP_LIB_TABLE_ROW::SetType().

94 {
95  const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
96 
97  for( const auto& plugin : plugins )
98  {
99  if ( plugin.m_name == aType )
100  {
101  return plugin.m_type;
102  }
103  }
104 
105  return PCB_FILE_T( -1 );
106 }
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:116
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:84
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:52
const wxString IO_MGR::GetFileExtension ( PCB_FILE_T  aFileType)
static

Function GetFileExtension returns the file extension for aFileType.

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

Definition at line 109 of file io_mgr.cpp.

References PLUGIN::GetFileExtension(), PluginFind(), and PluginRelease().

Referenced by plugin_type().

110 {
111  wxString ext = wxEmptyString;
112  PLUGIN* plugin = PluginFind( aFileType );
113 
114  if( plugin != NULL )
115  {
116  ext = plugin->GetFileExtension();
117  PluginRelease( plugin );
118  }
119 
120  return ext;
121 }
virtual const wxString GetFileExtension() const =0
Function GetFileExtension returns the file extension for the PLUGIN.
static void PluginRelease(PLUGIN *aPlugin)
Function PluginRelease releases a PLUGIN back to the system, and may cause it to be unloaded from mem...
Definition: io_mgr.cpp:67
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath ( const wxString &  aLibPath)
static

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

Definition at line 124 of file io_mgr.cpp.

References EAGLE, EagleFootprintLibPathExtension, GEDA_PCB, GedaPcbFootprintLibFileExtension, GITHUB, KICAD_SEXP, KiCadFootprintLibPathExtension, LEGACY, and LegacyFootprintLibPathExtension.

Referenced by DIALOG_FP_LIB_TABLE::browseLibrariesHandler(), FOOTPRINT_EDIT_FRAME::DeleteModuleFromCurrentLibrary(), FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs(), FOOTPRINT_EDIT_FRAME::SaveCurrentModule(), and FOOTPRINT_EDIT_FRAME::SaveFootprintInLibrary().

125 {
126  PCB_FILE_T ret = KICAD_SEXP; // default guess, unless detected otherwise.
127  wxFileName fn( aLibPath );
128 
129  if( fn.GetExt() == LegacyFootprintLibPathExtension )
130  {
131  ret = LEGACY;
132  }
133  else if( fn.GetExt() == GedaPcbFootprintLibFileExtension )
134  {
135  ret = GEDA_PCB;
136  }
137  else if( fn.GetExt() == EagleFootprintLibPathExtension )
138  {
139  ret = EAGLE;
140  }
141 
142  // Test this one anyways, even though it's the default guess, to avoid
143  // the wxURI instantiation below.
144  // We default ret to KICAD above, because somebody might have
145  // mistakenly put a pretty library into a directory other than
146  // *.pretty/ with *.kicad_mod in there., and I don't want to return -1,
147  // since we only claimed to be guessing.
148  //
149  // However libraries on GitHub have names ending by .pretty
150  // so test also this is not a name starting by http (including https).
151  else if( fn.GetExt() == KiCadFootprintLibPathExtension &&
152  !aLibPath.StartsWith( wxT( "http" ) ) )
153  {
154  ret = KICAD_SEXP;
155  }
156  else
157  {
158  // There is no extension for a remote repo, so test the server name.
159  wxURI uri( aLibPath );
160 
161  if( uri.HasServer() && uri.GetServer() == wxT( "github.com" ) )
162  {
163  ret = GITHUB;
164  }
165  }
166 
167  return ret;
168 }
Geda PCB file formats.
Definition: io_mgr.h:58
const wxString LegacyFootprintLibPathExtension
const wxString KiCadFootprintLibPathExtension
const wxString GedaPcbFootprintLibFileExtension
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
const wxString EagleFootprintLibPathExtension
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:52
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:59
S-expression Pcbnew file format.
Definition: io_mgr.h:55
BOARD * IO_MGR::Load ( PCB_FILE_T  aFileType,
const wxString &  aFileName,
BOARD aAppendToMe = NULL,
const PROPERTIES aProperties = NULL 
)
static

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

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

Parameters
aFileTypeis the PCB_FILE_T of file to load.
aFileNameis the name of the file to load.
aAppendToMeis an existing BOARD to append to, use NULL if fresh board load is wanted.
aPropertiesis an associative array that allows the caller to pass additional tuning parameters to the PLUGIN.
Returns
BOARD* - caller owns it, never NULL because exception thrown if error.
Exceptions
IO_ERRORif the PLUGIN cannot be found, file cannot be found, or file cannot be loaded.

Definition at line 171 of file io_mgr.cpp.

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

Referenced by LoadBoard().

173 {
174  // release the PLUGIN even if an exception is thrown.
175  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
176 
177  if( (PLUGIN*) pi ) // test pi->plugin
178  {
179  return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
180  }
181 
182  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
183 }
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:563
#define FMT_NOTFOUND
Definition: io_mgr.cpp:43
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
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
PLUGIN * IO_MGR::PluginFind ( PCB_FILE_T  aFileType)
static

Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.

The returned PLUGIN, may be reference counted, so please call PluginRelease() when you are done using the returned PLUGIN. It may or may not be code running from a DLL/DSO.

Parameters
aFileTypeis from PCB_FILE_T and tells which plugin to find.
Returns
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 58 of file io_mgr.cpp.

References IO_MGR::PLUGIN_REGISTRY::Create(), and IO_MGR::PLUGIN_REGISTRY::Instance().

Referenced by PCB_EDIT_FRAME::AppendBoardFile(), PCBNEW_CONTROL::AppendBoardFromFile(), PCB_EDIT_FRAME::ArchiveModulesOnBoard(), PCB_BASE_EDIT_FRAME::CreateNewLibrary(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), FP_LIB_TABLE::FindRow(), GetFileExtension(), Load(), FOOTPRINT_EDIT_FRAME::OnSaveLibraryAs(), PCB_EDIT_FRAME::OpenProjectFiles(), parse_module_with_plugin(), Save(), FOOTPRINT_EDIT_FRAME::SaveCurrentModule(), PCB_EDIT_FRAME::SavePcbCopy(), and PCB_EDIT_FRAME::SavePcbFile().

59 {
60  // This implementation is subject to change, any magic is allowed here.
61  // The public IO_MGR API is the only pertinent public information.
62 
63  return PLUGIN_REGISTRY::Instance()->Create( aFileType );
64 }
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:84
PLUGIN * Create(PCB_FILE_T aFileType) const
Definition: io_mgr.h:104
void IO_MGR::PluginRelease ( PLUGIN aPlugin)
static

Function PluginRelease releases a 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 67 of file io_mgr.cpp.

Referenced by GetFileExtension(), and PLUGIN::RELEASER::release().

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

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

Parameters
aFileTypeis the PCB_FILE_T of file to save.
aFileNameis the name of a file to save to on disk.
aBoardis the BOARD document (data tree) to save or export to disk.
aBoardis the in memory document tree from which to extract information when writing to aFileName. The caller continues to own the BOARD, and the plugin should refrain from modifying the BOARD 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 186 of file io_mgr.cpp.

References EAGLE, FMT_NOTFOUND, Format(), GEDA_PCB, GITHUB, KICAD_SEXP, LEGACY, PCAD, PluginFind(), registerEaglePlugin, registerGPCBPlugin, registerKicadPlugin, registerLegacyPlugin, registerPcadPlugin, PLUGIN::Save(), ShowType(), and THROW_IO_ERROR.

Referenced by SaveBoard().

187 {
188  // release the PLUGIN even if an exception is thrown.
189  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
190 
191  if( (PLUGIN*) pi ) // test pi->plugin
192  {
193  pi->Save( aFileName, aBoard, aProperties ); // virtual
194  return;
195  }
196 
197  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
198 }
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:77
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:563
#define FMT_NOTFOUND
Definition: io_mgr.cpp:43
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
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Function PluginFind returns a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
const wxString IO_MGR::ShowType ( PCB_FILE_T  aFileType)
static

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

Definition at line 77 of file io_mgr.cpp.

References IO_MGR::PLUGIN_REGISTRY::AllPlugins(), Format(), and IO_MGR::PLUGIN_REGISTRY::Instance().

Referenced by DIALOG_FP_LIB_TABLE::browseLibrariesHandler(), DIALOG_FP_LIB_TABLE::DIALOG_FP_LIB_TABLE(), FP_LIB_TABLE_ROW::GetType(), Load(), and Save().

78 {
79  const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
80 
81  for( const auto& plugin : plugins )
82  {
83  if ( plugin.m_type == aType )
84  {
85  return plugin.m_name;
86  }
87  }
88 
89  return wxString::Format( _( "UNKNOWN (%d)" ), aType );
90 }
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:116
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:84
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: