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 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
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 // Virtual root sheet UUID must be the same as the schematic file UUID.
71 const_cast<KIID&>( rootSheet->m_Uuid ) = screen->GetUuid();
72 }
73
74 SYMBOL_LIB_TABLE* libTable = PROJECT_SCH::SchSymbolLibTable( &aSchematic->Prj() );
75
76 wxCHECK_MSG( libTable, nullptr, "Could not load symbol lib table." );
77
78 // Windows path: C:\Users\USERNAME\AppData\Local\LTspice\lib
79 wxFileName ltspiceDataDir( KIPLATFORM::ENV::GetUserLocalDataPath(), wxEmptyString );
80 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
81 ltspiceDataDir.AppendDir( wxS( "lib" ) );
82
83 if( !ltspiceDataDir.DirExists() )
84 {
85 // Mac path
86 ltspiceDataDir = wxFileName( KIPLATFORM::ENV::GetUserDataPath(), wxEmptyString );
87 ltspiceDataDir.RemoveLastDir(); // "kicad"
88 ltspiceDataDir.AppendDir( wxS( "LTspice" ) );
89 ltspiceDataDir.AppendDir( wxS( "lib" ) );
90 }
91
92 if( !ltspiceDataDir.DirExists() )
93 {
94 // See if user has older version of LTspice installed
95 // (e.g. C:\Users\USERNAME\Documents\LTspiceXVII\lib
96 wxString foundFile = wxFindFirstFile( KIPLATFORM::ENV::GetDocumentsPath() +
97 wxFileName::GetPathSeparator() + "LTspice*", wxDIR );
98
99 while( !foundFile.empty() )
100 {
101 ltspiceDataDir = wxFileName(foundFile, wxEmptyString);
102 ltspiceDataDir.AppendDir( wxS( "lib" ) );
103
104 if( ltspiceDataDir.DirExists() )
105 break;
106
107 foundFile = wxFindNextFile();
108 }
109 }
110
111 try
112 {
113 LTSPICE_SCHEMATIC ascFile( aFileName, ltspiceDataDir, m_reporter, m_progressReporter );
114 ascFile.Load( aSchematic, rootSheet, aFileName, m_reporter );
115 }
116 catch( IO_ERROR& e )
117 {
119 }
120
122
123 return rootSheet;
124}
const KIID m_Uuid
Definition: eda_item.h:490
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition: io_base.h:223
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:226
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
Definition: kiid.h:49
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:82
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:161
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:146
SCH_SHEET & Root() const
Definition: schematic.h:130
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:97
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,...
const KIID & GetUuid() const
Definition: sch_screen.h:531
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:311
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:109
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:170
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