Skip to content

Commit

Permalink
feat: add dot, frequency, and digraph plot display plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
hello-adam committed Apr 20, 2020
1 parent 33cc7d4 commit 272d692
Show file tree
Hide file tree
Showing 39 changed files with 1,585 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/hobbits-core/bitarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ static char INVERSE_BIT_MASKS[8] = {
0x7f, -65, -33, -17, -9, -5, -3, -2
};

static quint64 QUINT64_BIT_MASKS[64] = {
0x8000000000000000, 0x4000000000000000, 0x2000000000000000, 0x1000000000000000,
0x0800000000000000, 0x0400000000000000, 0x0200000000000000, 0x0100000000000000,
0x0080000000000000, 0x0040000000000000, 0x0020000000000000, 0x0010000000000000,
0x0008000000000000, 0x0004000000000000, 0x0002000000000000, 0x0001000000000000,
0x0000800000000000, 0x0000400000000000, 0x0000200000000000, 0x0000100000000000,
0x0000080000000000, 0x0000040000000000, 0x0000020000000000, 0x0000010000000000,
0x0000008000000000, 0x0000004000000000, 0x0000002000000000, 0x0000001000000000,
0x0000000800000000, 0x0000000400000000, 0x0000000200000000, 0x0000000100000000,
0x0000000080000000, 0x0000000040000000, 0x0000000020000000, 0x0000000010000000,
0x0000000008000000, 0x0000000004000000, 0x0000000002000000, 0x0000000001000000,
0x0000000000800000, 0x0000000000400000, 0x0000000000200000, 0x0000000000100000,
0x0000000000080000, 0x0000000000040000, 0x0000000000020000, 0x0000000000010000,
0x0000000000008000, 0x0000000000004000, 0x0000000000002000, 0x0000000000001000,
0x0000000000000800, 0x0000000000000400, 0x0000000000000200, 0x0000000000000100,
0x0000000000000080, 0x0000000000000040, 0x0000000000000020, 0x0000000000000010,
0x0000000000000008, 0x0000000000000004, 0x0000000000000002, 0x0000000000000001
};

#define CACHE_CHUNK_BYTE_SIZE (10 * 1000 * 1000)
#define CACHE_CHUNK_BIT_SIZE (CACHE_CHUNK_BYTE_SIZE * 8)
#define MAX_ACTIVE_CACHE_CHUNKS 5
Expand Down Expand Up @@ -155,6 +174,18 @@ bool BitArray::at(qint64 i) const
return m_dataCaches[cacheIdx][index / 8] & BIT_MASKS[index % 8];
}


quint64 BitArray::getWordValue(qint64 bitOffset, int wordBitSize) const
{
quint64 word = 0;
for (qint64 i = 0; i < wordBitSize; i++) {
if (this->at(bitOffset + i)) {
word += 1 << (wordBitSize - i - 1);
}
}
return word;
}

bool BitArray::loadCacheAt(qint64 i) const
{
qint64 cacheIdx = i / CACHE_CHUNK_BIT_SIZE;
Expand Down
1 change: 1 addition & 0 deletions src/hobbits-core/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HOBBITSCORESHARED_EXPORT BitArray
bool at(qint64 i) const;
qint64 sizeInBits() const;
qint64 sizeInBytes() const;
quint64 getWordValue(qint64 bitOffset, int wordBitSize) const;

void resize(qint64 sizeInBits);

Expand Down
1 change: 1 addition & 0 deletions src/hobbits-gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QCoreApplication::setOrganizationName("Mahlet");
QCoreApplication::setApplicationName("hobbits");
QCoreApplication::setApplicationVersion(HobbitsGuiInfo::getGuiVersion());

Expand Down
51 changes: 51 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/FrequencyPlot.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#-------------------------------------------------
#
# Project created by QtCreator 2020-04-20T23:19:44.928Z
#
#-------------------------------------------------

QT += widgets

QT -= gui

TARGET = FrequencyPlot
TEMPLATE = lib

DEFINES += FREQUENCYPLOT_LIBRARY

CONFIG += c++11 plugin
CONFIG -= debug_and_release_target

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += frequencyplot.cpp frequencyplotwidget.cpp frequencyplotcontrols.cpp

HEADERS += frequencyplot.h frequencyplotwidget.h frequencyplotcontrols.h

FORMS += frequencyplotcontrols.ui

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../hobbits-core/release/ -lhobbits-core
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../hobbits-core/debug/ -lhobbits-core
else:unix: LIBS += -L$$OUT_PWD/../../../hobbits-core/ -lhobbits-core

INCLUDEPATH += $$PWD/../../../hobbits-core
DEPENDPATH += $$PWD/../../../hobbits-core

unix:{
QMAKE_LFLAGS_RPATH=
QMAKE_LFLAGS += "-Wl,-rpath,'$$ORIGIN/../../lib:$$ORIGIN'"
}

unix {
target.path = target.path = $$(HOME)/.local/share/hobbits/plugins/displays
INSTALLS += target
}
40 changes: 40 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "frequencyplot.h"

FrequencyPlot::FrequencyPlot() :
m_displayWidget(nullptr),
m_controlsWidget(nullptr)
{

}

DisplayInterface* FrequencyPlot::createDefaultDisplay()
{
return new FrequencyPlot();
}

QString FrequencyPlot::getName()
{
return "FrequencyPlot";
}

QWidget* FrequencyPlot::getDisplayWidget(QSharedPointer<DisplayHandle> displayHandle)
{
initialize(displayHandle);
return m_displayWidget;
}

QWidget* FrequencyPlot::getControlsWidget(QSharedPointer<DisplayHandle> displayHandle)
{
initialize(displayHandle);
return m_controlsWidget;
}

void FrequencyPlot::initialize(QSharedPointer<DisplayHandle> displayHandle)
{
if (!m_displayWidget) {
m_displayWidget = new FrequencyPlotWidget(displayHandle, this);
m_controlsWidget = new FrequencyPlotControls();

// make necessary connections here
}
}
30 changes: 30 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef FREQUENCYPLOT_H
#define FREQUENCYPLOT_H

#include "displayinterface.h"
#include "frequencyplotcontrols.h"
#include "frequencyplotwidget.h"

class FrequencyPlot : public QObject, DisplayInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "hobbits.DisplayInterface.FrequencyPlot")
Q_INTERFACES(DisplayInterface)

public:
FrequencyPlot();

DisplayInterface* createDefaultDisplay();

QString getName();

QWidget* getDisplayWidget(QSharedPointer<DisplayHandle> displayHandle);
QWidget* getControlsWidget(QSharedPointer<DisplayHandle> displayHandle);

private:
void initialize(QSharedPointer<DisplayHandle> displayHandle);
FrequencyPlotWidget* m_displayWidget;
FrequencyPlotControls* m_controlsWidget;
};

#endif // FREQUENCYPLOT_H
9 changes: 9 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplotcontrols.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "frequencyplotcontrols.h"
#include "ui_frequencyplotcontrols.h"


FrequencyPlotControls::FrequencyPlotControls() :
ui(new Ui::FrequencyPlotControls())
{
ui->setupUi(this);
}
22 changes: 22 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplotcontrols.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef FREQUENCYPLOTCONTROLS_H
#define FREQUENCYPLOTCONTROLS_H

#include <QWidget>

namespace Ui
{
class FrequencyPlotControls;
}

class FrequencyPlotControls : public QWidget
{
Q_OBJECT

public:
FrequencyPlotControls();

private:
Ui::FrequencyPlotControls *ui;
};

#endif // FREQUENCYPLOTCONTROLS_H
21 changes: 21 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplotcontrols.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FrequencyPlotControls</class>
<widget class="QWidget" name="FrequencyPlotControls">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>100</height>
</rect>
</property>

<layout class="QVBoxLayout" name="verticalLayout">

</layout>

</widget>
<resources/>
<connections/>
</ui>
36 changes: 36 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplotwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "frequencyplotwidget.h"

#include <QPainter>
#include <QImage>
#include "displayhelper.h"

FrequencyPlotWidget::FrequencyPlotWidget(
QSharedPointer<DisplayHandle> displayHandle,
DisplayInterface *pluginRef,
QWidget *parent) :
DisplayBase(displayHandle, pluginRef, parent)
{

}

void FrequencyPlotWidget::paintEvent(QPaintEvent*) {
if (m_displayHandle->getContainer().isNull()) {
return;
}

QImage raster = DisplayHelper::getBitRasterImage(
m_displayHandle->getContainer(),
m_displayHandle->getBitOffset(),
m_displayHandle->getFrameOffset(),
this->width(), this->height());

QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, false);
painter.drawImage(0, 0, raster);
}

void FrequencyPlotWidget::mouseMoveEvent(QMouseEvent *event) {
sendHoverUpdate(event, 1, 1, 1, 1, QPoint(0, 0));
}


20 changes: 20 additions & 0 deletions src/hobbits-plugins/FrequencyPlot/frequencyplotwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef FREQUENCYPLOTWIDGET_H
#define FREQUENCYPLOTWIDGET_H

#include "displaybase.h"

class FrequencyPlotWidget : public DisplayBase
{
Q_OBJECT

public:
FrequencyPlotWidget(
QSharedPointer<DisplayHandle> displayHandle,
DisplayInterface *pluginRef,
QWidget *parent = nullptr);

void paintEvent(QPaintEvent*) override;
void mouseMoveEvent(QMouseEvent *event) override;
};

#endif // FREQUENCYPLOTWIDGET_H
51 changes: 51 additions & 0 deletions src/hobbits-plugins/displays/DigraphPlot/DigraphPlot.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#-------------------------------------------------
#
# Project created by QtCreator 2020-04-20T21:04:46.839Z
#
#-------------------------------------------------

QT += widgets

QT -= gui

TARGET = DigraphPlot
TEMPLATE = lib

DEFINES += DIGRAPHPLOT_LIBRARY

CONFIG += c++11 plugin
CONFIG -= debug_and_release_target

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += digraphplot.cpp digraphplotwidget.cpp digraphplotcontrols.cpp

HEADERS += digraphplot.h digraphplotwidget.h digraphplotcontrols.h

FORMS += digraphplotcontrols.ui

win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../hobbits-core/release/ -lhobbits-core
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../hobbits-core/debug/ -lhobbits-core
else:unix: LIBS += -L$$OUT_PWD/../../../hobbits-core/ -lhobbits-core

INCLUDEPATH += $$PWD/../../../hobbits-core
DEPENDPATH += $$PWD/../../../hobbits-core

unix:{
QMAKE_LFLAGS_RPATH=
QMAKE_LFLAGS += "-Wl,-rpath,'$$ORIGIN/../../lib:$$ORIGIN'"
}

unix {
target.path = target.path = $$(HOME)/.local/share/hobbits/plugins/displays
INSTALLS += target
}
Loading

0 comments on commit 272d692

Please sign in to comment.