Initial commit for drawing
MODIFY
RISC-V-sim.pro
RISC-V-sim.pro
@@ -29,7 +29,10 @@ SOURCES += src/main.cpp \
src/addressdialog.cpp \
src/codeeditor.cpp \
src/asmhighlighter.cpp \
- src/tabbar.cpp
+ src/tabbar.cpp \
+ src/graphics/shape.cpp \
+ src/graphics/connection.cpp \
+ src/graphics/pipelinewidget.cpp
HEADERS += \
src/parser.h \
@@ -55,7 +58,10 @@ HEADERS += \
src/addressdialog.h \
src/codeeditor.h \
src/asmhighlighter.h \
- src/tabbar.h
+ src/tabbar.h \
+ src/graphics/shape.h \
+ src/graphics/connection.h \
+ src/graphics/pipelinewidget.h
FORMS += \
src/mainwindow.ui \

ADD
src/graphics/connection.cpp
+#include "connection.h"
+
+namespace Graphics {
+
+Connection::Connection(Shape* source, Shape* dest) : m_source(source), m_dest(dest)
+{
+
+}
+
+QRectF Connection::boundingRect() const {
+ return QRectF();
+}
+
+void Connection::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
+
+}
+
+} // namespace Graphics

ADD
src/graphics/connection.h
+#ifndef CONNECTION_H
+#define CONNECTION_H
+
+#include <QGraphicsItem>
+
+namespace Graphics {
+class Shape;
+
+enum class ValueDrawPos { Source, Middle, Destination };
+
+/*
+ Class for drawing connections and signal values between shapes in the
+ pipeline view.
+*/
+class Connection : public QGraphicsItem {
+
+public:
+ Connection(Shape *source, Shape *dest);
+ void setValueDrawPos(ValueDrawPos pos) { m_valuePos = pos, update(); }
+
+ void setValue(int value) { m_value = value; }
+ void showValue(bool state) {
+ m_showValue = state;
+ update();
+ }
+ Shape *getSource() const { return m_source; }
+ Shape *getDest() const { return m_dest; }
+
+protected:
+ QRectF boundingRect() const override;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget) override;
+
+private:
+ Shape *m_source;
+ Shape *m_dest;
+
+ // Variables related to the current value of the connection (signal value)
+ bool m_showValue = false;
+ int m_value;
+ ValueDrawPos m_valuePos = ValueDrawPos::Source;
+
+ QPointF m_sourcePoint;
+ QPointF m_destPoint;
+};
+
+} // namespace Graphics
+
+#endif // CONNECTION_H

ADD
src/graphics/pipelinewidget.cpp
+#include "pipelinewidget.h"
+#include "shape.h"
+
+PipelineWidget::PipelineWidget(QWidget *parent) : QGraphicsView(parent) {
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->setSceneRect(rect());
+ scene->setItemIndexMethod(QGraphicsScene::NoIndex);
+ setScene(scene);
+ setCacheMode(CacheBackground);
+ setRenderHint(QPainter::Antialiasing);
+ scale(qreal(0.8), qreal(0.8));
+
+ // Create pipeline objects
+ Graphics::Shape *instr_mem = new Graphics::Shape();
+ Graphics::Shape *registers = new Graphics::Shape();
+ Graphics::Shape *data_mem = new Graphics::Shape();
+
+ // Add pipeline objects to graphics scene
+ scene->addItem(instr_mem);
+ scene->addItem(registers);
+ scene->addItem(data_mem);
+
+ // Set item positions
+ instr_mem->setPos(50, 0);
+}

ADD
src/graphics/pipelinewidget.h
+#ifndef PIPELINEWIDGET_H
+#define PIPELINEWIDGET_H
+
+#include <QGraphicsView>
+
+class PipelineWidget : public QGraphicsView {
+ Q_OBJECT
+public:
+ PipelineWidget(QWidget *parent = nullptr);
+};
+
+#endif // PIPELINEWIDGET_H

ADD
src/graphics/shape.cpp
+#include "shape.h"
+
+namespace Graphics {
+
+Shape::Shape() {}
+
+} // namespace Graphics

ADD
src/graphics/shape.h
+#ifndef SHAPE_H
+#define SHAPE_H
+
+#include <QBrush>
+#include <QGraphicsItem>
+#include <QPen>
+
+namespace Graphics {
+
+class Shape : public QGraphicsItem {
+ Q_OBJECT
+public:
+ Shape();
+
+private:
+ QSize m_size; // height, width
+
+ QString m_name;
+ QList<QPair<QPoint, QString>> m_inputPoints;
+ QList<QPair<QPoint, QString>> m_outputPoints;
+
+ QPen m_pen;
+ QBrush m_brush;
+};
+
+class Rectangle : public Shape {
+
+protected:
+ // void paintEvent(QPaintEvent *event);
+};
+
+class ALU : public Shape {};
+}
+
+#endif // SHAPE_H

Initial commit for drawing