KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_ltspice.cpp
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-2024 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
25
26#include <project_sch.h>
27#include <schematic.h>
28#include <sch_sheet.h>
29#include <sch_screen.h>
31
37{
38 return 0;
39}
40
41
42SCH_SHEET* SCH_IO_LTSPICE::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
43 SCH_SHEET* aAppendToMe,
44 const STRING_UTF8_MAP* aProperties )
45{
46 wxASSERT( !aFileName || aSchematic );
47
48 SCH_SHEET* rootSheet = nullptr;
49
50 if( aAppendToMe )
51 {
52 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
53 rootSheet = &aSchematic->Root();
54 }
55 else
56 {
57 rootSheet = new SCH_SHEET( aSchematic );
58 rootSheet->SetFileName( aFileName );
59 aSchematic->SetRoot( rootSheet );
60 }
61
62 if( !rootSheet->GetScreen() )
63 {
64 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
65
66 screen->SetFileName( aFileName );
67 rootSheet->SetScreen( screen );
68 }
69
70 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
71
72 wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
73
74 // Windows path: C:\Users\USERNAME\AppData\Local\LTspice\lib
75 wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserLocalDataPath(), wxEmptyString );
76 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
77 ltspiceDataDir.AppendDir( wxS( "lib" ) );
78
79 if( !ltspiceDataDir.DirExists() )
80 {
81 // Mac path
82 ltspiceDataDir = wxFileName( KIPLATFORM::ENV::GetUserDataPath(), wxEmptyString );
83 ltspiceDataDir.RemoveLastDir(); // "kicad"
84 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
85 ltspiceDataDir.AppendDir( wxS( "lib" ) );
86 }
87
88 if( !ltspiceDataDir.DirExists() )
89 {
90 // See if user has older version of LTspice installed
91 // (e.g. C:\Users\USERNAME\Documents\LTspiceXVII\lib
92 wxString foundFile = wxFindFirstFile( KIPLATFORM::ENV::GetDocumentsPath() +
93 wxFileName::GetPathSeparator() + "LTspice*", wxDIR );
94
95 while( !foundFile.empty() )
96 {
97 ltspiceDataDir = wxFileName(foundFile, wxEmptyString);
98 ltspiceDataDir.AppendDir( wxS( "lib" ) );
99
100 if( ltspiceDataDir.DirExists() )
101 break;
102
103 foundFile = wxFindNextFile();
104 }
105 }
106
107 try
108 {
109 LTSPICE_SCHEMATIC ascFile( aFileName, ltspiceDataDir, m_reporter, m_progressReporter );
110 ascFile.Load( aSchematic, rootSheet, aFileName, m_reporter );
111 }
112 catch( IO_ERROR& e )
113 {
115 }
116
118
119 return rootSheet;
120}
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:210
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:213
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
void Load(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxFileName &aLibraryFileName, REPORTER *aReporter)
The main function responsible for loading the .asc and .asy files.
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Holds all the data relating to one schematic.
Definition: schematic.h:75
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:136
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:184
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:121
SCH_SHEET & Root() const
Definition: schematic.h:105
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
int GetModifyHash() const override
schematic PLUGIN for LTspice (*.asc) and (.asy) format.
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 SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:115
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:312
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
A name/value tuple with unique names and optional values.
wxString GetUserDataPath()
Retrieves the operating system specific path for a user's data store.
wxString GetDocumentsPath()
Retrieves the operating system specific path for a user's documents.
wxString GetUserLocalDataPath()
Retrieves the operating system specific path for a user's local data store.
@ RPT_SEVERITY_ERROR