-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponents.mjs
289 lines (240 loc) · 12.8 KB
/
components.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import { Component } from "./component.mjs";
import { PathComponent } from "./pathComponent.mjs";
import { PotentialComponent } from "./potentialComponent.mjs";
import { Coordinate } from "./coordinate.mjs";
import { Pin } from "./pin.mjs";
import { Transistor } from "./transistor.mjs";
import { ABLTransistorMapper } from "./ablTransistorMapper.mjs";
const TWO_POLE_COMPONENT_LENGTH = 1;
const ZERO_COORD = new Coordinate(0, 0);
const ZERO_PIN = new Pin(ZERO_COORD, null, 1, null);
const TRANSISTOR_TOP_PIN = new Pin(new Coordinate(.5, .5), null, 1, null);
const TRANSISTOR_TAP_PIN = new Pin(ZERO_COORD, null, 2, null);
const TRANSISTOR_BOTTOM_PIN = new Pin(new Coordinate(.5, -.5), null, 3, null);
const TWO_POLE_SECOND_PIN = new Pin(new Coordinate(TWO_POLE_COMPONENT_LENGTH, 0), null, 2, null);
const TWO_POLE_COMPONENT_PINS = [ZERO_PIN, TWO_POLE_SECOND_PIN];
const TWO_POLE_COMPONENT_PINS_MIRRORED = [TWO_POLE_SECOND_PIN, ZERO_PIN];
// prettier-ignore
/**
* Enum/map-alike of all (supported) TikZ components.
*
* @readonly
* @enum {Component}
*/
const TIKZ_COMPONENTS = {
// # one poles
// ## grounds:
ground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.GROUND, ZERO_COORD), // generic ground
tlground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.TLGROUND, ZERO_COORD), // tailless ground
rground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.RGROUND, ZERO_COORD), // reference ground
sground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.SGROUND, ZERO_COORD), // signal ground
tground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.TGROUND, ZERO_COORD), // thick tailless reference ground
nground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.NGROUND, ZERO_COORD), // noiseless ground
pground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.PGROUND, ZERO_COORD), // protective ground
cground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.CGROUND, ZERO_COORD), // chassis ground
eground: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.EGROUND, ZERO_COORD), // european ground
eground2: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.EGROUND2, ZERO_COORD), // european ground v2
// # two poles
// ## power supplies
vcc: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.VCC, ZERO_COORD), // arrow up
vee: new PotentialComponent(PotentialComponent.POTENTIAL_TYPE.VEE, ZERO_COORD), // arrow down
// ## generics --> skip
// ## resistors
R: new PathComponent("R", null, TWO_POLE_COMPONENT_PINS), // resistor
vR: new PathComponent("vR", null, TWO_POLE_COMPONENT_PINS), // variable resistor
// TODO change poti to 3 term type
pR: new PathComponent("pR", null, TWO_POLE_COMPONENT_PINS), // potentiometer
sR: new PathComponent("sR", null, TWO_POLE_COMPONENT_PINS), // resistive sensor
ldR: new PathComponent("ldR", null, TWO_POLE_COMPONENT_PINS), // light dependant resistor
varistor: new PathComponent("varistor", null, TWO_POLE_COMPONENT_PINS), // varistor
phR: new PathComponent("phR", null, TWO_POLE_COMPONENT_PINS), // photoresistor
thR: new PathComponent("thR", null, TWO_POLE_COMPONENT_PINS), // thermistor
thRp: new PathComponent("thRp", null, TWO_POLE_COMPONENT_PINS), // thermistor (PTC)
thRn: new PathComponent("thRn", null, TWO_POLE_COMPONENT_PINS), // thermistor (NTC)
// ## capacitors and similar components
C: new PathComponent("C", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -| |- capacitor
cC: new PathComponent("cC", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -| (- curved/polarized capacitor
eC: new PathComponent("eC", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -+[]- electrolyte capacitor
vC: new PathComponent("vC", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -|/^|- variable capacitor
sC: new PathComponent("sC", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -|/|- capacitive sensor
PZ: new PathComponent("PZ", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -|[]|- piezoelectric element
cpe: new PathComponent("cpe", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -> >- constant phase element
feC: new PathComponent("feC", null, TWO_POLE_COMPONENT_PINS_MIRRORED), // -||\||- ferroelectric capacitor
// ## inductors
L: new PathComponent("L", null, TWO_POLE_COMPONENT_PINS), // inductor
vL: new PathComponent("vL", null, TWO_POLE_COMPONENT_PINS), // variable inductor
sL: new PathComponent("sL", null, TWO_POLE_COMPONENT_PINS), // inductive sensor
sR: new PathComponent("sR", null, TWO_POLE_COMPONENT_PINS), // resistive sensor
cuteChoke: new PathComponent("cute choke", null, TWO_POLE_COMPONENT_PINS), // (cute) choke
cuteChokeTwoLine: new PathComponent("cute choke, twolineschoke", null, TWO_POLE_COMPONENT_PINS), // (cute) choke
// ## diodes etc
Do: new PathComponent("Do", null, TWO_POLE_COMPONENT_PINS), // empty diode
// TODO
// ## sources
battery: new PathComponent("battery", null, TWO_POLE_COMPONENT_PINS), // battery (symbol: 2 cells)
batteryCell1: new PathComponent("battery1", null, TWO_POLE_COMPONENT_PINS), // single battery cell
batteryCell2: new PathComponent("battery2", null, TWO_POLE_COMPONENT_PINS), // single battery cell with fat negative pole
vsource: new PathComponent("vsource", null, TWO_POLE_COMPONENT_PINS), // generic voltage source (european)
vsourceAM: new PathComponent("vsourceAM", null, TWO_POLE_COMPONENT_PINS), // generic voltage source (american)
vsourceC: new PathComponent("vsourceC", null, TWO_POLE_COMPONENT_PINS), // generic voltage source (european, cute)
isource: new PathComponent("isource", null, TWO_POLE_COMPONENT_PINS), // generic current source (european)
isourceAM: new PathComponent("isourceAM", null, TWO_POLE_COMPONENT_PINS), // generic current source (american)
isourceC: new PathComponent("isourceC", null, TWO_POLE_COMPONENT_PINS), // generic current source (european, cute)
sV: new PathComponent("sV", null, TWO_POLE_COMPONENT_PINS), // sinusoidal voltage source
sI: new PathComponent("sI", null, TWO_POLE_COMPONENT_PINS), // sinusoidal current source
dcvsource: new PathComponent("dcvsource", null, TWO_POLE_COMPONENT_PINS), // dc voltage source
dcisource: new PathComponent("dcisource", null, TWO_POLE_COMPONENT_PINS), // dc current source
// ## controlled sources
// TODO
// ## noise sources
// TODO
// ## special sources
sqV: new PathComponent("sqV", null, TWO_POLE_COMPONENT_PINS), // Square voltage source
// TODO
// ## Nullator and norator
// TODO
// ## instruments
// TODO
// ## mechanical analogy
// --> ignore
// ## misc bipoles
// TODO
// ## multiple wires / busses
// TODO
// ## crossings
// TODO
// ## currentarrow
// --> ignore
// ## poles
// --> maybe
// ## connectors
// --> maybe more
iecConnector: new Component("iec connector", null, TWO_POLE_COMPONENT_PINS),
// ## block diagram components
amp: new PathComponent("amp", null, TWO_POLE_COMPONENT_PINS),
// ## Transistors
// ### BJTs
npn: Transistor.fromStruct("npn", ["C", "E", "B"], {width: .6, connHeight: 0, height: 1.1}),
pnp: Transistor.fromStruct("pnp", ["E", "C", "B"], {width: .6, connHeight: 0, height: 1.1}),
// ### FETs
nmos: Transistor.fromStruct("nmos", ["D", "S", "G"], {width: .7, connHeight: 0, height: 1.1}),
pmos: Transistor.fromStruct("pmos", ["S", "D", "G"], {width: .7, connHeight: 0, height: 1.1}),
nigfete: Transistor.fromStruct("nigfete", ["D", "S", "G"], {width: .7, connHeight: -.35, height: 1.1}),
pigfete: Transistor.fromStruct("pigfete", ["S", "D", "G"], {width: .7, connHeight: .35, height: 1.1}),
// ## Tubees
// ## RF Components
// ## Electro-Mechanical Devices
// ## Double bipoles (transformers)
// ## Amplifiers
"op amp": new Transistor("op amp", null, [
// x: pgfCircRlen * tripoles/op amp/width * .5
// y: pgfCircRlen * tripoles/op amp/height * tripoles/op amp/input height * .5
new Pin(new Coordinate(-1.4*1.7*.5, +1.4*1.4*.5*.5), "-"),
new Pin(new Coordinate(-1.4*1.7*.5, -1.4*1.4*.5*.5), "+"),
new Pin(new Coordinate(+1.4*1.7*.5, 0), "out")
], ["-", "+", "out"], null, ZERO_COORD),
// ## Switches, buttons and jumpers
// ## Logic gates
// ## Flip-flops
// ## Multiplexer and de-multiplexer
// ## Chips (integrated circuits)
// ## Seven segment displays
};
// prettier-ignore
/**
* Enum/map-alike of mapper objects. These contain both an TikZ and an ADS component and are used for more complex
* transformations.
*
* @readonly
* @enum {Component}
*/
const ADS_TIKZ_MAPPERS = {
BJT: new ABLTransistorMapper(TIKZ_COMPONENTS.npn, [TRANSISTOR_TOP_PIN, TRANSISTOR_BOTTOM_PIN, TRANSISTOR_TAP_PIN], 2),
SIMPLE_FETN: new ABLTransistorMapper(TIKZ_COMPONENTS.nmos, [TRANSISTOR_TOP_PIN, TRANSISTOR_BOTTOM_PIN, TRANSISTOR_TAP_PIN], 2),
};
/**
* Maps an ABL component to a TikZ component stencil. The key is either just the cellName (e.g. "R"), or
* libraryName:cellName for specific components.
*
* @type {Map<string, Component>}
*/
const ADS_COMPONENTS_MAP = new Map([
// Potentials
["GROUND", TIKZ_COMPONENTS.ground], // ads_rflib
// Voltage sources
["V_AC", TIKZ_COMPONENTS.sV], // ads_simulation
["V_DC", TIKZ_COMPONENTS.battery], // ads_simulation
["VtPulse", TIKZ_COMPONENTS.sqV], // ads_simulation
// #passive components
// ##Capacitors
["C", TIKZ_COMPONENTS.cC], // ads_rflib,
["ads_rflib:CAPQ", TIKZ_COMPONENTS.cC], // capacitor + quality factor
["ads_rflib:C_Pad1", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:C_Space", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:C_Conn", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:C_dxdy", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CAPP2", TIKZ_COMPONENTS.cC], // ads_rflib, chip capacitor
["ads_rflib:CAPP2_Pad1", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CAPP2_Space", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CAPP2_Conn", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CQ_Pad1", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CQ_Space", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:CQ_Conn", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:DICAP", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
["ads_rflib:DILABMLC", TIKZ_COMPONENTS.cC], // ads_rflib, FET modelling
// ##Inductors
["L", TIKZ_COMPONENTS.L], // ads_rflib
["ads_rflib:CIND", TIKZ_COMPONENTS.cuteChokeTwoLine], // toroidal inductor --> choke
["ads_rflib:RIND", TIKZ_COMPONENTS.L], // chip inductor
["ads_rflib:INDQ", TIKZ_COMPONENTS.L], // inductor + quality factor
["ads_rflib:INDQ2", TIKZ_COMPONENTS.L], // inductor + quality factor
["ads_rflib:L_Pad1", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
["ads_rflib:L_Space", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
["ads_rflib:L_Conn", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
["ads_rflib:LQ_Pad1", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
["ads_rflib:LQ_Space", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
["ads_rflib:LQ_Conn", TIKZ_COMPONENTS.L], // ads_rflib, FET modelling
// ##Resistors
["R", TIKZ_COMPONENTS.R], // ads_rflib
["ads_rflib:R_Pad1", TIKZ_COMPONENTS.R], // ads_rflib, FET modelling
["ads_rflib:R_Space", TIKZ_COMPONENTS.R], // ads_rflib, FET modelling
["ads_rflib:R_Conn", TIKZ_COMPONENTS.R], // ads_rflib, FET modelling
["ads_rflib:R_dxdy", TIKZ_COMPONENTS.R], // ads_rflib, FET modelling
// #active components
// ##Diodes
["Diode", TIKZ_COMPONENTS.Do], // ads_rflib,
["PIN", TIKZ_COMPONENTS.Do], // ads_rflib, PIN diode
["PIN2", TIKZ_COMPONENTS.Do], // ads_rflib, PIN diode
// ##Transistors
// ###FETs
["EE_MOS1", new ABLTransistorMapper(TIKZ_COMPONENTS.nigfete, [TRANSISTOR_TOP_PIN, TRANSISTOR_BOTTOM_PIN, TRANSISTOR_TAP_PIN], 2)],
["ads_rflib:FET", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FET2", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN1", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN2", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN3", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN4", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN4a", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_rflib:FETN5", ADS_TIKZ_MAPPERS.SIMPLE_FETN], // ads_rflib, Devices-Linear
["ads_pelib:MOS_GENERIC_N", ADS_TIKZ_MAPPERS.SIMPLE_FETN],
// ###BJTs
["BJT_NPN", ADS_TIKZ_MAPPERS.BJT],
["ads_rflib:BIP", ADS_TIKZ_MAPPERS.BJT],
["ads_rflib:BIPB", ADS_TIKZ_MAPPERS.BJT],
["ads_rflib:HYBPI", ADS_TIKZ_MAPPERS.BJT],
// ###Hacky workaround for OpAmps
["ads_behavioral:Amplifier2", TIKZ_COMPONENTS.amp], // generic amplifier
[
"OpAmp",
new ABLTransistorMapper(
TIKZ_COMPONENTS["op amp"],
[
new Pin(ZERO_COORD, "P__0", 1), // -
new Pin(new Coordinate(0, -0.5), "P__2", 3), // +
new Pin(new Coordinate(1, -0.25), "P__1", 2), // out
],
0 /* inv */
),
],
]);
export { ADS_COMPONENTS_MAP };