KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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 STRING_UTF8_MAP;
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 SCH_LTSPICE,
65
66 // Add your schematic type here.
67 SCH_FILE_UNKNOWN
68 } )
69
84 static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
85
92 static void ReleasePlugin( SCH_PLUGIN* aPlugin );
93
97 static const wxString ShowType( SCH_FILE_T aFileType );
98
102 static SCH_FILE_T EnumFromStr( const wxString& aFileType );
103
111 static const wxString GetFileExtension( SCH_FILE_T aFileType );
112
120 static const wxString GetLibraryFileExtension( SCH_FILE_T aFileType );
121
125 static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath );
126
130 static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath );
131};
132
133
156{
157public:
158
159 //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
160
164 virtual const wxString GetName() const = 0;
165
169 virtual void SetReporter( REPORTER* aReporter ) {}
170
174 virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) {}
175
179 virtual const wxString GetFileExtension() const = 0;
180
184 virtual const wxString GetLibraryFileExtension() const = 0;
185
195 virtual int GetModifyHash() const = 0;
196
197 virtual void SaveLibrary( const wxString& aFileName, const STRING_UTF8_MAP* aProperties = nullptr );
198
227 virtual SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
228 SCH_SHEET* aAppendToMe = nullptr,
229 const STRING_UTF8_MAP* aProperties = nullptr );
230
256 virtual void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
257 const STRING_UTF8_MAP* aProperties = nullptr );
258
275 virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
276 const STRING_UTF8_MAP* aProperties = nullptr );
277
297 virtual void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
298 const wxString& aLibraryPath,
299 const STRING_UTF8_MAP* aProperties = nullptr );
300
322 virtual LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
323 const STRING_UTF8_MAP* aProperties = nullptr );
324
346 virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
347 const STRING_UTF8_MAP* aProperties = nullptr );
348
367 virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
368 const STRING_UTF8_MAP* aProperties = nullptr );
369
385 virtual void CreateSymbolLib( const wxString& aLibraryPath,
386 const STRING_UTF8_MAP* aProperties = nullptr );
387
407 virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
408 const STRING_UTF8_MAP* aProperties = nullptr );
409
419 virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
420
445 virtual void SymbolLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const;
446
450 virtual bool SupportsSubLibraries() const { return false; }
451
464 virtual void GetSubLibraryNames( std::vector<wxString>& aNames ) {}
465
475 virtual void GetAvailableSymbolFields( std::vector<wxString>& aNames ) {}
476
489 virtual void GetDefaultSymbolFields( std::vector<wxString>& aNames )
490 {
491 return GetAvailableSymbolFields( aNames );
492 }
493
500 virtual bool CheckHeader( const wxString& aFileName );
501
510 virtual const wxString& GetError() const;
511
516 virtual void SetLibTable( SYMBOL_LIB_TABLE* aTable ) {}
517
518 //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
519
520
521 /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
522 automatically if you do not provide one. If you decide you need to
523 provide a zero argument constructor of your own design, that is allowed.
524 It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
525 passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
526 API functions which take one.
527 */
528 virtual ~SCH_PLUGIN() { }
529
530
536 {
538
539 // private assignment operator so it's illegal
541
542 // private copy constructor so it's illegal
544
545 public:
546 SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = nullptr ) :
547 plugin( aPlugin )
548 {
549 }
550
552 {
553 if( plugin )
554 release();
555 }
556
557 void release()
558 {
560 plugin = nullptr;
561 }
562
563 void set( SCH_PLUGIN* aPlugin )
564 {
565 if( plugin )
566 release();
567 plugin = aPlugin;
568 }
569
570 operator SCH_PLUGIN* () const
571 {
572 return plugin;
573 }
574
576 {
577 return plugin;
578 }
579 };
580};
581
582#endif // _SCH_IO_MGR_H_
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
Define a library symbol object.
Definition: lib_symbol.h:99
A progress reporter interface for use in multi-threaded environments.
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:72
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:105
static const wxString GetFileExtension(SCH_FILE_T aFileType)
Return the schematic file extension for aFileType.
Definition: sch_io_mgr.cpp:130
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:84
static const wxString GetLibraryFileExtension(SCH_FILE_T aFileType)
Return the symbol library file extension (if any) for aFileType.
Definition: sch_io_mgr.cpp:145
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:74
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:204
DEFINE_ENUM_VECTOR(SCH_FILE_T, { SCH_LEGACY, SCH_KICAD, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_EAGLE, SCH_DATABASE, SCH_LTSPICE, 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:160
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:536
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:563
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:543
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:540
SCH_PLUGIN * operator->() const
Definition: sch_io_mgr.h:575
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=nullptr)
Definition: sch_io_mgr.h:546
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:156
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:56
virtual int GetModifyHash() const =0
Return the modification hash from the library cache.
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:82
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:90
virtual void SaveLibrary(const wxString &aFileName, const STRING_UTF8_MAP *aProperties=nullptr)
Definition: sch_plugin.cpp:35
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:475
virtual const wxString GetLibraryFileExtension() const =0
Return the library file extension for the SCH_PLUGIN object.
virtual void SymbolLibOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:119
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:74
virtual bool SupportsSubLibraries() const
Definition: sch_io_mgr.h:450
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:516
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:138
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:98
virtual void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:48
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:41
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:105
virtual void GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
Definition: sch_io_mgr.h:464
virtual const wxString GetFileExtension() const =0
Return the file extension for the SCH_PLUGIN.
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition: sch_io_mgr.h:169
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:489
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition: sch_io_mgr.h:174
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:528
virtual bool CheckHeader(const wxString &aFileName)
Return true if the first line in aFileName begins with the expected header.
Definition: sch_plugin.cpp:131
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:112
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
A name/value tuple with unique names and optional values.
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