KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_mgr.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Wayne Stambaugh <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef _SCH_IO_MGR_H_
24#define _SCH_IO_MGR_H_
25
26#include <import_export.h>
27#include <map>
28#include <enum_vector.h>
29#include <reporter.h>
30#include <i18n_utility.h>
31#include <plugin_file_desc.h>
32#include <wx/arrstr.h>
33
34
35class SCH_SHEET;
36class SCH_SCREEN;
37class SCH_PLUGIN;
38class SCHEMATIC;
40class KIWAY;
41class LIB_SYMBOL;
42class SYMBOL_LIB;
43class STRING_UTF8_MAP;
45
46
51{
52public:
53
58 // clang-format off
59 DEFINE_ENUM_VECTOR( SCH_FILE_T,
60 {
61 SCH_KICAD,
62 SCH_LEGACY,
63 SCH_ALTIUM,
64 SCH_CADSTAR_ARCHIVE,
65 SCH_DATABASE,
66 SCH_EAGLE,
67 SCH_EASYEDA,
68 SCH_EASYEDAPRO,
69 SCH_LTSPICE,
70 SCH_HTTP,
71
72 // Add your schematic type here.
73 SCH_FILE_UNKNOWN
74 } )
75 // clang-format on
76
91 static SCH_PLUGIN* FindPlugin( SCH_FILE_T aFileType );
92
99 static void ReleasePlugin( SCH_PLUGIN* aPlugin );
100
104 static const wxString ShowType( SCH_FILE_T aFileType );
105
109 static SCH_FILE_T EnumFromStr( const wxString& aFileType );
110
114 static SCH_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl = 0 );
115
119 static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath, int aCtl = 0 );
120};
121
122
145{
146public:
147
148 //-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
149
153 virtual const wxString GetName() const = 0;
154
158 virtual void SetReporter( REPORTER* aReporter ) {}
159
163 virtual void SetProgressReporter( PROGRESS_REPORTER* aReporter ) {}
164
168 virtual const PLUGIN_FILE_DESC GetSchematicFileDesc() const;
169
173 virtual const PLUGIN_FILE_DESC GetLibraryFileDesc() const;
174
179 virtual bool CanReadSchematicFile( const wxString& aFileName ) const;
180
185 virtual bool CanReadLibrary( const wxString& aFileName ) const;
186
196 virtual int GetModifyHash() const = 0;
197
198 virtual void SaveLibrary( const wxString& aFileName, const STRING_UTF8_MAP* aProperties = nullptr );
199
228 virtual SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
229 SCH_SHEET* aAppendToMe = nullptr,
230 const STRING_UTF8_MAP* aProperties = nullptr );
231
257 virtual void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
258 SCHEMATIC* aSchematic,
259 const STRING_UTF8_MAP* aProperties = nullptr );
260
277 virtual void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
278 const STRING_UTF8_MAP* aProperties = nullptr );
279
299 virtual void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
300 const wxString& aLibraryPath,
301 const STRING_UTF8_MAP* aProperties = nullptr );
302
324 virtual LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aPartName,
325 const STRING_UTF8_MAP* aProperties = nullptr );
326
348 virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
349 const STRING_UTF8_MAP* aProperties = nullptr );
350
369 virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
370 const STRING_UTF8_MAP* aProperties = nullptr );
371
387 virtual void CreateSymbolLib( const wxString& aLibraryPath,
388 const STRING_UTF8_MAP* aProperties = nullptr );
389
409 virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
410 const STRING_UTF8_MAP* aProperties = nullptr );
411
421 virtual bool IsSymbolLibWritable( const wxString& aLibraryPath );
422
447 virtual void SymbolLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const;
448
452 virtual bool SupportsSubLibraries() const { return false; }
453
466 virtual void GetSubLibraryNames( std::vector<wxString>& aNames ) {}
467
477 virtual void GetAvailableSymbolFields( std::vector<wxString>& aNames ) {}
478
491 virtual void GetDefaultSymbolFields( std::vector<wxString>& aNames )
492 {
493 return GetAvailableSymbolFields( aNames );
494 }
495
504 virtual const wxString& GetError() const;
505
510 virtual void SetLibTable( SYMBOL_LIB_TABLE* aTable ) {}
511
512 //-----</PUBLIC SCH_PLUGIN API>------------------------------------------------
513
514
515 /* The compiler writes the "zero argument" constructor for a SCH_PLUGIN
516 automatically if you do not provide one. If you decide you need to
517 provide a zero argument constructor of your own design, that is allowed.
518 It must be public, and it is what the SCH_IO_MGR uses. Parameters may be
519 passed into a SCH_PLUGIN via the PROPERTIES variable for any of the public
520 API functions which take one.
521 */
522 virtual ~SCH_PLUGIN() { }
523
524
530 {
532
533 // private assignment operator so it's illegal
535
536 // private copy constructor so it's illegal
538
539 public:
540 SCH_PLUGIN_RELEASER( SCH_PLUGIN* aPlugin = nullptr ) :
541 plugin( aPlugin )
542 {
543 }
544
546 {
547 if( plugin )
548 release();
549 }
550
551 void release()
552 {
554 plugin = nullptr;
555 }
556
557 void set( SCH_PLUGIN* aPlugin )
558 {
559 if( plugin )
560 release();
561 plugin = aPlugin;
562 }
563
564 operator SCH_PLUGIN* () const
565 {
566 return plugin;
567 }
568
570 {
571 return plugin;
572 }
573 };
574
575 protected:
576 static bool fileStartsWithPrefix( const wxString& aFilePath, const wxString& aPrefix,
577 bool aIgnoreWhitespace );
578
579 static bool fileStartsWithBinaryHeader( const wxString& aFilePath,
580 const std::vector<uint8_t>& aHeader );
581};
582
583#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:75
A factory which returns an instance of a SCH_PLUGIN.
Definition: sch_io_mgr.h:51
DEFINE_ENUM_VECTOR(SCH_FILE_T, { SCH_KICAD, SCH_LEGACY, SCH_ALTIUM, SCH_CADSTAR_ARCHIVE, SCH_DATABASE, SCH_EAGLE, SCH_EASYEDA, SCH_EASYEDAPRO, SCH_LTSPICE, SCH_HTTP, 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 EnumFromStr(const wxString &aFileType)
Return the #SCH_FILE_T from the corresponding plugin type name: "kicad", "legacy",...
Definition: sch_io_mgr.cpp:116
static const wxString ShowType(SCH_FILE_T aFileType)
Return a brief name for a plugin, given aFileType enum.
Definition: sch_io_mgr.cpp:92
static SCH_FILE_T GuessPluginTypeFromSchPath(const wxString &aSchematicPath, int aCtl=0)
Return a plugin type given a schematic using the file extension of aSchematicPath.
Definition: sch_io_mgr.cpp:174
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:82
static SCH_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a symbol library using the file extension of aLibPath.
Definition: sch_io_mgr.cpp:149
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:530
void set(SCH_PLUGIN *aPlugin)
Definition: sch_io_mgr.h:557
SCH_PLUGIN_RELEASER(const SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:537
SCH_PLUGIN_RELEASER & operator=(SCH_PLUGIN_RELEASER &aOther)
Definition: sch_io_mgr.h:534
SCH_PLUGIN * operator->() const
Definition: sch_io_mgr.h:569
SCH_PLUGIN_RELEASER(SCH_PLUGIN *aPlugin=nullptr)
Definition: sch_io_mgr.h:540
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
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:141
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:167
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:175
virtual void SaveLibrary(const wxString &aFileName, const STRING_UTF8_MAP *aProperties=nullptr)
Definition: sch_plugin.cpp:120
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:477
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified schematic file.
Definition: sch_plugin.cpp:53
virtual void SymbolLibOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:204
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:159
virtual bool SupportsSubLibraries() const
Definition: sch_io_mgr.h:452
virtual void SetLibTable(SYMBOL_LIB_TABLE *aTable)
Some library plugins need to have access to their parent library table.
Definition: sch_io_mgr.h:510
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:216
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:183
virtual SCH_SHEET * LoadSchematicFile(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:126
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified symbol library file.
Definition: sch_plugin.cpp:69
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:190
virtual void GetSubLibraryNames(std::vector< wxString > &aNames)
Retrieves a list of sub-libraries in this library.
Definition: sch_io_mgr.h:466
virtual void SaveSchematicFile(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:133
virtual const PLUGIN_FILE_DESC GetSchematicFileDesc() const
Returns schematic file description for the SCH_PLUGIN.
Definition: sch_plugin.cpp:41
virtual void SetReporter(REPORTER *aReporter)
Set an optional reporter for warnings/errors.
Definition: sch_io_mgr.h:158
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:491
static bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Definition: sch_plugin.cpp:223
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition: sch_io_mgr.h:163
virtual ~SCH_PLUGIN()
Definition: sch_io_mgr.h:522
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:197
virtual const PLUGIN_FILE_DESC GetLibraryFileDesc() const
Returns symbol library description for the SCH_PLUGIN.
Definition: sch_plugin.cpp:47
static bool fileStartsWithBinaryHeader(const wxString &aFilePath, const std::vector< uint8_t > &aHeader)
Definition: sch_plugin.cpp:248
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.
Some functions to handle hotkeys in KiCad.
#define APIEXPORT
Macros which export functions from a DLL/DSO.
Definition: import_export.h:42
Container that describes file type info.