Search in sources :

Example 1 with Rotation

use of de.neemann.digital.core.element.Rotation 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)));
    }
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Wire(de.neemann.digital.draw.elements.Wire) Rotation(de.neemann.digital.core.element.Rotation) Vector(de.neemann.digital.draw.graphics.Vector)

Example 2 with Rotation

use of de.neemann.digital.core.element.Rotation in project Digital by hneemann.

the class CircuitBuilder method addClockToFlipFlops.

private void addClockToFlipFlops(Circuit circuit) {
    int x = Integer.MAX_VALUE;
    int yMin = Integer.MAX_VALUE;
    int yMax = Integer.MIN_VALUE;
    for (FragmentVisualElement ff : flipflops) {
        Vector p = ff.getVisualElement().getPos();
        if (p.x < x)
            x = p.x;
        if (p.y < yMin)
            yMin = p.y;
        if (p.y > yMax)
            yMax = p.y;
    }
    x -= SIZE;
    if (useJKff)
        x -= SIZE;
    int yPos = yMin - SIZE * 3;
    if (useJKff)
        yPos = -SIZE;
    circuit.add(new Wire(new Vector(x, yPos), new Vector(x, yMax + SIZE)));
    for (FragmentVisualElement ff : flipflops) {
        Vector p = ff.getVisualElement().getPos();
        circuit.add(new Wire(new Vector(x, p.y + SIZE), new Vector(p.x, p.y + SIZE)));
    }
    VisualElement clock = new VisualElement(Clock.DESCRIPTION.getName()).setShapeFactory(shapeFactory).setPos(new Vector(x, yPos));
    clock.getElementAttributes().set(Keys.LABEL, "C").set(Keys.ROTATE, new Rotation(3)).set(Keys.FREQUENCY, 2).set(Keys.RUN_AT_REAL_TIME, true);
    circuit.add(clock);
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector) Rotation(de.neemann.digital.core.element.Rotation)

Aggregations

Rotation (de.neemann.digital.core.element.Rotation)2 VisualElement (de.neemann.digital.draw.elements.VisualElement)2 Wire (de.neemann.digital.draw.elements.Wire)2 Vector (de.neemann.digital.draw.graphics.Vector)2