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 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.
115 };
116
120 enum class ORIENTATION
121 {
122 R0, // 0 degree rotation
123 R90, // 90 degree rotatioin.
124 R180, // 180 degree rotation.
125 R270, // 270 degree rotation.
126 M0, // 0 degree mirror
127 M90, // 90 degree mirror
128 M180, // 180 degree mirror
129 M270 // 270 degree mirror
130 };
131
132 struct LINE
133 {
138 };
139
140 struct LT_PIN
141 {
145 std::map<wxString, wxString> PinAttribute;
146 };
147
152 struct CIRCLE
153 {
158 };
159
161 {
166 };
167
172 struct ARC
173 {
180 };
181
186 {
191 };
192
196 struct WIRE
197 {
200 };
201
202 struct FLAG
203 {
206 wxString Value;
207 };
208
209 struct DATAFLAG
210 {
213 wxString Expression;
214 };
215
216 struct TEXT
217 {
221 wxString Value;
222 };
223
227 struct IOPIN
228 {
231 };
232
233 struct BUSTAP
234 {
237 };
238
243 {
244 wxString Name;
247 std::map<wxString, wxString> SymAttributes;
248 std::vector<LT_PIN> Pins;
249 std::vector<LINE> Lines;
250 std::vector<CIRCLE> Circles;
251 std::vector<LT_WINDOW> Windows;
252 std::vector<ARC> Arcs;
253 std::vector<RECTANGLE> Rectangles;
254 std::vector<WIRE> Wires;
256 };
257
261 struct LT_ASC
262 {
267 std::vector<LT_SYMBOL> Symbols;
268 std::vector<LINE> Lines;
269 std::vector<CIRCLE> Circles;
270 std::vector<LT_WINDOW> Windows;
271 std::vector<ARC> Arcs;
272 std::vector<RECTANGLE> Rectangles;
273 std::vector<WIRE> Wires;
274 std::vector<FLAG> Flags;
275 std::vector<DATAFLAG> DataFlags;
276 std::vector<IOPIN> Iopins;
277 std::vector<BUSTAP> Bustap;
278 std::vector<TEXT> Texts;
280 };
281
282 explicit LTSPICE_SCHEMATIC( const wxString& aFilename, const wxFileName& aLTspiceDataDir,
283 REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) :
284 m_reporter( aReporter ),
285 m_schematic( nullptr ),
286 m_ltspiceDataDir( aLTspiceDataDir ),
287 m_progressReporter( aProgressReporter )
288 {}
289
291
299 void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName,
300 REPORTER* aReporter );
301
308 void GetAscAndAsyFilePaths( const wxDir& aDir, bool aRecursive,
309 std::map<wxString, wxString>& aMapOfAscFiles,
310 std::map<wxString, wxString>& aMapOfAsyFiles,
311 const std::vector<wxString>& aBaseDirs = {} );
312
320 std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile );
321
327 bool IsAsySubsheet( const wxString& aAsyFile );
328
337 std::map<wxString, wxString> ReadAsyFiles( const std::vector<LTSPICE_FILE>& aSourceFiles,
338 const std::map<wxString, wxString>& aAsyFileMap );
339
340 std::map<wxString, wxString> ReadAsyFile( const LTSPICE_FILE& aSourceFile,
341 const std::map<wxString, wxString>& aAsyFileMap );
342
347 std::vector<LT_ASC> StructureBuilder();
348
349 LT_SYMBOL SymbolBuilder( const wxString& aAscFileName, LT_ASC& aAscFile );
350
351 LT_SYMBOL SymbolBuilder( const wxString& aAscFileName, const wxString& aAsyFileContent,
352 LT_ASC& aAscFile );
353
354 LT_SYMBOL MakeDummySymbol( const wxString& aAscFileName );
355
356 const wxFileName& GetLTspiceDataDir() { return m_ltspiceDataDir; }
357
358private:
365 static void aggregateAttributeValue( wxArrayString& aTokens, int aIndex );
366
376 static int integerCheck( const wxString& aToken, int aLineNumber, const wxString& aFileName );
377
378 static VECTOR2I pointCheck( const wxString& aTokenX, const wxString& aTokenY, int aLineNumber,
379 const wxString& aFileName );
390 static void tokensSizeRangeCheck( size_t aActualSize, int aExpectedMin, int aExpectedMax,
391 int aLineNumber, const wxString& aFileName );
392
393 static void removeCarriageReturn( wxString& elementFromLine );
394
399 static LINESTYLE getLineStyle( int aValue );
400
405 static LINEWIDTH getLineWidth( const wxString& aValue );
406
411 static POLARITY getPolarity( const wxString& aValue );
412
417 static ORIENTATION getSymbolRotationOrMirror( const wxString& aValue );
418
423 static JUSTIFICATION getTextJustification( const wxString& aValue );
424
429 static JUSTIFICATION getPinJustification( const wxString& aValue );
430
435 static SYMBOLTYPE getSymbolType( const wxString& aValue );
436
437private:
441 PROGRESS_REPORTER* m_progressReporter; // optional; may be nullptr
442
443 std::map<wxString, std::map<wxString, wxString>> m_fileCache;
444};
445
446#endif // LTSPICE_SCHEMATIC_LOADER_H
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)
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.
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 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.
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:73
Holds all the data relating to one schematic.
Definition: schematic.h:69
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:47
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.