Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
335 Kevin 1
#include "Gate_BUFFER.h"
2
 
3
Gate_BUFFER::Gate_BUFFER(int gateID, gType type, int numInputs, int gateLevel)
4
    : Gate_BASE(gateID, type, numInputs, gateLevel)
5
{
6
    // Override base gate to limit to one I/O point only
7
    this->xSize = BASE_GATE_SIZE_X;
8
    this->ySize = BASE_GATE_SIZE_Y + ADDITONAL_INPUTS;
9
 
10
    QPointF point = QPointF(0, this->ySize / 2);
11
    this->inputPoints[0] = point;
12
    QPointF scenePoint = QPointF(this->scenePos().x(), this->scenePos().y() + this->ySize / 2);
13
    this->gateInputPoints[0] = scenePoint;
14
 
15
    outputPoint = QPointF(this->xSize, this->ySize / 2);
16
    gateOutputPoint = QPointF(this->scenePos().x() + this->xSize, this->scenePos().y() + this->ySize / 2);
17
 
18
    textRect = QRectF(BORDER_OFFSET, BORDER_OFFSET, xSize - BORDER_OFFSET * 3, ySize - BORDER_OFFSET * 2);
19
}
20
 
21
void Gate_BUFFER::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
22
{
23
    Q_UNUSED(widget);
24
    Q_UNUSED(option);
25
 
26
#ifdef _DEBUG
27
    painter->save();
28
    painter->setPen((auxSelected) ? debugSelectedPen : debugPen);
29
    painter->setBrush(debugBrush);
30
    painter->drawRect(0, 0, xSize, ySize);
31
    painter->drawRect(textRect);
32
    if (numInputs != 1) {
33
        painter->setPen(debugErrorPen);
34
        painter->drawLine(0, 0, xSize, ySize);
35
        painter->drawLine(xSize, 0, 0, ySize);
36
    }
37
    painter->restore();
38
#endif
39
 
40
    if (auxSelected) painter->setPen(highlightedPen);
41
    else painter->setPen(defaultPen);
42
    painter->setBrush(defaultBrush);
43
 
44
    // Draw circles indicating I/O points
45
    painter->drawEllipse(inputPoints[0], INPUT_CIRCLE_SIZE, INPUT_CIRCLE_SIZE);
46
    painter->drawEllipse(outputPoint, INPUT_CIRCLE_SIZE, INPUT_CIRCLE_SIZE);
47
 
48
    // Draw gate outline
49
    QPointF points[3] = {
50
        QPointF(BORDER_OFFSET, BORDER_OFFSET),
51
        QPointF(xSize - BORDER_OFFSET, ySize / 2),
52
        QPointF(BORDER_OFFSET, ySize - BORDER_OFFSET)
53
    };
54
    painter->drawPolygon(points, 3);
55
 
56
    // Draw I/O lines
57
    painter->drawLine(inputPoints[0], QPointF(inputPoints[0].x() + BORDER_OFFSET, inputPoints[0].y()));
58
    painter->drawLine(outputPoint, QPointF(outputPoint.x() - BORDER_OFFSET, outputPoint.y()));
59
 
60
    // Draw text showing gate ID
61
    painter->setPen(defaultPen);
62
    painter->setFont(defaultFont);
63
    painter->drawText(textRect, Qt::AlignCenter, QString::number(gateID));
64
 
65
    // If enqueued, draw circle around gate ID
66
    if (enqueued) {
67
        painter->drawEllipse(textRect.center(), ENQUEUED_CIRCLE_WIDTH, ENQUEUED_CIRCLE_WIDTH);
68
    }
69
}
70
 
71
void Gate_BUFFER::simulateToOutput()
72
{
73
    // Save initial values to compare to later
74
    logicValue initValue = outputValue;
75
    logicValue initFaultyValue = outputFaultyValue;
76
 
77
    // Compute new output values
78
    outputValue = inputValues[0];
79
    outputFaultyValue = inputFaultyValues[0];
80
 
81
    // If outputs have changed, queue the connected gate for simulation
82
    if (outputValue != initValue || outputFaultyValue != initFaultyValue)
83
        emit enqueueSim(this);
84
 
85
    // Update connected wire values
86
    for (int i = 0; i < gateOutputWires.size(); i++) {
87
        gateOutputWires[i]->setValue(outputValue, outputFaultyValue, false);
88
    }
89
}