2022-02-21 03:58:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sim/sim_model.h>
|
|
|
|
#include <sim/sim_model_behavioral.h>
|
2022-05-08 09:54:35 +00:00
|
|
|
#include <sim/sim_model_ideal.h>
|
2022-09-11 17:00:09 +00:00
|
|
|
#include <sim/sim_model_mutual_inductor.h>
|
2022-05-08 09:54:35 +00:00
|
|
|
#include <sim/sim_model_ngspice.h>
|
2022-10-22 02:33:26 +00:00
|
|
|
#include <sim/sim_model_r_pot.h>
|
2022-09-27 20:47:00 +00:00
|
|
|
#include <sim/sim_model_kibis.h>
|
2022-02-21 03:58:31 +00:00
|
|
|
#include <sim/sim_model_source.h>
|
2022-09-18 05:25:56 +00:00
|
|
|
#include <sim/sim_model_raw_spice.h>
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <sim/sim_model_subckt.h>
|
2022-08-28 12:51:03 +00:00
|
|
|
#include <sim/sim_model_switch.h>
|
2022-05-31 02:55:48 +00:00
|
|
|
#include <sim/sim_model_tline.h>
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <sim/sim_model_xspice.h>
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-10-25 09:45:40 +00:00
|
|
|
#include <sim/sim_library_kibis.h>
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
#include <lib_symbol.h>
|
2022-09-16 03:44:23 +00:00
|
|
|
#include <confirm.h>
|
2022-09-22 05:38:45 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include <fmt/core.h>
|
2022-06-12 03:39:13 +00:00
|
|
|
#include <pegtl.hpp>
|
|
|
|
#include <pegtl/contrib/parse_tree.hpp>
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
#include <iterator>
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
using DEVICE_TYPE = SIM_MODEL::DEVICE_TYPE_;
|
2022-02-21 03:58:31 +00:00
|
|
|
using TYPE = SIM_MODEL::TYPE;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
namespace SIM_MODEL_PARSER
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
using namespace SIM_MODEL_GRAMMAR;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
template <typename Rule> struct fieldParamValuePairsSelector : std::false_type {};
|
2022-10-15 17:31:15 +00:00
|
|
|
template <> struct fieldParamValuePairsSelector<param> : std::true_type {};
|
|
|
|
template <> struct fieldParamValuePairsSelector<quotedStringContent> : std::true_type {};
|
|
|
|
template <> struct fieldParamValuePairsSelector<unquotedString> : std::true_type {};
|
2022-08-24 04:13:55 +00:00
|
|
|
|
|
|
|
|
2022-10-21 06:14:13 +00:00
|
|
|
template <typename Rule> struct pinSequenceSelector : std::false_type {};
|
|
|
|
template <> struct pinSequenceSelector<pinNumber> : std::true_type {};
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
template <typename Rule> struct fieldInferValueSelector : std::false_type {};
|
2022-10-21 06:14:13 +00:00
|
|
|
template <> struct fieldInferValueSelector<fieldInferValueType> : std::true_type {};
|
2022-10-23 23:10:17 +00:00
|
|
|
template <> struct fieldInferValueSelector<fieldInferValuePrimaryValue> : std::true_type {};
|
2022-10-15 17:31:15 +00:00
|
|
|
template <> struct fieldInferValueSelector<number<SIM_VALUE::TYPE_FLOAT, NOTATION::SI>> : std::true_type {};
|
|
|
|
template <> struct fieldInferValueSelector<fieldParamValuePairs> : std::true_type {};
|
2022-05-31 02:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceTypeInfo( DEVICE_TYPE_ aDeviceType )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
|
|
|
switch( aDeviceType )
|
|
|
|
{
|
2022-09-14 07:19:25 +00:00
|
|
|
case DEVICE_TYPE_::NONE: return { "", "" };
|
|
|
|
case DEVICE_TYPE_::R: return { "R", "Resistor" };
|
|
|
|
case DEVICE_TYPE_::C: return { "C", "Capacitor" };
|
|
|
|
case DEVICE_TYPE_::L: return { "L", "Inductor" };
|
|
|
|
case DEVICE_TYPE_::TLINE: return { "TLINE", "Transmission Line" };
|
|
|
|
case DEVICE_TYPE_::SW: return { "SW", "Switch" };
|
|
|
|
|
|
|
|
case DEVICE_TYPE_::D: return { "D", "Diode" };
|
|
|
|
case DEVICE_TYPE_::NPN: return { "NPN", "NPN BJT" };
|
|
|
|
case DEVICE_TYPE_::PNP: return { "PNP", "PNP BJT" };
|
|
|
|
|
|
|
|
case DEVICE_TYPE_::NJFET: return { "NJFET", "N-channel JFET" };
|
|
|
|
case DEVICE_TYPE_::PJFET: return { "PJFET", "P-channel JFET" };
|
|
|
|
|
|
|
|
case DEVICE_TYPE_::NMOS: return { "NMOS", "N-channel MOSFET" };
|
|
|
|
case DEVICE_TYPE_::PMOS: return { "PMOS", "P-channel MOSFET" };
|
|
|
|
case DEVICE_TYPE_::NMES: return { "NMES", "N-channel MESFET" };
|
|
|
|
case DEVICE_TYPE_::PMES: return { "PMES", "P-channel MESFET" };
|
|
|
|
|
|
|
|
case DEVICE_TYPE_::V: return { "V", "Voltage Source" };
|
|
|
|
case DEVICE_TYPE_::I: return { "I", "Current Source" };
|
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
case DEVICE_TYPE_::KIBIS: return { "IBIS", "Ibis Model" };
|
2022-09-27 20:47:00 +00:00
|
|
|
|
2022-09-14 07:19:25 +00:00
|
|
|
case DEVICE_TYPE_::SUBCKT: return { "SUBCKT", "Subcircuit" };
|
|
|
|
case DEVICE_TYPE_::XSPICE: return { "XSPICE", "XSPICE Code Model" };
|
|
|
|
case DEVICE_TYPE_::SPICE: return { "SPICE", "Raw Spice Element" };
|
|
|
|
case DEVICE_TYPE_::_ENUM_END: break;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_MODEL::INFO SIM_MODEL::TypeInfo( TYPE aType )
|
|
|
|
{
|
|
|
|
switch( aType )
|
2022-09-29 11:06:50 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NONE: return { DEVICE_TYPE_::NONE, "", "" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::R: return { DEVICE_TYPE_::R, "", "Ideal" };
|
2022-10-22 02:33:26 +00:00
|
|
|
case TYPE::R_POT: return { DEVICE_TYPE_::R, "POT", "Potentiometer" };
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::R_BEHAVIORAL: return { DEVICE_TYPE_::R, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::C: return { DEVICE_TYPE_::C, "", "Ideal" };
|
|
|
|
case TYPE::C_BEHAVIORAL: return { DEVICE_TYPE_::C, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::L: return { DEVICE_TYPE_::L, "", "Ideal" };
|
2022-09-29 11:06:50 +00:00
|
|
|
case TYPE::L_MUTUAL: return { DEVICE_TYPE_::L, "MUTUAL", "Mutual" };
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::L_BEHAVIORAL: return { DEVICE_TYPE_::L, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
case TYPE::TLINE_Z0: return { DEVICE_TYPE_::TLINE, "", "Characteristic impedance" };
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::TLINE_RLGC: return { DEVICE_TYPE_::TLINE, "RLGC", "RLGC" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::SW_V: return { DEVICE_TYPE_::SW, "V", "Voltage-controlled" };
|
|
|
|
case TYPE::SW_I: return { DEVICE_TYPE_::SW, "I", "Current-controlled" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::D: return { DEVICE_TYPE_::D, "", "" };
|
2022-09-29 11:06:50 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NPN_GUMMELPOON: return { DEVICE_TYPE_::NPN, "GUMMELPOON", "Gummel-Poon" };
|
|
|
|
case TYPE::PNP_GUMMELPOON: return { DEVICE_TYPE_::PNP, "GUMMELPOON", "Gummel-Poon" };
|
|
|
|
case TYPE::NPN_VBIC: return { DEVICE_TYPE_::NPN, "VBIC", "VBIC" };
|
|
|
|
case TYPE::PNP_VBIC: return { DEVICE_TYPE_::PNP, "VBIC", "VBIC" };
|
2022-02-21 03:58:31 +00:00
|
|
|
//case TYPE::BJT_MEXTRAM: return {};
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NPN_HICUM2: return { DEVICE_TYPE_::NPN, "HICUML2", "HICUM level 2" };
|
|
|
|
case TYPE::PNP_HICUM2: return { DEVICE_TYPE_::PNP, "HICUML2", "HICUM level 2" };
|
2022-02-21 03:58:31 +00:00
|
|
|
//case TYPE::BJT_HICUM_L0: return {};
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NJFET_SHICHMANHODGES: return { DEVICE_TYPE_::NJFET, "SHICHMANHODGES", "Shichman-Hodges" };
|
|
|
|
case TYPE::PJFET_SHICHMANHODGES: return { DEVICE_TYPE_::PJFET, "SHICHMANHODGES", "Shichman-Hodges" };
|
|
|
|
case TYPE::NJFET_PARKERSKELLERN: return { DEVICE_TYPE_::NJFET, "PARKERSKELLERN", "Parker-Skellern" };
|
|
|
|
case TYPE::PJFET_PARKERSKELLERN: return { DEVICE_TYPE_::PJFET, "PARKERSKELLERN", "Parker-Skellern" };
|
|
|
|
|
|
|
|
case TYPE::NMES_STATZ: return { DEVICE_TYPE_::NMES, "STATZ", "Statz" };
|
|
|
|
case TYPE::PMES_STATZ: return { DEVICE_TYPE_::PMES, "STATZ", "Statz" };
|
|
|
|
case TYPE::NMES_YTTERDAL: return { DEVICE_TYPE_::NMES, "YTTERDAL", "Ytterdal" };
|
|
|
|
case TYPE::PMES_YTTERDAL: return { DEVICE_TYPE_::PMES, "YTTERDAL", "Ytterdal" };
|
|
|
|
case TYPE::NMES_HFET1: return { DEVICE_TYPE_::NMES, "HFET1", "HFET1" };
|
|
|
|
case TYPE::PMES_HFET1: return { DEVICE_TYPE_::PMES, "HFET1", "HFET1" };
|
|
|
|
case TYPE::NMES_HFET2: return { DEVICE_TYPE_::NMES, "HFET2", "HFET2" };
|
|
|
|
case TYPE::PMES_HFET2: return { DEVICE_TYPE_::PMES, "HFET2", "HFET2" };
|
|
|
|
|
|
|
|
case TYPE::NMOS_MOS1: return { DEVICE_TYPE_::NMOS, "MOS1", "Classical quadratic (MOS1)" };
|
|
|
|
case TYPE::PMOS_MOS1: return { DEVICE_TYPE_::PMOS, "MOS1", "Classical quadratic (MOS1)" };
|
|
|
|
case TYPE::NMOS_MOS2: return { DEVICE_TYPE_::NMOS, "MOS2", "Grove-Frohman (MOS2)" };
|
|
|
|
case TYPE::PMOS_MOS2: return { DEVICE_TYPE_::PMOS, "MOS2", "Grove-Frohman (MOS2)" };
|
|
|
|
case TYPE::NMOS_MOS3: return { DEVICE_TYPE_::NMOS, "MOS3", "MOS3" };
|
|
|
|
case TYPE::PMOS_MOS3: return { DEVICE_TYPE_::PMOS, "MOS3", "MOS3" };
|
|
|
|
case TYPE::NMOS_BSIM1: return { DEVICE_TYPE_::NMOS, "BSIM1", "BSIM1" };
|
|
|
|
case TYPE::PMOS_BSIM1: return { DEVICE_TYPE_::PMOS, "BSIM1", "BSIM1" };
|
|
|
|
case TYPE::NMOS_BSIM2: return { DEVICE_TYPE_::NMOS, "BSIM2", "BSIM2" };
|
|
|
|
case TYPE::PMOS_BSIM2: return { DEVICE_TYPE_::PMOS, "BSIM2", "BSIM2" };
|
|
|
|
case TYPE::NMOS_MOS6: return { DEVICE_TYPE_::NMOS, "MOS6", "MOS6" };
|
|
|
|
case TYPE::PMOS_MOS6: return { DEVICE_TYPE_::PMOS, "MOS6", "MOS6" };
|
|
|
|
case TYPE::NMOS_BSIM3: return { DEVICE_TYPE_::NMOS, "BSIM3", "BSIM3" };
|
|
|
|
case TYPE::PMOS_BSIM3: return { DEVICE_TYPE_::PMOS, "BSIM3", "BSIM3" };
|
|
|
|
case TYPE::NMOS_MOS9: return { DEVICE_TYPE_::NMOS, "MOS9", "MOS9" };
|
|
|
|
case TYPE::PMOS_MOS9: return { DEVICE_TYPE_::PMOS, "MOS9", "MOS9" };
|
|
|
|
case TYPE::NMOS_B4SOI: return { DEVICE_TYPE_::NMOS, "B4SOI", "BSIM4 SOI (B4SOI)" };
|
|
|
|
case TYPE::PMOS_B4SOI: return { DEVICE_TYPE_::PMOS, "B4SOI", "BSIM4 SOI (B4SOI)" };
|
|
|
|
case TYPE::NMOS_BSIM4: return { DEVICE_TYPE_::NMOS, "BSIM4", "BSIM4" };
|
|
|
|
case TYPE::PMOS_BSIM4: return { DEVICE_TYPE_::PMOS, "BSIM4", "BSIM4" };
|
2022-02-21 03:58:31 +00:00
|
|
|
//case TYPE::NMOS_EKV2_6: return {};
|
|
|
|
//case TYPE::PMOS_EKV2_6: return {};
|
|
|
|
//case TYPE::NMOS_PSP: return {};
|
|
|
|
//case TYPE::PMOS_PSP: return {};
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NMOS_B3SOIFD: return { DEVICE_TYPE_::NMOS, "B3SOIFD", "B3SOIFD (BSIM3 FD-SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIFD: return { DEVICE_TYPE_::PMOS, "B3SOIFD", "B3SOIFD (BSIM3 FD-SOI)" };
|
|
|
|
case TYPE::NMOS_B3SOIDD: return { DEVICE_TYPE_::NMOS, "B3SOIDD", "B3SOIDD (BSIM3 SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIDD: return { DEVICE_TYPE_::PMOS, "B3SOIDD", "B3SOIDD (BSIM3 SOI)" };
|
|
|
|
case TYPE::NMOS_B3SOIPD: return { DEVICE_TYPE_::NMOS, "B3SOIPD", "B3SOIPD (BSIM3 PD-SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIPD: return { DEVICE_TYPE_::PMOS, "B3SOIPD", "B3SOIPD (BSIM3 PD-SOI)" };
|
2022-02-21 03:58:31 +00:00
|
|
|
//case TYPE::NMOS_STAG: return {};
|
|
|
|
//case TYPE::PMOS_STAG: return {};
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::NMOS_HISIM2: return { DEVICE_TYPE_::NMOS, "HISIM2", "HiSIM2" };
|
|
|
|
case TYPE::PMOS_HISIM2: return { DEVICE_TYPE_::PMOS, "HISIM2", "HiSIM2" };
|
|
|
|
case TYPE::NMOS_HISIMHV1: return { DEVICE_TYPE_::NMOS, "HISIMHV1", "HiSIM_HV1" };
|
|
|
|
case TYPE::PMOS_HISIMHV1: return { DEVICE_TYPE_::PMOS, "HISIMHV1", "HiSIM_HV1" };
|
|
|
|
case TYPE::NMOS_HISIMHV2: return { DEVICE_TYPE_::NMOS, "HISIMHV2", "HiSIM_HV2" };
|
|
|
|
case TYPE::PMOS_HISIMHV2: return { DEVICE_TYPE_::PMOS, "HISIMHV2", "HiSIM_HV2" };
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
case TYPE::V: return { DEVICE_TYPE_::V, "", "DC", };
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::V_SIN: return { DEVICE_TYPE_::V, "SIN", "Sine" };
|
|
|
|
case TYPE::V_PULSE: return { DEVICE_TYPE_::V, "PULSE", "Pulse" };
|
|
|
|
case TYPE::V_EXP: return { DEVICE_TYPE_::V, "EXP", "Exponential" };
|
2022-06-12 03:39:13 +00:00
|
|
|
/*case TYPE::V_SFAM: return { DEVICE_TYPE::V, "SFAM", "Single-frequency AM" };
|
|
|
|
case TYPE::V_SFFM: return { DEVICE_TYPE::V, "SFFM", "Single-frequency FM" };*/
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::V_PWL: return { DEVICE_TYPE_::V, "PWL", "Piecewise linear" };
|
|
|
|
case TYPE::V_WHITENOISE: return { DEVICE_TYPE_::V, "WHITENOISE", "White noise" };
|
|
|
|
case TYPE::V_PINKNOISE: return { DEVICE_TYPE_::V, "PINKNOISE", "Pink noise (1/f)" };
|
|
|
|
case TYPE::V_BURSTNOISE: return { DEVICE_TYPE_::V, "BURSTNOISE", "Burst noise" };
|
|
|
|
case TYPE::V_RANDUNIFORM: return { DEVICE_TYPE_::V, "RANDUNIFORM", "Random uniform" };
|
|
|
|
case TYPE::V_RANDNORMAL: return { DEVICE_TYPE_::V, "RANDNORMAL", "Random normal" };
|
|
|
|
case TYPE::V_RANDEXP: return { DEVICE_TYPE_::V, "RANDEXP", "Random exponential" };
|
|
|
|
//case TYPE::V_RANDPOISSON: return { DEVICE_TYPE::V, "RANDPOISSON", "Random Poisson" };
|
|
|
|
case TYPE::V_BEHAVIORAL: return { DEVICE_TYPE_::V, "=", "Behavioral" };
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
case TYPE::I: return { DEVICE_TYPE_::I, "", "DC", };
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::I_SIN: return { DEVICE_TYPE_::I, "SIN", "Sine" };
|
|
|
|
case TYPE::I_PULSE: return { DEVICE_TYPE_::I, "PULSE", "Pulse" };
|
|
|
|
case TYPE::I_EXP: return { DEVICE_TYPE_::I, "EXP", "Exponential" };
|
2022-06-12 03:39:13 +00:00
|
|
|
/*case TYPE::I_SFAM: return { DEVICE_TYPE::I, "SFAM", "Single-frequency AM" };
|
|
|
|
case TYPE::I_SFFM: return { DEVICE_TYPE::I, "SFFM", "Single-frequency FM" };*/
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::I_PWL: return { DEVICE_TYPE_::I, "PWL", "Piecewise linear" };
|
|
|
|
case TYPE::I_WHITENOISE: return { DEVICE_TYPE_::I, "WHITENOISE", "White noise" };
|
|
|
|
case TYPE::I_PINKNOISE: return { DEVICE_TYPE_::I, "PINKNOISE", "Pink noise (1/f)" };
|
|
|
|
case TYPE::I_BURSTNOISE: return { DEVICE_TYPE_::I, "BURSTNOISE", "Burst noise" };
|
|
|
|
case TYPE::I_RANDUNIFORM: return { DEVICE_TYPE_::I, "RANDUNIFORM", "Random uniform" };
|
|
|
|
case TYPE::I_RANDNORMAL: return { DEVICE_TYPE_::I, "RANDNORMAL", "Random normal" };
|
|
|
|
case TYPE::I_RANDEXP: return { DEVICE_TYPE_::I, "RANDEXP", "Random exponential" };
|
|
|
|
//case TYPE::I_RANDPOISSON: return { DEVICE_TYPE::I, "RANDPOISSON", "Random Poisson" };
|
|
|
|
case TYPE::I_BEHAVIORAL: return { DEVICE_TYPE_::I, "=", "Behavioral" };
|
|
|
|
|
|
|
|
case TYPE::SUBCKT: return { DEVICE_TYPE_::SUBCKT, "", "" };
|
|
|
|
case TYPE::XSPICE: return { DEVICE_TYPE_::XSPICE, "", "" };
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
case TYPE::KIBIS_DEVICE: return { DEVICE_TYPE_::KIBIS, "IBISDEVICE", "Device" };
|
|
|
|
case TYPE::KIBIS_DRIVER_DC: return { DEVICE_TYPE_::KIBIS, "IBISDRIVERDC", "DC driver" };
|
|
|
|
case TYPE::KIBIS_DRIVER_RECT: return { DEVICE_TYPE_::KIBIS, "IBISDRIVERRECT", "Rectangular wave driver" };
|
|
|
|
case TYPE::KIBIS_DRIVER_PRBS: return { DEVICE_TYPE_::KIBIS, "IBISDRIVERPRBS", "PRBS driver" };
|
|
|
|
|
|
|
|
case TYPE::RAWSPICE: return { DEVICE_TYPE_::SPICE, "", "" };
|
|
|
|
|
|
|
|
case TYPE::_ENUM_END: break;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL;
|
2022-04-01 04:30:50 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_MODEL::SPICE_INFO SIM_MODEL::SpiceInfo( TYPE aType )
|
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::R: return { "R", "" };
|
2022-10-22 02:33:26 +00:00
|
|
|
case TYPE::R_POT: return { "A", "" };
|
2022-05-31 02:55:48 +00:00
|
|
|
case TYPE::R_BEHAVIORAL: return { "R", "", "", "0", false, true };
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::C: return { "C", "" };
|
2022-05-31 02:55:48 +00:00
|
|
|
case TYPE::C_BEHAVIORAL: return { "C", "", "", "0", false, true };
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::L: return { "L", "" };
|
2022-09-11 17:00:09 +00:00
|
|
|
case TYPE::L_MUTUAL: return { "K", "" };
|
2022-05-31 02:55:48 +00:00
|
|
|
case TYPE::L_BEHAVIORAL: return { "L", "", "", "0", false, true };
|
2022-09-29 11:06:50 +00:00
|
|
|
|
2022-08-31 13:01:05 +00:00
|
|
|
//case TYPE::TLINE_Z0: return { "T" };
|
2022-09-10 00:42:02 +00:00
|
|
|
case TYPE::TLINE_Z0: return { "O", "LTRA" };
|
|
|
|
case TYPE::TLINE_RLGC: return { "O", "LTRA" };
|
|
|
|
|
|
|
|
case TYPE::SW_V: return { "S", "SW" };
|
|
|
|
case TYPE::SW_I: return { "W", "CSW" };
|
|
|
|
|
|
|
|
case TYPE::D: return { "D", "D" };
|
|
|
|
|
|
|
|
case TYPE::NPN_GUMMELPOON: return { "Q", "NPN", "", "1", true };
|
|
|
|
case TYPE::PNP_GUMMELPOON: return { "Q", "PNP", "", "1", true };
|
|
|
|
|
|
|
|
case TYPE::NPN_VBIC: return { "Q", "NPN", "", "4" };
|
|
|
|
case TYPE::PNP_VBIC: return { "Q", "PNP", "", "4" };
|
|
|
|
|
|
|
|
case TYPE::NPN_HICUM2: return { "Q", "NPN", "", "8" };
|
|
|
|
case TYPE::PNP_HICUM2: return { "Q", "PNP", "", "8" };
|
|
|
|
|
|
|
|
case TYPE::NJFET_SHICHMANHODGES: return { "M", "NJF", "", "1" };
|
|
|
|
case TYPE::PJFET_SHICHMANHODGES: return { "M", "PJF", "", "1" };
|
|
|
|
case TYPE::NJFET_PARKERSKELLERN: return { "M", "NJF", "", "2" };
|
|
|
|
case TYPE::PJFET_PARKERSKELLERN: return { "M", "PJF", "", "2" };
|
|
|
|
|
|
|
|
case TYPE::NMES_STATZ: return { "Z", "NMF", "", "1" };
|
|
|
|
case TYPE::PMES_STATZ: return { "Z", "PMF", "", "1" };
|
|
|
|
case TYPE::NMES_YTTERDAL: return { "Z", "NMF", "", "2" };
|
|
|
|
case TYPE::PMES_YTTERDAL: return { "Z", "PMF", "", "2" };
|
|
|
|
case TYPE::NMES_HFET1: return { "Z", "NMF", "", "5" };
|
|
|
|
case TYPE::PMES_HFET1: return { "Z", "PMF", "", "5" };
|
|
|
|
case TYPE::NMES_HFET2: return { "Z", "NMF", "", "6" };
|
|
|
|
case TYPE::PMES_HFET2: return { "Z", "PMF", "", "6" };
|
|
|
|
|
|
|
|
case TYPE::NMOS_MOS1: return { "M", "NMOS", "", "1" };
|
|
|
|
case TYPE::PMOS_MOS1: return { "M", "PMOS", "", "1" };
|
|
|
|
case TYPE::NMOS_MOS2: return { "M", "NMOS", "", "2" };
|
|
|
|
case TYPE::PMOS_MOS2: return { "M", "PMOS", "", "2" };
|
|
|
|
case TYPE::NMOS_MOS3: return { "M", "NMOS", "", "3" };
|
|
|
|
case TYPE::PMOS_MOS3: return { "M", "PMOS", "", "3" };
|
|
|
|
case TYPE::NMOS_BSIM1: return { "M", "NMOS", "", "4" };
|
|
|
|
case TYPE::PMOS_BSIM1: return { "M", "PMOS", "", "4" };
|
|
|
|
case TYPE::NMOS_BSIM2: return { "M", "NMOS", "", "5" };
|
|
|
|
case TYPE::PMOS_BSIM2: return { "M", "PMOS", "", "5" };
|
|
|
|
case TYPE::NMOS_MOS6: return { "M", "NMOS", "", "6" };
|
|
|
|
case TYPE::PMOS_MOS6: return { "M", "PMOS", "", "6" };
|
|
|
|
case TYPE::NMOS_BSIM3: return { "M", "NMOS", "", "8" };
|
|
|
|
case TYPE::PMOS_BSIM3: return { "M", "PMOS", "", "8" };
|
|
|
|
case TYPE::NMOS_MOS9: return { "M", "NMOS", "", "9" };
|
|
|
|
case TYPE::PMOS_MOS9: return { "M", "PMOS", "", "9" };
|
|
|
|
case TYPE::NMOS_B4SOI: return { "M", "NMOS", "", "10" };
|
|
|
|
case TYPE::PMOS_B4SOI: return { "M", "PMOS", "", "10" };
|
|
|
|
case TYPE::NMOS_BSIM4: return { "M", "NMOS", "", "14" };
|
|
|
|
case TYPE::PMOS_BSIM4: return { "M", "PMOS", "", "14" };
|
2022-04-01 04:30:50 +00:00
|
|
|
//case TYPE::NMOS_EKV2_6: return {};
|
|
|
|
//case TYPE::PMOS_EKV2_6: return {};
|
|
|
|
//case TYPE::NMOS_PSP: return {};
|
|
|
|
//case TYPE::PMOS_PSP: return {};
|
2022-09-10 00:42:02 +00:00
|
|
|
case TYPE::NMOS_B3SOIFD: return { "M", "NMOS", "", "55" };
|
|
|
|
case TYPE::PMOS_B3SOIFD: return { "M", "PMOS", "", "55" };
|
|
|
|
case TYPE::NMOS_B3SOIDD: return { "M", "NMOS", "", "56" };
|
|
|
|
case TYPE::PMOS_B3SOIDD: return { "M", "PMOS", "", "56" };
|
|
|
|
case TYPE::NMOS_B3SOIPD: return { "M", "NMOS", "", "57" };
|
|
|
|
case TYPE::PMOS_B3SOIPD: return { "M", "PMOS", "", "57" };
|
2022-04-01 04:30:50 +00:00
|
|
|
//case TYPE::NMOS_STAG: return {};
|
|
|
|
//case TYPE::PMOS_STAG: return {};
|
2022-09-10 00:42:02 +00:00
|
|
|
case TYPE::NMOS_HISIM2: return { "M", "NMOS", "", "68" };
|
|
|
|
case TYPE::PMOS_HISIM2: return { "M", "PMOS", "", "68" };
|
|
|
|
case TYPE::NMOS_HISIMHV1: return { "M", "NMOS", "", "73", true, false, "1.2.4" };
|
|
|
|
case TYPE::PMOS_HISIMHV1: return { "M", "PMOS", "", "73", true, false, "1.2.4" };
|
|
|
|
case TYPE::NMOS_HISIMHV2: return { "M", "NMOS", "", "73", true, false, "2.2.0" };
|
|
|
|
case TYPE::PMOS_HISIMHV2: return { "M", "PMOS", "", "73", true, false, "2.2.0" };
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::V: return { "V", "" };
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::V_SIN: return { "V", "", "SIN" };
|
|
|
|
case TYPE::V_PULSE: return { "V", "", "PULSE" };
|
|
|
|
case TYPE::V_EXP: return { "V", "", "EXP" };
|
2022-06-12 03:39:13 +00:00
|
|
|
/*case TYPE::V_SFAM: return { "V", "", "AM" };
|
|
|
|
case TYPE::V_SFFM: return { "V", "", "SFFM" };*/
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::V_PWL: return { "V", "", "PWL" };
|
|
|
|
case TYPE::V_WHITENOISE: return { "V", "", "TRNOISE" };
|
|
|
|
case TYPE::V_PINKNOISE: return { "V", "", "TRNOISE" };
|
|
|
|
case TYPE::V_BURSTNOISE: return { "V", "", "TRNOISE" };
|
|
|
|
case TYPE::V_RANDUNIFORM: return { "V", "", "TRRANDOM" };
|
|
|
|
case TYPE::V_RANDNORMAL: return { "V", "", "TRRANDOM" };
|
|
|
|
case TYPE::V_RANDEXP: return { "V", "", "TRRANDOM" };
|
2022-06-21 02:22:52 +00:00
|
|
|
//case TYPE::V_RANDPOISSON: return { "V", "", "TRRANDOM" };
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::V_BEHAVIORAL: return { "B" };
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::I: return { "I", "" };
|
|
|
|
case TYPE::I_PULSE: return { "I", "", "PULSE" };
|
|
|
|
case TYPE::I_SIN: return { "I", "", "SIN" };
|
|
|
|
case TYPE::I_EXP: return { "I", "", "EXP" };
|
2022-06-12 03:39:13 +00:00
|
|
|
/*case TYPE::I_SFAM: return { "V", "", "AM" };
|
|
|
|
case TYPE::I_SFFM: return { "V", "", "SFFM" };*/
|
2022-06-21 02:22:52 +00:00
|
|
|
case TYPE::I_PWL: return { "I", "", "PWL" };
|
|
|
|
case TYPE::I_WHITENOISE: return { "I", "", "TRNOISE" };
|
|
|
|
case TYPE::I_PINKNOISE: return { "I", "", "TRNOISE" };
|
|
|
|
case TYPE::I_BURSTNOISE: return { "I", "", "TRNOISE" };
|
|
|
|
case TYPE::I_RANDUNIFORM: return { "I", "", "TRRANDOM" };
|
|
|
|
case TYPE::I_RANDNORMAL: return { "I", "", "TRRANDOM" };
|
|
|
|
case TYPE::I_RANDEXP: return { "I", "", "TRRANDOM" };
|
|
|
|
//case TYPE::I_RANDPOISSON: return { "I", "", "TRRANDOM" };
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::I_BEHAVIORAL: return { "B" };
|
|
|
|
|
|
|
|
case TYPE::SUBCKT: return { "X" };
|
|
|
|
case TYPE::XSPICE: return { "A" };
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
case TYPE::KIBIS_DEVICE: return { "X" };
|
2022-09-30 12:29:44 +00:00
|
|
|
case TYPE::KIBIS_DRIVER_DC: return { "X" };
|
|
|
|
case TYPE::KIBIS_DRIVER_RECT: return { "X" };
|
|
|
|
case TYPE::KIBIS_DRIVER_PRBS: return { "X" };
|
2022-09-29 08:35:01 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
case TYPE::NONE:
|
2022-09-18 19:22:59 +00:00
|
|
|
case TYPE::RAWSPICE:
|
2022-04-01 04:30:50 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
case TYPE::_ENUM_END:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFAIL;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 02:33:26 +00:00
|
|
|
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields,
|
|
|
|
int aSymbolPinCount );
|
|
|
|
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFields,
|
|
|
|
int aSymbolPinCount );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-10-22 02:33:26 +00:00
|
|
|
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, int aSymbolPinCount )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string deviceTypeFieldValue = GetFieldValue( &aFields, DEVICE_TYPE_FIELD );
|
|
|
|
std::string typeFieldValue = GetFieldValue( &aFields, TYPE_FIELD );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( deviceTypeFieldValue != "" )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
for( TYPE type : TYPE_ITERATOR() )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
if( typeFieldValue == TypeInfo( type ).fieldValue )
|
|
|
|
{
|
|
|
|
if( deviceTypeFieldValue == DeviceTypeInfo( TypeInfo( type ).deviceType ).fieldValue )
|
|
|
|
return type;
|
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
if( typeFieldValue != "" )
|
2022-04-12 14:37:06 +00:00
|
|
|
return TYPE::NONE;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
// No type information. Look for legacy (pre-V7) fields.
|
|
|
|
|
|
|
|
TYPE typeFromLegacyFields = InferTypeFromLegacyFields( aFields );
|
2022-10-26 13:03:20 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( typeFromLegacyFields != TYPE::NONE )
|
|
|
|
return typeFromLegacyFields;
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
// Still no type information.
|
2022-10-15 17:31:15 +00:00
|
|
|
// We try to infer the model from the mandatory fields in this case.
|
2022-06-21 02:22:52 +00:00
|
|
|
return InferTypeFromRefAndValue( GetFieldValue( &aFields, REFERENCE_FIELD ),
|
2022-10-22 02:33:26 +00:00
|
|
|
GetFieldValue( &aFields, VALUE_FIELD ),
|
|
|
|
aSymbolPinCount );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-10-16 03:10:57 +00:00
|
|
|
DEVICE_TYPE SIM_MODEL::InferDeviceTypeFromRef( const std::string& aRef )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( boost::starts_with( aRef, "R" ) )
|
|
|
|
return DEVICE_TYPE::R;
|
|
|
|
else if( boost::starts_with( aRef, "C" ) )
|
|
|
|
return DEVICE_TYPE::C;
|
|
|
|
else if( boost::starts_with( aRef, "L" ) )
|
|
|
|
return DEVICE_TYPE::L;
|
|
|
|
else if( boost::starts_with( aRef, "V" ) )
|
|
|
|
return DEVICE_TYPE::V;
|
|
|
|
else if( boost::starts_with( aRef, "I" ) )
|
|
|
|
return DEVICE_TYPE::I;
|
|
|
|
else if( boost::starts_with( aRef, "TL" ) )
|
|
|
|
return DEVICE_TYPE::TLINE;
|
|
|
|
|
|
|
|
return DEVICE_TYPE::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-22 02:33:26 +00:00
|
|
|
TYPE SIM_MODEL::InferTypeFromRefAndValue( const std::string& aRef, const std::string& aValue,
|
|
|
|
int aSymbolPinCount )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
std::string typeString;
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
try
|
2022-06-12 03:39:13 +00:00
|
|
|
{
|
2022-10-15 17:31:15 +00:00
|
|
|
tao::pegtl::string_input<> in( aValue, VALUE_FIELD );
|
|
|
|
auto root = tao::pegtl::parse_tree::parse<SIM_MODEL_PARSER::fieldInferValueGrammar,
|
|
|
|
SIM_MODEL_PARSER::fieldInferValueSelector,
|
|
|
|
tao::pegtl::nothing,
|
|
|
|
SIM_MODEL_PARSER::control>( in );
|
2022-06-12 03:39:13 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
for( const auto& node : root->children )
|
2022-06-12 03:39:13 +00:00
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
if( node->is_type<SIM_MODEL_PARSER::fieldInferValueType>() )
|
|
|
|
typeString = node->string();
|
2022-06-12 03:39:13 +00:00
|
|
|
}
|
2022-10-15 17:31:15 +00:00
|
|
|
}
|
|
|
|
catch( const tao::pegtl::parse_error& )
|
|
|
|
{
|
|
|
|
}
|
2022-06-12 03:39:13 +00:00
|
|
|
|
2022-10-16 03:10:57 +00:00
|
|
|
DEVICE_TYPE deviceType = InferDeviceTypeFromRef( aRef );
|
2022-06-12 03:39:13 +00:00
|
|
|
|
2022-10-22 02:33:26 +00:00
|
|
|
// Exception. Potentiometer model is determined from pin count.
|
|
|
|
if( deviceType == DEVICE_TYPE_::R && aSymbolPinCount == 3 )
|
|
|
|
return TYPE::R_POT;
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
for( TYPE type : TYPE_ITERATOR() )
|
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
if( TypeInfo( type ).deviceType == deviceType && TypeInfo( type ).fieldValue == typeString )
|
2022-10-15 17:31:15 +00:00
|
|
|
return type;
|
2022-06-12 03:39:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
return TYPE::NONE;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
template <typename T>
|
|
|
|
TYPE SIM_MODEL::InferTypeFromLegacyFields( const std::vector<T>& aFields )
|
|
|
|
{
|
2022-09-18 05:25:56 +00:00
|
|
|
if( GetFieldValue( &aFields, SIM_MODEL_RAW_SPICE::LEGACY_TYPE_FIELD ) != ""
|
|
|
|
|| GetFieldValue( &aFields, SIM_MODEL_RAW_SPICE::LEGACY_MODEL_FIELD ) != ""
|
|
|
|
|| GetFieldValue( &aFields, SIM_MODEL_RAW_SPICE::LEGACY_ENABLED_FIELD ) != ""
|
|
|
|
|| GetFieldValue( &aFields, SIM_MODEL_RAW_SPICE::LEGACY_LIB_FIELD ) != "" )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-09-18 19:22:59 +00:00
|
|
|
return TYPE::RAWSPICE;
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
2022-10-26 13:03:20 +00:00
|
|
|
{
|
2022-05-08 09:54:35 +00:00
|
|
|
return TYPE::NONE;
|
2022-10-26 13:03:20 +00:00
|
|
|
}
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-31 23:43:52 +00:00
|
|
|
template <typename T>
|
|
|
|
void SIM_MODEL::ReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields )
|
|
|
|
{
|
|
|
|
doReadDataFields( aSymbolPinCount, aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void SIM_MODEL::ReadDataFields( unsigned aSymbolPinCount, const std::vector<SCH_FIELD>* aFields )
|
|
|
|
{
|
|
|
|
ReadDataSchFields( aSymbolPinCount, aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void SIM_MODEL::ReadDataFields( unsigned aSymbolPinCount, const std::vector<LIB_FIELD>* aFields )
|
|
|
|
{
|
|
|
|
ReadDataLibFields( aSymbolPinCount, aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::ReadDataSchFields( unsigned aSymbolPinCount, const std::vector<SCH_FIELD>* aFields )
|
|
|
|
{
|
|
|
|
doReadDataFields( aSymbolPinCount, aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::ReadDataLibFields( unsigned aSymbolPinCount, const std::vector<LIB_FIELD>* aFields )
|
|
|
|
{
|
|
|
|
doReadDataFields( aSymbolPinCount, aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void SIM_MODEL::WriteFields( std::vector<SCH_FIELD>& aFields ) const
|
|
|
|
{
|
|
|
|
WriteDataSchFields( aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void SIM_MODEL::WriteFields( std::vector<LIB_FIELD>& aFields ) const
|
|
|
|
{
|
|
|
|
WriteDataLibFields( aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const
|
|
|
|
{
|
|
|
|
doWriteFields( aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) const
|
|
|
|
{
|
|
|
|
doWriteFields( aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, unsigned aSymbolPinCount, bool aResolve )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = Create( aType, aResolve );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
// Passing nullptr to ReadDataFields will make it act as if all fields were empty.
|
|
|
|
model->ReadDataFields( aSymbolPinCount, static_cast<const std::vector<void>*>( nullptr ) );
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL& aBaseModel, unsigned aSymbolPinCount,
|
|
|
|
bool aResolve )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = Create( aBaseModel.GetType(), aResolve );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
model->SetBaseModel( aBaseModel );
|
|
|
|
model->ReadDataFields( aSymbolPinCount, static_cast<const std::vector<void>*>( nullptr ) );
|
|
|
|
return model;
|
|
|
|
}
|
2022-04-12 14:37:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL& aBaseModel, unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<T>& aFields, bool aResolve )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-22 02:33:26 +00:00
|
|
|
TYPE type = ReadTypeFromFields( aFields, aSymbolPinCount );
|
2022-10-09 18:44:03 +00:00
|
|
|
|
|
|
|
// If the model has a specified type, it takes priority over the type of its base class.
|
|
|
|
if( type == TYPE::NONE )
|
|
|
|
type = aBaseModel.GetType();
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = Create( type, aResolve );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
model->SetBaseModel( aBaseModel );
|
2022-04-12 14:37:06 +00:00
|
|
|
model->ReadDataFields( aSymbolPinCount, &aFields );
|
2022-04-01 04:30:50 +00:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL& aBaseModel,
|
|
|
|
unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<SCH_FIELD>& aFields,
|
|
|
|
bool aResolve );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL& aBaseModel,
|
|
|
|
unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<LIB_FIELD>& aFields,
|
|
|
|
bool aResolve );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<T>& aFields, bool aResolve )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-10-22 02:33:26 +00:00
|
|
|
TYPE type = ReadTypeFromFields( aFields, aSymbolPinCount );
|
2022-10-15 17:31:15 +00:00
|
|
|
|
|
|
|
if( type == TYPE::NONE )
|
2022-10-26 13:03:20 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Failed to read simulation model from fields." ) ) );
|
2022-10-15 17:31:15 +00:00
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( type, aResolve );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
model->ReadDataFields( aSymbolPinCount, &aFields );
|
|
|
|
return model;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<SCH_FIELD>& aFields,
|
|
|
|
bool aResolve );
|
2022-06-21 02:22:52 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( unsigned aSymbolPinCount,
|
2022-10-31 22:31:29 +00:00
|
|
|
const std::vector<LIB_FIELD>& aFields,
|
|
|
|
bool aResolve );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
|
|
|
|
|
|
|
|
if( !aFields )
|
2022-09-22 05:38:45 +00:00
|
|
|
return ""; // Should not happen, T=void specialization will be called instead.
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
auto it = std::find_if( aFields->begin(), aFields->end(),
|
|
|
|
[aFieldName]( const T& field )
|
|
|
|
{
|
|
|
|
return field.GetName() == aFieldName;
|
|
|
|
} );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
if( it != aFields->end() )
|
|
|
|
return std::string( it->GetText().ToUTF8() );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
return "";
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This specialization is used when no fields are passed.
|
|
|
|
template <>
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const std::string& aFieldName )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
return "";
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-09-22 05:38:45 +00:00
|
|
|
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName,
|
|
|
|
const std::string& aValue )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
static_assert( std::is_same<T, SCH_FIELD>::value || std::is_same<T, LIB_FIELD>::value );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
auto fieldIt = std::find_if( aFields.begin(), aFields.end(),
|
|
|
|
[&]( const T& f )
|
|
|
|
{
|
|
|
|
return f.GetName() == aFieldName;
|
|
|
|
} );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
if( fieldIt != aFields.end() )
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
if( aValue == "" )
|
2022-04-01 04:30:50 +00:00
|
|
|
aFields.erase( fieldIt );
|
|
|
|
else
|
|
|
|
fieldIt->SetText( aValue );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
if( aValue == "" )
|
2022-04-01 04:30:50 +00:00
|
|
|
return;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
if constexpr( std::is_same<T, SCH_FIELD>::value )
|
|
|
|
{
|
|
|
|
wxASSERT( aFields.size() >= 1 );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
SCH_ITEM* parent = static_cast<SCH_ITEM*>( aFields.at( 0 ).GetParent() );
|
|
|
|
aFields.emplace_back( wxPoint(), aFields.size(), parent, aFieldName );
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
else if constexpr( std::is_same<T, LIB_FIELD>::value )
|
|
|
|
aFields.emplace_back( aFields.size(), aFieldName );
|
|
|
|
|
|
|
|
aFields.back().SetText( aValue );
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-15 03:25:57 +00:00
|
|
|
SIM_MODEL::~SIM_MODEL() = default;
|
|
|
|
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
void SIM_MODEL::AddPin( const PIN& aPin )
|
|
|
|
{
|
|
|
|
m_pins.push_back( aPin );
|
|
|
|
}
|
|
|
|
|
2022-10-25 09:45:40 +00:00
|
|
|
void SIM_MODEL::DeletePins()
|
|
|
|
{
|
|
|
|
m_pins.clear();
|
|
|
|
}
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
int SIM_MODEL::FindModelPinIndex( const std::string& aSymbolPinNumber )
|
2022-04-12 14:37:06 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int modelPinIndex = 0; modelPinIndex < GetPinCount(); ++modelPinIndex )
|
2022-04-12 14:37:06 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
if( GetPin( modelPinIndex ).symbolPinNumber == aSymbolPinNumber )
|
|
|
|
return modelPinIndex;
|
2022-04-12 14:37:06 +00:00
|
|
|
}
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
return PIN::NOT_CONNECTED;
|
2022-04-12 14:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
void SIM_MODEL::AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant )
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
m_params.emplace_back( aInfo, aIsOtherVariant );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
std::vector<std::reference_wrapper<const SIM_MODEL::PIN>> SIM_MODEL::GetPins() const
|
|
|
|
{
|
|
|
|
std::vector<std::reference_wrapper<const PIN>> pins;
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int modelPinIndex = 0; modelPinIndex < GetPinCount(); ++modelPinIndex )
|
|
|
|
pins.emplace_back( GetPin( modelPinIndex ) );
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
return pins;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const SIM_MODEL::PARAM& SIM_MODEL::GetParam( unsigned aParamIndex ) const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-31 22:31:29 +00:00
|
|
|
const SIM_MODEL::PARAM& param = m_params.at( aParamIndex );
|
|
|
|
|
|
|
|
if( m_baseModel )
|
|
|
|
{
|
|
|
|
std::string value = param.resolved ? param.value->ToString() : param.source.ToStdString();
|
|
|
|
|
|
|
|
if( value.empty() )
|
|
|
|
return m_baseModel->GetParam( aParamIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
return param;
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
const SIM_MODEL::PARAM* SIM_MODEL::FindParam( const std::string& aParamName ) const
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
|
|
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
|
|
|
|
|
|
|
auto it = std::find_if( params.begin(), params.end(),
|
|
|
|
[aParamName]( const PARAM& param )
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
return param.info.name == boost::to_lower_copy( aParamName );
|
2022-05-31 02:55:48 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( it == params.end() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &it->get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
std::vector<std::reference_wrapper<const SIM_MODEL::PARAM>> SIM_MODEL::GetParams() const
|
|
|
|
{
|
|
|
|
std::vector<std::reference_wrapper<const PARAM>> params;
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int i = 0; i < GetParamCount(); ++i )
|
2022-09-14 01:15:42 +00:00
|
|
|
params.emplace_back( GetParam( i ) );
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const SIM_MODEL::PARAM& SIM_MODEL::GetUnderlyingParam( unsigned aParamIndex ) const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
return m_params.at( aParamIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
const SIM_MODEL::PARAM& SIM_MODEL::GetBaseParam( unsigned aParamIndex ) const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
if( m_baseModel )
|
|
|
|
return m_baseModel->GetParam( aParamIndex );
|
|
|
|
else
|
|
|
|
return m_params.at( aParamIndex );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-12 02:26:16 +00:00
|
|
|
void SIM_MODEL::SetParamValue( int aParamIndex, const SIM_VALUE& aValue )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-04 15:17:41 +00:00
|
|
|
*m_params.at( aParamIndex ).value = aValue;
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-12 02:26:16 +00:00
|
|
|
void SIM_MODEL::SetParamValue( int aParamIndex, const std::string& aValue,
|
2022-10-04 15:17:41 +00:00
|
|
|
SIM_VALUE::NOTATION aNotation )
|
|
|
|
{
|
|
|
|
const SIM_VALUE& value = *GetParam( aParamIndex ).value;
|
2022-10-12 02:26:16 +00:00
|
|
|
SetParamValue( aParamIndex, *SIM_VALUE::Create( value.GetType(), aValue, aNotation ) );
|
2022-10-04 15:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-12 02:26:16 +00:00
|
|
|
void SIM_MODEL::SetParamValue( const std::string& aParamName, const SIM_VALUE& aValue )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
|
|
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
|
|
|
|
|
|
|
auto it = std::find_if( params.begin(), params.end(),
|
|
|
|
[aParamName]( const PARAM& param )
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
return param.info.name == boost::to_lower_copy( aParamName );
|
2022-06-21 02:22:52 +00:00
|
|
|
} );
|
2022-09-29 11:06:50 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( it == params.end() )
|
2022-10-12 02:26:16 +00:00
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in simulation model of type '%s'" ),
|
|
|
|
aParamName,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
2022-10-12 02:26:16 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-10-04 15:17:41 +00:00
|
|
|
SetParamValue( static_cast<int>( it - params.begin() ), aValue );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-12 02:26:16 +00:00
|
|
|
void SIM_MODEL::SetParamValue( const std::string& aParamName, const std::string& aValue,
|
2022-10-04 15:17:41 +00:00
|
|
|
SIM_VALUE::NOTATION aNotation )
|
|
|
|
{
|
2022-10-12 02:26:16 +00:00
|
|
|
const PARAM* param = FindParam( aParamName );
|
|
|
|
|
|
|
|
if( !param )
|
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in simulation model of type '%s'" ),
|
|
|
|
aParamName,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
2022-10-12 02:26:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 15:17:41 +00:00
|
|
|
const SIM_VALUE& value = *FindParam( aParamName )->value;
|
2022-10-12 02:26:16 +00:00
|
|
|
SetParamValue( aParamName, *SIM_VALUE::Create( value.GetType(), aValue, aNotation ) );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
void SIM_MODEL::SetParamSource( const std::string& aParamName, const wxString& aSource )
|
|
|
|
{
|
|
|
|
for( PARAM& param : m_params )
|
|
|
|
{
|
|
|
|
if( param.info.name == boost::to_lower_copy( aParamName ) )
|
|
|
|
{
|
|
|
|
param.source = aSource;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in simulation model of type '%s'" ),
|
|
|
|
aParamName,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::SetParamSource( int aParamIndex, const wxString& aSource )
|
|
|
|
{
|
|
|
|
SIM_MODEL::PARAM& param = m_params.at( aParamIndex );
|
|
|
|
|
|
|
|
wxASSERT( !param.resolved );
|
|
|
|
|
|
|
|
param.source = aSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
bool SIM_MODEL::HasOverrides() const
|
|
|
|
{
|
|
|
|
for( const PARAM& param : m_params )
|
|
|
|
{
|
2022-05-31 02:55:48 +00:00
|
|
|
if( param.value->ToString() != "" )
|
2022-04-01 04:30:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
bool SIM_MODEL::HasNonInstanceOverrides() const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
for( const PARAM& param : m_params )
|
|
|
|
{
|
2022-05-31 02:55:48 +00:00
|
|
|
if( !param.info.isInstanceParam && param.value->ToString() != "" )
|
2022-04-01 04:30:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
bool SIM_MODEL::HasSpiceNonInstanceOverrides() const
|
|
|
|
{
|
|
|
|
for( const PARAM& param : m_params )
|
|
|
|
{
|
|
|
|
if( !param.info.isSpiceInstanceParam && param.value->ToString() != "" )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::doCreate( TYPE aType )
|
2022-09-18 19:22:59 +00:00
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
case TYPE::R:
|
|
|
|
case TYPE::C:
|
|
|
|
case TYPE::L:
|
|
|
|
return std::make_unique<SIM_MODEL_IDEAL>( aType );
|
2022-10-22 02:33:26 +00:00
|
|
|
|
|
|
|
case TYPE::R_POT:
|
|
|
|
return std::make_unique<SIM_MODEL_R_POT>();
|
2022-09-18 19:22:59 +00:00
|
|
|
|
|
|
|
case TYPE::L_MUTUAL:
|
|
|
|
return std::make_unique<SIM_MODEL_MUTUAL_INDUCTOR>();
|
|
|
|
|
|
|
|
case TYPE::R_BEHAVIORAL:
|
|
|
|
case TYPE::C_BEHAVIORAL:
|
|
|
|
case TYPE::L_BEHAVIORAL:
|
|
|
|
case TYPE::V_BEHAVIORAL:
|
|
|
|
case TYPE::I_BEHAVIORAL:
|
|
|
|
return std::make_unique<SIM_MODEL_BEHAVIORAL>( aType );
|
2022-09-29 11:06:50 +00:00
|
|
|
|
2022-09-18 19:22:59 +00:00
|
|
|
case TYPE::TLINE_Z0:
|
|
|
|
case TYPE::TLINE_RLGC:
|
|
|
|
return std::make_unique<SIM_MODEL_TLINE>( aType );
|
|
|
|
|
|
|
|
case TYPE::SW_V:
|
|
|
|
case TYPE::SW_I:
|
|
|
|
return std::make_unique<SIM_MODEL_SWITCH>( aType );
|
|
|
|
|
|
|
|
case TYPE::V:
|
|
|
|
case TYPE::I:
|
|
|
|
case TYPE::V_SIN:
|
|
|
|
case TYPE::I_SIN:
|
|
|
|
case TYPE::V_PULSE:
|
|
|
|
case TYPE::I_PULSE:
|
|
|
|
case TYPE::V_EXP:
|
|
|
|
case TYPE::I_EXP:
|
|
|
|
/*case TYPE::V_SFAM:
|
|
|
|
case TYPE::I_SFAM:
|
|
|
|
case TYPE::V_SFFM:
|
|
|
|
case TYPE::I_SFFM:*/
|
|
|
|
case TYPE::V_PWL:
|
|
|
|
case TYPE::I_PWL:
|
|
|
|
case TYPE::V_WHITENOISE:
|
|
|
|
case TYPE::I_WHITENOISE:
|
|
|
|
case TYPE::V_PINKNOISE:
|
|
|
|
case TYPE::I_PINKNOISE:
|
|
|
|
case TYPE::V_BURSTNOISE:
|
|
|
|
case TYPE::I_BURSTNOISE:
|
|
|
|
case TYPE::V_RANDUNIFORM:
|
|
|
|
case TYPE::I_RANDUNIFORM:
|
|
|
|
case TYPE::V_RANDNORMAL:
|
|
|
|
case TYPE::I_RANDNORMAL:
|
|
|
|
case TYPE::V_RANDEXP:
|
|
|
|
case TYPE::I_RANDEXP:
|
|
|
|
//case TYPE::V_RANDPOISSON:
|
|
|
|
//case TYPE::I_RANDPOISSON:
|
|
|
|
return std::make_unique<SIM_MODEL_SOURCE>( aType );
|
|
|
|
|
|
|
|
case TYPE::SUBCKT:
|
2022-09-19 05:18:06 +00:00
|
|
|
return std::make_unique<SIM_MODEL_SUBCKT>();
|
2022-09-18 19:22:59 +00:00
|
|
|
|
|
|
|
case TYPE::XSPICE:
|
|
|
|
return std::make_unique<SIM_MODEL_XSPICE>( aType );
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
case TYPE::KIBIS_DEVICE:
|
2022-09-30 12:29:44 +00:00
|
|
|
case TYPE::KIBIS_DRIVER_DC:
|
|
|
|
case TYPE::KIBIS_DRIVER_RECT:
|
|
|
|
case TYPE::KIBIS_DRIVER_PRBS:
|
2022-09-27 20:47:00 +00:00
|
|
|
return std::make_unique<SIM_MODEL_KIBIS>( aType );
|
|
|
|
|
2022-09-18 19:22:59 +00:00
|
|
|
case TYPE::RAWSPICE:
|
|
|
|
return std::make_unique<SIM_MODEL_RAW_SPICE>();
|
|
|
|
|
|
|
|
default:
|
|
|
|
return std::make_unique<SIM_MODEL_NGSPICE>( aType );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, bool aResolve )
|
|
|
|
{
|
|
|
|
std::unique_ptr<SIM_MODEL> model = doCreate( aType );
|
|
|
|
|
|
|
|
if( !aResolve )
|
|
|
|
{
|
|
|
|
for( PARAM& param : model->m_params )
|
|
|
|
{
|
|
|
|
param.source = param.value->ToString();
|
|
|
|
param.resolved = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-15 03:25:57 +00:00
|
|
|
SIM_MODEL::SIM_MODEL( TYPE aType ) :
|
|
|
|
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ) )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator ) :
|
2022-09-14 07:19:25 +00:00
|
|
|
m_baseModel( nullptr ),
|
2022-09-29 11:06:50 +00:00
|
|
|
m_spiceGenerator( std::move( aSpiceGenerator ) ),
|
2022-09-14 07:19:25 +00:00
|
|
|
m_type( aType ),
|
|
|
|
m_isEnabled( true ),
|
|
|
|
m_isInferred( false )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-11 00:42:16 +00:00
|
|
|
void SIM_MODEL::CreatePins( unsigned aSymbolPinCount )
|
|
|
|
{
|
|
|
|
// Default pin sequence: model pins are the same as symbol pins.
|
|
|
|
// Excess model pins are set as Not Connected.
|
|
|
|
// Note that intentionally nothing is added if `getPinNames()` returns an empty vector.
|
2022-08-26 01:26:54 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
// SIM_MODEL pins must be ordered by symbol pin numbers -- this is assumed by the code that
|
2022-08-26 01:26:54 +00:00
|
|
|
// accesses them.
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( unsigned modelPinIndex = 0; modelPinIndex < getPinNames().size(); ++modelPinIndex )
|
2022-08-11 00:42:16 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
if( modelPinIndex < aSymbolPinCount )
|
2022-09-22 05:38:45 +00:00
|
|
|
AddPin( { getPinNames().at( modelPinIndex ), fmt::format( "{}", modelPinIndex + 1 ) } );
|
2022-08-11 00:42:16 +00:00
|
|
|
else
|
2022-08-22 05:40:23 +00:00
|
|
|
AddPin( { getPinNames().at( modelPinIndex ), "" } );
|
2022-08-11 00:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
template void SIM_MODEL::WriteInferredDataFields( std::vector<SCH_FIELD>& aFields,
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string& aValue ) const;
|
2022-05-08 09:54:35 +00:00
|
|
|
template void SIM_MODEL::WriteInferredDataFields( std::vector<LIB_FIELD>& aFields,
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string& aValue ) const;
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-09-22 05:38:45 +00:00
|
|
|
void SIM_MODEL::WriteInferredDataFields( std::vector<T>& aFields, const std::string& aValue ) const
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-10-25 06:49:41 +00:00
|
|
|
bool removePinsField = true;
|
|
|
|
|
|
|
|
// Only write Sim_Pins field if the pins are not in the canonical order.
|
|
|
|
for( int i = 0; i < GetPinCount(); ++i )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-10-25 06:49:41 +00:00
|
|
|
if( GetPin( i ).symbolPinNumber != fmt::format( "{}", i + 1 ) )
|
|
|
|
{
|
|
|
|
removePinsField = false;
|
|
|
|
break;
|
|
|
|
}
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-10-25 06:49:41 +00:00
|
|
|
if( removePinsField )
|
|
|
|
SetFieldValue( aFields, PINS_FIELD, "" );
|
|
|
|
|
2022-10-26 06:58:00 +00:00
|
|
|
std::string value = aValue;
|
|
|
|
|
|
|
|
if( value == "" )
|
|
|
|
value = GenerateValueField( "=" );
|
|
|
|
|
|
|
|
SetFieldValue( aFields, VALUE_FIELD, value );
|
2022-05-08 09:54:35 +00:00
|
|
|
SetFieldValue( aFields, DEVICE_TYPE_FIELD, "" );
|
|
|
|
SetFieldValue( aFields, TYPE_FIELD, "" );
|
|
|
|
SetFieldValue( aFields, PARAMS_FIELD, "" );
|
2022-10-15 22:45:54 +00:00
|
|
|
SetFieldValue( aFields, ENABLE_FIELD, "" );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::GenerateParamValuePair( const PARAM& aParam, bool& aIsFirst ) const
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string result;
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
if( aIsFirst )
|
|
|
|
aIsFirst = false;
|
|
|
|
else
|
2022-09-22 05:38:45 +00:00
|
|
|
result.append( " " );
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string name = aParam.info.name;
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
// Because of collisions with instance parameters, we append some model parameters with "_".
|
2022-09-22 05:38:45 +00:00
|
|
|
if( boost::ends_with( aParam.info.name, "_" ) )
|
|
|
|
name = aParam.info.name.substr( 0, aParam.info.name.length() - 1);
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
std::string value = aParam.resolved ? aParam.value->ToString() : aParam.source.ToStdString();
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
if( value.find( " " ) != std::string::npos )
|
2022-06-21 02:22:52 +00:00
|
|
|
value = "\"" + value + "\"";
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
result.append( fmt::format( "{}={}", name, value ) );
|
2022-05-08 09:54:35 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-26 06:58:00 +00:00
|
|
|
std::string SIM_MODEL::GenerateValueField( const std::string& aPairSeparator ) const
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
for( int i = 0; i < GetParamCount(); ++i )
|
|
|
|
{
|
|
|
|
const PARAM& param = GetParam( i );
|
|
|
|
|
|
|
|
if( i == 0 && hasPrimaryValue() )
|
|
|
|
{
|
|
|
|
result.append( param.value->ToString() );
|
|
|
|
isFirst = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( param.value->ToString() == "" )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result.append( GenerateParamValuePair( param, isFirst ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result == "" )
|
|
|
|
result = GetDeviceTypeInfo().fieldValue;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::GenerateParamsField( const std::string& aPairSeparator ) const
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string result;
|
2022-05-08 09:54:35 +00:00
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
for( const PARAM& param : m_params )
|
|
|
|
{
|
2022-10-31 22:31:29 +00:00
|
|
|
std::string value = param.resolved ? param.value->ToString() : param.source.ToStdString();
|
|
|
|
|
|
|
|
if( value.empty() )
|
2022-05-08 09:54:35 +00:00
|
|
|
continue;
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
result.append( GenerateParamValuePair( param, isFirst ) );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
void SIM_MODEL::ParseParamsField( const std::string& aParamsField )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
tao::pegtl::string_input<> in( aParamsField, "Sim_Params" );
|
2022-05-08 09:54:35 +00:00
|
|
|
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Using parse tree instead of actions because we don't care about performance that much,
|
2022-10-21 06:14:13 +00:00
|
|
|
// and having a tree greatly simplifies things.
|
2022-10-31 22:31:29 +00:00
|
|
|
root = tao::pegtl::parse_tree::parse< SIM_MODEL_PARSER::fieldParamValuePairsGrammar,
|
|
|
|
SIM_MODEL_PARSER::fieldParamValuePairsSelector,
|
|
|
|
tao::pegtl::nothing,
|
|
|
|
SIM_MODEL_PARSER::control>( in );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
catch( const tao::pegtl::parse_error& e )
|
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
THROW_IO_ERROR( e.what() );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string paramName;
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
for( const auto& node : root->children )
|
|
|
|
{
|
|
|
|
if( node->is_type<SIM_MODEL_PARSER::param>() )
|
2022-10-31 22:31:29 +00:00
|
|
|
{
|
2022-05-08 09:54:35 +00:00
|
|
|
paramName = node->string();
|
2022-10-31 22:31:29 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
// TODO: Do something with number<SIM_VALUE::TYPE_INT, ...>.
|
2022-05-08 09:54:35 +00:00
|
|
|
// It doesn't seem too useful?
|
2022-09-29 11:06:50 +00:00
|
|
|
else if( node->is_type<SIM_MODEL_PARSER::quotedStringContent>()
|
2022-05-08 09:54:35 +00:00
|
|
|
|| node->is_type<SIM_MODEL_PARSER::unquotedString>() )
|
|
|
|
{
|
2022-05-31 02:55:48 +00:00
|
|
|
wxASSERT( paramName != "" );
|
2022-05-08 09:54:35 +00:00
|
|
|
// TODO: Shouldn't be named "...fromSpiceCode" here...
|
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
if( FindParam( paramName )->resolved )
|
|
|
|
SetParamValue( paramName, node->string(), SIM_VALUE_GRAMMAR::NOTATION::SI );
|
|
|
|
else
|
|
|
|
SetParamSource( paramName, node->string() );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
else if( node->is_type<SIM_MODEL_PARSER::quotedString>() )
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string str = node->string();
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
// Unescape quotes.
|
2022-09-22 05:38:45 +00:00
|
|
|
boost::replace_all( str, "\\\"", "\"" );
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-10-31 22:31:29 +00:00
|
|
|
if( FindParam( paramName )->resolved )
|
|
|
|
SetParamValue( paramName, str, SIM_VALUE_GRAMMAR::NOTATION::SI );
|
|
|
|
else
|
|
|
|
SetParamSource( paramName, str );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
void SIM_MODEL::ParsePinsField( unsigned aSymbolPinCount, const std::string& aPinsField )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-08-11 00:42:16 +00:00
|
|
|
CreatePins( aSymbolPinCount );
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( aPinsField == "" )
|
|
|
|
return;
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
tao::pegtl::string_input<> in( aPinsField, PINS_FIELD );
|
2022-05-08 09:54:35 +00:00
|
|
|
std::unique_ptr<tao::pegtl::parse_tree::node> root;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
root = tao::pegtl::parse_tree::parse<SIM_MODEL_PARSER::pinSequenceGrammar,
|
2022-10-15 17:31:15 +00:00
|
|
|
SIM_MODEL_PARSER::pinSequenceSelector,
|
|
|
|
tao::pegtl::nothing,
|
|
|
|
SIM_MODEL_PARSER::control>( in );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
catch( const tao::pegtl::parse_error& e )
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
THROW_IO_ERROR( e.what() );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( static_cast<int>( root->children.size() ) != GetPinCount() )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format( _( "%s describes %lu pins, expected %u" ),
|
|
|
|
PINS_FIELD,
|
|
|
|
root->children.size(),
|
|
|
|
GetPinCount() ) );
|
|
|
|
}
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int pinIndex = 0; pinIndex < static_cast<int>( root->children.size() ); ++pinIndex )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
if( root->children.at( pinIndex )->string() == "~" )
|
|
|
|
SetPinSymbolPinNumber( pinIndex, "" );
|
2022-05-08 09:54:35 +00:00
|
|
|
else
|
2022-08-22 05:40:23 +00:00
|
|
|
SetPinSymbolPinNumber( pinIndex, root->children.at( pinIndex )->string() );
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-10-15 22:45:54 +00:00
|
|
|
void SIM_MODEL::ParseEnableField( const std::string& aEnableField )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-15 22:45:54 +00:00
|
|
|
if( aEnableField == "" )
|
2022-06-21 02:22:52 +00:00
|
|
|
return;
|
|
|
|
|
2022-10-15 22:45:54 +00:00
|
|
|
char c = boost::to_lower_copy( aEnableField )[0];
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-10-15 22:45:54 +00:00
|
|
|
if( c == 'n' || c == 'f' || c == '0' )
|
2022-06-21 02:22:52 +00:00
|
|
|
m_isEnabled = false;
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void SIM_MODEL::doReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-10-15 22:45:54 +00:00
|
|
|
ParseEnableField( GetFieldValue( aFields, ENABLE_FIELD ) );
|
2022-10-15 17:31:15 +00:00
|
|
|
ParsePinsField( aSymbolPinCount, GetFieldValue( aFields, PINS_FIELD ) );
|
2022-08-28 12:51:03 +00:00
|
|
|
|
|
|
|
if( GetFieldValue( aFields, PARAMS_FIELD ) != "" )
|
|
|
|
ParseParamsField( GetFieldValue( aFields, PARAMS_FIELD ) );
|
|
|
|
else
|
2022-10-26 06:58:00 +00:00
|
|
|
InferredReadDataFields( aSymbolPinCount, aFields );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template <typename T>
|
2022-10-26 06:58:00 +00:00
|
|
|
void SIM_MODEL::InferredReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-15 17:31:15 +00:00
|
|
|
// TODO: Make a subclass SIM_MODEL_NONE.
|
|
|
|
if( GetType() == SIM_MODEL::TYPE::NONE )
|
|
|
|
return;
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
// TODO: Don't call this multiple times.
|
2022-06-21 02:22:52 +00:00
|
|
|
if( InferTypeFromRefAndValue( GetFieldValue( aFields, REFERENCE_FIELD ),
|
2022-10-22 02:33:26 +00:00
|
|
|
GetFieldValue( aFields, VALUE_FIELD ),
|
|
|
|
aSymbolPinCount ) != GetType() )
|
2022-08-24 04:13:55 +00:00
|
|
|
{
|
|
|
|
// Not an inferred model. Nothing to do here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-15 17:31:15 +00:00
|
|
|
try
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-15 17:31:15 +00:00
|
|
|
// TODO: Don't call this multiple times.
|
|
|
|
tao::pegtl::string_input<> in( GetFieldValue( aFields, VALUE_FIELD ), VALUE_FIELD );
|
|
|
|
auto root = tao::pegtl::parse_tree::parse<SIM_MODEL_PARSER::fieldInferValueGrammar,
|
|
|
|
SIM_MODEL_PARSER::fieldInferValueSelector,
|
|
|
|
tao::pegtl::nothing,
|
|
|
|
SIM_MODEL_PARSER::control>( in );
|
|
|
|
|
|
|
|
for( const auto& node : root->children )
|
2022-08-24 04:13:55 +00:00
|
|
|
{
|
2022-10-23 23:10:17 +00:00
|
|
|
if( node->is_type<SIM_MODEL_PARSER::fieldInferValuePrimaryValue>() )
|
2022-09-02 18:19:50 +00:00
|
|
|
{
|
2022-10-26 06:58:00 +00:00
|
|
|
if( hasPrimaryValue() )
|
2022-10-15 17:31:15 +00:00
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
for( const auto& subnode : node->children )
|
2022-10-15 17:31:15 +00:00
|
|
|
{
|
|
|
|
if( subnode->is_type<SIM_MODEL_PARSER::number<SIM_VALUE::TYPE_FLOAT,
|
|
|
|
SIM_VALUE::NOTATION::SI>>() )
|
|
|
|
{
|
|
|
|
SetParamValue( 0, subnode->string() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-21 06:14:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR(
|
2022-10-23 23:10:17 +00:00
|
|
|
wxString::Format( _( "Simulation model of type '%s' cannot have a primary value (which is '%s') in Value field" ),
|
2022-10-21 06:14:13 +00:00
|
|
|
GetTypeInfo().fieldValue,
|
|
|
|
node->string() ) );
|
|
|
|
}
|
2022-09-02 18:19:50 +00:00
|
|
|
}
|
2022-10-21 06:14:13 +00:00
|
|
|
else if( node->is_type<SIM_MODEL_PARSER::fieldParamValuePairs>() )
|
2022-10-31 22:31:29 +00:00
|
|
|
{
|
2022-10-21 06:14:13 +00:00
|
|
|
ParseParamsField( node->string() );
|
2022-10-31 22:31:29 +00:00
|
|
|
}
|
2022-08-24 04:13:55 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
2022-10-15 17:31:15 +00:00
|
|
|
catch( const tao::pegtl::parse_error& e )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-15 17:31:15 +00:00
|
|
|
THROW_IO_ERROR( e.what() );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
2022-08-24 04:13:55 +00:00
|
|
|
|
2022-10-21 06:14:13 +00:00
|
|
|
SetIsInferred( true );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
SetFieldValue( aFields, DEVICE_TYPE_FIELD, generateDeviceTypeField() );
|
|
|
|
SetFieldValue( aFields, TYPE_FIELD, generateTypeField() );
|
|
|
|
SetFieldValue( aFields, PINS_FIELD, generatePinsField() );
|
2022-05-08 09:54:35 +00:00
|
|
|
SetFieldValue( aFields, PARAMS_FIELD, GenerateParamsField( " " ) );
|
2022-10-15 22:45:54 +00:00
|
|
|
SetFieldValue( aFields, ENABLE_FIELD, generateEnableField() );
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::generateDeviceTypeField() const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
return DeviceTypeInfo( TypeInfo( m_type ).deviceType ).fieldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::generateTypeField() const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
return TypeInfo( m_type ).fieldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string SIM_MODEL::generatePinsField() const
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string result = "";
|
2022-03-09 01:40:59 +00:00
|
|
|
bool isFirst = true;
|
|
|
|
|
2022-08-23 22:06:16 +00:00
|
|
|
for( const PIN& pin : GetPins() )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
|
|
|
if( isFirst )
|
|
|
|
isFirst = false;
|
|
|
|
else
|
2022-09-22 05:38:45 +00:00
|
|
|
result.append( " " );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-23 22:06:16 +00:00
|
|
|
if( pin.symbolPinNumber == "" )
|
2022-09-22 05:38:45 +00:00
|
|
|
result.append( "~" );
|
2022-03-09 01:40:59 +00:00
|
|
|
else
|
2022-09-22 05:38:45 +00:00
|
|
|
result.append( pin.symbolPinNumber ); // Note that it's numbered from 1.
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2022-05-31 02:55:48 +00:00
|
|
|
|
|
|
|
|
2022-10-15 22:45:54 +00:00
|
|
|
std::string SIM_MODEL::generateEnableField() const
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-10-15 22:45:54 +00:00
|
|
|
return m_isEnabled ? "" : "0";
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-14 01:15:42 +00:00
|
|
|
bool SIM_MODEL::requiresSpiceModelLine() const
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
|
|
|
for( const PARAM& param : GetParams() )
|
|
|
|
{
|
|
|
|
if( !param.info.isSpiceInstanceParam )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|