Skip to content

Commit

Permalink
Introduce PostProcessingSettings. Remove utils/dsoStrings and add tra…
Browse files Browse the repository at this point in the history
…nslation methods directly to the location where the relevant enums are declared. Remove union for math-channel/coupling value: Some compilers have issues here.
  • Loading branch information
David Graeff committed Jan 20, 2018
1 parent 9b32a46 commit 1c7190e
Show file tree
Hide file tree
Showing 25 changed files with 316 additions and 346 deletions.
24 changes: 22 additions & 2 deletions openhantek/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,28 @@ and the graphical part.

All OpenGL rendering takes place in the `GlScope` class. A helper class `GlScopeGraph` contains exactly one
data sample snapshot including all channels for voltage and spectrum and a pointer to the respective GPU buffer.
`GlScope` works for OpenGL 3.2 and OpenGL ES 2.0, but this needs to be decided at compile time. Usually Qt
selects the right interface.
`GlScope` works for OpenGL 3.2 and OpenGL ES 2.0. If both is present, OpenGL will be prefered, but can be
overwritten by the user via a command flag.

### Export

All export related funtionality is within *src/exporting*.

The following exporters are implemented:

* Export to comma separated value file (CSV): Write to a user selected file,
* Export to an image/pdf: Writes an image/pdf to a user selected file,
* Print exporter: Creates a printable document and opens the print dialog.

All export classes (exportcsv, exportimage, exportprint) implement the
ExporterInterface and are registered to the ExporterRegistry in the main.cpp.

Some export classes are still using the legacyExportDrawer class to
draw the grid and paint all the labels, values and graphs.

The plan is to retire this legacy class and replace the paint code with
a `GlScope` class shared OpenGL drawing code for at least the grid and the
scope graphs.

## Data flow

Expand Down
12 changes: 6 additions & 6 deletions openhantek/src/configdialog/DsoConfigAnalysisPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par
windowFunctionLabel = new QLabel(tr("Window function"));
windowFunctionComboBox = new QComboBox();
windowFunctionComboBox->addItems(windowFunctionStrings);
windowFunctionComboBox->setCurrentIndex((int)settings->scope.spectrumWindow);
windowFunctionComboBox->setCurrentIndex((int)settings->post.spectrumWindow);

referenceLevelLabel = new QLabel(tr("Reference level"));
referenceLevelSpinBox = new QDoubleSpinBox();
referenceLevelSpinBox->setDecimals(1);
referenceLevelSpinBox->setMinimum(-40.0);
referenceLevelSpinBox->setMaximum(100.0);
referenceLevelSpinBox->setValue(settings->scope.spectrumReference);
referenceLevelSpinBox->setValue(settings->post.spectrumReference);
referenceLevelUnitLabel = new QLabel(tr("dBm"));
referenceLevelLayout = new QHBoxLayout();
referenceLevelLayout->addWidget(referenceLevelSpinBox);
Expand All @@ -33,7 +33,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par
minimumMagnitudeSpinBox->setDecimals(1);
minimumMagnitudeSpinBox->setMinimum(-40.0);
minimumMagnitudeSpinBox->setMaximum(100.0);
minimumMagnitudeSpinBox->setValue(settings->scope.spectrumLimit);
minimumMagnitudeSpinBox->setValue(settings->post.spectrumLimit);
minimumMagnitudeUnitLabel = new QLabel(tr("dBm"));
minimumMagnitudeLayout = new QHBoxLayout();
minimumMagnitudeLayout->addWidget(minimumMagnitudeSpinBox);
Expand All @@ -59,7 +59,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *par

/// \brief Saves the new settings.
void DsoConfigAnalysisPage::saveSettings() {
settings->scope.spectrumWindow = (Dso::WindowFunction)windowFunctionComboBox->currentIndex();
settings->scope.spectrumReference = referenceLevelSpinBox->value();
settings->scope.spectrumLimit = minimumMagnitudeSpinBox->value();
settings->post.spectrumWindow = (Dso::WindowFunction)windowFunctionComboBox->currentIndex();
settings->post.spectrumReference = referenceLevelSpinBox->value();
settings->post.spectrumLimit = minimumMagnitudeSpinBox->value();
}
1 change: 0 additions & 1 deletion openhantek/src/docks/HorizontalDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "scopesettings.h"
#include "sispinbox.h"
#include "utils/dsoStrings.h"
#include "utils/printutils.h"

template<typename... Args> struct SELECT {
Expand Down
1 change: 0 additions & 1 deletion openhantek/src/docks/SpectrumDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "settings.h"
#include "sispinbox.h"
#include "utils/dsoStrings.h"
#include "utils/printutils.h"

template<typename... Args> struct SELECT {
Expand Down
1 change: 0 additions & 1 deletion openhantek/src/docks/TriggerDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "hantekdso/controlspecification.h"
#include "settings.h"
#include "sispinbox.h"
#include "utils/dsoStrings.h"
#include "utils/printutils.h"

TriggerDock::TriggerDock(DsoSettingsScope *scope, const Dso::ControlSpecification *spec, QWidget *parent,
Expand Down
14 changes: 6 additions & 8 deletions openhantek/src/docks/VoltageDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "settings.h"
#include "sispinbox.h"
#include "utils/dsoStrings.h"
#include "utils/printutils.h"

template<typename... Args> struct SELECT {
Expand Down Expand Up @@ -66,9 +65,9 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio
dockLayout->addWidget(b.invertCheckBox, (int)channel * 3 + 2, 1);

if (channel < spec->channels)
setCoupling(channel, scope->voltage[channel].couplingIndex);
setCoupling(channel, scope->voltage[channel].couplingOrMathIndex);
else
setMode(scope->voltage[channel].math);
setMode(scope->voltage[channel].couplingOrMathIndex);
setGain(channel, scope->voltage[channel].gainStepIndex);
setUsed(channel, scope->voltage[channel].used);

Expand All @@ -80,12 +79,11 @@ VoltageDock::VoltageDock(DsoSettingsScope *scope, const Dso::ControlSpecificatio
this->scope->voltage[channel].inverted = checked;
});
connect(b.miscComboBox, SELECT<int>::OVERLOAD_OF(&QComboBox::currentIndexChanged), [this,channel,spec,scope](int index){
this->scope->voltage[channel].couplingOrMathIndex = (unsigned)index;
if (channel < spec->channels) {
this->scope->voltage[channel].couplingIndex = (unsigned)index;
emit couplingChanged(channel, scope->coupling(channel, spec));
} else {
this->scope->voltage[channel].math = (Dso::MathMode) index;
emit modeChanged(this->scope->voltage[channel].math);
emit modeChanged(Dso::getMathMode(this->scope->voltage[channel]));
}
});
connect(b.usedCheckBox, &QAbstractButton::toggled, [this,channel](bool checked) {
Expand Down Expand Up @@ -119,9 +117,9 @@ void VoltageDock::setGain(ChannelID channel, unsigned gainStepIndex) {
channelBlocks[channel].gainComboBox->setCurrentIndex((unsigned)gainStepIndex);
}

void VoltageDock::setMode(Dso::MathMode mode) {
void VoltageDock::setMode(unsigned mathModeIndex) {
QSignalBlocker blocker(channelBlocks[spec->channels].miscComboBox);
channelBlocks[spec->channels].miscComboBox->setCurrentIndex((int)mode);
channelBlocks[spec->channels].miscComboBox->setCurrentIndex((int)mathModeIndex);
}

void VoltageDock::setUsed(ChannelID channel, bool used) {
Expand Down
7 changes: 4 additions & 3 deletions openhantek/src/docks/VoltageDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "scopesettings.h"
#include "hantekdso/controlspecification.h"
#include "post/postprocessingsettings.h"

class SiSpinBox;

Expand All @@ -28,7 +29,7 @@ class VoltageDock : public QDockWidget {

/// \brief Sets the coupling for a channel.
/// \param channel The channel, whose coupling should be set.
/// \param coupling The coupling-mode.
/// \param couplingIndex The coupling-mode index.
void setCoupling(ChannelID channel, unsigned couplingIndex);

/// \brief Sets the gain for a channel.
Expand All @@ -37,8 +38,8 @@ class VoltageDock : public QDockWidget {
void setGain(ChannelID channel, unsigned gainStepIndex);

/// \brief Sets the mode for the math channel.
/// \param mode The math-mode.
void setMode(Dso::MathMode mode);
/// \param mathModeIndex The math-mode index.
void setMode(unsigned mathModeIndex);

/// \brief Enables/disables a channel.
/// \param channel The channel, that should be enabled/disabled.
Expand Down
2 changes: 1 addition & 1 deletion openhantek/src/docks/dockwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <cmath>

#include "post/enums.h"
#include "post/postprocessingsettings.h"
#include "hantekdso/enums.h"
#include "hantekprotocol/types.h"
#include "dockwindows.h"
Expand Down
20 changes: 5 additions & 15 deletions openhantek/src/dsowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#include "dsowidget.h"

#include "post/postprocessingsettings.h"
#include "post/graphgenerator.h"
#include "post/ppresult.h"

#include "utils/dsoStrings.h"
#include "utils/printutils.h"

#include "glscope.h"
Expand Down Expand Up @@ -252,10 +252,6 @@ void DsoWidget::setupSliders(DsoWidget::Sliders &sliders) {
}
}

void DsoWidget::setExporterForNextFrame(std::unique_ptr<Exporter> exporter) {
this->exportNextFrame = std::move(exporter);
}

/// \brief Set the trigger level sliders minimum and maximum to the new values.
void DsoWidget::adaptTriggerLevelSlider(DsoWidget::Sliders &sliders, ChannelID channel) {
sliders.triggerLevelSlider->setLimits((int)channel,
Expand Down Expand Up @@ -422,7 +418,8 @@ void DsoWidget::updateVoltageCoupling(ChannelID channel) {

/// \brief Handles modeChanged signal from the voltage dock.
void DsoWidget::updateMathMode() {
measurementMiscLabel[spec->channels]->setText(Dso::mathModeString(scope->voltage[spec->channels].math));
measurementMiscLabel[spec->channels]->setText(
Dso::mathModeString(Dso::getMathMode(scope->voltage[spec->channels])));
}

/// \brief Handles gainChanged signal from the voltage dock.
Expand Down Expand Up @@ -486,15 +483,8 @@ void DsoWidget::updateZoom(bool enabled) {

/// \brief Prints analyzed data.
void DsoWidget::showNew(std::shared_ptr<PPresult> data) {
if (exportNextFrame) {
exportNextFrame->exportSamples(data.get());
exportNextFrame.reset(nullptr);
}

mainScope->showData(data.get());
mainScope->update();
zoomScope->showData(data.get());
zoomScope->update();
mainScope->showData(data);
zoomScope->showData(data);

if (spec->isSoftwareTriggerDevice) {
QPalette triggerLabelPalette = palette();
Expand Down
3 changes: 0 additions & 3 deletions openhantek/src/dsowidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <QGridLayout>
#include <memory>

#include "exporting/exporter.h"
#include "glscope.h"
#include "levelslider.h"
#include "hantekdso/controlspecification.h"
Expand Down Expand Up @@ -36,7 +35,6 @@ class DsoWidget : public QWidget {
/// \param parent The parent widget.
/// \param flags Flags for the window manager.
DsoWidget(DsoSettingsScope* scope, DsoSettingsView* view, const Dso::ControlSpecification* spec, QWidget *parent = 0, Qt::WindowFlags flags = 0);
void setExporterForNextFrame(std::unique_ptr<Exporter> exporter);

// Data arrived
void showNew(std::shared_ptr<PPresult> data);
Expand Down Expand Up @@ -87,7 +85,6 @@ class DsoWidget : public QWidget {

GlScope *mainScope; ///< The main scope screen
GlScope *zoomScope; ///< The optional magnified scope screen
std::unique_ptr<Exporter> exportNextFrame;

public slots:
// Horizontal axis
Expand Down
89 changes: 89 additions & 0 deletions openhantek/src/hantekdso/enums.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,96 @@
#include "enums.h"
#include <QCoreApplication>

namespace Dso {
Enum<Dso::TriggerMode, Dso::TriggerMode::HARDWARE_SOFTWARE, Dso::TriggerMode::SINGLE> TriggerModeEnum;
Enum<Dso::Slope, Dso::Slope::Positive, Dso::Slope::Negative> SlopeEnum;
Enum<Dso::GraphFormat, Dso::GraphFormat::TY, Dso::GraphFormat::XY> GraphFormatEnum;

/// \brief Return string representation of the given channel mode.
/// \param mode The ::ChannelMode that should be returned as string.
/// \return The string that should be used in labels etc., empty when invalid.
QString channelModeString(ChannelMode mode) {
switch (mode) {
case ChannelMode::Voltage:
return QCoreApplication::tr("Voltage");
case ChannelMode::Spectrum:
return QCoreApplication::tr("Spectrum");
}
return QString();
}

/// \brief Return string representation of the given graph format.
/// \param format The ::GraphFormat that should be returned as string.
/// \return The string that should be used in labels etc.
QString graphFormatString(GraphFormat format) {
switch (format) {
case GraphFormat::TY:
return QCoreApplication::tr("T - Y");
case GraphFormat::XY:
return QCoreApplication::tr("X - Y");
}
return QString();
}

/// \brief Return string representation of the given channel coupling.
/// \param coupling The ::Coupling that should be returned as string.
/// \return The string that should be used in labels etc.
QString couplingString(Coupling coupling) {
switch (coupling) {
case Coupling::AC:
return QCoreApplication::tr("AC");
case Coupling::DC:
return QCoreApplication::tr("DC");
case Coupling::GND:
return QCoreApplication::tr("GND");
}
return QString();
}


/// \brief Return string representation of the given trigger mode.
/// \param mode The ::TriggerMode that should be returned as string.
/// \return The string that should be used in labels etc.
QString triggerModeString(TriggerMode mode) {
switch (mode) {
case TriggerMode::WAIT_FORCE:
return QCoreApplication::tr("Wait/Force");
case TriggerMode::HARDWARE_SOFTWARE:
return QCoreApplication::tr("Hard-/Software");
case TriggerMode::SINGLE:
return QCoreApplication::tr("Single");
}
return QString();
}

/// \brief Return string representation of the given trigger slope.
/// \param slope The ::Slope that should be returned as string.
/// \return The string that should be used in labels etc.
QString slopeString(Slope slope) {
switch (slope) {
case Slope::Positive:
return QString::fromUtf8("\u2197");
case Slope::Negative:
return QString::fromUtf8("\u2198");
default:
return QString();
}
}

/// \brief Return string representation of the given graph interpolation mode.
/// \param interpolation The ::InterpolationMode that should be returned as
/// string.
/// \return The string that should be used in labels etc.
QString interpolationModeString(InterpolationMode interpolation) {
switch (interpolation) {
case INTERPOLATION_OFF:
return QCoreApplication::tr("Off");
case INTERPOLATION_LINEAR:
return QCoreApplication::tr("Linear");
case INTERPOLATION_SINC:
return QCoreApplication::tr("Sinc");
default:
return QString();
}
}
}
8 changes: 8 additions & 0 deletions openhantek/src/hantekdso/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "utils/enumclass.h"
#include <QMetaType>
#include <QString>
namespace Dso {
/// \enum ChannelMode
/// \brief The channel display modes.
Expand Down Expand Up @@ -52,6 +53,13 @@ enum InterpolationMode {
INTERPOLATION_SINC, ///< Smooth graph through the dots
INTERPOLATION_COUNT ///< Total number of interpolation modes
};

QString channelModeString(ChannelMode mode);
QString graphFormatString(GraphFormat format);
QString couplingString(Coupling coupling);
QString triggerModeString(TriggerMode mode);
QString slopeString(Slope slope);
QString interpolationModeString(InterpolationMode interpolation);
}

Q_DECLARE_METATYPE(Dso::TriggerMode)
Expand Down
Loading

0 comments on commit 1c7190e

Please sign in to comment.