2022-02-21 03:58:31 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SIM_MODEL_H
|
|
|
|
#define SIM_MODEL_H
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
2022-03-09 01:40:59 +00:00
|
|
|
#include <map>
|
2022-08-30 07:00:52 +00:00
|
|
|
#include <utility>
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-07-31 08:32:00 +00:00
|
|
|
#include <sch_field.h>
|
|
|
|
#include <lib_field.h>
|
|
|
|
|
|
|
|
// Must be included after sch_field.h (exactly eda_shape.h) to avoid a colliding
|
|
|
|
// declaration with a window header (under msys2)
|
|
|
|
#include <sim/sim_value.h>
|
|
|
|
#include <enum_vector.h>
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
class SIM_LIBRARY;
|
2022-09-15 03:25:57 +00:00
|
|
|
class SPICE_GENERATOR;
|
2022-11-11 02:07:34 +00:00
|
|
|
class SIM_SERDE;
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
class SIM_MODEL
|
|
|
|
{
|
|
|
|
public:
|
2022-09-15 03:25:57 +00:00
|
|
|
friend class SPICE_GENERATOR;
|
2022-09-27 20:47:00 +00:00
|
|
|
friend class NETLIST_EXPORTER_SPICE;
|
2022-09-15 03:25:57 +00:00
|
|
|
|
2022-09-14 07:19:25 +00:00
|
|
|
struct PIN;
|
|
|
|
struct PARAM;
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
static constexpr auto REFERENCE_FIELD = "Reference";
|
|
|
|
static constexpr auto VALUE_FIELD = "Value";
|
|
|
|
|
2022-11-20 02:37:54 +00:00
|
|
|
static constexpr auto DEVICE_TYPE_FIELD = "Sim.Device";
|
|
|
|
static constexpr auto TYPE_FIELD = "Sim.Type";
|
|
|
|
static constexpr auto PINS_FIELD = "Sim.Pins";
|
|
|
|
static constexpr auto PARAMS_FIELD = "Sim.Params";
|
|
|
|
static constexpr auto ENABLE_FIELD = "Sim.Enable";
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
// There's a trailing '_' because `DEVICE_TYPE` collides with something in Windows headers.
|
2022-07-31 08:32:00 +00:00
|
|
|
DEFINE_ENUM_CLASS_WITH_ITERATOR( DEVICE_TYPE_,
|
2022-02-21 03:58:31 +00:00
|
|
|
NONE,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
R,
|
|
|
|
C,
|
|
|
|
L,
|
2022-02-21 03:58:31 +00:00
|
|
|
TLINE,
|
2022-04-12 14:37:06 +00:00
|
|
|
SW,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
D,
|
2022-02-21 03:58:31 +00:00
|
|
|
NPN,
|
|
|
|
PNP,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
NJFET,
|
|
|
|
PJFET,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
NMES,
|
|
|
|
PMES,
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
NMOS,
|
|
|
|
PMOS,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
V,
|
|
|
|
I,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
SUBCKT,
|
|
|
|
XSPICE,
|
2022-09-30 12:29:44 +00:00
|
|
|
|
|
|
|
KIBIS,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
SPICE
|
2022-02-21 03:58:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
struct DEVICE_INFO
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string fieldValue;
|
|
|
|
std::string description;
|
2022-11-20 21:06:21 +00:00
|
|
|
bool isBuiltin;
|
2022-02-21 03:58:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DEFINE_ENUM_CLASS_WITH_ITERATOR( TYPE,
|
|
|
|
NONE,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
R,
|
2022-10-22 02:33:26 +00:00
|
|
|
R_POT,
|
2022-04-12 14:37:06 +00:00
|
|
|
R_BEHAVIORAL,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
C,
|
|
|
|
C_BEHAVIORAL,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
L,
|
2022-09-11 17:00:09 +00:00
|
|
|
L_MUTUAL,
|
2022-04-12 14:37:06 +00:00
|
|
|
L_BEHAVIORAL,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
TLINE_Z0,
|
|
|
|
TLINE_RLGC,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
SW_V,
|
|
|
|
SW_I,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
D,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
NPN_VBIC,
|
|
|
|
PNP_VBIC,
|
2022-11-29 09:10:33 +00:00
|
|
|
NPN_GUMMELPOON,
|
|
|
|
PNP_GUMMELPOON,
|
2022-02-21 03:58:31 +00:00
|
|
|
//NPN_MEXTRAM,
|
|
|
|
//PNP_MEXTRAM,
|
2022-06-21 02:22:52 +00:00
|
|
|
NPN_HICUM2,
|
|
|
|
PNP_HICUM2,
|
2022-02-21 03:58:31 +00:00
|
|
|
//NPN_HICUM_L0,
|
|
|
|
//PNP_HICUM_L0,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
NJFET_SHICHMANHODGES,
|
|
|
|
PJFET_SHICHMANHODGES,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
NJFET_PARKERSKELLERN,
|
|
|
|
PJFET_PARKERSKELLERN,
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
NMES_STATZ,
|
|
|
|
PMES_STATZ,
|
|
|
|
|
|
|
|
NMES_YTTERDAL,
|
|
|
|
PMES_YTTERDAL,
|
|
|
|
|
|
|
|
NMES_HFET1,
|
|
|
|
PMES_HFET1,
|
|
|
|
|
|
|
|
NMES_HFET2,
|
|
|
|
PMES_HFET2,
|
|
|
|
|
|
|
|
|
2022-11-28 03:45:00 +00:00
|
|
|
NMOS_VDMOS,
|
|
|
|
PMOS_VDMOS,
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
NMOS_MOS1,
|
|
|
|
PMOS_MOS1,
|
|
|
|
|
|
|
|
NMOS_MOS2,
|
|
|
|
PMOS_MOS2,
|
|
|
|
|
|
|
|
NMOS_MOS3,
|
|
|
|
PMOS_MOS3,
|
|
|
|
|
|
|
|
NMOS_BSIM1,
|
|
|
|
PMOS_BSIM1,
|
|
|
|
|
|
|
|
NMOS_BSIM2,
|
|
|
|
PMOS_BSIM2,
|
|
|
|
|
|
|
|
NMOS_MOS6,
|
|
|
|
PMOS_MOS6,
|
|
|
|
|
|
|
|
NMOS_MOS9,
|
|
|
|
PMOS_MOS9,
|
|
|
|
|
|
|
|
NMOS_BSIM3,
|
|
|
|
PMOS_BSIM3,
|
|
|
|
|
|
|
|
NMOS_B4SOI,
|
|
|
|
PMOS_B4SOI,
|
|
|
|
|
|
|
|
NMOS_BSIM4,
|
|
|
|
PMOS_BSIM4,
|
|
|
|
|
|
|
|
//NMOS_EKV2_6,
|
|
|
|
//PMOS_EKV2_6,
|
|
|
|
|
|
|
|
//NMOS_PSP,
|
|
|
|
//PMOS_PSP,
|
|
|
|
|
|
|
|
NMOS_B3SOIFD,
|
|
|
|
PMOS_B3SOIFD,
|
|
|
|
|
|
|
|
NMOS_B3SOIDD,
|
|
|
|
PMOS_B3SOIDD,
|
|
|
|
|
|
|
|
NMOS_B3SOIPD,
|
|
|
|
PMOS_B3SOIPD,
|
|
|
|
|
|
|
|
//NMOS_STAG,
|
|
|
|
//PMOS_STAG,
|
|
|
|
|
|
|
|
NMOS_HISIM2,
|
|
|
|
PMOS_HISIM2,
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
NMOS_HISIMHV1,
|
|
|
|
PMOS_HISIMHV1,
|
|
|
|
|
|
|
|
NMOS_HISIMHV2,
|
|
|
|
PMOS_HISIMHV2,
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
V,
|
2022-04-12 14:37:06 +00:00
|
|
|
V_SIN,
|
|
|
|
V_PULSE,
|
|
|
|
V_EXP,
|
2022-06-12 03:39:13 +00:00
|
|
|
/*V_SFAM,
|
|
|
|
V_SFFM,*/
|
2022-04-12 14:37:06 +00:00
|
|
|
V_PWL,
|
|
|
|
V_WHITENOISE,
|
|
|
|
V_PINKNOISE,
|
|
|
|
V_BURSTNOISE,
|
|
|
|
V_RANDUNIFORM,
|
|
|
|
V_RANDNORMAL,
|
|
|
|
V_RANDEXP,
|
2022-06-21 02:22:52 +00:00
|
|
|
//V_RANDPOISSON,
|
2022-04-12 14:37:06 +00:00
|
|
|
V_BEHAVIORAL,
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
I,
|
2022-04-12 14:37:06 +00:00
|
|
|
I_SIN,
|
|
|
|
I_PULSE,
|
|
|
|
I_EXP,
|
2022-06-12 03:39:13 +00:00
|
|
|
/*I_SFAM,
|
|
|
|
I_SFFM,*/
|
2022-04-12 14:37:06 +00:00
|
|
|
I_PWL,
|
|
|
|
I_WHITENOISE,
|
|
|
|
I_PINKNOISE,
|
|
|
|
I_BURSTNOISE,
|
|
|
|
I_RANDUNIFORM,
|
|
|
|
I_RANDNORMAL,
|
|
|
|
I_RANDEXP,
|
2022-06-21 02:22:52 +00:00
|
|
|
//I_RANDPOISSON,
|
2022-04-12 14:37:06 +00:00
|
|
|
I_BEHAVIORAL,
|
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
SUBCKT,
|
|
|
|
XSPICE,
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
KIBIS_DEVICE,
|
2022-09-30 12:29:44 +00:00
|
|
|
KIBIS_DRIVER_DC,
|
|
|
|
KIBIS_DRIVER_RECT,
|
|
|
|
KIBIS_DRIVER_PRBS,
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-09-18 19:22:59 +00:00
|
|
|
RAWSPICE
|
2022-02-21 03:58:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
struct INFO
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
DEVICE_TYPE_ deviceType;
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string fieldValue;
|
|
|
|
std::string description;
|
2022-02-21 03:58:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
struct SPICE_INFO
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string itemType;
|
|
|
|
std::string modelType = "";
|
|
|
|
std::string inlineTypeString = "";
|
|
|
|
std::string level = "";
|
2022-05-31 02:55:48 +00:00
|
|
|
bool isDefaultLevel = false;
|
2022-04-01 04:30:50 +00:00
|
|
|
bool hasExpression = false;
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string version = "";
|
2022-04-01 04:30:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
struct PIN
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string name;
|
|
|
|
std::string symbolPinNumber;
|
2022-08-22 05:40:23 +00:00
|
|
|
|
|
|
|
static constexpr auto NOT_CONNECTED = -1;
|
2022-03-09 01:40:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
struct PARAM
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
// MS Windows compilers complain about the names IN and OUT, so we prefix them.
|
|
|
|
enum DIR
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
DIR_IN,
|
|
|
|
DIR_OUT,
|
|
|
|
DIR_INOUT
|
2022-02-21 03:58:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class CATEGORY
|
|
|
|
{
|
|
|
|
PRINCIPAL,
|
2022-06-21 02:22:52 +00:00
|
|
|
GEOMETRY,
|
2022-06-12 03:39:13 +00:00
|
|
|
AC,
|
2022-02-21 03:58:31 +00:00
|
|
|
DC,
|
|
|
|
CAPACITANCE,
|
|
|
|
TEMPERATURE,
|
|
|
|
NOISE,
|
|
|
|
DISTRIBUTED_QUANTITIES,
|
|
|
|
LIMITING_VALUES,
|
|
|
|
ADVANCED,
|
|
|
|
FLAGS,
|
2022-09-27 20:47:00 +00:00
|
|
|
WAVEFORM,
|
2022-02-21 03:58:31 +00:00
|
|
|
INITIAL_CONDITIONS,
|
|
|
|
SUPERFLUOUS
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FLAGS {}; // Legacy.
|
|
|
|
|
|
|
|
struct INFO
|
|
|
|
{
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string name = "";
|
2022-05-08 09:54:35 +00:00
|
|
|
unsigned id = 0; // Legacy (don't remove).
|
2022-06-21 02:22:52 +00:00
|
|
|
DIR dir = DIR_INOUT;
|
|
|
|
SIM_VALUE::TYPE type = SIM_VALUE::TYPE_FLOAT;
|
2022-05-08 09:54:35 +00:00
|
|
|
FLAGS flags = {}; // Legacy (don't remove).
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string unit = "";
|
2022-04-01 04:30:50 +00:00
|
|
|
CATEGORY category = CATEGORY::PRINCIPAL;
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string defaultValue = "";
|
|
|
|
std::string defaultValueOfOtherVariant = ""; // Legacy (don't remove).
|
|
|
|
std::string description = "";
|
2022-05-31 02:55:48 +00:00
|
|
|
bool isSpiceInstanceParam = false;
|
2022-06-21 02:22:52 +00:00
|
|
|
bool isInstanceParam = false;
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string spiceModelName = "";
|
|
|
|
std::string spiceInstanceName = "";
|
|
|
|
std::vector<std::string> enumValues = {};
|
2022-08-02 12:43:03 +00:00
|
|
|
|
|
|
|
// TODO: Stop using brace-initializers, use this constructor for all info structs.
|
2022-09-22 05:38:45 +00:00
|
|
|
INFO( std::string aName = "",
|
2022-08-02 12:43:03 +00:00
|
|
|
unsigned aId = 0,
|
|
|
|
DIR aDir = DIR_INOUT,
|
|
|
|
SIM_VALUE::TYPE aType = SIM_VALUE::TYPE_FLOAT,
|
|
|
|
FLAGS aFlags = {},
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string& aUnit = "",
|
2022-08-02 12:43:03 +00:00
|
|
|
CATEGORY aCategory = CATEGORY::PRINCIPAL,
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string& aDefaultValue = "",
|
|
|
|
const std::string& aDefaultValueOfOtherVariant = "",
|
|
|
|
const std::string& aDescription = "",
|
2022-08-02 12:43:03 +00:00
|
|
|
bool aIsSpiceInstanceParam = false,
|
|
|
|
bool aIsInstanceParam = false,
|
2022-09-22 05:38:45 +00:00
|
|
|
const std::string& aSpiceModelName = "",
|
|
|
|
const std::string& aSpiceInstanceName = "",
|
|
|
|
std::vector<std::string> aEnumValues = {} ) :
|
2022-08-02 12:43:03 +00:00
|
|
|
name( aName ),
|
|
|
|
id( aId ),
|
|
|
|
dir( aDir ),
|
|
|
|
type( aType ),
|
|
|
|
flags( aFlags ),
|
|
|
|
unit( aUnit ),
|
|
|
|
category( aCategory ),
|
|
|
|
defaultValue( aDefaultValue ),
|
|
|
|
defaultValueOfOtherVariant( aDefaultValueOfOtherVariant ),
|
|
|
|
description( aDescription ),
|
|
|
|
isSpiceInstanceParam( aIsSpiceInstanceParam ),
|
|
|
|
isInstanceParam( aIsInstanceParam ),
|
2022-08-30 07:00:52 +00:00
|
|
|
spiceModelName( aSpiceModelName ),
|
|
|
|
spiceInstanceName( aSpiceInstanceName ),
|
|
|
|
enumValues( std::move( aEnumValues ) )
|
2022-08-02 12:43:03 +00:00
|
|
|
{
|
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
};
|
|
|
|
|
2022-10-03 20:14:14 +00:00
|
|
|
std::unique_ptr<SIM_VALUE> value;
|
2022-11-07 18:33:31 +00:00
|
|
|
const INFO& info;
|
|
|
|
bool isOtherVariant = false; // Legacy.
|
2022-07-31 08:32:00 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
PARAM( const INFO& aInfo, bool aIsOtherVariant = false )
|
2022-11-07 18:33:31 +00:00
|
|
|
: value( SIM_VALUE::Create( aInfo.type ) ),
|
2022-04-01 04:30:50 +00:00
|
|
|
info( aInfo ),
|
|
|
|
isOtherVariant( aIsOtherVariant )
|
2022-02-21 03:58:31 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-11-20 21:06:21 +00:00
|
|
|
static DEVICE_INFO DeviceInfo( DEVICE_TYPE_ aDeviceType );
|
2022-02-21 03:58:31 +00:00
|
|
|
static INFO TypeInfo( TYPE aType );
|
2022-04-01 04:30:50 +00:00
|
|
|
static SPICE_INFO SpiceInfo( TYPE aType );
|
|
|
|
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
template <typename T>
|
2022-10-22 02:33:26 +00:00
|
|
|
static TYPE ReadTypeFromFields( const std::vector<T>& aFields, int aSymbolPinCount );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
template <typename T>
|
|
|
|
static TYPE InferTypeFromLegacyFields( const std::vector<T>& aFields );
|
|
|
|
|
2022-11-07 18:33:31 +00:00
|
|
|
static std::unique_ptr<SIM_MODEL> Create( TYPE aType, unsigned aSymbolPinCount );
|
|
|
|
static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL& aBaseModel,
|
|
|
|
unsigned aSymbolPinCount );
|
2022-04-12 14:37:06 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
static std::unique_ptr<SIM_MODEL> Create( const SIM_MODEL& aBaseModel, unsigned aSymbolPinCount,
|
2022-11-07 18:33:31 +00:00
|
|
|
const std::vector<T>& aFields );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
static std::unique_ptr<SIM_MODEL> Create( unsigned aSymbolPinCount,
|
2022-11-07 18:33:31 +00:00
|
|
|
const std::vector<T>& aFields );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-09-22 05:38:45 +00:00
|
|
|
static std::string GetFieldValue( const std::vector<T>* aFields, const std::string& aFieldName );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-09-22 05:38:45 +00:00
|
|
|
static void SetFieldValue( std::vector<T>& aFields, const std::string& aFieldName,
|
|
|
|
const std::string& aValue );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-09-14 07:19:25 +00:00
|
|
|
const SPICE_GENERATOR& SpiceGenerator() const { return *m_spiceGenerator; }
|
2022-11-22 00:46:02 +00:00
|
|
|
const SIM_SERDE& Serde() const { return *m_serde; }
|
2022-09-14 07:19:25 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
// Move semantics.
|
|
|
|
// Rule of five.
|
2022-09-15 03:25:57 +00:00
|
|
|
virtual ~SIM_MODEL(); // = default in implementation file.
|
2022-02-21 03:58:31 +00:00
|
|
|
SIM_MODEL() = delete;
|
|
|
|
SIM_MODEL( const SIM_MODEL& aOther ) = delete;
|
|
|
|
SIM_MODEL( SIM_MODEL&& aOther ) = default;
|
2022-04-01 04:30:50 +00:00
|
|
|
SIM_MODEL& operator=(SIM_MODEL&& aOther ) = delete;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void ReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-11-18 07:37:58 +00:00
|
|
|
virtual void ReadDataSchFields( unsigned aSymbolPinCount,
|
|
|
|
const std::vector<SCH_FIELD>* aFields );
|
|
|
|
virtual void ReadDataLibFields( unsigned aSymbolPinCount,
|
|
|
|
const std::vector<LIB_FIELD>* aFields );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void WriteFields( std::vector<T>& aFields ) const;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
virtual void WriteDataSchFields( std::vector<SCH_FIELD>& aFields ) const;
|
|
|
|
virtual void WriteDataLibFields( std::vector<LIB_FIELD>& aFields ) const;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
virtual bool HasToIncludeSpiceLibrary() const { return GetBaseModel() && !HasOverrides(); }
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-05-31 02:55:48 +00:00
|
|
|
SPICE_INFO GetSpiceInfo() const { return SpiceInfo( GetType() ); }
|
2022-04-12 14:37:06 +00:00
|
|
|
|
|
|
|
void AddPin( const PIN& aPin );
|
2022-11-25 04:31:03 +00:00
|
|
|
void ClearPins();
|
2022-10-25 09:45:40 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
int FindModelPinIndex( const std::string& aSymbolPinNumber );
|
2022-04-01 04:30:50 +00:00
|
|
|
void AddParam( const PARAM::INFO& aInfo, bool aIsOtherVariant = false );
|
|
|
|
|
2022-11-20 21:06:21 +00:00
|
|
|
DEVICE_INFO GetDeviceInfo() const { return DeviceInfo( GetDeviceType() ); }
|
2022-05-31 02:55:48 +00:00
|
|
|
INFO GetTypeInfo() const { return TypeInfo( GetType() ); }
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
DEVICE_TYPE_ GetDeviceType() const { return GetTypeInfo().deviceType; }
|
2022-04-01 04:30:50 +00:00
|
|
|
TYPE GetType() const { return m_type; }
|
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
const SIM_MODEL* GetBaseModel() const { return m_baseModel; }
|
2022-10-09 18:44:03 +00:00
|
|
|
virtual void SetBaseModel( const SIM_MODEL& aBaseModel )
|
|
|
|
{
|
|
|
|
if( GetType() != aBaseModel.GetType() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Simulation model type must be the same as of its base class: '%s', but is '%s'" ),
|
|
|
|
aBaseModel.GetTypeInfo().fieldValue,
|
|
|
|
GetTypeInfo().fieldValue ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_baseModel = &aBaseModel;
|
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
int GetPinCount() const { return static_cast<int>( m_pins.size() ); }
|
2022-05-08 09:54:35 +00:00
|
|
|
const PIN& GetPin( unsigned aIndex ) const { return m_pins.at( aIndex ); }
|
|
|
|
|
|
|
|
std::vector<std::reference_wrapper<const PIN>> GetPins() const;
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-11-25 04:31:03 +00:00
|
|
|
void SetPinSymbolPinNumber( int aPinIndex, const std::string& aSymbolPinNumber );
|
|
|
|
void SetPinSymbolPinNumber( const std::string& aPinName, const std::string& aSymbolPinNumber );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
int GetParamCount() const { return static_cast<int>( m_params.size() ); }
|
2022-09-29 08:35:01 +00:00
|
|
|
virtual const PARAM& GetParam( unsigned aParamIndex ) const; // Return base parameter unless it's overridden.
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-10-24 01:11:52 +00:00
|
|
|
virtual const PARAM* GetTunerParam() const { return nullptr; }
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
const PARAM* FindParam( const std::string& aParamName ) const;
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
std::vector<std::reference_wrapper<const PARAM>> GetParams() const;
|
|
|
|
|
|
|
|
const PARAM& GetUnderlyingParam( unsigned aParamIndex ) const; // Return the actual parameter.
|
|
|
|
const PARAM& GetBaseParam( unsigned aParamIndex ) const; // Always return base parameter if it exists.
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-10-12 02:26:16 +00:00
|
|
|
virtual void SetParamValue( int aParamIndex, const SIM_VALUE& aValue );
|
|
|
|
void SetParamValue( int aParamIndex, const std::string& aValue,
|
2022-10-04 15:17:41 +00:00
|
|
|
SIM_VALUE::NOTATION aNotation = SIM_VALUE::NOTATION::SI );
|
2022-10-12 02:26:16 +00:00
|
|
|
void SetParamValue( const std::string& aParamName, const SIM_VALUE& aValue );
|
|
|
|
void SetParamValue( const std::string& aParamName, const std::string& aValue,
|
2022-10-04 15:17:41 +00:00
|
|
|
SIM_VALUE::NOTATION aNotation = SIM_VALUE::NOTATION::SI );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
bool HasOverrides() const;
|
2022-05-31 02:55:48 +00:00
|
|
|
bool HasNonInstanceOverrides() const;
|
2022-06-21 02:22:52 +00:00
|
|
|
bool HasSpiceNonInstanceOverrides() const;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// Can modifying a model parameter also modify other parameters?
|
|
|
|
virtual bool HasAutofill() const { return false; }
|
2022-11-11 02:07:34 +00:00
|
|
|
virtual bool HasPrimaryValue() const { return false; }
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
void SetIsEnabled( bool aIsEnabled ) { m_isEnabled = aIsEnabled; }
|
|
|
|
bool IsEnabled() const { return m_isEnabled; }
|
2022-05-08 09:54:35 +00:00
|
|
|
|
2022-11-22 00:46:02 +00:00
|
|
|
void SetIsStoredInValue( bool aIsStoredInValue )
|
|
|
|
{
|
|
|
|
if( HasPrimaryValue() )
|
|
|
|
m_isStoredInValue = aIsStoredInValue;
|
|
|
|
}
|
2022-11-18 07:37:58 +00:00
|
|
|
bool IsStoredInValue() const { return m_isStoredInValue; }
|
2022-10-16 03:10:57 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
protected:
|
2022-11-07 18:33:31 +00:00
|
|
|
static std::unique_ptr<SIM_MODEL> Create( TYPE aType );
|
2022-09-18 19:22:59 +00:00
|
|
|
|
2022-09-15 03:25:57 +00:00
|
|
|
SIM_MODEL( TYPE aType );
|
2022-11-11 02:07:34 +00:00
|
|
|
SIM_MODEL( TYPE aType,
|
|
|
|
std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator );
|
|
|
|
SIM_MODEL( TYPE aType,
|
|
|
|
std::unique_ptr<SPICE_GENERATOR> aSpiceGenerator,
|
|
|
|
std::unique_ptr<SIM_SERDE> aSerde );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-08-11 00:42:16 +00:00
|
|
|
virtual void CreatePins( unsigned aSymbolPinCount );
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
std::vector<PARAM> m_params;
|
2022-09-29 08:35:01 +00:00
|
|
|
const SIM_MODEL* m_baseModel;
|
2022-11-11 02:07:34 +00:00
|
|
|
std::unique_ptr<SIM_SERDE> m_serde;
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
private:
|
2022-09-22 05:38:45 +00:00
|
|
|
static TYPE readTypeFromSpiceStrings( const std::string& aTypeString,
|
|
|
|
const std::string& aLevel = "",
|
|
|
|
const std::string& aVersion = "",
|
2022-05-31 02:55:48 +00:00
|
|
|
bool aSkipDefaultLevel = true );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void doReadDataFields( unsigned aSymbolPinCount, const std::vector<T>* aFields );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-05-08 09:54:35 +00:00
|
|
|
void doWriteFields( std::vector<T>& aFields ) const;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-09-14 01:15:42 +00:00
|
|
|
virtual bool requiresSpiceModelLine() const;
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
virtual std::vector<std::string> getPinNames() const { return {}; }
|
2022-08-24 04:13:55 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-09-14 07:19:25 +00:00
|
|
|
std::unique_ptr<SPICE_GENERATOR> m_spiceGenerator;
|
2022-04-12 14:37:06 +00:00
|
|
|
|
|
|
|
const TYPE m_type;
|
|
|
|
std::vector<PIN> m_pins;
|
2022-06-21 02:22:52 +00:00
|
|
|
bool m_isEnabled;
|
2022-11-18 07:37:58 +00:00
|
|
|
bool m_isStoredInValue;
|
2022-02-21 03:58:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SIM_MODEL_H
|