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 (C) 2021-2024 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_IO_ALTIUM_H_
26#define _SCH_IO_ALTIUM_H_
27
28#include <memory>
29#include <sch_sheet_path.h>
30#include <vector>
31#include <sch_io/sch_io.h>
32#include <sch_io/sch_io_mgr.h>
33#include <wx/filename.h>
34#include <wx/gdicmn.h>
35
36#include "altium_parser_sch.h"
37
38
39class SCH_SYMBOL;
40class SCH_SHEET;
41class TITLE_BLOCK;
42
44
52static std::vector<LIB_SYMBOL*> nullsym;
53static std::vector<int> nullint;
54
55
56class SCH_IO_ALTIUM : public SCH_IO
57{
58public:
61
63 {
64 return IO_BASE::IO_FILE_DESC( _HKI( "Altium schematic files" ), { "SchDoc" } );
65 }
66
68 {
69 return IO_BASE::IO_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 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
111
112 wxString getLibName();
113 wxFileName getLibFileName();
114
115 void ParseAltiumSch( const wxString& aFileName );
116 void ParseStorage( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
117 void ParseAdditional( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
118 void ParseFileHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
119
120 void ParseASCIISchematic( const wxString& aFileName );
121
122 void ParseRecord( int index, std::map<wxString, wxString>& properties,
123 const wxString& aSectionName );
124
125private:
128
129 bool ShouldPutItemOnSheet( int aOwnerindex );
130 bool IsComponentPartVisible( const ASCH_OWNER_INTERFACE& aElem ) const;
131 const ASCH_STORAGE_FILE* GetFileFromStorage( const wxString& aFilename ) const;
132 void AddTextBox( const ASCH_TEXT_FRAME* aElem );
133 void AddLibTextBox( const ASCH_TEXT_FRAME* aElem, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
134
135 void ParseComponent( int aIndex, const std::map<wxString, wxString>& aProperties );
136 void ParseTemplate( int aIndex, const std::map<wxString, wxString>& aProperties );
137 void ParsePin( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
138 void ParseLabel( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
139 void ParseTextFrame( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
140 void ParseNote( const std::map<wxString, wxString>& aProperties );
141 void ParseBezier( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
142 void ParsePolyline( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
143 void ParsePolygon( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
144 void ParseRoundRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
145 void ParseArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
146 void ParseEllipticalArc( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
147 void ParseEllipse( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
148 void ParseCircle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
149 void ParseLine( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
150 void ParseSignalHarness( const std::map<wxString, wxString>& aProperties );
151 void ParseHarnessConnector( int aIndex, const std::map<wxString, wxString>& aProperties );
152 void ParseHarnessEntry( const std::map<wxString, wxString>& aProperties );
153 void ParseHarnessType( const std::map<wxString, wxString>& aProperties );
154 void ParseHarnessPort( const ASCH_PORT& aElem );
155 void ParseHyperlink( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
156 void ParseRectangle( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym);
157 void ParseSheetSymbol( int aIndex, const std::map<wxString, wxString>& aProperties );
158 void ParseSheetEntry( const std::map<wxString, wxString>& aProperties );
159 void ParsePowerPort( const std::map<wxString, wxString>& aProperties );
160 void ParsePort( const ASCH_PORT& aElem );
161 void ParseNoERC( const std::map<wxString, wxString>& aProperties );
162 void ParseNetLabel( const std::map<wxString, wxString>& aProperties );
163 void ParseBus( const std::map<wxString, wxString>& aProperties );
164 void ParseWire( const std::map<wxString, wxString>& aProperties );
165 void ParseJunction( const std::map<wxString, wxString>& aProperties );
166 void ParseImage( const std::map<wxString, wxString>& aProperties );
167 void ParseSheet( const std::map<wxString, wxString>& aProperties );
168 void ParseSheetName( const std::map<wxString, wxString>& aProperties );
169 void ParseFileName( const std::map<wxString, wxString>& aProperties );
170 void ParseDesignator( const std::map<wxString, wxString>& aProperties );
171 void ParseLibDesignator( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
172 void ParseBusEntry( const std::map<wxString, wxString>& aProperties );
173 void ParseParameter( const std::map<wxString, wxString>& aProperties );
174 void ParseLibParameter( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym, std::vector<int>& aFontSize = nullint );
175 void ParseImplementationList( int aIndex, const std::map<wxString, wxString>& aProperties );
176 void ParseImplementation( const std::map<wxString, wxString>& aProperties, std::vector<LIB_SYMBOL*>& aSymbol = nullsym );
177
178 void ParseLibHeader( const ALTIUM_COMPOUND_FILE& aAltiumSchFile, std::vector<int>& aFontSizes );
179 std::map<wxString,LIB_SYMBOL*> ParseLibFile( const ALTIUM_COMPOUND_FILE& aAltiumSchFile );
180 std::vector<LIB_SYMBOL*> ParseLibComponent( const std::map<wxString, wxString>& aProperties );
181
182private:
183 SCH_SHEET* m_rootSheet; // The root sheet of the schematic being loaded..
185 SCHEMATIC* m_schematic; // Passed to Load(), the schematic object being loaded
186 wxString m_libName; // Library name to save symbols
187 bool m_isIntLib; // Flag to indicate Integrated Library
188
189 IO_RELEASER<SCH_IO> m_pi; // Plugin to create KiCad symbol library.
190 std::unique_ptr<STRING_UTF8_MAP> m_properties; // Library plugin properties.
191
192 std::unique_ptr<TITLE_BLOCK> m_currentTitleBlock; // Will be assigned at the end of parsing
193 // a sheet
194
196 std::unique_ptr<ASCH_SHEET> m_altiumSheet;
197 std::map<int, SCH_SYMBOL*> m_symbols;
198 std::map<int, SCH_SHEET*> m_sheets;
199 std::map<int, LIB_SYMBOL*> m_libSymbols; // every symbol has its unique lib_symbol
200
201 std::map<wxString, LIB_SYMBOL*> m_powerSymbols;
202 std::vector<ASCH_STORAGE_FILE> m_altiumStorage;
203 std::vector<ASCH_ADDITIONAL_FILE> m_altiumAdditional;
204
205 std::map<int, ASCH_SYMBOL> m_altiumComponents;
206 std::map<int, ASCH_TEMPLATE> m_altiumTemplates;
207 std::map<int, int> m_altiumImplementationList;
208 std::vector<ASCH_PORT> m_altiumPortsCurrentSheet; // we require all connections first
209
210 // parse harness ports after "FileHeader" was parsed, in 2nd run.
211 std::vector<ASCH_PORT> m_altiumHarnessPortsCurrentSheet;
212
213 // Add offset to all harness ownerIndex'es after parsing FileHeader.
215 int m_harnessEntryParent; // used to identify harness connector for harness entry element
216
217 // Symbol caching
218 void ensureLoadedLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties );
219 long long getLibraryTimestamp( const wxString& aLibraryPath ) const;
220
221 static bool isBinaryFile( const wxString& aFileName );
222 static bool isASCIIFile( const wxString& aFileName );
223 static bool checkFileHeader( const wxString& aFileName );
224
225 std::map<wxString, long long> m_timestamps;
226 std::map<wxString, std::map<wxString, LIB_SYMBOL*>> m_libCache;
227
228 // List of available fonts with font name and font size in pt
229 std::vector<std::pair<wxString, int>> m_fonts;
230};
231
232#endif // _SCH_IO_ALTIUM_H_
Define a library symbol object.
Definition: lib_symbol.h:77
Holds all the data relating to one schematic.
Definition: schematic.h:75
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)
bool IsComponentPartVisible(const ASCH_OWNER_INTERFACE &aElem) const
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.
Definition: sch_io_altium.h:67
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
std::map< int, SCH_SHEET * > m_sheets
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
Definition: sch_io_altium.h:62
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< int, int > m_altiumImplementationList
int m_harnessEntryParent
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 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.
VECTOR2I m_sheetOffset
void ParseRecord(int index, std::map< wxString, wxString > &properties, const wxString &aSectionName)
std::vector< ASCH_PORT > m_altiumHarnessPortsCurrentSheet
std::unique_ptr< STRING_UTF8_MAP > m_properties
void ParseDesignator(const std::map< wxString, wxString > &aProperties)
int m_harnessOwnerIndexOffset
std::map< wxString, LIB_SYMBOL * > ParseLibFile(const ALTIUM_COMPOUND_FILE &aAltiumSchFile)
static bool checkFileHeader(const wxString &aFileName)
long long getLibraryTimestamp(const wxString &aLibraryPath) const
std::map< wxString, std::map< wxString, LIB_SYMBOL * > > m_libCache
void ParseSheetEntry(const std::map< wxString, wxString > &aProperties)
IO_RELEASER< SCH_IO > m_pi
SCH_SHEET * m_rootSheet
static bool isBinaryFile(const wxString &aFileName)
void ParseHarnessType(const std::map< wxString, wxString > &aProperties)
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
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)
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)
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 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.
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_IO implementation knows about,...
void ParseEllipticalArc(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
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 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 ensureLoadedLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties)
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.
const ASCH_STORAGE_FILE * GetFileFromStorage(const wxString &aFilename) const
void ParseRectangle(const std::map< wxString, wxString > &aProperties, std::vector< LIB_SYMBOL * > &aSymbol=nullsym)
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)
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)
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
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:105
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)
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition: io_mgr.h:33
static std::vector< int > nullint
Definition: sch_io_altium.h:53
static std::vector< LIB_SYMBOL * > nullsym
SCH_IO_ALTIUM is a SCH_IO derivation for loading Altium .SchDoc schematic files.
Definition: sch_io_altium.h:52
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Container that describes file type info.
Definition: io_base.h:39