Search in sources :

Example 1 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement 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 VisualElement

use of de.neemann.digital.draw.elements.VisualElement 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 VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class ExportZipAction method addFile.

private void addFile(ZipOutputStream zip, File file, Circuit circuit) throws ElementNotFoundException, IOException {
    addToZip(zip, file);
    for (VisualElement ve : circuit.getElements()) {
        String name = ve.getElementName();
        if (!elementSet.contains(name)) {
            elementSet.add(name);
            ElementTypeDescription desc = lib.getElementType(name);
            if (desc instanceof ElementLibrary.ElementTypeDescriptionCustom) {
                ElementLibrary.ElementTypeDescriptionCustom custom = (ElementLibrary.ElementTypeDescriptionCustom) desc;
                addFile(zip, custom.getFile(), custom.getCircuit());
            }
        }
    }
}
Also used : ElementTypeDescription(de.neemann.digital.core.element.ElementTypeDescription) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) VisualElement(de.neemann.digital.draw.elements.VisualElement)

Example 4 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class InsertAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (node.isUnique()) {
        VisualElement visualElement = new VisualElement(node.getName()).setPos(new Vector(10, 10)).setShapeFactory(shapeFactory);
        if (getIcon() == null) {
            try {
                node.getDescription();
                setIcon(node.getIcon(shapeFactory));
            } catch (IOException ex) {
                SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorImportingModel_N0", node.getName())).addCause(ex));
            }
        }
        if (visualElement.getShape() instanceof MissingShape)
            return;
        circuitComponent.setPartToInsert(visualElement);
        insertHistory.add(this);
    }
}
Also used : VisualElement(de.neemann.digital.draw.elements.VisualElement) IOException(java.io.IOException) ErrorMessage(de.neemann.gui.ErrorMessage) Vector(de.neemann.digital.draw.graphics.Vector) MissingShape(de.neemann.digital.draw.shapes.MissingShape)

Example 5 with VisualElement

use of de.neemann.digital.draw.elements.VisualElement in project Digital by hneemann.

the class ModifySetBits method modify.

@Override
public void modify(Circuit circuit, ElementLibrary library) {
    ArrayList<Movable> list = circuit.getElementsToMove(min, max);
    for (Movable m : list) if (m instanceof VisualElement) {
        VisualElement ve = (VisualElement) m;
        try {
            ElementTypeDescription td = library.getElementType(ve.getElementName());
            if (td != null) {
                if (td.getAttributeList().contains(Keys.BITS))
                    ve.setAttribute(Keys.BITS, bits);
            }
        } catch (ElementNotFoundException e) {
            e.printStackTrace();
        }
    }
    circuit.modified();
}
Also used : ElementTypeDescription(de.neemann.digital.core.element.ElementTypeDescription) Movable(de.neemann.digital.draw.elements.Movable) VisualElement(de.neemann.digital.draw.elements.VisualElement) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException)

Aggregations

VisualElement (de.neemann.digital.draw.elements.VisualElement)25 Vector (de.neemann.digital.draw.graphics.Vector)11 Wire (de.neemann.digital.draw.elements.Wire)8 Circuit (de.neemann.digital.draw.elements.Circuit)7 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)5 ElementTypeDescription (de.neemann.digital.core.element.ElementTypeDescription)4 TestCaseDescription (de.neemann.digital.testing.TestCaseDescription)4 File (java.io.File)4 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)3 Main (de.neemann.digital.gui.Main)3 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)3 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)3 ErrorMessage (de.neemann.gui.ErrorMessage)3 IOException (java.io.IOException)3 Expression (de.neemann.digital.analyse.expression.Expression)2 Signal (de.neemann.digital.core.Signal)2 And (de.neemann.digital.core.basic.And)2 Keys (de.neemann.digital.core.element.Keys)2 External (de.neemann.digital.core.extern.External)2 In (de.neemann.digital.core.io.In)2