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 42 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 51 of file io_mgr.h.

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

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 97 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().

98 {
99  // keep this function in sync with ShowType() relative to the
100  // text spellings. If you change the spellings, you will obsolete
101  // library tables, so don't do change, only additions are ok.
102 
103  const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
104 
105  for( const auto& plugin : plugins )
106  {
107  if ( plugin.m_name == aType )
108  {
109  return plugin.m_type;
110  }
111  }
112 
113  return PCB_FILE_T( -1 );
114 }
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:115
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:83
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:51
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 117 of file io_mgr.cpp.

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

Referenced by plugin_type().

118 {
119  wxString ext = wxEmptyString;
120  PLUGIN* plugin = PluginFind( aFileType );
121 
122  if( plugin != NULL )
123  {
124  ext = plugin->GetFileExtension();
125  PluginRelease( plugin );
126  }
127 
128  return ext;
129 }
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:265
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 132 of file io_mgr.cpp.

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

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

133 {
134  PCB_FILE_T ret = KICAD_SEXP; // default guess, unless detected otherwise.
135  wxFileName fn( aLibPath );
136 
137  if( fn.GetExt() == LegacyFootprintLibPathExtension )
138  {
139  ret = LEGACY;
140  }
141  else if( fn.GetExt() == GedaPcbFootprintLibFileExtension )
142  {
143  ret = GEDA_PCB;
144  }
145  else if( fn.GetExt() == EagleFootprintLibPathExtension )
146  {
147  ret = EAGLE;
148  }
149 
150  // Test this one anyways, even though it's the default guess, to avoid
151  // the wxURI instantiation below.
152  // We default ret to KICAD above, because somebody might have
153  // mistakenly put a pretty library into a directory other than
154  // *.pretty/ with *.kicad_mod in there., and I don't want to return -1,
155  // since we only claimed to be guessing.
156  //
157  // However libraries on GitHub have names ending by .pretty
158  // so test also this is not a name starting by http (including https).
159  else if( fn.GetExt() == KiCadFootprintLibPathExtension &&
160  !aLibPath.StartsWith( wxT( "http" ) ) )
161  {
162  ret = KICAD_SEXP;
163  }
164  else
165  {
166  // There is no extension for a remote repo, so test the server name.
167  wxURI uri( aLibPath );
168 
169  if( uri.HasServer() && uri.GetServer() == wxT( "github.com" ) )
170  {
171  ret = GITHUB;
172  }
173  }
174 
175  return ret;
176 }
Geda PCB file formats.
Definition: io_mgr.h:57
const wxString LegacyFootprintLibPathExtension
const wxString KiCadFootprintLibPathExtension
const wxString GedaPcbFootprintLibFileExtension
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
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:51
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
S-expression Pcbnew file format.
Definition: io_mgr.h:54
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 179 of file io_mgr.cpp.

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

Referenced by LoadBoard().

181 {
182  // release the PLUGIN even if an exception is thrown.
183  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
184 
185  if( (PLUGIN*) pi ) // test pi->plugin
186  {
187  return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
188  }
189 
190  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
191 }
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:546
#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:265
#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(), PCB_EDIT_FRAME::SavePcbFile(), and WIZARD_FPLIB_TABLE::LIBRARY::Test().

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:83
PLUGIN * Create(PCB_FILE_T aFileType) const
Definition: io_mgr.h:103
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 194 of file io_mgr.cpp.

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

Referenced by SaveBoard().

195 {
196  // release the PLUGIN even if an exception is thrown.
197  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
198 
199  if( (PLUGIN*) pi ) // test pi->plugin
200  {
201  pi->Save( aFileName, aBoard, aProperties ); // virtual
202  return;
203  }
204 
205  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
206 }
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:546
#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:265
#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::DIALOG_FP_LIB_TABLE(), FP_LIB_TABLE_ROW::GetType(), Load(), and Save().

78 {
79  // keep this function in sync with EnumFromStr() relative to the
80  // text spellings. If you change the spellings, you will obsolete
81  // library tables, so don't do change, only additions are ok.
82 
83  const auto& plugins = PLUGIN_REGISTRY::Instance()->AllPlugins();
84 
85  for( const auto& plugin : plugins )
86  {
87  if ( plugin.m_type == aType )
88  {
89  return plugin.m_name;
90  }
91  }
92 
93  return wxString::Format( _( "Unknown PCB_FILE_T value: %d" ), aType );
94 }
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:115
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:83
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: