Search in sources :

Example 1 with GraphicsImage

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

the class TestCaseDescription method testData.

/**
 * Runs a 4 bit counter build from JK flip flops 16 ticks.
 * The 4 output signals are recoded in a DataSet.
 *
 * @throws Exception
 */
public void testData() throws Exception {
    ToBreakRunner toBreakRunner = new ToBreakRunner("dig/data.dig").runToBreak(29);
    // check recorded data
    ValueTable dataSet = toBreakRunner.getModel().getObserver(ValueTableObserver.class).getLogData();
    assertEquals(29, dataSet.getRows());
    int i = 0;
    for (Value[] ds : dataSet) {
        // clock
        assertEquals((~i) & 1, ds[0].getValue());
        int s = i / 2 + 1;
        // q_0
        assertEquals(s & 1, ds[1].getValue());
        // q_1
        assertEquals((s >> 1) & 1, ds[2].getValue());
        // q_2
        assertEquals((s >> 2) & 1, ds[3].getValue());
        // q_3
        assertEquals((s >> 3) & 1, ds[4].getValue());
        i++;
    }
    // try to write data to graphics instance
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Export(toBreakRunner.getCircuit(), (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
    assertTrue(baos.size() > 15000);
    // export data to CSV
    StringWriter w = new StringWriter();
    dataSet.saveCSV(new BufferedWriter(w));
    assertEquals("\"step\",\"C\",\"q_0n\",\"q_1n\",\"q_2n\",\"q_3n\"\n" + "\"0\",\"1\",\"1\",\"0\",\"0\",\"0\"\n" + "\"1\",\"0\",\"1\",\"0\",\"0\",\"0\"\n" + "\"2\",\"1\",\"0\",\"1\",\"0\",\"0\"\n" + "\"3\",\"0\",\"0\",\"1\",\"0\",\"0\"\n" + "\"4\",\"1\",\"1\",\"1\",\"0\",\"0\"\n" + "\"5\",\"0\",\"1\",\"1\",\"0\",\"0\"\n" + "\"6\",\"1\",\"0\",\"0\",\"1\",\"0\"\n" + "\"7\",\"0\",\"0\",\"0\",\"1\",\"0\"\n" + "\"8\",\"1\",\"1\",\"0\",\"1\",\"0\"\n" + "\"9\",\"0\",\"1\",\"0\",\"1\",\"0\"\n" + "\"10\",\"1\",\"0\",\"1\",\"1\",\"0\"\n" + "\"11\",\"0\",\"0\",\"1\",\"1\",\"0\"\n" + "\"12\",\"1\",\"1\",\"1\",\"1\",\"0\"\n" + "\"13\",\"0\",\"1\",\"1\",\"1\",\"0\"\n" + "\"14\",\"1\",\"0\",\"0\",\"0\",\"1\"\n" + "\"15\",\"0\",\"0\",\"0\",\"0\",\"1\"\n" + "\"16\",\"1\",\"1\",\"0\",\"0\",\"1\"\n" + "\"17\",\"0\",\"1\",\"0\",\"0\",\"1\"\n" + "\"18\",\"1\",\"0\",\"1\",\"0\",\"1\"\n" + "\"19\",\"0\",\"0\",\"1\",\"0\",\"1\"\n" + "\"20\",\"1\",\"1\",\"1\",\"0\",\"1\"\n" + "\"21\",\"0\",\"1\",\"1\",\"0\",\"1\"\n" + "\"22\",\"1\",\"0\",\"0\",\"1\",\"1\"\n" + "\"23\",\"0\",\"0\",\"0\",\"1\",\"1\"\n" + "\"24\",\"1\",\"1\",\"0\",\"1\",\"1\"\n" + "\"25\",\"0\",\"1\",\"0\",\"1\",\"1\"\n" + "\"26\",\"1\",\"0\",\"1\",\"1\",\"1\"\n" + "\"27\",\"0\",\"0\",\"1\",\"1\",\"1\"\n" + "\"28\",\"1\",\"1\",\"1\",\"1\",\"1\"\n", w.toString());
}
Also used : Value(de.neemann.digital.data.Value) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) TestCase(junit.framework.TestCase) Export(de.neemann.digital.draw.graphics.Export) ValueTable(de.neemann.digital.data.ValueTable) ValueTableObserver(de.neemann.digital.gui.components.data.ValueTableObserver) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) StringWriter(java.io.StringWriter) ValueTable(de.neemann.digital.data.ValueTable) Value(de.neemann.digital.data.Value) Export(de.neemann.digital.draw.graphics.Export) ValueTableObserver(de.neemann.digital.gui.components.data.ValueTableObserver) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedWriter(java.io.BufferedWriter)

Example 2 with GraphicsImage

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

the class TestShapes method useShapes.

private void useShapes(boolean ieee) throws Exception {
    File filename = new File(Resources.getRoot(), "dig/shapes.dig");
    ElementLibrary library = new ElementLibrary();
    library.setRootFilePath(new File(Resources.getRoot(), "dig"));
    ShapeFactory shapeFactory = new ShapeFactory(library, ieee);
    Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
    // try to write circuit to graphics instance
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Export(circuit, (out) -> new GraphicsImage(out, "PNG", 1)).export(baos);
    assertTrue(baos.size() > 30000);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) TestCase(junit.framework.TestCase) Export(de.neemann.digital.draw.graphics.Export) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) File(java.io.File) Circuit(de.neemann.digital.draw.elements.Circuit) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) Export(de.neemann.digital.draw.graphics.Export) Circuit(de.neemann.digital.draw.elements.Circuit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File)

Example 3 with GraphicsImage

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

the class GifExporter method createBufferedImage.

private BufferedImage createBufferedImage() throws IOException {
    GraphicsImage gri = new GraphicsImage(null, "gif", 1);
    gri.setBoundingBox(minMax.getMin(), minMax.getMax());
    BufferedImage bi = gri.getBufferedImage();
    Graphics gr = bi.getGraphics();
    gr.setColor(Color.WHITE);
    gr.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    GraphicLineCollector glc = new GraphicLineCollector();
    circuit.drawTo(glc);
    glc.drawTo(gri);
    circuit.drawTo(new GraphicSkipLines(gri));
    return gri.getBufferedImage();
}
Also used : GraphicsImage(de.neemann.digital.draw.graphics.GraphicsImage) GraphicLineCollector(de.neemann.digital.draw.graphics.linemerger.GraphicLineCollector) GraphicSkipLines(de.neemann.digital.draw.graphics.linemerger.GraphicSkipLines) BufferedImage(java.awt.image.BufferedImage)

Aggregations

GraphicsImage (de.neemann.digital.draw.graphics.GraphicsImage)3 Export (de.neemann.digital.draw.graphics.Export)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 TestCase (junit.framework.TestCase)2 Value (de.neemann.digital.data.Value)1 ValueTable (de.neemann.digital.data.ValueTable)1 Circuit (de.neemann.digital.draw.elements.Circuit)1 GraphicLineCollector (de.neemann.digital.draw.graphics.linemerger.GraphicLineCollector)1 GraphicSkipLines (de.neemann.digital.draw.graphics.linemerger.GraphicSkipLines)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)1 ValueTableObserver (de.neemann.digital.gui.components.data.ValueTableObserver)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1