-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_group_ex.cpp
739 lines (478 loc) · 22.5 KB
/
trace_group_ex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
#include "trace_group_ex.h"
#include "ui_trace_group_ex.h"
#include <QFile>
#include <QDebug>
#include <QBitArray>
#include <stdio.h>
#include <qcustomPlot.h>
#include <QVector>
#include <QVector2D>
#include <QMetaObject>
#include <complex>
#include <fft_complx.h>
extern QString modelname;
quint32 grp_fillen;
extern int intsample;
extern quint32 tlength;
extern int code;
extern int inittr;
extern int numtr;
int grp_trpos;
double grp_gain;
double grp_clip;
int grp_numtr;
quint32 grp_filepos;
int grp_sign;
double grp_mantissa;
int grp_exponent;
QByteArray tr_group_temp;
QByteArray hd_group_temp;
QByteArray tr_group_lbyte[100];
// In this subroutine we need to scan a group of traces and show them.
trace_group_ex::trace_group_ex(QWidget *parent) :
QWidget(parent),
ui(new Ui::trace_group_ex)
{
ui->setupUi(this);
setWindowTitle("Trace Group Explorer");
QFile f(modelname);
QDataStream in(&f);
f.open(QFile::ReadOnly);
grp_fillen=f.size();
ui->spinBox->setMinimum(1);
ui->pushButton->setVisible(false);
f.close();
}
void trace_group_ex::traceread(int grp_trpos, int grp_numtr)
{
if(ui->spinBox->value()>(grp_fillen-3200-400)/(240+4*tlength)){
ui->spinBox->setValue((grp_fillen-3200-400)/(240+4*tlength));
}
grp_trpos=ui->spinBox->value();
grp_numtr=ui->spinBox_2->value();
grp_gain=ui->spinBox_3->value();
grp_clip=ui->spinBox_4->value();
if (grp_numtr + grp_trpos > (grp_fillen-3200-400)/(240+4*tlength)+1) {
grp_numtr = (grp_fillen-3200-400)/(240+4*tlength)-grp_trpos+1;
ui->spinBox_2->setValue(grp_numtr);
}
// qDebug() << "Entering trace read group" << grp_trpos << grp_numtr << (grp_fillen-3200-400)/(240+4*tlength)-1;
QFile f(modelname);
f.open(QFile::ReadOnly);
QVector<double> trace(tlength),traceposi(tlength); //Initializing vector with trace
QVector<double> time(tlength), timeposi(tlength); //Initializing vector time axis
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setWidth(1);
pen.setColor(QColor(1,1,1));
QPen pennone;
pennone.setStyle(Qt::NoPen);
pennone.setWidth(1);
pennone.setColor(QColor(0,0,255,255));
ui->tracePlot->clearGraphs();
ui->tracePlot->yAxis->setLabel("Time (ms)"); //adding labels
ui->tracePlot->xAxis->setVisible(false);
for(int l=0;l<grp_numtr;l++){
// qDebug() << "Reading initial trace conditions" << l << grp_numtr;
grp_filepos=3200+400+(240+4*tlength)*(grp_trpos+l-1)+240;
f.seek(grp_filepos); //we must seek to the right trace header reading
if (code==1) { // start 4-byte IBM floating point
QByteArray btrace(f.read(4*tlength));
// This loop will make groups of 4 bytes
int j =0;
for (quint32 i = 0 ; i < 4*tlength ;i = i + 4) {
tr_group_temp.append(btrace[i]);
tr_group_temp.append(btrace[i+1]);
tr_group_temp.append(btrace[i+2]);
tr_group_temp.append(btrace[i+3]);
tr_group_temp=QByteArray::number(tr_group_temp.toHex().toLongLong(nullptr,16),2); //converting the array to a binary 0,1
// if(grp_trpos=0 && j==0) qDebug() << "Plotting binary for sample j=" << j << tr_group_temp;
// exit(0);
while(tr_group_temp.length()<32) {
tr_group_temp.insert(0,"0"); // inserting leading zeroes
}
if(tr_group_temp.at(0)=='1') grp_sign =-1; else grp_sign=1; // if bit 0 is 1 number is negative
tr_group_temp.remove(0,1); //removing from element 0 with length 1
// // remove grp_sign bit
QByteArray fraction = tr_group_temp.right(24); //get the fractional part
grp_mantissa=0;
for(int k=0 ; k< 24; k++) {
// iterate through the fraction to claculate the grp_mantissa
if(fraction.at(k)=='1') grp_mantissa += 1.0/(pow(2,k));
}
grp_exponent=0;
for(int k=0; k < tr_group_temp.length()-24; k++) {
// iterate through the array to calculate the grp_exponent
grp_exponent += (tr_group_temp.at(k)-48)*pow(2,6-k);
}
trace[j]=grp_gain*(grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64));
time[j]=j*intsample*1e-3;//just adding the time vector
timeposi[j]=j*intsample*1e-3;
tr_group_temp=0;
grp_exponent=0;
grp_mantissa=0;
j=j+1;
}
for(int j=0; j<trace.size(); j++){
if(trace[j]>0 && trace[j+1]<0){
traceposi[j]=0;
double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]);
timeposi[j]=yp;
}
else if(trace[j-1] < 0 && trace[j] > 0){
traceposi[j]=0;
double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]);
timeposi[j]=yp;
}
else if(trace[j] > 0 && trace[j+1] > 0){
traceposi[j]=0;
}
else{
traceposi[j]=trace[j];
}
}
for(int j=0; j<trace.size(); j++){
trace[j]=trace[j]+l*1.000005;
traceposi[j]=traceposi[j]+l*1.000005;
}
// This section plots the trace data
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
qDebug() << l << 2*l << 2*l+1;
ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph
ui->tracePlot->graph(2*l)->setPen(pen);
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph
ui->tracePlot->graph(2*l+1)->setPen(pennone);
ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1)));
ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1));
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
ui->tracePlot->yAxis->setRangeReversed(true);
} // end 4-byte IBM floating point
else if (code==2){
QByteArray btrace(f.read(4*tlength));}// 4-byte two's complement integer
else if (code==3){QByteArray trace(f.read(2*tlength));} // 2-byte two's complement integer
else if (code==4){QByteArray trace(f.read(4*tlength));} // 4-byte fixed-point with gain
else if (code==5){ // start 4-byte IEEE floating-point
QByteArray btrace(f.read(4*tlength));
// This loop will make groups of 4 bytes
int j =0;
// for (int i = 0 ; i < 4*tlength ;i = i + 4) {
for (quint32 i = 0 ; i < 4 ;i = i + 4) {
tr_group_temp.append(btrace[i]);
tr_group_temp.append(btrace[i+1]);
tr_group_temp.append(btrace[i+2]);
tr_group_temp.append(btrace[i+3]);
tr_group_temp=QByteArray::number(tr_group_temp.toHex().toLongLong(nullptr,16),2); //converting the array to a binary 0,1
while(tr_group_temp.length()<32) {
tr_group_temp.insert(0,"0"); // inserting leading zeroes
}
if(tr_group_temp.at(0)=='1') grp_sign =-1; else grp_sign=1; // if bit 0 is 1 number is negative
tr_group_temp.remove(0,1); //removing from element 0 with length 1
// // remove grp_sign bit
QByteArray fraction = tr_group_temp.right(23); //get the fractional part
grp_mantissa=0;
for(int i=0 ; i < 23; i++) {
// iterate through the fraction to claculate the grp_mantissa
if(fraction.at(i)=='1') grp_mantissa += 1.0/(pow(2,i));
}
grp_exponent=0;
for(int i=0; i < tr_group_temp.length()-23; i++) {
// iterate through the array to calculate the grp_exponent
grp_exponent += (tr_group_temp.at(i)-48)*pow(2,7-i);
}
trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127);
time[j]=j*intsample*1e-3;//just adding the time vector
timeposi[j]=j*intsample*1e-3;//just adding the time vector
tr_group_temp=0;
grp_exponent=0;
grp_mantissa=0;
j=j+1;
}
for(int j=0; j<trace.size(); j++){
if(trace[j]>0 && trace[j+1]<0){
traceposi[j]=0;
double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]);
timeposi[j]=yp;
}
else if(trace[j-1] < 0 && trace[j] > 0){
traceposi[j]=0;
double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]);
timeposi[j]=yp;
}
else if(trace[j] > 0 && trace[j+1] > 0){
traceposi[j]=0;
}
else{
traceposi[j]=trace[j];
}
}
for(int j=0; j<trace.size(); j++){
trace[j]=trace[j]+l*1.000005;
traceposi[j]=traceposi[j]+l*1.000005;
}
// This section plots the trace data
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph
ui->tracePlot->graph(2*l)->setPen(pen);
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l+1)->setData(time,trace); //adding a graph
ui->tracePlot->graph(2*l+1)->setPen(pennone);
ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1)));
ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1));
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
ui->tracePlot->yAxis->setRangeReversed(true);
} // end 4-byte IEEE floating-point
else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer
}
ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal);
ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal);
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
ui->tracePlot->rescaleAxes();
ui->tracePlot->yAxis->setRangeReversed(true);
ui->tracePlot->replot();
}
void trace_group_ex::on_pushButton_clicked()
{
if(ui->spinBox->value()>(grp_fillen-3200-400)/(240+4*tlength)){
ui->spinBox->setValue((grp_fillen-3200-400)/(240+4*tlength));
}
grp_trpos=ui->spinBox->value();
grp_numtr=ui->spinBox_2->value();
grp_gain=ui->spinBox_3->value();
grp_clip=ui->spinBox_4->value();
if (grp_numtr + grp_trpos > (grp_fillen-3200-400)/(240+4*tlength)+1) {
grp_numtr = (grp_fillen-3200-400)/(240+4*tlength)-grp_trpos+1;
ui->spinBox_2->setValue(grp_numtr);
}
// qDebug() << "Entering trace read group" << grp_trpos << grp_numtr << (grp_fillen-3200-400)/(240+4*tlength)-1;
QFile f(modelname);
f.open(QFile::ReadOnly);
QVector<double> trace(tlength),traceposi(tlength); //Initializing vector with trace
QVector<double> time(tlength), timeposi(tlength); //Initializing vector time axis
QPen pen;
pen.setStyle(Qt::SolidLine);
pen.setWidth(1);
pen.setColor(QColor(1,1,1));
QPen pennone;
pennone.setStyle(Qt::NoPen);
pennone.setWidth(1);
pennone.setColor(QColor(0,0,255,255));
ui->tracePlot->clearGraphs();
ui->tracePlot->yAxis->setLabel("Time (ms)"); //adding labels
ui->tracePlot->xAxis->setVisible(false);
for(int l=0;l<grp_numtr;l++){
// qDebug() << "Reading initial trace conditions" << l << grp_numtr;
grp_filepos=3200+400+(240+4*tlength)*(grp_trpos+l-1)+240;
f.seek(grp_filepos); //we must seek to the right trace header reading
if (code==1) { // start 4-byte IBM floating point
QByteArray btrace(f.read(4*tlength));
// This loop will make groups of 4 bytes
int j =0;
for (quint32 i = 0 ; i < 4*tlength ;i = i + 4) {
tr_group_temp.append(btrace[i]);
tr_group_temp.append(btrace[i+1]);
tr_group_temp.append(btrace[i+2]);
tr_group_temp.append(btrace[i+3]);
tr_group_temp=QByteArray::number(tr_group_temp.toHex().toLongLong(nullptr,16),2); //converting the array to a binary 0,1
// if(grp_trpos=0 && j==0) qDebug() << "Plotting binary for sample j=" << j << tr_group_temp;
// exit(0);
while(tr_group_temp.length()<32) {
tr_group_temp.insert(0,"0"); // inserting leading zeroes
}
if(tr_group_temp.at(0)=='1') grp_sign =-1; else grp_sign=1; // if bit 0 is 1 number is negative
tr_group_temp.remove(0,1); //removing from element 0 with length 1
// // remove grp_sign bit
QByteArray fraction = tr_group_temp.right(24); //get the fractional part
grp_mantissa=0;
for(int k=0 ; k< 24; k++) {
// iterate through the fraction to claculate the grp_mantissa
if(fraction.at(k)=='1') grp_mantissa += 1.0/(pow(2,k));
}
grp_exponent=0;
for(int k=0; k < tr_group_temp.length()-24; k++) {
// iterate through the array to calculate the grp_exponent
grp_exponent += (tr_group_temp.at(k)-48)*pow(2,6-k);
}
trace[j]=grp_gain*(grp_sign*(grp_mantissa/2)*pow(16,grp_exponent-64));
time[j]=j*intsample*1e-3;//just adding the time vector
timeposi[j]=j*intsample*1e-3;
tr_group_temp=0;
grp_exponent=0;
grp_mantissa=0;
j=j+1;
}
for(int j=0; j<trace.size(); j++){
if(trace[j]>0 && trace[j+1]<0){
traceposi[j]=0;
double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]);
timeposi[j]=yp;
}
else if(trace[j-1] < 0 && trace[j] > 0){
traceposi[j]=0;
double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]);
timeposi[j]=yp;
}
else if(trace[j] > 0 && trace[j+1] > 0){
traceposi[j]=0;
}
else{
traceposi[j]=trace[j];
}
}
for(int j=0; j<trace.size(); j++){
trace[j]=trace[j]+l*1.000005;
traceposi[j]=traceposi[j]+l*1.000005;
}
// This section plots the trace data
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph
ui->tracePlot->graph(2*l)->setPen(pen);
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph
ui->tracePlot->graph(2*l+1)->setPen(pennone);
ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1)));
ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1));
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
ui->tracePlot->yAxis->setRangeReversed(true);
} // end 4-byte IBM floating point
else if (code==2){
QByteArray btrace(f.read(4*tlength));}// 4-byte two's complement integer
else if (code==3){QByteArray trace(f.read(2*tlength));} // 2-byte two's complement integer
else if (code==4){QByteArray trace(f.read(4*tlength));} // 4-byte fixed-point with gain
else if (code==5){ // start 4-byte IEEE floating-point
QByteArray btrace(f.read(4*tlength));
// This loop will make groups of 4 bytes
int j =0;
// for (int i = 0 ; i < 4*tlength ;i = i + 4) {
for (quint32 i = 0 ; i < 4 ;i = i + 4) {
tr_group_temp.append(btrace[i]);
tr_group_temp.append(btrace[i+1]);
tr_group_temp.append(btrace[i+2]);
tr_group_temp.append(btrace[i+3]);
tr_group_temp=QByteArray::number(tr_group_temp.toHex().toLongLong(nullptr,16),2); //converting the array to a binary 0,1
while(tr_group_temp.length()<32) {
tr_group_temp.insert(0,"0"); // inserting leading zeroes
}
if(tr_group_temp.at(0)=='1') grp_sign =-1; else grp_sign=1; // if bit 0 is 1 number is negative
tr_group_temp.remove(0,1); //removing from element 0 with length 1
// // remove grp_sign bit
QByteArray fraction = tr_group_temp.right(23); //get the fractional part
grp_mantissa=0;
for(int i=0 ; i < 23; i++) {
// iterate through the fraction to claculate the grp_mantissa
if(fraction.at(i)=='1') grp_mantissa += 1.0/(pow(2,i));
}
grp_exponent=0;
for(int i=0; i < tr_group_temp.length()-23; i++) {
// iterate through the array to calculate the grp_exponent
grp_exponent += (tr_group_temp.at(i)-48)*pow(2,7-i);
}
trace[j]=grp_gain*grp_sign*(1+grp_mantissa)*pow(2,grp_exponent-127);
time[j]=j*intsample*1e-3;//just adding the time vector
timeposi[j]=j*intsample*1e-3;//just adding the time vector
tr_group_temp=0;
grp_exponent=0;
grp_mantissa=0;
j=j+1;
}
for(int j=0; j<trace.size(); j++){
if(trace[j]>0 && trace[j+1]<0){
traceposi[j]=0;
double yp=time[j+1]-trace[j+1]*(time[j+1]-time[j])/(trace[j+1]-trace[j]);
timeposi[j]=yp;
}
else if(trace[j-1] < 0 && trace[j] > 0){
traceposi[j]=0;
double yp=time[j-1]-trace[j-1]*(time[j]-time[j-1])/(trace[j]-trace[j-1]);
timeposi[j]=yp;
}
else if(trace[j] > 0 && trace[j+1] > 0){
traceposi[j]=0;
}
else{
traceposi[j]=trace[j];
}
}
for(int j=0; j<trace.size(); j++){
trace[j]=trace[j]+l*1.000005;
traceposi[j]=traceposi[j]+l*1.000005;
}
// This section plots the trace data
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l)->setData(time,trace); //adding a graph
ui->tracePlot->graph(2*l)->setPen(pen);
ui->tracePlot->addGraph(ui->tracePlot->yAxis,ui->tracePlot->xAxis);
ui->tracePlot->graph(2*l+1)->setData(timeposi,traceposi); //adding a graph
ui->tracePlot->graph(2*l+1)->setPen(pennone);
ui->tracePlot->graph(2*l)->setBrush(QBrush(QColor(0,0,1)));
ui->tracePlot->graph(2*l)->setChannelFillGraph(ui->tracePlot->graph(2*l+1));
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
ui->tracePlot->yAxis->setRangeReversed(true);
} // end 4-byte IEEE floating-point
else if (code==8){QByteArray btrace(f.read(tlength));} // 1-byte two's complement integer
}
ui->tracePlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
ui->tracePlot->axisRect(0)->setRangeDrag(Qt::Vertical|Qt::Horizontal);
ui->tracePlot->axisRect(0)->setRangeZoom(Qt::Vertical|Qt::Horizontal);
connect(ui->tracePlot->yAxis,SIGNAL(rangeChanged(QCPRange)),this,SLOT(onYRangeChanged(QCPRange)));
// ui->tracePlot->rescaleAxes();
ui->tracePlot->yAxis->setRangeReversed(true);
ui->tracePlot->replot();
}
void trace_group_ex::onYRangeChanged(const QCPRange &range)
{
QCPRange boundedRange = range;
double lowerRangeBound = 0;
double upperRangeBound = tlength*intsample/(1.e3);
if(boundedRange.lower < lowerRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in
boundedRange.lower = lowerRangeBound;
boundedRange.upper = lowerRangeBound + boundedRange.size();
if(boundedRange.upper > upperRangeBound){
boundedRange.upper = upperRangeBound;
ui->tracePlot->yAxis->setRange(boundedRange);
}
}
else if(boundedRange.upper > upperRangeBound || qFuzzyCompare(boundedRange.size(),upperRangeBound-lowerRangeBound)) { // restrict max zoom in
boundedRange.upper = upperRangeBound;
boundedRange.lower = upperRangeBound - boundedRange.size();
if(boundedRange.lower < lowerRangeBound){
boundedRange.lower = lowerRangeBound;
ui->tracePlot->yAxis->setRange(boundedRange);
}
}
ui->tracePlot->yAxis->setRange(boundedRange);
}
void trace_group_ex::on_spinBox_3_editingFinished()
{
ui->pushButton->click();
}
void trace_group_ex::on_spinBox_editingFinished()
{
ui->pushButton->click();
}
void trace_group_ex::on_spinBox_2_editingFinished()
{
ui->pushButton->click();
}
trace_group_ex::~trace_group_ex()
{
delete ui;
}
//void trace_group_ex::on_spinBox_valueChanged(int arg1)
//{
// ui->pushButton->click();
//}
//void trace_group_ex::on_spinBox_2_valueChanged(int arg1)
//{
// ui->pushButton->click();
//}
//void trace_group_ex::on_spinBox_3_valueChanged(double arg1)
//{
// ui->pushButton->click();
//}
void trace_group_ex::on_pushButton_2_clicked()
{
ui->tracePlot->rescaleAxes();
ui->tracePlot->replot();
}