KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_model_r_pot.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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <sim/sim_model_r_pot.h>
22#include <fmt/core.h>
23
24
25std::string SPICE_GENERATOR_R_POT::ModelLine( const SPICE_ITEM& aItem ) const
26{
27 std::string r = "0";
28 std::string position = "";
29
30 if( const SIM_MODEL::PARAM* r_param = m_model.FindParam( "r" ) )
31 r = SIM_VALUE::ToSpice( r_param->value );
32
33 if( const SIM_MODEL::PARAM* pos_param = m_model.FindParam( "pos" ) )
34 position = SIM_VALUE::ToSpice( pos_param->value );
35
36 if( position != "" )
37 {
38 return fmt::format( ".model {} potentiometer( r={} position={} )\n", aItem.modelName, r,
39 position );
40 }
41 else
42 return fmt::format( ".model {} potentiometer( r={} )\n", aItem.modelName, r );
43}
44
45
46std::string SPICE_GENERATOR_R_POT::TunerCommand( const SPICE_ITEM& aItem, double aValue ) const
47{
48 return fmt::format( "altermod @{}[position]={:g}",
49 aItem.model->SpiceGenerator().ItemName( aItem ),
50 aValue );
51}
52
53
55 SIM_MODEL( TYPE::R_POT, std::make_unique<SPICE_GENERATOR_R_POT>( *this ) )
56{
57 static std::vector<PARAM::INFO> paramInfos = makeParamInfos();
58
59 for( const SIM_MODEL::PARAM::INFO& paramInfo : paramInfos )
60 AddParam( paramInfo );
61}
62
63
64const std::vector<SIM_MODEL::PARAM::INFO> SIM_MODEL_R_POT::makeParamInfos()
65{
66 std::vector<PARAM::INFO> paramInfos;
67 PARAM::INFO paramInfo;
68
69 paramInfo.name = "r";
70 paramInfo.type = SIM_VALUE::TYPE_STRING;
71 paramInfo.unit = "Ω";
72 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
73 paramInfo.defaultValue = "";
74 paramInfo.description = "Resistance";
75 paramInfos.push_back( paramInfo );
76
77 paramInfo.name = "pos";
78 paramInfo.type = SIM_VALUE::TYPE_FLOAT;
79 paramInfo.unit = "";
80 paramInfo.category = PARAM::CATEGORY::PRINCIPAL;
81 paramInfo.defaultValue = "0.5";
82 paramInfo.description = "Wiper position";
83 paramInfos.push_back( paramInfo );
84
85 return paramInfos;
86}
static const std::vector< PARAM::INFO > makeParamInfos()
void AddParam(const PARAM::INFO &aInfo)
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:428
SIM_MODEL()=delete
@ TYPE_STRING
Definition sim_value.h:67
static std::string ToSpice(const std::string &aString)
std::string ModelLine(const SPICE_ITEM &aItem) const override
std::string TunerCommand(const SPICE_ITEM &aItem, double aValue) const override
virtual std::string ItemName(const SPICE_ITEM &aItem) const
const SIM_MODEL & m_model
STL namespace.
SIM_MODEL::TYPE TYPE
Definition sim_model.cpp:54
std::string modelName
const SIM_MODEL * model