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-2017 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 
280  virtual void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
281  const PROPERTIES* aProperties = NULL );
282 
302  virtual void PrefetchLib( const wxString& aLibraryPath,
303  const PROPERTIES* aProperties = NULL );
304 
326  virtual MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
327  const PROPERTIES* aProperties = NULL );
328 
348  virtual void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
349  const PROPERTIES* aProperties = NULL );
350 
368  virtual void FootprintDelete( const wxString& aLibraryPath,
369  const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
370 
388  virtual void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
389 
409  virtual bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
410 
421  virtual bool IsFootprintLibWritable( const wxString& aLibraryPath );
422 
449  virtual void FootprintLibOptions( PROPERTIES* aListToAppendTo ) const;
450 
451  //-----</PUBLIC PLUGIN API>------------------------------------------------
452 
453 
454  /* The compiler writes the "zero argument" constructor for a PLUGIN
455  automatically if you do not provide one. If you decide you need to
456  provide a zero argument constructor of your own design, that is allowed.
457  It must be public, and it is what the IO_MGR uses. Parameters may be
458  passed into a PLUGIN via the PROPERTIES variable for any of the public
459  API functions which take one.
460  */
461 
462  virtual ~PLUGIN()
463  {
464  //printf( "~%s", __func__ );
465  };
466 
467 
468 #ifndef SWIG
469 
474  class RELEASER
475  {
477 
478  // private assignment operator so it's illegal
479  RELEASER& operator=( RELEASER& aOther ) { return *this; }
480 
481  // private copy constructor so it's illegal
482  RELEASER( const RELEASER& aOther ) {}
483 
484  public:
485  RELEASER( PLUGIN* aPlugin = NULL ) :
486  plugin( aPlugin )
487  {
488  }
489 
491  {
492  if( plugin )
493  release();
494  }
495 
496  void release()
497  {
498  IO_MGR::PluginRelease( plugin );
499  plugin = NULL;
500  }
501 
502  void set( PLUGIN* aPlugin )
503  {
504  if( plugin )
505  release();
506  plugin = aPlugin;
507  }
508 
509  operator PLUGIN* () const
510  {
511  return plugin;
512  }
513 
515  {
516  return plugin;
517  }
518  };
519 #endif
520 };
521 
522 #endif // IO_MGR_H_
void release()
Definition: io_mgr.h:496
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
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: plugin.cpp:61
virtual void PrefetchLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function PrefetchLib If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:69
RELEASER(PLUGIN *aPlugin=NULL)
Definition: io_mgr.h:485
RELEASER(const RELEASER &aOther)
Definition: io_mgr.h:482
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:85
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:514
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 bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:114
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:474
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:76
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:106
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:479
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:502
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:476
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:169
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:92
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:99
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:462
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:122
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