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>
30#include <symbol_lib_table.h>
32
38{
39 return 0;
40}
41
42
43SCH_SHEET* SCH_IO_LTSPICE::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
44 SCH_SHEET* aAppendToMe,
45 const std::map<std::string, UTF8>* aProperties )
46{
47 wxASSERT( !aFileName || aSchematic );
48
49 SCH_SHEET* rootSheet = nullptr;
50
51 if( aAppendToMe )
52 {
53 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
54 rootSheet = &aSchematic->Root();
55 }
56 else
57 {
58 rootSheet = new SCH_SHEET( aSchematic );
59 rootSheet->SetFileName( aFileName );
60 aSchematic->SetRoot( rootSheet );
61 }
62
63 if( !rootSheet->GetScreen() )
64 {
65 SCH_SCREEN* screen = new SCH_SCREEN( aSchematic );
66
67 screen->SetFileName( aFileName );
68 rootSheet->SetScreen( screen );
69 }
70
71 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
72
73 wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
74
75 // Windows path: C:\Users\USERNAME\AppData\Local\LTspice\lib
76 wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserLocalDataPath(), wxEmptyString );
77 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
78 ltspiceDataDir.AppendDir( wxS( "lib" ) );
79
80 if( !ltspiceDataDir.DirExists() )
81 {
82 // Mac path
83 ltspiceDataDir = wxFileName( KIPLATFORM::ENV::GetUserDataPath(), wxEmptyString );
84 ltspiceDataDir.RemoveLastDir(); // "kicad"
85 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
86 ltspiceDataDir.AppendDir( wxS( "lib" ) );
87 }
88
89 if( !ltspiceDataDir.DirExists() )
90 {
91 // See if user has older version of LTspice installed
92 // (e.g. C:\Users\USERNAME\Documents\LTspiceXVII\lib
93 wxString foundFile = wxFindFirstFile( KIPLATFORM::ENV::GetDocumentsPath() +
94 wxFileName::GetPathSeparator() + "LTspice*", wxDIR );
95
96 while( !foundFile.empty() )
97 {
98 ltspiceDataDir = wxFileName(foundFile, wxEmptyString);
99 ltspiceDataDir.AppendDir( wxS( "lib" ) );
100
101 if( ltspiceDataDir.DirExists() )
102 break;
103
104 foundFile = wxFindNextFile();
105 }
106 }
107
108 try
109 {
110 LTSPICE_SCHEMATIC ascFile( aFileName, ltspiceDataDir, m_reporter, m_progressReporter );
111 ascFile.Load( aSchematic, rootSheet, aFileName, m_reporter );
112 }
113 catch( IO_ERROR& e )
114 {
116 }
117
119
120 return rootSheet;
121}
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:218
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:221
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:77
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:152
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:194
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:137
SCH_SHEET & Root() const
Definition: schematic.h:121
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:92
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 std::map< std::string, UTF8 > *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:118
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:173
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