50#include <boost/algorithm/string.hpp>
52#include <pegtl/contrib/parse_tree.hpp>
57using TYPE = SIM_MODEL::TYPE;
67 case DEVICE_T::NONE:
return {
"",
"",
true };
68 case DEVICE_T::R:
return {
"R",
"Resistor",
true };
69 case DEVICE_T::C:
return {
"C",
"Capacitor",
true };
70 case DEVICE_T::L:
return {
"L",
"Inductor",
true };
71 case DEVICE_T::K:
return {
"K",
"Mutual Inductance Statement",
true };
72 case DEVICE_T::TLINE:
return {
"TLINE",
"Transmission Line",
true };
73 case DEVICE_T::SW:
return {
"SW",
"Switch",
true };
75 case DEVICE_T::D:
return {
"D",
"Diode",
true };
76 case DEVICE_T::NPN:
return {
"NPN",
"NPN BJT",
true };
77 case DEVICE_T::PNP:
return {
"PNP",
"PNP BJT",
true };
79 case DEVICE_T::NJFET:
return {
"NJFET",
"N-channel JFET",
true };
80 case DEVICE_T::PJFET:
return {
"PJFET",
"P-channel JFET",
true };
82 case DEVICE_T::NMOS:
return {
"NMOS",
"N-channel MOSFET",
true };
83 case DEVICE_T::PMOS:
return {
"PMOS",
"P-channel MOSFET",
true };
84 case DEVICE_T::NMES:
return {
"NMES",
"N-channel MESFET",
true };
85 case DEVICE_T::PMES:
return {
"PMES",
"P-channel MESFET",
true };
87 case DEVICE_T::V:
return {
"V",
"Voltage Source",
true };
88 case DEVICE_T::I:
return {
"I",
"Current Source",
true };
89 case DEVICE_T::E:
return {
"E",
"Voltage Source",
false };
90 case DEVICE_T::F:
return {
"F",
"Current Source",
false };
91 case DEVICE_T::G:
return {
"G",
"Current Source",
false };
92 case DEVICE_T::H:
return {
"H",
"Voltage Source",
false };
94 case DEVICE_T::KIBIS:
return {
"IBIS",
"IBIS Model",
false };
96 case DEVICE_T::SUBCKT:
return {
"SUBCKT",
"Subcircuit",
false };
97 case DEVICE_T::XSPICE:
return {
"XSPICE",
"XSPICE Code Model",
true };
98 case DEVICE_T::SPICE:
return {
"SPICE",
"Raw SPICE Element",
true };
100 default: wxFAIL;
return {};
112 case TYPE::NONE:
return { DEVICE_T::NONE,
"",
"" };
114 case TYPE::R:
return { DEVICE_T::R,
"",
"Ideal" };
115 case TYPE::R_POT:
return { DEVICE_T::R,
"POT",
"Potentiometer" };
116 case TYPE::R_BEHAVIORAL:
return { DEVICE_T::R,
"=",
"Behavioral" };
118 case TYPE::C:
return { DEVICE_T::C,
"",
"Ideal" };
119 case TYPE::C_BEHAVIORAL:
return { DEVICE_T::C,
"=",
"Behavioral" };
121 case TYPE::L:
return { DEVICE_T::L,
"",
"Ideal" };
122 case TYPE::L_BEHAVIORAL:
return { DEVICE_T::L,
"=",
"Behavioral" };
124 case TYPE::K:
return { DEVICE_T::K,
"",
"Mutual Inductance Statement" };
126 case TYPE::TLINE_Z0:
return { DEVICE_T::TLINE,
"",
"Characteristic impedance" };
127 case TYPE::TLINE_RLGC:
return { DEVICE_T::TLINE,
"RLGC",
"RLGC" };
129 case TYPE::SW_V:
return { DEVICE_T::SW,
"V",
"Voltage-controlled" };
130 case TYPE::SW_I:
return { DEVICE_T::SW,
"I",
"Current-controlled" };
132 case TYPE::D:
return { DEVICE_T::D,
"",
"" };
134 case TYPE::NPN_VBIC:
return { DEVICE_T::NPN,
"VBIC",
"VBIC" };
135 case TYPE::PNP_VBIC:
return { DEVICE_T::PNP,
"VBIC",
"VBIC" };
136 case TYPE::NPN_GUMMELPOON:
return { DEVICE_T::NPN,
"GUMMELPOON",
"Gummel-Poon" };
137 case TYPE::PNP_GUMMELPOON:
return { DEVICE_T::PNP,
"GUMMELPOON",
"Gummel-Poon" };
139 case TYPE::NPN_HICUM2:
return { DEVICE_T::NPN,
"HICUML2",
"HICUM level 2" };
140 case TYPE::PNP_HICUM2:
return { DEVICE_T::PNP,
"HICUML2",
"HICUM level 2" };
143 case TYPE::NJFET_SHICHMANHODGES:
return { DEVICE_T::NJFET,
"SHICHMANHODGES",
"Shichman-Hodges" };
144 case TYPE::PJFET_SHICHMANHODGES:
return { DEVICE_T::PJFET,
"SHICHMANHODGES",
"Shichman-Hodges" };
145 case TYPE::NJFET_PARKERSKELLERN:
return { DEVICE_T::NJFET,
"PARKERSKELLERN",
"Parker-Skellern" };
146 case TYPE::PJFET_PARKERSKELLERN:
return { DEVICE_T::PJFET,
"PARKERSKELLERN",
"Parker-Skellern" };
148 case TYPE::NMES_STATZ:
return { DEVICE_T::NMES,
"STATZ",
"Statz" };
149 case TYPE::PMES_STATZ:
return { DEVICE_T::PMES,
"STATZ",
"Statz" };
150 case TYPE::NMES_YTTERDAL:
return { DEVICE_T::NMES,
"YTTERDAL",
"Ytterdal" };
151 case TYPE::PMES_YTTERDAL:
return { DEVICE_T::PMES,
"YTTERDAL",
"Ytterdal" };
152 case TYPE::NMES_HFET1:
return { DEVICE_T::NMES,
"HFET1",
"HFET1" };
153 case TYPE::PMES_HFET1:
return { DEVICE_T::PMES,
"HFET1",
"HFET1" };
154 case TYPE::NMES_HFET2:
return { DEVICE_T::NMES,
"HFET2",
"HFET2" };
155 case TYPE::PMES_HFET2:
return { DEVICE_T::PMES,
"HFET2",
"HFET2" };
157 case TYPE::NMOS_VDMOS:
return { DEVICE_T::NMOS,
"VDMOS",
"VDMOS" };
158 case TYPE::PMOS_VDMOS:
return { DEVICE_T::PMOS,
"VDMOS",
"VDMOS" };
159 case TYPE::NMOS_MOS1:
return { DEVICE_T::NMOS,
"MOS1",
"Classical quadratic (MOS1)" };
160 case TYPE::PMOS_MOS1:
return { DEVICE_T::PMOS,
"MOS1",
"Classical quadratic (MOS1)" };
161 case TYPE::NMOS_MOS2:
return { DEVICE_T::NMOS,
"MOS2",
"Grove-Frohman (MOS2)" };
162 case TYPE::PMOS_MOS2:
return { DEVICE_T::PMOS,
"MOS2",
"Grove-Frohman (MOS2)" };
163 case TYPE::NMOS_MOS3:
return { DEVICE_T::NMOS,
"MOS3",
"MOS3" };
164 case TYPE::PMOS_MOS3:
return { DEVICE_T::PMOS,
"MOS3",
"MOS3" };
165 case TYPE::NMOS_BSIM1:
return { DEVICE_T::NMOS,
"BSIM1",
"BSIM1" };
166 case TYPE::PMOS_BSIM1:
return { DEVICE_T::PMOS,
"BSIM1",
"BSIM1" };
167 case TYPE::NMOS_BSIM2:
return { DEVICE_T::NMOS,
"BSIM2",
"BSIM2" };
168 case TYPE::PMOS_BSIM2:
return { DEVICE_T::PMOS,
"BSIM2",
"BSIM2" };
169 case TYPE::NMOS_MOS6:
return { DEVICE_T::NMOS,
"MOS6",
"MOS6" };
170 case TYPE::PMOS_MOS6:
return { DEVICE_T::PMOS,
"MOS6",
"MOS6" };
171 case TYPE::NMOS_BSIM3:
return { DEVICE_T::NMOS,
"BSIM3",
"BSIM3" };
172 case TYPE::PMOS_BSIM3:
return { DEVICE_T::PMOS,
"BSIM3",
"BSIM3" };
173 case TYPE::NMOS_MOS9:
return { DEVICE_T::NMOS,
"MOS9",
"MOS9" };
174 case TYPE::PMOS_MOS9:
return { DEVICE_T::PMOS,
"MOS9",
"MOS9" };
175 case TYPE::NMOS_B4SOI:
return { DEVICE_T::NMOS,
"B4SOI",
"BSIM4 SOI (B4SOI)" };
176 case TYPE::PMOS_B4SOI:
return { DEVICE_T::PMOS,
"B4SOI",
"BSIM4 SOI (B4SOI)" };
177 case TYPE::NMOS_BSIM4:
return { DEVICE_T::NMOS,
"BSIM4",
"BSIM4" };
178 case TYPE::PMOS_BSIM4:
return { DEVICE_T::PMOS,
"BSIM4",
"BSIM4" };
183 case TYPE::NMOS_B3SOIFD:
return { DEVICE_T::NMOS,
"B3SOIFD",
"B3SOIFD (BSIM3 FD-SOI)" };
184 case TYPE::PMOS_B3SOIFD:
return { DEVICE_T::PMOS,
"B3SOIFD",
"B3SOIFD (BSIM3 FD-SOI)" };
185 case TYPE::NMOS_B3SOIDD:
return { DEVICE_T::NMOS,
"B3SOIDD",
"B3SOIDD (BSIM3 SOI)" };
186 case TYPE::PMOS_B3SOIDD:
return { DEVICE_T::PMOS,
"B3SOIDD",
"B3SOIDD (BSIM3 SOI)" };
187 case TYPE::NMOS_B3SOIPD:
return { DEVICE_T::NMOS,
"B3SOIPD",
"B3SOIPD (BSIM3 PD-SOI)" };
188 case TYPE::PMOS_B3SOIPD:
return { DEVICE_T::PMOS,
"B3SOIPD",
"B3SOIPD (BSIM3 PD-SOI)" };
191 case TYPE::NMOS_HISIM2:
return { DEVICE_T::NMOS,
"HISIM2",
"HiSIM2" };
192 case TYPE::PMOS_HISIM2:
return { DEVICE_T::PMOS,
"HISIM2",
"HiSIM2" };
193 case TYPE::NMOS_HISIMHV1:
return { DEVICE_T::NMOS,
"HISIMHV1",
"HiSIM_HV1" };
194 case TYPE::PMOS_HISIMHV1:
return { DEVICE_T::PMOS,
"HISIMHV1",
"HiSIM_HV1" };
195 case TYPE::NMOS_HISIMHV2:
return { DEVICE_T::NMOS,
"HISIMHV2",
"HiSIM_HV2" };
196 case TYPE::PMOS_HISIMHV2:
return { DEVICE_T::PMOS,
"HISIMHV2",
"HiSIM_HV2" };
198 case TYPE::V:
return { DEVICE_T::V,
"DC",
"DC", };
199 case TYPE::V_SIN:
return { DEVICE_T::V,
"SIN",
"Sine" };
200 case TYPE::V_PULSE:
return { DEVICE_T::V,
"PULSE",
"Pulse" };
201 case TYPE::V_EXP:
return { DEVICE_T::V,
"EXP",
"Exponential" };
202 case TYPE::V_AM:
return { DEVICE_T::V,
"AM",
"Amplitude modulated" };
203 case TYPE::V_SFFM:
return { DEVICE_T::V,
"SFFM",
"Single-frequency FM" };
204 case TYPE::V_VCL:
return { DEVICE_T::E,
"",
"Voltage-controlled" };
205 case TYPE::V_CCL:
return { DEVICE_T::H,
"",
"Current-controlled" };
206 case TYPE::V_PWL:
return { DEVICE_T::V,
"PWL",
"Piecewise linear" };
207 case TYPE::V_WHITENOISE:
return { DEVICE_T::V,
"WHITENOISE",
"White noise" };
208 case TYPE::V_PINKNOISE:
return { DEVICE_T::V,
"PINKNOISE",
"Pink noise (1/f)" };
209 case TYPE::V_BURSTNOISE:
return { DEVICE_T::V,
"BURSTNOISE",
"Burst noise" };
210 case TYPE::V_RANDUNIFORM:
return { DEVICE_T::V,
"RANDUNIFORM",
"Random uniform" };
211 case TYPE::V_RANDGAUSSIAN:
return { DEVICE_T::V,
"RANDGAUSSIAN",
"Random Gaussian" };
212 case TYPE::V_RANDEXP:
return { DEVICE_T::V,
"RANDEXP",
"Random exponential" };
213 case TYPE::V_RANDPOISSON:
return { DEVICE_T::V,
"RANDPOISSON",
"Random Poisson" };
214 case TYPE::V_BEHAVIORAL:
return { DEVICE_T::V,
"=",
"Behavioral" };
216 case TYPE::I:
return { DEVICE_T::I,
"DC",
"DC", };
217 case TYPE::I_SIN:
return { DEVICE_T::I,
"SIN",
"Sine" };
218 case TYPE::I_PULSE:
return { DEVICE_T::I,
"PULSE",
"Pulse" };
219 case TYPE::I_EXP:
return { DEVICE_T::I,
"EXP",
"Exponential" };
220 case TYPE::I_AM:
return { DEVICE_T::I,
"AM",
"Amplitude modulated" };
221 case TYPE::I_SFFM:
return { DEVICE_T::I,
"SFFM",
"Single-frequency FM" };
222 case TYPE::I_VCL:
return { DEVICE_T::G,
"",
"Voltage-controlled" };
223 case TYPE::I_CCL:
return { DEVICE_T::F,
"",
"Current-controlled" };
224 case TYPE::I_PWL:
return { DEVICE_T::I,
"PWL",
"Piecewise linear" };
225 case TYPE::I_WHITENOISE:
return { DEVICE_T::I,
"WHITENOISE",
"White noise" };
226 case TYPE::I_PINKNOISE:
return { DEVICE_T::I,
"PINKNOISE",
"Pink noise (1/f)" };
227 case TYPE::I_BURSTNOISE:
return { DEVICE_T::I,
"BURSTNOISE",
"Burst noise" };
228 case TYPE::I_RANDUNIFORM:
return { DEVICE_T::I,
"RANDUNIFORM",
"Random uniform" };
229 case TYPE::I_RANDGAUSSIAN:
return { DEVICE_T::I,
"RANDGAUSSIAN",
"Random Gaussian" };
230 case TYPE::I_RANDEXP:
return { DEVICE_T::I,
"RANDEXP",
"Random exponential" };
231 case TYPE::I_RANDPOISSON:
return { DEVICE_T::I,
"RANDPOISSON",
"Random Poisson" };
232 case TYPE::I_BEHAVIORAL:
return { DEVICE_T::I,
"=",
"Behavioral" };
234 case TYPE::SUBCKT:
return { DEVICE_T::SUBCKT,
"",
"Subcircuit" };
235 case TYPE::XSPICE:
return { DEVICE_T::XSPICE,
"",
"" };
237 case TYPE::KIBIS_DEVICE:
return { DEVICE_T::KIBIS,
"DEVICE",
"Device" };
238 case TYPE::KIBIS_DRIVER_DC:
return { DEVICE_T::KIBIS,
"DCDRIVER",
"DC driver" };
239 case TYPE::KIBIS_DRIVER_RECT:
return { DEVICE_T::KIBIS,
"RECTDRIVER",
"Rectangular wave driver" };
240 case TYPE::KIBIS_DRIVER_PRBS:
return { DEVICE_T::KIBIS,
"PRBSDRIVER",
"PRBS driver" };
242 case TYPE::RAWSPICE:
return { DEVICE_T::SPICE,
"",
"" };
244 default: wxFAIL;
return {};
255 case TYPE::R:
return {
"R",
"" };
256 case TYPE::R_POT:
return {
"A",
"" };
257 case TYPE::R_BEHAVIORAL:
return {
"R",
"",
"",
"0",
false,
true };
259 case TYPE::C:
return {
"C",
"" };
260 case TYPE::C_BEHAVIORAL:
return {
"C",
"",
"",
"0",
false,
true };
262 case TYPE::L:
return {
"L",
"" };
263 case TYPE::L_BEHAVIORAL:
return {
"L",
"",
"",
"0",
false,
true };
265 case TYPE::K:
return {
"K",
"" };
268 case TYPE::TLINE_Z0:
return {
"O",
"LTRA" };
269 case TYPE::TLINE_RLGC:
return {
"O",
"LTRA" };
271 case TYPE::SW_V:
return {
"S",
"SW" };
272 case TYPE::SW_I:
return {
"W",
"CSW" };
274 case TYPE::D:
return {
"D",
"D" };
276 case TYPE::NPN_VBIC:
return {
"Q",
"NPN",
"",
"4" };
277 case TYPE::PNP_VBIC:
return {
"Q",
"PNP",
"",
"4" };
278 case TYPE::NPN_GUMMELPOON:
return {
"Q",
"NPN",
"",
"1",
true };
279 case TYPE::PNP_GUMMELPOON:
return {
"Q",
"PNP",
"",
"1",
true };
280 case TYPE::NPN_HICUM2:
return {
"Q",
"NPN",
"",
"8" };
281 case TYPE::PNP_HICUM2:
return {
"Q",
"PNP",
"",
"8" };
283 case TYPE::NJFET_SHICHMANHODGES:
return {
"J",
"NJF",
"",
"1",
true };
284 case TYPE::PJFET_SHICHMANHODGES:
return {
"J",
"PJF",
"",
"1",
true };
285 case TYPE::NJFET_PARKERSKELLERN:
return {
"J",
"NJF",
"",
"2" };
286 case TYPE::PJFET_PARKERSKELLERN:
return {
"J",
"PJF",
"",
"2" };
288 case TYPE::NMES_STATZ:
return {
"Z",
"NMF",
"",
"1",
true };
289 case TYPE::PMES_STATZ:
return {
"Z",
"PMF",
"",
"1",
true };
290 case TYPE::NMES_YTTERDAL:
return {
"Z",
"NMF",
"",
"2" };
291 case TYPE::PMES_YTTERDAL:
return {
"Z",
"PMF",
"",
"2" };
292 case TYPE::NMES_HFET1:
return {
"Z",
"NMF",
"",
"5" };
293 case TYPE::PMES_HFET1:
return {
"Z",
"PMF",
"",
"5" };
294 case TYPE::NMES_HFET2:
return {
"Z",
"NMF",
"",
"6" };
295 case TYPE::PMES_HFET2:
return {
"Z",
"PMF",
"",
"6" };
297 case TYPE::NMOS_VDMOS:
return {
"M",
"VDMOS NCHAN" };
298 case TYPE::PMOS_VDMOS:
return {
"M",
"VDMOS PCHAN" };
299 case TYPE::NMOS_MOS1:
return {
"M",
"NMOS",
"",
"1",
true };
300 case TYPE::PMOS_MOS1:
return {
"M",
"PMOS",
"",
"1",
true };
301 case TYPE::NMOS_MOS2:
return {
"M",
"NMOS",
"",
"2" };
302 case TYPE::PMOS_MOS2:
return {
"M",
"PMOS",
"",
"2" };
303 case TYPE::NMOS_MOS3:
return {
"M",
"NMOS",
"",
"3" };
304 case TYPE::PMOS_MOS3:
return {
"M",
"PMOS",
"",
"3" };
305 case TYPE::NMOS_BSIM1:
return {
"M",
"NMOS",
"",
"4" };
306 case TYPE::PMOS_BSIM1:
return {
"M",
"PMOS",
"",
"4" };
307 case TYPE::NMOS_BSIM2:
return {
"M",
"NMOS",
"",
"5" };
308 case TYPE::PMOS_BSIM2:
return {
"M",
"PMOS",
"",
"5" };
309 case TYPE::NMOS_MOS6:
return {
"M",
"NMOS",
"",
"6" };
310 case TYPE::PMOS_MOS6:
return {
"M",
"PMOS",
"",
"6" };
311 case TYPE::NMOS_BSIM3:
return {
"M",
"NMOS",
"",
"8" };
312 case TYPE::PMOS_BSIM3:
return {
"M",
"PMOS",
"",
"8" };
313 case TYPE::NMOS_MOS9:
return {
"M",
"NMOS",
"",
"9" };
314 case TYPE::PMOS_MOS9:
return {
"M",
"PMOS",
"",
"9" };
315 case TYPE::NMOS_B4SOI:
return {
"M",
"NMOS",
"",
"10" };
316 case TYPE::PMOS_B4SOI:
return {
"M",
"PMOS",
"",
"10" };
317 case TYPE::NMOS_BSIM4:
return {
"M",
"NMOS",
"",
"14" };
318 case TYPE::PMOS_BSIM4:
return {
"M",
"PMOS",
"",
"14" };
323 case TYPE::NMOS_B3SOIFD:
return {
"M",
"NMOS",
"",
"55" };
324 case TYPE::PMOS_B3SOIFD:
return {
"M",
"PMOS",
"",
"55" };
325 case TYPE::NMOS_B3SOIDD:
return {
"M",
"NMOS",
"",
"56" };
326 case TYPE::PMOS_B3SOIDD:
return {
"M",
"PMOS",
"",
"56" };
327 case TYPE::NMOS_B3SOIPD:
return {
"M",
"NMOS",
"",
"57" };
328 case TYPE::PMOS_B3SOIPD:
return {
"M",
"PMOS",
"",
"57" };
331 case TYPE::NMOS_HISIM2:
return {
"M",
"NMOS",
"",
"68" };
332 case TYPE::PMOS_HISIM2:
return {
"M",
"PMOS",
"",
"68" };
333 case TYPE::NMOS_HISIMHV1:
return {
"M",
"NMOS",
"",
"73",
false,
false,
"1.2.4" };
334 case TYPE::PMOS_HISIMHV1:
return {
"M",
"PMOS",
"",
"73",
false,
false,
"1.2.4" };
335 case TYPE::NMOS_HISIMHV2:
return {
"M",
"NMOS",
"",
"73",
false,
false,
"2.2.0" };
336 case TYPE::PMOS_HISIMHV2:
return {
"M",
"PMOS",
"",
"73",
false,
false,
"2.2.0" };
338 case TYPE::V:
return {
"V",
"",
"DC" };
339 case TYPE::V_SIN:
return {
"V",
"",
"SIN" };
340 case TYPE::V_PULSE:
return {
"V",
"",
"PULSE" };
341 case TYPE::V_EXP:
return {
"V",
"",
"EXP" };
342 case TYPE::V_AM:
return {
"V",
"",
"AM" };
343 case TYPE::V_SFFM:
return {
"V",
"",
"SFFM" };
344 case TYPE::V_VCL:
return {
"E",
"",
"" };
345 case TYPE::V_CCL:
return {
"H",
"",
"" };
346 case TYPE::V_PWL:
return {
"V",
"",
"PWL" };
347 case TYPE::V_WHITENOISE:
return {
"V",
"",
"TRNOISE" };
348 case TYPE::V_PINKNOISE:
return {
"V",
"",
"TRNOISE" };
349 case TYPE::V_BURSTNOISE:
return {
"V",
"",
"TRNOISE" };
350 case TYPE::V_RANDUNIFORM:
return {
"V",
"",
"TRRANDOM" };
351 case TYPE::V_RANDGAUSSIAN:
return {
"V",
"",
"TRRANDOM" };
352 case TYPE::V_RANDEXP:
return {
"V",
"",
"TRRANDOM" };
353 case TYPE::V_RANDPOISSON:
return {
"V",
"",
"TRRANDOM" };
354 case TYPE::V_BEHAVIORAL:
return {
"B" };
356 case TYPE::I:
return {
"I",
"",
"DC" };
357 case TYPE::I_PULSE:
return {
"I",
"",
"PULSE" };
358 case TYPE::I_SIN:
return {
"I",
"",
"SIN" };
359 case TYPE::I_EXP:
return {
"I",
"",
"EXP" };
360 case TYPE::I_AM:
return {
"V",
"",
"AM" };
361 case TYPE::I_SFFM:
return {
"V",
"",
"SFFM" };
362 case TYPE::I_VCL:
return {
"G",
"",
"" };
363 case TYPE::I_CCL:
return {
"F",
"",
"" };
364 case TYPE::I_PWL:
return {
"I",
"",
"PWL" };
365 case TYPE::I_WHITENOISE:
return {
"I",
"",
"TRNOISE" };
366 case TYPE::I_PINKNOISE:
return {
"I",
"",
"TRNOISE" };
367 case TYPE::I_BURSTNOISE:
return {
"I",
"",
"TRNOISE" };
368 case TYPE::I_RANDUNIFORM:
return {
"I",
"",
"TRRANDOM" };
369 case TYPE::I_RANDGAUSSIAN:
return {
"I",
"",
"TRRANDOM" };
370 case TYPE::I_RANDEXP:
return {
"I",
"",
"TRRANDOM" };
371 case TYPE::I_RANDPOISSON:
return {
"I",
"",
"TRRANDOM" };
372 case TYPE::I_BEHAVIORAL:
return {
"B" };
374 case TYPE::SUBCKT:
return {
"X" };
375 case TYPE::XSPICE:
return {
"A" };
377 case TYPE::KIBIS_DEVICE:
return {
"X" };
378 case TYPE::KIBIS_DRIVER_DC:
return {
"X" };
379 case TYPE::KIBIS_DRIVER_RECT:
return {
"X" };
380 case TYPE::KIBIS_DRIVER_PRBS:
return {
"X" };
383 case TYPE::RAWSPICE:
return {};
385 default: wxFAIL;
return {};
395 if( !deviceTypeFieldValue.empty() )
397 for(
TYPE type : TYPE_ITERATOR() )
399 if( typeFieldValue ==
TypeInfo( type ).fieldValue )
407 if( typeFieldValue.empty() )
412 aReporter.
Report( wxString::Format(
_(
"No simulation model definition found for "
419 aReporter.
Report(
_(
"No simulation model definition found." ),
428 const std::vector<SCH_PIN*>& aPins )
448 for(
size_t ii = aFields.size() - 1; ii > 0; ii-- )
450 wxString currFieldName = aFields[ii].GetName();
452 auto end_candidate_list = aFields.begin() + ii - 1;
454 auto fieldIt = std::find_if( aFields.begin(), end_candidate_list,
457 return f.GetName() == currFieldName;
461 if( fieldIt != end_candidate_list )
462 aFields.erase( aFields.begin() + ii );
481 for(
auto& fld : aFields )
483 if( fld.GetId() >= lastFreeId )
484 lastFreeId = fld.GetId() + 1;
488 for(
auto& fld : aFields )
490 if( fld.GetId() < 0 )
491 fld.SetId( lastFreeId++ );
499 std::unique_ptr<SIM_MODEL> model =
Create( aType );
504 model->ReadDataFields(
static_cast<const std::vector<SCH_FIELD>*
>(
nullptr ), aPins );
508 wxFAIL_MSG(
"Shouldn't throw reading empty fields!" );
516 const std::vector<SCH_PIN*>& aPins,
519 std::unique_ptr<SIM_MODEL> model;
526 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
528 model = std::make_unique<SIM_MODEL_RAW_SPICE>();
532 model->SetBaseModel( *aBaseModel );
536 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( TYPE::NONE );
541 model->ReadDataFields(
static_cast<const std::vector<SCH_FIELD>*
>(
nullptr ), aPins );
545 wxFAIL_MSG(
"Shouldn't throw reading empty fields!" );
553 const std::vector<SCH_PIN*>& aPins,
554 const std::vector<SCH_FIELD>& aFields,
557 std::unique_ptr<SIM_MODEL> model;
568 type_override != TYPE::NONE )
570 type = type_override;
574 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
576 model = std::make_unique<SIM_MODEL_RAW_SPICE>();
580 model->SetBaseModel( *aBaseModel );
585 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
590 model->ReadDataFields( &aFields, aPins );
594 aReporter.
Report( wxString::Format(
_(
"Error reading simulation model from "
595 "symbol '%s':\n%s" ),
606 const std::vector<SCH_PIN*>& aPins,
607 bool aResolved,
REPORTER& aReporter )
614 model->ReadDataFields( &aFields, aPins );
629 if( modelData.empty() )
632 model = std::make_unique<SIM_MODEL_RAW_SPICE>( modelData );
636 model->createPins( aPins );
642 aReporter.
Report( wxString::Format(
_(
"Error reading simulation model from "
643 "symbol '%s':\n%s" ),
655 const wxString& aFieldName,
bool aResolve )
662 if( field.GetName() == aFieldName )
664 return aResolve ? field.GetShownText(
false ).ToStdString()
665 : field.GetText().ToStdString();
674 const std::string& aValue )
676 auto fieldIt = std::find_if( aFields.begin(), aFields.end(),
679 return f.GetName() == aFieldName;
682 if( fieldIt != aFields.end() )
685 aFields.erase( fieldIt );
687 fieldIt->SetText( aValue );
696 aFields.emplace_back(
VECTOR2I(), aFields.size(), parent, aFieldName );
698 aFields.back().SetText( aValue );
719 for(
int modelPinIndex = 0; modelPinIndex <
GetPinCount(); ++modelPinIndex )
722 return modelPinIndex;
742 wxS(
"Simulation model type must be the same as its base class!" ) );
750 std::vector<std::reference_wrapper<const SIM_MODEL_PIN>> pins;
752 for(
int modelPinIndex = 0; modelPinIndex <
GetPinCount(); ++modelPinIndex )
753 pins.emplace_back(
GetPin( modelPinIndex ) );
759 const wxString& aSymbolPinNumber )
761 if( aModelPinIndex >= 0 && aModelPinIndex < (
int)
m_modelPins.size() )
762 m_modelPins.at( aModelPinIndex ).symbolPinNumber = aSymbolPinNumber;
767 const wxString& aSymbolPinNumber )
771 if(
pin.modelPinName == aModelPinName )
773 pin.symbolPinNumber = aSymbolPinNumber;
780 int pinIndex = (int) strtol( aModelPinName.c_str(),
nullptr, 10 );
782 if( pinIndex < 1 || pinIndex > (
int)
m_modelPins.size() )
783 THROW_IO_ERROR( wxString::Format(
_(
"Unknown simulation model pin '%s'" ), aModelPinName ) );
785 m_modelPins[ --pinIndex ].symbolPinNumber = aSymbolPinNumber;
800 return boost::iequals(
name, aParamName );
820 return idx >= 0 ? &
GetParam( idx ) :
nullptr;
841 m_params.at( aParamIndex ).value = aValue;
851 [](
const std::string& aString )
853 for(
char c : aString )
855 if( c !=
'.' && ( c <
'0' || c >
'9' ) )
863 if( aValue.find(
',' ) != std::string::npos )
866 SIM_VALUE::NOTATION::SI ) );
868 else if( aNotation != SIM_VALUE::NOTATION::SI && !plainNumber( aValue ) )
871 SIM_VALUE::NOTATION::SI ) );
886 THROW_IO_ERROR( wxString::Format(
"Unknown simulation model parameter '%s'", aParamName ) );
899 return std::make_unique<SIM_MODEL_IDEAL>( aType );
902 return std::make_unique<SIM_MODEL_R_POT>();
905 return std::make_unique<SIM_MODEL_L_MUTUAL>();
907 case TYPE::R_BEHAVIORAL:
908 case TYPE::C_BEHAVIORAL:
909 case TYPE::L_BEHAVIORAL:
910 case TYPE::V_BEHAVIORAL:
911 case TYPE::I_BEHAVIORAL:
912 return std::make_unique<SIM_MODEL_BEHAVIORAL>( aType );
915 case TYPE::TLINE_RLGC:
916 return std::make_unique<SIM_MODEL_TLINE>( aType );
920 return std::make_unique<SIM_MODEL_SWITCH>( aType );
940 case TYPE::V_WHITENOISE:
941 case TYPE::I_WHITENOISE:
942 case TYPE::V_PINKNOISE:
943 case TYPE::I_PINKNOISE:
944 case TYPE::V_BURSTNOISE:
945 case TYPE::I_BURSTNOISE:
946 case TYPE::V_RANDUNIFORM:
947 case TYPE::I_RANDUNIFORM:
948 case TYPE::V_RANDGAUSSIAN:
949 case TYPE::I_RANDGAUSSIAN:
950 case TYPE::V_RANDEXP:
951 case TYPE::I_RANDEXP:
952 case TYPE::V_RANDPOISSON:
953 case TYPE::I_RANDPOISSON:
954 return std::make_unique<SIM_MODEL_SOURCE>( aType );
957 return std::make_unique<SIM_MODEL_SUBCKT>();
960 return std::make_unique<SIM_MODEL_XSPICE>( aType );
962 case TYPE::KIBIS_DEVICE:
963 case TYPE::KIBIS_DRIVER_DC:
964 case TYPE::KIBIS_DRIVER_RECT:
965 case TYPE::KIBIS_DRIVER_PRBS:
966 return std::make_unique<SIM_MODEL_IBIS>( aType );
969 return std::make_unique<SIM_MODEL_RAW_SPICE>();
972 return std::make_unique<SIM_MODEL_NGSPICE>( aType );
992 std::unique_ptr<SIM_MODEL_SERIALIZER> aSerializer ) :
993 m_baseModel( nullptr ),
994 m_serializer(
std::
move( aSerializer ) ),
995 m_spiceGenerator(
std::
move( aSpiceGenerator ) ),
998 m_isStoredInValue( false )
1012 std::vector<std::string> pinNames =
GetPinNames();
1014 for(
unsigned modelPinIndex = 0; modelPinIndex < pinNames.size(); ++modelPinIndex )
1016 wxString pinName = pinNames[ modelPinIndex ];
1017 bool optional =
false;
1019 if( pinName.StartsWith(
'<' ) && pinName.EndsWith(
'>' ) )
1021 pinName = pinName.Mid( 1, pinName.Length() - 2 );
1025 if( modelPinIndex < aSymbolPins.size() )
1027 AddPin( { pinNames.at( modelPinIndex ),
1028 aSymbolPins[ modelPinIndex ]->GetNumber().ToStdString() } );
1030 else if( !optional )
1032 AddPin( { pinNames.at( modelPinIndex ),
"" } );
1041 if(
m_type == TYPE::SUBCKT )
1057 if ( param.
value ==
"" )
1062 const std::string& baseValue = baseModel->m_params[ii].value;
1064 if( param.
value == baseValue )
1084 wxString* aModelType, wxString* aModelParams, wxString* aPinMap )
1113 auto convertNotation =
1114 [&](
const wxString& units ) -> wxString
1118 if( units == wxS(
"µ" ) || units == wxS(
"μ" ) )
1123 if( units == wxT(
"M" ) )
1124 return wxT(
"Meg" );
1128 if( units.Capitalize() == wxT(
"Meg" ) )
1136 []( wxString* mantissa )
1138 mantissa->Replace( wxS(
" " ), wxEmptyString );
1140 wxChar ambiguousSeparator =
'?';
1141 wxChar thousandsSeparator =
'?';
1142 bool thousandsSeparatorFound =
false;
1143 wxChar decimalSeparator =
'?';
1144 bool decimalSeparatorFound =
false;
1147 for(
int ii = (
int) mantissa->length() - 1; ii >= 0; --ii )
1149 wxChar c = mantissa->GetChar( ii );
1151 if( c >=
'0' && c <=
'9' )
1155 else if( c ==
'.' || c ==
',' )
1157 if( decimalSeparator !=
'?' || thousandsSeparator !=
'?' )
1161 if( c == decimalSeparator )
1163 if( thousandsSeparatorFound )
1165 else if( decimalSeparatorFound )
1168 decimalSeparatorFound =
true;
1170 else if( c == thousandsSeparator )
1175 thousandsSeparatorFound =
true;
1178 else if( ambiguousSeparator !=
'?' )
1183 if( c == ambiguousSeparator )
1186 thousandsSeparator = ambiguousSeparator;
1187 thousandsSeparatorFound =
true;
1188 decimalSeparator = c ==
'.' ?
',' :
'.';
1194 decimalSeparator = ambiguousSeparator;
1195 decimalSeparatorFound =
true;
1196 thousandsSeparator = c;
1197 thousandsSeparatorFound =
true;
1210 if( ( ii == 1 && mantissa->GetChar( 0 ) ==
'0' ) || digits != 3 )
1212 decimalSeparator = c;
1213 decimalSeparatorFound =
true;
1214 thousandsSeparator = c ==
'.' ?
',' :
'.';
1218 ambiguousSeparator = c;
1231 if( decimalSeparator ==
'?' && thousandsSeparator ==
'?' )
1233 decimalSeparator =
'.';
1234 thousandsSeparator =
',';
1237 mantissa->Replace( thousandsSeparator, wxEmptyString );
1238 mantissa->Replace( decimalSeparator,
'.' );
1243 wxString prefix = aSymbol.GetPrefix();
1247 std::vector<SCH_PIN*> pins = aSymbol.GetAllLibPins();
1254 if( pins.size() != 2 )
1257 if( ( ( *aDeviceType ==
"R" || *aDeviceType ==
"L" || *aDeviceType ==
"C" )
1258 && aModelType->IsEmpty() )
1260 (
library.IsEmpty() && modelName.IsEmpty()
1261 && aDeviceType->IsEmpty()
1262 && aModelType->IsEmpty()
1264 && ( prefix.StartsWith(
"R" ) || prefix.StartsWith(
"L" ) || prefix.StartsWith(
"C" ) ) ) )
1266 if( aModelParams->IsEmpty() )
1268 wxRegEx idealVal( wxT(
"^"
1270 "([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
1271 "([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
1273 "([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
1276 if( idealVal.Matches( value ) )
1278 wxString valueMantissa( idealVal.GetMatch( value, 1 ) );
1279 wxString valueExponent( idealVal.GetMatch( value, 2 ) );
1280 wxString valueFraction( idealVal.GetMatch( value, 6 ) );
1285 if( valueMantissa.Contains( wxT(
"." ) ) || valueFraction.IsEmpty() )
1287 aModelParams->Printf( wxT(
"%s=\"%s%s\"" ),
1288 prefix.Left(1).Lower(),
1290 convertNotation( valueExponent ) );
1294 aModelParams->Printf( wxT(
"%s=\"%s.%s%s\"" ),
1295 prefix.Left(1).Lower(),
1298 convertNotation( valueExponent ) );
1303 *aModelType = wxT(
"=" );
1304 aModelParams->Printf( wxT(
"%s=\"%s\"" ), prefix.Left(1).Lower(), value );
1308 if( aDeviceType->IsEmpty() )
1309 *aDeviceType = prefix.Left( 1 );
1311 if( aPinMap->IsEmpty() )
1312 aPinMap->Printf( wxT(
"%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
1317 if( ( ( *aDeviceType == wxT(
"V" ) || *aDeviceType == wxT(
"I" ) )
1318 && ( aModelType->IsEmpty() || *aModelType == wxT(
"DC" ) ) )
1320 ( aDeviceType->IsEmpty()
1321 && aModelType->IsEmpty()
1323 && ( prefix.StartsWith(
"V" ) || prefix.StartsWith(
"I" ) ) ) )
1325 if( !value.IsEmpty() )
1327 wxString param =
"dc";
1329 if( value.StartsWith( wxT(
"DC " ) ) )
1331 value = value.Right( value.Length() - 3 );
1333 else if( value.StartsWith( wxT(
"AC " ) ) )
1335 value = value.Right( value.Length() - 3 );
1339 wxRegEx sourceVal( wxT(
"^"
1341 "([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
1347 if( sourceVal.Matches( value ) )
1349 wxString valueMantissa( sourceVal.GetMatch( value, 1 ) );
1350 wxString valueExponent( sourceVal.GetMatch( value, 2 ) );
1351 wxString valueFraction( sourceVal.GetMatch( value, 6 ) );
1356 if( valueMantissa.Contains( wxT(
"." ) ) || valueFraction.IsEmpty() )
1358 aModelParams->Printf( wxT(
"%s=\"%s%s\" %s" ),
1361 convertNotation( valueExponent ),
1366 aModelParams->Printf( wxT(
"%s=\"%s.%s%s\" %s" ),
1370 convertNotation( valueExponent ),
1376 aModelParams->Printf( wxT(
"%s=\"%s\" %s" ),
1383 if( aDeviceType->IsEmpty() )
1384 *aDeviceType = prefix.Left( 1 );
1386 if( aModelType->IsEmpty() )
1387 *aModelType = wxT(
"DC" );
1389 if( aPinMap->IsEmpty() )
1390 aPinMap->Printf( wxT(
"%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
1399template bool SIM_MODEL::InferSimModel<SCH_SYMBOL>(
SCH_SYMBOL& aSymbol,
1400 std::vector<SCH_FIELD>* aFields,
bool aResolve,
1402 wxString* aDeviceType, wxString* aModelType,
1403 wxString* aModelParams, wxString* aPinMap );
1404template bool SIM_MODEL::InferSimModel<LIB_SYMBOL>(
LIB_SYMBOL& aSymbol,
1405 std::vector<SCH_FIELD>* aFields,
bool aResolve,
1407 wxString* aDeviceType, wxString* aModelType,
1408 wxString* aModelParams, wxString* aPinMap );
1411template <
typename T>
1419 m_Attributes.m_Visible =
false;
1424 FIELD_INFO(
const wxString& aText,
SCH_FIELD* aField ) :
1430 bool IsEmpty()
const {
return m_Text.IsEmpty(); }
1432 SCH_FIELD CreateField( T* aSymbol,
const wxString& aFieldName )
1434 SCH_FIELD field( aSymbol, -1, aFieldName );
1454 wxString existing_deviceSubtype;
1456 if( existing_deviceSubtypeField )
1457 existing_deviceSubtype = existing_deviceSubtypeField->
GetShownText(
false ).Upper();
1459 if( existing_deviceField
1460 || existing_deviceSubtypeField
1461 || existing_pinsField
1462 || existing_paramsField )
1468 if( existing_deviceSubtype == wxS(
"POT" ) )
1470 if( existing_pinsField )
1472 wxString pinMap = existing_pinsField->
GetText();
1473 pinMap.Replace( wxS(
"=+" ), wxS(
"=r1" ) );
1474 pinMap.Replace( wxS(
"=-" ), wxS(
"=r0" ) );
1475 existing_pinsField->
SetText( pinMap );
1480 if( existing_deviceSubtype.StartsWith( wxS(
"RAND" ) ) )
1484 existing_deviceSubtype = existing_deviceSubtypeField->
GetText().Upper();
1486 if( existing_deviceSubtype.Replace( wxS(
"NORMAL" ), wxS(
"GAUSSIAN" ) ) )
1487 existing_deviceSubtypeField->
SetText( existing_deviceSubtype );
1489 if( existing_paramsField )
1491 wxString params = existing_paramsField->
GetText().Lower();
1498 count += params.Replace( wxS(
"min=0 " ), wxEmptyString );
1499 count += params.Replace( wxS(
"max=0 " ), wxEmptyString );
1502 count += params.Replace( wxS(
"dt=" ), wxS(
"ts=" ) );
1505 existing_paramsField->
SetText( params );
1511 if( existing_deviceSubtype == wxS(
"MUTUAL" ) )
1513 if( existing_deviceSubtypeField )
1514 aSymbol.RemoveField( existing_deviceSubtypeField );
1516 if( existing_deviceField )
1518 existing_deviceField->
SetText( wxS(
"K" ) );
1522 FIELD_INFO deviceFieldInfo;
1523 deviceFieldInfo.m_Text = wxS(
"K" );
1526 aSymbol.AddField( deviceField );
1537 return wxString( wxEmptyString );
1539 wxRegEx regex( wxT(
"([^a-z])(M)(e|E)(g|G)($|[^a-z])" ) );
1540 wxString value = aField->GetText();
1543 regex.ReplaceAll( &value, wxT(
"\\1\\2\\5" ) );
1548 auto generateDefaultPinMapFromSymbol =
1549 [](
const std::vector<SCH_PIN*>& sourcePins )
1556 for(
unsigned ii = 0; ii < sourcePins.size(); ++ii )
1559 pinMap.Append( wxS(
" " ) );
1561 pinMap.Append( wxString::Format( wxT(
"%s=%u" ),
1562 sourcePins[ii]->GetNumber(),
1569 wxString prefix = aSymbol.GetPrefix();
1570 SCH_FIELD* valueField = aSymbol.FindField( wxT(
"Value" ) );
1571 std::vector<SCH_PIN*> sourcePins = aSymbol.GetAllLibPins();
1572 bool sourcePinsSorted =
false;
1574 auto lazySortSourcePins =
1575 [&sourcePins, &sourcePinsSorted]()
1577 if( !sourcePinsSorted )
1579 std::sort( sourcePins.begin(), sourcePins.end(),
1582 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
1586 sourcePinsSorted =
true;
1589 FIELD_INFO deviceInfo;
1590 FIELD_INFO modelInfo;
1591 FIELD_INFO deviceSubtypeInfo;
1593 FIELD_INFO spiceParamsInfo;
1594 FIELD_INFO pinMapInfo;
1595 bool modelFromValueField =
false;
1605 deviceInfo = FIELD_INFO( primitiveField->GetText(), primitiveField );
1606 aSymbol.RemoveField( primitiveField );
1611 const wxString delimiters(
"{:,; }" );
1612 const wxString& nodeSequence = nodeSequenceField->GetText();
1615 if( nodeSequence !=
"" )
1617 wxStringTokenizer tkz( nodeSequence, delimiters );
1619 for(
long modelPinNumber = 1; tkz.HasMoreTokens(); ++modelPinNumber )
1621 long symbolPinNumber = 1;
1622 tkz.GetNextToken().ToLong( &symbolPinNumber );
1624 if( modelPinNumber != 1 )
1625 pinMap.Append(
" " );
1627 pinMap.Append( wxString::Format(
"%ld=%ld", symbolPinNumber, modelPinNumber ) );
1631 pinMapInfo = FIELD_INFO( pinMap, nodeSequenceField );
1632 aSymbol.RemoveField( nodeSequenceField );
1637 modelInfo = FIELD_INFO( getSIValue( modelField ), modelField );
1638 aSymbol.RemoveField( modelField );
1640 else if( valueField )
1642 modelInfo = FIELD_INFO( getSIValue( valueField ), valueField );
1643 modelFromValueField =
true;
1648 libInfo = FIELD_INFO( libFileField->GetText(), libFileField );
1649 aSymbol.RemoveField( libFileField );
1656 if(
SCH_FIELD* legacyType = aSymbol.FindField( wxT(
"Sim_Type" ) ) )
1661 if(
SCH_FIELD* legacyDevice = aSymbol.FindField( wxT(
"Sim_Device" ) ) )
1666 if(
SCH_FIELD* legacyPins = aSymbol.FindField( wxT(
"Sim_Pins" ) ) )
1668 bool isPassive = prefix.StartsWith( wxT(
"R" ) )
1669 || prefix.StartsWith( wxT(
"L" ) )
1670 || prefix.StartsWith( wxT(
"C" ) );
1674 wxArrayString pinIndexes;
1678 lazySortSourcePins();
1680 if( isPassive && pinIndexes.size() == 2 && sourcePins.size() == 2 )
1682 if( pinIndexes[0] == wxT(
"2" ) )
1684 pinMap.Printf( wxT(
"%s=- %s=+" ),
1685 sourcePins[0]->GetNumber(),
1686 sourcePins[1]->GetNumber() );
1690 pinMap.Printf( wxT(
"%s=+ %s=-" ),
1691 sourcePins[0]->GetNumber(),
1692 sourcePins[1]->GetNumber() );
1697 for(
unsigned ii = 0; ii < pinIndexes.size() && ii < sourcePins.size(); ++ii )
1700 pinMap.Append( wxS(
" " ) );
1702 pinMap.Append( wxString::Format( wxT(
"%s=%s" ),
1703 sourcePins[ii]->GetNumber(),
1704 pinIndexes[ ii ] ) );
1709 legacyPins->SetText( pinMap );
1712 if(
SCH_FIELD* legacyParams = aSymbol.FindField( wxT(
"Sim_Params" ) ) )
1720 wxString device = deviceInfo.m_Text.Trim(
true ).Trim(
false );
1721 wxString lib = libInfo.m_Text.Trim(
true ).Trim(
false );
1722 wxString model = modelInfo.m_Text.Trim(
true ).Trim(
false );
1723 wxString modelLineParams;
1725 bool libraryModel =
false;
1726 bool inferredModel =
false;
1727 bool internalModel =
false;
1729 if( !lib.IsEmpty() )
1733 std::vector<SCH_FIELD> emptyFields;
1736 model = model.BeforeFirst(
' ', &modelLineParams );
1737 modelInfo.m_Text = model;
1739 lazySortSourcePins();
1742 emptyFields, sourcePins, reporter );
1745 libraryModel =
false;
1747 libraryModel =
true;
1749 if( pinMapInfo.IsEmpty() )
1755 if( pinMapInfo.IsEmpty() )
1756 pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
1759 else if( ( device == wxS(
"R" )
1760 || device == wxS(
"L" )
1761 || device == wxS(
"C" )
1762 || device == wxS(
"V" )
1763 || device == wxS(
"I" ) )
1764 && prefix.StartsWith( device )
1765 && modelFromValueField )
1767 inferredModel =
true;
1769 else if( device == wxS(
"V" ) || device == wxS(
"I" ) )
1774 wxStringTokenizer tokenizer( model, wxT(
"() " ), wxTOKEN_STRTOK );
1776 if( tokenizer.HasMoreTokens() )
1778 deviceSubtypeInfo.m_Text = tokenizer.GetNextToken();
1779 deviceSubtypeInfo.m_Text.MakeUpper();
1781 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1790 if( deviceSubtypeInfo.m_Text == wxT(
"DC" ) && tokenizer.CountTokens() == 1 )
1792 wxCHECK( valueField, );
1793 valueField->
SetText( tokenizer.GetNextToken() );
1794 modelFromValueField =
false;
1798 for(
int ii = 0; tokenizer.HasMoreTokens(); ++ii )
1800 simModel->SetParamValue( ii, tokenizer.GetNextToken().ToStdString(),
1806 spiceParamsInfo = modelInfo;
1807 spiceParamsInfo.m_Text = wxString( simModel->Serializer().GenerateParams() );
1810 internalModel =
true;
1812 if( pinMapInfo.IsEmpty() )
1814 lazySortSourcePins();
1817 simModel->createPins( sourcePins );
1818 pinMapInfo.m_Text = wxString( simModel->Serializer().GeneratePins() );
1835 aSymbol.AddField( libField );
1838 aSymbol.AddField( nameField );
1840 if( !modelLineParams.IsEmpty() )
1842 spiceParamsInfo = modelInfo;
1844 spiceParamsInfo.m_Text = modelLineParams;
1847 int nameWidth = nameBBox.
GetWidth();
1853 spiceParamsInfo.m_Pos.x -= nameWidth;
1855 spiceParamsInfo.m_Pos.x += nameWidth;
1858 aSymbol.AddField( paramsField );
1861 if( modelFromValueField )
1862 valueField->
SetText( wxT(
"${SIM.NAME}" ) );
1864 else if( inferredModel )
1869 else if( internalModel )
1872 aSymbol.AddField( deviceField );
1874 if( !deviceSubtypeInfo.m_Text.IsEmpty() )
1877 aSymbol.AddField( subtypeField );
1880 if( !spiceParamsInfo.IsEmpty() )
1883 aSymbol.AddField( paramsField );
1886 if( modelFromValueField )
1887 valueField->
SetText( wxT(
"${SIM.PARAMS}" ) );
1891 if( device.IsEmpty() && lib.IsEmpty() )
1893 spiceParamsInfo = modelInfo;
1897 spiceParamsInfo.m_Text.Printf( wxT(
"type=\"%s\" model=\"%s\" lib=\"%s\"" ), device,
1904 aSymbol.AddField( deviceField );
1907 aSymbol.AddField( paramsField );
1909 if( modelFromValueField )
1912 valueField = aSymbol.FindField( wxT(
"Value" ) );
1915 valueField->
SetText( wxT(
"${SIM.PARAMS}" ) );
1921 if( pinMapInfo.IsEmpty() )
1923 lazySortSourcePins();
1924 pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
1928 if( !pinMapInfo.IsEmpty() )
1931 aSymbol.AddField( pinsField );
1936template void SIM_MODEL::MigrateSimModel<SCH_SYMBOL>(
SCH_SYMBOL& aSymbol,
1938template void SIM_MODEL::MigrateSimModel<LIB_SYMBOL>(
LIB_SYMBOL& aSymbol,
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
virtual const wxString & GetText() const
Return the string associated with the text object.
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
GR_TEXT_H_ALIGN_T GetHorizJustify() const
const TEXT_ATTRIBUTES & GetAttributes() const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const wxString Problem() const
what was the problem?
Define a library symbol object.
A singleton reporter that reports to nowhere.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
void SetPosition(const VECTOR2I &aPosition) override
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
static constexpr auto DIFF_FIELD
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
Serializes/deserializes a SIM_MODEL for storage in LIB_FIELDs/SCH_FIELDs.
std::string GeneratePins() const
int FindModelPinIndex(const std::string &aSymbolPinNumber)
static void MigrateSimModel(T &aSymbol, const PROJECT *aProject)
const PARAM & GetBaseParam(unsigned aParamIndex) const
void AddParam(const PARAM::INFO &aInfo)
bool IsStoredInValue() const
virtual std::vector< std::string > GetPinNames() const
virtual bool requiresSpiceModelLine(const SPICE_ITEM &aItem) const
static TYPE ReadTypeFromFields(const std::vector< SCH_FIELD > &aFields, REPORTER &aReporter)
std::vector< SIM_MODEL_PIN > m_modelPins
static INFO TypeInfo(TYPE aType)
static void SetFieldValue(std::vector< SCH_FIELD > &aFields, const wxString &aFieldName, const std::string &aValue)
void AddPin(const SIM_MODEL_PIN &aPin)
static SPICE_INFO SpiceInfo(TYPE aType)
const SIM_MODEL_SERIALIZER & Serializer() const
void ReadDataFields(const std::vector< SCH_FIELD > *aFields, const std::vector< SCH_PIN * > &aPins)
virtual const PARAM & GetParam(unsigned aParamIndex) const
static bool InferSimModel(T &aSymbol, std::vector< SCH_FIELD > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
void createPins(const std::vector< SCH_PIN * > &aSymbolPins)
void WriteFields(std::vector< SCH_FIELD > &aFields) const
virtual void SetBaseModel(const SIM_MODEL &aBaseModel)
static std::string GetFieldValue(const std::vector< SCH_FIELD > *aFields, const wxString &aFieldName, bool aResolve=true)
int GetParamCount() const
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
const PARAM * FindParam(const std::string &aParamName) const
virtual void doSetParamValue(int aParamIndex, const std::string &aValue)
std::vector< PARAM > m_params
const PARAM & GetParamOverride(unsigned aParamIndex) const
static std::unique_ptr< SIM_MODEL > Create(TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
virtual void SwitchSingleEndedDiff(bool aDiff)
const SIM_MODEL_PIN & GetPin(unsigned aIndex) const
std::unique_ptr< SIM_MODEL_SERIALIZER > m_serializer
virtual int doFindParam(const std::string &aParamName) const
std::vector< std::reference_wrapper< const SIM_MODEL_PIN > > GetPins() const
const SIM_MODEL * m_baseModel
static std::string Normalize(double aValue)
static std::string ConvertNotation(const std::string &aString, NOTATION aFromNotation, NOTATION aToNotation)
static double ToDouble(const std::string &aString, double aDefault=NAN)
A wrapper for reporting to a wxString object.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
#define THROW_IO_ERROR(msg)
#define SIM_LIBRARY_FIELD
#define SIM_LEGACY_ENABLE_FIELD
#define SIM_LEGACY_ENABLE_FIELD_V7
#define SIM_LEGACY_MODEL_FIELD
#define SIM_LEGACY_PINS_FIELD
#define SIM_LEGACY_LIBRARY_FIELD
#define SIM_LEGACY_PRIMITIVE_FIELD
#define SIM_DEVICE_SUBTYPE_FIELD
bool convertSeparators(wxString *value)
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
std::vector< std::string > enumValues
bool isSpiceInstanceParam
bool Matches(const std::string &aName) const
static constexpr auto NOT_CONNECTED
std::string baseModelName
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< int32_t > VECTOR2I