KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_library.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 Mikolaj Wielgus
5 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * https://www.gnu.org/licenses/gpl-3.0.html
20 * or you may search the http://www.gnu.org website for the version 3 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
26#include <sim/sim_library.h>
28#include <boost/algorithm/string/case_conv.hpp>
29#include <macros.h>
30
31
32std::unique_ptr<SIM_LIBRARY>
33SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
34 std::function<wxString( const wxString&, const wxString& )>* aResolver )
35{
36 std::unique_ptr<SIM_LIBRARY> library;
37
38 if( aFilePath.EndsWith( ".ibs" ) )
39 library = std::make_unique<SIM_LIBRARY_KIBIS>();
40 else
41 library = std::make_unique<SIM_LIBRARY_SPICE>( aForceFullParse );
42
43 library->m_pathResolver = aResolver;
44 library->ReadFile( aFilePath, aReporter );
45
46 return library;
47}
48
49
50void SIM_LIBRARY::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
51{
52 m_filePath = aFilePath;
53}
54
55
56SIM_MODEL* SIM_LIBRARY::FindModel( const std::string& aModelName ) const
57{
58 std::string lowerName = boost::to_lower_copy( aModelName );
59
60 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
61 {
62 if( boost::to_lower_copy( m_modelNames.at( i ) ) == lowerName )
63 return m_models.at( i ).get();
64 }
65
66 return nullptr;
67}
68
69
70std::vector<SIM_LIBRARY::MODEL> SIM_LIBRARY::GetModels() const
71{
72 std::vector<MODEL> result;
73
74 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
75 result.push_back( { m_modelNames.at( i ), *m_models.at( i ) } );
76
77 return result;
78}
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
std::vector< MODEL > GetModels() const
Definition: sim_library.cpp:70
virtual void ReadFile(const wxString &aFilePath, REPORTER &aReporter)=0
Read library from a source file.
Definition: sim_library.cpp:50
static std::unique_ptr< SIM_LIBRARY > Create(const wxString &aFilePath, bool aForceFullParse, REPORTER &aReporter, std::function< wxString(const wxString &, const wxString &)> *aResolver)
Read library from a source file (e.g.
Definition: sim_library.cpp:33
std::vector< std::string > m_modelNames
Definition: sim_library.h:77
SIM_MODEL * FindModel(const std::string &aModelName) const
Definition: sim_library.cpp:56
std::vector< std::unique_ptr< SIM_MODEL > > m_models
Definition: sim_library.h:78
std::string m_filePath
Definition: sim_library.h:82
This file contains miscellaneous commonly used macros and functions.