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 );
480 for(
auto& fld : aFields )
482 if( fld.GetId() >= lastFreeId )
483 lastFreeId = fld.GetId() + 1;
487 for(
auto& fld : aFields )
489 if( fld.GetId() < 0 )
490 fld.SetId( lastFreeId++ );
498 std::unique_ptr<SIM_MODEL> model =
Create( aType );
503 model->ReadDataFields(
static_cast<const std::vector<SCH_FIELD>*
>(
nullptr ), aPins );
507 wxFAIL_MSG(
"Shouldn't throw reading empty fields!" );
515 const std::vector<SCH_PIN*>& aPins,
518 std::unique_ptr<SIM_MODEL> model;
525 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
527 model = std::make_unique<SIM_MODEL_RAW_SPICE>();
531 model->SetBaseModel( *aBaseModel );
535 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( TYPE::NONE );
540 model->ReadDataFields(
static_cast<const std::vector<SCH_FIELD>*
>(
nullptr ), aPins );
544 wxFAIL_MSG(
"Shouldn't throw reading empty fields!" );
552 const std::vector<SCH_PIN*>& aPins,
553 const std::vector<SCH_FIELD>& aFields,
556 std::unique_ptr<SIM_MODEL> model;
567 type_override != TYPE::NONE )
569 type = type_override;
573 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
575 model = std::make_unique<SIM_MODEL_RAW_SPICE>();
579 model->SetBaseModel( *aBaseModel );
584 model = std::make_unique<SIM_MODEL_SPICE_FALLBACK>( type );
589 model->ReadDataFields( &aFields, aPins );
593 aReporter.
Report( wxString::Format(
_(
"Error reading simulation model from "
594 "symbol '%s':\n%s" ),
605 const std::vector<SCH_PIN*>& aPins,
606 bool aResolved,
REPORTER& aReporter )
613 model->ReadDataFields( &aFields, aPins );
628 if( modelData.empty() )
631 model = std::make_unique<SIM_MODEL_RAW_SPICE>( modelData );
635 model->createPins( aPins );
641 aReporter.
Report( wxString::Format(
_(
"Error reading simulation model from "
642 "symbol '%s':\n%s" ),
654 const wxString& aFieldName,
bool aResolve )
661 if( field.GetName() == aFieldName )
663 return aResolve ? field.GetShownText(
false ).ToStdString()
664 : field.GetText().ToStdString();
673 const std::string& aValue,
bool aIsVisible )
675 auto fieldIt = std::find_if( aFields.begin(), aFields.end(),
678 return f.GetName() == aFieldName;
681 if( fieldIt != aFields.end() )
685 aFields.erase( fieldIt );
689 fieldIt->SetText( aValue );
699 aFields.emplace_back(
VECTOR2I(), aFields.size(), parent, aFieldName );
701 aFields.back().SetText( aValue );
702 aFields.back().SetVisible( aIsVisible );
723 for(
int modelPinIndex = 0; modelPinIndex <
GetPinCount(); ++modelPinIndex )
726 return modelPinIndex;
746 wxS(
"Simulation model type must be the same as its base class!" ) );
754 std::vector<std::reference_wrapper<const SIM_MODEL_PIN>> pins;
756 for(
int modelPinIndex = 0; modelPinIndex <
GetPinCount(); ++modelPinIndex )
757 pins.emplace_back(
GetPin( modelPinIndex ) );
763 const wxString& aSymbolPinNumber )
765 if( aModelPinIndex >= 0 && aModelPinIndex < (
int)
m_modelPins.size() )
766 m_modelPins.at( aModelPinIndex ).symbolPinNumber = aSymbolPinNumber;
771 const wxString& aSymbolPinNumber )
775 if(
pin.modelPinName == aModelPinName )
777 pin.symbolPinNumber = aSymbolPinNumber;
784 int pinIndex = (int) strtol( aModelPinName.c_str(),
nullptr, 10 );
786 if( pinIndex < 1 || pinIndex > (
int)
m_modelPins.size() )
787 THROW_IO_ERROR( wxString::Format(
_(
"Unknown simulation model pin '%s'" ), aModelPinName ) );
789 m_modelPins[ --pinIndex ].symbolPinNumber = aSymbolPinNumber;
804 return boost::iequals(
name, aParamName );
824 return idx >= 0 ? &
GetParam( idx ) :
nullptr;
845 m_params.at( aParamIndex ).value = aValue;
855 [](
const std::string& aString )
857 for(
char c : aString )
859 if( c !=
'.' && ( c <
'0' || c >
'9' ) )
867 if( aValue.find(
',' ) != std::string::npos )
870 SIM_VALUE::NOTATION::SI ) );
872 else if( aNotation != SIM_VALUE::NOTATION::SI && !plainNumber( aValue ) )
875 SIM_VALUE::NOTATION::SI ) );
890 THROW_IO_ERROR( wxString::Format(
"Unknown simulation model parameter '%s'", aParamName ) );
903 return std::make_unique<SIM_MODEL_IDEAL>( aType );
906 return std::make_unique<SIM_MODEL_R_POT>();
909 return std::make_unique<SIM_MODEL_L_MUTUAL>();
911 case TYPE::R_BEHAVIORAL:
912 case TYPE::C_BEHAVIORAL:
913 case TYPE::L_BEHAVIORAL:
914 case TYPE::V_BEHAVIORAL:
915 case TYPE::I_BEHAVIORAL:
916 return std::make_unique<SIM_MODEL_BEHAVIORAL>( aType );
919 case TYPE::TLINE_RLGC:
920 return std::make_unique<SIM_MODEL_TLINE>( aType );
924 return std::make_unique<SIM_MODEL_SWITCH>( aType );
944 case TYPE::V_WHITENOISE:
945 case TYPE::I_WHITENOISE:
946 case TYPE::V_PINKNOISE:
947 case TYPE::I_PINKNOISE:
948 case TYPE::V_BURSTNOISE:
949 case TYPE::I_BURSTNOISE:
950 case TYPE::V_RANDUNIFORM:
951 case TYPE::I_RANDUNIFORM:
952 case TYPE::V_RANDGAUSSIAN:
953 case TYPE::I_RANDGAUSSIAN:
954 case TYPE::V_RANDEXP:
955 case TYPE::I_RANDEXP:
956 case TYPE::V_RANDPOISSON:
957 case TYPE::I_RANDPOISSON:
958 return std::make_unique<SIM_MODEL_SOURCE>( aType );
961 return std::make_unique<SIM_MODEL_SUBCKT>();
964 return std::make_unique<SIM_MODEL_XSPICE>( aType );
966 case TYPE::KIBIS_DEVICE:
967 case TYPE::KIBIS_DRIVER_DC:
968 case TYPE::KIBIS_DRIVER_RECT:
969 case TYPE::KIBIS_DRIVER_PRBS:
970 return std::make_unique<SIM_MODEL_IBIS>( aType );
973 return std::make_unique<SIM_MODEL_RAW_SPICE>();
976 return std::make_unique<SIM_MODEL_NGSPICE>( aType );
996 std::unique_ptr<SIM_MODEL_SERIALIZER> aSerializer ) :
997 m_baseModel( nullptr ),
998 m_serializer(
std::
move( aSerializer ) ),
999 m_spiceGenerator(
std::
move( aSpiceGenerator ) ),
1001 m_isEnabled( true ),
1002 m_isStoredInValue( false )
1016 std::vector<std::string> pinNames =
GetPinNames();
1018 for(
unsigned modelPinIndex = 0; modelPinIndex < pinNames.size(); ++modelPinIndex )
1020 wxString pinName = pinNames[ modelPinIndex ];
1021 bool optional =
false;
1023 if( pinName.StartsWith(
'<' ) && pinName.EndsWith(
'>' ) )
1025 pinName = pinName.Mid( 1, pinName.Length() - 2 );
1029 if( modelPinIndex < aSymbolPins.size() )
1031 AddPin( { pinNames.at( modelPinIndex ),
1032 aSymbolPins[ modelPinIndex ]->GetNumber().ToStdString() } );
1034 else if( !optional )
1036 AddPin( { pinNames.at( modelPinIndex ),
"" } );
1045 if(
m_type == TYPE::SUBCKT )
1061 if ( param.
value ==
"" )
1066 const std::string& baseValue = baseModel->m_params[ii].value;
1068 if( param.
value == baseValue )
1088 wxString* aModelType, wxString* aModelParams, wxString* aPinMap )
1117 auto convertNotation =
1118 [&](
const wxString& units ) -> wxString
1122 if( units == wxS(
"µ" ) || units == wxS(
"μ" ) )
1127 if( units == wxT(
"M" ) )
1128 return wxT(
"Meg" );
1132 if( units.Capitalize() == wxT(
"Meg" ) )
1140 []( wxString* mantissa )
1142 mantissa->Replace( wxS(
" " ), wxEmptyString );
1144 wxChar ambiguousSeparator =
'?';
1145 wxChar thousandsSeparator =
'?';
1146 bool thousandsSeparatorFound =
false;
1147 wxChar decimalSeparator =
'?';
1148 bool decimalSeparatorFound =
false;
1151 for(
int ii = (
int) mantissa->length() - 1; ii >= 0; --ii )
1153 wxChar c = mantissa->GetChar( ii );
1155 if( c >=
'0' && c <=
'9' )
1159 else if( c ==
'.' || c ==
',' )
1161 if( decimalSeparator !=
'?' || thousandsSeparator !=
'?' )
1165 if( c == decimalSeparator )
1167 if( thousandsSeparatorFound )
1169 else if( decimalSeparatorFound )
1172 decimalSeparatorFound =
true;
1174 else if( c == thousandsSeparator )
1179 thousandsSeparatorFound =
true;
1182 else if( ambiguousSeparator !=
'?' )
1187 if( c == ambiguousSeparator )
1190 thousandsSeparator = ambiguousSeparator;
1191 thousandsSeparatorFound =
true;
1192 decimalSeparator = c ==
'.' ?
',' :
'.';
1198 decimalSeparator = ambiguousSeparator;
1199 decimalSeparatorFound =
true;
1200 thousandsSeparator = c;
1201 thousandsSeparatorFound =
true;
1214 if( ( ii == 1 && mantissa->GetChar( 0 ) ==
'0' ) || digits != 3 )
1216 decimalSeparator = c;
1217 decimalSeparatorFound =
true;
1218 thousandsSeparator = c ==
'.' ?
',' :
'.';
1222 ambiguousSeparator = c;
1235 if( decimalSeparator ==
'?' && thousandsSeparator ==
'?' )
1237 decimalSeparator =
'.';
1238 thousandsSeparator =
',';
1241 mantissa->Replace( thousandsSeparator, wxEmptyString );
1242 mantissa->Replace( decimalSeparator,
'.' );
1247 wxString prefix = aSymbol.GetPrefix();
1251 std::vector<SCH_PIN*> pins = aSymbol.GetPins();
1258 if( pins.size() != 2 )
1261 if( ( ( *aDeviceType ==
"R" || *aDeviceType ==
"L" || *aDeviceType ==
"C" )
1262 && aModelType->IsEmpty() )
1264 (
library.IsEmpty() && modelName.IsEmpty()
1265 && aDeviceType->IsEmpty()
1266 && aModelType->IsEmpty()
1268 && ( prefix.StartsWith(
"R" ) || prefix.StartsWith(
"L" ) || prefix.StartsWith(
"C" ) ) ) )
1270 if( aModelParams->IsEmpty() )
1272 wxRegEx idealVal( wxT(
"^"
1274 "([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
1275 "([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
1277 "([fFhHΩΩ𝛀𝛺𝝮rR]|ohm)?"
1280 if( idealVal.Matches( value ) )
1282 wxString valueMantissa( idealVal.GetMatch( value, 1 ) );
1283 wxString valueExponent( idealVal.GetMatch( value, 2 ) );
1284 wxString valueFraction( idealVal.GetMatch( value, 6 ) );
1289 if( valueMantissa.Contains( wxT(
"." ) ) || valueFraction.IsEmpty() )
1291 aModelParams->Printf( wxT(
"%s=\"%s%s\"" ),
1292 prefix.Left(1).Lower(),
1294 convertNotation( valueExponent ) );
1298 aModelParams->Printf( wxT(
"%s=\"%s.%s%s\"" ),
1299 prefix.Left(1).Lower(),
1302 convertNotation( valueExponent ) );
1307 *aModelType = wxT(
"=" );
1308 aModelParams->Printf( wxT(
"%s=\"%s\"" ), prefix.Left(1).Lower(), value );
1312 if( aDeviceType->IsEmpty() )
1313 *aDeviceType = prefix.Left( 1 );
1315 if( aPinMap->IsEmpty() )
1316 aPinMap->Printf( wxT(
"%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
1321 if( ( ( *aDeviceType == wxT(
"V" ) || *aDeviceType == wxT(
"I" ) )
1322 && ( aModelType->IsEmpty() || *aModelType == wxT(
"DC" ) ) )
1324 ( aDeviceType->IsEmpty()
1325 && aModelType->IsEmpty()
1327 && ( prefix.StartsWith(
"V" ) || prefix.StartsWith(
"I" ) ) ) )
1329 if( !value.IsEmpty() )
1331 wxString param =
"dc";
1333 if( value.StartsWith( wxT(
"DC " ) ) )
1335 value = value.Right( value.Length() - 3 );
1337 else if( value.StartsWith( wxT(
"AC " ) ) )
1339 value = value.Right( value.Length() - 3 );
1343 wxRegEx sourceVal( wxT(
"^"
1345 "([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
1351 if( sourceVal.Matches( value ) )
1353 wxString valueMantissa( sourceVal.GetMatch( value, 1 ) );
1354 wxString valueExponent( sourceVal.GetMatch( value, 2 ) );
1355 wxString valueFraction( sourceVal.GetMatch( value, 6 ) );
1360 if( valueMantissa.Contains( wxT(
"." ) ) || valueFraction.IsEmpty() )
1362 aModelParams->Printf( wxT(
"%s=\"%s%s\" %s" ),
1365 convertNotation( valueExponent ),
1370 aModelParams->Printf( wxT(
"%s=\"%s.%s%s\" %s" ),
1374 convertNotation( valueExponent ),
1380 aModelParams->Printf( wxT(
"%s=\"%s\" %s" ),
1387 if( aDeviceType->IsEmpty() )
1388 *aDeviceType = prefix.Left( 1 );
1390 if( aModelType->IsEmpty() )
1391 *aModelType = wxT(
"DC" );
1393 if( aPinMap->IsEmpty() )
1394 aPinMap->Printf( wxT(
"%s=+ %s=-" ), pins[0]->GetNumber(), pins[1]->GetNumber() );
1403template bool SIM_MODEL::InferSimModel<SCH_SYMBOL>(
SCH_SYMBOL& aSymbol,
1404 std::vector<SCH_FIELD>* aFields,
bool aResolve,
1406 wxString* aDeviceType, wxString* aModelType,
1407 wxString* aModelParams, wxString* aPinMap );
1408template bool SIM_MODEL::InferSimModel<LIB_SYMBOL>(
LIB_SYMBOL& aSymbol,
1409 std::vector<SCH_FIELD>* aFields,
bool aResolve,
1411 wxString* aDeviceType, wxString* aModelType,
1412 wxString* aModelParams, wxString* aPinMap );
1415template <
typename T>
1423 m_Attributes.m_Visible =
false;
1428 FIELD_INFO(
const wxString& aText,
SCH_FIELD* aField ) :
1434 bool IsEmpty()
const {
return m_Text.IsEmpty(); }
1436 SCH_FIELD CreateField( T* aSymbol,
const wxString& aFieldName )
1438 SCH_FIELD field( aSymbol, -1, aFieldName );
1458 wxString existing_deviceSubtype;
1460 if( existing_deviceSubtypeField )
1461 existing_deviceSubtype = existing_deviceSubtypeField->
GetShownText(
false ).Upper();
1463 if( existing_deviceField
1464 || existing_deviceSubtypeField
1465 || existing_pinsField
1466 || existing_paramsField )
1472 if( existing_deviceSubtype == wxS(
"POT" ) )
1474 if( existing_pinsField )
1476 wxString pinMap = existing_pinsField->
GetText();
1477 pinMap.Replace( wxS(
"=+" ), wxS(
"=r1" ) );
1478 pinMap.Replace( wxS(
"=-" ), wxS(
"=r0" ) );
1479 existing_pinsField->
SetText( pinMap );
1484 if( existing_deviceSubtype.StartsWith( wxS(
"RAND" ) ) )
1488 existing_deviceSubtype = existing_deviceSubtypeField->
GetText().Upper();
1490 if( existing_deviceSubtype.Replace( wxS(
"NORMAL" ), wxS(
"GAUSSIAN" ) ) )
1491 existing_deviceSubtypeField->
SetText( existing_deviceSubtype );
1493 if( existing_paramsField )
1495 wxString params = existing_paramsField->
GetText().Lower();
1502 count += params.Replace( wxS(
"min=0 " ), wxEmptyString );
1503 count += params.Replace( wxS(
"max=0 " ), wxEmptyString );
1506 count += params.Replace( wxS(
"dt=" ), wxS(
"ts=" ) );
1509 existing_paramsField->
SetText( params );
1515 if( existing_deviceSubtype == wxS(
"MUTUAL" ) )
1517 if( existing_deviceSubtypeField )
1518 aSymbol.RemoveField( existing_deviceSubtypeField );
1520 if( existing_deviceField )
1522 existing_deviceField->
SetText( wxS(
"K" ) );
1526 FIELD_INFO deviceFieldInfo;
1527 deviceFieldInfo.m_Text = wxS(
"K" );
1530 aSymbol.AddField( deviceField );
1541 return wxString( wxEmptyString );
1543 wxRegEx regex( wxT(
"([^a-z])(M)(e|E)(g|G)($|[^a-z])" ) );
1544 wxString value = aField->GetText();
1547 regex.ReplaceAll( &value, wxT(
"\\1\\2\\5" ) );
1552 auto generateDefaultPinMapFromSymbol =
1553 [](
const std::vector<SCH_PIN*>& sourcePins )
1560 for(
unsigned ii = 0; ii < sourcePins.size(); ++ii )
1563 pinMap.Append( wxS(
" " ) );
1565 pinMap.Append( wxString::Format( wxT(
"%s=%u" ),
1566 sourcePins[ii]->GetNumber(),
1573 wxString prefix = aSymbol.GetPrefix();
1574 SCH_FIELD* valueField = aSymbol.FindField( wxT(
"Value" ) );
1575 std::vector<SCH_PIN*> sourcePins = aSymbol.GetPins();
1576 bool sourcePinsSorted =
false;
1578 auto lazySortSourcePins =
1579 [&sourcePins, &sourcePinsSorted]()
1581 if( !sourcePinsSorted )
1583 std::sort( sourcePins.begin(), sourcePins.end(),
1586 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
1590 sourcePinsSorted =
true;
1593 FIELD_INFO deviceInfo;
1594 FIELD_INFO modelInfo;
1595 FIELD_INFO deviceSubtypeInfo;
1597 FIELD_INFO spiceParamsInfo;
1598 FIELD_INFO pinMapInfo;
1599 bool modelFromValueField =
false;
1609 deviceInfo = FIELD_INFO( primitiveField->GetText(), primitiveField );
1610 aSymbol.RemoveField( primitiveField );
1615 const wxString delimiters(
"{:,; }" );
1616 const wxString& nodeSequence = nodeSequenceField->GetText();
1619 if( nodeSequence !=
"" )
1621 wxStringTokenizer tkz( nodeSequence, delimiters );
1623 for(
long modelPinNumber = 1; tkz.HasMoreTokens(); ++modelPinNumber )
1625 long symbolPinNumber = 1;
1626 tkz.GetNextToken().ToLong( &symbolPinNumber );
1628 if( modelPinNumber != 1 )
1629 pinMap.Append(
" " );
1631 pinMap.Append( wxString::Format(
"%ld=%ld", symbolPinNumber, modelPinNumber ) );
1635 pinMapInfo = FIELD_INFO( pinMap, nodeSequenceField );
1636 aSymbol.RemoveField( nodeSequenceField );
1641 modelInfo = FIELD_INFO( getSIValue( modelField ), modelField );
1642 aSymbol.RemoveField( modelField );
1644 else if( valueField )
1646 modelInfo = FIELD_INFO( getSIValue( valueField ), valueField );
1647 modelFromValueField =
true;
1652 libInfo = FIELD_INFO( libFileField->GetText(), libFileField );
1653 aSymbol.RemoveField( libFileField );
1660 if(
SCH_FIELD* legacyType = aSymbol.FindField( wxT(
"Sim_Type" ) ) )
1665 if(
SCH_FIELD* legacyDevice = aSymbol.FindField( wxT(
"Sim_Device" ) ) )
1670 if(
SCH_FIELD* legacyPins = aSymbol.FindField( wxT(
"Sim_Pins" ) ) )
1672 bool isPassive = prefix.StartsWith( wxT(
"R" ) )
1673 || prefix.StartsWith( wxT(
"L" ) )
1674 || prefix.StartsWith( wxT(
"C" ) );
1678 wxArrayString pinIndexes;
1682 lazySortSourcePins();
1684 if( isPassive && pinIndexes.size() == 2 && sourcePins.size() == 2 )
1686 if( pinIndexes[0] == wxT(
"2" ) )
1688 pinMap.Printf( wxT(
"%s=- %s=+" ),
1689 sourcePins[0]->GetNumber(),
1690 sourcePins[1]->GetNumber() );
1694 pinMap.Printf( wxT(
"%s=+ %s=-" ),
1695 sourcePins[0]->GetNumber(),
1696 sourcePins[1]->GetNumber() );
1701 for(
unsigned ii = 0; ii < pinIndexes.size() && ii < sourcePins.size(); ++ii )
1704 pinMap.Append( wxS(
" " ) );
1706 pinMap.Append( wxString::Format( wxT(
"%s=%s" ),
1707 sourcePins[ii]->GetNumber(),
1708 pinIndexes[ ii ] ) );
1713 legacyPins->SetText( pinMap );
1716 if(
SCH_FIELD* legacyParams = aSymbol.FindField( wxT(
"Sim_Params" ) ) )
1724 wxString device = deviceInfo.m_Text.Trim(
true ).Trim(
false );
1725 wxString lib = libInfo.m_Text.Trim(
true ).Trim(
false );
1726 wxString model = modelInfo.m_Text.Trim(
true ).Trim(
false );
1727 wxString modelLineParams;
1729 bool libraryModel =
false;
1730 bool inferredModel =
false;
1731 bool internalModel =
false;
1733 if( !lib.IsEmpty() )
1737 std::vector<SCH_FIELD> emptyFields;
1740 model = model.BeforeFirst(
' ', &modelLineParams );
1741 modelInfo.m_Text = model;
1743 lazySortSourcePins();
1746 emptyFields, sourcePins, reporter );
1749 libraryModel =
false;
1751 libraryModel =
true;
1753 if( pinMapInfo.IsEmpty() )
1759 if( pinMapInfo.IsEmpty() )
1760 pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
1763 else if( ( device == wxS(
"R" )
1764 || device == wxS(
"L" )
1765 || device == wxS(
"C" )
1766 || device == wxS(
"V" )
1767 || device == wxS(
"I" ) )
1768 && prefix.StartsWith( device )
1769 && modelFromValueField )
1771 inferredModel =
true;
1773 else if( device == wxS(
"V" ) || device == wxS(
"I" ) )
1778 wxStringTokenizer tokenizer( model, wxT(
"() " ), wxTOKEN_STRTOK );
1780 if( tokenizer.HasMoreTokens() )
1782 deviceSubtypeInfo.m_Text = tokenizer.GetNextToken();
1783 deviceSubtypeInfo.m_Text.MakeUpper();
1785 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1794 if( deviceSubtypeInfo.m_Text == wxT(
"DC" ) && tokenizer.CountTokens() == 1 )
1796 wxCHECK( valueField, );
1797 valueField->
SetText( tokenizer.GetNextToken() );
1798 modelFromValueField =
false;
1802 for(
int ii = 0; tokenizer.HasMoreTokens(); ++ii )
1804 simModel->SetParamValue( ii, tokenizer.GetNextToken().ToStdString(),
1810 spiceParamsInfo = modelInfo;
1811 spiceParamsInfo.m_Text = wxString( simModel->Serializer().GenerateParams() );
1814 internalModel =
true;
1816 if( pinMapInfo.IsEmpty() )
1818 lazySortSourcePins();
1821 simModel->createPins( sourcePins );
1822 pinMapInfo.m_Text = wxString( simModel->Serializer().GeneratePins() );
1839 aSymbol.AddField( libField );
1842 aSymbol.AddField( nameField );
1844 if( !modelLineParams.IsEmpty() )
1846 spiceParamsInfo = modelInfo;
1848 spiceParamsInfo.m_Text = modelLineParams;
1851 int nameWidth = nameBBox.
GetWidth();
1857 spiceParamsInfo.m_Pos.x -= nameWidth;
1859 spiceParamsInfo.m_Pos.x += nameWidth;
1862 aSymbol.AddField( paramsField );
1865 if( modelFromValueField )
1866 valueField->
SetText( wxT(
"${SIM.NAME}" ) );
1868 else if( inferredModel )
1873 else if( internalModel )
1876 aSymbol.AddField( deviceField );
1878 if( !deviceSubtypeInfo.m_Text.IsEmpty() )
1881 aSymbol.AddField( subtypeField );
1884 if( !spiceParamsInfo.IsEmpty() )
1887 aSymbol.AddField( paramsField );
1890 if( modelFromValueField )
1891 valueField->
SetText( wxT(
"${SIM.PARAMS}" ) );
1895 if( device.IsEmpty() && lib.IsEmpty() )
1897 spiceParamsInfo = modelInfo;
1901 spiceParamsInfo.m_Text.Printf( wxT(
"type=\"%s\" model=\"%s\" lib=\"%s\"" ), device,
1908 aSymbol.AddField( deviceField );
1911 aSymbol.AddField( paramsField );
1913 if( modelFromValueField )
1916 valueField = aSymbol.FindField( wxT(
"Value" ) );
1919 valueField->
SetText( wxT(
"${SIM.PARAMS}" ) );
1925 if( pinMapInfo.IsEmpty() )
1927 lazySortSourcePins();
1928 pinMapInfo.m_Text = generateDefaultPinMapFromSymbol( sourcePins );
1932 if( !pinMapInfo.IsEmpty() )
1935 aSymbol.AddField( pinsField );
1940template void SIM_MODEL::MigrateSimModel<SCH_SYMBOL>(
SCH_SYMBOL& aSymbol,
1942template 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)
void AddPin(const SIM_MODEL_PIN &aPin)
static SPICE_INFO SpiceInfo(TYPE aType)
static void SetFieldValue(std::vector< SCH_FIELD > &aFields, const wxString &aFieldName, const std::string &aValue, bool aIsVisible=true)
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, LIB_PART, and FOOTPRINT constru...
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< int32_t > VECTOR2I