Search in sources :

Example 1 with Entry

use of com.cburch.logisim.analyze.model.Entry in project logisim-evolution by reds-heig.

the class KarnaughMapPanel method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    TruthTable table = model.getTruthTable();
    int row = getRow(event);
    int col = getOutputColumn(event);
    Entry entry = table.getOutputEntry(row, col);
    return entry.getErrorMessage();
}
Also used : Entry(com.cburch.logisim.analyze.model.Entry) TruthTable(com.cburch.logisim.analyze.model.TruthTable)

Example 2 with Entry

use of com.cburch.logisim.analyze.model.Entry in project logisim-evolution by reds-heig.

the class TableTab method paintComponent.

@Override
public void paintComponent(Graphics g) {
    /* Anti-aliasing changes from https://github.com/hausen/logisim-evolution */
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    super.paintComponent(g);
    caret.paintBackground(g);
    Dimension sz = getSize();
    int top = Math.max(0, (sz.height - tableHeight) / 2);
    int left = Math.max(0, (sz.width - tableWidth) / 2);
    int inputs = table.getInputColumnCount();
    int outputs = table.getOutputColumnCount();
    if (inputs == 0 && outputs == 0) {
        g.setFont(HeaderFont);
        GraphicsUtil.drawCenteredText(g, Strings.get("tableEmptyMessage"), sz.width / 2, sz.height / 2);
        return;
    }
    g.setColor(Color.GRAY);
    int lineX = left + (cellWidth + ColSeperate) * inputs - ColSeperate / 2;
    if (inputs == 0)
        lineX = left + cellWidth + ColSeperate / 2;
    int lineY = top + cellHeight + HeadSeperate / 2;
    g.drawLine(left, lineY, left + tableWidth, lineY);
    g.drawLine(left, lineY - 1, left + tableWidth, lineY - 1);
    g.drawLine(left, lineY + 1, left + tableWidth, lineY + 1);
    g.drawLine(lineX, top, lineX, top + tableHeight);
    g.drawLine(lineX - 1, top, lineX - 1, top + tableHeight);
    g.setColor(Color.BLACK);
    g.setFont(HeaderFont);
    FontMetrics headerMetric = g.getFontMetrics();
    int x = left;
    int y = top + headerMetric.getAscent() + 1;
    if (inputs == 0) {
        x = paintHeader(Strings.get("tableNullHeader"), x, y, g, headerMetric);
    } else {
        for (int i = 0; i < inputs; i++) {
            x = paintHeader(table.getInputHeader(i), x, y, g, headerMetric);
        }
    }
    if (outputs == 0) {
        x = paintHeader(Strings.get("tableNullHeader"), x, y, g, headerMetric);
    } else {
        for (int i = 0; i < outputs; i++) {
            x = paintHeader(table.getOutputHeader(i), x, y, g, headerMetric);
        }
    }
    g.setColor(Color.BLUE);
    g.setFont(EntryFont);
    FontMetrics bodyMetric = g.getFontMetrics();
    y = top + cellHeight + HeadSeperate;
    Rectangle clip = g.getClipBounds();
    int firstRow = Math.max(0, (clip.y - y) / cellHeight);
    int lastRow = Math.min(table.getRowCount(), 2 + (clip.y + clip.height - y) / cellHeight);
    y += firstRow * cellHeight;
    if (inputs == 0)
        left += cellWidth + ColSeperate;
    boolean provisional = false;
    for (int i = firstRow; i < lastRow; i++) {
        x = left;
        for (int j = 0; j < inputs + outputs; j++) {
            Entry entry = j < inputs ? table.getInputEntry(i, j) : table.getOutputEntry(i, j - inputs);
            if (provisionalValue != null && i == provisionalY && j - inputs == provisionalX) {
                provisional = true;
                entry = provisionalValue;
            }
            if (entry.isError()) {
                g.setColor(ERROR_COLOR);
                g.fillRect(x, y, cellWidth, cellHeight);
                g.setColor(Color.BLUE);
            }
            String label = entry.getDescription();
            int width = bodyMetric.stringWidth(label);
            if (provisional) {
                provisional = false;
                g.setColor(Color.ORANGE);
                g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
                g.setColor(Color.BLUE);
            } else {
                g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
            }
            x += cellWidth + ColSeperate;
        }
        y += cellHeight;
    }
    caret.paintForeground(g);
}
Also used : Entry(com.cburch.logisim.analyze.model.Entry) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 3 with Entry

use of com.cburch.logisim.analyze.model.Entry in project logisim-evolution by reds-heig.

the class Analyze method computeTable.

// 
// ComputeTable
// 
/**
 * Returns a truth table corresponding to the circuit.
 */
public static void computeTable(AnalyzerModel model, Project proj, Circuit circuit, Map<Instance, String> pinLabels) {
    ArrayList<Instance> inputPins = new ArrayList<Instance>();
    ArrayList<String> inputNames = new ArrayList<String>();
    ArrayList<Instance> outputPins = new ArrayList<Instance>();
    ArrayList<String> outputNames = new ArrayList<String>();
    for (Map.Entry<Instance, String> entry : pinLabels.entrySet()) {
        Instance pin = entry.getKey();
        if (Pin.FACTORY.isInputPin(pin)) {
            inputPins.add(pin);
            inputNames.add(entry.getValue());
        } else {
            outputPins.add(pin);
            outputNames.add(entry.getValue());
        }
    }
    int inputCount = inputPins.size();
    int rowCount = 1 << inputCount;
    Entry[][] columns = new Entry[outputPins.size()][rowCount];
    for (int i = 0; i < rowCount; i++) {
        CircuitState circuitState = new CircuitState(proj, circuit);
        for (int j = 0; j < inputCount; j++) {
            Instance pin = inputPins.get(j);
            InstanceState pinState = circuitState.getInstanceState(pin);
            boolean value = TruthTable.isInputSet(i, j, inputCount);
            Pin.FACTORY.setValue(pinState, value ? Value.TRUE : Value.FALSE);
        }
        Propagator prop = circuitState.getPropagator();
        prop.propagate();
        if (prop.isOscillating()) {
            for (int j = 0; j < columns.length; j++) {
                columns[j][i] = Entry.OSCILLATE_ERROR;
            }
        } else {
            for (int j = 0; j < columns.length; j++) {
                Instance pin = outputPins.get(j);
                InstanceState pinState = circuitState.getInstanceState(pin);
                Entry out;
                Value outValue = Pin.FACTORY.getValue(pinState).get(0);
                if (outValue == Value.TRUE)
                    out = Entry.ONE;
                else if (outValue == Value.FALSE)
                    out = Entry.ZERO;
                else if (outValue == Value.ERROR)
                    out = Entry.BUS_ERROR;
                else
                    out = Entry.DONT_CARE;
                columns[j][i] = out;
            }
        }
    }
    model.setVariables(inputNames, outputNames);
    for (int i = 0; i < columns.length; i++) {
        model.getTruthTable().setOutputColumn(i, columns[i]);
    }
}
Also used : Instance(com.cburch.logisim.instance.Instance) ArrayList(java.util.ArrayList) Entry(com.cburch.logisim.analyze.model.Entry) InstanceState(com.cburch.logisim.instance.InstanceState) Value(com.cburch.logisim.data.Value) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 4 with Entry

use of com.cburch.logisim.analyze.model.Entry in project logisim-evolution by reds-heig.

the class KarnaughMapPanel method paintComponent.

@Override
public void paintComponent(Graphics g) {
    /* Anti-aliasing changes from https://github.com/hausen/logisim-evolution */
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    super.paintComponent(g);
    TruthTable table = model.getTruthTable();
    int inputCount = table.getInputColumnCount();
    Dimension sz = getSize();
    String message = null;
    if (output == null) {
        message = Strings.get("karnaughNoOutputError");
    } else if (inputCount > MAX_VARS) {
        message = Strings.get("karnaughTooManyInputsError");
    }
    if (message != null) {
        g.setFont(HeaderFont);
        GraphicsUtil.drawCenteredText(g, message, sz.width / 2, sz.height / 2);
        return;
    }
    int left = computeMargin(sz.width, tableWidth);
    int top = computeMargin(sz.height, tableHeight);
    int x = left;
    int y = top;
    int rowVars = ROW_VARS[inputCount];
    int colVars = COL_VARS[inputCount];
    int rows = 1 << rowVars;
    int cols = 1 << colVars;
    g.setFont(HeaderFont);
    FontMetrics headFm = g.getFontMetrics(HeaderFont);
    for (int i = 0; i < inputCount; i++) {
        String header = model.getInputs().get(i);
        Boolean rotated = false;
        int middleOffset = (headFm.stringWidth(header) >> 1);
        int xoffset = headHeight + 11;
        int yoffset = headHeight + 11;
        switch(i) {
            case 0:
                if (inputCount == 1) {
                    rotated = false;
                    xoffset += cellWidth + cellWidth / 2;
                    yoffset = headFm.getAscent();
                } else {
                    rotated = true;
                    yoffset += (rows - 1) * cellHeight;
                    if (inputCount < 4)
                        yoffset += cellHeight / 2;
                    xoffset = headFm.getAscent();
                }
                break;
            case 1:
                if (inputCount == 2) {
                    rotated = false;
                    xoffset += cellWidth + cellWidth / 2;
                    yoffset = headFm.getAscent();
                } else if (inputCount == 3) {
                    rotated = false;
                    xoffset += 3 * cellWidth;
                    yoffset = headFm.getAscent();
                } else {
                    rotated = true;
                    xoffset += 4 * cellWidth + 11 + headFm.getAscent();
                    yoffset += 2 * cellHeight;
                    if (inputCount > 4) {
                        xoffset += 4 * cellWidth;
                    }
                }
                break;
            case 2:
                rotated = false;
                if (inputCount == 3) {
                    xoffset += 2 * cellWidth;
                    yoffset += 11 + 2 * cellHeight + headFm.getAscent();
                } else if (inputCount == 4) {
                    xoffset += 3 * cellWidth;
                    yoffset = headFm.getAscent();
                } else {
                    xoffset += 6 * cellWidth;
                    yoffset += 11 + 4 * cellHeight + headFm.getAscent();
                }
                break;
            case 3:
                rotated = false;
                if (inputCount == 4) {
                    xoffset += 2 * cellWidth;
                    yoffset += 11 + 4 * cellHeight + headFm.getAscent();
                } else {
                    xoffset += 4 * cellWidth;
                    yoffset = headFm.getAscent();
                }
                break;
            case 4:
                rotated = false;
                xoffset += 2 * cellWidth;
                yoffset += 11 + 4 * cellHeight + headFm.getAscent() + headHeight;
                break;
            default:
                break;
        }
        if (g instanceof Graphics2D) {
            Graphics2D g2 = (Graphics2D) g.create();
            if (rotated) {
                g2.translate(xoffset + x, yoffset + y);
                g2.rotate(-Math.PI / 2.0);
                g2.drawString(header, -middleOffset, 0);
            } else
                g2.drawString(header, xoffset + x - middleOffset, yoffset + y);
            if (i == 4)
                g2.drawString(header, 4 * cellWidth + xoffset + x - middleOffset, yoffset + y);
        }
    }
    x += headHeight;
    y += headHeight;
    g.setFont(EntryFont);
    FontMetrics fm = g.getFontMetrics();
    int dy = (cellHeight + fm.getAscent()) / 2;
    x += 11;
    y += 11;
    /* Here the 0/1 labels are placed */
    switch(cols) {
        case 2:
            g.drawLine(x + cellWidth, y - 8, x + 2 * cellWidth, y - 8);
            g.drawLine(x + cellWidth, y - 9, x + 2 * cellWidth, y - 9);
            break;
        case 4:
            g.drawLine(x + 2 * cellWidth, y - 8, x + 4 * cellWidth, y - 8);
            g.drawLine(x + 2 * cellWidth, y - 9, x + 4 * cellWidth, y - 9);
            g.drawLine(x + cellWidth, y + 8 + rows * cellHeight, x + 3 * cellWidth, y + 8 + rows * cellHeight);
            g.drawLine(x + cellWidth, y + 9 + rows * cellHeight, x + 3 * cellWidth, y + 9 + rows * cellHeight);
            break;
        case 8:
            g.drawLine(x + cellWidth, y + 8 + rows * cellHeight + headHeight, x + 3 * cellWidth, y + 8 + rows * cellHeight + headHeight);
            g.drawLine(x + cellWidth, y + 9 + rows * cellHeight + headHeight, x + 3 * cellWidth, y + 9 + rows * cellHeight + headHeight);
            g.drawLine(x + 5 * cellWidth, y + 8 + rows * cellHeight + headHeight, x + 7 * cellWidth, y + 8 + rows * cellHeight + headHeight);
            g.drawLine(x + 5 * cellWidth, y + 9 + rows * cellHeight + headHeight, x + 7 * cellWidth, y + 9 + rows * cellHeight + headHeight);
            g.drawLine(x + 2 * cellWidth, y - 8, x + 6 * cellWidth, y - 8);
            g.drawLine(x + 2 * cellWidth, y - 9, x + 6 * cellWidth, y - 9);
            g.drawLine(x + 4 * cellWidth, y + 8 + rows * cellHeight, x + 8 * cellWidth, y + 8 + rows * cellHeight);
            g.drawLine(x + 4 * cellWidth, y + 9 + rows * cellHeight, x + 8 * cellWidth, y + 9 + rows * cellHeight);
            break;
    }
    switch(rows) {
        case 2:
            g.drawLine(x - 8, y + cellHeight, x - 8, y + 2 * cellHeight);
            g.drawLine(x - 9, y + cellHeight, x - 9, y + 2 * cellHeight);
            break;
        case 4:
            g.drawLine(x - 8, y + 2 * cellHeight, x - 8, y + 4 * cellHeight);
            g.drawLine(x - 9, y + 2 * cellHeight, x - 9, y + 4 * cellHeight);
            g.drawLine(x + cols * cellWidth + 8, y + cellHeight, x + cols * cellWidth + 8, y + 3 * cellHeight);
            g.drawLine(x + cols * cellWidth + 9, y + cellHeight, x + cols * cellWidth + 9, y + 3 * cellHeight);
            break;
    }
    int outputColumn = table.getOutputIndex(output);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            int row = getTableRow(i, j, rows, cols);
            Entry entry = table.getOutputEntry(row, outputColumn);
            if (provisionalValue != null && row == provisionalY && outputColumn == provisionalX)
                entry = provisionalValue;
            if (entry.isError()) {
                g.setColor(ERROR_COLOR);
                g.fillRect(x + j * cellWidth, y + i * cellHeight, cellWidth, cellHeight);
                g.setColor(Color.BLACK);
            }
            g.drawRect(x + j * cellWidth, y + i * cellHeight, cellWidth, cellHeight);
            g.drawRect(x + j * cellWidth + 1, y + i * cellHeight + 1, cellWidth - 2, cellHeight - 2);
        }
    }
    g.drawRect(x, y, cols * cellWidth, rows * cellHeight);
    g.drawRect(x - 1, y - 1, cols * cellWidth + 2, rows * cellHeight + 2);
    List<Implicant> implicants = model.getOutputExpressions().getMinimalImplicants(output);
    if (implicants != null) {
        int index = 0;
        for (Implicant imp : implicants) {
            g.setColor(IMP_COLORS[index % IMP_COLORS.length]);
            paintImplicant(g, imp, x, y, rows, cols);
            index++;
        }
    }
    if (outputColumn < 0)
        return;
    g.setColor(Color.BLUE);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            int row = getTableRow(i, j, rows, cols);
            if (provisionalValue != null && row == provisionalY && outputColumn == provisionalX) {
                String text = provisionalValue.getDescription();
                g.setColor(Color.ORANGE);
                g.drawString(text, x + j * cellWidth + (cellWidth - fm.stringWidth(text)) / 2, y + i * cellHeight + dy);
                g.setColor(Color.BLUE);
            } else {
                Entry entry = table.getOutputEntry(row, outputColumn);
                String text = entry.getDescription();
                g.drawString(text, x + j * cellWidth + (cellWidth - fm.stringWidth(text)) / 2, y + i * cellHeight + dy);
            }
        }
    }
}
Also used : Entry(com.cburch.logisim.analyze.model.Entry) Implicant(com.cburch.logisim.analyze.model.Implicant) FontMetrics(java.awt.FontMetrics) TruthTable(com.cburch.logisim.analyze.model.TruthTable) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 5 with Entry

use of com.cburch.logisim.analyze.model.Entry in project logisim-evolution by reds-heig.

the class TableTab method getToolTipText.

@Override
public String getToolTipText(MouseEvent event) {
    int row = getRow(event);
    int col = getOutputColumn(event);
    Entry entry = table.getOutputEntry(row, col);
    return entry.getErrorMessage();
}
Also used : Entry(com.cburch.logisim.analyze.model.Entry)

Aggregations

Entry (com.cburch.logisim.analyze.model.Entry)6 TruthTable (com.cburch.logisim.analyze.model.TruthTable)3 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 Graphics2D (java.awt.Graphics2D)2 Implicant (com.cburch.logisim.analyze.model.Implicant)1 Value (com.cburch.logisim.data.Value)1 Instance (com.cburch.logisim.instance.Instance)1 InstanceState (com.cburch.logisim.instance.InstanceState)1 Rectangle (java.awt.Rectangle)1 Clipboard (java.awt.datatransfer.Clipboard)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 StringTokenizer (java.util.StringTokenizer)1 TreeMap (java.util.TreeMap)1