mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
added micro stepping
This commit is contained in:
parent
9200771046
commit
5f3b608fff
@ -41,7 +41,16 @@ public class Model {
|
||||
|
||||
public void doStep(boolean noise) throws NodeException {
|
||||
int counter = 0;
|
||||
while (!nodesToUpdateNext.isEmpty()) {
|
||||
while (!doMicroStep(noise)) {
|
||||
if (listener != null)
|
||||
listener.needsUpdate();
|
||||
if (counter++ > maxCounter) {
|
||||
throw new NodeException("seemsToOscillate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean doMicroStep(boolean noise) throws NodeException {
|
||||
version++;
|
||||
// swap lists
|
||||
ArrayList<Node> nl = nodesToUpdateNext;
|
||||
@ -64,12 +73,7 @@ public class Model {
|
||||
n.writeOutputs();
|
||||
}
|
||||
}
|
||||
if (counter++ > maxCounter) {
|
||||
throw new NodeException("seemsToOscillate");
|
||||
}
|
||||
if (listener != null)
|
||||
listener.needsUpdate();
|
||||
}
|
||||
return nodesToUpdateNext.isEmpty();
|
||||
}
|
||||
|
||||
public void init() throws NodeException {
|
||||
|
@ -3,6 +3,7 @@ package de.neemann.digital.gui;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
|
||||
import com.thoughtworks.xstream.io.xml.StaxDriver;
|
||||
import de.neemann.digital.core.Listener;
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.PartDescription;
|
||||
import de.neemann.digital.core.basic.*;
|
||||
@ -121,14 +122,29 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
JMenu run = new JMenu("Run");
|
||||
bar.add(run);
|
||||
|
||||
JCheckBox microStep = new JCheckBox("micro");
|
||||
|
||||
ToolTipAction runModel = new ToolTipAction("Run") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
ModelDescription m = new ModelDescription(circuitComponent.getCircuit());
|
||||
Model model = m.create(circuitComponent);
|
||||
model.init(true);
|
||||
circuitComponent.setMode(CircuitComponent.Mode.running);
|
||||
ModelDescription m = new ModelDescription(circuitComponent.getCircuit());
|
||||
Model model = m.createModel(circuitComponent);
|
||||
if (microStep.isSelected()) {
|
||||
model.setListener(new Listener() {
|
||||
@Override
|
||||
public void needsUpdate() {
|
||||
circuitComponent.paintImmediately(circuitComponent.getVisibleRect());
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
model.init(true);
|
||||
} catch (Exception e1) {
|
||||
new ErrorMessage("error creating model").addCause(e1).show(Main.this);
|
||||
}
|
||||
@ -142,6 +158,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
toolBar.add(partsMode.createJButton());
|
||||
toolBar.add(wireMode.createJButton());
|
||||
toolBar.add(selectionMode.createJButton());
|
||||
toolBar.add(runModel.createJButton());
|
||||
toolBar.add(microStep);
|
||||
|
||||
toolBar.addSeparator();
|
||||
insertHistory = new InsertHistory(toolBar);
|
||||
|
@ -75,6 +75,7 @@ public class CircuitComponent extends JComponent implements Listener {
|
||||
addMouseMotionListener(listener);
|
||||
addMouseListener(listener);
|
||||
requestFocusInWindow();
|
||||
circuit.clearState();
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class ModelDescription {
|
||||
}
|
||||
}
|
||||
|
||||
public Model create(Listener listener) throws PinException, NodeException {
|
||||
public Model createModel(Listener listener) throws PinException, NodeException {
|
||||
for (Net n : netList)
|
||||
n.interconnect();
|
||||
|
||||
|
@ -105,4 +105,11 @@ public class Circuit implements Drawable {
|
||||
dots = WireConsistencyChecker.createDots(wires);
|
||||
return dots;
|
||||
}
|
||||
|
||||
public void clearState() {
|
||||
for (VisualPart vp : visualParts)
|
||||
vp.setState(null, null, null);
|
||||
for (Wire w : wires)
|
||||
w.setValue(null);
|
||||
}
|
||||
}
|
||||
|
@ -132,6 +132,9 @@ public class VisualPart implements Drawable, Moveable {
|
||||
*/
|
||||
public void setState(State state, Listener listener, Model model) {
|
||||
this.state = state;
|
||||
if (state == null)
|
||||
interactor = null;
|
||||
else
|
||||
interactor = partDescription.getShape().applyStateMonitor(state, listener, model);
|
||||
}
|
||||
|
||||
|
@ -76,21 +76,6 @@ public class GenericShape implements Shape {
|
||||
|
||||
@Override
|
||||
public Interactor applyStateMonitor(State state, Listener listener, Model model) {
|
||||
if (symmetric) {
|
||||
state.getOutput(0).addListener(new Listener() {
|
||||
public long lastValue = 0;
|
||||
|
||||
@Override
|
||||
public void needsUpdate() {
|
||||
long value = state.getInput(0).getValue();
|
||||
if (lastValue != value) {
|
||||
lastValue = value;
|
||||
listener.needsUpdate();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -99,9 +84,9 @@ public class GenericShape implements Shape {
|
||||
int max = Math.max(inputs, outputs);
|
||||
int height = (max - 1) * SIZE + SIZE2;
|
||||
|
||||
if (symmetric && state != null) {
|
||||
graphic.drawText(new Vector(width * SIZE, 0), new Vector((width + 1) * SIZE, 0), Long.toString(state.getOutput(0).getValue()));
|
||||
}
|
||||
// if (symmetric && state != null) {
|
||||
// graphic.drawText(new Vector(width * SIZE, 0), new Vector((width + 1) * SIZE, 0), Long.toString(state.getOutput(0).getValue()));
|
||||
// }
|
||||
|
||||
|
||||
if (symmetric && ((inputs & 1) == 0)) height += SIZE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user