Implement ALU drawing
MODIFY
resources/binary-code.svg
resources/binary-code.svg
<?xml version="1.0"?>
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 261.501 261.501" style="enable-background:new 0 0 261.501 261.501;" xml:space="preserve" width="512px" height="512px"><g><g>
- <path d="M37.984,161.696c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-58.627c0-3.034-1.827-5.768-4.63-6.929 c-2.801-1.16-6.028-0.519-8.173,1.626L21.177,116.77c-2.929,2.929-2.929,7.678,0,10.606c2.929,2.929,7.678,2.929,10.606,0 l6.201-6.201V161.696z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M82.279,31.807l6.201-6.201v40.521c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5V7.5c0-3.034-1.827-5.768-4.63-6.929 c-2.801-1.16-6.028-0.519-8.173,1.626L71.673,21.201c-2.929,2.929-2.929,7.678,0,10.606C74.602,34.736,79.351,34.736,82.279,31.807 z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M167.815,96.14c-2.801-1.16-6.028-0.519-8.173,1.626l-19.004,19.004c-2.929,2.929-2.929,7.678,0,10.606 c2.929,2.929,7.678,2.929,10.606,0l6.201-6.201v40.521c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-58.627 C172.445,100.036,170.618,97.301,167.815,96.14z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M135.217,188.445c-2.801-1.16-6.028-0.519-8.173,1.626l-19.004,19.004c-2.929,2.929-2.929,7.678,0,10.606 c2.929,2.929,7.678,2.929,10.606,0l6.201-6.201v22.197c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-40.303 C139.847,192.34,138.02,189.606,135.217,188.445z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M122.504,143.42v-22.074c0-14.213-11.563-25.776-25.776-25.776h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074 c0,14.213,11.563,25.776,25.776,25.776h0.369C110.941,169.196,122.504,157.633,122.504,143.42z M107.504,143.42 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776v-22.074c0-5.942,4.834-10.776,10.776-10.776 h0.369c5.942,0,10.776,4.834,10.776,10.776V143.42z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M216.745,95.569h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776v-22.074C242.521,107.133,230.958,95.569,216.745,95.569z M227.521,143.42 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776v-22.074c0-5.942,4.834-10.776,10.776-10.776 h0.369c5.942,0,10.776,4.834,10.776,10.776V143.42z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M147.224,0h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c4.142,0,7.5-3.358,7.5-7.5s-3.358-7.5-7.5-7.5h-0.369c-5.942,0-10.776-4.834-10.776-10.776V25.776 c0-5.942,4.834-10.776,10.776-10.776h0.369c5.942,0,10.776,4.834,10.776,10.776c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5 C173.001,11.563,161.438,0,147.224,0z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M216.745,0h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776V25.776C242.521,11.563,230.958,0,216.745,0z M227.521,47.851 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776V25.776c0-5.942,4.834-10.776,10.776-10.776h0.369 c5.942,0,10.776,4.834,10.776,10.776V47.851z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
- <path d="M61.682,187.874h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776V213.65C87.459,199.438,75.896,187.874,61.682,187.874z M72.459,235.725 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776V213.65c0-5.942,4.834-10.776,10.776-10.776h0.369 c5.942,0,10.776,4.834,10.776,10.776V235.725z" data-original="#000000" class="active-path" data-old_color="#7F7C7C" fill="#7F7E7E"/>
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Capa_1" x="0px" y="0px" viewBox="0 0 261.501 261.501" style="enable-background:new 0 0 261.501 261.501;" xml:space="preserve" width="512px" height="512px" class=""><g><g>
+ <path d="M37.984,161.696c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-58.627c0-3.034-1.827-5.768-4.63-6.929 c-2.801-1.16-6.028-0.519-8.173,1.626L21.177,116.77c-2.929,2.929-2.929,7.678,0,10.606c2.929,2.929,7.678,2.929,10.606,0 l6.201-6.201V161.696z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M82.279,31.807l6.201-6.201v40.521c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5V7.5c0-3.034-1.827-5.768-4.63-6.929 c-2.801-1.16-6.028-0.519-8.173,1.626L71.673,21.201c-2.929,2.929-2.929,7.678,0,10.606C74.602,34.736,79.351,34.736,82.279,31.807 z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M167.815,96.14c-2.801-1.16-6.028-0.519-8.173,1.626l-19.004,19.004c-2.929,2.929-2.929,7.678,0,10.606 c2.929,2.929,7.678,2.929,10.606,0l6.201-6.201v40.521c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-58.627 C172.445,100.036,170.618,97.301,167.815,96.14z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M135.217,188.445c-2.801-1.16-6.028-0.519-8.173,1.626l-19.004,19.004c-2.929,2.929-2.929,7.678,0,10.606 c2.929,2.929,7.678,2.929,10.606,0l6.201-6.201v22.197c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5v-40.303 C139.847,192.34,138.02,189.606,135.217,188.445z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M122.504,143.42v-22.074c0-14.213-11.563-25.776-25.776-25.776h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074 c0,14.213,11.563,25.776,25.776,25.776h0.369C110.941,169.196,122.504,157.633,122.504,143.42z M107.504,143.42 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776v-22.074c0-5.942,4.834-10.776,10.776-10.776 h0.369c5.942,0,10.776,4.834,10.776,10.776V143.42z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M216.745,95.569h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776v-22.074C242.521,107.133,230.958,95.569,216.745,95.569z M227.521,143.42 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776v-22.074c0-5.942,4.834-10.776,10.776-10.776 h0.369c5.942,0,10.776,4.834,10.776,10.776V143.42z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M147.224,0h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c4.142,0,7.5-3.358,7.5-7.5s-3.358-7.5-7.5-7.5h-0.369c-5.942,0-10.776-4.834-10.776-10.776V25.776 c0-5.942,4.834-10.776,10.776-10.776h0.369c5.942,0,10.776,4.834,10.776,10.776c0,4.142,3.358,7.5,7.5,7.5s7.5-3.358,7.5-7.5 C173.001,11.563,161.438,0,147.224,0z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M216.745,0h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776V25.776C242.521,11.563,230.958,0,216.745,0z M227.521,47.851 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776V25.776c0-5.942,4.834-10.776,10.776-10.776h0.369 c5.942,0,10.776,4.834,10.776,10.776V47.851z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
+ <path d="M61.682,187.874h-0.369c-14.213,0-25.776,11.563-25.776,25.776v22.074c0,14.213,11.563,25.776,25.776,25.776h0.369 c14.213,0,25.776-11.563,25.776-25.776V213.65C87.459,199.438,75.896,187.874,61.682,187.874z M72.459,235.725 c0,5.942-4.834,10.776-10.776,10.776h-0.369c-5.942,0-10.776-4.834-10.776-10.776V213.65c0-5.942,4.834-10.776,10.776-10.776h0.369 c5.942,0,10.776,4.834,10.776,10.776V235.725z" data-original="#000000" class="active-path" data-old_color="#2C2C2C" fill="#2D2D2D"/>
</g></g> </svg>

MODIFY
resources/images.qrc
resources/images.qrc
<file>logo.png</file>
<file>breakpoint_disabled.png</file>
<file>breakpoint_enabled.png</file>
- <file>binary-code.svg</file>
<file>cpu.svg</file>
<file>graph.svg</file>
<file>server.svg</file>
<file>ram-memory.svg</file>
+ <file>binary-code.svg</file>
</qresource>
</RCC>

MODIFY
src/graphics/pipelinewidget.cpp
src/graphics/pipelinewidget.cpp
#include "pipelinewidget.h"
#include "shape.h"
+#include <QWheelEvent>
+
PipelineWidget::PipelineWidget(QWidget* parent) : QGraphicsView(parent) {
QGraphicsScene* scene = new QGraphicsScene(this);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
@@ -42,15 +44,44 @@ PipelineWidget::PipelineWidget(QWidget* parent) : QGraphicsView(parent) {
new Graphics::Shape(Graphics::ShapeType::Block, 30, 3);
pc->setName("PC");
+ // MUX
+ Graphics::Shape* mux1 =
+ new Graphics::Shape(Graphics::ShapeType::MUX, 20, 8);
+ mux1->setName("M\nu\nx");
+
+ // ALU
+ Graphics::Shape* ALU1 =
+ new Graphics::Shape(Graphics::ShapeType::ALU, 70, 30);
+ ALU1->setName("Add");
+ ALU1->addOutput("Sum");
+
// Add pipeline objects to graphics scene
scene->addItem(registers);
scene->addItem(data_mem);
scene->addItem(instr_mem);
scene->addItem(pc);
+ scene->addItem(mux1);
+ scene->addItem(ALU1);
// Set item positions
pc->setPos(-250, -100);
instr_mem->setPos(-200, 0);
registers->setPos(0, 0);
data_mem->setPos(200, 0);
+ mux1->setPos(0, -100);
+ ALU1->setPos(100, 100);
+}
+
+void PipelineWidget::wheelEvent(QWheelEvent* event) {
+ scaleView(pow((double)2, -event->delta() / 240.0));
+}
+
+void PipelineWidget::scaleView(qreal scaleFactor) {
+ qreal factor = transform()
+ .scale(scaleFactor, scaleFactor)
+ .mapRect(QRectF(0, 0, 1, 1))
+ .width();
+ if (factor < 0.07 || factor > 100) return;
+
+ scale(scaleFactor, scaleFactor);
}

MODIFY
src/graphics/pipelinewidget.h
src/graphics/pipelinewidget.h
@@ -7,6 +7,11 @@ class PipelineWidget : public QGraphicsView {
Q_OBJECT
public:
PipelineWidget(QWidget* parent = nullptr);
+
+ void wheelEvent(QWheelEvent* event);
+
+ private:
+ void scaleView(qreal scaleFactor);
};
#endif // PIPELINEWIDGET_H

MODIFY
src/graphics/shape.h
src/graphics/shape.h
#include <QBrush>
#include <QGraphicsItem>
+#include <QPainterPath>
#include <QPen>
namespace Graphics {
@@ -17,13 +18,14 @@ class Shape : public QGraphicsItem {
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget);
void addInput(QString input);
- void addInput(QStringList input) { m_inputs.append(input); }
+ void addInput(QStringList input);
void addOutput(QString output) { m_outputs.append(output); }
void addOutput(QStringList output) { m_outputs.append(output); }
void setName(QString name) { m_name = name; }
private:
QRectF calculateRect() const;
+ QPainterPath drawALUPath(QRectF boundingRect) const;
ShapeType m_type;
QString m_name;
@@ -36,6 +38,9 @@ class Shape : public QGraphicsItem {
QList<QString> m_inputs;
QList<QString> m_outputs;
+ QList<QPointF> m_inputPoints;
+ QList<QPointF> m_outputPoints;
+
// drawing constants
qreal nodeHeight = 20;
qreal nameFontSize = 10;

MODIFY
src/registercontainerwidget.ui
src/registercontainerwidget.ui
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
- <layout class="QVBoxLayout" name="registerLayout"/>
+ <layout class="QVBoxLayout" name="registerLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ </layout>
</item>
</layout>
</widget>

Implement ALU drawing