diff --git a/openhantek/src/exporter.cpp b/openhantek/src/exporting/exporter.cpp index a8a5d75..6d1fcd0 100644 --- a/openhantek/src/exporter.cpp +++ b/openhantek/src/exporting/exporter.cpp @@ -17,31 +17,34 @@ #include "exporter.h" -#include "analyse/dataanalyzerresult.h" -#include "glgenerator.h" +#include "controlspecification.h" +#include "post/graphgenerator.h" +#include "post/ppresult.h" #include "settings.h" -#include "viewconstants.h" #include "utils/dsoStrings.h" #include "utils/printutils.h" +#include "viewconstants.h" #define tr(msg) QCoreApplication::translate("Exporter", msg) -Exporter::Exporter(DsoSettings *settings, const QString &filename, ExportFormat format) - : settings(settings), filename(filename), format(format) {} +Exporter::Exporter(const Dso::ControlSpecification *deviceSpecification, DsoSettings *settings, const QString &filename, + ExportFormat format) + : deviceSpecification(deviceSpecification), settings(settings), filename(filename), format(format) {} -Exporter *Exporter::createPrintExporter(DsoSettings *settings) { +Exporter *Exporter::createPrintExporter(const Dso::ControlSpecification *deviceSpecification, DsoSettings *settings) { std::unique_ptr printer = printPaintDevice(settings); // Show the printing dialog QPrintDialog dialog(printer.get()); dialog.setWindowTitle(tr("Print oscillograph")); if (dialog.exec() != QDialog::Accepted) { return nullptr; } - Exporter *exporter = new Exporter(settings, QString(), EXPORT_FORMAT_PRINTER); + Exporter *exporter = new Exporter(deviceSpecification, settings, QString(), EXPORT_FORMAT_PRINTER); exporter->selectedPrinter = std::move(printer); return exporter; } -Exporter *Exporter::createSaveToFileExporter(DsoSettings *settings) { +Exporter *Exporter::createSaveToFileExporter(const Dso::ControlSpecification *deviceSpecification, + DsoSettings *settings) { QStringList filters; filters << tr("Portable Document Format (*.pdf)") << tr("Image (*.png *.xpm *.jpg)") << tr("Comma-Separated Values (*.csv)"); @@ -51,7 +54,7 @@ Exporter *Exporter::createSaveToFileExporter(DsoSettings *settings) { fileDialog.setAcceptMode(QFileDialog::AcceptSave); if (fileDialog.exec() != QDialog::Accepted) return nullptr; - return new Exporter(settings, fileDialog.selectedFiles().first(), + return new Exporter(deviceSpecification, settings, fileDialog.selectedFiles().first(), (ExportFormat)(EXPORT_FORMAT_PDF + filters.indexOf(fileDialog.selectedNameFilter()))); } @@ -63,7 +66,7 @@ std::unique_ptr Exporter::printPaintDevice(DsoSettings *settings) { return printer; } -bool Exporter::exportSamples(const DataAnalyzerResult *result) { +bool Exporter::exportSamples(const PPresult *result) { if (this->format == EXPORT_FORMAT_CSV) { return exportCSV(result); } // Choose the color values we need @@ -77,7 +80,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) { if (this->format == EXPORT_FORMAT_IMAGE) { // We need a QPixmap for image-export - QPixmap *qPixmap = new QPixmap(settings->options.imageSize); + QPixmap *qPixmap = new QPixmap(settings->exporting.imageSize); qPixmap->fill(colorValues->background); paintDevice = std::unique_ptr(qPixmap); } else if (this->format == EXPORT_FORMAT_PRINTER) { @@ -146,9 +149,10 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) { painter.setPen(colorValues->voltage[channel]); painter.drawText(QRectF(0, top, lineHeight * 4, lineHeight), settings->scope.voltage[channel].name); // Print coupling/math mode - if ((unsigned int)channel < settings->deviceSpecification->channels) - painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight), - Dso::couplingString(settings->scope.coupling(channel, settings->deviceSpecification))); + if ((unsigned int)channel < deviceSpecification->channels) + painter.drawText( + QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight), + Dso::couplingString(settings->scope.coupling(channel, deviceSpecification))); else painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight), Dso::mathModeString(settings->scope.voltage[channel].math)); @@ -169,7 +173,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) { // Amplitude string representation (4 significant digits) painter.setPen(colorValues->text); painter.drawText(QRectF(lineHeight * 6 + stretchBase * 4, top, stretchBase * 3, lineHeight), - valueToString(result->data(channel)->amplitude, UNIT_VOLTS, 4), + valueToString(result->data(channel)->computeAmplitude(), UNIT_VOLTS, 4), QTextOption(Qt::AlignRight)); // Frequency string representation (5 significant digits) painter.drawText(QRectF(lineHeight * 6 + stretchBase * 7, top, stretchBase * 3, lineHeight), @@ -329,7 +333,7 @@ bool Exporter::exportSamples(const DataAnalyzerResult *result) { return true; } -bool Exporter::exportCSV(const DataAnalyzerResult *result) { +bool Exporter::exportCSV(const PPresult *result) { QFile csvFile(this->filename); if (!csvFile.open(QIODevice::WriteOnly | QIODevice::Text)) return false; diff --git a/openhantek/src/exporter.h b/openhantek/src/exporting/exporter.h index 63fd0aa..154ee4b 100644 --- a/openhantek/src/exporter.h +++ b/openhantek/src/exporting/exporter.h @@ -6,34 +6,30 @@ #include #include #include +#include "exportsettings.h" class DsoSettings; -class DataAnalyzerResult; +class PPresult; struct DsoSettingsColorValues; +namespace Dso { struct ControlSpecification; } -//////////////////////////////////////////////////////////////////////////////// -/// \enum ExportFormat exporter.h -/// \brief Possible file formats for the export. -enum ExportFormat { EXPORT_FORMAT_PRINTER, EXPORT_FORMAT_PDF, EXPORT_FORMAT_IMAGE, EXPORT_FORMAT_CSV }; - -//////////////////////////////////////////////////////////////////////////////// -/// \class Exporter exporter.h /// \brief Exports the oscilloscope screen to a file or prints it. class Exporter { public: - static Exporter *createPrintExporter(DsoSettings *settings); - static Exporter *createSaveToFileExporter(DsoSettings *settings); + static Exporter *createPrintExporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings); + static Exporter *createSaveToFileExporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings); /// \brief Print the document (May be a file too) - bool exportSamples(const DataAnalyzerResult *result); + bool exportSamples(const PPresult *result); private: - Exporter(DsoSettings *settings, const QString &filename, ExportFormat format); + Exporter(const Dso::ControlSpecification* deviceSpecification, DsoSettings *settings, const QString &filename, ExportFormat format); void setFormat(ExportFormat format); - bool exportCSV(const DataAnalyzerResult *result); + bool exportCSV(const PPresult *result); static std::unique_ptr printPaintDevice(DsoSettings *settings); void drawGrids(QPainter &painter, DsoSettingsColorValues *colorValues, double lineHeight, double scopeHeight, int scopeWidth); + const Dso::ControlSpecification* deviceSpecification; DsoSettings *settings; std::unique_ptr selectedPrinter; diff --git a/openhantek/src/exporting/exportsettings.h b/openhantek/src/exporting/exportsettings.h new file mode 100644 index 0000000..586bc35 --- /dev/null +++ b/openhantek/src/exporting/exportsettings.h @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#pragma once + +#include + +/// \brief Holds the general options of the program. +struct DsoSettingsExport { + QSize imageSize = QSize(640, 480); ///< Size of exported images in pixels +}; + +/// \brief Possible file formats for the export. +enum ExportFormat { EXPORT_FORMAT_PRINTER, EXPORT_FORMAT_PDF, EXPORT_FORMAT_IMAGE, EXPORT_FORMAT_CSV }; diff --git a/openhantek/src/scopesettings.h b/openhantek/src/scopesettings.h index b26a431..00e844a 100644 --- a/openhantek/src/scopesettings.h +++ b/openhantek/src/scopesettings.h @@ -4,10 +4,10 @@ #include -#include "analyse/enums.h" #include "hantekdso/controlspecification.h" #include "hantekdso/enums.h" #include "hantekprotocol/definitions.h" +#include "post/enums.h" #include #define MARKER_COUNT 2 ///< Number of markers @@ -21,9 +21,9 @@ struct DsoSettingsScopeHorizontal { unsigned int recordLength = 0; ///< Sample count - ///TODO Use ControlSettingsSamplerateTarget - double timebase = 1e-3; ///< Timebase in s/div - double samplerate = 1e6; ///< The samplerate of the oscilloscope in S + /// TODO Use ControlSettingsSamplerateTarget + double timebase = 1e-3; ///< Timebase in s/div + double samplerate = 1e6; ///< The samplerate of the oscilloscope in S enum SamplerateSource { Samplerrate, Duration } samplerateSource = Samplerrate; }; @@ -31,12 +31,12 @@ struct DsoSettingsScopeHorizontal { /// TODO Use ControlSettingsTrigger struct DsoSettingsScopeTrigger { Dso::TriggerMode mode = Dso::TriggerMode::HARDWARE_SOFTWARE; ///< Automatic, normal or single trigger - double position = 0.0; ///< Horizontal position for pretrigger - Dso::Slope slope = Dso::Slope::Positive; ///< Rising or falling edge causes trigger - unsigned int source = 0; ///< Channel that is used as trigger source - bool special = false; ///< true if the trigger source is not a standard channel - unsigned swTriggerThreshold = 7; ///< Software trigger, threshold - unsigned swTriggerSampleSet = 11; ///< Software trigger, sample set + double position = 0.0; ///< Horizontal position for pretrigger + Dso::Slope slope = Dso::Slope::Positive; ///< Rising or falling edge causes trigger + unsigned int source = 0; ///< Channel that is used as trigger source + bool special = false; ///< true if the trigger source is not a standard channel + unsigned swTriggerThreshold = 7; ///< Software trigger, threshold + unsigned swTriggerSampleSet = 11; ///< Software trigger, sample set }; /// \brief Holds the settings for the spectrum analysis. @@ -51,17 +51,17 @@ struct DsoSettingsScopeSpectrum { /// \brief Holds the settings for the normal voltage graphs. /// TODO Use ControlSettingsVoltage struct DsoSettingsScopeVoltage { + double offset = 0.0; ///< Vertical offset in divs + double trigger = 0.0; ///< Trigger level in V unsigned gainStepIndex = 6; ///< The vertical resolution in V/div (default = 1.0) - bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis) union { ///< Different enums, coupling for real- and mode for math-channels Dso::MathMode math; unsigned couplingIndex = 0; int rawValue; }; - QString name; ///< Name of this channel - double offset = 0.0; ///< Vertical offset in divs - double trigger = 0.0; ///< Trigger level in V - bool used = false; ///< true if this channel is enabled + QString name; ///< Name of this channel + bool inverted = false; ///< true if the channel is inverted (mirrored on cross-axis) + bool used = false; ///< true if this channel is enabled }; /// \brief Holds the settings for the oscilloscope. @@ -82,4 +82,6 @@ struct DsoSettingsScope { Dso::Coupling coupling(ChannelID channel, const Dso::ControlSpecification *deviceSpecification) { return deviceSpecification->couplings[voltage[channel].couplingIndex]; } + // Channels, including math channels + unsigned countChannels() { return (unsigned)voltage.size(); } }; diff --git a/openhantek/src/settings.cpp b/openhantek/src/settings.cpp index 1361189..bb8fc99 100644 --- a/openhantek/src/settings.cpp +++ b/openhantek/src/settings.cpp @@ -11,9 +11,7 @@ /// \brief Set the number of channels. /// \param channels The new channel count, that will be applied to lists. -DsoSettings::DsoSettings(const Dso::ControlSpecification* deviceSpecification) - : deviceSpecification(deviceSpecification) { - +DsoSettings::DsoSettings(const Dso::ControlSpecification* deviceSpecification) { // Add new channels to the list while (scope.spectrum.size() < deviceSpecification->channels) { // Spectrum @@ -63,10 +61,11 @@ bool DsoSettings::setFilename(const QString &filename) { void DsoSettings::load() { // General options store->beginGroup("options"); - if (store->contains("alwaysSave")) options.alwaysSave = store->value("alwaysSave").toBool(); - if (store->contains("imageSize")) options.imageSize = store->value("imageSize").toSize(); - // If the window/* keys were found in this group, remove them from settings - store->remove("window"); + if (store->contains("alwaysSave")) alwaysSave = store->value("alwaysSave").toBool(); + store->endGroup(); + + store->beginGroup("exporting"); + if (store->contains("imageSize")) exporting.imageSize = store->value("imageSize").toSize(); store->endGroup(); // Oscilloscope settings @@ -170,8 +169,11 @@ void DsoSettings::load() { void DsoSettings::save() { // Main window layout and other general options store->beginGroup("options"); - store->setValue("alwaysSave", options.alwaysSave); - store->setValue("imageSize", options.imageSize); + store->setValue("alwaysSave", alwaysSave); + store->endGroup(); + + store->beginGroup("exporting"); + store->setValue("imageSize", exporting.imageSize); store->endGroup(); // Oszilloskope settings diff --git a/openhantek/src/settings.h b/openhantek/src/settings.h index b6f8801..ff1cbeb 100644 --- a/openhantek/src/settings.h +++ b/openhantek/src/settings.h @@ -9,31 +9,20 @@ #include "scopesettings.h" #include "viewsettings.h" +#include "exporting/exportsettings.h" #include "hantekdso/controlspecification.h" #include "hantekdso/controlsettings.h" -//////////////////////////////////////////////////////////////////////////////// -/// \struct DsoSettingsOptions -/// \brief Holds the general options of the program. -struct DsoSettingsOptions { - bool alwaysSave = true; ///< Always save the settings on exit - QSize imageSize = QSize(640, 480); ///< Size of exported images in pixels -}; - -//////////////////////////////////////////////////////////////////////////////// -/// \class DsoSettings /// \brief Holds the settings of the program. class DsoSettings { public: explicit DsoSettings(const Dso::ControlSpecification* deviceSpecification); bool setFilename(const QString &filename); - DsoSettingsOptions options; ///< General options of the program + DsoSettingsExport exporting; ///< General options of the program DsoSettingsScope scope; ///< All oscilloscope related settings DsoSettingsView view; ///< All view related settings - - // Read only access to device settings and device specification - const Dso::ControlSpecification* deviceSpecification; + bool alwaysSave = true; ///< Always save the settings on exit QByteArray mainWindowGeometry; ///< Geometry of the main window QByteArray mainWindowState; ///< State of docking windows and toolbars