use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class CircuitBuilder method createInputBus.
private void createInputBus(Collection<Variable> inputs, Circuit circuit) {
HashMap<String, Integer> varPos = new HashMap<>();
int dx = -inputs.size() * SIZE * 2;
pos -= SIZE;
for (Variable v : inputs) {
VisualElement visualElement;
if (sequentialVars.contains(v) || varsToNet.contains(v.getIdentifier())) {
visualElement = new VisualElement(Tunnel.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(1)).set(Keys.NETNAME, v.getIdentifier());
} else {
visualElement = new VisualElement(In.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3)).set(Keys.LABEL, v.getIdentifier());
checkPinNumber(visualElement);
}
visualElement.setPos(new Vector(dx, -SIZE * 5));
circuit.add(visualElement);
circuit.add(new Wire(new Vector(dx, -SIZE * 5), new Vector(dx, pos)));
if (isNotNeeded(v.getIdentifier())) {
visualElement = new VisualElement(de.neemann.digital.core.basic.Not.DESCRIPTION.getName()).setShapeFactory(shapeFactory);
visualElement.getElementAttributes().set(Keys.ROTATE, new Rotation(3));
visualElement.setPos(new Vector(dx + SIZE, -SIZE * 3));
circuit.add(visualElement);
circuit.add(new Wire(new Vector(dx, -SIZE * 4), new Vector(dx + SIZE, -SIZE * 4)));
circuit.add(new Wire(new Vector(dx + SIZE, -SIZE * 3), new Vector(dx + SIZE, -SIZE * 4)));
circuit.add(new Wire(new Vector(dx + SIZE, -SIZE), new Vector(dx + SIZE, pos)));
}
varPos.put(v.getIdentifier(), dx);
dx += SIZE * 2;
}
for (FragmentVariable f : fragmentVariables) {
Vector p = f.getCircuitPos();
int in = varPos.get(f.getVariable().getIdentifier());
if (f.isInvert())
in += SIZE;
circuit.add(new Wire(p, new Vector(in, p.y)));
}
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class CircuitBuilder method checkForInputBus.
private void checkForInputBus(Collection<Variable> variables, int splitterXPos, Circuit circuit) {
StringBuilder pinString = new StringBuilder();
int y = 0;
for (Map.Entry<String, ArrayList<String>> e : mis.getInputBusMap().entrySet()) {
pinString.setLength(0);
int found = 0;
final ArrayList<String> inputs = e.getValue();
for (String n : inputs) {
if (variables.contains(new Variable(n))) {
found++;
String p = mis.getPins().get(n);
if (p != null) {
if (pinString.length() != 0)
pinString.append(",");
pinString.append(p);
}
}
}
if (found == inputs.size()) {
varsToNet.addAll(inputs);
circuit.add(new VisualElement(Splitter.DESCRIPTION.getName()).setAttribute(Keys.INPUT_SPLIT, "" + inputs.size()).setAttribute(Keys.OUTPUT_SPLIT, "1*" + inputs.size()).setPos(new Vector(splitterXPos, y)).setShapeFactory(shapeFactory));
circuit.add(new VisualElement(In.DESCRIPTION.getName()).setAttribute(Keys.LABEL, e.getKey()).setAttribute(Keys.BITS, inputs.size()).setAttribute(Keys.PINNUMBER, pinString.toString()).setPos(new Vector(splitterXPos - 2 * SIZE, y)).setShapeFactory(shapeFactory));
circuit.add(new Wire(new Vector(splitterXPos - 2 * SIZE, y), new Vector(splitterXPos, y)));
for (int i = 0; i < inputs.size(); i++) {
circuit.add(new VisualElement(Tunnel.DESCRIPTION.getName()).setAttribute(Keys.NETNAME, inputs.get(i)).setPos(new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)).setShapeFactory(shapeFactory));
circuit.add(new Wire(new Vector(splitterXPos + SIZE, y + i * SIZE), new Vector(splitterXPos + 2 * SIZE, y + i * SIZE)));
}
y += (inputs.size() + 2) * SIZE;
}
}
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class FragmentExpression method addToCircuit.
@Override
public void addToCircuit(Vector offset, Circuit circuit) {
Vector p = pos.add(offset);
merger.addToCircuit(p, circuit);
for (int i = 0; i < fragments.size(); i++) {
FragmentHolder fr = fragments.get(i);
fr.fragment.addToCircuit(p, circuit);
Vector pin = fr.fragment.getOutputs().get(0);
Vector start = pin.add(p);
Vector end = merger.getInputs().get(i).add(p);
int back = 0;
if (normalLayout)
back = calcBackOffset(fragments.size(), i);
if (back > 0) {
Vector inter2 = end.add(-back * SIZE, 0);
Vector inter1 = new Vector(inter2.x, start.y);
circuit.add(new Wire(start, inter1));
circuit.add(new Wire(inter1, inter2));
circuit.add(new Wire(inter2, end));
} else {
circuit.add(new Wire(start, end));
}
}
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class FragmentSameInValue method addToCircuit.
@Override
public void addToCircuit(Vector pos, Circuit circuit) {
List<Vector> in = Vector.add(fragment.getInputs(), pos);
Vector last = null;
for (Vector v : in) {
Vector p = v.add(-SIZE, 0);
circuit.add(new Wire(v, p));
if (last != null)
circuit.add(new Wire(last, p));
last = p;
}
fragment.addToCircuit(pos, circuit);
}
use of de.neemann.digital.draw.elements.Wire in project Digital by hneemann.
the class NetListTest method testTunnel2.
public void testTunnel2() throws Exception {
Circuit c = new Circuit();
c.add(new Wire(new Vector(1, 1), new Vector(2, 1)));
addTunnel(c, new Vector(2, 1), "A");
c.add(new Wire(new Vector(3, 1), new Vector(4, 1)));
addTunnel(c, new Vector(3, 1), "A");
c.add(new Wire(new Vector(1, 4), new Vector(2, 4)));
addTunnel(c, new Vector(2, 4), "B");
c.add(new Wire(new Vector(3, 4), new Vector(4, 4)));
addTunnel(c, new Vector(3, 4), "B");
NetList ns = new NetList(c);
assertEquals(2, ns.size());
}
Aggregations