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 LIB_ALIAS;
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_EAGLE,
59  // Add your schematic type here.
60 
61  // ALTIUM,
62  // etc.
63  } );
64 
78  APIEXPORT
79  static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
80 
87  static void ReleasePlugin( SCH_PLUGIN* aPlugin );
88 
92  static const wxString ShowType( SCH_FILE_T aFileType );
93 
97  static SCH_FILE_T EnumFromStr( const wxString& aFileType );
98 
106  static const wxString GetFileExtension( SCH_FILE_T aFileType );
107 
111  static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
112 
137  static SCH_SHEET* Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway,
138  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
139 
162  static void Save( SCH_FILE_T aFileType, const wxString& aFileName,
163  SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
164 };
165 
166 
189 {
190 public:
191 
192  //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
193 
197  virtual const wxString GetName() const = 0;
198 
202  virtual const wxString GetFileExtension() const = 0;
203 
213  virtual int GetModifyHash() const = 0;
214 
215  virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL );
216 
245  virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
246  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
247 
271  virtual void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
272  const PROPERTIES* aProperties = NULL );
273 
274  virtual size_t GetSymbolLibCount( const wxString& aLibraryPath,
275  const PROPERTIES* aProperties = NULL );
276 
293  virtual void EnumerateSymbolLib( wxArrayString& aAliasNameList,
294  const wxString& aLibraryPath,
295  const PROPERTIES* aProperties = NULL );
296 
313  virtual void EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
314  const wxString& aLibraryPath,
315  const PROPERTIES* aProperties = NULL );
316 
339  virtual LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
340  const PROPERTIES* aProperties = NULL );
341 
363  virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
364  const PROPERTIES* aProperties = NULL );
365 
387  virtual void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
388  const PROPERTIES* aProperties = NULL );
389 
408  virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
409  const PROPERTIES* aProperties = NULL );
410 
426  virtual void CreateSymbolLib( const wxString& aLibraryPath,
427  const PROPERTIES* aProperties = NULL );
428 
448  virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
449  const PROPERTIES* aProperties = NULL );
450 
460  virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
461 
486  virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
487 
494  virtual bool CheckHeader( const wxString& aFileName );
495 
496  //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
497 
498 
499  /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
500  automatically if you do not provide one. If you decide you need to
501  provide a zero argument constructor of your own design, that is allowed.
502  It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
503  passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
504  API functions which take one.
505  */
506  virtual ~SCH_PLUGIN() { }
507 
508 
514  {
516 
517  // private assignment operator so it's illegal
518  SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
519 
520  // private copy constructor so it's illegal
522 
523  public:
524  SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = NULL ) :
525  plugin( aPlugin )
526  {
527  }
528 
530  {
531  if( plugin )
532  release();
533  }
534 
535  void release()
536  {
537  SCH_IO_MGR::ReleasePlugin( plugin );
538  plugin = NULL;
539  }
540 
541  void set( SCH_PLUGIN* aPlugin )
542  {
543  if( plugin )
544  release();
545  plugin = aPlugin;
546  }
547 
548  operator SCH_PLUGIN* () const
549  {
550  return plugin;
551  }
552 
554  {
555  return plugin;
556  }
557  };
558 };
559 
560 #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:46
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a footprint library's libPath.
Definition: sch_io_mgr.cpp:130
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:134
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44
Part library alias object definition.
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:101
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:141
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:126
static APIEXPORT SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Return a SCH_PLUGIN which the caller can use to import, export, save, or load design documents...
Definition: sch_io_mgr.cpp:49
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:78
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:521
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:58
virtual void EnumerateSymbolLib(wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:83
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:159
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:541
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 void SymbolLibOptions(PROPERTIES *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions...
Definition: sch_plugin.cpp:157
virtual bool CheckHeader(const wxString &aFileName)
Function CheckHeader returns true if the first line in aFileName begins with the expected header...
Definition: sch_plugin.cpp:193
virtual size_t GetSymbolLibCount(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:74
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:188
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the file extension for aFileType.
Definition: sch_io_mgr.cpp:115
Class LIB_PART defines a library part object.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
DEFINE_ENUM_VECTOR(SCH_FILE_T,{SCH_LEGACY, SCH_KICAD, SCH_EAGLE,})
A set of file types that the SCH_IO_MGR knows about, and for which there has been a plugin written...
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:506
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=NULL)
Definition: sch_io_mgr.h:524
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
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:144
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:513
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:66
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:52
static SCH_FILE_T EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
Definition: sch_io_mgr.cpp:98
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:149
virtual void DeleteAlias(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete aAliasName from the library at aLibraryPath.
Definition: sch_plugin.cpp:118
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:110
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:518
SCH_PLUGIN * operator->() const
Definition: sch_io_mgr.h:553
Class PART_LIB is used to load, save, search, and otherwise manipulate part 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:68