KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_model_ideal.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_ideal.h>
22#include <pegtl.hpp>
23#include <pegtl/contrib/parse_tree.hpp>
24#include <fmt/core.h>
25#include <wx/regex.h>
26
27std::string SPICE_GENERATOR_IDEAL::ModelLine( const SPICE_ITEM& aItem ) const
28{
29 return "";
30}
31
32
33std::string SPICE_GENERATOR_IDEAL::ItemLine( const SPICE_ITEM& aItem ) const
34{
35 SPICE_ITEM item = aItem;
36 item.modelName = SIM_VALUE::ToSpice( m_model.GetParam( 0 ).value );
37
38 if( item.modelName != "" )
39 return SPICE_GENERATOR::ItemLine( item );
40 else
41 return "";
42}
43
44
45std::string SPICE_GENERATOR_IDEAL::TunerCommand( const SPICE_ITEM& aItem, double aValue ) const
46{
47 return fmt::format( "alter @{}={:g}",
48 aItem.model->SpiceGenerator().ItemName( aItem ),
49 aValue );
50}
51
52
54 SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR_IDEAL>( *this ) )
55{
56 static PARAM::INFO resistor = makeParamInfo( "r", "Resistance", "Ω" );
57 static PARAM::INFO capacitor = makeParamInfo( "c", "Capacitance", "F" );
58 static PARAM::INFO inductor = makeParamInfo( "l", "Inductance", "H" );
59
60 switch( aType )
61 {
62 case TYPE::R: AddParam( resistor ); break;
63 case TYPE::C: AddParam( capacitor ); break;
64 case TYPE::L: AddParam( inductor ); break;
65 default:
66 wxFAIL_MSG( "Unhandled SIM_MODEL type in SIM_MODEL_IDEAL" );
67 }
68}
69
70
72 const std::string& aDescription,
73 const std::string& aUnit )
74{
75 PARAM::INFO paramInfo( aName, 0, PARAM::DIR_INOUT, SIM_VALUE::TYPE_FLOAT, aUnit,
76 PARAM::CATEGORY::PRINCIPAL );
77
78 paramInfo.description = aDescription;
79
80 return paramInfo;
81}
static PARAM::INFO makeParamInfo(const std::string &aName, const std::string &aDescription, const std::string &aUnit)
SIM_MODEL_IDEAL(TYPE aType)
void AddParam(const PARAM::INFO &aInfo)
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:428
SIM_MODEL()=delete
static std::string ToSpice(const std::string &aString)
std::string TunerCommand(const SPICE_ITEM &aItem, double aValue) const override
std::string ModelLine(const SPICE_ITEM &aItem) const override
std::string ItemLine(const SPICE_ITEM &aItem) const override
virtual std::string ItemName(const SPICE_ITEM &aItem) const
virtual std::string ItemLine(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