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 The 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>
30#include <macros.h>
31
32
33std::unique_ptr<SIM_LIBRARY>
34SIM_LIBRARY::Create( const wxString& aFilePath, bool aForceFullParse, REPORTER& aReporter,
35 const std::function<wxString( const wxString&, const wxString& )>& aResolver )
36{
37 std::unique_ptr<SIM_LIBRARY> library;
38
39 if( aFilePath.EndsWith( FILEEXT::IbisFileExtension ) )
40 library = std::make_unique<SIM_LIBRARY_IBIS>();
41 else
42 library = std::make_unique<SIM_LIBRARY_SPICE>( aForceFullParse );
43
44 library->m_pathResolver = aResolver;
45 library->ReadFile( aFilePath, aReporter );
46
47 return library;
48}
49
50
51void SIM_LIBRARY::ReadFile( const wxString& aFilePath, REPORTER& aReporter )
52{
53 m_filePath = aFilePath;
54}
55
56
57SIM_MODEL* SIM_LIBRARY::FindModel( const std::string& aModelName ) const
58{
59 std::string lowerName = boost::to_lower_copy( aModelName );
60
61 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
62 {
63 if( boost::to_lower_copy( m_modelNames.at( i ) ) == lowerName )
64 return m_models.at( i ).get();
65 }
66
67 return nullptr;
68}
69
70
71std::vector<SIM_LIBRARY::MODEL> SIM_LIBRARY::GetModels() const
72{
73 std::vector<MODEL> result;
74
75 for( int i = 0; i < static_cast<int>( m_modelNames.size() ); ++i )
76 result.push_back( { m_modelNames.at( i ), *m_models.at( i ) } );
77
78 return result;
79}
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
std::vector< MODEL > GetModels() const
Definition: sim_library.cpp:71
static std::unique_ptr< SIM_LIBRARY > Create(const wxString &aFilePath, bool aForceFullParse, REPORTER &aReporter, const std::function< wxString(const wxString &, const wxString &)> &aResolver)
Read library from a source file (e.g.
Definition: sim_library.cpp:34
virtual void ReadFile(const wxString &aFilePath, REPORTER &aReporter)=0
Read library from a source file.
Definition: sim_library.cpp:51
std::vector< std::string > m_modelNames
Definition: sim_library.h:77
SIM_MODEL * FindModel(const std::string &aModelName) const
Definition: sim_library.cpp:57
std::vector< std::unique_ptr< SIM_MODEL > > m_models
Definition: sim_library.h:78
std::string m_filePath
Definition: sim_library.h:82
static const std::string IbisFileExtension
This file contains miscellaneous commonly used macros and functions.
Definition of file extensions used in Kicad.