Skip to content

Commit

Permalink
SubCircuitElm quick fix
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson- committed Jan 27, 2016
1 parent eaf14fe commit 0722e1d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/s3f/pyrite/core/circuitsim/CircuitDOTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String parse(String inputCircuitFile) {
}

public static Circuit parseFromFile(String fileData) {
return parse(SimBuilder.newHiddenSim(fileData, false));
return parse(SimBuilder.newHiddenSim(fileData, false, true));
}

public static Circuit parse(CircuitSimulator cs) {
Expand Down Expand Up @@ -241,7 +241,7 @@ public static Circuit parse(CircuitSimulator cs) {
Component c = entry.getValue();
long sleep = SLEEP;
SLEEP = 0;
Circuit sub = parse(SimBuilder.newHiddenSim(subCircuitElm.getCircuit(), false));
Circuit sub = parse(SimBuilder.newHiddenSim(subCircuitElm.getCircuit(), false, true));
SLEEP = sleep;
cir.insert(sub, c);
sleep();
Expand Down
9 changes: 6 additions & 3 deletions src/s3f/pyrite/core/circuitsim/SimBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public class SimBuilder {

//simulador escondido
public static CircuitSimulator newHiddenSim(String text, boolean run) {
public static CircuitSimulator newHiddenSim(String text, boolean run, boolean dummy) {
JApplet window = new JApplet();
final CircuitSimulator cs = new CircuitSimulator(!run);
cs.setStopped(!run);
Expand All @@ -42,11 +42,14 @@ public static CircuitSimulator newHiddenSim(String text, boolean run) {
cs.register(SubCircuitElm.class);
cs.register(DigitalLogicTester.class);
}
if (dummy) {
cs.setDisabled();
}
cs.init();
window.setJMenuBar(cs.getGUI().createGUI(true));
cs.posInit();

if (!run) {
if (!run && !dummy) {
cs.analyzeCircuit();
for (int i = 0; i < 30; i++) {
cs.updateCircuit(null);
Expand Down Expand Up @@ -84,7 +87,7 @@ public static CircuitSimulator newWindowSim(String text) {
}

public static CircuitSimulator newWindowSim(Circuit circuit) {
CircuitSimulator cs = newHiddenSim("", false);
CircuitSimulator cs = newHiddenSim("", false, false);

HashMap<Component, Point> pointMap = new HashMap<>();

Expand Down
2 changes: 1 addition & 1 deletion src/s3f/pyrite/ui/components/MyLogicInputElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void draw(Graphics g) {
public void setVInput(double v) {
if (v != this.v) {
System.out.println(v + " " + this.v);
currentSim.setUnstable(true);
sim.setUnstable(true);
}
this.v = v;
}
Expand Down
42 changes: 25 additions & 17 deletions src/s3f/pyrite/ui/components/SubCircuitElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public SubCircuitElm(int xa, int ya, int xb, int yb, int f,
super(xa, ya, xb, yb, f, st);
if (st.hasMoreTokens()) {
name = st.nextToken("\0").trim();
}
}

@Override
public void setSim(CircuitSimulator sim) {
super.setSim(sim);
if (!name.isEmpty()) {
reload();
}
}
Expand All @@ -80,22 +87,23 @@ public void draw(Graphics g) {
int yc = y;
int circleSize = 5;
super.draw(g);

SubCircuitElm i = this;
boolean s = true;
while (s && i != null) {
s &= isStable(i.cs);
i = i.parent;
}
if (this.cs.isStopped()) {
g.setColor(Color.ORANGE);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
} else if (this.cs != null && s) {
g.setColor(Color.green);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
} else {
g.setColor(Color.red);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
if (cs != null) {
SubCircuitElm i = this;
boolean s = true;
while (s && i != null) {
s &= isStable(i.cs);
i = i.parent;
}
if (cs.isStopped()) {
g.setColor(Color.ORANGE);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
} else if (s) {
g.setColor(Color.green);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
} else {
g.setColor(Color.red);
g.fillOval(xc - circleSize, yc - circleSize, circleSize * 2, circleSize * 2);
}
}
}

Expand Down Expand Up @@ -264,7 +272,7 @@ private void reload() {
CircuitFile circuitModule = (CircuitFile) e;
if (circuitModule.getName().equals(name)) {
circuit = circuitModule.getText();
CircuitSimulator cs = SimBuilder.newHiddenSim(circuit, true);
CircuitSimulator cs = SimBuilder.newHiddenSim(circuit, true, false);

for (int i = 0; i < cs.elmListSize(); i++) {
CircuitElm elm = cs.getElm(i);
Expand Down

0 comments on commit 0722e1d

Please sign in to comment.