Search in sources :

Example 11 with ElementLibrary

use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.

the class TestResultTest method getModel.

private Model getModel(String func) throws IOException, ParseException, BuilderException, PinException, NodeException, ElementNotFoundException {
    ArrayList<Expression> exp = new Parser(func).parse();
    ElementLibrary library = new ElementLibrary();
    CircuitBuilder cb = new CircuitBuilder(new ShapeFactory(library));
    cb.addCombinatorial("Y", exp.get(0));
    Circuit circ = cb.createCircuit();
    Model model = new ModelCreator(circ, library).createModel(false);
    model.init();
    return model;
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) Expression(de.neemann.digital.analyse.expression.Expression) Model(de.neemann.digital.core.Model) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Circuit(de.neemann.digital.draw.elements.Circuit) ModelCreator(de.neemann.digital.draw.model.ModelCreator) Parser(de.neemann.digital.analyse.parser.Parser) CircuitBuilder(de.neemann.digital.builder.circuit.CircuitBuilder)

Example 12 with ElementLibrary

use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.

the class ElementHelpDialog method writeFullHTMLDocumentation.

/**
 * Creates a full HTML documentation of all elements
 *
 * @param library      the library which parts are documented
 * @param imageHandler the imageHandler creates the url to get the image representing a concrete part
 * @throws IOException   IOException
 * @throws PinException  PinException
 * @throws NodeException NodeException
 */
private static void writeFullHTMLDocumentation(Writer w, ElementLibrary library, ImageHandler imageHandler) throws IOException, NodeException, PinException {
    ArrayList<String> chapter = new ArrayList<>();
    String actPath = null;
    StringWriter content = new StringWriter();
    int chapNum = 0;
    for (ElementLibrary.ElementContainer e : library) {
        String p = e.getTreePath();
        if (!p.equals(actPath)) {
            actPath = p;
            chapter.add(actPath);
            chapNum++;
            content.append("<h2>").append(Integer.toString(chapNum)).append(". <a name=\"").append(actPath).append("\">").append(actPath).append("</a></h2>\n");
            content.append("<hr/>\n");
        }
        String url = imageHandler.getUrl(e.getDescription());
        BufferedImage bi = MyURLStreamHandlerFactory.getImage(e.getDescription().getName());
        content.append("<center><img src=\"").append(url).append("\" width=\"").append(Integer.toString(bi.getWidth() / IMAGE_SCALE)).append("\" height=\"").append(Integer.toString(bi.getHeight() / IMAGE_SCALE)).append("\"/></center>\n");
        writeHTMLDescription(content, e.getDescription(), new ElementAttributes());
        content.append("<hr/>\n");
    }
    content.flush();
    w.append("<h1>").append(Lang.get("digital")).append("</h1>\n");
    w.append("<h2>").append(Lang.get("tableOfContent")).append("</h2>\n");
    chapNum = 0;
    for (String chap : chapter) {
        chapNum++;
        w.append(Integer.toString(chapNum)).append(". <a href=\"#").append(chap).append("\">").append(chap).append("</a><br/>\n");
    }
    w.write(content.toString());
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage)

Example 13 with ElementLibrary

use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.

the class CircuitBuilderTest method testBuilderSequentialJK.

public void testBuilderSequentialJK() throws Exception {
    Variable y0 = new Variable("Y_0");
    Variable y1 = new Variable("Y_1");
    // counter
    Expression y0s = not(y0);
    Expression y1s = or(not(y0), not(y1));
    ElementLibrary library = new ElementLibrary();
    Circuit circuit = new CircuitBuilder(new ShapeFactory(library), true).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, 1);
    te.checkC(0, 0);
    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)

Example 14 with ElementLibrary

use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.

the class CircuitTest method test64Bit.

public void test64Bit() throws IOException {
    Circuit c = createCircuit();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    c.save(baos);
    // check ROM
    c = Circuit.loadCircuit(new ByteArrayInputStream(baos.toByteArray()), new ShapeFactory(new ElementLibrary()));
    VisualElement rom = c.getElements().get(0);
    DataField d = rom.getElementAttributes().get(Keys.DATA);
    assertEquals(0xffff0000ffff0000L, d.getDataWord(0));
    assertEquals(0x8fff0000ffff0000L, d.getDataWord(1));
    // check input
    VisualElement in = c.getElements().get(1);
    assertEquals(0x8fff0000ffff0000L, in.getElementAttributes().get(Keys.INPUT_DEFAULT).getValue());
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) DataField(de.neemann.digital.core.memory.DataField) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory)

Example 15 with ElementLibrary

use of de.neemann.digital.draw.library.ElementLibrary in project Digital by hneemann.

the class FragmentVisualElementTest method testBox.

public void testBox() throws Exception {
    ShapeFactory shapeFactory = new ShapeFactory(new ElementLibrary());
    FragmentVisualElement ve = new FragmentVisualElement(FlipflopJK.DESCRIPTION, shapeFactory);
    ve.setPos(new Vector(0, 0));
    Box box = ve.doLayout();
    assertEquals(SIZE * 3, box.getHeight());
    assertEquals(SIZE * 3, box.getWidth());
}
Also used : ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Vector(de.neemann.digital.draw.graphics.Vector)

Aggregations

ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)15 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)11 Circuit (de.neemann.digital.draw.elements.Circuit)7 ModelCreator (de.neemann.digital.draw.model.ModelCreator)6 TestExecuter (de.neemann.digital.TestExecuter)5 Expression (de.neemann.digital.analyse.expression.Expression)5 Variable (de.neemann.digital.analyse.expression.Variable)4 File (java.io.File)3 Model (de.neemann.digital.core.Model)2 Vector (de.neemann.digital.draw.graphics.Vector)2 Parser (de.neemann.digital.analyse.parser.Parser)1 CircuitBuilder (de.neemann.digital.builder.circuit.CircuitBuilder)1 Node (de.neemann.digital.core.Node)1 DataField (de.neemann.digital.core.memory.DataField)1 VisualElement (de.neemann.digital.draw.elements.VisualElement)1 Export (de.neemann.digital.draw.graphics.Export)1 GraphicsImage (de.neemann.digital.draw.graphics.GraphicsImage)1 LibraryNode (de.neemann.digital.draw.library.LibraryNode)1 ModelEntry (de.neemann.digital.draw.model.ModelEntry)1 BufferedImage (java.awt.image.BufferedImage)1