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
|
2022-12-08 23:56:55 +00:00
|
|
|
* Copyright (C) 2022 CERN
|
2023-01-12 12:46:52 +00:00
|
|
|
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2022-02-21 03:58:31 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2022-11-19 10:25:58 +00:00
|
|
|
#include <lib_symbol.h>
|
2022-12-08 23:56:55 +00:00
|
|
|
#include <sch_symbol.h>
|
2022-11-19 10:25:58 +00:00
|
|
|
#include <confirm.h>
|
2022-12-08 23:56:55 +00:00
|
|
|
#include <string_utils.h>
|
2022-12-09 20:58:47 +00:00
|
|
|
#include <wx/regex.h>
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
#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-11-21 04:01:12 +00:00
|
|
|
#include <sim/sim_model_l_mutual.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-12-14 13:00:25 +00:00
|
|
|
#include <sim/sim_lib_mgr.h>
|
2022-10-25 09:45:40 +00:00
|
|
|
#include <sim/sim_library_kibis.h>
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
#include <fmt/core.h>
|
2022-06-12 03:39:13 +00:00
|
|
|
#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-12-22 20:21:10 +00:00
|
|
|
#include "sim_model_spice_fallback.h"
|
2022-08-28 12:51:03 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
using TYPE = SIM_MODEL::TYPE;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
SIM_MODEL::DEVICE_INFO SIM_MODEL::DeviceInfo( DEVICE_T aDeviceType )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
|
|
|
switch( aDeviceType )
|
|
|
|
{
|
2022-12-06 14:59:49 +00:00
|
|
|
case DEVICE_T::NONE: return { "", "", true };
|
|
|
|
case DEVICE_T::R: return { "R", "Resistor", true };
|
|
|
|
case DEVICE_T::C: return { "C", "Capacitor", true };
|
|
|
|
case DEVICE_T::L: return { "L", "Inductor", true };
|
|
|
|
case DEVICE_T::TLINE: return { "TLINE", "Transmission Line", true };
|
|
|
|
case DEVICE_T::SW: return { "SW", "Switch", true };
|
|
|
|
|
|
|
|
case DEVICE_T::D: return { "D", "Diode", true };
|
|
|
|
case DEVICE_T::NPN: return { "NPN", "NPN BJT", true };
|
|
|
|
case DEVICE_T::PNP: return { "PNP", "PNP BJT", true };
|
|
|
|
|
|
|
|
case DEVICE_T::NJFET: return { "NJFET", "N-channel JFET", true };
|
|
|
|
case DEVICE_T::PJFET: return { "PJFET", "P-channel JFET", true };
|
|
|
|
|
|
|
|
case DEVICE_T::NMOS: return { "NMOS", "N-channel MOSFET", true };
|
|
|
|
case DEVICE_T::PMOS: return { "PMOS", "P-channel MOSFET", true };
|
|
|
|
case DEVICE_T::NMES: return { "NMES", "N-channel MESFET", true };
|
|
|
|
case DEVICE_T::PMES: return { "PMES", "P-channel MESFET", true };
|
|
|
|
|
|
|
|
case DEVICE_T::V: return { "V", "Voltage Source", true };
|
|
|
|
case DEVICE_T::I: return { "I", "Current Source", true };
|
|
|
|
|
2022-12-31 16:53:37 +00:00
|
|
|
case DEVICE_T::KIBIS: return { "IBIS", "IBIS Model", false };
|
2022-12-06 14:59:49 +00:00
|
|
|
|
|
|
|
case DEVICE_T::SUBCKT: return { "SUBCKT", "Subcircuit", false };
|
|
|
|
case DEVICE_T::XSPICE: return { "XSPICE", "XSPICE Code Model", true };
|
|
|
|
case DEVICE_T::SPICE: return { "SPICE", "Raw Spice Element", true };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-09 20:58:47 +00:00
|
|
|
default: wxFAIL; return {};
|
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_MODEL::INFO SIM_MODEL::TypeInfo( TYPE aType )
|
|
|
|
{
|
|
|
|
switch( aType )
|
2022-09-29 11:06:50 +00:00
|
|
|
{
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::NONE: return { DEVICE_T::NONE, "", "" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::R: return { DEVICE_T::R, "", "Ideal" };
|
|
|
|
case TYPE::R_POT: return { DEVICE_T::R, "POT", "Potentiometer" };
|
|
|
|
case TYPE::R_BEHAVIORAL: return { DEVICE_T::R, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::C: return { DEVICE_T::C, "", "Ideal" };
|
|
|
|
case TYPE::C_BEHAVIORAL: return { DEVICE_T::C, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::L: return { DEVICE_T::L, "", "Ideal" };
|
|
|
|
case TYPE::L_MUTUAL: return { DEVICE_T::L, "MUTUAL", "Mutual" };
|
|
|
|
case TYPE::L_BEHAVIORAL: return { DEVICE_T::L, "=", "Behavioral" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::TLINE_Z0: return { DEVICE_T::TLINE, "", "Characteristic impedance" };
|
|
|
|
case TYPE::TLINE_RLGC: return { DEVICE_T::TLINE, "RLGC", "RLGC" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::SW_V: return { DEVICE_T::SW, "V", "Voltage-controlled" };
|
|
|
|
case TYPE::SW_I: return { DEVICE_T::SW, "I", "Current-controlled" };
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::D: return { DEVICE_T::D, "", "" };
|
2022-09-29 11:06:50 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::NPN_VBIC: return { DEVICE_T::NPN, "VBIC", "VBIC" };
|
|
|
|
case TYPE::PNP_VBIC: return { DEVICE_T::PNP, "VBIC", "VBIC" };
|
|
|
|
case TYPE::NPN_GUMMELPOON: return { DEVICE_T::NPN, "GUMMELPOON", "Gummel-Poon" };
|
|
|
|
case TYPE::PNP_GUMMELPOON: return { DEVICE_T::PNP, "GUMMELPOON", "Gummel-Poon" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::BJT_MEXTRAM: return {};
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::NPN_HICUM2: return { DEVICE_T::NPN, "HICUML2", "HICUM level 2" };
|
|
|
|
case TYPE::PNP_HICUM2: return { DEVICE_T::PNP, "HICUML2", "HICUM level 2" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::BJT_HICUM_L0: return {};
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::NJFET_SHICHMANHODGES: return { DEVICE_T::NJFET, "SHICHMANHODGES", "Shichman-Hodges" };
|
|
|
|
case TYPE::PJFET_SHICHMANHODGES: return { DEVICE_T::PJFET, "SHICHMANHODGES", "Shichman-Hodges" };
|
|
|
|
case TYPE::NJFET_PARKERSKELLERN: return { DEVICE_T::NJFET, "PARKERSKELLERN", "Parker-Skellern" };
|
|
|
|
case TYPE::PJFET_PARKERSKELLERN: return { DEVICE_T::PJFET, "PARKERSKELLERN", "Parker-Skellern" };
|
|
|
|
|
|
|
|
case TYPE::NMES_STATZ: return { DEVICE_T::NMES, "STATZ", "Statz" };
|
|
|
|
case TYPE::PMES_STATZ: return { DEVICE_T::PMES, "STATZ", "Statz" };
|
|
|
|
case TYPE::NMES_YTTERDAL: return { DEVICE_T::NMES, "YTTERDAL", "Ytterdal" };
|
|
|
|
case TYPE::PMES_YTTERDAL: return { DEVICE_T::PMES, "YTTERDAL", "Ytterdal" };
|
|
|
|
case TYPE::NMES_HFET1: return { DEVICE_T::NMES, "HFET1", "HFET1" };
|
|
|
|
case TYPE::PMES_HFET1: return { DEVICE_T::PMES, "HFET1", "HFET1" };
|
|
|
|
case TYPE::NMES_HFET2: return { DEVICE_T::NMES, "HFET2", "HFET2" };
|
|
|
|
case TYPE::PMES_HFET2: return { DEVICE_T::PMES, "HFET2", "HFET2" };
|
|
|
|
|
|
|
|
case TYPE::NMOS_VDMOS: return { DEVICE_T::NMOS, "VDMOS", "VDMOS" };
|
|
|
|
case TYPE::PMOS_VDMOS: return { DEVICE_T::PMOS, "VDMOS", "VDMOS" };
|
|
|
|
case TYPE::NMOS_MOS1: return { DEVICE_T::NMOS, "MOS1", "Classical quadratic (MOS1)" };
|
|
|
|
case TYPE::PMOS_MOS1: return { DEVICE_T::PMOS, "MOS1", "Classical quadratic (MOS1)" };
|
|
|
|
case TYPE::NMOS_MOS2: return { DEVICE_T::NMOS, "MOS2", "Grove-Frohman (MOS2)" };
|
|
|
|
case TYPE::PMOS_MOS2: return { DEVICE_T::PMOS, "MOS2", "Grove-Frohman (MOS2)" };
|
|
|
|
case TYPE::NMOS_MOS3: return { DEVICE_T::NMOS, "MOS3", "MOS3" };
|
|
|
|
case TYPE::PMOS_MOS3: return { DEVICE_T::PMOS, "MOS3", "MOS3" };
|
|
|
|
case TYPE::NMOS_BSIM1: return { DEVICE_T::NMOS, "BSIM1", "BSIM1" };
|
|
|
|
case TYPE::PMOS_BSIM1: return { DEVICE_T::PMOS, "BSIM1", "BSIM1" };
|
|
|
|
case TYPE::NMOS_BSIM2: return { DEVICE_T::NMOS, "BSIM2", "BSIM2" };
|
|
|
|
case TYPE::PMOS_BSIM2: return { DEVICE_T::PMOS, "BSIM2", "BSIM2" };
|
|
|
|
case TYPE::NMOS_MOS6: return { DEVICE_T::NMOS, "MOS6", "MOS6" };
|
|
|
|
case TYPE::PMOS_MOS6: return { DEVICE_T::PMOS, "MOS6", "MOS6" };
|
|
|
|
case TYPE::NMOS_BSIM3: return { DEVICE_T::NMOS, "BSIM3", "BSIM3" };
|
|
|
|
case TYPE::PMOS_BSIM3: return { DEVICE_T::PMOS, "BSIM3", "BSIM3" };
|
|
|
|
case TYPE::NMOS_MOS9: return { DEVICE_T::NMOS, "MOS9", "MOS9" };
|
|
|
|
case TYPE::PMOS_MOS9: return { DEVICE_T::PMOS, "MOS9", "MOS9" };
|
|
|
|
case TYPE::NMOS_B4SOI: return { DEVICE_T::NMOS, "B4SOI", "BSIM4 SOI (B4SOI)" };
|
|
|
|
case TYPE::PMOS_B4SOI: return { DEVICE_T::PMOS, "B4SOI", "BSIM4 SOI (B4SOI)" };
|
|
|
|
case TYPE::NMOS_BSIM4: return { DEVICE_T::NMOS, "BSIM4", "BSIM4" };
|
|
|
|
case TYPE::PMOS_BSIM4: return { DEVICE_T::PMOS, "BSIM4", "BSIM4" };
|
2023-02-22 13:19: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-12-06 14:59:49 +00:00
|
|
|
case TYPE::NMOS_B3SOIFD: return { DEVICE_T::NMOS, "B3SOIFD", "B3SOIFD (BSIM3 FD-SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIFD: return { DEVICE_T::PMOS, "B3SOIFD", "B3SOIFD (BSIM3 FD-SOI)" };
|
|
|
|
case TYPE::NMOS_B3SOIDD: return { DEVICE_T::NMOS, "B3SOIDD", "B3SOIDD (BSIM3 SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIDD: return { DEVICE_T::PMOS, "B3SOIDD", "B3SOIDD (BSIM3 SOI)" };
|
|
|
|
case TYPE::NMOS_B3SOIPD: return { DEVICE_T::NMOS, "B3SOIPD", "B3SOIPD (BSIM3 PD-SOI)" };
|
|
|
|
case TYPE::PMOS_B3SOIPD: return { DEVICE_T::PMOS, "B3SOIPD", "B3SOIPD (BSIM3 PD-SOI)" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::NMOS_STAG: return {};
|
|
|
|
//case TYPE::PMOS_STAG: return {};
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::NMOS_HISIM2: return { DEVICE_T::NMOS, "HISIM2", "HiSIM2" };
|
|
|
|
case TYPE::PMOS_HISIM2: return { DEVICE_T::PMOS, "HISIM2", "HiSIM2" };
|
|
|
|
case TYPE::NMOS_HISIMHV1: return { DEVICE_T::NMOS, "HISIMHV1", "HiSIM_HV1" };
|
|
|
|
case TYPE::PMOS_HISIMHV1: return { DEVICE_T::PMOS, "HISIMHV1", "HiSIM_HV1" };
|
|
|
|
case TYPE::NMOS_HISIMHV2: return { DEVICE_T::NMOS, "HISIMHV2", "HiSIM_HV2" };
|
|
|
|
case TYPE::PMOS_HISIMHV2: return { DEVICE_T::PMOS, "HISIMHV2", "HiSIM_HV2" };
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
case TYPE::V: return { DEVICE_T::V, "DC", "DC", };
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::V_SIN: return { DEVICE_T::V, "SIN", "Sine" };
|
|
|
|
case TYPE::V_PULSE: return { DEVICE_T::V, "PULSE", "Pulse" };
|
|
|
|
case TYPE::V_EXP: return { DEVICE_T::V, "EXP", "Exponential" };
|
2023-02-22 13:19:31 +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-12-06 14:59:49 +00:00
|
|
|
case TYPE::V_PWL: return { DEVICE_T::V, "PWL", "Piecewise linear" };
|
|
|
|
case TYPE::V_WHITENOISE: return { DEVICE_T::V, "WHITENOISE", "White noise" };
|
|
|
|
case TYPE::V_PINKNOISE: return { DEVICE_T::V, "PINKNOISE", "Pink noise (1/f)" };
|
|
|
|
case TYPE::V_BURSTNOISE: return { DEVICE_T::V, "BURSTNOISE", "Burst noise" };
|
|
|
|
case TYPE::V_RANDUNIFORM: return { DEVICE_T::V, "RANDUNIFORM", "Random uniform" };
|
|
|
|
case TYPE::V_RANDNORMAL: return { DEVICE_T::V, "RANDNORMAL", "Random normal" };
|
|
|
|
case TYPE::V_RANDEXP: return { DEVICE_T::V, "RANDEXP", "Random exponential" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::V_RANDPOISSON: return { DEVICE_TYPE::V, "RANDPOISSON", "Random Poisson" };
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::V_BEHAVIORAL: return { DEVICE_T::V, "=", "Behavioral" };
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
case TYPE::I: return { DEVICE_T::I, "DC", "DC", };
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::I_SIN: return { DEVICE_T::I, "SIN", "Sine" };
|
|
|
|
case TYPE::I_PULSE: return { DEVICE_T::I, "PULSE", "Pulse" };
|
|
|
|
case TYPE::I_EXP: return { DEVICE_T::I, "EXP", "Exponential" };
|
2023-02-22 13:19:31 +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-12-06 14:59:49 +00:00
|
|
|
case TYPE::I_PWL: return { DEVICE_T::I, "PWL", "Piecewise linear" };
|
|
|
|
case TYPE::I_WHITENOISE: return { DEVICE_T::I, "WHITENOISE", "White noise" };
|
|
|
|
case TYPE::I_PINKNOISE: return { DEVICE_T::I, "PINKNOISE", "Pink noise (1/f)" };
|
|
|
|
case TYPE::I_BURSTNOISE: return { DEVICE_T::I, "BURSTNOISE", "Burst noise" };
|
|
|
|
case TYPE::I_RANDUNIFORM: return { DEVICE_T::I, "RANDUNIFORM", "Random uniform" };
|
|
|
|
case TYPE::I_RANDNORMAL: return { DEVICE_T::I, "RANDNORMAL", "Random normal" };
|
|
|
|
case TYPE::I_RANDEXP: return { DEVICE_T::I, "RANDEXP", "Random exponential" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::I_RANDPOISSON: return { DEVICE_TYPE::I, "RANDPOISSON", "Random Poisson" };
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::I_BEHAVIORAL: return { DEVICE_T::I, "=", "Behavioral" };
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2023-02-04 20:55:52 +00:00
|
|
|
case TYPE::SUBCKT: return { DEVICE_T::SUBCKT, "", "Subcircuit" };
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::XSPICE: return { DEVICE_T::XSPICE, "", "" };
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::KIBIS_DEVICE: return { DEVICE_T::KIBIS, "DEVICE", "Device" };
|
|
|
|
case TYPE::KIBIS_DRIVER_DC: return { DEVICE_T::KIBIS, "DCDRIVER", "DC driver" };
|
|
|
|
case TYPE::KIBIS_DRIVER_RECT: return { DEVICE_T::KIBIS, "RECTDRIVER", "Rectangular wave driver" };
|
|
|
|
case TYPE::KIBIS_DRIVER_PRBS: return { DEVICE_T::KIBIS, "PRBSDRIVER", "PRBS driver" };
|
2022-09-30 12:29:44 +00:00
|
|
|
|
2022-12-06 14:59:49 +00:00
|
|
|
case TYPE::RAWSPICE: return { DEVICE_T::SPICE, "", "" };
|
2022-09-30 12:29:44 +00:00
|
|
|
|
2022-12-09 20:58:47 +00:00
|
|
|
default: wxFAIL; return {};
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_MODEL::SPICE_INFO SIM_MODEL::SpiceInfo( TYPE aType )
|
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::R: return { "R", "" };
|
|
|
|
case TYPE::R_POT: return { "A", "" };
|
|
|
|
case TYPE::R_BEHAVIORAL: return { "R", "", "", "0", false, true };
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::C: return { "C", "" };
|
|
|
|
case TYPE::C_BEHAVIORAL: return { "C", "", "", "0", false, true };
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::L: return { "L", "" };
|
|
|
|
case TYPE::L_MUTUAL: return { "K", "" };
|
|
|
|
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-11-28 03:45:00 +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_VBIC: return { "Q", "NPN", "", "4" };
|
|
|
|
case TYPE::PNP_VBIC: return { "Q", "PNP", "", "4" };
|
2022-11-29 09:10:33 +00:00
|
|
|
case TYPE::NPN_GUMMELPOON: return { "Q", "NPN", "", "1", true };
|
|
|
|
case TYPE::PNP_GUMMELPOON: return { "Q", "PNP", "", "1", true };
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::NPN_HICUM2: return { "Q", "NPN", "", "8" };
|
|
|
|
case TYPE::PNP_HICUM2: return { "Q", "PNP", "", "8" };
|
|
|
|
|
2023-02-22 13:19:31 +00:00
|
|
|
case TYPE::NJFET_SHICHMANHODGES: return { "J", "NJF", "", "1", true };
|
|
|
|
case TYPE::PJFET_SHICHMANHODGES: return { "J", "PJF", "", "1", true };
|
2023-02-03 17:12:13 +00:00
|
|
|
case TYPE::NJFET_PARKERSKELLERN: return { "J", "NJF", "", "2" };
|
|
|
|
case TYPE::PJFET_PARKERSKELLERN: return { "J", "PJF", "", "2" };
|
2022-11-28 03:45:00 +00:00
|
|
|
|
2023-02-22 13:19:31 +00:00
|
|
|
case TYPE::NMES_STATZ: return { "Z", "NMF", "", "1", true };
|
|
|
|
case TYPE::PMES_STATZ: return { "Z", "PMF", "", "1", true };
|
2022-11-28 03:45:00 +00:00
|
|
|
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_VDMOS: return { "M", "VDMOS NCHAN", };
|
|
|
|
case TYPE::PMOS_VDMOS: return { "M", "VDMOS PCHAN", };
|
2023-02-22 13:19:31 +00:00
|
|
|
case TYPE::NMOS_MOS1: return { "M", "NMOS", "", "1", true };
|
|
|
|
case TYPE::PMOS_MOS1: return { "M", "PMOS", "", "1", true };
|
2022-11-28 03:45:00 +00:00
|
|
|
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" };
|
2023-02-22 13:19: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-11-28 03:45:00 +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" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::NMOS_STAG: return {};
|
|
|
|
//case TYPE::PMOS_STAG: return {};
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::NMOS_HISIM2: return { "M", "NMOS", "", "68" };
|
|
|
|
case TYPE::PMOS_HISIM2: return { "M", "PMOS", "", "68" };
|
2023-02-03 18:18:54 +00:00
|
|
|
case TYPE::NMOS_HISIMHV1: return { "M", "NMOS", "", "73", false, false, "1.2.4" };
|
|
|
|
case TYPE::PMOS_HISIMHV1: return { "M", "PMOS", "", "73", false, false, "1.2.4" };
|
|
|
|
case TYPE::NMOS_HISIMHV2: return { "M", "NMOS", "", "73", false, false, "2.2.0" };
|
|
|
|
case TYPE::PMOS_HISIMHV2: return { "M", "PMOS", "", "73", false, false, "2.2.0" };
|
2022-11-28 03:45:00 +00:00
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
case TYPE::V: return { "V", "", "DC" };
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::V_SIN: return { "V", "", "SIN" };
|
|
|
|
case TYPE::V_PULSE: return { "V", "", "PULSE" };
|
|
|
|
case TYPE::V_EXP: return { "V", "", "EXP" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::V_SFAM: return { "V", "", "AM" };
|
|
|
|
//case TYPE::V_SFFM: return { "V", "", "SFFM" };
|
2022-11-28 03:45:00 +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" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::V_RANDPOISSON: return { "V", "", "TRRANDOM" };
|
2022-04-12 14:37:06 +00:00
|
|
|
case TYPE::V_BEHAVIORAL: return { "B" };
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
case TYPE::I: return { "I", "", "DC" };
|
2022-11-28 03:45:00 +00:00
|
|
|
case TYPE::I_PULSE: return { "I", "", "PULSE" };
|
|
|
|
case TYPE::I_SIN: return { "I", "", "SIN" };
|
|
|
|
case TYPE::I_EXP: return { "I", "", "EXP" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//case TYPE::I_SFAM: return { "V", "", "AM" };
|
|
|
|
//case TYPE::I_SFFM: return { "V", "", "SFFM" };
|
2022-11-28 03:45:00 +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" };
|
2023-02-22 13:19:31 +00:00
|
|
|
//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-12-09 20:58:47 +00:00
|
|
|
case TYPE::RAWSPICE: return {};
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-12-09 20:58:47 +00:00
|
|
|
default: wxFAIL; return {};
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-17 14:12:58 +00:00
|
|
|
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<SCH_FIELD>& aFields,
|
|
|
|
REPORTER* aReporter );
|
|
|
|
template TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<LIB_FIELD>& aFields,
|
|
|
|
REPORTER* aReporter );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2023-03-17 14:12:58 +00:00
|
|
|
TYPE SIM_MODEL::ReadTypeFromFields( const std::vector<T>& aFields, REPORTER* aReporter )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
std::string deviceTypeFieldValue = GetFieldValue( &aFields, SIM_DEVICE_TYPE_FIELD );
|
|
|
|
std::string typeFieldValue = GetFieldValue( &aFields, SIM_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 )
|
|
|
|
{
|
2022-11-20 21:06:21 +00:00
|
|
|
if( deviceTypeFieldValue == DeviceInfo( TypeInfo( type ).deviceType ).fieldValue )
|
2022-04-12 14:37:06 +00:00
|
|
|
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
|
|
|
|
2023-03-17 14:12:58 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
if( aFields.size() > REFERENCE_FIELD )
|
|
|
|
{
|
|
|
|
aReporter->Report( wxString::Format( _( "Error reading simulation model from symbol '%s':\n%s" ),
|
|
|
|
aFields[REFERENCE_FIELD].GetText(),
|
|
|
|
_( "Failed to read simulation model from fields." ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 07:37:58 +00:00
|
|
|
return TYPE::NONE;
|
2022-10-16 03:10:57 +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-12-17 15:21:35 +00:00
|
|
|
template <>
|
|
|
|
void SIM_MODEL::ReadDataFields( const std::vector<SCH_FIELD>* aFields,
|
|
|
|
const std::vector<LIB_PIN*>& aPins )
|
2022-07-31 23:43:52 +00:00
|
|
|
{
|
2022-12-17 15:21:35 +00:00
|
|
|
doReadDataFields( aFields, aPins );
|
2022-07-31 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
template <>
|
|
|
|
void SIM_MODEL::ReadDataFields( const std::vector<LIB_FIELD>* aFields,
|
|
|
|
const std::vector<LIB_PIN*>& aPins )
|
2022-11-18 07:37:58 +00:00
|
|
|
{
|
2022-12-17 15:21:35 +00:00
|
|
|
doReadDataFields( aFields, aPins );
|
2022-11-18 07:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-31 23:43:52 +00:00
|
|
|
template <>
|
|
|
|
void SIM_MODEL::WriteFields( std::vector<SCH_FIELD>& aFields ) const
|
|
|
|
{
|
2022-12-17 15:21:35 +00:00
|
|
|
doWriteFields( aFields );
|
2022-07-31 23:43:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void SIM_MODEL::WriteFields( std::vector<LIB_FIELD>& aFields ) const
|
|
|
|
{
|
|
|
|
doWriteFields( aFields );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( TYPE aType, const std::vector<LIB_PIN*>& aPins,
|
|
|
|
REPORTER* aReporter )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-11-07 18:33:31 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = Create( aType );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Passing nullptr to ReadDataFields will make it act as if all fields were empty.
|
|
|
|
model->ReadDataFields( static_cast<const std::vector<SCH_FIELD>*>( nullptr ), aPins );
|
|
|
|
}
|
2023-01-02 22:47:46 +00:00
|
|
|
catch( IO_ERROR& err )
|
2022-12-31 18:51:47 +00:00
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
if( aReporter )
|
|
|
|
aReporter->Report( err.What(), RPT_SEVERITY_ERROR );
|
|
|
|
else
|
|
|
|
DisplayErrorMessage( nullptr, err.What() );
|
2022-12-31 18:51:47 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
|
|
|
REPORTER* aReporter )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
TYPE type = aBaseModel ? aBaseModel->GetType() : TYPE::NONE;
|
2022-12-22 20:21:10 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model;
|
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
// A null base model means the model wasn't found in the library, so create a fallback
|
|
|
|
|
|
|
|
if( !aBaseModel || dynamic_cast<const SIM_MODEL_SPICE_FALLBACK*>( aBaseModel ) )
|
|
|
|
model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
|
|
|
|
else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) )
|
2022-12-31 18:51:47 +00:00
|
|
|
model = std::make_unique<SIM_MODEL_RAW_SPICE>();
|
2022-12-22 20:21:10 +00:00
|
|
|
else
|
2023-01-03 15:29:45 +00:00
|
|
|
model = Create( type );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-12-14 16:47:20 +00:00
|
|
|
try
|
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
if( aBaseModel )
|
|
|
|
model->SetBaseModel( *aBaseModel );
|
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
model->ReadDataFields( static_cast<const std::vector<SCH_FIELD>*>( nullptr ), aPins );
|
2022-12-14 16:47:20 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR& err )
|
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
if( aReporter )
|
|
|
|
aReporter->Report( err.What(), RPT_SEVERITY_ERROR );
|
|
|
|
else
|
|
|
|
DisplayErrorMessage( nullptr, err.What() );
|
2022-12-14 16:47:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
return model;
|
|
|
|
}
|
2022-04-12 14:37:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2023-01-03 15:29:45 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<T>& aFields,
|
|
|
|
REPORTER* aReporter )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2023-03-17 15:30:24 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model;
|
|
|
|
TYPE type;
|
2022-10-09 18:44:03 +00:00
|
|
|
|
2023-03-17 15:30:24 +00:00
|
|
|
if( aBaseModel )
|
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
type = aBaseModel->GetType();
|
2022-10-09 18:44:03 +00:00
|
|
|
|
2023-03-17 15:30:24 +00:00
|
|
|
// No REPORTER here; we're just checking to see if we have an override
|
|
|
|
if( ReadTypeFromFields( aFields, nullptr ) != TYPE::NONE )
|
|
|
|
type = ReadTypeFromFields( aFields, nullptr );
|
2022-12-22 20:21:10 +00:00
|
|
|
|
2023-03-17 15:30:24 +00:00
|
|
|
if( dynamic_cast<const SIM_MODEL_SPICE_FALLBACK*>( aBaseModel ) )
|
|
|
|
model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
|
|
|
|
else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) )
|
|
|
|
model = std::make_unique<SIM_MODEL_RAW_SPICE>();
|
|
|
|
else
|
|
|
|
model = Create( type );
|
2023-01-03 15:29:45 +00:00
|
|
|
|
2023-03-17 15:30:24 +00:00
|
|
|
model->SetBaseModel( *aBaseModel );
|
|
|
|
}
|
|
|
|
else // No base model means the model wasn't found in the library, so create a fallback
|
|
|
|
{
|
|
|
|
type = ReadTypeFromFields( aFields, aReporter );
|
2022-12-31 18:51:47 +00:00
|
|
|
model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
|
2023-03-17 15:30:24 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-12-14 16:47:20 +00:00
|
|
|
try
|
|
|
|
{
|
2022-12-31 18:51:47 +00:00
|
|
|
model->ReadDataFields( &aFields, aPins );
|
2022-12-14 16:47:20 +00:00
|
|
|
}
|
|
|
|
catch( IO_ERROR& err )
|
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
if( aReporter )
|
2023-03-17 14:12:58 +00:00
|
|
|
{
|
|
|
|
aReporter->Report( wxString::Format( _( "Error reading simulation model from "
|
|
|
|
"symbol '%s':\n%s" ),
|
|
|
|
aFields[REFERENCE_FIELD].GetText(),
|
|
|
|
err.Problem() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2022-12-14 16:47:20 +00:00
|
|
|
}
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<SCH_FIELD>& aFields,
|
|
|
|
REPORTER* aReporter );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const SIM_MODEL* aBaseModel,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<LIB_FIELD>& aFields,
|
|
|
|
REPORTER* aReporter );
|
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-12-17 15:21:35 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<T>& aFields,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-03 15:29:45 +00:00
|
|
|
bool aResolved, REPORTER* aReporter )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2023-03-17 14:12:58 +00:00
|
|
|
TYPE type = ReadTypeFromFields( aFields, aReporter );
|
2022-11-07 18:33:31 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( type );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
model->ReadDataFields( &aFields, aPins );
|
|
|
|
}
|
2023-01-02 09:12:16 +00:00
|
|
|
catch( const IO_ERROR& parse_err )
|
2022-12-31 18:51:47 +00:00
|
|
|
{
|
2023-01-03 15:29:45 +00:00
|
|
|
if( !aResolved )
|
|
|
|
{
|
|
|
|
aReporter->Report( parse_err.What(), RPT_SEVERITY_ERROR );
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
// Just because we can't parse it doesn't mean that a SPICE interpreter can't. Fall
|
|
|
|
// back to a raw spice code model.
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
std::string modelData = GetFieldValue( &aFields, SIM_PARAMS_FIELD );
|
2022-12-31 18:51:47 +00:00
|
|
|
|
|
|
|
if( modelData.empty() )
|
2023-01-05 14:16:06 +00:00
|
|
|
modelData = GetFieldValue( &aFields, SIM_VALUE_FIELD );
|
2022-12-31 18:51:47 +00:00
|
|
|
|
|
|
|
model = std::make_unique<SIM_MODEL_RAW_SPICE>( modelData );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
model->createPins( aPins );
|
2023-01-05 14:16:06 +00:00
|
|
|
model->m_serializer->ParsePins( GetFieldValue( &aFields, SIM_PINS_FIELD ) );
|
2022-12-31 18:51:47 +00:00
|
|
|
}
|
2023-01-02 09:12:16 +00:00
|
|
|
catch( const IO_ERROR& err )
|
2022-12-31 18:51:47 +00:00
|
|
|
{
|
2023-03-17 14:12:58 +00:00
|
|
|
// We own the pin syntax, so if we can't parse it then there's an error.
|
2023-01-02 22:47:46 +00:00
|
|
|
if( aReporter )
|
2023-03-17 14:12:58 +00:00
|
|
|
{
|
|
|
|
aReporter->Report( wxString::Format( _( "Error reading simulation model from "
|
|
|
|
"symbol '%s':\n%s" ),
|
|
|
|
aFields[REFERENCE_FIELD].GetText(),
|
|
|
|
err.Problem() ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2022-12-31 18:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
return model;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<SCH_FIELD>& aFields,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-03 15:29:45 +00:00
|
|
|
bool aResolved, REPORTER* aReporter );
|
2022-12-17 15:21:35 +00:00
|
|
|
template std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( const std::vector<LIB_FIELD>& aFields,
|
2023-01-02 22:47:46 +00:00
|
|
|
const std::vector<LIB_PIN*>& aPins,
|
2023-01-03 15:29:45 +00:00
|
|
|
bool aResolved, REPORTER* aReporter );
|
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>
|
2023-01-05 14:16:06 +00:00
|
|
|
std::string SIM_MODEL::GetFieldValue( const std::vector<T>* aFields, const wxString& aFieldName,
|
2022-12-19 18:10:57 +00:00
|
|
|
bool aResolve )
|
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-12-20 23:49:11 +00:00
|
|
|
for( const T& field : *aFields )
|
|
|
|
{
|
|
|
|
if( field.GetName() == aFieldName )
|
2023-02-23 16:56:47 +00:00
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
return aResolve ? field.GetShownText( false ).ToStdString()
|
2023-02-23 16:56:47 +00:00
|
|
|
: field.GetText().ToStdString();
|
|
|
|
}
|
2022-12-20 23:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This specialization is used when no fields are passed.
|
|
|
|
template <>
|
2023-01-05 14:16:06 +00:00
|
|
|
std::string SIM_MODEL::GetFieldValue( const std::vector<void>* aFields, const wxString& aFieldName,
|
|
|
|
bool aResolve )
|
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>
|
2023-01-05 14:16:06 +00:00
|
|
|
void SIM_MODEL::SetFieldValue( std::vector<T>& aFields, const wxString& aFieldName,
|
2022-09-22 05:38:45 +00:00
|
|
|
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 )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
aFields.emplace_back( aFields.size(), aFieldName );
|
2022-12-17 15:21:35 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
aFields.back().SetText( aValue );
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
template void SIM_MODEL::SetFieldValue<SCH_FIELD>( std::vector<SCH_FIELD>& aFields,
|
2023-01-05 14:16:06 +00:00
|
|
|
const wxString& aFieldName,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::string& aValue );
|
|
|
|
template void SIM_MODEL::SetFieldValue<LIB_FIELD>( std::vector<LIB_FIELD>& aFields,
|
2023-01-05 14:16:06 +00:00
|
|
|
const wxString& aFieldName,
|
2022-12-17 15:21:35 +00:00
|
|
|
const std::string& aValue );
|
|
|
|
|
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-12-08 23:56:55 +00:00
|
|
|
|
2022-11-25 04:31:03 +00:00
|
|
|
void SIM_MODEL::ClearPins()
|
2022-10-25 09:45:40 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-21 19:55:47 +00:00
|
|
|
void SIM_MODEL::AddParam( const PARAM::INFO& aInfo )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2023-02-21 19:55:47 +00:00
|
|
|
m_params.emplace_back( aInfo );
|
2022-11-30 11:40:50 +00:00
|
|
|
|
|
|
|
// Enums are initialized with their default values.
|
|
|
|
if( aInfo.enumValues.size() >= 1 )
|
2023-02-22 09:10:06 +00:00
|
|
|
m_params.back().value = aInfo.defaultValue;
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-04 20:55:52 +00:00
|
|
|
void SIM_MODEL::SetBaseModel( const SIM_MODEL& aBaseModel )
|
|
|
|
{
|
2023-03-17 14:12:58 +00:00
|
|
|
wxASSERT_MSG( GetType() == aBaseModel.GetType(),
|
|
|
|
wxS( "Simulation model type must be the same as its base class!" ) );
|
2023-02-04 20:55:52 +00:00
|
|
|
|
|
|
|
m_baseModel = &aBaseModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-25 04:31:03 +00:00
|
|
|
void SIM_MODEL::SetPinSymbolPinNumber( int aPinIndex, const std::string& aSymbolPinNumber )
|
|
|
|
{
|
2022-12-26 14:30:57 +00:00
|
|
|
if( aPinIndex >= 0 && aPinIndex < (int) m_pins.size() )
|
|
|
|
m_pins.at( aPinIndex ).symbolPinNumber = aSymbolPinNumber;
|
2022-11-25 04:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_MODEL::SetPinSymbolPinNumber( const std::string& aPinName,
|
|
|
|
const std::string& aSymbolPinNumber )
|
|
|
|
{
|
2022-12-22 20:21:10 +00:00
|
|
|
for( PIN& pin : m_pins )
|
2022-12-14 13:00:25 +00:00
|
|
|
{
|
2022-12-22 20:21:10 +00:00
|
|
|
if( pin.name == aPinName )
|
2022-12-14 13:00:25 +00:00
|
|
|
{
|
2022-12-22 20:21:10 +00:00
|
|
|
pin.symbolPinNumber = aSymbolPinNumber;
|
2022-12-20 23:49:11 +00:00
|
|
|
return;
|
2022-12-14 13:00:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
// If aPinName wasn't in fact a name, see if it's a raw (1-based) index. This is required
|
|
|
|
// for legacy files which didn't use pin names.
|
|
|
|
int aPinIndex = (int) strtol( aPinName.c_str(), nullptr, 10 );
|
2022-11-25 04:31:03 +00:00
|
|
|
|
2022-12-26 14:30:57 +00:00
|
|
|
if( aPinIndex < 1 || aPinIndex > (int) m_pins.size() )
|
2022-11-25 04:31:03 +00:00
|
|
|
{
|
2022-12-20 23:49:11 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a pin named '%s' in simulation "
|
|
|
|
"model of type '%s'" ),
|
2022-11-25 04:31:03 +00:00
|
|
|
aPinName,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
|
|
|
}
|
|
|
|
|
2022-12-22 20:21:10 +00:00
|
|
|
m_pins[ --aPinIndex /* convert to 0-based */ ].symbolPinNumber = aSymbolPinNumber;
|
2022-11-25 04:31:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
|
|
|
|
const SIM_MODEL::PARAM& SIM_MODEL::GetParam( unsigned aParamIndex ) const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2023-02-22 09:10:06 +00:00
|
|
|
if( m_baseModel && m_params.at( aParamIndex ).value == "" )
|
2022-11-07 18:33:31 +00:00
|
|
|
return m_baseModel->GetParam( aParamIndex );
|
|
|
|
else
|
|
|
|
return m_params.at( aParamIndex );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
int SIM_MODEL::doFindParam( const std::string& aParamName ) const
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
2022-12-16 16:31:39 +00:00
|
|
|
std::string lowerParamName = boost::to_lower_copy( aParamName );
|
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
|
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
for( int ii = 0; ii < (int) params.size(); ++ii )
|
2022-12-16 16:31:39 +00:00
|
|
|
{
|
2022-12-20 23:49:11 +00:00
|
|
|
if( params[ii].get().info.name == lowerParamName )
|
|
|
|
return ii;
|
2022-12-16 16:31:39 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
const SIM_MODEL::PARAM* SIM_MODEL::FindParam( const std::string& aParamName ) const
|
|
|
|
{
|
|
|
|
int idx = doFindParam( aParamName );
|
|
|
|
|
|
|
|
return idx >= 0 ? &GetParam( idx ) : nullptr;
|
2022-05-31 02:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
const SIM_MODEL::PARAM& SIM_MODEL::GetParamOverride( 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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-22 09:10:06 +00:00
|
|
|
void SIM_MODEL::doSetParamValue( int aParamIndex, const std::string& aValue )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2023-02-22 09:10:06 +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 )
|
|
|
|
{
|
2023-02-24 00:37:00 +00:00
|
|
|
// Note: also converts decimal separators to '.'
|
|
|
|
std::string value = SIM_VALUE::ConvertNotation( aValue, aNotation, SIM_VALUE::NOTATION::SI );
|
|
|
|
|
|
|
|
doSetParamValue( aParamIndex, value );
|
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 std::string& aValue,
|
2022-10-04 15:17:41 +00:00
|
|
|
SIM_VALUE::NOTATION aNotation )
|
|
|
|
{
|
2022-12-20 23:49:11 +00:00
|
|
|
int idx = doFindParam( aParamName );
|
2022-10-12 02:26:16 +00:00
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
if( idx < 0 )
|
2022-10-12 02:26:16 +00:00
|
|
|
{
|
2022-12-14 13:00:25 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "Could not find a parameter named '%s' in "
|
|
|
|
"simulation model of type '%s'" ),
|
2022-10-21 06:14:13 +00:00
|
|
|
aParamName,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
2022-10-12 02:26:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 23:49:11 +00:00
|
|
|
SetParamValue( idx, aValue, aNotation );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-07 18:33:31 +00:00
|
|
|
std::unique_ptr<SIM_MODEL> SIM_MODEL::Create( 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-11-19 10:25:58 +00:00
|
|
|
|
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:
|
2022-11-21 04:01:12 +00:00
|
|
|
return std::make_unique<SIM_MODEL_L_MUTUAL>();
|
2022-09-18 19:22:59 +00:00
|
|
|
|
|
|
|
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-09-15 03:25:57 +00:00
|
|
|
SIM_MODEL::SIM_MODEL( TYPE aType ) :
|
2022-12-08 23:56:55 +00:00
|
|
|
SIM_MODEL( aType, std::make_unique<SPICE_GENERATOR>( *this ),
|
2022-12-21 00:38:52 +00:00
|
|
|
std::make_unique<SIM_MODEL_SERIALIZER>( *this ) )
|
2022-11-11 02:07:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
|
|
|
|
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator ) :
|
2022-12-21 00:38:52 +00:00
|
|
|
SIM_MODEL( aType, std::move( aSpiceGenerator ),
|
|
|
|
std::make_unique<SIM_MODEL_SERIALIZER>( *this ) )
|
2022-09-15 03:25:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
SIM_MODEL::SIM_MODEL( TYPE aType, std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator,
|
2022-12-21 00:38:52 +00:00
|
|
|
std::unique_ptr<SIM_MODEL_SERIALIZER> aSerializer ) :
|
2022-11-11 02:07:34 +00:00
|
|
|
m_baseModel( nullptr ),
|
2022-12-21 00:38:52 +00:00
|
|
|
m_serializer( std::move( aSerializer ) ),
|
2022-11-11 02:07:34 +00:00
|
|
|
m_spiceGenerator( std::move( aSpiceGenerator ) ),
|
|
|
|
m_type( aType ),
|
2022-11-22 00:46:02 +00:00
|
|
|
m_isEnabled( true ),
|
|
|
|
m_isStoredInValue( false )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-22 20:21:10 +00:00
|
|
|
void SIM_MODEL::createPins( const std::vector<LIB_PIN*>& aSymbolPins )
|
2022-08-11 00:42:16 +00:00
|
|
|
{
|
|
|
|
// Default pin sequence: model pins are the same as symbol pins.
|
|
|
|
// Excess model pins are set as Not Connected.
|
2023-01-19 12:14:29 +00:00
|
|
|
// 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.
|
|
|
|
|
2023-01-19 12:14:29 +00:00
|
|
|
std::vector<std::string> pinNames = GetPinNames();
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-12-17 20:25:29 +00:00
|
|
|
for( unsigned modelPinIndex = 0; modelPinIndex < pinNames.size(); ++modelPinIndex )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2023-02-25 20:36:15 +00:00
|
|
|
wxString pinName = pinNames[ modelPinIndex ];
|
|
|
|
bool optional = false;
|
|
|
|
|
|
|
|
if( pinName.StartsWith( '<' ) && pinName.EndsWith( '>' ) )
|
|
|
|
{
|
|
|
|
pinName = pinName.Mid( 1, pinName.Length() - 2 );
|
|
|
|
optional = true;
|
|
|
|
}
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
if( modelPinIndex < aSymbolPins.size() )
|
|
|
|
{
|
2022-12-17 20:25:29 +00:00
|
|
|
AddPin( { pinNames.at( modelPinIndex ),
|
2022-12-17 15:21:35 +00:00
|
|
|
aSymbolPins[ modelPinIndex ]->GetNumber().ToStdString() } );
|
|
|
|
}
|
2023-02-25 20:36:15 +00:00
|
|
|
else if( !optional )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2022-12-17 20:25:29 +00:00
|
|
|
AddPin( { pinNames.at( modelPinIndex ), "" } );
|
2022-12-17 15:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void SIM_MODEL::doReadDataFields( const std::vector<T>* aFields,
|
|
|
|
const std::vector<LIB_PIN*>& aPins )
|
|
|
|
{
|
|
|
|
bool diffMode = GetFieldValue( aFields, SIM_LIBRARY_KIBIS::DIFF_FIELD ) == "1";
|
|
|
|
SwitchSingleEndedDiff( diffMode );
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
m_serializer->ParseEnable( GetFieldValue( aFields, SIM_ENABLE_FIELD ) );
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
createPins( aPins );
|
2023-01-05 14:16:06 +00:00
|
|
|
m_serializer->ParsePins( GetFieldValue( aFields, SIM_PINS_FIELD ) );
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
std::string paramsField = GetFieldValue( aFields, SIM_PARAMS_FIELD );
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-12-31 18:51:47 +00:00
|
|
|
if( !m_serializer->ParseParams( paramsField ) )
|
2023-01-09 15:22:18 +00:00
|
|
|
m_serializer->ParseValue( GetFieldValue( aFields, SIM_VALUE_FIELD ) );
|
2022-12-17 15:21: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::doWriteFields( std::vector<T>& aFields ) const
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
SetFieldValue( aFields, SIM_DEVICE_TYPE_FIELD, m_serializer->GenerateDevice() );
|
|
|
|
SetFieldValue( aFields, SIM_TYPE_FIELD, m_serializer->GenerateType() );
|
2022-11-18 07:37:58 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
SetFieldValue( aFields, SIM_ENABLE_FIELD, m_serializer->GenerateEnable() );
|
|
|
|
SetFieldValue( aFields, SIM_PINS_FIELD, m_serializer->GeneratePins() );
|
2022-11-18 07:37:58 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
SetFieldValue( aFields, SIM_PARAMS_FIELD, m_serializer->GenerateParams() );
|
2022-11-22 06:06:53 +00:00
|
|
|
|
2022-11-18 07:37:58 +00:00
|
|
|
if( IsStoredInValue() )
|
2023-01-05 14:16:06 +00:00
|
|
|
SetFieldValue( aFields, SIM_VALUE_FIELD, m_serializer->GenerateValue() );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-25 15:21:08 +00:00
|
|
|
bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
2023-04-22 20:23:42 +00:00
|
|
|
// SUBCKTs are a single level; there's never a baseModel.
|
|
|
|
if( m_type == TYPE::SUBCKT )
|
|
|
|
return false;
|
|
|
|
|
2023-03-01 13:30:22 +00:00
|
|
|
// Model must be written if there's no base model or the base model is an internal model
|
|
|
|
if( !m_baseModel || aItem.baseModelName == "" )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < GetParamCount(); ++ii )
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
2023-03-01 13:30:22 +00:00
|
|
|
const PARAM& param = m_params[ii];
|
|
|
|
|
|
|
|
// Instance parameters are written in item lines
|
|
|
|
if( param.info.isSpiceInstanceParam )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Empty parameters are interpreted as default-value
|
|
|
|
if ( param.value == "" )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const SIM_MODEL* baseModel = dynamic_cast<const SIM_MODEL*>( m_baseModel );
|
2023-03-04 18:02:05 +00:00
|
|
|
|
|
|
|
wxCHECK( baseModel, false );
|
|
|
|
|
2023-03-01 13:30:22 +00:00
|
|
|
std::string baseValue = baseModel->m_params[ii].value;
|
|
|
|
|
|
|
|
if( param.value == baseValue )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// One more check for equivalence, mostly for early 7.0 files which wrote all parameters
|
|
|
|
// to the Sim.Params field in normalized format
|
|
|
|
if( param.value == SIM_VALUE::Normalize( SIM_VALUE::ToDouble( baseValue ) ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Overrides must be written
|
|
|
|
return true;
|
2022-05-31 02:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
template <class T_symbol, class T_field>
|
2022-12-19 18:10:57 +00:00
|
|
|
bool SIM_MODEL::InferSimModel( T_symbol& aSymbol, std::vector<T_field>* aFields, bool aResolve,
|
2022-12-18 22:53:53 +00:00
|
|
|
SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString* aDeviceType,
|
|
|
|
wxString* aModelType, wxString* aModelParams, wxString* aPinMap )
|
2022-12-09 15:09:34 +00:00
|
|
|
{
|
2022-12-21 17:01:05 +00:00
|
|
|
// SPICE notation is case-insensitive and locale-insensitve. This means it uses "Meg" for
|
|
|
|
// mega (as both 'M' and 'm' must mean milli), and "." (always) for a decimal separator.
|
|
|
|
//
|
|
|
|
// KiCad's GUI uses the SI-standard 'M' for mega and 'm' for milli, and a locale-dependent
|
|
|
|
// decimal separator.
|
|
|
|
//
|
|
|
|
// KiCad's Sim.* fields are in-between, using SI notation but a fixed decimal separator.
|
|
|
|
//
|
|
|
|
// So where does that leave inferred value fields? Behavioural models must be passed in
|
|
|
|
// straight, because we don't (at present) know how to parse them.
|
|
|
|
//
|
|
|
|
// However, behavioural models _look_ like SPICE code, so it's not a stretch to expect them
|
|
|
|
// to _be_ SPICE code. A passive capacitor model on the other hand, just looks like a
|
|
|
|
// capacitance. Some users might expect 3,3u to work, while others might expect 3,300uF to
|
|
|
|
// work.
|
|
|
|
//
|
|
|
|
// Checking the locale isn't reliable because it assumes the current computer's locale is
|
|
|
|
// the same as the locale the schematic was authored in -- something that isn't true, for
|
|
|
|
// instance, when sharing designs over DIYAudio.com.
|
|
|
|
//
|
|
|
|
// However, even the E192 series of preferred values uses only 3 significant digits, so a ','
|
|
|
|
// or '.' followed by 3 digits _could_ reasonably-reliably be interpreted as a thousands
|
|
|
|
// separator.
|
|
|
|
//
|
|
|
|
// Or we could just say inferred values are locale-independent, with "." used as a decimal
|
|
|
|
// separator and "," used as a thousands separator. 3,300uF works, but 3,3 does not.
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
auto convertNotation =
|
|
|
|
[&]( const wxString& units ) -> wxString
|
|
|
|
{
|
2023-01-23 23:21:05 +00:00
|
|
|
/// KiCad Spice PEGTL only handles ASCII
|
|
|
|
/// Although these two look the same, they are U+03BC and U+00B5
|
|
|
|
if( units == wxS( "µ" ) || units == wxS( "μ" ) )
|
|
|
|
return wxS( "u" );
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
if( aNotation == SIM_VALUE_GRAMMAR::NOTATION::SPICE )
|
|
|
|
{
|
|
|
|
if( units == wxT( "M" ) )
|
|
|
|
return wxT( "Meg" );
|
|
|
|
}
|
|
|
|
else if( aNotation == SIM_VALUE_GRAMMAR::NOTATION::SI )
|
|
|
|
{
|
2022-12-21 17:01:05 +00:00
|
|
|
if( units.Capitalize() == wxT( "Meg" ) )
|
2022-12-18 22:53:53 +00:00
|
|
|
return wxT( "M" );
|
|
|
|
}
|
2022-12-14 23:21:35 +00:00
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
return units;
|
|
|
|
};
|
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
auto convertSeparators =
|
|
|
|
[]( wxString* mantissa )
|
|
|
|
{
|
|
|
|
mantissa->Replace( wxS( " " ), wxEmptyString );
|
|
|
|
|
2023-01-30 21:09:36 +00:00
|
|
|
wxChar ambiguousSeparator = '?';
|
2022-12-21 17:01:05 +00:00
|
|
|
wxChar thousandsSeparator = '?';
|
2023-01-30 21:09:36 +00:00
|
|
|
bool thousandsSeparatorFound = false;
|
2022-12-21 17:01:05 +00:00
|
|
|
wxChar decimalSeparator = '?';
|
2023-01-30 21:09:36 +00:00
|
|
|
bool decimalSeparatorFound = false;
|
|
|
|
int digits = 0;
|
2022-12-21 17:01:05 +00:00
|
|
|
|
2023-01-30 21:09:36 +00:00
|
|
|
for( int ii = (int) mantissa->length() - 1; ii >= 0; --ii )
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
|
|
|
wxChar c = mantissa->GetChar( ii );
|
|
|
|
|
2023-01-30 21:09:36 +00:00
|
|
|
if( c >= '0' && c <= '9' )
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
digits += 1;
|
|
|
|
}
|
|
|
|
else if( c == '.' || c == ',' )
|
|
|
|
{
|
|
|
|
if( decimalSeparator != '?' || thousandsSeparator != '?' )
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
// We've previously found a non-ambiguous separator...
|
|
|
|
|
|
|
|
if( c == decimalSeparator )
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
if( thousandsSeparatorFound )
|
|
|
|
return false; // decimal before thousands
|
|
|
|
else if( decimalSeparatorFound )
|
|
|
|
return false; // more than one decimal
|
|
|
|
else
|
|
|
|
decimalSeparatorFound = true;
|
|
|
|
}
|
|
|
|
else if( c == thousandsSeparator )
|
|
|
|
{
|
|
|
|
if( digits != 3 )
|
|
|
|
return false; // thousands not followed by 3 digits
|
|
|
|
else
|
|
|
|
thousandsSeparatorFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( ambiguousSeparator != '?' )
|
|
|
|
{
|
|
|
|
// We've previously found a separator, but we don't know for sure
|
|
|
|
// which...
|
|
|
|
|
|
|
|
if( c == ambiguousSeparator )
|
|
|
|
{
|
|
|
|
// They both must be thousands separators
|
|
|
|
thousandsSeparator = ambiguousSeparator;
|
|
|
|
thousandsSeparatorFound = true;
|
2022-12-21 17:01:05 +00:00
|
|
|
decimalSeparator = c == '.' ? ',' : '.';
|
|
|
|
}
|
2023-01-30 21:09:36 +00:00
|
|
|
else
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
// The first must have been a decimal, and this must be a
|
|
|
|
// thousands.
|
|
|
|
decimalSeparator = ambiguousSeparator;
|
|
|
|
decimalSeparatorFound = true;
|
|
|
|
thousandsSeparator = c;
|
|
|
|
thousandsSeparatorFound = true;
|
2022-12-21 17:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
// This is the first separator...
|
|
|
|
|
|
|
|
// If it's followed by 3 digits then it could be either.
|
|
|
|
// Otherwise it -must- be a decimal separator (and the thousands
|
|
|
|
// separator must be the other).
|
|
|
|
if( digits == 3 )
|
2022-12-21 17:01:05 +00:00
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
ambiguousSeparator = c;
|
2022-12-21 17:01:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-30 21:09:36 +00:00
|
|
|
decimalSeparator = c;
|
|
|
|
decimalSeparatorFound = true;
|
|
|
|
thousandsSeparator = c == '.' ? ',' : '.';
|
2022-12-21 17:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-30 21:09:36 +00:00
|
|
|
|
|
|
|
digits = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
digits = 0;
|
2022-12-21 17:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 21:09:36 +00:00
|
|
|
// If we found nothing difinitive then we have to assume SPICE-native syntax
|
|
|
|
if( decimalSeparator == '?' && thousandsSeparator == '?' )
|
|
|
|
{
|
|
|
|
decimalSeparator = '.';
|
|
|
|
thousandsSeparator = ',';
|
|
|
|
}
|
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
mantissa->Replace( thousandsSeparator, wxEmptyString );
|
|
|
|
mantissa->Replace( decimalSeparator, '.' );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString prefix = aSymbol.GetPrefix();
|
2023-02-04 20:55:52 +00:00
|
|
|
wxString library = GetFieldValue( aFields, SIM_LIBRARY_FIELD, aResolve );
|
|
|
|
wxString modelName = GetFieldValue( aFields, SIM_NAME_FIELD, aResolve );
|
2023-01-05 14:16:06 +00:00
|
|
|
wxString value = GetFieldValue( aFields, SIM_VALUE_FIELD, aResolve );
|
2022-12-18 22:53:53 +00:00
|
|
|
std::vector<LIB_PIN*> pins = aSymbol.GetAllLibPins();
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
*aDeviceType = GetFieldValue( aFields, SIM_DEVICE_TYPE_FIELD, aResolve );
|
|
|
|
*aModelType = GetFieldValue( aFields, SIM_TYPE_FIELD, aResolve );
|
|
|
|
*aModelParams = GetFieldValue( aFields, SIM_PARAMS_FIELD, aResolve );
|
|
|
|
*aPinMap = GetFieldValue( aFields, SIM_PINS_FIELD, aResolve );
|
2022-12-18 22:53:53 +00:00
|
|
|
|
|
|
|
if( pins.size() != 2 )
|
|
|
|
return false;
|
2022-12-09 15:09:34 +00:00
|
|
|
|
2022-12-19 18:10:57 +00:00
|
|
|
if( ( ( *aDeviceType == "R" || *aDeviceType == "L" || *aDeviceType == "C" )
|
|
|
|
&& aModelType->IsEmpty() )
|
|
|
|
||
|
2023-02-04 20:55:52 +00:00
|
|
|
( library.IsEmpty() && modelName.IsEmpty()
|
|
|
|
&& aDeviceType->IsEmpty()
|
2022-12-19 18:10:57 +00:00
|
|
|
&& aModelType->IsEmpty()
|
|
|
|
&& !value.IsEmpty()
|
|
|
|
&& ( prefix.StartsWith( "R" ) || prefix.StartsWith( "L" ) || prefix.StartsWith( "C" ) ) ) )
|
2022-12-09 15:09:34 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
if( aModelParams->IsEmpty() )
|
2022-12-09 15:09:34 +00:00
|
|
|
{
|
2022-12-14 23:21:35 +00:00
|
|
|
wxRegEx idealVal( wxT( "^"
|
2022-12-19 20:05:54 +00:00
|
|
|
"([0-9\\,\\. ]+)"
|
2022-12-14 23:21:35 +00:00
|
|
|
"([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
|
2022-12-18 22:53:53 +00:00
|
|
|
"([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
|
2022-12-14 23:21:35 +00:00
|
|
|
"([-1-9 ]*)"
|
2022-12-18 22:53:53 +00:00
|
|
|
"([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
|
2022-12-14 23:21:35 +00:00
|
|
|
"$" ) );
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
if( idealVal.Matches( value ) ) // Ideal
|
2022-12-09 15:09:34 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString valueMantissa( idealVal.GetMatch( value, 1 ) );
|
2022-12-19 01:51:24 +00:00
|
|
|
wxString valueExponent( idealVal.GetMatch( value, 2 ) );
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString valueFraction( idealVal.GetMatch( value, 6 ) );
|
2022-12-09 15:09:34 +00:00
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
if( !convertSeparators( &valueMantissa ) )
|
|
|
|
return false;
|
2022-12-19 20:05:54 +00:00
|
|
|
|
2022-12-19 18:10:57 +00:00
|
|
|
if( valueMantissa.Contains( wxT( "." ) ) || valueFraction.IsEmpty() )
|
2022-12-09 20:58:47 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
aModelParams->Printf( wxT( "%s=\"%s%s\"" ),
|
|
|
|
prefix.Left(1).Lower(),
|
2022-12-19 01:51:24 +00:00
|
|
|
valueMantissa,
|
|
|
|
convertNotation( valueExponent ) );
|
2022-12-09 20:58:47 +00:00
|
|
|
}
|
2022-12-18 22:53:53 +00:00
|
|
|
else
|
2022-12-09 20:58:47 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
aModelParams->Printf( wxT( "%s=\"%s.%s%s\"" ),
|
|
|
|
prefix.Left(1).Lower(),
|
|
|
|
valueMantissa,
|
|
|
|
valueFraction,
|
2022-12-19 01:51:24 +00:00
|
|
|
convertNotation( valueExponent ) );
|
2022-12-09 20:58:47 +00:00
|
|
|
}
|
2022-12-14 23:21:35 +00:00
|
|
|
}
|
|
|
|
else // Behavioral
|
|
|
|
{
|
|
|
|
*aModelType = wxT( "=" );
|
2022-12-18 22:53:53 +00:00
|
|
|
aModelParams->Printf( wxT( "%s=\"%s\"" ), prefix.Left(1).Lower(), value );
|
2022-12-14 23:21:35 +00:00
|
|
|
}
|
2022-12-18 22:53:53 +00:00
|
|
|
}
|
2022-12-14 23:21:35 +00:00
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
if( aDeviceType->IsEmpty() )
|
|
|
|
*aDeviceType = prefix.Left( 1 );
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
if( aPinMap->IsEmpty() )
|
|
|
|
aPinMap->Printf( wxT( "%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
|
2022-12-14 23:21:35 +00:00
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-19 18:10:57 +00:00
|
|
|
if( ( ( *aDeviceType == wxT( "V" ) || *aDeviceType == wxT( "I" ) )
|
|
|
|
&& aModelType->IsEmpty() )
|
|
|
|
||
|
|
|
|
( aDeviceType->IsEmpty()
|
|
|
|
&& aModelType->IsEmpty()
|
|
|
|
&& !value.IsEmpty()
|
|
|
|
&& ( prefix.StartsWith( "V" ) || prefix.StartsWith( "I" ) ) ) )
|
2022-12-18 22:53:53 +00:00
|
|
|
{
|
2022-12-19 01:20:54 +00:00
|
|
|
if( aModelParams->IsEmpty() && !value.IsEmpty() )
|
2022-12-18 22:53:53 +00:00
|
|
|
{
|
2022-12-19 01:20:54 +00:00
|
|
|
if( value.StartsWith( wxT( "DC " ) ) )
|
|
|
|
value = value.Right( value.Length() - 3 );
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
wxRegEx sourceVal( wxT( "^"
|
2022-12-21 17:01:05 +00:00
|
|
|
"([0-9\\,\\. ]+)"
|
2022-12-18 22:53:53 +00:00
|
|
|
"([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
|
|
|
|
"([vVaA])?"
|
|
|
|
"([-1-9 ]*)"
|
|
|
|
"([vVaA])?"
|
|
|
|
"$" ) );
|
|
|
|
|
|
|
|
if( sourceVal.Matches( value ) )
|
2022-12-09 15:09:34 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString valueMantissa( sourceVal.GetMatch( value, 1 ) );
|
2022-12-19 01:51:24 +00:00
|
|
|
wxString valueExponent( sourceVal.GetMatch( value, 2 ) );
|
2022-12-18 22:53:53 +00:00
|
|
|
wxString valueFraction( sourceVal.GetMatch( value, 6 ) );
|
2022-12-14 23:21:35 +00:00
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
if( !convertSeparators( &valueMantissa ) )
|
|
|
|
return false;
|
2022-12-19 20:05:54 +00:00
|
|
|
|
2022-12-19 18:10:57 +00:00
|
|
|
if( valueMantissa.Contains( wxT( "." ) ) || valueFraction.IsEmpty() )
|
2022-12-14 23:21:35 +00:00
|
|
|
{
|
2022-12-18 22:53:53 +00:00
|
|
|
aModelParams->Printf( wxT( "dc=\"%s%s\"" ),
|
|
|
|
valueMantissa,
|
2022-12-19 01:51:24 +00:00
|
|
|
convertNotation( valueExponent ) );
|
2022-12-18 22:53:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aModelParams->Printf( wxT( "dc=\"%s.%s%s\"" ),
|
|
|
|
valueMantissa,
|
|
|
|
valueFraction,
|
2022-12-19 01:51:24 +00:00
|
|
|
convertNotation( valueExponent ) );
|
2022-12-14 23:21:35 +00:00
|
|
|
}
|
2022-12-09 15:09:34 +00:00
|
|
|
}
|
2022-12-18 22:53:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
aModelParams->Printf( wxT( "dc=\"%s\"" ), value );
|
|
|
|
}
|
2022-12-09 15:09:34 +00:00
|
|
|
}
|
2022-12-18 22:53:53 +00:00
|
|
|
|
2022-12-21 17:01:05 +00:00
|
|
|
if( aDeviceType->IsEmpty() )
|
|
|
|
*aDeviceType = prefix.Left( 1 );
|
|
|
|
|
|
|
|
if( aModelType->IsEmpty() )
|
|
|
|
*aModelType = wxT( "DC" );
|
|
|
|
|
2022-12-18 22:53:53 +00:00
|
|
|
if( aPinMap->IsEmpty() )
|
|
|
|
aPinMap->Printf( wxT( "%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
|
|
|
|
|
|
|
|
return true;
|
2022-12-09 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 23:21:35 +00:00
|
|
|
return false;
|
2022-12-09 15:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-19 18:10:57 +00:00
|
|
|
template bool SIM_MODEL::InferSimModel<SCH_SYMBOL, SCH_FIELD>( SCH_SYMBOL& aSymbol,
|
|
|
|
std::vector<SCH_FIELD>* aFields,
|
|
|
|
bool aResolve,
|
2022-12-18 22:53:53 +00:00
|
|
|
SIM_VALUE_GRAMMAR::NOTATION aNotation,
|
|
|
|
wxString* aDeviceType,
|
|
|
|
wxString* aModelType,
|
|
|
|
wxString* aModelParams,
|
|
|
|
wxString* aPinMap );
|
2022-12-19 18:10:57 +00:00
|
|
|
template bool SIM_MODEL::InferSimModel<LIB_SYMBOL, LIB_FIELD>( LIB_SYMBOL& aSymbol,
|
|
|
|
std::vector<LIB_FIELD>* aFields,
|
|
|
|
bool aResolve,
|
2022-12-18 22:53:53 +00:00
|
|
|
SIM_VALUE_GRAMMAR::NOTATION aNotation,
|
|
|
|
wxString* aDeviceType,
|
|
|
|
wxString* aModelType,
|
|
|
|
wxString* aModelParams,
|
|
|
|
wxString* aPinMap );
|
2022-12-14 23:21:35 +00:00
|
|
|
|
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
template <typename T_symbol, typename T_field>
|
2022-12-14 13:00:25 +00:00
|
|
|
void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol, const PROJECT* aProject )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
if( aSymbol.FindField( SIM_DEVICE_TYPE_FIELD )
|
|
|
|
|| aSymbol.FindField( SIM_TYPE_FIELD )
|
|
|
|
|| aSymbol.FindField( SIM_PINS_FIELD )
|
|
|
|
|| aSymbol.FindField( SIM_PARAMS_FIELD ) )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-02-02 16:21:24 +00:00
|
|
|
// Has a V7 model field.
|
|
|
|
|
|
|
|
// Up until 7.0RC2 we used '+' and '-' for potentiometer pins, which doesn't match
|
|
|
|
// SPICE. Here we remap them to 'r0' and 'r1'.
|
|
|
|
if( T_field* deviceType = aSymbol.FindField( SIM_TYPE_FIELD ) )
|
|
|
|
{
|
2023-05-05 13:21:56 +00:00
|
|
|
if( deviceType->GetShownText( false ).Lower() == wxS( "pot" ) )
|
2023-02-02 16:21:24 +00:00
|
|
|
{
|
|
|
|
if( T_field* pins = aSymbol.FindField( SIM_PINS_FIELD ) )
|
|
|
|
{
|
|
|
|
wxString pinMap = pins->GetText();
|
|
|
|
pinMap.Replace( wxS( "=+" ), wxS( "=r1" ) );
|
|
|
|
pinMap.Replace( wxS( "=-" ), wxS( "=r0" ) );
|
|
|
|
pins->SetText( pinMap );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
class FIELD_INFO
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FIELD_INFO()
|
|
|
|
{
|
|
|
|
m_Attributes.m_Visible = false;
|
2023-02-22 11:39:48 +00:00
|
|
|
m_Attributes.m_Size = VECTOR2I( DEFAULT_SIZE_TEXT * schIUScale.IU_PER_MILS,
|
|
|
|
DEFAULT_SIZE_TEXT * schIUScale.IU_PER_MILS );
|
2023-01-02 17:35:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FIELD_INFO( const wxString& aText, T_field* aField ) :
|
|
|
|
m_Text( aText ),
|
|
|
|
m_Attributes( aField->GetAttributes() ),
|
|
|
|
m_Pos( aField->GetPosition() )
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool IsEmpty() { return m_Text.IsEmpty(); }
|
|
|
|
|
|
|
|
T_field CreateField( T_symbol* aSymbol, const wxString& aFieldName )
|
|
|
|
{
|
|
|
|
T_field field( aSymbol, -1, aFieldName );
|
|
|
|
|
|
|
|
field.SetText( m_Text );
|
|
|
|
field.SetAttributes( m_Attributes );
|
|
|
|
field.SetPosition( m_Pos );
|
|
|
|
|
2023-01-03 18:20:18 +00:00
|
|
|
return field;
|
2023-01-02 17:35:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
wxString m_Text;
|
|
|
|
TEXT_ATTRIBUTES m_Attributes;
|
|
|
|
VECTOR2I m_Pos;
|
|
|
|
};
|
|
|
|
|
2022-12-09 20:58:47 +00:00
|
|
|
auto getSIValue =
|
|
|
|
[]( T_field* aField )
|
|
|
|
{
|
2022-12-15 18:14:19 +00:00
|
|
|
if( !aField ) // no, not really, but it keeps Coverity happy
|
|
|
|
return wxString( wxEmptyString );
|
|
|
|
|
2022-12-09 20:58:47 +00:00
|
|
|
wxRegEx regex( wxT( "([^a-z])(M)(e|E)(g|G)($|[^a-z])" ) );
|
|
|
|
wxString value = aField->GetText();
|
|
|
|
|
|
|
|
// Keep prefix, M, and suffix, but drop e|E and g|G
|
|
|
|
regex.ReplaceAll( &value, wxT( "\\1\\2\\5" ) );
|
|
|
|
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
|
2022-12-19 11:35:05 +00:00
|
|
|
auto generateDefaultPinMapFromSymbol =
|
|
|
|
[]( const std::vector<LIB_PIN*>& sourcePins )
|
|
|
|
{
|
|
|
|
wxString pinMap;
|
|
|
|
|
|
|
|
// If we're creating the pinMap from the symbol it means we don't know what the
|
|
|
|
// SIM_MODEL's pin names are, so just use indexes.
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < sourcePins.size(); ++ii )
|
|
|
|
{
|
|
|
|
if( ii > 0 )
|
|
|
|
pinMap.Append( wxS( " " ) );
|
|
|
|
|
|
|
|
pinMap.Append( wxString::Format( wxT( "%s=%u" ),
|
|
|
|
sourcePins[ii]->GetNumber(),
|
|
|
|
ii + 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return pinMap;
|
|
|
|
};
|
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
wxString prefix = aSymbol.GetPrefix();
|
|
|
|
T_field* valueField = aSymbol.FindField( wxT( "Value" ) );
|
|
|
|
std::vector<LIB_PIN*> sourcePins = aSymbol.GetAllLibPins();
|
|
|
|
|
|
|
|
std::sort( sourcePins.begin(), sourcePins.end(),
|
|
|
|
[]( const LIB_PIN* lhs, const LIB_PIN* rhs )
|
|
|
|
{
|
|
|
|
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
|
|
|
|
} );
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
FIELD_INFO spiceDeviceInfo;
|
|
|
|
FIELD_INFO spiceModelInfo;
|
|
|
|
FIELD_INFO spiceTypeInfo;
|
|
|
|
FIELD_INFO spiceLibInfo;
|
|
|
|
FIELD_INFO spiceParamsInfo;
|
|
|
|
FIELD_INFO pinMapInfo;
|
|
|
|
bool modelFromValueField = false;
|
2022-12-08 23:56:55 +00:00
|
|
|
|
|
|
|
if( aSymbol.FindField( wxT( "Spice_Primitive" ) )
|
|
|
|
|| aSymbol.FindField( wxT( "Spice_Node_Sequence" ) )
|
|
|
|
|| aSymbol.FindField( wxT( "Spice_Model" ) )
|
|
|
|
|| aSymbol.FindField( wxT( "Spice_Netlist_Enabled" ) )
|
|
|
|
|| aSymbol.FindField( wxT( "Spice_Lib_File" ) ) )
|
|
|
|
{
|
|
|
|
if( T_field* primitiveField = aSymbol.FindField( wxT( "Spice_Primitive" ) ) )
|
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceDeviceInfo = FIELD_INFO( primitiveField->GetText(), primitiveField );
|
2022-12-08 23:56:55 +00:00
|
|
|
aSymbol.RemoveField( primitiveField );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* nodeSequenceField = aSymbol.FindField( wxT( "Spice_Node_Sequence" ) ) )
|
|
|
|
{
|
|
|
|
const wxString delimiters( "{:,; }" );
|
|
|
|
const wxString& nodeSequence = nodeSequenceField->GetText();
|
2023-01-02 17:35:37 +00:00
|
|
|
wxString pinMap;
|
2022-12-08 23:56:55 +00:00
|
|
|
|
|
|
|
if( nodeSequence != "" )
|
|
|
|
{
|
|
|
|
wxStringTokenizer tkz( nodeSequence, delimiters );
|
|
|
|
|
|
|
|
for( long modelPinNumber = 1; tkz.HasMoreTokens(); ++modelPinNumber )
|
|
|
|
{
|
|
|
|
long symbolPinNumber = 1;
|
|
|
|
tkz.GetNextToken().ToLong( &symbolPinNumber );
|
|
|
|
|
|
|
|
if( modelPinNumber != 1 )
|
|
|
|
pinMap.Append( " " );
|
|
|
|
|
|
|
|
pinMap.Append( wxString::Format( "%ld=%ld", symbolPinNumber, modelPinNumber ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
pinMapInfo = FIELD_INFO( pinMap, nodeSequenceField );
|
2022-12-08 23:56:55 +00:00
|
|
|
aSymbol.RemoveField( nodeSequenceField );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* modelField = aSymbol.FindField( wxT( "Spice_Model" ) ) )
|
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceModelInfo = FIELD_INFO( getSIValue( modelField ), modelField );
|
2022-12-08 23:56:55 +00:00
|
|
|
aSymbol.RemoveField( modelField );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceModelInfo = FIELD_INFO( getSIValue( valueField ), valueField );
|
2022-12-14 13:00:25 +00:00
|
|
|
modelFromValueField = true;
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* netlistEnabledField = aSymbol.FindField( wxT( "Spice_Netlist_Enabled" ) ) )
|
|
|
|
{
|
|
|
|
wxString netlistEnabled = netlistEnabledField->GetText().Lower();
|
|
|
|
|
|
|
|
if( netlistEnabled.StartsWith( wxT( "0" ) )
|
|
|
|
|| netlistEnabled.StartsWith( wxT( "n" ) )
|
|
|
|
|| netlistEnabled.StartsWith( wxT( "f" ) ) )
|
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
netlistEnabledField->SetName( SIM_ENABLE_FIELD );
|
2022-12-14 23:21:35 +00:00
|
|
|
netlistEnabledField->SetText( wxT( "0" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aSymbol.RemoveField( netlistEnabledField );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* libFileField = aSymbol.FindField( wxT( "Spice_Lib_File" ) ) )
|
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceLibInfo = FIELD_INFO( libFileField->GetText(), libFileField );
|
2022-12-08 23:56:55 +00:00
|
|
|
aSymbol.RemoveField( libFileField );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Auto convert some legacy fields used in the middle of 7.0 development...
|
|
|
|
|
2022-12-19 01:20:54 +00:00
|
|
|
if( T_field* legacyType = aSymbol.FindField( wxT( "Sim_Type" ) ) )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
legacyType->SetName( SIM_TYPE_FIELD );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* legacyDevice = aSymbol.FindField( wxT( "Sim_Device" ) ) )
|
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
legacyDevice->SetName( SIM_DEVICE_TYPE_FIELD );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( T_field* legacyPins = aSymbol.FindField( wxT( "Sim_Pins" ) ) )
|
|
|
|
{
|
2022-12-14 23:21:35 +00:00
|
|
|
bool isPassive = prefix.StartsWith( wxT( "R" ) )
|
|
|
|
|| prefix.StartsWith( wxT( "L" ) )
|
|
|
|
|| prefix.StartsWith( wxT( "C" ) );
|
2022-12-09 20:58:47 +00:00
|
|
|
|
2022-12-08 23:56:55 +00:00
|
|
|
// Migrate pins from array of indexes to name-value-pairs
|
2023-01-02 17:35:37 +00:00
|
|
|
wxString pinMap;
|
2022-12-08 23:56:55 +00:00
|
|
|
wxArrayString pinIndexes;
|
|
|
|
|
|
|
|
wxStringSplit( legacyPins->GetText(), pinIndexes, ' ' );
|
|
|
|
|
2022-12-14 15:12:50 +00:00
|
|
|
if( isPassive && pinIndexes.size() == 2 && sourcePins.size() == 2 )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
|
|
|
if( pinIndexes[0] == wxT( "2" ) )
|
2022-12-14 15:12:50 +00:00
|
|
|
{
|
|
|
|
pinMap.Printf( wxT( "%s=- %s=+" ),
|
|
|
|
sourcePins[0]->GetNumber(),
|
|
|
|
sourcePins[1]->GetNumber() );
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
else
|
2022-12-14 15:12:50 +00:00
|
|
|
{
|
|
|
|
pinMap.Printf( wxT( "%s=+ %s=-" ),
|
|
|
|
sourcePins[0]->GetNumber(),
|
|
|
|
sourcePins[1]->GetNumber() );
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-12 07:36:07 +00:00
|
|
|
for( unsigned ii = 0; ii < pinIndexes.size() && ii < sourcePins.size(); ++ii )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
|
|
|
if( ii > 0 )
|
2022-12-14 15:12:50 +00:00
|
|
|
pinMap.Append( wxS( " " ) );
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2022-12-18 19:30:15 +00:00
|
|
|
pinMap.Append( wxString::Format( wxT( "%s=%s" ),
|
2022-12-14 15:12:50 +00:00
|
|
|
sourcePins[ii]->GetNumber(),
|
|
|
|
pinIndexes[ ii ] ) );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
legacyPins->SetName( SIM_PINS_FIELD );
|
2022-12-14 15:12:50 +00:00
|
|
|
legacyPins->SetText( pinMap );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
if( T_field* legacyParams = aSymbol.FindField( wxT( "Sim_Params" ) ) )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
legacyParams->SetName( SIM_PARAMS_FIELD );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
wxString spiceDeviceType = spiceDeviceInfo.m_Text.Trim( true ).Trim( false );
|
2023-01-02 22:47:46 +00:00
|
|
|
wxString spiceLib = spiceLibInfo.m_Text.Trim( true ).Trim( false );
|
2023-01-02 17:35:37 +00:00
|
|
|
wxString spiceModel = spiceModelInfo.m_Text.Trim( true ).Trim( false );
|
2023-03-25 12:15:19 +00:00
|
|
|
wxString modelLineParams;
|
2022-12-17 20:25:29 +00:00
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
bool libraryModel = false;
|
2022-12-19 01:20:54 +00:00
|
|
|
bool inferredModel = false;
|
2022-12-17 15:21:35 +00:00
|
|
|
bool internalModel = false;
|
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
if( !spiceLib.IsEmpty() )
|
2022-12-14 13:00:25 +00:00
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
2023-01-12 12:46:52 +00:00
|
|
|
SIM_LIB_MGR libMgr( aProject, &reporter );
|
2023-01-02 22:47:46 +00:00
|
|
|
std::vector<T_field> emptyFields;
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2023-03-25 12:15:19 +00:00
|
|
|
// Pull out any following parameters from model name
|
|
|
|
spiceModel = spiceModel.BeforeFirst( ' ', &modelLineParams );
|
|
|
|
spiceModelInfo.m_Text = spiceModel;
|
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
SIM_LIBRARY::MODEL model = libMgr.CreateModel( spiceLib, spiceModel.ToStdString(),
|
|
|
|
emptyFields, sourcePins );
|
2022-12-09 20:58:47 +00:00
|
|
|
|
2023-01-03 15:29:45 +00:00
|
|
|
if( reporter.HasMessage() )
|
|
|
|
libraryModel = false; // Fall back to raw spice model
|
|
|
|
else
|
|
|
|
libraryModel = true;
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
if( pinMapInfo.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Try to generate a default pin map from the SIM_MODEL's pins; if that fails,
|
|
|
|
// generate one from the symbol's pins
|
2022-12-19 11:35:05 +00:00
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
model.model.SIM_MODEL::createPins( sourcePins );
|
|
|
|
pinMapInfo.m_Text = wxString( model.model.Serializer().GeneratePins() );
|
2022-12-19 11:35:05 +00:00
|
|
|
|
2023-01-02 22:47:46 +00:00
|
|
|
if( pinMapInfo.IsEmpty() )
|
|
|
|
pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
|
2022-12-14 13:00:25 +00:00
|
|
|
}
|
2022-12-09 20:58:47 +00:00
|
|
|
}
|
2022-12-19 01:20:54 +00:00
|
|
|
else if( ( spiceDeviceType == "R" || spiceDeviceType == "L" || spiceDeviceType == "C" )
|
|
|
|
&& prefix.StartsWith( spiceDeviceType )
|
|
|
|
&& modelFromValueField )
|
|
|
|
{
|
|
|
|
inferredModel = true;
|
|
|
|
}
|
2022-12-17 15:21:35 +00:00
|
|
|
else
|
|
|
|
{
|
2022-12-19 01:20:54 +00:00
|
|
|
// See if we have a SPICE model such as "sin(0 1 60)" or "sin 0 1 60" that can be handled
|
2022-12-17 20:25:29 +00:00
|
|
|
// by a built-in SIM_MODEL.
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-12-19 01:20:54 +00:00
|
|
|
wxStringTokenizer tokenizer( spiceModel, wxT( "() " ), wxTOKEN_STRTOK );
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2022-12-19 01:20:54 +00:00
|
|
|
if( tokenizer.HasMoreTokens() )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2023-01-03 16:58:36 +00:00
|
|
|
spiceTypeInfo.m_Text = tokenizer.GetNextToken();
|
|
|
|
spiceTypeInfo.m_Text.MakeUpper();
|
2022-12-17 15:21:35 +00:00
|
|
|
|
|
|
|
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
|
|
|
{
|
|
|
|
if( spiceDeviceType == SIM_MODEL::SpiceInfo( type ).itemType
|
2023-01-03 16:58:36 +00:00
|
|
|
&& spiceTypeInfo.m_Text == SIM_MODEL::SpiceInfo( type ).inlineTypeString )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( type );
|
|
|
|
|
2023-01-03 16:58:36 +00:00
|
|
|
if( spiceTypeInfo.m_Text == wxT( "DC" ) && tokenizer.CountTokens() == 1 )
|
2022-12-19 01:20:54 +00:00
|
|
|
{
|
2023-03-04 18:02:05 +00:00
|
|
|
wxCHECK( valueField, /* void */ );
|
2022-12-19 01:20:54 +00:00
|
|
|
valueField->SetText( tokenizer.GetNextToken() );
|
|
|
|
modelFromValueField = false;
|
|
|
|
}
|
|
|
|
else
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2022-12-19 01:20:54 +00:00
|
|
|
for( int ii = 0; tokenizer.HasMoreTokens(); ++ii )
|
|
|
|
{
|
|
|
|
model->SetParamValue( ii, tokenizer.GetNextToken().ToStdString(),
|
|
|
|
SIM_VALUE_GRAMMAR::NOTATION::SPICE );
|
|
|
|
}
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceTypeInfo.m_Text = SIM_MODEL::TypeInfo( type ).fieldValue;
|
|
|
|
|
|
|
|
spiceParamsInfo = spiceModelInfo;
|
|
|
|
spiceParamsInfo.m_Text = wxString( model->Serializer().GenerateParams() );
|
2022-12-17 15:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internalModel = true;
|
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
if( pinMapInfo.IsEmpty() )
|
2022-12-17 15:21:35 +00:00
|
|
|
{
|
2022-12-19 11:35:05 +00:00
|
|
|
// Generate a default pin map from the SIM_MODEL's pins
|
2022-12-22 20:21:10 +00:00
|
|
|
model->createPins( sourcePins );
|
2023-01-02 17:35:37 +00:00
|
|
|
pinMapInfo.m_Text = wxString( model->Serializer().GeneratePins() );
|
2022-12-17 15:21:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Fall back to raw spice model
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( libraryModel )
|
2022-12-09 20:58:47 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field libraryField = spiceLibInfo.CreateField( &aSymbol, SIM_LIBRARY_FIELD );
|
2022-12-14 13:00:25 +00:00
|
|
|
aSymbol.AddField( libraryField );
|
2022-12-09 20:58:47 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field nameField = spiceModelInfo.CreateField( &aSymbol, SIM_NAME_FIELD );
|
2022-12-14 13:00:25 +00:00
|
|
|
aSymbol.AddField( nameField );
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2023-03-22 13:51:16 +00:00
|
|
|
if( !modelLineParams.IsEmpty() )
|
2022-12-23 12:33:39 +00:00
|
|
|
{
|
2023-03-22 13:51:16 +00:00
|
|
|
spiceParamsInfo = spiceModelInfo;
|
2023-03-25 12:15:19 +00:00
|
|
|
spiceParamsInfo.m_Pos.x += nameField.GetBoundingBox().GetWidth();
|
2023-03-22 13:51:16 +00:00
|
|
|
spiceParamsInfo.m_Text = modelLineParams;
|
|
|
|
|
2023-03-25 12:15:19 +00:00
|
|
|
BOX2I nameBBox = nameField.GetBoundingBox();
|
|
|
|
int nameWidth = nameBBox.GetWidth();
|
|
|
|
|
|
|
|
// Add space between model name and additional parameters
|
|
|
|
nameWidth += KiROUND( nameBBox.GetHeight() * 1.25 );
|
|
|
|
|
|
|
|
if( nameField.GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
|
|
|
|
spiceParamsInfo.m_Pos.x -= nameWidth;
|
|
|
|
else
|
|
|
|
spiceParamsInfo.m_Pos.x += nameWidth;
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
|
2022-12-23 12:33:39 +00:00
|
|
|
aSymbol.AddField( paramsField );
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
if( modelFromValueField )
|
|
|
|
valueField->SetText( wxT( "${SIM.NAME}" ) );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
2022-12-19 01:20:54 +00:00
|
|
|
else if( inferredModel )
|
|
|
|
{
|
|
|
|
// DeviceType is left in the reference designator and Model is left in the value field,
|
|
|
|
// so there's nothing to do here....
|
|
|
|
}
|
2022-12-17 15:21:35 +00:00
|
|
|
else if( internalModel )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_DEVICE_TYPE_FIELD );
|
2023-01-02 17:35:37 +00:00
|
|
|
aSymbol.AddField( deviceField );
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field typeField = spiceTypeInfo.CreateField( &aSymbol, SIM_TYPE_FIELD );
|
2022-12-17 15:21:35 +00:00
|
|
|
aSymbol.AddField( typeField );
|
|
|
|
|
2023-01-03 17:19:30 +00:00
|
|
|
if( !spiceParamsInfo.IsEmpty() )
|
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
|
2023-01-03 17:19:30 +00:00
|
|
|
aSymbol.AddField( paramsField );
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
|
2022-12-17 15:21:35 +00:00
|
|
|
if( modelFromValueField )
|
|
|
|
valueField->SetText( wxT( "${SIM.PARAMS}" ) );
|
|
|
|
}
|
|
|
|
else // Insert a raw spice model as a substitute.
|
|
|
|
{
|
2023-01-02 22:47:46 +00:00
|
|
|
if( spiceDeviceType.IsEmpty() && spiceLib.IsEmpty() )
|
2022-12-08 23:56:55 +00:00
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceParamsInfo = spiceModelInfo;
|
2022-12-14 13:00:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-02 17:35:37 +00:00
|
|
|
spiceParamsInfo.m_Text.Printf( wxT( "type=\"%s\" model=\"%s\" lib=\"%s\"" ),
|
2023-01-02 22:47:46 +00:00
|
|
|
spiceDeviceType, spiceModel, spiceLib );
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
2023-01-03 01:23:02 +00:00
|
|
|
spiceDeviceInfo.m_Text = SIM_MODEL::DeviceInfo( SIM_MODEL::DEVICE_T::SPICE ).fieldValue;
|
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field deviceField = spiceDeviceInfo.CreateField( &aSymbol, SIM_DEVICE_TYPE_FIELD );
|
2023-01-02 17:35:37 +00:00
|
|
|
aSymbol.AddField( deviceField );
|
2022-12-14 13:00:25 +00:00
|
|
|
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field paramsField = spiceParamsInfo.CreateField( &aSymbol, SIM_PARAMS_FIELD );
|
2022-12-14 13:00:25 +00:00
|
|
|
aSymbol.AddField( paramsField );
|
|
|
|
|
|
|
|
if( modelFromValueField )
|
2022-12-14 16:47:20 +00:00
|
|
|
{
|
|
|
|
// Get the current Value field, after previous changes.
|
|
|
|
valueField = aSymbol.FindField( wxT( "Value" ) );
|
|
|
|
|
|
|
|
if( valueField )
|
|
|
|
valueField->SetText( wxT( "${SIM.PARAMS}" ) );
|
|
|
|
}
|
2022-12-14 13:00:25 +00:00
|
|
|
|
2022-12-19 11:35:05 +00:00
|
|
|
// We know nothing about the SPICE model here, so we've got no choice but to generate
|
|
|
|
// the default pin map from the symbol's pins.
|
2022-12-14 14:16:18 +00:00
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
if( pinMapInfo.IsEmpty() )
|
|
|
|
pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
|
2022-12-14 14:16:18 +00:00
|
|
|
}
|
2022-12-17 15:21:35 +00:00
|
|
|
|
2023-01-02 17:35:37 +00:00
|
|
|
if( !pinMapInfo.IsEmpty() )
|
2022-12-19 11:03:00 +00:00
|
|
|
{
|
2023-01-05 14:16:06 +00:00
|
|
|
T_field pinsField = pinMapInfo.CreateField( &aSymbol, SIM_PINS_FIELD );
|
2022-12-19 11:03:00 +00:00
|
|
|
aSymbol.AddField( pinsField );
|
|
|
|
}
|
2022-12-08 23:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-14 13:00:25 +00:00
|
|
|
template void SIM_MODEL::MigrateSimModel<SCH_SYMBOL, SCH_FIELD>( SCH_SYMBOL& aSymbol,
|
|
|
|
const PROJECT* aProject );
|
|
|
|
template void SIM_MODEL::MigrateSimModel<LIB_SYMBOL, LIB_FIELD>( LIB_SYMBOL& aSymbol,
|
|
|
|
const PROJECT* aProject );
|