KiCad PCB EDA Suite
sch_legacy_plugin.h
Go to the documentation of this file.
1 #ifndef _SCH_LEGACY_PLUGIN_H_
2 #define _SCH_LEGACY_PLUGIN_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-2019 KiCad Developers, see change_log.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 2
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 <memory>
27 #include <sch_io_mgr.h>
28 #include <stack>
29 #include <general.h>
30 
31 
32 class KIWAY;
33 class LINE_READER;
34 class SCH_SCREEN;
35 class SCH_SHEET;
36 class SCH_BITMAP;
37 class SCH_JUNCTION;
38 class SCH_NO_CONNECT;
39 class SCH_LINE;
40 class SCH_BUS_ENTRY_BASE;
41 class SCH_TEXT;
42 class SCH_COMPONENT;
43 class SCH_FIELD;
44 class PROPERTIES;
45 class SELECTION;
47 class LIB_PART;
48 class PART_LIB;
49 class LIB_ALIAS;
50 class BUS_ALIAS;
51 
52 
65 {
66 public:
67 
69  virtual ~SCH_LEGACY_PLUGIN();
70 
71  const wxString GetName() const override
72  {
73  return wxT( "Eeschema-Legacy" );
74  }
75 
76  const wxString GetFileExtension() const override
77  {
78  return wxT( "sch" );
79  }
80 
88  static const char* PropBuffering;
89 
96  static const char* PropNoDocFile;
97 
98  int GetModifyHash() const override;
99 
100  SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
101  SCH_SHEET* aAppendToMe = nullptr,
102  const PROPERTIES* aProperties = nullptr ) override;
103 
104  void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
105  int version = EESCHEMA_VERSION );
106 
107  void Save( const wxString& aFileName, SCH_SCREEN* aScreen, KIWAY* aKiway,
108  const PROPERTIES* aProperties = nullptr ) override;
109 
110  void Format( SCH_SCREEN* aScreen );
111 
112  void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
113 
114  void EnumerateSymbolLib( wxArrayString& aAliasNameList,
115  const wxString& aLibraryPath,
116  const PROPERTIES* aProperties = nullptr ) override;
117  void EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
118  const wxString& aLibraryPath,
119  const PROPERTIES* aProperties = nullptr ) override;
120  LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
121  const PROPERTIES* aProperties = nullptr ) override;
122  void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
123  const PROPERTIES* aProperties = nullptr ) override;
124  void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
125  const PROPERTIES* aProperties = nullptr ) override;
126  void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
127  const PROPERTIES* aProperties = nullptr ) override;
128  void CreateSymbolLib( const wxString& aLibraryPath,
129  const PROPERTIES* aProperties = nullptr ) override;
130  bool DeleteSymbolLib( const wxString& aLibraryPath,
131  const PROPERTIES* aProperties = nullptr ) override;
132  void SaveLibrary( const wxString& aLibraryPath,
133  const PROPERTIES* aProperties = nullptr ) override;
134 
135  bool CheckHeader( const wxString& aFileName ) override;
136  bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
137 
138  const wxString& GetError() const override { return m_error; }
139 
140  static LIB_PART* ParsePart( LINE_READER& aReader, int majorVersion = 0, int minorVersion = 0 );
141  static void FormatPart( LIB_PART* aPart, OUTPUTFORMATTER& aFormatter );
142 
143 private:
144  void loadHierarchy( SCH_SHEET* aSheet );
145  void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
146  void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
147  void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
148  SCH_SHEET* loadSheet( LINE_READER& aReader );
149  SCH_BITMAP* loadBitmap( LINE_READER& aReader );
152  SCH_LINE* loadWire( LINE_READER& aReader );
154  SCH_TEXT* loadText( LINE_READER& aReader );
156  std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
157 
158  void saveComponent( SCH_COMPONENT* aComponent );
159  void saveField( SCH_FIELD* aField );
160  void saveBitmap( SCH_BITMAP* aBitmap );
161  void saveSheet( SCH_SHEET* aSheet );
162  void saveJunction( SCH_JUNCTION* aJunction );
163  void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
164  void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
165  void saveLine( SCH_LINE* aLine );
166  void saveText( SCH_TEXT* aText );
167  void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
168 
169  void cacheLib( const wxString& aLibraryFileName );
170  bool writeDocFile( const PROPERTIES* aProperties );
171  bool isBuffering( const PROPERTIES* aProperties );
172 
173 protected:
174  int m_version;
175 
177  wxString m_error;
178 
179  wxString m_path;
180  std::stack<wxString> m_currentPath;
186 
188  void init( KIWAY* aKiway, const PROPERTIES* aProperties = nullptr );
189 };
190 
191 #endif // _SCH_LEGACY_PLUGIN_H_
SCH_SHEET * loadSheet(LINE_READER &aReader)
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
void init(KIWAY *aKiway, const PROPERTIES *aProperties=nullptr)
initialize PLUGIN like a constructor would.
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
Part library alias object definition.
void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void saveLine(SCH_LINE *aLine)
SCH_COMPONENT * loadComponent(LINE_READER &aReader)
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded..
void Format(SCH_SCREEN *aScreen)
void saveText(SCH_TEXT *aText)
Class OUTPUTFORMATTER is an important interface (abstract class) used to output 8 bit text in a conve...
Definition: richio.h:327
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
static LIB_PART * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
void saveSheet(SCH_SHEET *aSheet)
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
const wxString GetName() const override
Returns a brief hard coded name for this SCH_PLUGIN.
void EnumerateSymbolLib(wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
const wxString & GetError() const override
Return an error string to the caller.
A cache assistant for the part library portion of the SCH_PLUGIN API, and only for the SCH_LEGACY_PLU...
void saveField(SCH_FIELD *aField)
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
const wxString GetFileExtension() const override
Returns the file extension for the SCH_PLUGIN.
void saveJunction(SCH_JUNCTION *aJunction)
int m_version
Version of file being loaded.
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
wxString m_path
Root project path for loading child sheets.
#define EESCHEMA_VERSION
Definition: general.h:42
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:188
bool isBuffering(const PROPERTIES *aProperties)
void loadHierarchy(SCH_SHEET *aSheet)
LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Define a library symbol object.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
void saveBitmap(SCH_BITMAP *aBitmap)
static const char * PropNoDocFile
const char* PropBuffering
static void FormatPart(LIB_PART *aPart, OUTPUTFORMATTER &aFormatter)
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
void saveComponent(SCH_COMPONENT *aComponent)
void SaveLibrary(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
A SCH_PLUGIN derivation for loading schematic files created before the new s-expression file format.
void DeleteAlias(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
Delete aAliasName from the library at aLibraryPath.
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
OUTPUTFORMATTER * m_out
The output formatter for saving SCH_SCREEN objects.
void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void Save(const wxString &aFileName, SCH_SCREEN *aScreen, KIWAY *aKiway, const PROPERTIES *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
static const char * PropBuffering
const char* PropBuffering
void cacheLib(const wxString &aLibraryFileName)
int GetModifyHash() const override
Return the modification hash from the library cache.
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_LINE * loadWire(LINE_READER &aReader)
KIWAY * m_kiway
Required for path to legacy component libraries.
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=nullptr) override
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
SCH_TEXT * loadText(LINE_READER &aReader)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
Object used to load, save, search, and otherwise manipulate symbol library files.
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
bool writeDocFile(const PROPERTIES *aProperties)
const PROPERTIES * m_props
Passed via Save() or Load(), no ownership, may be nullptr.
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
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...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.