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
33
35{
36 wxString ElementName;
39
40 LTSPICE_FILE( const wxString& aElementName, const VECTOR2I& aOffset, int aSourceLine ) :
41 ElementName( aElementName.Lower() ),
42 Offset( aOffset ),
43 SourceLine( aSourceLine )
44 { }
45
46 bool operator<( const LTSPICE_FILE& t ) const
47 {
48 return ElementName < t.ElementName;
49 }
50};
51
52
54{
55public:
56 enum class LINESTYLE
57 {
58 SOLID = 0,
59 DASH = 1,
60 DOT = 2,
63 };
64
65 enum class LINEWIDTH
66 {
67 Normal = 5,
68 Wide = 10
69 };
70
74 enum class POLARITY
75 {
76 PIN_INPUT, // IN POLARITY
77 OUTPUT, // OUT POLARITY
78 BIDIR // BI-DIRECTIONAL POLARITY
79 };
80
87 enum class SYMBOLTYPE
88 {
91 };
92
96 enum class JUSTIFICATION
97 {
104 VBOTTOM, // Vertical Bottom Justification
105 VLEFT, // Vertical Left Justification
106 VRIGHT, // Vertical Right Justification
107 VCENTER, // Vertical Center Justification
108 VTOP, // Vertical Top Justification.
110 };
111
115 enum class ORIENTATION
116 {
117 R0, // 0 degree rotation
118 R90, // 90 degree rotatioin.
119 R180, // 180 degree rotation.
120 R270, // 270 degree rotation.
121 M0, // 0 degree mirror
122 M90, // 90 degree mirror
123 M180, // 180 degree mirror
124 M270 // 270 degree mirror
125 };
126
134
135 struct LT_PIN
136 {
140 std::map<wxString, wxString> PinAttribute;
141 };
142
154
162
176
187
191 struct WIRE
192 {
195 };
196
197 struct FLAG
198 {
201 wxString Value;
202 };
203
204 struct DATAFLAG
205 {
208 wxString Expression;
209 };
210
218
227
228 struct BUSTAP
229 {
232 };
233
238 {
239 wxString Name;
240 wxString AsyKey;
243 std::map<wxString, wxString> SymAttributes;
244 std::vector<LT_PIN> Pins;
245 std::vector<LINE> Lines;
246 std::vector<CIRCLE> Circles;
247 std::vector<LT_WINDOW> Windows;
248 std::vector<ARC> Arcs;
249 std::vector<RECTANGLE> Rectangles;
250 std::vector<TEXT> Texts;
252 };
253
257 struct LT_ASC
258 {
263 std::vector<LT_SYMBOL> Symbols;
264 std::vector<LINE> Lines;
265 std::vector<CIRCLE> Circles;
266 std::vector<LT_WINDOW> Windows;
267 std::vector<ARC> Arcs;
268 std::vector<RECTANGLE> Rectangles;
269 std::vector<WIRE> Wires;
270 std::vector<FLAG> Flags;
271 std::vector<DATAFLAG> DataFlags;
272 std::vector<IOPIN> Iopins;
273 std::vector<BUSTAP> Bustap;
274 std::vector<TEXT> Texts;
276 };
277
278 explicit LTSPICE_SCHEMATIC( const wxString& aFilename, const wxFileName& aLTspiceDataDir,
279 REPORTER* aReporter, PROGRESS_REPORTER* aProgressReporter ) :
280 m_reporter( aReporter ),
281 m_ltspiceDataDir( aLTspiceDataDir )
282 {}
283
285
294 void Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet, const wxFileName& aLibraryFileName,
295 REPORTER* aReporter );
296
300 wxString GetSchematicFileName( const wxString& aAscKey ) const;
301
305 wxString GetSymbolName( const wxString& aSymbolName ) const;
306
316 void GetAscAndAsyFilePaths( const wxDir& aDir, bool aRecursive,
317 std::map<wxString, wxString>& aMapOfAscFiles,
318 std::map<wxString, wxString>& aMapOfAsyFiles,
319 const std::vector<wxString>& aBaseDirs = {} );
320
326 std::vector<LTSPICE_FILE> GetSchematicElements( const wxString& aAscFile );
327
333 bool IsAsySubsheet( const wxString& aAsyFile );
334
343 std::map<wxString, wxString> ReadAsyFiles( const std::vector<LTSPICE_FILE>& aSourceFiles,
344 const std::map<wxString, wxString>& aAsyFileMap );
345
352 std::map<wxString, LT_ASC> ParseAscFiles( const std::map<wxString, wxString>& aAscFilesContent );
353
354 LT_SYMBOL ParseSymbol( const wxString& aSymbolName, const wxString& aAsyFileContent, LT_ASC& aAscFile );
355
356 LT_SYMBOL MakeDummySymbol( const wxString& aAscFileName );
357
358 const wxFileName& GetLTspiceDataDir() { return m_ltspiceDataDir; }
359
360private:
367 static void aggregateAttributeValue( wxArrayString& aTokens, int aIndex );
368
378 static int integerCheck( const wxString& aToken, int aLineNumber, const wxString& aFileName );
379
380 static VECTOR2I pointCheck( const wxString& aTokenX, const wxString& aTokenY, int aLineNumber,
381 const wxString& aFileName );
392 static void tokensSizeRangeCheck( size_t aActualSize, int aExpectedMin, int aExpectedMax,
393 int aLineNumber, const wxString& aFileName );
394
395 static void removeCarriageReturn( wxString& elementFromLine );
396
401 static LINESTYLE getLineStyle( int aValue );
402
407 static LINEWIDTH getLineWidth( const wxString& aValue );
408
413 static POLARITY getPolarity( const wxString& aValue );
414
419 static ORIENTATION getSymbolRotationOrMirror( const wxString& aValue );
420
425 static JUSTIFICATION getTextJustification( const wxString& aValue );
426
431 static JUSTIFICATION getPinJustification( const wxString& aValue );
432
437 static SYMBOLTYPE getSymbolType( const wxString& aValue );
438
439private:
442
443 std::map<wxString, wxString> m_ascFileCache;
444 std::map<wxString, wxString> m_asyFileCache;
445
446 std::map<wxString, wxString> m_ascNamesMap;
447 std::map<wxString, wxString> m_asyNamesMap;
448};
449
450#endif // LTSPICE_SCHEMATIC_LOADER_H
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
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.
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:149
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
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