Skip to content

Commit

Permalink
Add units check when attempting to append new RUNs
Browse files Browse the repository at this point in the history
After plotting vars from RUN_a, then selecting RUN_b
in the RUNs panel, koviz tries to add curves from
RUN_b to the plots present from RUN_a.

If the units from RUN_a and RUN_b for the same named
parameter differ, do not append RUN_b's curve.

A case when this happens is the following, if one
were to bring up RUN_a, select a param,
then do a fourier transform, the xunits change to {Hz}.
Then if one were to try and add RUN_b, the xunit
for RUN_b is {s}.  In this case, don't try to add
the RUN_b curve since units mismatch.
  • Loading branch information
keithvetter committed Aug 15, 2024
1 parent 53f914d commit c722ea5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions libkoviz/plotmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ void PlotMainWindow::_runsRefreshed()
QString xName = varHash.keys().at(0).first;
QString yName = varHash.keys().at(0).second;
foreach ( QString runPathToAppend, runPathsToAppend ) {
// Append new run using values from last curve
// Try to append new run using values from last curve
int rc = _runs->runsModel()->rowCount();
QList<QColor> colors = _bookModel->createCurveColors(rc);
for ( int r = 0; r < rc; ++r ) {
Expand All @@ -1693,7 +1693,7 @@ void PlotMainWindow::_runsRefreshed()
QFileInfo fi(path);
if ( runPathToAppend == fi.absoluteFilePath() ) {
// Turn off signals (to keep from redrawing)
bool block = _bookModel->blockSignals(true);
_bookModel->blockSignals(true);

// Make presentation "compare"
QModelIndex presIdx = _bookModel->getDataIndex(
Expand Down Expand Up @@ -1761,6 +1761,16 @@ void PlotMainWindow::_runsRefreshed()
"CurveSymbolEnd","Curve");
QString symbolEnd =_bookModel->data(idx).toString();

// Unit check
bool canConvertXUnit = Unit::canConvert(xUnit,
curveModel->x()->unit());
bool canConvertYUnit = Unit::canConvert(yUnit,
curveModel->y()->unit());
if( !canConvertXUnit || !canConvertYUnit ) {
_bookModel->blockSignals(false);
continue; // Don't add curve if units mismatch
}

// Add Curve
QStandardItem* curvesItem = _bookModel->
itemFromIndex(curvesIdx);
Expand Down Expand Up @@ -1811,7 +1821,7 @@ void PlotMainWindow::_runsRefreshed()
_bookModel->addChild(curveItem, "CurveData", v);

// Turn signals back on and reset bounding box
_bookModel->blockSignals(block);
_bookModel->blockSignals(false);
QRectF bbox = _bookModel->calcCurvesBBox(curvesIdx);
QRectF E; // Empty set below to force redraw
_bookModel->setPlotMathRect(E,plotIdx);
Expand Down

0 comments on commit c722ea5

Please sign in to comment.