KiCad PCB EDA Suite
sch_io_mgr.h
Go to the documentation of this file.
1 #ifndef _SCH_IO_MGR_H_
2 #define _SCH_IO_MGR_H_
3 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2016 CERN
8  * Copyright (C) 2016-2017 KiCad Developers, see CHANGELOG.TXT for contributors.
9  *
10  * @author Wayne Stambaugh <stambaughw@gmail.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 3
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include <richio.h>
27 #include <import_export.h>
28 #include <map>
29 #include <enum_vector.h>
30 
31 
32 class SCH_SHEET;
33 class SCH_SCREEN;
34 class SCH_PLUGIN;
35 class KIWAY;
36 class LIB_PART;
37 class PART_LIB;
38 class PROPERTIES;
39 
40 
46 {
47 public:
48 
53  DEFINE_ENUM_VECTOR( SCH_FILE_T,
54  {
55  SCH_LEGACY,
56 // SCH_KICAD, ///< The s-expression version of the schematic file formats.
57  SCH_EAGLE,
58  // Add your schematic type here.
59 
60  // ALTIUM,
61  // etc.
62  } )
63 
77  APIEXPORT
78  static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
79 
86  static void ReleasePlugin( SCH_PLUGIN* aPlugin );
87 
91  static const wxString ShowType( SCH_FILE_T aFileType );
92 
96  static SCH_FILE_T EnumFromStr( const wxString& aFileType );
97 
105  static const wxString GetFileExtension( SCH_FILE_T aFileType );
106 
110  static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
111 
136  static SCH_SHEET* Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway,
137  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
138 
161  static void Save( SCH_FILE_T aFileType, const wxString& aFileName,
162  SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
163 };
164 
165 
188 {
189 public:
190 
191  //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
192 
196  virtual const wxString GetName() const = 0;
197 
201  virtual const wxString GetFileExtension() const = 0;
202 
212  virtual int GetModifyHash() const = 0;
213 
214  virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL );
215 
244  virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
245  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
246 
270  virtual void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
271  const PROPERTIES* aProperties = NULL );
272 
289  virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
290  const wxString& aLibraryPath,
291  const PROPERTIES* aProperties = NULL );
292 
312  virtual void EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
313  const wxString& aLibraryPath,
314  const PROPERTIES* aProperties = NULL );
315 
337  virtual LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
338  const PROPERTIES* aProperties = NULL );
339 
361  virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
362  const PROPERTIES* aProperties = NULL );
363 
382  virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
383  const PROPERTIES* aProperties = NULL );
384 
400  virtual void CreateSymbolLib( const wxString& aLibraryPath,
401  const PROPERTIES* aProperties = NULL );
402 
422  virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
423  const PROPERTIES* aProperties = NULL );
424 
434  virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
435 
460  virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
461 
468  virtual bool CheckHeader( const wxString& aFileName );
469 
478  virtual const wxString& GetError() const;
479 
480  //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
481 
482 
483  /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
484  automatically if you do not provide one. If you decide you need to
485  provide a zero argument constructor of your own design, that is allowed.
486  It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
487  passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
488  API functions which take one.
489  */
490  virtual ~SCH_PLUGIN() { }
491 
492 
498  {
500 
501  // private assignment operator so it's illegal
502  SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
503 
504  // private copy constructor so it's illegal
506 
507  public:
508  SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = NULL ) :
509  plugin( aPlugin )
510  {
511  }
512 
514  {
515  if( plugin )
516  release();
517  }
518 
519  void release()
520  {
522  plugin = NULL;
523  }
524 
525  void set( SCH_PLUGIN* aPlugin )
526  {
527  if( plugin )
528  release();
529  plugin = aPlugin;
530  }
531 
532  operator SCH_PLUGIN* () const
533  {
534  return plugin;
535  }
536 
538  {
539  return plugin;
540  }
541  };
542 };
543 
544 #endif // _SCH_IO_MGR_H_
Class SCH_IO_MGR is a factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:45
DEFINE_ENUM_VECTOR(SCH_FILE_T, { SCH_LEGACY, SCH_EAGLE, }) APIEXPORT static SCH_PLUGIN *FindPlugin(SCH_FILE_T aFileType)
A set of file types that the SCH_IO_MGR knows about, and for which there has been a plugin written.
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a footprint library's libPath.
Definition: sch_io_mgr.cpp:128
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:109
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:116
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:76
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:505
virtual SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:50
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=NULL)
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:101
static void Save(SCH_FILE_T aFileType, const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Write either a full aSchematic to a storage file in a format that this implementation knows about,...
Definition: sch_io_mgr.cpp:157
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:525
virtual const wxString GetName() const =0
Returns a brief hard coded name for this SCH_PLUGIN.
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
virtual bool CheckHeader(const wxString &aFileName)
Return true if the first line in aFileName begins with the expected header.
Definition: sch_plugin.cpp:168
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:187
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:66
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the file extension for aFileType.
Definition: sch_io_mgr.cpp:113
virtual LIB_PART * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=NULL)
Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this S...
Definition: sch_plugin.cpp:84
Define a library symbol object.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:274
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:490
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=NULL)
Definition: sch_io_mgr.h:508
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
static SCH_SHEET * Load(SCH_FILE_T aFileType, const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function on it using the a...
Definition: sch_io_mgr.cpp:142
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:497
virtual void Save(const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:58
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:44
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Definition: sch_io_mgr.cpp:96
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:176
virtual const wxString GetFileExtension() const =0
Returns the file extension for the SCH_PLUGIN.
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:124
virtual void SymbolLibOptions(PROPERTIES *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:132
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:93
SCH_PLUGIN * operator ->() const
Definition: sch_io_mgr.h:537
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:502
Object used to load, save, search, and otherwise manipulate symbol library files.
static void ReleasePlugin(SCH_PLUGIN *aPlugin)
Release a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory.
Definition: sch_io_mgr.cpp:66