KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ltspice_schematic.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) 2022 Chetan Subhash Shinde<[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#ifndef LTSPICE_SCHEMATIC_LOADER_H
23#define LTSPICE_SCHEMATIC_LOADER_H
24
25#include <sch_io/sch_io_mgr.h>
26#include <sch_sheet_path.h>
27#include <pin_type.h>
28#include <layer_ids.h>
29#include <math/box2.h>
30#include <wx/filename.h>
31#include <wx/dir.h>
32#include <set>
33
34
36{
37 wxString ElementName;
40
41 LTSPICE_FILE( const wxString& aElementName, const VECTOR2I& aOffset, int aSourceLine ) :
42 ElementName( aElementName.Lower() ),
43 Offset( aOffset ),
44 SourceLine( aSourceLine )
45 { }
46
47 bool operator<( const LTSPICE_FILE& t ) const
48 {
49 return ElementName < t.ElementName;
50 }
51};
52
53
55{
56public:
57 enum class LINESTYLE
58 {
59 SOLID = 0,
60 DASH = 1,
61 DOT = 2,
64 };
65
66 enum class LINEWIDTH
67 {
68 Normal = 5,
69 Wide = 10
70 };
71
75 enum class POLARITY
76 {
77 PIN_INPUT, // IN POLARITY
78 OUTPUT, // OUT POLARITY
79 BIDIR // BI-DIRECTIONAL POLARITY
80 };
81
88 enum class SYMBOLTYPE
89 {
92 };
93
97 enum class JUSTIFICATION
98 {
105 VBOTTOM, // Vertical Bottom Justification
106 VLEFT, // Vertical Left Justification
107 VRIGHT, // Vertical Right Justification
108 VCENTER, // Vertical Center Justification
109 VTOP, // Vertical Top Justification.
111 };
112
116 enum class ORIENTATION
117 {
118 R0, // 0 degree rotation
119 R90, // 90 degree rotatioin.
120 R180, // 180 degree rotation.
121 R270, // 270 degree rotation.
122 M0, // 0 degree mirror
123 M90, // 90 degree mirror
124 M180, // 180 degree mirror
125 M270 // 270 degree mirror
126 };
127
135
136 struct LT_PIN
137 {
141 std::map<wxString, wxString> PinAttribute;
142 };
143
155
163
177
188
192 struct WIRE
193 {
196 };
197
198 struct FLAG
199 {
202 wxString Value;
203 };
204
205 struct DATAFLAG
206 {
209 wxString Expression;
210 };
211
219
228
229 struct BUSTAP
230 {
233 };
234
239 {
240 wxString Name;
241 wxString AsyKey;
244 std::map<wxString, wxString> SymAttributes;
245 std::vector<LT_PIN> Pins;
246 std::vector<LINE> Lines;
247 std::vector<CIRCLE> Circles;
248 std::vector<LT_WINDOW> Windows;
249 std::vector<ARC> Arcs;
250 std::vector<RECTANGLE> Rectangles;
251 std::vector<TEXT> Texts;
253 };
254
258 struct LT_ASC
259 {
264 std::vector<LT_SYMBOL> Symbols;
265 std::vector<LINE> Lines;
266 std::vector<CIRCLE> Circles;
267 std::vector<LT_WINDOW> Windows;
268 std::vector<ARC> Arcs;
269 std::vector<RECTANGLE> Rectangles;
270 std::vector<WIRE> Wires;
271 std::vector<FLAG> Flags;
272 std::vector<DATAFLAG> DataFlags;
273 std::vector<IOPIN> Iopins;
274 std::vector<BUSTAP> Bustap;
275 std::vector<TEXT> Texts;
277 };
278
279 explicit LTSPICE_SCHEMATIC( const wxString& aFilename, const wxFileName& aLTspiceDataDir,
280 REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) :
281 m_reporter( aReporter ),
282 m_ltspiceDataDir( aLTspiceDataDir )
283 {}
284
286
295 void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName,
296 REPORTER* aReporter );
297
301 wxString GetSchematicFileName( const wxString& aAscKey ) const;
302
306 wxString GetSymbolName( const wxString& aSymbolName ) const;
307
317 void GetAscAndAsyFilePaths( const wxDir& aDir, bool aRecursive,
318 std::map<wxString, wxString>& aMapOfAscFiles,
319 std::map<wxString, wxString>& aMapOfAsyFiles,
320 const std::vector<wxString>& aBaseDirs = {} );
321
327 std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile );
328
334 bool IsAsySubsheet( const wxString& aAsyFile );
335
344 std::map<wxString, wxString> ReadAsyFiles( const std::vector<LTSPICE_FILE>& aSourceFiles,
345 const std::map<wxString, wxString>& aAsyFileMap );
346
353 std::map<wxString, LT_ASC> ParseAscFiles( const std::map<wxString, wxString>& aAscFilesContent );
354
355 LT_SYMBOL ParseSymbol( const wxString& aSymbolName, const wxString& aAsyFileContent, LT_ASC& aAscFile );
356
357 LT_SYMBOL MakeDummySymbol( const wxString& aAscFileName );
358
359 const wxFileName& GetLTspiceDataDir() { return m_ltspiceDataDir; }
360
361private:
368 static void aggregateAttributeValue( wxArrayString& aTokens, int aIndex );
369
379 static int integerCheck( const wxString& aToken, int aLineNumber, const wxString& aFileName );
380
381 static VECTOR2I pointCheck( const wxString& aTokenX, const wxString& aTokenY, int aLineNumber,
382 const wxString& aFileName );
393 static void tokensSizeRangeCheck( size_t aActualSize, int aExpectedMin, int aExpectedMax,
394 int aLineNumber, const wxString& aFileName );
395
396 static void removeCarriageReturn( wxString& elementFromLine );
397
402 static LINESTYLE getLineStyle( int aValue );
403
408 static LINEWIDTH getLineWidth( const wxString& aValue );
409
414 static POLARITY getPolarity( const wxString& aValue );
415
420 static ORIENTATION getSymbolRotationOrMirror( const wxString& aValue );
421
426 static JUSTIFICATION getTextJustification( const wxString& aValue );
427
432 static JUSTIFICATION getPinJustification( const wxString& aValue );
433
438 static SYMBOLTYPE getSymbolType( const wxString& aValue );
439
440private:
442 std::set<wxString> m_missingSymbols;
444
445 std::map<wxString, wxString> m_ascFileCache;
446 std::map<wxString, wxString> m_asyFileCache;
447
448 std::map<wxString, wxString> m_ascNamesMap;
449 std::map<wxString, wxString> m_asyNamesMap;
450};
451
452#endif // LTSPICE_SCHEMATIC_LOADER_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
static VECTOR2I pointCheck(const wxString &aTokenX, const wxString &aTokenY, int aLineNumber, const wxString &aFileName)
LT_SYMBOL MakeDummySymbol(const wxString &aAscFileName)
static SYMBOLTYPE getSymbolType(const wxString &aValue)
LT_SYMBOL ParseSymbol(const wxString &aSymbolName, const wxString &aAsyFileContent, LT_ASC &aAscFile)
std::map< wxString, wxString > m_ascNamesMap
std::map< wxString, LT_ASC > ParseAscFiles(const std::map< wxString, wxString > &aAscFilesContent)
Build Intermediate data structure.
std::vector< LTSPICE_FILE > GetSchematicElements(const wxString &aAscFile)
Used to get symbols list present in asc file.
POLARITY
Polarity enum represents polarity of pin.
wxString GetSchematicFileName(const wxString &aAscKey) const
Return "amp.kicad_sch" for "foo/amp" when both keys are one .asc, else "foo_amp.kicad_sch".
const wxFileName & GetLTspiceDataDir()
wxString GetSymbolName(const wxString &aSymbolName) const
Return "amp" for "foo/amp" when both keys are one .asy, else "foo_amp".
JUSTIFICATION
Defines in what ways the PIN or TEXT can be justified.
static ORIENTATION getSymbolRotationOrMirror(const wxString &aValue)
bool IsAsySubsheet(const wxString &aAsyFile)
Check if the asy file content indicates that we need to load subsheet.
std::map< wxString, wxString > m_asyNamesMap
static POLARITY getPolarity(const wxString &aValue)
static void tokensSizeRangeCheck(size_t aActualSize, int aExpectedMin, int aExpectedMax, int aLineNumber, const wxString &aFileName)
Used to check size of the token generated from split function.
std::map< wxString, wxString > m_asyFileCache
static LINEWIDTH getLineWidth(const wxString &aValue)
ORIENTATION
Defines different types or rotation and mirror operation can be applied to a LT_SYMBOL.
static void aggregateAttributeValue(wxArrayString &aTokens, int aIndex)
Join value present across multiple tokens into one.
void GetAscAndAsyFilePaths(const wxDir &aDir, bool aRecursive, std::map< wxString, wxString > &aMapOfAscFiles, std::map< wxString, wxString > &aMapOfAsyFiles, const std::vector< wxString > &aBaseDirs={})
Used to get file path for Asc and Asy files.
void Load(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxFileName &aLibraryFileName, REPORTER *aReporter)
The main function responsible for loading the .asc and .asy files.
static int integerCheck(const wxString &aToken, int aLineNumber, const wxString &aFileName)
Used to check if the given token in integer or not.
std::set< wxString > m_missingSymbols
LTSPICE_SCHEMATIC(const wxString &aFilename, const wxFileName &aLTspiceDataDir, REPORTER *aReporter, PROGRESS_REPORTER *aProgressReporter)
static JUSTIFICATION getTextJustification(const wxString &aValue)
static JUSTIFICATION getPinJustification(const wxString &aValue)
SYMBOLTYPE
Type of Symbol loaded from asc and asy file.
std::map< wxString, wxString > m_ascFileCache
std::map< wxString, wxString > ReadAsyFiles(const std::vector< LTSPICE_FILE > &aSourceFiles, const std::map< wxString, wxString > &aAsyFileMap)
The function returns a map.
static void removeCarriageReturn(wxString &elementFromLine)
static LINESTYLE getLineStyle(int aValue)
A progress reporter interface for use in multi-threaded environments.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Holds all the data relating to one schematic.
Definition schematic.h:155
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
LTSPICE_FILE(const wxString &aElementName, const VECTOR2I &aOffset, int aSourceLine)
bool operator<(const LTSPICE_FILE &t) const
The ARC is represented inside a rectangle whose opposite site are given.
The CIRCLE is represented in Ltpsice inside a rectangle whose two opposite points and line style are ...
IOPIN is special contact on symbol used for IO operations.
A struct to hold .asc file definition.
std::vector< CIRCLE > Circles
std::vector< IOPIN > Iopins
std::vector< BUSTAP > Bustap
std::vector< LT_SYMBOL > Symbols
std::vector< DATAFLAG > DataFlags
std::vector< LT_WINDOW > Windows
std::vector< RECTANGLE > Rectangles
std::map< wxString, wxString > PinAttribute
A struct to hold SYMBOL definition.
std::map< wxString, wxString > SymAttributes
std::vector< RECTANGLE > Rectangles
std::vector< LT_WINDOW > Windows
std::vector< CIRCLE > Circles
A 4-sided polygon with opposite equal sides, used in representing shapes.
A metallic connection, used for transfer, between two points or pin.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708