Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
335 Kevin 1
#ifndef Gate_BASE_H
2
#define Gate_BASE_H
3
 
4
#include "GlobalDefines.h"
5
#include "Wire.h"
6
 
7
#define BASE_GATE_SIZE_X 100
8
#define BASE_GATE_SIZE_Y 80
9
#define ADDITONAL_INPUTS 20
10
#define INPUT_CIRCLE_SIZE qreal(5)
11
#define BORDER_OFFSET 20
12
#define DEFAULT_LINE_WIDTH 3
13
#define ENQUEUED_CIRCLE_WIDTH 20
14
 
15
#define COLOR_MAIN 0,0,0,255
16
#define COLOR_MAIN_SELECTED 200,0,200,255
17
#define COLOR_INPUT COLOR_MAIN
18
#define COLOR_INPUT_SELECTED 255,0,0,255
19
#define COLOR_OUTPUT COLOR_MAIN
20
#define COLOR_OUTPUT_SELECTED 0,0,255,255
21
#define COLOR_DEBUG 0,0,0,100
22
#define COLOR_DEBUG_SELECTED 0,255,0,100
23
#define COLOR_DEBUG_ERROR 255,0,0,200
24
 
25
#define GATE_DEFAULT_Z 0
26
#define WIRE_DEFAULT_Z 1
27
#define SELECTED_Z 2
28
 
29
class Wire;
30
 
31
typedef enum {
32
    gate_UNKNOWN	= 0,
33
    gate_INPUT 		= 1,
34
    gate_OUTPUT  	= 2,
35
    gate_XOR 		= 3,
36
    gate_XNOR 		= 4,
37
    gate_DFF 		= 5,
38
    gate_AND 		= 6,
39
    gate_NAND 		= 7,
40
    gate_OR 		= 8,
41
    gate_NOR 		= 9,
42
    gate_NOT 		= 10,
43
    gate_BUFFER  	= 11
44
} gType;
45
 
46
/* Generic gate object */
47
class Gate_BASE : public QGraphicsObject
48
{
49
        Q_OBJECT
50
    public:
51
        Gate_BASE(int gateID, gType type,
52
                    int numInputs, int gateLevel,
53
                    QGraphicsItem *parent = 0);
54
        ~Gate_BASE();
55
 
56
        QRectF boundingRect() const;
57
        QPainterPath shape() const;
58
 
59
        // paint() should be overwritten by child classes
60
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)=0;
61
 
62
        void setCanvasPosition(int x, int y);
63
        void setHighlight(bool state, QColor color);
64
 
65
        void reset(void);
66
        void setInputValue(int input, logicValue value, logicValue faultyValue);
67
        void setOutputValue(logicValue value, logicValue faultyValue);
68
        void setEnqueued(bool value);
69
 
70
        virtual void simulateToOutput()=0;
71
 
72
        // Variables
73
        int xSize, ySize;
74
        QPoint canvasPoint;
75
 
76
        int gateID;
77
        gType gateType;
78
        int numInputs;
79
        int gateLevel;
80
 
81
        QList<logicValue> inputValues;
82
        QList<logicValue> inputFaultyValues;
83
        logicValue outputValue;
84
        logicValue outputFaultyValue;
85
 
86
        QList<Gate_BASE*> fanInGates;
87
        QList<Gate_BASE*> fanOutGates;
88
        QList<QPointF> gateInputPoints; // Scene inputs
89
        QPointF gateOutputPoint;		// Scene outputs
90
 
91
        QList<Wire*> gateInputWires;
92
        QList<Wire*> gateOutputWires;
93
 
94
    signals:
95
        void updateStatus(QString status);
96
        void enqueueSim(Gate_BASE *gate);
97
 
98
    public slots:
99
 
100
    protected:
101
        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
102
 
103
        bool auxSelected;
104
        bool enqueued;
105
 
106
        // 'Local' points for I/O
107
        QList<QPointF> inputPoints;
108
        QPointF outputPoint;
109
 
110
        QPen defaultPen;
111
        QBrush defaultBrush;
112
        QFont defaultFont;
113
 
114
        QPen selectedPen;
115
        QPen highlightedPen;
116
 
117
        QRectF textRect;
118
 
119
#ifdef _DEBUG
120
        QPen debugPen;
121
        QBrush debugBrush;
122
        QPen debugSelectedPen;
123
        QPen debugErrorPen;
124
#endif
125
};
126
 
127
#endif // Gate_BASE_H