KiCad PCB EDA Suite
io_mgr.h
Go to the documentation of this file.
1 #ifndef IO_MGR_H_
2 #define IO_MGR_H_
3 
4 /*
5  * This program source code file is part of KICAD, a free EDA CAD application.
6  *
7  * Copyright (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
8  * Copyright (C) 2016 Kicad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <richio.h>
29 #include <map>
30 
31 
32 class BOARD;
33 class PLUGIN;
34 class MODULE;
35 class PROPERTIES;
36 
37 
42 class IO_MGR
43 {
44 public:
45 
52  {
59 
60  // add your type here.
61 
62  // ALTIUM,
63  // etc.
64 
66  };
67 
80  static PLUGIN* PluginFind( PCB_FILE_T aFileType );
81 
89  static void PluginRelease( PLUGIN* aPlugin );
90 
95  static const wxString ShowType( PCB_FILE_T aFileType );
96 
101  static PCB_FILE_T EnumFromStr( const wxString& aFileType );
102 
111  static const wxString GetFileExtension( PCB_FILE_T aFileType );
112 
117  static PCB_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
118 
140  static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName,
141  BOARD* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
142 
166  static void Save( PCB_FILE_T aFileType, const wxString& aFileName,
167  BOARD* aBoard, const PROPERTIES* aProperties = NULL );
168 };
169 
170 
193 class PLUGIN
194 {
195 public:
196 
197  //-----<PUBLIC PLUGIN API>-------------------------------------------------
198 
203  virtual const wxString PluginName() const = 0;
204 
209  virtual const wxString GetFileExtension() const = 0;
210 
237  virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe,
238  const PROPERTIES* aProperties = NULL );
239 
260  virtual void Save( const wxString& aFileName, BOARD* aBoard,
261  const PROPERTIES* aProperties = NULL );
262 
263  //-----<Footprint Stuff>-----------------------------
264 
282  virtual wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
283  const PROPERTIES* aProperties = NULL );
284 
306  virtual MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
307  const PROPERTIES* aProperties = NULL );
308 
328  virtual void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
329  const PROPERTIES* aProperties = NULL );
330 
348  virtual void FootprintDelete( const wxString& aLibraryPath,
349  const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
350 
368  virtual void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
369 
389  virtual bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
390 
401  virtual bool IsFootprintLibWritable( const wxString& aLibraryPath );
402 
429  virtual void FootprintLibOptions( PROPERTIES* aListToAppendTo ) const;
430 
431  //-----</PUBLIC PLUGIN API>------------------------------------------------
432 
433 
434  /* The compiler writes the "zero argument" constructor for a PLUGIN
435  automatically if you do not provide one. If you decide you need to
436  provide a zero argument constructor of your own design, that is allowed.
437  It must be public, and it is what the IO_MGR uses. Parameters may be
438  passed into a PLUGIN via the PROPERTIES variable for any of the public
439  API functions which take one.
440  */
441 
442  virtual ~PLUGIN()
443  {
444  //printf( "~%s", __func__ );
445  };
446 
447 
448 #ifndef SWIG
449 
454  class RELEASER
455  {
457 
458  // private assignment operator so it's illegal
459  RELEASER& operator=( RELEASER& aOther ) { return *this; }
460 
461  // private copy constructor so it's illegal
462  RELEASER( const RELEASER& aOther ) {}
463 
464  public:
465  RELEASER( PLUGIN* aPlugin = NULL ) :
466  plugin( aPlugin )
467  {
468  }
469 
471  {
472  if( plugin )
473  release();
474  }
475 
476  void release()
477  {
478  IO_MGR::PluginRelease( plugin );
479  plugin = NULL;
480  }
481 
482  void set( PLUGIN* aPlugin )
483  {
484  if( plugin )
485  release();
486  plugin = aPlugin;
487  }
488 
489  operator PLUGIN* () const
490  {
491  return plugin;
492  }
493 
495  {
496  return plugin;
497  }
498  };
499 #endif
500 };
501 
502 #endif // IO_MGR_H_
void release()
Definition: io_mgr.h:476
virtual void Save(const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows a...
Definition: plugin.cpp:54
RELEASER(PLUGIN *aPlugin=NULL)
Definition: io_mgr.h:465
RELEASER(const RELEASER &aOther)
Definition: io_mgr.h:462
virtual void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
Definition: plugin.cpp:78
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 PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
PLUGIN * operator->() const
Definition: io_mgr.h:494
Geda PCB file formats.
Definition: io_mgr.h:57
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath...
Definition: io_mgr.cpp:182
virtual wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
Definition: plugin.cpp:61
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:107
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:454
Class IO_MGR is a factory which returns an instance of a PLUGIN.
Definition: io_mgr.h:42
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:69
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
Definition: plugin.cpp:99
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Function EnumFromStr returns the PCB_FILE_T from the corresponding plugin type name: "kicad"...
Definition: io_mgr.cpp:137
S-expression Pcbnew file format.
Definition: io_mgr.h:54
static BOARD * Load(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...
Definition: io_mgr.cpp:229
RELEASER & operator=(RELEASER &aOther)
Definition: io_mgr.h:459
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:482
virtual const wxString PluginName() const =0
Function PluginName returns a brief hard coded name for this PLUGIN.
virtual const wxString GetFileExtension() const =0
Function GetFileExtension returns the file extension for the PLUGIN.
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 ...
Definition: io_mgr.cpp:244
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
PLUGIN * plugin
Definition: io_mgr.h:456
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:53
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
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
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintDelete deletes aFootprintName from the library at aLibraryPath. ...
Definition: plugin.cpp:85
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:92
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
virtual ~PLUGIN()
Definition: io_mgr.h:442
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:115
Read only http://github.com repo holding pretty footprints.
Definition: io_mgr.h:58
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL)
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
Definition: plugin.cpp:47
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: io_mgr.cpp:167