Skip to content

Commit

Permalink
circular symbol #110
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalstad committed Oct 23, 2024
1 parent 41d2919 commit 400e7fe
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions src/com/lushprojects/circuitjs1/client/AmmeterElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AmmeterElm extends CircuitElm {

public AmmeterElm(int xx, int yy) {
super(xx, yy);
flags = FLAG_SHOWCURRENT;
flags = FLAG_SHOWCURRENT|FLAG_CIRCLE;
scale = SCALE_AUTO;
}
public AmmeterElm(int xa, int ya, int xb, int yb, int f,
Expand All @@ -68,10 +68,14 @@ String getMeter(){
void setPoints(){
super.setPoints();
mid = interpPoint(point1,point2,0.6);
center = interpPoint(point1,point2,0.5);
arrowPoly = calcArrow(point1, mid, 14, 7);
}
Point center;
Point mid;
static final int FLAG_SHOWCURRENT = 1;
static final int FLAG_CIRCLE = 2; // Add this line

void stepFinished(){
count++;//how many counts are in a cycle
total += current*current; //sum of squares
Expand Down Expand Up @@ -145,10 +149,35 @@ void stepFinished(){
void draw(Graphics g) {
super.draw(g);//BC required for highlighting
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, point2);
g.fillPolygon(arrowPoly);
double width = 4;
if (!drawAsCircle()) {
drawThickLine(g, point1, point2);
g.fillPolygon(arrowPoly);
} else {
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickCircle(g, center.x, center.y, circleSize);
drawCenteredText(g, "A", center.x, center.y, true);

calcLeads(circleSize*2);
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);
drawThickLine(g, lead2, point2);

g.setColor(whiteColor);
g.setFont(unitsFont);
double len = circleSize*2;
Point plusPoint = interpPoint(point1, point2, (dn/2-len/2-4)/dn, -10*dsign );
if (y2 > y)
plusPoint.y += 4;
if (y > y2)
plusPoint.y += 3;
int w = (int)g.context.measureText("+").getWidth();
g.drawString("+", plusPoint.x-w/2, plusPoint.y);
width = circleSize;
}

doDots(g);
setBbox(point1, point2, 3);
setBbox(point1, point2, width);
String s = "A";
switch (meter) {
case AM_VOL:
Expand All @@ -159,9 +188,12 @@ void draw(Graphics g) {
break;
}

drawValues(g, s, 4);
drawValues(g, s, width);
drawPosts(g);
}

final int circleSize = 12;

int getDumpType() { return 370; }
void stamp() {
sim.stampVoltageSource(nodes[0], nodes[1], voltSource, 0);
Expand All @@ -188,6 +220,10 @@ void getInfo(String arr[]) {
// (because we need current calculated every timestep)
boolean isWireEquivalent() { return true; }

boolean drawAsCircle() {
return (flags & FLAG_CIRCLE) != 0;
}

public EditInfo getEditInfo(int n) {
if (n==0){
EditInfo ei = new EditInfo("Value", selectedValue, -1, -1);
Expand All @@ -207,13 +243,19 @@ public EditInfo getEditInfo(int n) {
ei.choice.select(scale);
return ei;
}
if (n == 2) {
return EditInfo.createCheckbox("Circular Symbol", drawAsCircle());
}
return null;
}

public void setEditValue(int n, EditInfo ei) {
if (n==0)
meter = ei.choice.getSelectedIndex();
if (n==1)
scale = ei.choice.getSelectedIndex();
if (n==2)
flags = ei.changeFlag(flags, FLAG_CIRCLE);
}

}
Expand Down

0 comments on commit 400e7fe

Please sign in to comment.