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 <[email protected]>
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
33class SCH_SHEET;
34class SCH_SCREEN;
35class SCH_PLUGIN;
36class SCHEMATIC;
38class KIWAY;
39class LIB_SYMBOL;
40class SYMBOL_LIB;
41class PROPERTIES;
43
44
49{
50public:
51
56 DEFINE_ENUM_VECTOR( SCH_FILE_T,
57 {
58 SCH_LEGACY,
59 SCH_KICAD,
60 SCH_ALTIUM,
61 SCH_CADSTAR_ARCHIVE,
62 SCH_EAGLE,
63 SCH_DATABASE,
64
65 // Add your schematic type here.
66 SCH_FILE_UNKNOWN
67 } )
68
83 static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
84
91 static void ReleasePlugin( SCH_PLUGIN* aPlugin );
92
96 static const wxString ShowType( SCH_FILE_T aFileType );
97
101 static SCH_FILE_T EnumFromStr( const wxString& aFileType );
102
110 static const wxString GetFileExtension( SCH_FILE_T aFileType );
111
119 static const wxString GetLibraryFileExtension( SCH_FILE_T aFileType );
120
124 static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
125
129 static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath );
130};
131
132
155{
156public:
157
158 //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
159
163 virtual const wxString GetName() const = 0;
164
168 virtual void SetReporter( REPORTER* aReporter ) {}
169
173 virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) {}
174
178 virtual const wxString GetFileExtension() const = 0;
179
183 virtual const wxString GetLibraryFileExtension() const = 0;
184
194 virtual int GetModifyHash() const = 0;
195
196 virtual void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = nullptr );
197
226 virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
227 SCH_SHEET* aAppendToMe = nullptr,
228 const PROPERTIES* aProperties = nullptr );
229
255 virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
256 const PROPERTIES* aProperties = nullptr );
257
274 virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
275 const PROPERTIES* aProperties = nullptr );
276
296 virtual void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
297 const wxString& aLibraryPath,
298 const PROPERTIES* aProperties = nullptr );
299
321 virtual LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
322 const PROPERTIES* aProperties = nullptr );
323
345 virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
346 const PROPERTIES* aProperties = nullptr );
347
366 virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
367 const PROPERTIES* aProperties = nullptr );
368
384 virtual void CreateSymbolLib( const wxString& aLibraryPath,
385 const PROPERTIES* aProperties = nullptr );
386
406 virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
407 const PROPERTIES* aProperties = nullptr );
408
418 virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
419
444 virtual void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const;
445
449 virtual bool SupportsSubLibraries() const { return false; }
450
463 virtual void GetSubLibraryNames( std::vector<wxString>& aNames ) {}
464
474 virtual void GetAvailableSymbolFields( std::vector<wxString>& aNames ) {}
475
488 virtual void GetDefaultSymbolFields( std::vector<wxString>& aNames )
489 {
490 return GetAvailableSymbolFields( aNames );
491 }
492
499 virtual bool CheckHeader( const wxString& aFileName );
500
509 virtual const wxString& GetError() const;
510
515 virtual void SetLibTable( SYMBOL_LIB_TABLE* aTable ) {}
516
517 //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
518
519
520 /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
521 automatically if you do not provide one. If you decide you need to
522 provide a zero argument constructor of your own design, that is allowed.
523 It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
524 passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
525 API functions which take one.
526 */
527 virtual ~SCH_PLUGIN() { }
528
529
535 {
537
538 // private assignment operator so it's illegal
540
541 // private copy constructor so it's illegal
543
544 public:
545 SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = nullptr ) :
546 plugin( aPlugin )
547 {
548 }
549
551 {
552 if( plugin )
553 release();
554 }
555
556 void release()
557 {
559 plugin = nullptr;
560 }
561
562 void set( SCH_PLUGIN* aPlugin )
563 {
564 if( plugin )
565 release();
566 plugin = aPlugin;
567 }
568
569 operator SCH_PLUGIN* () const
570 {
571 return plugin;
572 }
573
575 {
576 return plugin;
577 }
578 };
579};
580
581#endif // _SCH_IO_MGR_H_
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:267
Define a library symbol object.
Definition: lib_symbol.h:98
A progress reporter interface for use in multi-threaded environments.
A name/value tuple with unique names and optional values.
Definition: properties.h:34
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Holds all the data relating to one schematic.
Definition: schematic.h:60
A factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:49
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:101
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
Definition: sch_io_mgr.cpp:126
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:81
static const wxString GetLibraryFileExtension(SCH_FILE_T aFileType)
Return the symbol library file extension (if any) for aFileType.
Definition: sch_io_mgr.cpp:141
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:71
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:174
DEFINE_ENUM_VECTOR(SCH_FILE_T, { SCH_LEGACY, SCH_KICAD, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_EAGLE, SCH_DATABASE, 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 GuessPluginTypeFromLibPath(const wxString &aLibPath)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:156
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:535
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:562
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:542
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:539
SCH_PLUGIN * operator->() const
Definition: sch_io_mgr.h:574
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=nullptr)
Definition: sch_io_mgr.h:545
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:155
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
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 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
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
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
virtual const wxString GetName() const =0
Return a brief hard coded name for this SCH_PLUGIN.
virtual void GetAvailableSymbolFields(std::vector< wxString > &aNames)
Retrieves a list of (custom) field names that are present on symbols in this library.
Definition: sch_io_mgr.h:474
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=nullptr)
Definition: sch_plugin.cpp:45
virtual bool SupportsSubLibraries() const
Definition: sch_io_mgr.h:449
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:515
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
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 GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
Definition: sch_io_mgr.h:463
virtual const wxString GetFileExtension() const =0
Return the file extension for the SCH_PLUGIN.
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 void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition: sch_io_mgr.h:168
virtual void GetDefaultSymbolFields(std::vector< wxString > &aNames)
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
Definition: sch_io_mgr.h:488
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition: sch_io_mgr.h:173
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 SymbolLibOptions(PROPERTIES *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:133
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:527
virtual bool CheckHeader(const wxString &aFileName)
Return true if the first line in aFileName begins with the expected header.
Definition: sch_plugin.cpp:169
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:125
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
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:55
Object used to load, save, search, and otherwise manipulate symbol library files.
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:44