KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_altium.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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef _SCH_IO_ALTIUM_H_
22#define _SCH_IO_ALTIUM_H_
23
24#include <memory>
25#include <sch_sheet_path.h>
26#include <vector>
27#include <sch_io/sch_io.h>
28#include <sch_io/sch_io_mgr.h>
29#include <wx/filename.h>
30#include <wx/gdicmn.h>
32
33#include "altium_parser_sch.h"
34
35class SYMBOL;
36class SCH_SYMBOL;
37class SCH_SHEET;
38class TITLE_BLOCK;
39
41
48
49static std::vector<LIB_SYMBOL*> nullsym;
50static std::vector<int> nullint;
51
69
70
71class SCH_IO_ALTIUM : public SCH_IO
72{
73public:
76
78 {
79 return IO_BASE::IO_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
80 }
81
83 {
84 return IO_BASE::IO_FILE_DESC( _HKI( "Altium Schematic Library or Integrated Library" ),
85 { "SchLib", "IntLib" } );
86 }
87
88 bool CanReadSchematicFile( const wxString& aFileName ) const override;
89 bool CanReadLibrary( const wxString& aFileName ) const override;
90
91 int GetModifyHash() const override;
92
93 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
94 SCH_SHEET* aAppendToMe = nullptr,
95 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
96
98 const std::map<std::string, UTF8>* aProperties );
99
100 // unimplemented functions. Will trigger a not_implemented IO error.
101 //void SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties = NULL ) override;
102
103 //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
104 // const PROPERTIES* aProperties = NULL ) override;
105
106
107 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
108 const wxString& aLibraryPath,
109 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
110
111 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
112 const wxString& aLibraryPath,
113 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
114
115 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath,
116 const wxString& aAliasName,
117 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
118
119 //void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
120 // const PROPERTIES* aProperties = NULL ) override;
121
122 //void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
123 // const PROPERTIES* aProperties = NULL ) override;
124
125 //void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
126 // const PROPERTIES* aProperties = NULL ) override;
127
128 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
129
130 wxString getLibName();
131 wxFileName getLibFileName();
132
133 void ParseAltiumSch( const wxString& aFileName );
134 void ParseStorage( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
135 void ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
136 void ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
137
138 void ParseASCIISchematic( const wxString& aFileName );
139
140 void ParseRecord( int index, std::map<wxString, wxString>& properties,
141 const wxString& aSectionName );
142
143private:
146
147 bool ShouldPutItemOnSheet( int aOwnerindex );
148 const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
149 void CreateAliases();
150 void AddTextBox( const ASCH_TEXT_FRAME* aElem );
151 void AddLibTextBox( const ASCH_TEXT_FRAME* aElem, std::vector<LIB_SYMBOL*>& aSymbol = nullsym,
152 std::vector<int>& aFontSize = nullint );
153
154 void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
155 void ParseTemplate( int aIndex, const std::map<wxString, wxString>& aProperties );
156 void ParsePin( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
157 void ParseLabel( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym,
158 std::vector<int>& aFontSize = nullint );
159 void ParseTextFrame( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym,
160 std::vector<int>& aFontSize = nullint );
161 void ParseNote( const std::map<wxString, wxString>& aProperties );
162 void ParseBezier( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
163 void ParsePolyline( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
164 void ParsePolygon( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
165 void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
166 void ParseArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
167 void ParseEllipticalArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
168 void ParseEllipse( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
169 void ParseCircle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
170 void ParseLine( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
171 void ParseSignalHarness( const std::map<wxString, wxString>& aProperties );
172 void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
173 void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
174 void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
175 void ParseHarnessPort( const ASCH_PORT& aElem );
176 void ParseHyperlink( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
177 void ParsePieChart( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
178 void ParseRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
179 void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
180 void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
181 void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
182 void ParsePort( const ASCH_PORT& aElem );
183 void ParsePortHelper( const ASCH_PORT& aElem );
184 void ParseNoERC( const std::map<wxString, wxString>& aProperties );
185 void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
186 void ParseBus( const std::map<wxString, wxString>& aProperties );
187 void ParseWire( const std::map<wxString, wxString>& aProperties );
188 void ParseJunction( const std::map<wxString, wxString>& aProperties );
189 void ParseImage( const std::map<wxString, wxString>& aProperties );
190 void ParseSheet( const std::map<wxString, wxString>& aProperties );
191 void ParseSheetName( const std::map<wxString, wxString>& aProperties );
192 void ParseFileName( const std::map<wxString, wxString>& aProperties );
193 void ParseDesignator( const std::map<wxString, wxString>& aProperties );
194 void ParseLibDesignator( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
195 void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
196 void ParseParameter( const std::map<wxString, wxString>& aProperties );
197 void ParseLibParameter( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
198 void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
199 void ParseImplementation( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym );
200
201 void ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile, std::vector<int>& aFontSizes );
203 std::vector<LIB_SYMBOL*> ParseLibComponent( const std::map<wxString, wxString>& aProperties );
204
205 void doEnumerateSymbolLib( const wxString& aLibraryPath, const std::map<std::string, UTF8>* aProperties,
206 std::function<void(const wxString&, LIB_SYMBOL*)> aInserter );
207
208 void fixupSymbolPinNameNumbers( SYMBOL* aSymbol );
209
210 // Symbol caching
211 void ensureLoadedLibrary( const wxString& aLibraryPath, const std::map<std::string, UTF8>* aProperties );
212 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
213
214 static bool isBinaryFile( const wxString& aFileName );
215 static bool isASCIIFile( const wxString& aFileName );
216 static bool checkFileHeader( const wxString& aFileName );
217
218private:
219 wxString m_rootFilepath; // The file path of the root sheet being imported
220 SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
222 SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
223 wxString m_libName; // Library name to save symbols
224 bool m_isIntLib; // Flag to indicate Integrated Library
225
226 std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
227 // a sheet
228
230 std::unique_ptr<ASCH_SHEET> m_altiumSheet;
231 std::map<int, SCH_SYMBOL*> m_symbols;
232 std::map<int, SCH_SHEET*> m_sheets;
233 std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
234
235 std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
236 std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
237 std::vector<ASCH_ADDITIONAL_FILE> m_altiumAdditional;
238
239 std::map<int, ASCH_SYMBOL> m_altiumComponents;
240 std::map<int, ASCH_TEMPLATE> m_altiumTemplates;
241 std::map<int, int> m_altiumImplementationList;
242 std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
243
244 // parse harness ports after "FileHeader" was parsed, in 2nd run.
245 std::vector<ASCH_PORT> m_altiumHarnessPortsCurrentSheet;
246 std::map<int, HARNESS> m_altiumHarnesses;
247
248 // Add offset to all harness ownerIndex'es after parsing FileHeader.
250 int m_harnessEntryParent; // used to identify harness connector for harness entry element
251
252 std::map<wxString, long long> m_timestamps;
253 std::map<wxString, CASE_INSENSITIVE_MAP<LIB_SYMBOL*>> m_libCache;
254
255 // List of available fonts with font name and font size in pt
256 std::vector<std::pair<wxString, int>> m_fonts;
257
258 // Persists across sheets so variant application can match by Altium UniqueId
259 std::map<const SCH_SYMBOL*, wxString> m_altiumSymbolToUid;
260
261 // Cache the error messages to avoid duplicate messages
262 std::unordered_map<wxString, SEVERITY > m_errorMessages;
263};
264
265#endif // _SCH_IO_ALTIUM_H_
int index
ASCH_SHEET_ENTRY_SIDE
std::map< wxString, ValueType, DETAIL::CASE_INSENSITIVE_COMPARER > CASE_INSENSITIVE_MAP
Define a library symbol object.
Definition lib_symbol.h:79
Holds all the data relating to one schematic.
Definition schematic.h:90
void ParseFileHeader(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
void ParseHyperlink(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseSignalHarness(const std::map< wxString, wxString > &aProperties)
std::map< int, ASCH_TEMPLATE > m_altiumTemplates
std::map< int, ASCH_SYMBOL > m_altiumComponents
void ParsePort(const ASCH_PORT &aElem)
void ParseNote(const std::map< wxString, wxString > &aProperties)
void ParseAltiumSch(const wxString &aFileName)
std::vector< ASCH_PORT > m_altiumPortsCurrentSheet
void ParseSheetName(const std::map< wxString, wxString > &aProperties)
void ParseBusEntry(const std::map< wxString, wxString > &aProperties)
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
SCH_SHEET * getCurrentSheet()
void ParseStorage(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
std::map< wxString, LIB_SYMBOL * > m_powerSymbols
void ParseBus(const std::map< wxString, wxString > &aProperties)
void ParseFileName(const std::map< wxString, wxString > &aProperties)
static bool isASCIIFile(const wxString &aFileName)
wxString m_libName
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::map< int, SCH_SHEET * > m_sheets
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
void ParseLibHeader(const ALTIUM_COMPOUND_FILE &aAltiumSchFile, std::vector< int > &aFontSizes)
void ParseHarnessPort(const ASCH_PORT &aElem)
void ParseRoundRectangle(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 ParseLibDesignator(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
std::map< wxString, CASE_INSENSITIVE_MAP< LIB_SYMBOL * > > m_libCache
std::map< int, int > m_altiumImplementationList
void ParseTextFrame(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
void ParsePolygon(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void fixupSymbolPinNameNumbers(SYMBOL *aSymbol)
VECTOR2I m_sheetOffset
void ParseRecord(int index, std::map< wxString, wxString > &properties, const wxString &aSectionName)
std::vector< ASCH_PORT > m_altiumHarnessPortsCurrentSheet
void ParseDesignator(const std::map< wxString, wxString > &aProperties)
int m_harnessOwnerIndexOffset
void ParsePortHelper(const ASCH_PORT &aElem)
static bool checkFileHeader(const wxString &aFileName)
long long getLibraryTimestamp(const wxString &aLibraryPath) const
void ParseSheetEntry(const std::map< wxString, wxString > &aProperties)
SCH_SHEET * m_rootSheet
static bool isBinaryFile(const wxString &aFileName)
void ParseHarnessType(const std::map< wxString, wxString > &aProperties)
wxString m_rootFilepath
void ParseJunction(const std::map< wxString, wxString > &aProperties)
SCHEMATIC * m_schematic
void ParseLibParameter(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
void ParseASCIISchematic(const wxString &aFileName)
void ParsePolyline(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::unique_ptr< ASCH_SHEET > m_altiumSheet
void ParseComponent(int aIndex, const std::map< wxString, wxString > &aProperties)
std::unique_ptr< TITLE_BLOCK > m_currentTitleBlock
SCH_SHEET * LoadSchematicProject(SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties)
void ParseImage(const std::map< wxString, wxString > &aProperties)
void ParseArc(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseNetLabel(const std::map< wxString, wxString > &aProperties)
void ParseNoERC(const std::map< wxString, wxString > &aProperties)
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
std::unordered_map< wxString, SEVERITY > m_errorMessages
void ParseImplementationList(int aIndex, const std::map< wxString, wxString > &aProperties)
std::vector< LIB_SYMBOL * > ParseLibComponent(const std::map< wxString, wxString > &aProperties)
void ParseSheet(const std::map< wxString, wxString > &aProperties)
void ParseParameter(const std::map< wxString, wxString > &aProperties)
bool ShouldPutItemOnSheet(int aOwnerindex)
void AddLibTextBox(const ASCH_TEXT_FRAME *aElem, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
void ParsePieChart(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseEllipticalArc(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::map< int, HARNESS > m_altiumHarnesses
void ParseEllipse(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseWire(const std::map< wxString, wxString > &aProperties)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void ParseHarnessEntry(const std::map< wxString, wxString > &aProperties)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
void ParseImplementation(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseTemplate(int aIndex, const std::map< wxString, wxString > &aProperties)
void ParseAdditional(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
std::vector< ASCH_ADDITIONAL_FILE > m_altiumAdditional
void AddTextBox(const ASCH_TEXT_FRAME *aElem)
void ParsePowerPort(const std::map< wxString, wxString > &aProperties)
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
std::map< const SCH_SYMBOL *, wxString > m_altiumSymbolToUid
const ASCH_STORAGE_FILE * GetFileFromStorage(const wxString &aFilename) const
void ParseRectangle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void doEnumerateSymbolLib(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties, std::function< void(const wxString &, LIB_SYMBOL *)> aInserter)
wxString getLibName()
std::vector< ASCH_STORAGE_FILE > m_altiumStorage
SCH_SHEET_PATH m_sheetPath
void ParseLabel(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym, std::vector< int > &aFontSize=nullint)
CASE_INSENSITIVE_MAP< LIB_SYMBOL * > ParseLibFile(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
void ParseBezier(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseLine(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
void ParseCircle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::map< int, SCH_SYMBOL * > m_symbols
void ParseSheetSymbol(int aIndex, const std::map< wxString, wxString > &aProperties)
std::vector< std::pair< wxString, int > > m_fonts
std::map< wxString, long long > m_timestamps
wxFileName getLibFileName()
SCH_SCREEN * getCurrentScreen()
void ParsePin(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
std::map< int, LIB_SYMBOL * > m_libSymbols
void ParseHarnessConnector(int aIndex, const std::map< wxString, wxString > &aProperties)
void ensureLoadedLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties)
SCH_IO(const wxString &aName)
Definition sch_io.h:375
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:44
Schematic symbol object.
Definition sch_symbol.h:69
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:59
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:37
#define _HKI(x)
Definition page_info.cpp:40
static std::vector< int > nullint
static std::vector< LIB_SYMBOL * > nullsym
SCH_IO_ALTIUM is a SCH_IO derivation for loading Altium .SchDoc schematic files.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
ASCH_SHEET_ENTRY_SIDE m_harnessConnectorSide
VECTOR2I m_location
std::vector< HARNESS_PORT > m_ports
HARNESS_PORT m_entry
wxString m_name
VECTOR2I m_size
Container that describes file type info.
Definition io_base.h:43
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683