Search in sources :

Example 6 with Circuit

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

the class NetListTest method testTunnel.

public void testTunnel() 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");
    NetList ns = new NetList(c);
    assertEquals(1, ns.size());
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) Wire(de.neemann.digital.draw.elements.Wire) Vector(de.neemann.digital.draw.graphics.Vector)

Example 7 with Circuit

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

the class ElementLibrary method importElement.

/**
 * Imports the given file
 *
 * @param file the file to load
 * @return the description
 * @throws IOException IOException
 */
ElementTypeDescription importElement(File file) throws IOException {
    try {
        LOGGER.debug("load element " + file);
        Circuit circuit;
        try {
            circuit = Circuit.loadCircuit(file, shapeFactory);
        } catch (FileNotFoundException e) {
            throw new IOException(Lang.get("err_couldNotFindIncludedFile_N0", file));
        }
        ElementTypeDescriptionCustom description = new ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, ElementLibrary.this), circuit);
        description.setShortName(createShortName(file));
        String descriptionText = circuit.getAttributes().get(Keys.DESCRIPTION);
        if (descriptionText != null && descriptionText.length() > 0) {
            description.setDescription(descriptionText);
        }
        return description;
    } catch (PinException e) {
        throw new IOException(Lang.get("msg_errorImportingModel_N0", file), e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Circuit(de.neemann.digital.draw.elements.Circuit) IOException(java.io.IOException) PinException(de.neemann.digital.draw.elements.PinException)

Example 8 with Circuit

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

the class LibraryNode method getToolTipText.

/**
 * @return the tool tip text
 */
public String getToolTipText() {
    if (isCustom()) {
        if (isUnique()) {
            if (description == null) {
                if (toolTipText == null) {
                    try {
                        LOGGER.debug("load tooltip from " + file);
                        Circuit c = Circuit.loadCircuit(file, null);
                        toolTipText = new LineBreaker().toHTML().breakLines(c.getAttributes().get(Keys.DESCRIPTION));
                    } catch (Exception e) {
                        toolTipText = Lang.get("msg_fileNotImportedYet");
                    }
                }
                return toolTipText;
            } else
                return new LineBreaker().toHTML().breakLines(description.getDescription(new ElementAttributes()));
        } else
            return Lang.get("msg_fileIsNotUnique");
    } else
        return new LineBreaker().toHTML().breakLines(Lang.getNull("elem_" + getName() + "_tt"));
}
Also used : Circuit(de.neemann.digital.draw.elements.Circuit) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) LineBreaker(de.neemann.gui.LineBreaker) IOException(java.io.IOException)

Example 9 with Circuit

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

the class CircuitBuilderTest method testBuilderCombinatorial.

public void testBuilderCombinatorial() throws Exception {
    Variable a = new Variable("a");
    Variable b = new Variable("b");
    // xor
    Expression y = and(or(a, b), not(and(a, b)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addCombinatorial("y", y).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0, 0);
    te.check(0, 1, 1);
    te.check(1, 0, 1);
    te.check(1, 1, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Example 10 with Circuit

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

the class CircuitBuilderTest method testBuilderSequential.

public void testBuilderSequential() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(and(not(y0), y1), and(y0, not(y1)));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library)).addSequential("Y_0", y0s).addSequential("Y_1", y1s).createCircuit();
    ModelCreator m = new ModelCreator(circuit, library);
    TestExecuter te = new TestExecuter(m.createModel(false)).setUp(m);
    te.check(0, 0);
    te.checkC(1, 0);
    te.checkC(0, 1);
    te.checkC(1, 1);
    te.checkC(0, 0);
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) TestExecuter(de.neemann.digital.TestExecuter) ModelCreator(de.neemann.digital.draw.model.ModelCreator)

Aggregations

Circuit (de.neemann.digital.draw.elements.Circuit)26 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)9 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)8 Vector (de.neemann.digital.draw.graphics.Vector)7 ModelCreator (de.neemann.digital.draw.model.ModelCreator)7 Expression (de.neemann.digital.analyse.expression.Expression)6 VisualElement (de.neemann.digital.draw.elements.VisualElement)6 File (java.io.File)6 TestExecuter (de.neemann.digital.TestExecuter)5 Wire (de.neemann.digital.draw.elements.Wire)5 Variable (de.neemann.digital.analyse.expression.Variable)4 IOException (java.io.IOException)4 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)3 Main (de.neemann.digital.gui.Main)3 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)2 Model (de.neemann.digital.core.Model)2 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)2 ToBreakRunner (de.neemann.digital.integration.ToBreakRunner)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1