##// END OF EJS Templates
Implementation of the calibration for the synchronization...
perrinel -
r445:a75bae0e8d4d
parent child
Show More
@@ -71,6 +71,10 private slots:
71 71
72 72 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
73 73 void onMouseWheel(QWheelEvent *event) noexcept;
74 /// Slot called when a mouse press was made, to activate the calibration of a graph
75 void onMousePress(QMouseEvent *event) noexcept;
76 /// Slot called when a mouse release was made, to deactivate the calibration of a graph
77 void onMouseRelease(QMouseEvent *event) noexcept;
74 78
75 79 void onDataCacheVariableUpdated();
76 80 };
@@ -25,12 +25,17 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
25 25
26 26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27 27
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize(true) {}
28 explicit VisualizationGraphWidgetPrivate() : m_DoSynchronize(true), m_IsCalibration(false) {}
29
30
31 // Return the operation when range changed
32 VisualizationGraphWidgetZoomType getZoomType(const QCPRange &t1, const QCPRange &t2);
29 33
30 34 // 1 variable -> n qcpplot
31 35 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
32 36
33 37 bool m_DoSynchronize;
38 bool m_IsCalibration;
34 39 };
35 40
36 41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
@@ -52,10 +57,13 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
52 57 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
53 58 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
54 59 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
60 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
61 connect(ui->widget, &QCustomPlot::mouseRelease, this,
62 &VisualizationGraphWidget::onMouseRelease);
55 63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
56 64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
57 65 &QCPAxis::rangeChanged),
58 this, &VisualizationGraphWidget::onRangeChanged);
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
59 67
60 68 // Activates menu when right clicking on the graph
61 69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -149,8 +157,7 SqpDateTime VisualizationGraphWidget::graphRange()
149 157
150 158 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
151 159 {
152 qCDebug(LOG_VisualizationGraphWidget())
153 << tr("VisualizationGraphWidget::setGraphRange START");
160 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
154 161 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
155 162 ui->widget->replot();
156 163 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
@@ -216,7 +223,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
216 223
217 224 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
218 225
219 auto zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
226 auto zoomType = impl->getZoomType(t1, t2);
220 227 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
221 228 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
222 229
@@ -240,14 +247,13 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
240 247 if (!variable->isInside(currentDateTime)) {
241 248 auto variableDateTime = variable->dateTime();
242 249 if (variable->contains(variableDateTimeWithTolerance)) {
243 qCInfo(LOG_VisualizationGraphWidget())
250 qCDebug(LOG_VisualizationGraphWidget())
244 251 << tr("TORM: Detection zoom in that need request:");
245 252 // add 10% tolerance for each side
246 253 tolerance
247 254 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
248 255 variableDateTimeWithTolerance.m_TStart -= tolerance;
249 256 variableDateTimeWithTolerance.m_TEnd += tolerance;
250 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
251 257 }
252 258 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
253 259 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
@@ -259,10 +265,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
259 265 tolerance
260 266 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
261 267 variableDateTimeWithTolerance.m_TEnd += tolerance;
262 zoomType = VisualizationGraphWidgetZoomType::PanRight;
263 268 }
264 269 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
265 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
270 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
266 271 auto diffStartToKeepDelta
267 272 = variableDateTime.m_TStart - currentDateTime.m_TStart;
268 273 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
@@ -271,16 +276,14 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
271 276 tolerance
272 277 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
273 278 variableDateTimeWithTolerance.m_TStart -= tolerance;
274 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
275 279 }
276 280 else {
277 qCInfo(LOG_VisualizationGraphWidget())
281 qCCritical(LOG_VisualizationGraphWidget())
278 282 << tr("Detection anormal zoom detection: ");
279 zoomType = VisualizationGraphWidgetZoomType::Unknown;
280 283 }
281 284 }
282 285 else {
283 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
286 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
284 287 // add 10% tolerance for each side
285 288 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
286 289 variableDateTimeWithTolerance.m_TStart -= tolerance;
@@ -288,12 +291,12 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
288 291 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
289 292 }
290 293 if (!variable->contains(dateTimeRange)) {
291 qCInfo(LOG_VisualizationGraphWidget())
294 qCDebug(LOG_VisualizationGraphWidget())
292 295 << "TORM: Modif on variable datetime detected" << currentDateTime;
293 296 variable->setDateTime(currentDateTime);
294 297 }
295 298
296 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
299 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
297 300 // CHangement detected, we need to ask controller to request data loading
298 301 emit requestDataLoading(variable, variableDateTimeWithTolerance);
299 302 }
@@ -304,7 +307,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
304 307 }
305 308 }
306 309
307 if (impl->m_DoSynchronize) {
310 if (impl->m_DoSynchronize && !impl->m_IsCalibration) {
308 311 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
309 312 qCDebug(LOG_VisualizationGraphWidget())
310 313 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
@@ -331,6 +334,16 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
331 334 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
332 335 }
333 336
337 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
338 {
339 impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
340 }
341
342 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
343 {
344 impl->m_IsCalibration = false;
345 }
346
334 347 void VisualizationGraphWidget::onDataCacheVariableUpdated()
335 348 {
336 349 // NOTE:
@@ -360,3 +373,27 void VisualizationGraphWidget::onDataCacheVariableUpdated()
360 373 }
361 374 }
362 375 }
376
377 VisualizationGraphWidgetZoomType
378 VisualizationGraphWidget::VisualizationGraphWidgetPrivate::getZoomType(const QCPRange &t1,
379 const QCPRange &t2)
380 {
381 // t1.lower <= t2.lower && t2.upper <= t1.upper
382 auto zoomType = VisualizationGraphWidgetZoomType::Unknown;
383 if (t1.lower <= t2.lower && t2.upper <= t1.upper) {
384 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
385 }
386 else if (t1.lower > t2.lower && t1.upper > t2.upper) {
387 zoomType = VisualizationGraphWidgetZoomType::PanRight;
388 }
389 else if (t1.lower < t2.lower && t1.upper < t2.upper) {
390 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
391 }
392 else if (t1.lower > t2.lower && t2.upper > t1.upper) {
393 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
394 }
395 else {
396 qCCritical(LOG_VisualizationGraphWidget()) << "getZoomType: Unknown type detected";
397 }
398 return zoomType;
399 }
@@ -79,7 +79,6 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
79 79 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
80 80 if (graphChild && (graphChild != graphWidget)) {
81 81
82 auto dateTimeThatKeepDelta = dateTime;
83 82 auto graphChildRange = graphChild->graphRange();
84 83 switch (zoomType) {
85 84 case VisualizationGraphWidgetZoomType::ZoomIn: {
@@ -87,30 +86,45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
87 86 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
88 87 graphChildRange.m_TStart += deltaLeft;
89 88 graphChildRange.m_TEnd -= deltaRight;
90 dateTimeThatKeepDelta = graphChildRange;
89 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn");
90 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
91 << deltaLeft;
92 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
93 << deltaRight;
94 qCCritical(LOG_VisualizationZoneWidget())
95 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
96
91 97 break;
92 98 }
93 99
94 100 case VisualizationGraphWidgetZoomType::ZoomOut: {
101 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
95 102 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
96 103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft")
105 << deltaLeft;
106 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight")
107 << deltaRight;
108 qCCritical(LOG_VisualizationZoneWidget())
109 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
97 110 graphChildRange.m_TStart -= deltaLeft;
98 111 graphChildRange.m_TEnd += deltaRight;
99 dateTimeThatKeepDelta = graphChildRange;
100 112 break;
101 113 }
102 114 case VisualizationGraphWidgetZoomType::PanRight: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
103 116 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 117 graphChildRange.m_TStart += deltaRight;
105 118 graphChildRange.m_TEnd += deltaRight;
106 dateTimeThatKeepDelta = graphChildRange;
119 qCCritical(LOG_VisualizationZoneWidget())
120 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
107 121 break;
108 122 }
109 123 case VisualizationGraphWidgetZoomType::PanLeft: {
124 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
110 125 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
111 126 graphChildRange.m_TStart -= deltaLeft;
112 127 graphChildRange.m_TEnd -= deltaLeft;
113 dateTimeThatKeepDelta = graphChildRange;
114 128 break;
115 129 }
116 130 case VisualizationGraphWidgetZoomType::Unknown: {
@@ -125,7 +139,13 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
125 139 break;
126 140 }
127 141 graphChild->enableSynchronize(false);
128 graphChild->setGraphRange(dateTimeThatKeepDelta);
142 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ")
143 << graphChild->graphRange();
144 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ")
145 << graphChildRange;
146 qCCritical(LOG_VisualizationZoneWidget())
147 << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart;
148 graphChild->setGraphRange(graphChildRange);
129 149 graphChild->enableSynchronize(true);
130 150 }
131 151 }
General Comments 0
You need to be logged in to leave comments. Login now