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 <map>
28 
29 
30 class SCH_SHEET;
31 class SCH_SCREEN;
32 class SCH_PLUGIN;
33 class KIWAY;
34 class LIB_PART;
35 class LIB_ALIAS;
36 class PART_LIB;
37 class PROPERTIES;
38 
39 
45 {
46 public:
47 
54  {
57  // Add your schematic type here.
58 
59  // ALTIUM,
60  // etc.
61  };
62 
75  static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
76 
84  static void ReleasePlugin( SCH_PLUGIN* aPlugin );
85 
90  static const wxString ShowType( SCH_FILE_T aFileType );
91 
96  static SCH_FILE_T EnumFromStr( const wxString& aFileType );
97 
106  static const wxString GetFileExtension( SCH_FILE_T aFileType );
107 
112  static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
113 
134  static SCH_SHEET* Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway,
135  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
136 
160  static void Save( SCH_FILE_T aFileType, const wxString& aFileName,
161  SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties = NULL );
162 };
163 
164 
188 {
189 public:
190 
191  //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
192 
198  virtual const wxString GetName() const = 0;
199 
204  virtual const wxString GetFileExtension() const = 0;
205 
217  virtual int GetModifyHash() const = 0;
218 
219  virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL );
220 
248  virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
249  SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
250 
273  virtual void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
274  const PROPERTIES* aProperties = NULL );
275 
276  virtual size_t GetSymbolLibCount( const wxString& aLibraryPath,
277  const PROPERTIES* aProperties = NULL );
278 
295  virtual void EnumerateSymbolLib( wxArrayString& aAliasNameList,
296  const wxString& aLibraryPath,
297  const PROPERTIES* aProperties = NULL );
298 
315  virtual void EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
316  const wxString& aLibraryPath,
317  const PROPERTIES* aProperties = NULL );
318 
343  virtual LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
344  const PROPERTIES* aProperties = NULL );
345 
369  virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
370  const PROPERTIES* aProperties = NULL );
371 
395  virtual void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
396  const PROPERTIES* aProperties = NULL );
397 
418  virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
419  const PROPERTIES* aProperties = NULL );
420 
438  virtual void CreateSymbolLib( const wxString& aLibraryPath,
439  const PROPERTIES* aProperties = NULL );
440 
462  virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
463  const PROPERTIES* aProperties = NULL );
464 
475  virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
476 
503  virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
504 
505  //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
506 
507 
508  /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
509  automatically if you do not provide one. If you decide you need to
510  provide a zero argument constructor of your own design, that is allowed.
511  It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
512  passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
513  API functions which take one.
514  */
515  virtual ~SCH_PLUGIN() { }
516 
517 
525  {
527 
528  // private assignment operator so it's illegal
529  SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
530 
531  // private copy constructor so it's illegal
533 
534  public:
535  SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = NULL ) :
536  plugin( aPlugin )
537  {
538  }
539 
541  {
542  if( plugin )
543  release();
544  }
545 
546  void release()
547  {
548  SCH_IO_MGR::ReleasePlugin( plugin );
549  plugin = NULL;
550  }
551 
552  void set( SCH_PLUGIN* aPlugin )
553  {
554  if( plugin )
555  release();
556  plugin = aPlugin;
557  }
558 
559  operator SCH_PLUGIN* () const
560  {
561  return plugin;
562  }
563 
565  {
566  return plugin;
567  }
568  };
569 };
570 
571 #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:44
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath)
Function GuessPluginTypeFromLibPath returns a plugin type given a footprint library's libPath...
Definition: sch_io_mgr.cpp:122
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function CreateSymbolLib.
Definition: sch_plugin.cpp:134
Part library alias object definition.
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Function LoadSymbol.
Definition: sch_plugin.cpp:101
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function DeleteSymbolLib.
Definition: sch_plugin.cpp:141
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Function DeleteSymbol.
Definition: sch_plugin.cpp:126
static SCH_PLUGIN * FindPlugin(SCH_FILE_T aFileType)
Function FindPlugin returns a SCH_PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: sch_io_mgr.cpp:48
static const wxString ShowType(SCH_FILE_T aFileType)
Function ShowType returns a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:75
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:532
virtual SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Function Load.
Definition: sch_plugin.cpp:58
virtual void EnumerateSymbolLib(wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function EnumerateSymbolLib.
Definition: sch_plugin.cpp:83
static void Save(SCH_FILE_T aFileType, const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Function Save will write either a full aSchematic to a storage file in a format that this implementat...
Definition: sch_io_mgr.cpp:151
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:552
virtual const wxString GetName() const =0
Function GetName 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
Function SymbolLibOptions.
Definition: sch_plugin.cpp:157
virtual size_t GetSymbolLibCount(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:74
virtual int GetModifyHash() const =0
Function GetModifyHash.
Class SCH_PLUGIN is a base class that SCHEMATIC loading and saving plugins should derive from...
Definition: sch_io_mgr.h:187
Legacy Eeschema file formats prior to s-expression.
Definition: sch_io_mgr.h:55
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: sch_io_mgr.cpp:107
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
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:515
The s-expression version of the schematic file formats.
Definition: sch_io_mgr.h:56
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=NULL)
Definition: sch_io_mgr.h:535
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)
Function Load finds the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function on it using the arguments passed to this function.
Definition: sch_io_mgr.cpp:136
Class SCH_PLUGIN_RELEASER.
Definition: sch_io_mgr.h:524
virtual void Save(const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Function Save.
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)
Function EnumFromStr returns the SCH_FILE_T from the corresponding plugin type name: "kicad"...
Definition: sch_io_mgr.cpp:92
virtual const wxString GetFileExtension() const =0
Function GetFileExtension returns the file extension for the SCH_PLUGIN.
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Function IsSymbolLibWritable returns 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)
Function DeleteAlias.
Definition: sch_plugin.cpp:118
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Function SaveSymbol.
Definition: sch_plugin.cpp:110
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:529
SCH_PLUGIN * operator->() const
Definition: sch_io_mgr.h:564
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
static void ReleasePlugin(SCH_PLUGIN *aPlugin)
Function PluginRelease releases a SCH_PLUGIN back to the system, and may cause it to be unloaded from...
Definition: sch_io_mgr.cpp:65
SCH_FILE_T
Enum SCH_FILE_T is a set of file types that the SCH_IO_MGR knows about, and for which there has been ...
Definition: sch_io_mgr.h:53