mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 14:56:29 -04:00
added a probe, simplified outputs
This commit is contained in:
parent
18ec49d2c4
commit
fd0bb0a576
@ -1,35 +0,0 @@
|
||||
package de.neemann.digital.core.io;
|
||||
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.part.AttributeKey;
|
||||
import de.neemann.digital.core.part.Part;
|
||||
import de.neemann.digital.core.part.PartAttributes;
|
||||
import de.neemann.digital.core.part.PartTypeDescription;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class LED implements Part {
|
||||
|
||||
public static final PartTypeDescription DESCRIPTION = new PartTypeDescription(LED.class, "in")
|
||||
.addAttribute(AttributeKey.Label)
|
||||
.addAttribute(AttributeKey.Color);
|
||||
|
||||
public LED(PartAttributes attributes) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValue[] getOutputs() {
|
||||
return new ObservableValue[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerNodes(Model model) {
|
||||
}
|
||||
}
|
@ -17,6 +17,15 @@ public class Out implements Part {
|
||||
.addAttribute(AttributeKey.Bits)
|
||||
.addAttribute(AttributeKey.Label);
|
||||
|
||||
public static final PartTypeDescription PROBEDESCRIPTION = new PartTypeDescription("Probe", Out.class, "in")
|
||||
.addAttribute(AttributeKey.Bits)
|
||||
.addAttribute(AttributeKey.Label);
|
||||
|
||||
public static final PartTypeDescription LEDDESCRIPTION = new PartTypeDescription("LED", Out.class, "in")
|
||||
.addAttribute(AttributeKey.Label)
|
||||
.addAttribute(AttributeKey.Color);
|
||||
|
||||
|
||||
private ObservableValue value;
|
||||
|
||||
public Out(PartAttributes attributes) {
|
||||
|
@ -17,7 +17,11 @@ public class PartTypeDescription {
|
||||
private final ArrayList<AttributeKey> attributeList;
|
||||
|
||||
public PartTypeDescription(Class<?> clazz, String... inputNames) {
|
||||
this(clazz.getSimpleName(), new PartFactory() {
|
||||
this(clazz.getSimpleName(), clazz, inputNames);
|
||||
}
|
||||
|
||||
public PartTypeDescription(String name, Class<?> clazz, String... inputNames) {
|
||||
this(name, new PartFactory() {
|
||||
@Override
|
||||
public Part create(PartAttributes attributes) {
|
||||
try {
|
||||
|
@ -10,7 +10,6 @@ import de.neemann.digital.core.flipflops.RS_FF;
|
||||
import de.neemann.digital.core.flipflops.T_FF;
|
||||
import de.neemann.digital.core.io.Const;
|
||||
import de.neemann.digital.core.io.In;
|
||||
import de.neemann.digital.core.io.LED;
|
||||
import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.part.PartTypeDescription;
|
||||
import de.neemann.digital.core.wiring.Delay;
|
||||
@ -38,9 +37,10 @@ public class PartLibrary implements Iterable<PartLibrary.PartContainer> {
|
||||
add(Delay.DESCRIPTION, "Logic");
|
||||
|
||||
add(In.DESCRIPTION, "IO");
|
||||
add(Out.DESCRIPTION, "IO");
|
||||
add(Const.DESCRIPTION, "IO");
|
||||
add(LED.DESCRIPTION, "IO");
|
||||
add(Out.DESCRIPTION, "IO");
|
||||
add(Out.LEDDESCRIPTION, "IO");
|
||||
add(Out.PROBEDESCRIPTION, "IO");
|
||||
|
||||
add(RS_FF.DESCRIPTION, "FlipFlops");
|
||||
add(JK_FF.DESCRIPTION, "FlipFlops");
|
||||
|
@ -33,11 +33,11 @@ public class ModelEntry {
|
||||
for (int i = 0; i < inputNames.length; i++) {
|
||||
Pin pin = ins.get(inputNames[i]);
|
||||
if (pin == null)
|
||||
throw new PinException("pin " + inputNames[i] + " not found!");
|
||||
throw new PinException("pin '" + inputNames[i] + "' at " + visualPart + " not found!");
|
||||
|
||||
ObservableValue value = pin.getValue();
|
||||
if (value == null)
|
||||
throw new PinException("no value set for " + inputNames[i] + "!");
|
||||
throw new PinException("no value set for '" + inputNames[i] + "' at " + visualPart + "!");
|
||||
|
||||
inputs[i] = value;
|
||||
}
|
||||
|
@ -165,4 +165,13 @@ public class VisualPart implements Drawable, Moveable, AttributeListener {
|
||||
shape = null;
|
||||
minMax = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String lab = partAttributes.get(AttributeKey.Label);
|
||||
if (lab != null && lab.length() > 0)
|
||||
return partName + "(" + lab + ")";
|
||||
else
|
||||
return partName;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package de.neemann.digital.gui.draw.shapes;
|
||||
|
||||
import de.neemann.digital.core.Listener;
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.gui.draw.graphics.Graphic;
|
||||
import de.neemann.digital.gui.draw.graphics.Orientation;
|
||||
import de.neemann.digital.gui.draw.graphics.Style;
|
||||
import de.neemann.digital.gui.draw.graphics.Vector;
|
||||
import de.neemann.digital.gui.draw.parts.Pin;
|
||||
import de.neemann.digital.gui.draw.parts.Pins;
|
||||
import de.neemann.digital.gui.draw.parts.State;
|
||||
|
||||
/**
|
||||
* @author hneemann
|
||||
*/
|
||||
public class ProbeShape implements Shape {
|
||||
|
||||
|
||||
private final String label;
|
||||
|
||||
public ProbeShape(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pins getPins() {
|
||||
return new Pins().add(new Pin(new Vector(0, 0), "in", Pin.Direction.input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Interactor applyStateMonitor(State state, Listener listener, Model model) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTo(Graphic graphic, State state) {
|
||||
graphic.drawText(new Vector(2, -1), new Vector(3, -1), label, Orientation.LEFTBOTTOM, Style.NORMAL);
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import de.neemann.digital.core.arithmetic.Sub;
|
||||
import de.neemann.digital.core.basic.*;
|
||||
import de.neemann.digital.core.io.Const;
|
||||
import de.neemann.digital.core.io.In;
|
||||
import de.neemann.digital.core.io.LED;
|
||||
import de.neemann.digital.core.io.Out;
|
||||
import de.neemann.digital.core.part.AttributeKey;
|
||||
import de.neemann.digital.core.part.PartAttributes;
|
||||
@ -42,9 +41,10 @@ public final class ShapeFactory {
|
||||
|
||||
|
||||
map.put(In.DESCRIPTION.getName(), attr -> new InputShape(attr.get(AttributeKey.Bits), attr.get(AttributeKey.Label)));
|
||||
map.put(Out.DESCRIPTION.getName(), attr -> new OutputShape(attr.get(AttributeKey.Bits), attr.get(AttributeKey.Label)));
|
||||
map.put(Const.DESCRIPTION.getName(), attr -> new ConstShape(attr.get(AttributeKey.Value)));
|
||||
map.put(LED.DESCRIPTION.getName(), attr -> new LEDShape(attr.get(AttributeKey.Label), attr.get(AttributeKey.Color)));
|
||||
map.put(Out.DESCRIPTION.getName(), attr -> new OutputShape(attr.get(AttributeKey.Bits), attr.get(AttributeKey.Label)));
|
||||
map.put(Out.LEDDESCRIPTION.getName(), attr -> new LEDShape(attr.get(AttributeKey.Label), attr.get(AttributeKey.Color)));
|
||||
map.put(Out.PROBEDESCRIPTION.getName(), attr -> new ProbeShape(attr.get(AttributeKey.Label)));
|
||||
}
|
||||
|
||||
public PartLibrary setLibrary(PartLibrary library) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user