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 (C) 2022-2023 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 along
19 * with this program. If not, see <http://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
33
35{
36 wxString ElementName;
42
43 LTSPICE_FILE( const wxString& aElementName, const VECTOR2I& aOffset ) :
44 ElementName( aElementName.Lower() ),
45 Offset( aOffset ),
46 ParentIndex( 0 ),
47 Sheet( nullptr ),
48 Screen( nullptr )
49 { }
50
51 bool operator<( const LTSPICE_FILE& t ) const
52 {
53 return ElementName < t.ElementName;
54 }
55};
56
57
59{
60public:
61 enum class LINESTYLE
62 {
63 SOLID = 0,
64 DASH = 1,
65 DOT = 2,
66 DASHDOT = 3,
67 DASHDOTDOT = 4
68 };
69
70 enum class LINEWIDTH
71 {
72 Normal = 5,
73 Wide = 10
74 };
75
79 enum class POLARITY
80 {
81 INPUT, // IN POLARITY
82 OUTPUT, // OUT POLARITY
83 BIDIR // BI-DIRECTIONAL POLARITY
84 };
85
92 enum class SYMBOLTYPE
93 {
94 CELL,
95 BLOCK
96 };
97
101 enum class JUSTIFICATION
102 {
103 NONE,
104 BOTTOM,
105 LEFT,
106 RIGHT,
107 CENTER,
108 TOP,
109 VBOTTOM, // Vertical Bottom Justification
110 VLEFT, // Vertical Left Justification
111 VRIGHT, // Vertical Right Justification
112 VCENTER, // Vertical Center Justification
113 VTOP // Vertical Top Justification.
114 };
115
119 enum class ORIENTATION
120 {
121 R0, // 0 degree rotation
122 R90, // 90 degree rotatioin.
123 R180, // 180 degree rotation.
124 R270, // 270 degree rotation.
125 M0, // 0 degree mirror
126 M90, // 90 degree mirror
127 M180, // 180 degree mirror
128 M270 // 270 degree mirror
129 };
130
131 struct LINE
132 {
137 };
138
139 struct LT_PIN
140 {
144 std::map<wxString, wxString> PinAttribute;
145 };
146
151 struct CIRCLE
152 {
157 };
158
160 {
165 };
166
171 struct ARC
172 {
179 };
180
185 {
190 };
191
195 struct WIRE
196 {
199 };
200
201 struct FLAG
202 {
205 wxString Value;
206 };
207
208 struct DATAFLAG
209 {
212 wxString Expression;
213 };
214
215 struct TEXT
216 {
220 wxString Value;
221 };
222
226 struct IOPIN
227 {
230 };
231
232 struct BUSTAP
233 {
236 };
237
242 {
243 wxString Name;
246 std::map<wxString, wxString> SymAttributes;
247 std::vector<LT_PIN> Pins;
248 std::vector<LINE> Lines;
249 std::vector<CIRCLE> Circles;
250 std::vector<LT_WINDOW> Windows;
251 std::vector<ARC> Arcs;
252 std::vector<RECTANGLE> Rectangles;
253 std::vector<WIRE> Wires;
255 };
256
260 struct LT_ASC
261 {
265 std::vector<LT_SYMBOL> Symbols;
266 std::vector<LINE> Lines;
267 std::vector<CIRCLE> Circles;
268 std::vector<LT_WINDOW> Windows;
269 std::vector<ARC> Arcs;
270 std::vector<RECTANGLE> Rectangles;
271 std::vector<WIRE> Wires;
272 std::vector<FLAG> Flags;
273 std::vector<DATAFLAG> DataFlags;
274 std::vector<IOPIN> Iopins;
275 std::vector<BUSTAP> Bustap;
276 std::vector<TEXT> Texts;
278 };
279
280 explicit LTSPICE_SCHEMATIC( const wxString& aFilename, const wxFileName& aLTspiceDataDir,
281 REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) :
282 m_reporter( aReporter ),
283 m_schematic( nullptr ),
284 m_ltspiceDataDir( aLTspiceDataDir ),
285 m_progressReporter( aProgressReporter )
286 {}
287
289
297 void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName,
298 REPORTER* aReporter );
299
306 void GetAscAndAsyFilePaths( const wxDir& aDir, bool aRecursive,
307 std::map<wxString, wxString>& aMapOfAscFiles,
308 std::map<wxString, wxString>& aMapOfAsyFiles,
309 const wxString& aBase = wxEmptyString );
310
318 std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile );
319
325 bool IsAsySubsheet( const wxString& aAsyFile );
326
335 std::map<wxString, wxString> ReadAsyFiles( const std::vector<LTSPICE_FILE>& aSourceFiles,
336 const std::map<wxString, wxString>& aAsyFileMap );
337
338 std::map<wxString, wxString> ReadAsyFile( const LTSPICE_FILE& aSourceFile,
339 const std::map<wxString, wxString>& aAsyFileMap );
340
345 std::vector<LT_ASC> StructureBuilder();
346
347 LT_SYMBOL SymbolBuilder( const wxString& aAscFileName, LT_ASC& aAscFile );
348
349 LT_SYMBOL SymbolBuilder( const wxString& aAscFileName, const wxString& aAsyFileContent,
350 LT_ASC& aAscFile );
351
352 const wxFileName& GetLTspiceDataDir() { return m_ltspiceDataDir; }
353
354private:
361 static void aggregateAttributeValue( wxArrayString& aTokens, int aIndex );
362
372 static int integerCheck( const wxString& aToken, int aLineNumber, const wxString& aFileName );
373
374 static VECTOR2I pointCheck( const wxString& aTokenX, const wxString& aTokenY, int aLineNumber,
375 const wxString& aFileName );
386 static void tokensSizeRangeCheck( size_t aActualSize, int aExpectedMin, int aExpectedMax,
387 int aLineNumber, const wxString& aFileName );
388
389 static void removeCarriageReturn( wxString& elementFromLine );
390
395 static LINESTYLE getLineStyle( int aValue );
396
401 static LINEWIDTH getLineWidth( const wxString& aValue );
402
407 static POLARITY getPolarity( const wxString& aValue );
408
413 static ORIENTATION getSymbolRotationOrMirror( const wxString& aValue );
414
419 static JUSTIFICATION getTextJustification( const wxString& aValue );
420
425 static JUSTIFICATION getPinJustification( const wxString& aValue );
426
431 static SYMBOLTYPE getSymbolType( const wxString& aValue );
432
433private:
437 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
438
439 std::map<wxString, std::map<wxString, wxString>> m_fileCache;
440};
441
442#endif // LTSPICE_SCHEMATIC_LOADER_H
static VECTOR2I pointCheck(const wxString &aTokenX, const wxString &aTokenY, int aLineNumber, const wxString &aFileName)
static SYMBOLTYPE getSymbolType(const wxString &aValue)
std::vector< LT_ASC > StructureBuilder()
Build Intermediate data structure.
std::vector< LTSPICE_FILE > GetSchematicElements(const wxString &aAscFile)
Used to get symbols list present in asc file.
LT_SYMBOL SymbolBuilder(const wxString &aAscFileName, LT_ASC &aAscFile)
POLARITY
Polarity enum represents polarity of pin.
const wxFileName & GetLTspiceDataDir()
JUSTIFICATION
Defines in what ways the PIN or TEXT can be justified.
void GetAscAndAsyFilePaths(const wxDir &aDir, bool aRecursive, std::map< wxString, wxString > &aMapOfAscFiles, std::map< wxString, wxString > &aMapOfAsyFiles, const wxString &aBase=wxEmptyString)
Used to get file path for Asc and Asy files.
static ORIENTATION getSymbolRotationOrMirror(const wxString &aValue)
bool IsAsySubsheet(const wxString &aAsyFile)
Check if the asy file content indicates that we need to load subsheet.
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.
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.
PROGRESS_REPORTER * m_progressReporter
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.
wxFileName m_ltspiceDataDir
std::map< wxString, std::map< wxString, wxString > > m_fileCache
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)
std::map< wxString, wxString > ReadAsyFile(const LTSPICE_FILE &aSourceFile, const std::map< wxString, wxString > &aAsyFileMap)
SYMBOLTYPE
Type of Symbol loaded from asc and asy file.
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:71
Holds all the data relating to one schematic.
Definition: schematic.h:75
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
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SCH_SCREEN * Screen
LTSPICE_FILE(const wxString &aElementName, const VECTOR2I &aOffset)
SCH_SHEET * Sheet
bool operator<(const LTSPICE_FILE &t) const
SCH_SHEET_PATH SheetPath
wxString ElementName
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< TEXT > Texts
std::vector< DATAFLAG > DataFlags
std::vector< LINE > Lines
std::vector< LT_WINDOW > Windows
std::vector< WIRE > Wires
std::vector< RECTANGLE > Rectangles
std::vector< FLAG > Flags
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< LT_PIN > Pins
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.