Skip to content

Commit

Permalink
more logical marker status display
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <[email protected]>
  • Loading branch information
Ho-Ro committed Nov 12, 2019
1 parent ccdceeb commit ec1196f
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 175 deletions.
2 changes: 1 addition & 1 deletion openhantek/src/OH_BUILD.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Do not edit, will be re-created at each commit!
#define OH_BUILD "20191109 build 547"
#define OH_BUILD "20191112 build 548"
107 changes: 67 additions & 40 deletions openhantek/src/dsowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ DsoWidget::DsoWidget(DsoSettingsScope *scope, DsoSettingsView *view, const Dso::

// The table for the marker details
markerInfoLabel = new QLabel();
markerInfoLabel->setMinimumWidth(160);
markerInfoLabel->setAlignment(Qt::AlignLeft);
markerInfoLabel->setPalette(palette);
markerTimeLabel = new QLabel();
markerTimeLabel->setAlignment(Qt::AlignRight);
Expand Down Expand Up @@ -406,54 +406,32 @@ void DsoWidget::setMeasurementVisible(ChannelID channel) {
if (!scope->spectrum[channel].used) { measurementMagnitudeLabel[channel]->setText(QString()); }
}

static QString markerToString(DsoSettingsScope *scope, unsigned index) {
double value = (DIVS_TIME * (0.5 - scope->trigger.position) + scope->getMarker(index)) * scope->horizontal.timebase;
int precision = 3 - (int)floor(log10(fabs(value)));

if (scope->horizontal.timebase < 1e-9)
return QApplication::tr("%L1 ps").arg(value / 1e-12, 0, 'f', qBound(0, precision - 12, 3));
else if (scope->horizontal.timebase < 1e-6)
return QApplication::tr("%L1 ns").arg(value / 1e-9, 0, 'f', qBound(0, precision - 9, 3));
else if (scope->horizontal.timebase < 1e-3)
return QApplication::tr("%L1 µs").arg(value / 1e-6, 0, 'f', qBound(0, precision - 6, 3));
else if (scope->horizontal.timebase < 1)
return QApplication::tr("%L1 ms").arg(value / 1e-3, 0, 'f', qBound(0, precision - 3, 3));
else
return QApplication::tr("%L1 s").arg(value, 0, 'f', qBound(0, precision, 3));
}

/// \brief Update the label about the marker measurements
void DsoWidget::updateMarkerDetails() {
double divs = fabs(scope->horizontal.cursor.pos[1].x() - scope->horizontal.cursor.pos[0].x());
double div0 = scope->horizontal.cursor.pos[0].x();
double div1 = scope->horizontal.cursor.pos[1].x();
if ( div0 > div1 )
std::swap( div0, div1 );
double divs = div1 - div0;
double time0 = div0 * scope->horizontal.timebase;
double time1 = div1 * scope->horizontal.timebase;
double time = divs * scope->horizontal.timebase;

QString prefix(tr("Markers"));
if (view->zoom) {
if ( divs != 0.0 )
prefix = tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3);
else // avoid div by zero
prefix = tr("Zoom ---");
markerTimebaseLabel->setText(valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"));
markerFrequencybaseLabel->setText(
valueToString(divs * scope->horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 4) + tr("/div"));
}
markerInfoLabel->setText(prefix.append(": %1 %2").arg(markerToString(scope, 0)).arg(markerToString(scope, 1)));
markerTimeLabel->setText(valueToString(time, UNIT_SECONDS, 4));
if ( time != 0.0 )
markerFrequencyLabel->setText(valueToString(1.0 / time, UNIT_HERTZ, 4));
else // avoid div by zero
markerFrequencyLabel->setText( "--- Hz" );
div0 += DIVS_TIME / 2; // zero at center -> zero at left margin
div1 += DIVS_TIME / 2;
double freq0 = div0 * scope->horizontal.frequencybase;
double freq1 = div1 * scope->horizontal.frequencybase;
double freq = divs * scope->horizontal.frequencybase;
bool timeUsed = false;
bool freqUsed = false;

int index = 0;
if ( time != 0.0 )
cursorDataGrid->updateInfo(index++, true, QString(),
valueToString(time, UNIT_SECONDS, 4), valueToString(1.0 / time, UNIT_HERTZ, 4));
else // avoid div by zero
cursorDataGrid->updateInfo(index++, true, QString(),
valueToString(time, UNIT_SECONDS, 4), "--- Hz");
cursorDataGrid->updateInfo(index++, true, QString(),
valueToString(time, UNIT_SECONDS, 3), valueToString( freq, UNIT_HERTZ, 3 ) );

for (ChannelID channel = 0; channel < scope->voltage.size(); ++channel) {
if (scope->voltage[channel].used) {
timeUsed = true; // at least one voltage channel used -> show marker time details
QPointF p0 = scope->voltage[channel].cursor.pos[0];
QPointF p1 = scope->voltage[channel].cursor.pos[1];
cursorDataGrid->updateInfo(index, true,
Expand All @@ -467,6 +445,7 @@ void DsoWidget::updateMarkerDetails() {
}
for (ChannelID channel = 0; channel < scope->spectrum.size(); ++channel) {
if (scope->spectrum[channel].used) {
freqUsed = true; // at least one spec channel used -> show marker freq details
QPointF p0 = scope->spectrum[channel].cursor.pos[0];
QPointF p1 = scope->spectrum[channel].cursor.pos[1];
cursorDataGrid->updateInfo(index, true,
Expand All @@ -478,6 +457,53 @@ void DsoWidget::updateMarkerDetails() {
}
++index;
}

if ( DIVS_TIME == divs || (div0 == 0 && div1 == 0) || (div0 == DIVS_TIME && div1 == DIVS_TIME) ) {
// markers at left/right margins -> don't display
markerInfoLabel->setVisible( false );
markerTimeLabel->setVisible( false );
markerFrequencyLabel->setVisible( false );
markerTimebaseLabel->setVisible( false );
markerFrequencybaseLabel->setVisible( false );
} else {
markerInfoLabel->setVisible( true );
markerTimeLabel->setVisible( true );
markerFrequencyLabel->setVisible( true );
markerTimebaseLabel->setVisible( view->zoom );
markerFrequencybaseLabel->setVisible( view->zoom );
QString mInfo( tr( "Markers ") );
QString mTime( tr( "Time: ") );
QString mFreq( tr( "Frequency: ") );
if (view->zoom) {
if ( divs != 0.0 )
mInfo = tr( "Zoom x%L1 " ).arg( DIVS_TIME / divs, -1, 'g', 3 );
else // avoid div by zero
mInfo = tr( "Zoom --- " );
mTime = " t: ";
mFreq = " f: ";
markerTimebaseLabel->setText(" " + valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div"));
markerTimebaseLabel->setVisible( timeUsed );
markerFrequencybaseLabel->setText( " " + valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) + tr("/div"));
markerFrequencybaseLabel->setVisible( freqUsed );
}
markerInfoLabel->setText( mInfo );
if ( timeUsed )
markerTimeLabel->setText( mTime.append( "%1 -> %2, Δt: %3 " )
.arg( valueToString( time0, UNIT_SECONDS, 4 ) )
.arg( valueToString( time1, UNIT_SECONDS, 4 ) )
.arg( valueToString( time, UNIT_SECONDS, 4 ) )
);
else
markerTimeLabel->setText( "" );
if ( freqUsed )
markerFrequencyLabel->setText( mFreq.append( "%1 -> %2, Δf: %3 " )
.arg( valueToString( freq0, UNIT_HERTZ, 4) )
.arg( valueToString( freq1, UNIT_HERTZ, 4) )
.arg( valueToString( freq, UNIT_HERTZ, 4) )
);
else
markerFrequencyLabel->setText( "" );
}
}

/// \brief Update the label about the trigger settings
Expand Down Expand Up @@ -535,6 +561,7 @@ void DsoWidget::updateVoltageDetails(ChannelID channel) {
/// \param frequencybase The frequencybase used for displaying the trace.
void DsoWidget::updateFrequencybase(double frequencybase) {
settingsFrequencybaseLabel->setText(valueToString(frequencybase, UNIT_HERTZ, -1) + tr("/div"));
updateMarkerDetails();
}

/// \brief Updates the samplerate field after changing the samplerate.
Expand Down
53 changes: 39 additions & 14 deletions openhantek/src/exporting/legacyexportdrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,46 +173,71 @@ bool LegacyExportDrawer::exportSamples(const PPresult *result, QPaintDevice* pai
}

// Draw the marker table
stretchBase = (double)paintDevice->width() / 5;
painter.setPen(colorValues->text);

// Calculate variables needed for zoomed scope
double m1 = settings->scope.getMarker(0);
double m2 = settings->scope.getMarker(1);
double divs = fabs(m2 - m1);
double time = divs * settings->scope.horizontal.timebase;
if ( m1 > m2 )
std::swap( m1, m2 );
double divs = m2 - m1;
double zoomFactor = DIVS_TIME / divs;
double zoomOffset = (m1 + m2) / 2;
double time1 = m1 * settings->scope.horizontal.timebase;
double time2 = m2 * settings->scope.horizontal.timebase;
double time = divs * settings->scope.horizontal.timebase;
m1 += DIVS_TIME / 2; // zero at center -> zero at left margin
m2 += DIVS_TIME / 2;
double freq1 = m1 * settings->scope.horizontal.frequencybase;
double freq2 = m2 * settings->scope.horizontal.frequencybase;
double freq = freq2 - freq1;

if (settings->view.zoom) {
stretchBase = (double)paintDevice->width() / 9;
scopeHeight = (double)(paintDevice->height() - (channelCount + 5) * lineHeight) / 2;
double top = 2.5 * lineHeight + scopeHeight;

painter.drawText(QRectF(0, top, stretchBase, lineHeight),
tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3));

painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight),
valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight));
valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight),
valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight));

valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight),
valueToString(time / DIVS_TIME, UNIT_SECONDS, 3) + tr("/div"),
QTextOption(Qt::AlignRight));
valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight),
valueToString(divs * settings->scope.horizontal.frequencybase / DIVS_TIME, UNIT_HERTZ, 3) +
valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight),
valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight),
valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));

painter.drawText(QRectF(stretchBase * 7, top, stretchBase, lineHeight),
valueToString( time / DIVS_TIME, UNIT_SECONDS, 3 ) + tr("/div"),
QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 8, top, stretchBase, lineHeight),
valueToString( freq / DIVS_TIME, UNIT_HERTZ, 3 ) +
tr("/div"),
QTextOption(Qt::AlignRight));
} else {
stretchBase = (double)paintDevice->width() / 7;
scopeHeight = (double)paintDevice->height() - (channelCount + 4) * lineHeight;
double top = 2.5 * lineHeight + scopeHeight;

painter.drawText(QRectF(0, top, stretchBase, lineHeight), tr("Marker 1/2"));

painter.drawText(QRectF(stretchBase * 0, top, stretchBase, lineHeight),
valueToString(time, UNIT_SECONDS, 4), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 1, top, stretchBase, lineHeight),
valueToString(1.0 / time, UNIT_HERTZ, 4), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase, top, stretchBase, lineHeight),
"t1: " + valueToString( time1, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 2, top, stretchBase, lineHeight),
"t2: " + valueToString( time2, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 3, top, stretchBase, lineHeight),
"Δt: " + valueToString( time, UNIT_SECONDS, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 4, top, stretchBase, lineHeight),
"f1: " + valueToString( freq1, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 5, top, stretchBase, lineHeight),
"f2: " + valueToString( freq2, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
painter.drawText(QRectF(stretchBase * 6, top, stretchBase, lineHeight),
"Δf: " + valueToString( freq, UNIT_HERTZ, 4 ), QTextOption(Qt::AlignRight));
}

// Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph
Expand Down
Loading

0 comments on commit ec1196f

Please sign in to comment.