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>

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 137 of file io_mgr.cpp.

References EAGLE, GEDA_PCB, GITHUB, KICAD_SEXP, LEGACY, and PCAD.

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

138 {
139  // keep this function in sync with ShowType() relative to the
140  // text spellings. If you change the spellings, you will obsolete
141  // library tables, so don't do change, only additions are ok.
142 
143  if( aType == wxT( "KiCad" ) )
144  return KICAD_SEXP;
145 
146  if( aType == wxT( "Legacy" ) )
147  return LEGACY;
148 
149  if( aType == wxT( "Eagle" ) )
150  return EAGLE;
151 
152  if( aType == wxT( "P-Cad" ) )
153  return PCAD;
154 
155  if( aType == wxT( "Geda-PCB" ) )
156  return GEDA_PCB;
157 
158  if( aType == wxT( "Github" ) )
159  return GITHUB;
160 
161  // wxASSERT( blow up here )
162 
163  return PCB_FILE_T( -1 );
164 }
Geda PCB file formats.
Definition: io_mgr.h:57
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
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
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 167 of file io_mgr.cpp.

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

Referenced by plugin_type().

168 {
169  wxString ext = wxEmptyString;
170  PLUGIN* plugin = PluginFind( aFileType );
171 
172  if( plugin != NULL )
173  {
174  ext = plugin->GetFileExtension();
175  PluginRelease( plugin );
176  }
177 
178  return ext;
179 }
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:95
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:193
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 182 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().

183 {
184  PCB_FILE_T ret = KICAD_SEXP; // default guess, unless detected otherwise.
185  wxFileName fn( aLibPath );
186 
187  if( fn.GetExt() == LegacyFootprintLibPathExtension )
188  {
189  ret = LEGACY;
190  }
191  else if( fn.GetExt() == GedaPcbFootprintLibFileExtension )
192  {
193  ret = GEDA_PCB;
194  }
195  else if( fn.GetExt() == EagleFootprintLibPathExtension )
196  {
197  ret = EAGLE;
198  }
199 
200  // Test this one anyways, even though it's the default guess, to avoid
201  // the wxURI instantiation below.
202  // We default ret to KICAD above, because somebody might have
203  // mistakenly put a pretty library into a directory other than
204  // *.pretty/ with *.kicad_mod in there., and I don't want to return -1,
205  // since we only claimed to be guessing.
206  //
207  // However libraries on GitHub have names ending by .pretty
208  // so test also this is not a name starting by http (including https).
209  else if( fn.GetExt() == KiCadFootprintLibPathExtension &&
210  !aLibPath.StartsWith( wxT( "http" ) ) )
211  {
212  ret = KICAD_SEXP;
213  }
214  else
215  {
216  // There is no extension for a remote repo, so test the server name.
217  wxURI uri( aLibPath );
218 
219  if( uri.HasServer() && uri.GetServer() == wxT( "github.com" ) )
220  {
221  ret = GITHUB;
222  }
223  }
224 
225  return ret;
226 }
const wxString KiCadFootprintLibPathExtension
Geda PCB file formats.
Definition: io_mgr.h:57
const wxString GedaPcbFootprintLibFileExtension
const wxString EagleFootprintLibPathExtension
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
const wxString LegacyFootprintLibPathExtension
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 229 of file io_mgr.cpp.

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

Referenced by LoadBoard().

231 {
232  // release the PLUGIN even if an exception is thrown.
233  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
234 
235  if( (PLUGIN*) pi ) // test pi->plugin
236  {
237  return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
238  }
239 
240  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
241 }
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:105
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:474
#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:193
#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 EAGLE, FILE_TYPE_NONE, GEDA_PCB, GITHUB, KICAD_SEXP, LEGACY, PCAD, and THROW_IO_ERROR.

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  switch( aFileType )
64  {
65  case LEGACY:
66  return new LEGACY_PLUGIN();
67 
68  case KICAD_SEXP:
69  return new PCB_IO();
70 
71  case EAGLE:
72  return new EAGLE_PLUGIN();
73 
74  case PCAD:
75  return new PCAD_PLUGIN();
76 
77  case GEDA_PCB:
78  return new GPCB_PLUGIN();
79 
80  case GITHUB:
81 #if defined(BUILD_GITHUB_PLUGIN)
82  return new GITHUB_PLUGIN();
83 #else
84  THROW_IO_ERROR( "BUILD_GITHUB_PLUGIN not enabled in cmake build environment" );
85 #endif
86 
87  case FILE_TYPE_NONE:
88  return NULL;
89  }
90 
91  return NULL;
92 }
Class PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files...
Class GPCB_PLUGIN is a PLUGIN derivation for saving and loading Geda PCB files.
Definition: gpcb_plugin.h:47
Geda PCB file formats.
Definition: io_mgr.h:57
Class EAGLE_PLUGIN works with Eagle 6.x XML board files and footprints to implement the Pcbnew PLUGIN...
Definition: eagle_plugin.h:83
Class LEGACY_PLUGIN is a PLUGIN derivation which could possibly be put into a DLL/DSO.
Definition: legacy_plugin.h:66
Class GITHUB_PLUGIN implements a portion of pcbnew's PLUGIN interface to provide read only access to ...
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
S-expression Pcbnew file format.
Definition: io_mgr.h:54
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 95 of file io_mgr.cpp.

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

96 {
97  // This function is a place holder for a future point in time where
98  // the plugin is a DLL/DSO. It could do reference counting, and then
99  // unload the DLL/DSO when count goes to zero.
100 
101  delete aPlugin;
102 }
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 244 of file io_mgr.cpp.

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

Referenced by SaveBoard().

245 {
246  // release the PLUGIN even if an exception is thrown.
247  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
248 
249  if( (PLUGIN*) pi ) // test pi->plugin
250  {
251  pi->Save( aFileName, aBoard, aProperties ); // virtual
252  return;
253  }
254 
255  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
256 }
static const wxString ShowType(PCB_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: io_mgr.cpp:105
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:474
#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:193
#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 105 of file io_mgr.cpp.

References EAGLE, Format(), GEDA_PCB, GITHUB, KICAD_SEXP, LEGACY, and PCAD.

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

106 {
107  // keep this function in sync with EnumFromStr() relative to the
108  // text spellings. If you change the spellings, you will obsolete
109  // library tables, so don't do change, only additions are ok.
110 
111  switch( aType )
112  {
113  default:
114  return wxString::Format( _( "Unknown PCB_FILE_T value: %d" ), aType );
115 
116  case LEGACY:
117  return wxString( wxT( "Legacy" ) );
118 
119  case KICAD_SEXP:
120  return wxString( wxT( "KiCad" ) );
121 
122  case EAGLE:
123  return wxString( wxT( "Eagle" ) );
124 
125  case PCAD:
126  return wxString( wxT( "P-Cad" ) );
127 
128  case GEDA_PCB:
129  return wxString( wxT( "Geda-PCB" ) );
130 
131  case GITHUB:
132  return wxString( wxT( "Github" ) );
133  }
134 }
Geda PCB file formats.
Definition: io_mgr.h:57
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
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
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
S-expression Pcbnew file format.
Definition: io_mgr.h:54

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