@@ -2222,6 +2222,7 @@ void CurvesView::keyPressEvent(QKeyEvent *event)
2222
2222
case Qt::Key_D: _keyPressD ();break ;
2223
2223
case Qt::Key_I: _keyPressI ();break ;
2224
2224
case Qt::Key_S: _keyPressS ();break ;
2225
+ case Qt::Key_M: _keyPressM ();break ;
2225
2226
case Qt::Key_Minus: _keyPressMinus ();break ;
2226
2227
default : ; // do nothing
2227
2228
}
@@ -3332,6 +3333,27 @@ void CurvesView::_keyPressI()
3332
3333
}
3333
3334
3334
3335
void CurvesView::_keyPressS ()
3336
+ {
3337
+ SumOperation curveOp;
3338
+ _combinePlotCurves (curveOp);
3339
+ }
3340
+
3341
+ void CurvesView::_keyPressM ()
3342
+ {
3343
+ MagnitudeOperation curveOp;
3344
+ _combinePlotCurves (curveOp);
3345
+ }
3346
+
3347
+ // Takes curves of curve's view plot and generates a new curve on the plot
3348
+ // by combining the curves using the given "curveOp".
3349
+ // For example, if curveOp is a summation,
3350
+ // a new curve is generated on the plot that is the sum of all the
3351
+ // curves point by point foreach timestamp.
3352
+ // Notes:
3353
+ // If curve has a timestamp with a nan y-val, throw out the timestamp
3354
+ // Handle case when there are duplicate timestamps
3355
+ // If times do not match, interpolate
3356
+ void CurvesView::_combinePlotCurves (CurveOperation &curveOp)
3335
3357
{
3336
3358
QModelIndex plotIdx = rootIndex ();
3337
3359
QModelIndex curvesIdx = _bookModel ()->getIndex (plotIdx," Curves" ," Plot" );
@@ -3354,64 +3376,8 @@ void CurvesView::_keyPressS()
3354
3376
}
3355
3377
}
3356
3378
3357
- SumOperation curveOp;
3358
- CurveModel* curveModel = _combineCurveModels (curveInfos,curveOp);
3359
- if ( !curveModel ) {
3360
- return ;
3361
- }
3362
-
3363
- bool block = _bookModel ()->blockSignals (true );
3364
- QStandardItem* curvesItem = _bookModel ()->itemFromIndex (curvesIdx);
3365
- QStandardItem *curveItem = _bookModel ()->addChild (curvesItem," Curve" );
3366
-
3367
- _bookModel ()->addChild (curveItem, " CurveRunID" , -1 );
3368
- _bookModel ()->addChild (curveItem, " CurveRunPath" ,QString (" koviz:memory" ));
3369
- _bookModel ()->addChild (curveItem, " CurveTimeName" ,curveModel->t ()->name ());
3370
- _bookModel ()->addChild (curveItem, " CurveTimeUnit" ,curveModel->t ()->unit ());
3371
-
3372
- _bookModel ()->addChild (curveItem, " CurveXName" , curveModel->x ()->name ());
3373
- _bookModel ()->addChild (curveItem, " CurveXUnit" , curveModel->x ()->unit ());
3374
- _bookModel ()->addChild (curveItem, " CurveXScale" , 1.0 );
3375
- _bookModel ()->addChild (curveItem, " CurveXBias" , 0.0 );
3376
-
3377
- _bookModel ()->addChild (curveItem, " CurveYName" , curveModel->y ()->name ());
3378
- _bookModel ()->addChild (curveItem, " CurveYLabel" , curveModel->y ()->name ());
3379
- _bookModel ()->addChild (curveItem, " CurveYUnit" , curveModel->y ()->unit ());
3380
- _bookModel ()->addChild (curveItem, " CurveYScale" , 1.0 );
3381
- _bookModel ()->addChild (curveItem, " CurveYBias" , 0.0 );
3382
-
3383
- _bookModel ()->addChild (curveItem, " CurveXMinRange" , -DBL_MAX);
3384
- _bookModel ()->addChild (curveItem, " CurveXMaxRange" , DBL_MAX);
3385
- _bookModel ()->addChild (curveItem, " CurveYMinRange" , -DBL_MAX);
3386
- _bookModel ()->addChild (curveItem, " CurveYMaxRange" , DBL_MAX);
3387
- _bookModel ()->addChild (curveItem, " CurveSymbolSize" , " " );
3388
- QColor color = (nCurvesToSum == 3 ) ? QColor (177 ,77 ,0 ) : QColor (35 ,106 ,26 );
3389
- _bookModel ()->addChild (curveItem, " CurveColor" ,color);
3390
- _bookModel ()->addChild (curveItem, " CurveLineStyle" , " plain" );
3391
- _bookModel ()->addChild (curveItem, " CurveSymbolStyle" , " none" );
3392
- _bookModel ()->addChild (curveItem, " CurveSymbolSize" , " " );
3393
- _bookModel ()->addChild (curveItem, " CurveSymbolEnd" , " none" );
3394
-
3395
- QVariant v = PtrToQVariant<CurveModel>::convert (curveModel);
3396
- _bookModel ()->addChild (curveItem, " CurveData" , v);
3397
-
3398
- // Turn signals back on and reset bounding box
3399
- _bookModel ()->blockSignals (block);
3400
- QRectF M = _bookModel ()->calcCurvesBBox (curvesIdx);
3401
- QRectF E; // Empty set below to force redraw
3402
- _bookModel ()->setPlotMathRect (E,plotIdx);
3403
- _bookModel ()->setPlotMathRect (M,plotIdx);
3404
- }
3405
-
3406
- // Sums up yvalues against time
3407
- // If curve has a timestamp with a nan y-val, throw out the timestamp
3408
- // Handle case when there are duplicate timestamps
3409
- // If times do not match, interpolate
3410
- CurveModel *CurvesView::_combineCurveModels (const QList<CurveInfo> &curveInfos,
3411
- CurveOperation &curveOp)
3412
- {
3413
3379
if (curveInfos.isEmpty ()) {
3414
- return nullptr ;
3380
+ return ;
3415
3381
}
3416
3382
3417
3383
// Map all models
@@ -3508,7 +3474,7 @@ CurveModel *CurvesView::_combineCurveModels(const QList<CurveInfo> &curveInfos,
3508
3474
it->start ();
3509
3475
}
3510
3476
3511
- // Load the sum into a vector of points
3477
+ // Load the curve combination into a vector of points
3512
3478
QVector<QPointF>* points = new QVector<QPointF>();
3513
3479
while (true ) {
3514
3480
@@ -3547,7 +3513,7 @@ CurveModel *CurvesView::_combineCurveModels(const QList<CurveInfo> &curveInfos,
3547
3513
}
3548
3514
3549
3515
if (isTimeMatch) {
3550
- // Sum the y-values for matching timestamps
3516
+ // Combine the y-values for matching timestamps
3551
3517
QVector<double > yvals;
3552
3518
foreach (ModelIterator* it, iterators) {
3553
3519
double t = _getTime (isXTime,xUnit,it,it2curveInfo.value (it));
@@ -3699,11 +3665,54 @@ CurveModel *CurvesView::_combineCurveModels(const QList<CurveInfo> &curveInfos,
3699
3665
DataModel* dataModel = new PointsModel (pointsPtr.take (),
3700
3666
QString (" sys.exec.out.time" ),
3701
3667
xUnitSum,
3702
- QString ( " sum " ),
3668
+ curveOp. name ( ),
3703
3669
yUnit);
3704
- CurveModel* sumCurveModel = new CurveModel (dataModel,0 ,0 ,1 );
3670
+ CurveModel* curveModel = new CurveModel (dataModel,0 ,0 ,1 );
3671
+
3672
+ //
3673
+ // Add new curve to plot
3674
+ //
3675
+ bool block = _bookModel ()->blockSignals (true );
3676
+ QStandardItem* curvesItem = _bookModel ()->itemFromIndex (curvesIdx);
3677
+ QStandardItem *curveItem = _bookModel ()->addChild (curvesItem," Curve" );
3705
3678
3706
- return sumCurveModel;
3679
+ _bookModel ()->addChild (curveItem, " CurveRunID" , -1 );
3680
+ _bookModel ()->addChild (curveItem, " CurveRunPath" ,QString (" koviz:memory" ));
3681
+ _bookModel ()->addChild (curveItem, " CurveTimeName" ,curveModel->t ()->name ());
3682
+ _bookModel ()->addChild (curveItem, " CurveTimeUnit" ,curveModel->t ()->unit ());
3683
+
3684
+ _bookModel ()->addChild (curveItem, " CurveXName" , curveModel->x ()->name ());
3685
+ _bookModel ()->addChild (curveItem, " CurveXUnit" , curveModel->x ()->unit ());
3686
+ _bookModel ()->addChild (curveItem, " CurveXScale" , 1.0 );
3687
+ _bookModel ()->addChild (curveItem, " CurveXBias" , 0.0 );
3688
+
3689
+ _bookModel ()->addChild (curveItem, " CurveYName" , curveModel->y ()->name ());
3690
+ _bookModel ()->addChild (curveItem, " CurveYLabel" , curveModel->y ()->name ());
3691
+ _bookModel ()->addChild (curveItem, " CurveYUnit" , curveModel->y ()->unit ());
3692
+ _bookModel ()->addChild (curveItem, " CurveYScale" , 1.0 );
3693
+ _bookModel ()->addChild (curveItem, " CurveYBias" , 0.0 );
3694
+
3695
+ _bookModel ()->addChild (curveItem, " CurveXMinRange" , -DBL_MAX);
3696
+ _bookModel ()->addChild (curveItem, " CurveXMaxRange" , DBL_MAX);
3697
+ _bookModel ()->addChild (curveItem, " CurveYMinRange" , -DBL_MAX);
3698
+ _bookModel ()->addChild (curveItem, " CurveYMaxRange" , DBL_MAX);
3699
+ _bookModel ()->addChild (curveItem, " CurveSymbolSize" , " " );
3700
+ QColor color = (nCurvesToSum == 3 ) ? QColor (177 ,77 ,0 ) : QColor (35 ,106 ,26 );
3701
+ _bookModel ()->addChild (curveItem, " CurveColor" ,color);
3702
+ _bookModel ()->addChild (curveItem, " CurveLineStyle" , " plain" );
3703
+ _bookModel ()->addChild (curveItem, " CurveSymbolStyle" , " none" );
3704
+ _bookModel ()->addChild (curveItem, " CurveSymbolSize" , " " );
3705
+ _bookModel ()->addChild (curveItem, " CurveSymbolEnd" , " none" );
3706
+
3707
+ QVariant v = PtrToQVariant<CurveModel>::convert (curveModel);
3708
+ _bookModel ()->addChild (curveItem, " CurveData" , v);
3709
+
3710
+ // Turn signals back on and reset bounding box
3711
+ _bookModel ()->blockSignals (block);
3712
+ QRectF M = _bookModel ()->calcCurvesBBox (curvesIdx);
3713
+ QRectF E; // Empty set below to force redraw
3714
+ _bookModel ()->setPlotMathRect (E,plotIdx);
3715
+ _bookModel ()->setPlotMathRect (M,plotIdx);
3707
3716
}
3708
3717
3709
3718
double CurvesView::_getTime (bool isXTime,
0 commit comments