KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_model_spice_fallback.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-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <fmt/format.h>
26
27
28SIM_MODEL_SPICE_FALLBACK::SIM_MODEL_SPICE_FALLBACK( TYPE aType, const std::string& aRawSpiceCode ) :
29 SIM_MODEL_SPICE( aType, std::make_unique<SPICE_GENERATOR_SPICE>( *this ) )
30{
31 // Create the model we *should* have had to copy its parameter list
32 std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( aType );
33
34 for( const SIM_MODEL::PARAM& param : model->GetParams() )
35 AddParam( param.info );
36
37 m_spiceCode = aRawSpiceCode;
38}
39
40
41void SIM_MODEL_SPICE_FALLBACK::SetPinSymbolPinNumber( const std::string& aPinName,
42 const std::string& aSymbolPinNumber )
43{
44 try
45 {
46 SIM_MODEL::SetPinSymbolPinNumber( aPinName, aSymbolPinNumber );
47 }
48 catch( IO_ERROR& )
49 {
50 // This is a fall-back, so we won't necessarily know the pin names. If we didn't find
51 // it, then just create a new pin.
52 m_pins.push_back( { aPinName, aSymbolPinNumber } );
53 }
54}
55
56
57std::vector<std::string> SIM_MODEL_SPICE_FALLBACK::GetPinNames() const
58{
59 // If we're a fall-back for a paticular model type, then return its pin names
60 std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( GetType() );
61 return model->GetPinNames();
62}
63
64
65int SIM_MODEL_SPICE_FALLBACK::doFindParam( const std::string& aParamName ) const
66{
67 // Special case to allow escaped model parameters (suffixed with "_")
68
69 std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
70
71 for( int ii = 0; ii < (int) params.size(); ++ii )
72 {
73 const PARAM& param = params[ii];
74
75 if( param.Matches( aParamName ) || param.Matches( aParamName + "_" ) )
76 return ii;
77 }
78
79 return -1;
80}
81
82
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
std::vector< std::string > GetPinNames() const override
void SetPinSymbolPinNumber(const std::string &aPinName, const std::string &aSymbolPinNumber) override
int doFindParam(const std::string &aParamName) const override
SIM_MODEL_SPICE_FALLBACK(TYPE aType, const std::string &aRawSpiceCode="")
std::string m_spiceCode
void AddParam(const PARAM::INFO &aInfo)
Definition: sim_model.cpp:720
std::vector< PIN > m_pins
Definition: sim_model.h:542
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< LIB_PIN * > &aPins, REPORTER &aReporter)
Definition: sim_model.cpp:492
void SetPinSymbolPinNumber(int aPinIndex, const std::string &aSymbolPinNumber)
Definition: sim_model.cpp:749
std::vector< std::reference_wrapper< const PARAM > > GetParams() const
Definition: sim_model.cpp:816
TYPE GetType() const
Definition: sim_model.h:465
STL namespace.
SIM_MODEL::TYPE TYPE
Definition: sim_model.cpp:53
bool Matches(const std::string &aName) const
Definition: sim_model.h:396