-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPlot2D.cpp
958 lines (769 loc) · 25.1 KB
/
Plot2D.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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
#include "Plot2D.h"
#include <epochevent.h>
Plot2D::Plot2D()
{
_echogram.setVisible(true);
_attitude.setVisible(true);
_encoder.setVisible(true);
_DVLBeamVelocity.setVisible(true);
_DVLSolution.setVisible(true);
_usblSolution.setVisible(true);
_bottomProcessing.setVisible(true);
_rangeFinder.setVisible(true);
_grid.setVisible(true);
_aim.setVisible(true);
_quadrature.setVisible(false);
setDataChannel(CHANNEL_FIRST);
_cursor.attitude.from = -180;
_cursor.attitude.to = 180;
_cursor.distance.set(0, 20);
// _cursor.velocity.set(-1, 1);
}
bool Plot2D::getImage(int width, int height, QPainter* painter, bool is_horizontal) {
if(is_horizontal) {
_canvas.setSize(width, height, painter);
} else {
_canvas.setSize(height, width, painter);
painter->rotate(-90);
painter->translate(-height, 0);
}
reindexingCursor();
reRangeDistance();
// painter->setCompositionMode(QPainter::RasterOp_SourceXorDestination);
_echogram.draw(_canvas, _dataset, _cursor);
_attitude.draw(_canvas, _dataset, _cursor);
_encoder.draw(_canvas, _dataset, _cursor);
_DVLBeamVelocity.draw(_canvas, _dataset, _cursor);
_DVLSolution.draw(_canvas, _dataset, _cursor);
_usblSolution.draw(_canvas, _dataset, _cursor);
_bottomProcessing.draw(_canvas, _dataset, _cursor);
_rangeFinder.draw(_canvas, _dataset, _cursor);
_GNSS.draw(_canvas, _dataset, _cursor);
_quadrature.draw(_canvas, _dataset, _cursor);
painter->setCompositionMode(QPainter::CompositionMode_Exclusion);
_grid.draw(_canvas, _dataset, _cursor);
_aim.draw(_canvas, _dataset, _cursor);
contacts_.draw(_canvas, _dataset, _cursor);
return true;
}
void Plot2D::setAimEpochEventState(bool state)
{
_aim.setEpochEventState(state);
}
void Plot2D::setTimelinePosition(float position)
{
if (position > 1.0f) {
position = 1.0f;
}
if (position < 0) {
position = 0;
}
if (_cursor.position != position) {
_cursor.position = position;
plotUpdate();
}
}
void Plot2D::resetAim()
{
_cursor.selectEpochIndx = -1;
}
void Plot2D::setTimelinePositionSec(float position)
{
if (position > 1.0f) {
position = 1.0f;
}
if (position < 0) {
position = 0;
}
_cursor.position = position;
plotUpdate();
}
void Plot2D::setTimelinePositionByEpoch(int epochIndx) {
float pos = epochIndx == -1 ? _cursor.position : static_cast<float>(epochIndx + _cursor.indexes.size() / 2) / static_cast<float>(_dataset->size());
_cursor.selectEpochIndx = epochIndx;
setTimelinePositionSec(pos);
}
void Plot2D::scrollPosition(int columns) {
float new_position = timelinePosition() + (1.0f/_dataset->size())*columns;
setTimelinePosition(new_position);
}
void Plot2D::setDataChannel(int channel, int channel2) {
_cursor.channel1 = channel;
_cursor.channel2 = channel2;
float from = NAN, to = NAN;
if(_dataset != NULL) {
_dataset->getMaxDistanceRange(&from, &to, channel, channel2);
if(isfinite(from) && isfinite(to) && (to - from) > 0) {
_cursor.distance.set(from, to);
}
}
resetCash();
plotUpdate();
}
bool Plot2D::getIsContactChanged()
{
return contacts_.isChanged();
}
QString Plot2D::getContactInfo()
{
return contacts_.getInfo();
}
void Plot2D::setContactInfo(const QString& str)
{
contacts_.setInfo(str);
}
bool Plot2D::getContactVisible()
{
return contacts_.getVisible();
}
void Plot2D::setContactVisible(bool state)
{
contacts_.setVisible(state);
}
int Plot2D::getContactPositionX()
{
return contacts_.getPosition().x();
}
int Plot2D::getContactPositionY()
{
return contacts_.getPosition().y();
}
int Plot2D::getContactIndx()
{
return contacts_.getIndx();
}
double Plot2D::getContactLat()
{
return contacts_.getLat();
}
double Plot2D::getContactLon()
{
return contacts_.getLon();
}
double Plot2D::getContactDepth()
{
return contacts_.getDepth();
}
void Plot2D::setEchogramLowLevel(float low) {
_echogram.setLowLevel(low);
plotUpdate();
}
void Plot2D::setEchogramHightLevel(float high) {
_echogram.setHightLevel(high);
plotUpdate();
}
void Plot2D::setEchogramVisible(bool visible) {
_echogram.setVisible(visible);
_echogram.resetCash();
plotUpdate();
}
void Plot2D::setEchogramTheme(int theme_id) {
_echogram.setThemeId(theme_id);
plotUpdate();
}
void Plot2D::setEchogramCompensation(int compensation_id) {
_echogram.setCompensation(compensation_id);
_echogram.resetCash();
plotUpdate();
}
void Plot2D::setBottomTrackVisible(bool visible) {
_bottomProcessing.setVisible(visible);
plotUpdate();
}
void Plot2D::setBottomTrackTheme(int theme_id) {
Q_UNUSED(theme_id);
}
void Plot2D::setRangefinderVisible(bool visible) {
_rangeFinder.setVisible(visible);
_grid.setRangeFinderVisible(visible);
plotUpdate();
}
void Plot2D::setRangefinderTheme(int theme_id) {
_rangeFinder.setTheme(theme_id);
plotUpdate();
}
void Plot2D::setAttitudeVisible(bool visible) {
_attitude.setVisible(visible);
plotUpdate();
}
void Plot2D::setDopplerBeamVisible(bool visible, int beam_filter) {
_DVLBeamVelocity.setVisible(visible);
_DVLBeamVelocity.setBeamFilter(beam_filter);
plotUpdate();
}
void Plot2D::setDopplerInstrumentVisible(bool visible) {
_DVLSolution.setVisible(visible);
plotUpdate();
}
void Plot2D::setGNSSVisible(bool visible, int flags) {
Q_UNUSED(flags);
_GNSS.setVisible(visible);
plotUpdate();
}
void Plot2D::setGridVetricalNumber(int grids) {
_grid.setVisible(grids > 0);
_grid.setVetricalNumber(grids);
plotUpdate();
}
void Plot2D::setGridFillWidth(bool state)
{
_grid.setFillWidth(state);
plotUpdate();
}
void Plot2D::setAngleVisibility(bool state)
{
_grid.setAngleVisibility(state);
plotUpdate();
}
void Plot2D::setAngleRange(int angleRange)
{
_cursor.attitude.from = static_cast<float>(-angleRange);
_cursor.attitude.to = static_cast<float>(angleRange);
plotUpdate();
}
void Plot2D::setVelocityVisible(bool visible) {
_grid.setVelocityVisible(visible);
plotUpdate();
}
void Plot2D::setVelocityRange(float velocity) {
_cursor.velocity.from = -velocity;
_cursor.velocity.to = velocity;
plotUpdate();
}
void Plot2D::setDistanceAutoRange(int auto_range_type) {
_cursor.distance.mode = AutoRangeMode(auto_range_type);
}
void Plot2D::setDistance(float from, float to) {
_cursor.distance.set(from, to);
}
void Plot2D::zoomDistance(float ratio) {
_cursor.distance.mode = AutoRangeNone;
int delta = ratio;
if(delta == 0) return;
float from = _cursor.distance.from;
float to = _cursor.distance.to;
float absrange = abs(to - from);
float zoom = delta < 0 ? -delta*0.01f : delta*0.01f;
float delta_range = absrange*zoom;
float new_range = 0;
if(delta_range < 0.1) {
delta_range = 0.1;
} else if(delta_range > 5) {
delta_range = 5;
}
if(delta > 0) {
new_range = absrange + delta_range;
} else {
new_range = absrange - delta_range;
}
if(new_range < 1) {
new_range = 1;
} else if(new_range > 500) {
new_range = 500;
}
if(_cursor.isChannelDoubled()) {
_cursor.distance.from = -ceil( new_range/2);
_cursor.distance.to = ceil( new_range/2);
} else {
_cursor.distance.to = ceil(_cursor.distance.from + new_range);
}
plotUpdate();
}
void Plot2D::scrollDistance(float ratio) {
_cursor.distance.mode = AutoRangeNone;
float from = _cursor.distance.from;
float to = _cursor.distance.to;
float absrange = abs(to - from);
float delta_offset = ((float)absrange*(float)ratio*0.001f);
if(from < to) {
float round_cef = 10.0f;
float from_n = (round((from + delta_offset)*round_cef)/round_cef);
float to_n = (round((to + delta_offset)*round_cef)/round_cef);
if(!_cursor.isChannelDoubled()) {
if(from_n < 0) {
to_n -= from_n;
from_n = 0;
}
}
_cursor.distance.from = from_n;
_cursor.distance.to = to_n;
} else if(from > to) {
_cursor.distance.from = (from - delta_offset);
_cursor.distance.to = (to - delta_offset);
}
plotUpdate();
}
void Plot2D::setMousePosition(int x, int y) {
const int image_width = _canvas.width();
const int image_height = _canvas.height();
const int dataset_from = _cursor.getIndex(0);
Q_UNUSED(dataset_from);
const float distance_from = _cursor.distance.from;
const float distance_range = _cursor.distance.to - _cursor.distance.from;
const float image_distance_ratio = distance_range/(float)image_height;
struct {
int x = -1, y = -1;
} _mouse;
_mouse.x = _cursor.mouseX;
_mouse.y = _cursor.mouseY;
_cursor.setMouse(x, y);
if(x < -1) { x = -1; }
if(x >= image_width) { x = image_width - 1; }
if(y < 0) { y = 0; }
if(y >= image_height) { x = image_height - 1; }
if(x == -1) {
_mouse.x = -1;
_cursor.selectEpochIndx = -1;
_cursor.currentEpochIndx = -1;
//_cursor.lastEpochIndx = -1; // ?
plotUpdate();
return;
}
int x_start = 0, y_start = 0;
int x_length = 0;
float y_scale = 0.0f;
if(_mouse.x != -1) {
if(_mouse.x < x) {
x_length = x - _mouse.x;
x_start = _mouse.x;
y_start = _mouse.y;
y_scale = (float)(y - _mouse.y)/(float)x_length;
} else if(_mouse.x > x) {
x_length = _mouse.x - x;
x_start = x;
y_start = y;
y_scale = -(float)(y - _mouse.y)/(float)x_length;
} else {
x_length = 1;
x_start = x;
y_start = y;
y_scale = 0;
}
} else {
x_length = 1;
x_start = x;
y_start = y;
y_scale = 0;
}
// _mouse.x = x;
// _mouse.y = y;
//qDebug() << "Cursor epoch" << _cursor.getIndex(x_start);
int epoch_index = _cursor.getIndex(x_start);
_cursor.currentEpochIndx = epoch_index;
_cursor.lastEpochIndx = _cursor.currentEpochIndx;
sendSyncEvent(epoch_index, EpochSelected2d);
if(_cursor.tool() > MouseToolNothing) {
for(int x_ind = 0; x_ind < x_length; x_ind++) {
int epoch_index = _cursor.getIndex(x_start + x_ind);
Epoch* epoch = _dataset->fromIndex(epoch_index);
const int channel1 = _cursor.channel1;
const int channel2 = _cursor.channel2;
if(epoch != NULL) {
float image_y_pos = ((float)y_start + (float)x_ind*y_scale);
float dist = abs(image_y_pos*image_distance_ratio + distance_from);
if(_cursor.tool() == MouseToolDistanceMin) {
epoch->setMinDistProc(channel1, dist);
epoch->setMinDistProc(channel2, dist);
} else if(_cursor.tool() == MouseToolDistance) {
epoch->setDistProcessing(channel1, dist);
epoch->setDistProcessing(channel2, dist);
} else if(_cursor.tool()== MouseToolDistanceMax) {
epoch->setMaxDistProc(channel1, dist);
epoch->setMaxDistProc(channel2, dist);
} else if(_cursor.tool() == MouseToolDistanceErase) {
epoch->clearDistProcessing(channel1);
epoch->clearDistProcessing(channel2);
}
}
}
if (_cursor.tool() == MouseToolDistanceMin || _cursor.tool() == MouseToolDistanceMax) {
if (auto btp = _dataset->getBottomTrackParamPtr(); btp) {
btp->indexFrom = _cursor.getIndex(x_start);
btp->indexTo = _cursor.getIndex(x_start + x_length);
_dataset->bottomTrackProcessing(_cursor.channel1, _cursor.channel2);
}
}
if(_cursor.tool() == MouseToolDistance || _cursor.tool() == MouseToolDistanceErase) {
emit _dataset->bottomTrackUpdated(_cursor.getIndex(x_start), _cursor.getIndex(x_start + x_length));
}
}
plotUpdate();
}
void Plot2D::simpleSetMousePosition(int x, int y)
{
const int image_width = _canvas.width();
const int image_height = _canvas.height();
int mouseX = -1;
if (x < -1) {
x = -1;
}
if (x >= image_width) {
x = image_width - 1;
}
if (y < 0) {
y = 0;
}
if (y >= image_height) {
x = image_height - 1;
}
if (x == -1) {
//_cursor.selectEpochIndx = -1;
_cursor.currentEpochIndx = -1;
//_cursor.lastEpochIndx = -1; // ?
return;
}
_cursor.setContactPos(x, y);
int x_start = 0;
if(mouseX != -1) {
if(mouseX < x) {
x_start = mouseX;
}
else if (mouseX > x) {
x_start = x;
}
else {
x_start = x;
}
}
else {
x_start = x;
}
_cursor.currentEpochIndx = _cursor.getIndex(x_start);
_cursor.lastEpochIndx = _cursor.currentEpochIndx;
//sendSyncEvent(epoch_index);
//plotUpdate();
}
void Plot2D::setMouseTool(MouseTool tool) {
_cursor.setTool(tool);
}
bool Plot2D::setContact(int indx, const QString& text)
{
if (!_dataset) {
qDebug() << "Plot2D::setContact returned: !_dataset";
return false;
}
if (text.isEmpty()) {
qDebug() << "Plot2D::setContact returned: text.isEmpty()";
return false;
}
bool primary = indx == -1;
int currIndx = primary ? _cursor.lastEpochIndx : indx;
//qDebug() << "indx" << indx << "currIndx" << currIndx << text;
auto* ep = _dataset->fromIndex(currIndx);
if (!ep) {
qDebug() << "Plot2D::setContact returned: !ep";
return false;
}
ep->contact_.info_ = text;
//qDebug() << "Plot2D::setContact: setted to epoch:" << currIndx << text;
if (primary) {
ep->contact_.cursorX_ = _cursor.contactX;
ep->contact_.cursorY_ = _cursor.contactY;
const float canvas_height = _canvas.height();
float value_range = _cursor.distance.to - _cursor.distance.from;
float value_scale = float(_cursor.contactY) / canvas_height;
float cursor_distance = value_scale * value_range + _cursor.distance.from;
ep->contact_.distance_ = cursor_distance;
auto pos = ep->getPositionGNSS();
ep->contact_.nedX_ = pos.ned.n;
ep->contact_.nedY_ = pos.ned.e;
ep->contact_.lat_ = pos.lla.latitude;
ep->contact_.lon_ = pos.lla.longitude;
}
else {
// update rect
}
sendSyncEvent(currIndx, ContactCreated);
plotUpdate();
return true;
}
bool Plot2D::deleteContact(int indx)
{
if (!_dataset) {
qDebug() << "Plot2D::deleteContact returned: !_dataset";
return false;
}
//qDebug() << "indx" << indx << "currIndx" << currIndx << text;
auto* ep = _dataset->fromIndex(indx);
if (!ep) {
qDebug() << "Plot2D::deleteContact returned: !ep";
return false;
}
ep->contact_.clear();
sendSyncEvent(indx, ContactDeleted);
plotUpdate();
return true;
}
void Plot2D::updateContact()
{
contacts_.setMousePos(-1,-1);
plotUpdate();
}
void Plot2D::onCursorMoved(int x, int y)
{
contacts_.setMousePos(x, y);
plotUpdate();
}
void Plot2D::resetCash() {
_echogram.resetCash();
}
void Plot2D::reindexingCursor() {
if(_dataset == nullptr) { return; }
const int image_width = _canvas.width();
const int data_width = _dataset->size();
const int last_indexes_size = _cursor.indexes.size();
if(image_width != last_indexes_size) {
_cursor.indexes.resize(image_width);
}
if(_cursor.last_dataset_size > 0) {
float position = timelinePosition();
float last_head = round(position*_cursor.last_dataset_size);
float last_offset_head = float(_cursor.last_dataset_size) - last_head;
float new_head = data_width - last_offset_head;
position = float(new_head)/float(data_width);
setTimelinePosition(position);
}
_cursor.last_dataset_size = data_width;
float hor_ratio = 1.0f;
float position = timelinePosition();
int head_data_index = round(position*float(data_width));
int cntZeros = 0;
for(int i = 0; i < image_width; i++) {
int data_index = head_data_index + round((i - image_width)/hor_ratio) - 1;
if(data_index >= 0 && data_index < data_width) {
_cursor.indexes[i] = data_index;
} else {
++cntZeros;
_cursor.indexes[i] = -1;
}
}
_cursor.numZeroEpoch = cntZeros;
}
void Plot2D::reRangeDistance() {
if(_dataset == NULL) { return; }
float max_range = NAN;
if(_cursor.distance.mode == AutoRangeLastData) {
for(int i = _dataset->endIndex() - 3; i < _dataset->endIndex(); i++) {
Epoch* epoch = _dataset->fromIndex(i);
if(epoch != NULL) {
float epoch_range = epoch->getMaxRnage(_cursor.channel1);
if(!isfinite(max_range) || max_range < epoch_range) {
max_range = epoch_range;
}
}
}
}
if(_cursor.distance.mode == AutoRangeLastOnScreen) {
for(unsigned int i = _cursor.indexes.size() - 3; i < _cursor.indexes.size(); i++) {
Epoch* epoch = _dataset->fromIndex(_cursor.getIndex(i));
if(epoch != NULL) {
float epoch_range = epoch->getMaxRnage(_cursor.channel1);
if(!isfinite(max_range) || max_range < epoch_range) {
max_range = epoch_range;
}
}
}
}
if(_cursor.distance.mode == AutoRangeMaxOnScreen) {
for(unsigned int i = 0; i < _cursor.indexes.size(); i++) {
Epoch* epoch = _dataset->fromIndex(_cursor.getIndex(i));
if(epoch != NULL) {
float epoch_range = epoch->getMaxRnage(_cursor.channel1);
if(!isfinite(max_range) || max_range < epoch_range) {
max_range = epoch_range;
}
}
}
}
if(isfinite(max_range)) {
if(_cursor.isChannelDoubled()) {
_cursor.distance.from = -ceil(max_range);;
} else {
_cursor.distance.from = 0;
}
_cursor.distance.to = ceil(max_range);
}
}
bool Plot2DAim::draw(Canvas &canvas, Dataset *dataset, DatasetCursor cursor)
{
if((cursor.mouseX < 0 || cursor.mouseY < 0) && (cursor.selectEpochIndx == -1) ) {
return false;
}
if (cursor.selectEpochIndx != -1) {
auto selectedEpoch = dataset->fromIndex(cursor.selectEpochIndx);
int offsetX = 0;
int halfCanvas = canvas.width() / 2;
int withoutHalf = dataset->size() - halfCanvas;
if (cursor.selectEpochIndx >= withoutHalf)
offsetX = cursor.selectEpochIndx - withoutHalf;
if (const auto keys{ dataset->channelsList().keys() }; !keys.empty()) {
if (const auto chartPtr{ selectedEpoch->chart(keys.at(0)) }; chartPtr) {
const int x = canvas.width() / 2 + offsetX;
const int y = keys.size() == 2 ? canvas.height() / 2 - canvas.height() * (chartPtr->bottomProcessing.distance / cursor.distance.range()) :
canvas.height() * (chartPtr->bottomProcessing.distance / cursor.distance.range());
cursor.setMouse(x, y);
}
}
}
QPen pen;
pen.setWidth(_lineWidth);
pen.setColor(_lineColor);
QPainter* p = canvas.painter();
p->setPen(pen);
QFont font = QFont("Asap", 14, QFont::Normal);
font.setPixelSize(18);
p->setFont(font);
const int image_height = canvas.height();
const int image_width = canvas.width();
if (cursor._tool == MouseToolNothing || beenEpochEvent_) {
p->drawLine(0, cursor.mouseY, image_width, cursor.mouseY);
p->drawLine(cursor.mouseX, 0, cursor.mouseX, image_height);
}
const float canvas_height = canvas.height();
float value_range = cursor.distance.to - cursor.distance.from;
float value_scale = float(cursor.mouseY)/canvas_height;
float cursor_distance = value_scale*value_range + cursor.distance.from;
// text & back
p->setCompositionMode(QPainter::CompositionMode_SourceOver);
QString distanceText = QString("%1 m").arg(cursor_distance, 0, 'g', 4);
QRect textRect = p->fontMetrics().boundingRect(distanceText);
bool onTheRight = (p->window().width() - cursor.mouseX - 65) < textRect.width();
QPoint shiftedPoint;
if (cursor.mouseY > 60) {
shiftedPoint = onTheRight ? QPoint(cursor.mouseX - 50 - textRect.width(), cursor.mouseY - 20) : QPoint(cursor.mouseX + 50, cursor.mouseY - 20);
}
else {
shiftedPoint = onTheRight ? QPoint(cursor.mouseX - 50 - textRect.width(), cursor.mouseY + 40) : QPoint(cursor.mouseX + 50, cursor.mouseY + 40);
}
textRect.moveTopLeft(shiftedPoint);
// back
p->setPen(Qt::NoPen);
p->setBrush(QColor(45,45,45));
p->drawRect(textRect.adjusted(-5, -20, 5, -15));
// text
p->setPen(QColor(255,255,255));
p->drawText(textRect.topLeft(), distanceText);
return true;
}
Plot2DContact::Plot2DContact()
{
}
bool Plot2DContact::draw(Canvas &canvas, Dataset *dataset, DatasetCursor cursor)
{
QPen pen;
pen.setWidth(lineWidth_);
pen.setColor(lineColor_);
QPainter* p = canvas.painter();
p->setPen(pen);
QFont font = QFont("Asap", 14, QFont::Normal);
font.setPixelSize(18);
p->setFont(font);
p->setCompositionMode(QPainter::CompositionMode_SourceOver);
qreal adjPix = 5;
qreal shiftXY = 20;
setVisibleContact(false);
for (auto& indx : cursor.indexes) {
auto* epoch = dataset->fromIndex(indx);
if (!epoch) {
continue;
}
if (epoch->contact_.isValid()) {
float xPos = cursor.numZeroEpoch + indx - cursor.indexes[0];
const float canvasHeight = canvas.height();
float valueRange = cursor.distance.to - cursor.distance.from;
float valueScale = canvasHeight / valueRange;
float yPos = (epoch->contact_.distance_ - cursor.distance.from) * valueScale;
bool intersects = false;
auto& epRect = epoch->contact_.rectEcho_;
if (!epRect.isEmpty()) {
QRectF locRect = epRect.translated(QPointF(xPos + shiftXY, yPos + shiftXY) - epRect.topLeft());
locRect = locRect.adjusted(-adjPix, -adjPix, adjPix, adjPix);
if (locRect.contains(QPointF(mouseX_, mouseY_))) {
indx_ = indx;
position_ = QPoint(xPos + shiftXY * 0.75, yPos + shiftXY *0.75);
info_ = epoch->contact_.info_;
lat_ = epoch->contact_.lat_;
lon_ = epoch->contact_.lon_;
depth_ = epoch->contact_.distance_;
setVisibleContact(true);
intersects = true;
}
}
QString infoText = epoch->contact_.info_;
QRectF textRect = p->fontMetrics().boundingRect(infoText);
textRect.moveTopLeft(QPointF(xPos + shiftXY, yPos + shiftXY));
// write rect
if (epRect.height() != textRect.height() ||
epRect.width() != textRect.width()) {
epRect = textRect;
}
if (intersects) {
QPointF topLeft = textRect.adjusted(-adjPix + 1, -adjPix + 1, adjPix, adjPix).topLeft();
p->setPen(QPen(QColor(0,190,0), 2));
p->drawLine(topLeft, topLeft + QPointF(-30, 0));
p->drawLine(topLeft, topLeft + QPointF(0, -30));
}
else {
// red back
p->setPen(Qt::NoPen);
p->setBrush(QColor(190, 0, 0));
p->drawRect(textRect.adjusted(-adjPix, -adjPix, adjPix, adjPix));
// lines
QPointF topLeft = textRect.adjusted(-adjPix + 1, -adjPix + 1, adjPix, adjPix).topLeft();
p->setPen(QPen(QColor(190,0,0), 2));
p->drawLine(topLeft, topLeft + QPointF(-30, 0));
p->drawLine(topLeft, topLeft + QPointF(0, -30));
// gray back
p->setPen(Qt::NoPen);
p->setBrush(QColor(45,45,45));
p->drawRect(textRect.adjusted(-3, -3, 3, 3));
// text
p->setPen(QColor(255,255,255));
p->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, infoText);
}
}
}
return true;
}
void Plot2DContact::setMousePos(int x, int y)
{
mouseX_ = x;
mouseY_ = y;
}
QString Plot2DContact::getInfo()
{
return info_;
}
void Plot2DContact::setInfo(const QString &info)
{
//qDebug() << "Plot2DContact::setInfo";
info_ = info;
}
bool Plot2DContact::getVisible()
{
return visible_;
}
void Plot2DContact::setVisible(bool visible)
{
visible_ = visible;
}
QPoint Plot2DContact::getPosition()
{
return position_;
}
int Plot2DContact::getIndx()
{
return indx_;
}
double Plot2DContact::getLat()
{
return lat_;
}
double Plot2DContact::getLon()
{
return lon_;
}
double Plot2DContact::getDepth()
{
return depth_;
}