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( int ii = 0; ii < GetParamCount(); ++ii )
35 AddParam( GetParam( ii ).info );
36
37 m_spiceCode = aRawSpiceCode;
38}
39
40
41void SIM_MODEL_SPICE_FALLBACK::AssignSymbolPinNumberToModelPin( const std::string& aModelPinName,
42 const wxString& aSymbolPinNumber )
43{
44 try
45 {
46 SIM_MODEL::AssignSymbolPinNumberToModelPin( aModelPinName, 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_modelPins.push_back( { aModelPinName, 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 for( int ii = 0; ii < GetParamCount(); ++ii )
68 {
69 const SIM_MODEL::PARAM& param = GetParam( ii );
70
71 if( param.Matches( aParamName ) )
72 return ii;
73 }
74
75 // Look for escaped param names as a second pass (as they're less common)
76 for( int ii = 0; ii < GetParamCount(); ++ii )
77 {
78 const SIM_MODEL::PARAM& param = GetParam( ii );
79
80 if( !param.info.name.ends_with( '_' ) )
81 continue;
82
83 if( param.Matches( aParamName + "_" ) )
84 return ii;
85 }
86
87 return -1;
88}
89
90
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
int doFindParam(const std::string &aParamName) const override
void AssignSymbolPinNumberToModelPin(const std::string &aModelPinName, const wxString &aSymbolPinNumber) 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< SIM_MODEL_PIN > m_modelPins
Definition: sim_model.h:539
virtual const PARAM & GetParam(unsigned aParamIndex) const
Definition: sim_model.cpp:780
int GetParamCount() const
Definition: sim_model.h:481
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
Definition: sim_model.cpp:749
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
Definition: sim_model.cpp:492
TYPE GetType() const
Definition: sim_model.h:464
STL namespace.
SIM_MODEL::TYPE TYPE
Definition: sim_model.cpp:53
bool Matches(const std::string &aName) const
Definition: sim_model.h:395
const INFO & info
Definition: sim_model.h:401