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-2020 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 SCHEMATIC;
36 class KIWAY;
37 class LIB_PART;
38 class PART_LIB;
39 class PROPERTIES;
40 
41 
47 {
48 public:
49 
54  DEFINE_ENUM_VECTOR( SCH_FILE_T,
55  {
56  SCH_LEGACY,
57  SCH_KICAD,
58  SCH_ALTIUM,
59  SCH_CADSTAR_ARCHIVE,
60  SCH_EAGLE,
61  // Add your schematic type here.
62 
63  // ALTIUM,
64  // etc.
65  SCH_FILE_UNKNOWN
66  } )
67 
81  APIEXPORT
82  static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
83 
90  static void ReleasePlugin( SCH_PLUGIN* aPlugin );
91 
95  static const wxString ShowType( SCH_FILE_T aFileType );
96 
100  static SCH_FILE_T EnumFromStr( const wxString& aFileType );
101 
109  static const wxString GetFileExtension( SCH_FILE_T aFileType );
110 
118  static const wxString GetLibraryFileExtension( SCH_FILE_T aFileType );
119 
123  static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
124 
128  static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath );
129 };
130 
131 
154 {
155 public:
156 
157  //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
158 
162  virtual const wxString GetName() const = 0;
163 
167  virtual const wxString GetFileExtension() const = 0;
168 
172  virtual const wxString GetLibraryFileExtension() const = 0;
173 
183  virtual int GetModifyHash() const = 0;
184 
185  virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL );
186 
215  virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
216  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
217 
243  virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
244  const PROPERTIES* aProperties = NULL );
245 
262  virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
263  const wxString& aLibraryPath,
264  const PROPERTIES* aProperties = NULL );
265 
285  virtual void EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
286  const wxString& aLibraryPath,
287  const PROPERTIES* aProperties = NULL );
288 
310  virtual LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
311  const PROPERTIES* aProperties = NULL );
312 
334  virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
335  const PROPERTIES* aProperties = NULL );
336 
355  virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
356  const PROPERTIES* aProperties = NULL );
357 
373  virtual void CreateSymbolLib( const wxString& aLibraryPath,
374  const PROPERTIES* aProperties = NULL );
375 
395  virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
396  const PROPERTIES* aProperties = NULL );
397 
407  virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
408 
433  virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
434 
441  virtual bool CheckHeader( const wxString& aFileName );
442 
451  virtual const wxString& GetError() const;
452 
453  //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
454 
455 
456  /* The compiler writes the "zero argument" constructor for a SCH_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 SCH_IO_MGR uses. Parameters may be
460  passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
461  API functions which take one.
462  */
463  virtual ~SCH_PLUGIN() { }
464 
465 
471  {
473 
474  // private assignment operator so it's illegal
475  SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
476 
477  // private copy constructor so it's illegal
479 
480  public:
482  plugin( aPlugin )
483  {
484  }
485 
487  {
488  if( plugin )
489  release();
490  }
491 
492  void release()
493  {
495  plugin = NULL;
496  }
497 
498  void set( SCH_PLUGIN* aPlugin )
499  {
500  if( plugin )
501  release();
502  plugin = aPlugin;
503  }
504 
505  operator SCH_PLUGIN* () const
506  {
507  return plugin;
508  }
509 
511  {
512  return plugin;
513  }
514  };
515 };
516 
517 #endif // _SCH_IO_MGR_H_
SCH_IO_MGR is a factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:46
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:169
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:110
#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:117
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:44
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:87
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:478
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, 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:51
static const wxString GetLibraryFileExtension(SCH_FILE_T aFileType)
Return the symbol library file extension (if any) for aFileType.
Definition: sch_io_mgr.cpp:154
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:102
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:498
virtual void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=NULL)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:59
virtual const wxString GetName() const =0
Returns a brief hard coded name for this SCH_PLUGIN.
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:169
DEFINE_ENUM_VECTOR(SCH_FILE_T, { SCH_LEGACY, SCH_KICAD, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_EAGLE, SCH_FILE_UNKNOWN }) 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 GuessPluginTypeFromSchPath(const wxString &aSchematicPath)
Return a plugin type given a schematic using the file extension of aSchematicPath.
Definition: sch_io_mgr.cpp:187
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:153
#define NULL
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:67
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
Definition: sch_io_mgr.cpp:139
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:85
Define a library symbol object.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:463
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=NULL)
Definition: sch_io_mgr.h:481
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:470
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:45
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:116
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
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:125
virtual void SymbolLibOptions(PROPERTIES *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:133
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:94
SCH_PLUGIN * operator ->() const
Definition: sch_io_mgr.h:510
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:475
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:77