Search in sources :

Example 1 with Vector

use of de.neemann.digital.draw.graphics.Vector 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 Vector

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

Example 3 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class FragmentExpression method doLayoutNormal.

private Box doLayoutNormal() {
    ArrayList<ConstExpression> constExpr = new ArrayList<>();
    int height = 0;
    int width = 0;
    for (FragmentHolder fr : fragments) {
        fr.fragment.setPos(new Vector(0, height));
        if (isConst(fr.fragment))
            constExpr.add(new ConstExpression(fr.fragment, height));
        fr.box = fr.fragment.doLayout();
        height += fr.box.getHeight();
        int w = fr.box.getWidth();
        if (w > width)
            width = w;
        height += SIZE * 2;
    }
    height -= SIZE * 2;
    Box mergerBox = merger.doLayout();
    width += (fragments.size() / 2 + 1) * SIZE;
    if (alignedWidth > 0) {
        width = alignedWidth - mergerBox.getWidth();
    }
    for (ConstExpression ce : constExpr) ce.setXPos(width);
    int centerIndex = fragments.size() / 2;
    int y;
    if ((fragments.size() & 1) == 0) {
        // even number of inputs
        int y1 = fragments.get(centerIndex - 1).fragment.getOutputs().get(0).y;
        int y2 = fragments.get(centerIndex).fragment.getOutputs().get(0).y;
        y = raster((y1 + y2) / 2) - centerIndex * SIZE;
    } else {
        // odd number of inputs
        y = fragments.get(centerIndex).fragment.getOutputs().get(0).y - centerIndex * SIZE;
    }
    merger.setPos(new Vector(width, y));
    width += mergerBox.getWidth();
    return new Box(width, Math.max(height, y + mergerBox.getHeight()));
}
Also used : ArrayList(java.util.ArrayList) Vector(de.neemann.digital.draw.graphics.Vector)

Example 4 with Vector

use of de.neemann.digital.draw.graphics.Vector in project Digital by hneemann.

the class FragmentExpression method doLayoutOnlyVariables.

private Box doLayoutOnlyVariables() {
    int xPos = SIZE;
    if (alignedWidth > 0) {
        Box mergerBox = merger.doLayout();
        xPos = alignedWidth - mergerBox.getWidth();
    }
    Box mergerBox = merger.doLayout();
    merger.setPos(new Vector(xPos, 0));
    Iterator<Vector> in = merger.getInputs().iterator();
    for (FragmentHolder fr : fragments) {
        fr.fragment.setPos(new Vector(0, in.next().y));
        fr.box = fr.fragment.doLayout();
    }
    return new Box(mergerBox.getWidth() + SIZE, mergerBox.getHeight());
}
Also used : Vector(de.neemann.digital.draw.graphics.Vector)

Example 5 with Vector

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

Aggregations

Vector (de.neemann.digital.draw.graphics.Vector)63 Wire (de.neemann.digital.draw.elements.Wire)13 Polygon (de.neemann.digital.draw.graphics.Polygon)12 VisualElement (de.neemann.digital.draw.elements.VisualElement)9 Style (de.neemann.digital.draw.graphics.Style)8 Circuit (de.neemann.digital.draw.elements.Circuit)6 Pin (de.neemann.digital.draw.elements.Pin)3 Pins (de.neemann.digital.draw.elements.Pins)3 ArrayList (java.util.ArrayList)3 Rotation (de.neemann.digital.core.element.Rotation)2 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)2 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)2 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)2 IOException (java.io.IOException)2 NodeException (de.neemann.digital.core.NodeException)1 ObservableValue (de.neemann.digital.core.ObservableValue)1 Movable (de.neemann.digital.draw.elements.Movable)1 GraphicMinMax (de.neemann.digital.draw.graphics.GraphicMinMax)1 Orientation (de.neemann.digital.draw.graphics.Orientation)1 Transform (de.neemann.digital.draw.graphics.Transform)1