-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentElm.java
More file actions
73 lines (69 loc) · 1.83 KB
/
CurrentElm.java
File metadata and controls
73 lines (69 loc) · 1.83 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
import java.awt.*;
import java.util.StringTokenizer;
class CurrentElm extends CircuitElm {
double currentValue;
public CurrentElm(int xx, int yy) {
super(xx, yy);
currentValue = .01;
}
public CurrentElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
try {
currentValue = new Double(st.nextToken()).doubleValue();
} catch (Exception e) {
currentValue = .01;
}
}
String dump() {
return super.dump() + " " + currentValue;
}
int getDumpType() { return 'i'; }
Polygon arrow;
Point ashaft1, ashaft2, center;
void setPoints() {
super.setPoints();
calcLeads(26);
ashaft1 = interpPoint(lead1, lead2, .25);
ashaft2 = interpPoint(lead1, lead2, .6);
center = interpPoint(lead1, lead2, .5);
Point p2 = interpPoint(lead1, lead2, .75);
arrow = calcArrow(center, p2, 4, 4);
}
void draw(Graphics g) {
int cr = 12;
draw2Leads(g);
setVoltageColor(g, (volts[0]+volts[1])/2);
setPowerColor(g, false);
drawThickCircle(g, center.x, center.y, cr);
drawThickLine(g, ashaft1, ashaft2);
g.fillPolygon(arrow);
setBbox(point1, point2, cr);
doDots(g);
if (sim.showValuesCheckItem.getState()) {
String s = getShortUnitText(currentValue, "A");
if (dx == 0 || dy == 0)
drawValues(g, s, cr);
}
drawPosts(g);
}
void stamp() {
current = currentValue;
sim.stampCurrentSource(nodes[0], nodes[1], current);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Current (A)", currentValue, 0, .1);
return null;
}
public void setEditValue(int n, EditInfo ei) {
currentValue = ei.value;
}
void getInfo(String arr[]) {
arr[0] = "current source";
getBasicInfo(arr);
}
double getVoltageDiff() {
return volts[1] - volts[0];
}
}