Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color SigMF Annotations (v2) #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/inputsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <QJsonObject>
#include <QJsonArray>
#include <QFile>
#include <QColor>


class ComplexF32SampleAdapter : public SampleAdapter {
Expand Down Expand Up @@ -339,10 +340,20 @@ void InputSource::readMetaData(const QString &filename)
auto frequencyRange = range_t<double>{freq_lower_edge, freq_upper_edge};

auto label = sigmf_annotation["core:label"].toString();

auto comment = sigmf_annotation["core:comment"].toString();

annotationList.emplace_back(sampleRange, frequencyRange, label, comment);
auto sigmf_color = sigmf_annotation["presentation:color"].toString();
// SigMF uses the format "#RRGGBBAA" for alpha-channel colors, QT uses "#AARRGGBB"
if ((sigmf_color.at(0) == '#') && (sigmf_color.length()) == 9) {
sigmf_color = "#" + sigmf_color.mid(7,2) + sigmf_color.mid(1,6);
}
auto boxColor = QString::fromStdString("white");
if (QColor::isValidColor(sigmf_color)) {
boxColor = sigmf_color;
}

annotationList.emplace_back(sampleRange, frequencyRange, label, comment, boxColor);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ MainWindow::MainWindow()
connect(dock->annosCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotations);
connect(dock->annosCheckBox, &QCheckBox::stateChanged, dock, &SpectrogramControls::enableAnnotations);
connect(dock->commentsCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnotationCommentsTooltips);
connect(dock->annoColorCheckBox, &QCheckBox::stateChanged, plots, &PlotView::enableAnnoColors);
connect(dock->cursorSymbolsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), plots, &PlotView::setCursorSegments);

// Connect dock outputs
Expand Down
10 changes: 10 additions & 0 deletions src/plotview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ PlotView::PlotView(InputSource *input) : cursors(this), viewRange({0, 0})
enableAnnotations(true);
enableAnnotationCommentsTooltips(true);

enableAnnoColors(true);

addPlot(spectrogramPlot);

mainSampleSource->subscribe(this);
Expand Down Expand Up @@ -654,6 +656,14 @@ void PlotView::enableAnnotationCommentsTooltips(bool enabled)
viewport()->update();
}

void PlotView::enableAnnoColors(bool enabled)
{
if (spectrogramPlot != nullptr)
spectrogramPlot->enableAnnoColors(enabled);

viewport()->update();
}

int PlotView::sampleToColumn(size_t sample)
{
return sample / samplesPerColumn();
Expand Down
1 change: 1 addition & 0 deletions src/plotview.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public slots:
void enableScales(bool enabled);
void enableAnnotations(bool enabled);
void enableAnnotationCommentsTooltips(bool enabled);
void enableAnnoColors(bool enabled);
void invalidateEvent() override;
void repaint();
void setCursorSegments(int segments);
Expand Down
6 changes: 4 additions & 2 deletions src/samplesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "util.h"
#include <QString>
#include <QObject>
#include <QColor>

class Annotation
{
Expand All @@ -34,11 +35,12 @@ class Annotation
range_t<double> frequencyRange;
QString label;
QString comment;
QColor boxColor;

Annotation(range_t<size_t> sampleRange, range_t<double>frequencyRange, QString label,
QString comment)
QString comment, QColor boxColor)
: sampleRange(sampleRange), frequencyRange(frequencyRange), label(label),
comment(comment) {}
comment(comment), boxColor(boxColor) {}
};

template<typename T>
Expand Down
6 changes: 4 additions & 2 deletions src/spectrogramcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent
annosCheckBox = new QCheckBox(widget);
layout->addRow(new QLabel(tr("Display Annotations:")), annosCheckBox);
commentsCheckBox = new QCheckBox(widget);
layout->addRow(new QLabel(tr("Display annotation comments tooltips:")), commentsCheckBox);
layout->addRow(new QLabel(tr("Annotation comments:")), commentsCheckBox);
annoColorCheckBox = new QCheckBox(widget);
layout->addRow(new QLabel(tr("Annotation Colors:")), annoColorCheckBox);

widget->setLayout(layout);
setWidget(widget);
Expand Down Expand Up @@ -136,7 +138,7 @@ void SpectrogramControls::setDefaults()
cursorSymbolsSpinBox->setValue(1);

annosCheckBox->setCheckState(Qt::Checked);
commentsCheckBox->setCheckState(Qt::Checked);
annoColorCheckBox->setCheckState(Qt::Checked);

// Try to set the sample rate from the last-used value
QSettings settings;
Expand Down
1 change: 1 addition & 0 deletions src/spectrogramcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ private slots:
QCheckBox *scalesCheckBox;
QCheckBox *annosCheckBox;
QCheckBox *commentsCheckBox;
QCheckBox *annoColorCheckBox;
};
10 changes: 10 additions & 0 deletions src/spectrogramplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float
sampleRate = 0;
frequencyScaleEnabled = false;
sigmfAnnotationsEnabled = true;
sigmfAnnotationColors = true;

for (int i = 0; i < 256; i++) {
float p = (float)i / 256;
Expand Down Expand Up @@ -194,6 +195,10 @@ void SpectrogramPlot::paintAnnotations(QPainter &painter, QRect &rect, range_t<s
int height = (a.frequencyRange.maximum - a.frequencyRange.minimum) / sampleRate * rect.height();
int width = (a.sampleRange.maximum - a.sampleRange.minimum) / getStride();

if (sigmfAnnotationColors) {
painter.setPen(a.boxColor);
}

// Draw the label 2 pixels above the box
painter.drawText(x, y - 2, a.label);
painter.drawRect(x, y, width, height);
Expand Down Expand Up @@ -417,6 +422,11 @@ bool SpectrogramPlot::isAnnotationsEnabled(void)
return sigmfAnnotationsEnabled;
}

void SpectrogramPlot::enableAnnoColors(bool enabled)
{
sigmfAnnotationColors = enabled;
}

bool SpectrogramPlot::tunerEnabled()
{
return (tunerTransform->subscriberCount() > 0);
Expand Down
2 changes: 2 additions & 0 deletions src/spectrogramplot.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SpectrogramPlot : public Plot
void enableScales(bool enabled);
void enableAnnotations(bool enabled);
bool isAnnotationsEnabled();
void enableAnnoColors(bool enabled);
QString *mouseAnnotationComment(const QMouseEvent *event);

public slots:
Expand Down Expand Up @@ -81,6 +82,7 @@ public slots:
double sampleRate;
bool frequencyScaleEnabled;
bool sigmfAnnotationsEnabled;
bool sigmfAnnotationColors;

Tuner tuner;
std::shared_ptr<TunerTransform> tunerTransform;
Expand Down