KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_altium_plugin.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) 2020 Thomas Pointhuber <[email protected]>
5 * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef _SCH_ALTIUM_PLUGIN_H_
26#define _SCH_ALTIUM_PLUGIN_H_
27
28#include <memory>
29#include <vector>
30#include <sch_io_mgr.h>
31#include <wx/filename.h>
32#include <wx/gdicmn.h>
33
34#include "altium_parser_sch.h"
35
36
37class SCH_SYMBOL;
38class SCH_SHEET;
39class TITLE_BLOCK;
40
42
50static std::vector<LIB_SYMBOL*> nullsym;
51static std::vector<int> nullint;
53{
54public:
57
58 const wxString GetName() const override;
59
60 void SetReporter( REPORTER* aReporter ) override { m_reporter = aReporter; }
61
63 {
64 return PLUGIN_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
65 }
66
67 const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
68 {
69 return PLUGIN_FILE_DESC( _HKI( "Altium Schematic Library or Integrated Library" ),
70 { "SchLib", "IntLib" } );
71 }
72
73 bool CanReadSchematicFile( const wxString& aFileName ) const override;
74 bool CanReadLibrary( const wxString& aFileName ) const override;
75
76 int GetModifyHash() const override;
77
78 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
79 SCH_SHEET* aAppendToMe = nullptr,
80 const STRING_UTF8_MAP* aProperties = nullptr ) override;
81
82 // unimplemented functions. Will trigger a not_implemented IO error.
83 //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
84
85 //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
86 // const PROPERTIES* aProperties = NULL ) override;
87
88
89 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
90 const wxString& aLibraryPath,
91 const STRING_UTF8_MAP* aProperties = nullptr ) override;
92
93 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
94 const wxString& aLibraryPath,
95 const STRING_UTF8_MAP* aProperties = nullptr ) override;
96
97 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath,
98 const wxString& aAliasName,
99 const STRING_UTF8_MAP* aProperties = nullptr ) override;
100
101 //void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
102 // const PROPERTIES* aProperties = NULL ) override;
103
104 //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
105 // const PROPERTIES* aProperties = NULL ) override;
106
107 //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
108 // const PROPERTIES* aProperties = NULL ) override;
109
110 //void CreateSymbolLib( const wxString& aLibraryPath,
111 // const PROPERTIES* aProperties = NULL ) override;
112
113 // bool DeleteSymbolLib( const wxString& aLibraryPath,
114 // const PROPERTIES* aProperties = NULL ) override;
115
116 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override
117 {
118 return false;
119 }
120
121 //void SymbolLibOptions( PROPERTIES* aListToAppendTo ) const override;
122
123 wxString getLibName();
124 wxFileName getLibFileName();
125
126 void ParseAltiumSch( const wxString& aFileName );
127 void ParseStorage( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
128 void ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
129 void ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
130
131private:
134
135 bool IsComponentPartVisible( int aOwnerindex, int aOwnerpartdisplaymode ) const;
136 const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
137 void AddTextBox( const ASCH_TEXT_FRAME* aElem );
138 void AddLibTextBox( const ASCH_TEXT_FRAME* aElem, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
139
140 void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
141 void ParsePin( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
142 void ParseLabel( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
143 void ParseTextFrame( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
144 void ParseNote( const std::map<wxString, wxString>& aProperties );
145 void ParseBezier( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
146 void ParsePolyline( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
147 void ParsePolygon( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
148 void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
149 void ParseArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
150 void ParseEllipticalArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
151 void ParseEllipse( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
152 void ParseCircle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
153 void ParseLine( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
154 void ParseSignalHarness( const std::map<wxString, wxString>& aProperties );
155 void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
156 void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
157 void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
158 void ParseHarnessPort( const ASCH_PORT& aElem );
159 void ParseHyperlink( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
160 void ParseRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
161 void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
162 void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
163 void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
164 void ParsePort( const ASCH_PORT& aElem );
165 void ParseNoERC( const std::map<wxString, wxString>& aProperties );
166 void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
167 void ParseBus( const std::map<wxString, wxString>& aProperties );
168 void ParseWire( const std::map<wxString, wxString>& aProperties );
169 void ParseJunction( const std::map<wxString, wxString>& aProperties );
170 void ParseImage( const std::map<wxString, wxString>& aProperties );
171 void ParseSheet( const std::map<wxString, wxString>& aProperties );
172 void ParseSheetName( const std::map<wxString, wxString>& aProperties );
173 void ParseFileName( const std::map<wxString, wxString>& aProperties );
174 void ParseDesignator( const std::map<wxString, wxString>& aProperties );
175 void ParseLibDesignator( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
176 void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
177 void ParseParameter( const std::map<wxString, wxString>& aProperties );
178 void ParseLibParameter( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
179 void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
180 void ParseImplementation( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym );
181
182 void ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile, std::vector<int>& aFontSizes );
183 std::map<wxString,LIB_SYMBOL*> ParseLibFile( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
184 std::vector<LIB_SYMBOL*> ParseLibComponent( const std::map<wxString, wxString>& aProperties );
185
186private:
187 REPORTER* m_reporter; // current reporter for warnings/errors
188
189 SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
191 SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
192 wxString m_libName; // Library name to save symbols
193 bool m_isIntLib; // Flag to indicate Integrated Library
194
195 SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi; // Plugin to create KiCad symbol library.
196 std::unique_ptr<STRING_UTF8_MAP> m_properties; // Library plugin properties.
197
198 std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
199 // a sheet
200
202 std::unique_ptr<ASCH_SHEET> m_altiumSheet;
203 std::map<int, SCH_SYMBOL*> m_symbols;
204 std::map<int, SCH_SHEET*> m_sheets;
205 std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
206
207 std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
208 std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
209 std::vector<ASCH_ADDITIONAL_FILE> m_altiumAdditional;
210
211 std::map<int, ASCH_SYMBOL> m_altiumComponents;
212 std::map<int, int> m_altiumImplementationList;
213 std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
214
215 // parse harness ports after "FileHeader" was parsed, in 2nd run.
216 std::vector<ASCH_PORT> m_altiumHarnessPortsCurrentSheet;
217
218 // Add offset to all harness ownerIndex'es after parsing FileHeader.
220 int m_harnessEntryParent; // used to identify harness connector for harness entry element
221
222 // Symbol caching
223 void ensureLoadedLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties );
224 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
225
226 static bool checkFileHeader( const wxString& aFileName );
227
228 std::map<wxString, long long> m_timestamps;
229 std::map<wxString, std::map<wxString, LIB_SYMBOL*>> m_libCache;
230
231 // List of available fonts with font name and font size in pt
232 std::vector<std::pair<wxString, int>> m_fonts;
233};
234
235#endif // _SCH_ALTIUM_PLUGIN_H_
Define a library symbol object.
Definition: lib_symbol.h:99
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
void ParseEllipse(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseLibHeader(const ALTIUM_COMPOUND_FILE &aAltiumSchFile, std::vector< int > &aFontSizes)
std::unique_ptr< ASCH_SHEET > m_altiumSheet
void ParseImplementationList(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParsePolygon(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::vector< ASCH_PORT > m_altiumHarnessPortsCurrentSheet
void ParseLabel(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
void ParseCircle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseArc(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseStorage(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
std::map< int, int > m_altiumImplementationList
void AddTextBox(const ASCH_TEXT_FRAME *aElem)
void ParseSheetEntry(const std::map< wxString, wxString > &aProperties)
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
void ParsePolyline(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
int GetModifyHash() const override
Return the modification hash from the library cache.
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
void ParseComponent(int aIndex, const std::map< wxString, wxString > &aProperties)
std::map< wxString, LIB_SYMBOL * > m_powerSymbols
void AddLibTextBox(const ASCH_TEXT_FRAME *aElem, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
wxFileName getLibFileName()
void ParseImage(const std::map< wxString, wxString > &aProperties)
void ParseNetLabel(const std::map< wxString, wxString > &aProperties)
void ParseBusEntry(const std::map< wxString, wxString > &aProperties)
void ParsePin(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseLibDesignator(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void ParseSheetName(const std::map< wxString, wxString > &aProperties)
void ParseBus(const std::map< wxString, wxString > &aProperties)
void ParseAdditional(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
void ParseDesignator(const std::map< wxString, wxString > &aProperties)
void ParseSheetSymbol(int aIndex, const std::map< wxString, wxString > &aProperties)
std::vector< LIB_SYMBOL * > ParseLibComponent(const std::map< wxString, wxString > &aProperties)
bool IsComponentPartVisible(int aOwnerindex, int aOwnerpartdisplaymode) const
void ParseAltiumSch(const wxString &aFileName)
void ParsePort(const ASCH_PORT &aElem)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void ParsePowerPort(const std::map< wxString, wxString > &aProperties)
std::unique_ptr< STRING_UTF8_MAP > m_properties
void SetReporter(REPORTER *aReporter) override
Set an optional reporter for warnings/errors.
void ParseWire(const std::map< wxString, wxString > &aProperties)
SCH_SCREEN * getCurrentScreen()
std::vector< ASCH_STORAGE_FILE > m_altiumStorage
std::map< int, LIB_SYMBOL * > m_libSymbols
void ParseSignalHarness(const std::map< wxString, wxString > &aProperties)
void ParseLibParameter(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
std::unique_ptr< TITLE_BLOCK > m_currentTitleBlock
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_PLUGIN.
long long getLibraryTimestamp(const wxString &aLibraryPath) const
SCH_SHEET_PATH m_sheetPath
void ensureLoadedLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties)
void ParseHarnessType(const std::map< wxString, wxString > &aProperties)
const ASCH_STORAGE_FILE * GetFileFromStorage(const wxString &aFilename) const
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
Returns symbol library description for the SCH_PLUGIN.
void ParseLine(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseHyperlink(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
SCH_SHEET * getCurrentSheet()
std::vector< std::pair< wxString, int > > m_fonts
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified symbol library file.
void ParseParameter(const std::map< wxString, wxString > &aProperties)
std::vector< ASCH_ADDITIONAL_FILE > m_altiumAdditional
SCH_PLUGIN::SCH_PLUGIN_RELEASER m_pi
void ParseEllipticalArc(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseHarnessConnector(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseRectangle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseTextFrame(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
std::vector< ASCH_PORT > m_altiumPortsCurrentSheet
void ParseSheet(const std::map< wxString, wxString > &aProperties)
void ParseImplementation(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified schematic file.
void ParseJunction(const std::map< wxString, wxString > &aProperties)
void ParseFileHeader(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
void ParseNoERC(const std::map< wxString, wxString > &aProperties)
std::map< wxString, std::map< wxString, LIB_SYMBOL * > > m_libCache
std::map< wxString, long long > m_timestamps
void ParseRoundRectangle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::map< int, ASCH_SYMBOL > m_altiumComponents
void ParseNote(const std::map< wxString, wxString > &aProperties)
static bool checkFileHeader(const wxString &aFileName)
std::map< int, SCH_SYMBOL * > m_symbols
std::map< wxString, LIB_SYMBOL * > ParseLibFile(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
void ParseBezier(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseHarnessPort(const ASCH_PORT &aElem)
void ParseFileName(const std::map< wxString, wxString > &aProperties)
std::map< int, SCH_SHEET * > m_sheets
void ParseHarnessEntry(const std::map< wxString, wxString > &aProperties)
Helper object to release a SCH_PLUGIN in the context of a potential thrown exception through its dest...
Definition: sch_io_mgr.h:530
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Schematic symbol object.
Definition: sch_symbol.h:81
A name/value tuple with unique names and optional values.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
#define _HKI(x)
static std::vector< int > nullint
static std::vector< LIB_SYMBOL * > nullsym
SCH_ALTIUM_PLUGIN is a SCH_PLUGIN derivation for loading Altium .SchDoc schematic files.
Container that describes file type info.