KiCad PCB EDA Suite
IO_MGR Class Reference

A factory which returns an instance of a PLUGIN. More...

#include <io_mgr.h>

Classes

class  PLUGIN_REGISTRY
 Hold a list of available plugins, created using a singleton REGISTER_PLUGIN object. More...
 
struct  REGISTER_PLUGIN
 Register a plugin. More...
 

Public Types

enum  PCB_FILE_T {
  LEGACY, KICAD_SEXP, EAGLE, PCAD,
  FABMASTER, ALTIUM_DESIGNER, ALTIUM_CIRCUIT_STUDIO, ALTIUM_CIRCUIT_MAKER,
  CADSTAR_PCB_ARCHIVE, GEDA_PCB, FILE_TYPE_NONE
}
 The 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)
 Return a PLUGIN which the caller can use to import, export, save, or load design documents. More...
 
static void PluginRelease (PLUGIN *aPlugin)
 Release a PLUGIN back to the system and may cause it to be unloaded from memory. More...
 
static const wxString ShowType (PCB_FILE_T aFileType)
 Return a brief name for a plugin given aFileType enum. More...
 
static PCB_FILE_T EnumFromStr (const wxString &aFileType)
 Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc. More...
 
static const wxString GetFileExtension (PCB_FILE_T aFileType)
 Return the file extension for aFileType. More...
 
static PCB_FILE_T GuessPluginTypeFromLibPath (const wxString &aLibPath)
 Return a plugin type given a footprint library's libPath. More...
 
static BOARDLoad (PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
 Find the requested PLUGIN and if found, calls the PLUGIN::Load() function 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=nullptr)
 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 ofaBoard to a special kind of export file. More...
 

Detailed Description

A factory which returns an instance of a PLUGIN.

Definition at line 45 of file io_mgr.h.

Member Enumeration Documentation

◆ PCB_FILE_T

The 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 
FABMASTER 
ALTIUM_DESIGNER 
ALTIUM_CIRCUIT_STUDIO 
ALTIUM_CIRCUIT_MAKER 
CADSTAR_PCB_ARCHIVE 
GEDA_PCB 

Geda PCB file formats.

FILE_TYPE_NONE 

Definition at line 53 of file io_mgr.h.

54  {
55  LEGACY,
56  KICAD_SEXP,
57  EAGLE,
58  PCAD,
59  FABMASTER,
64  GEDA_PCB,
65  // add your type here.
66 
67  // etc.
68 
70  };
Geda PCB file formats.
Definition: io_mgr.h:64
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
S-expression Pcbnew file format.
Definition: io_mgr.h:56

Member Function Documentation

◆ EnumFromStr()

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

Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.

Definition at line 93 of file io_mgr.cpp.

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 }
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:86
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:120
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:53

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

◆ GetFileExtension()

const wxString IO_MGR::GetFileExtension ( PCB_FILE_T  aFileType)
static

Return the file extension for aFileType.

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

Definition at line 109 of file io_mgr.cpp.

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

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

Referenced by plugin_type().

◆ GuessPluginTypeFromLibPath()

IO_MGR::PCB_FILE_T IO_MGR::GuessPluginTypeFromLibPath ( const wxString &  aLibPath)
static

Return a plugin type given a footprint library's libPath.

Definition at line 124 of file io_mgr.cpp.

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  else if( fn.GetExt() == KiCadFootprintLibPathExtension )
150  {
151  ret = KICAD_SEXP;
152  }
153 
154  return ret;
155 }
const std::string LegacyFootprintLibPathExtension
const std::string EagleFootprintLibPathExtension
Geda PCB file formats.
Definition: io_mgr.h:64
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
const std::string GedaPcbFootprintLibFileExtension
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:53
const std::string KiCadFootprintLibPathExtension
S-expression Pcbnew file format.
Definition: io_mgr.h:56

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

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintAs(), and FOOTPRINT_EDIT_FRAME::SaveLibraryAs().

◆ Load()

BOARD * IO_MGR::Load ( PCB_FILE_T  aFileType,
const wxString &  aFileName,
BOARD aAppendToMe = nullptr,
const PROPERTIES aProperties = nullptr,
PROJECT aProject = nullptr,
PROGRESS_REPORTER aProgressReporter = nullptr 
)
static

Find the requested PLUGIN and if found, calls the PLUGIN::Load() function 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.
aProjectis the optional PROJECT object primarily used by third party importers.
Returns
the loaded BOARD object. The caller owns it an it will 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 158 of file io_mgr.cpp.

161 {
162  // release the PLUGIN even if an exception is thrown.
163  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
164 
165  if( (PLUGIN*) pi ) // test pi->plugin
166  {
167  return pi->Load( aFileName, aAppendToMe, aProperties, aProject, aProgressReporter );
168  }
169 
170  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
171 }
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:46
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: io_mgr.cpp:77
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:555
#define FMT_NOTFOUND
Definition: io_mgr.cpp:43
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:269
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

Referenced by LoadBoard().

◆ PluginFind()

PLUGIN * IO_MGR::PluginFind ( PCB_FILE_T  aFileType)
static

Return 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.

Note
The caller owns the returned object and must call PluginRelease when done using it.
Parameters
aFileTypeis from PCB_FILE_T and tells which plugin to find.
Returns
the plug in corresponding to aFileType or NULL if not found.

Definition at line 58 of file io_mgr.cpp.

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 }
PLUGIN * Create(PCB_FILE_T aFileType) const
Definition: io_mgr.h:107
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:86

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

Referenced by PCB_CONTROL::AppendBoardFromFile(), AskLoadBoardFileName(), PCB_BASE_EDIT_FRAME::createNewLibrary(), DIALOG_FP_PLUGIN_OPTIONS::DIALOG_FP_PLUGIN_OPTIONS(), PCB_EDIT_FRAME::ExportFootprintsToLibrary(), FP_LIB_TABLE::FindRow(), GetFileExtension(), Load(), DIALOG_BOARD_SETUP::OnAuxiliaryAction(), PCB_EDIT_FRAME::OpenProjectFiles(), parse_footprint_with_plugin(), Save(), FOOTPRINT_EDIT_FRAME::SaveLibraryAs(), PCB_EDIT_FRAME::SavePcbCopy(), and PCB_EDIT_FRAME::SavePcbFile().

◆ PluginRelease()

void IO_MGR::PluginRelease ( PLUGIN aPlugin)
static

Release 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.

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 }

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

◆ Save()

void IO_MGR::Save ( PCB_FILE_T  aFileType,
const wxString &  aFileName,
BOARD aBoard,
const PROPERTIES aProperties = nullptr 
)
static

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

176 {
177  // release the PLUGIN even if an exception is thrown.
178  PLUGIN::RELEASER pi( PluginFind( aFileType ) );
179 
180  if( (PLUGIN*) pi ) // test pi->plugin
181  {
182  pi->Save( aFileName, aBoard, aProperties ); // virtual
183  return;
184  }
185 
186  THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) );
187 }
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: io_mgr.cpp:77
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:555
virtual void Save(const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=nullptr)
Write aBoard to a storage file in a format that this PLUGIN implementation knows about or it can be u...
Definition: plugin.cpp:60
#define FMT_NOTFOUND
Definition: io_mgr.cpp:43
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:269
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38

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

Referenced by SaveBoard().

◆ ShowType()

const wxString IO_MGR::ShowType ( PCB_FILE_T  aFileType)
static

Return a brief name for a plugin given aFileType enum.

Definition at line 77 of file io_mgr.cpp.

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 }
#define _(s)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static PLUGIN_REGISTRY * Instance()
Definition: io_mgr.h:86
const std::vector< ENTRY > & AllPlugins() const
Definition: io_mgr.h:120

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

Referenced by PCB_BASE_EDIT_FRAME::AddLibrary(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), FP_LIB_TABLE_ROW::GetType(), Load(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), and Save().


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