KiCad PCB EDA Suite
Go to the documentation of this file.
1 #ifndef _SCH_SEXPR_PLUGIN_H_
2 #define _SCH_SEXPR_PLUGIN_H_
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2020 CERN
8  *
9  * @author Wayne Stambaugh <>
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program. If not, see <>.
23  */
25 #include <memory>
26 #include <sch_io_mgr.h>
27 #include <sch_file_versions.h>
28 #include <stack>
31 class KIWAY;
32 class LINE_READER;
33 class SCH_SCREEN;
34 class SCH_SHEET;
35 class SCH_BITMAP;
36 class SCH_JUNCTION;
37 class SCH_NO_CONNECT;
38 class SCH_LINE;
40 class SCH_TEXT;
42 class SCH_FIELD;
43 class PROPERTIES;
44 class EE_SELECTION;
46 class LIB_PART;
47 class PART_LIB;
48 class BUS_ALIAS;
57 {
58 public:
61  virtual ~SCH_SEXPR_PLUGIN();
63  const wxString GetName() const override
64  {
65  return wxT( "Eeschema s-expression" );
66  }
68  const wxString GetFileExtension() const override
69  {
70  return wxT( "kicad_sch" );
71  }
73  const wxString GetLibraryFileExtension() const override
74  {
75  return wxT( "kicad_sym" );
76  }
83  static const char* PropBuffering;
85  int GetModifyHash() const override;
87  SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
88  SCH_SHEET* aAppendToMe = nullptr,
89  const PROPERTIES* aProperties = nullptr ) override;
91  void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet,
94  void Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
95  const PROPERTIES* aProperties = nullptr ) override;
97  void Format( SCH_SHEET* aSheet );
99  void Format( EE_SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
101  void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
102  const wxString& aLibraryPath,
103  const PROPERTIES* aProperties = nullptr ) override;
104  void EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
105  const wxString& aLibraryPath,
106  const PROPERTIES* aProperties = nullptr ) override;
107  LIB_PART* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
108  const PROPERTIES* aProperties = nullptr ) override;
109  void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
110  const PROPERTIES* aProperties = nullptr ) override;
111  void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
112  const PROPERTIES* aProperties = nullptr ) override;
113  void CreateSymbolLib( const wxString& aLibraryPath,
114  const PROPERTIES* aProperties = nullptr ) override;
115  bool DeleteSymbolLib( const wxString& aLibraryPath,
116  const PROPERTIES* aProperties = nullptr ) override;
117  void SaveLibrary( const wxString& aLibraryPath,
118  const PROPERTIES* aProperties = nullptr ) override;
120  bool CheckHeader( const wxString& aFileName ) override;
121  bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
123  const wxString& GetError() const override { return m_error; }
125  static LIB_PART* ParsePart( LINE_READER& aReader,
127  static void FormatPart( LIB_PART* aPart, OUTPUTFORMATTER& aFormatter );
129 private:
130  void loadHierarchy( SCH_SHEET* aSheet );
131  void loadFile( const wxString& aFileName, SCH_SHEET* aSheet );
133  void saveSymbol( SCH_COMPONENT* aComponent, int aNestLevel );
134  void saveField( SCH_FIELD* aField, int aNestLevel );
135  void saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel );
136  void saveSheet( SCH_SHEET* aSheet, int aNestLevel );
137  void saveJunction( SCH_JUNCTION* aJunction, int aNestLevel );
138  void saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel );
139  void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLevel );
140  void saveLine( SCH_LINE* aLine, int aNestLevel );
141  void saveText( SCH_TEXT* aText, int aNestLevel );
142  void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel );
144  void cacheLib( const wxString& aLibraryFileName );
145  bool isBuffering( const PROPERTIES* aProperties );
147 protected:
148  int m_version;
149  int m_fieldId;
152  wxString m_error;
154  wxString m_path;
155  std::stack<wxString> m_currentPath;
163  void init( SCHEMATIC* aSchematic, const PROPERTIES* aProperties = nullptr );
164 };
166 #endif // _SCH_SEXPR_PLUGIN_H_
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
int m_version
Version of file being loaded.
LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived to re...
Definition: richio.h:81
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void Format(SCH_SHEET *aSheet)
static LIB_PART * ParsePart(LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:42
wxString m_error
For throwing exceptions or errors on partial schematic loads.
int m_fieldId
Non-mandatory schematic field ID counter.
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const PROPERTIES *aProperties=nullptr) override
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
const wxString GetFileExtension() const override
Returns the file extension for the SCH_PLUGIN.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
void saveText(SCH_TEXT *aText, int aNestLevel)
OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a convenient ...
Definition: richio.h:327
void saveField(SCH_FIELD *aField, int aNestLevel)
static void FormatPart(LIB_PART *aPart, OUTPUTFORMATTER &aFormatter)
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
void saveSymbol(SCH_COMPONENT *aComponent, int aNestLevel)
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:43
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_SEXPR_PLUG...
LIB_PART * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
Load a LIB_PART object having aPartName from the aLibraryPath containing a library format that this S...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:151
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void SaveLibrary(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Define a library symbol object.
void cacheLib(const wxString &aLibraryFileName)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
bool isBuffering(const PROPERTIES *aProperties)
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
The output formatter for saving SCH_SCREEN objects.
const wxString GetName() const override
Returns a brief hard coded name for this SCH_PLUGIN.
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
const wxString GetLibraryFileExtension() const override
Return the library file extension for the SCH_PLUGIN object.
wxString m_path
Root project path for loading child sheets.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
Schematic symbol object.
Definition: sch_component.h:88
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
const wxString & GetError() const override
Return an error string to the caller.
void loadHierarchy(SCH_SHEET *aSheet)
void init(SCHEMATIC *aSchematic, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
Symbol library file version.
int GetModifyHash() const override
Return the modification hash from the library cache.
Object used to load, save, search, and otherwise manipulate symbol library files.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Delete an existing symbol library and returns true if successful, or if library does not exist return...
void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.