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-2021 KiCad Developers, see AUTHORS.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 #include <reporter.h>
31 
32 
33 class SCH_SHEET;
34 class SCH_SCREEN;
35 class SCH_PLUGIN;
36 class SCHEMATIC;
37 class KIWAY;
38 class LIB_SYMBOL;
39 class SYMBOL_LIB;
40 class PROPERTIES;
41 class PROGRESS_REPORTER;
42 
43 
48 {
49 public:
50 
55  DEFINE_ENUM_VECTOR( SCH_FILE_T,
56  {
57  SCH_LEGACY,
58  SCH_KICAD,
59  SCH_ALTIUM,
60  SCH_CADSTAR_ARCHIVE,
61  SCH_EAGLE,
62 
63  // Add your schematic type here.
64  SCH_FILE_UNKNOWN
65  } )
66 
80  APIEXPORT
81  static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
82 
89  static void ReleasePlugin( SCH_PLUGIN* aPlugin );
90 
94  static const wxString ShowType( SCH_FILE_T aFileType );
95 
99  static SCH_FILE_T EnumFromStr( const wxString& aFileType );
100 
108  static const wxString GetFileExtension( SCH_FILE_T aFileType );
109 
117  static const wxString GetLibraryFileExtension( SCH_FILE_T aFileType );
118 
122  static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
123 
127  static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath );
128 };
129 
130 
153 {
154 public:
155 
156  //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
157 
161  virtual const wxString GetName() const = 0;
162 
166  virtual void SetReporter( REPORTER* aReporter ) {}
167 
171  virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) {}
172 
176  virtual const wxString GetFileExtension() const = 0;
177 
181  virtual const wxString GetLibraryFileExtension() const = 0;
182 
192  virtual int GetModifyHash() const = 0;
193 
194  virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = nullptr );
195 
224  virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
225  SCH_SHEET* aAppendToMe = nullptr,
226  const PROPERTIES* aProperties = nullptr );
227 
253  virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
254  const PROPERTIES* aProperties = nullptr );
255 
272  virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
273  const PROPERTIES* aProperties = nullptr );
274 
294  virtual void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
295  const wxString& aLibraryPath,
296  const PROPERTIES* aProperties = nullptr );
297 
319  virtual LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
320  const PROPERTIES* aProperties = nullptr );
321 
343  virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
344  const PROPERTIES* aProperties = nullptr );
345 
364  virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
365  const PROPERTIES* aProperties = nullptr );
366 
382  virtual void CreateSymbolLib( const wxString& aLibraryPath,
383  const PROPERTIES* aProperties = nullptr );
384 
404  virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
405  const PROPERTIES* aProperties = nullptr );
406 
416  virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
417 
442  virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
443 
450  virtual bool CheckHeader( const wxString& aFileName );
451 
460  virtual const wxString& GetError() const;
461 
462  //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
463 
464 
465  /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
466  automatically if you do not provide one. If you decide you need to
467  provide a zero argument constructor of your own design, that is allowed.
468  It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
469  passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
470  API functions which take one.
471  */
472  virtual ~SCH_PLUGIN() { }
473 
474 
480  {
482 
483  // private assignment operator so it's illegal
484  SCH_PLUGIN_RELEASER& operator=( SCH_PLUGIN_RELEASER& aOther ) { return *this; }
485 
486  // private copy constructor so it's illegal
488 
489  public:
490  SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = nullptr ) :
491  plugin( aPlugin )
492  {
493  }
494 
496  {
497  if( plugin )
498  release();
499  }
500 
501  void release()
502  {
504  plugin = nullptr;
505  }
506 
507  void set( SCH_PLUGIN* aPlugin )
508  {
509  if( plugin )
510  release();
511  plugin = aPlugin;
512  }
513 
514  operator SCH_PLUGIN* () const
515  {
516  return plugin;
517  }
518 
520  {
521  return plugin;
522  }
523  };
524 };
525 
526 #endif // _SCH_IO_MGR_H_
A factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:47
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:151
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:102
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.
Holds all the data relating to one schematic.
Definition: schematic.h:59
Object used to load, save, search, and otherwise manipulate symbol library files.
A progress reporter interface for use in multi-threaded environments.
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:51
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:79
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:487
static const wxString GetLibraryFileExtension(SCH_FILE_T aFileType)
Return the symbol library file extension (if any) for aFileType.
Definition: sch_io_mgr.cpp:136
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:110
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const PROPERTIES *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:94
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:507
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
virtual const wxString GetName() const =0
Return a brief hard coded name for this SCH_PLUGIN.
A name/value tuple with unique names and optional values.
Definition: properties.h:33
Define a library symbol object.
Definition: lib_symbol.h:96
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.
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=nullptr)
Definition: sch_io_mgr.h:490
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:169
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:152
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
Definition: sch_io_mgr.cpp:121
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition: sch_io_mgr.h:166
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:117
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:67
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:472
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:479
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:98
virtual void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:59
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition: sch_io_mgr.h:171
virtual const wxString GetFileExtension() const =0
Return 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
SCH_PLUGIN * operator ->() const
Definition: sch_io_mgr.h:519
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:484
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const PROPERTIES *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:85
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=nullptr)
Definition: sch_plugin.cpp:45
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:69