-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailElm.java
More file actions
61 lines (59 loc) · 1.83 KB
/
RailElm.java
File metadata and controls
61 lines (59 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
import java.awt.*;
import java.util.StringTokenizer;
class RailElm extends VoltageElm {
public RailElm(int xx, int yy) { super(xx, yy, WF_DC); }
RailElm(int xx, int yy, int wf) { super(xx, yy, wf); }
public RailElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
final int FLAG_CLOCK = 1;
int getDumpType() { return 'R'; }
int getPostCount() { return 1; }
void setPoints() {
super.setPoints();
lead1 = interpPoint(point1, point2, 1-circleSize/dn);
}
void draw(Graphics g) {
setBbox(point1, point2, circleSize);
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);
boolean clock = waveform == WF_SQUARE && (flags & FLAG_CLOCK) != 0;
if (waveform == WF_DC || waveform == WF_VAR || clock) {
Font f = new Font("SansSerif", 0, 12);
g.setFont(f);
g.setColor(needsHighlight() ? selectColor : whiteColor);
setPowerColor(g, false);
double v = getVoltage();
String s = getShortUnitText(v, "V");
if (Math.abs(v) < 1)
s = showFormat.format(v) + "V";
if (getVoltage() > 0)
s = "+" + s;
if (this instanceof AntennaElm)
s = "Ant";
if (clock)
s = "CLK";
drawCenteredText(g, s, x2, y2, true);
} else {
drawWaveform(g, point2);
}
drawPosts(g);
curcount = updateDotCount(-current, curcount);
if (sim.dragElm != this)
drawDots(g, point1, lead1, curcount);
}
double getVoltageDiff() { return volts[0]; }
void stamp() {
if (waveform == WF_DC)
sim.stampVoltageSource(0, nodes[0], voltSource, getVoltage());
else
sim.stampVoltageSource(0, nodes[0], voltSource);
}
void doStep() {
if (waveform != WF_DC)
sim.updateVoltageSource(0, nodes[0], voltSource, getVoltage());
}
boolean hasGroundConnection(int n1) { return true; }
int getShortcut() { return 'V'; }
}