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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <ki_exception.h>
23#include <fmt/format.h>
24
25
26SIM_MODEL_SPICE_FALLBACK::SIM_MODEL_SPICE_FALLBACK( TYPE aType, const std::string& aRawSpiceCode ) :
27 SIM_MODEL_SPICE( aType, std::make_unique<SPICE_GENERATOR_SPICE>( *this ) )
28{
29 // Create the model we *should* have had to copy its parameter list
30 std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( aType );
31
32 for( int ii = 0; ii < GetParamCount(); ++ii )
33 AddParam( GetParam( ii ).info );
34
35 m_spiceCode = aRawSpiceCode;
36}
37
38
39void SIM_MODEL_SPICE_FALLBACK::AssignSymbolPinNumberToModelPin( const std::string& aModelPinName,
40 const wxString& aSymbolPinNumber )
41{
42 try
43 {
44 SIM_MODEL::AssignSymbolPinNumberToModelPin( aModelPinName, aSymbolPinNumber );
45 }
46 catch( IO_ERROR& )
47 {
48 // This is a fall-back, so we won't necessarily know the pin names. If we didn't find
49 // it, then just create a new pin.
50 m_modelPins.push_back( { aModelPinName, aSymbolPinNumber } );
51 }
52}
53
54
55std::vector<std::string> SIM_MODEL_SPICE_FALLBACK::GetPinNames() const
56{
57 // If we're a fall-back for a paticular model type, then return its pin names
58 std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( GetType() );
59 return model->GetPinNames();
60}
61
62
63int SIM_MODEL_SPICE_FALLBACK::doFindParam( const std::string& aParamName ) const
64{
65 for( int ii = 0; ii < GetParamCount(); ++ii )
66 {
67 const SIM_MODEL::PARAM& param = GetParam( ii );
68
69 if( param.Matches( aParamName ) )
70 return ii;
71 }
72
73 // Look for escaped param names as a second pass (as they're less common)
74 for( int ii = 0; ii < GetParamCount(); ++ii )
75 {
76 const SIM_MODEL::PARAM& param = GetParam( ii );
77
78 if( !param.info.name.ends_with( '_' ) )
79 continue;
80
81 if( param.Matches( aParamName + "_" ) )
82 return ii;
83 }
84
85 return -1;
86}
87
88
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
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
SIM_MODEL_SPICE(TYPE aType, std::unique_ptr< SPICE_GENERATOR > aSpiceGenerator)
friend class SPICE_GENERATOR_SPICE
void AddParam(const PARAM::INFO &aInfo)
std::vector< SIM_MODEL_PIN > m_modelPins
Definition sim_model.h:533
virtual const PARAM & GetParam(unsigned aParamIndex) const
int GetParamCount() const
Definition sim_model.h:475
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
TYPE GetType() const
Definition sim_model.h:458
STL namespace.
SIM_MODEL::TYPE TYPE
Definition sim_model.cpp:54
bool Matches(const std::string &aName) const
Definition sim_model.h:392
const INFO & info
Definition sim_model.h:398
KIBIS_MODEL * model