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 
282  virtual wxArrayString FootprintEnumerate( const wxString& aLibraryPath,
283  const PROPERTIES* aProperties = NULL );
284 
304  virtual void PrefetchLib( const wxString& aLibraryPath,
305  const PROPERTIES* aProperties = NULL );
306 
328  virtual MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
329  const PROPERTIES* aProperties = NULL );
330 
350  virtual void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
351  const PROPERTIES* aProperties = NULL );
352 
370  virtual void FootprintDelete( const wxString& aLibraryPath,
371  const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
372 
390  virtual void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
391 
411  virtual bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
412 
423  virtual bool IsFootprintLibWritable( const wxString& aLibraryPath );
424 
451  virtual void FootprintLibOptions( PROPERTIES* aListToAppendTo ) const;
452 
453  //-----</PUBLIC PLUGIN API>------------------------------------------------
454 
455 
456  /* The compiler writes the "zero argument" constructor for a PLUGIN
457  automatically if you do not provide one. If you decide you need to
458  provide a zero argument constructor of your own design, that is allowed.
459  It must be public, and it is what the IO_MGR uses. Parameters may be
460  passed into a PLUGIN via the PROPERTIES variable for any of the public
461  API functions which take one.
462  */
463 
464  virtual ~PLUGIN()
465  {
466  //printf( "~%s", __func__ );
467  };
468 
469 
470 #ifndef SWIG
471 
476  class RELEASER
477  {
479 
480  // private assignment operator so it's illegal
481  RELEASER& operator=( RELEASER& aOther ) { return *this; }
482 
483  // private copy constructor so it's illegal
484  RELEASER( const RELEASER& aOther ) {}
485 
486  public:
487  RELEASER( PLUGIN* aPlugin = NULL ) :
488  plugin( aPlugin )
489  {
490  }
491 
493  {
494  if( plugin )
495  release();
496  }
497 
498  void release()
499  {
500  IO_MGR::PluginRelease( plugin );
501  plugin = NULL;
502  }
503 
504  void set( PLUGIN* aPlugin )
505  {
506  if( plugin )
507  release();
508  plugin = aPlugin;
509  }
510 
511  operator PLUGIN* () const
512  {
513  return plugin;
514  }
515 
517  {
518  return plugin;
519  }
520  };
521 #endif
522 };
523 
524 #endif // IO_MGR_H_
void release()
Definition: io_mgr.h:498
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 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:487
RELEASER(const RELEASER &aOther)
Definition: io_mgr.h:484
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:516
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:114
Class RELEASER releases a PLUGIN in the context of a potential thrown exception, through its destruct...
Definition: io_mgr.h:476
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:481
void set(PLUGIN *aPlugin)
Definition: io_mgr.h:504
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:478
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: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:464
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