-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInductorElm.java
More file actions
90 lines (89 loc) · 2.38 KB
/
InductorElm.java
File metadata and controls
90 lines (89 loc) · 2.38 KB
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
import java.awt.*;
import java.util.StringTokenizer;
class InductorElm extends CircuitElm {
Inductor ind;
double inductance;
public InductorElm(int xx, int yy) {
super(xx, yy);
ind = new Inductor(sim);
inductance = 1;
ind.setup(inductance, current, flags);
}
public InductorElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
ind = new Inductor(sim);
inductance = new Double(st.nextToken()).doubleValue();
current = new Double(st.nextToken()).doubleValue();
ind.setup(inductance, current, flags);
}
int getDumpType() { return 'l'; }
String dump() {
return super.dump() + " " + inductance + " " + current;
}
void setPoints() {
super.setPoints();
calcLeads(32);
}
void draw(Graphics g) {
double v1 = volts[0];
double v2 = volts[1];
int i;
int hs = 8;
setBbox(point1, point2, hs);
draw2Leads(g);
setPowerColor(g, false);
drawCoil(g, 8, lead1, lead2, v1, v2);
if (sim.showValuesCheckItem.getState()) {
String s = getShortUnitText(inductance, "H");
drawValues(g, s, hs);
}
doDots(g);
drawPosts(g);
}
void reset() {
current = volts[0] = volts[1] = curcount = 0;
ind.reset();
}
void stamp() { ind.stamp(nodes[0], nodes[1]); }
void startIteration() {
ind.startIteration(volts[0]-volts[1]);
}
boolean nonLinear() { return ind.nonLinear(); }
void calculateCurrent() {
double voltdiff = volts[0]-volts[1];
current = ind.calculateCurrent(voltdiff);
}
void doStep() {
double voltdiff = volts[0]-volts[1];
ind.doStep(voltdiff);
}
void getInfo(String arr[]) {
arr[0] = "inductor";
getBasicInfo(arr);
arr[3] = "L = " + getUnitText(inductance, "H");
arr[4] = "P = " + getUnitText(getPower(), "W");
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Inductance (H)", inductance, 0, 0);
if (n == 1) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Trapezoidal Approximation",
ind.isTrapezoidal());
return ei;
}
return null;
}
public void setEditValue(int n, EditInfo ei) {
if (n == 0)
inductance = ei.value;
if (n == 1) {
if (ei.checkbox.getState())
flags &= ~Inductor.FLAG_BACK_EULER;
else
flags |= Inductor.FLAG_BACK_EULER;
}
ind.setup(inductance, current, flags);
}
}