##// 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 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
72 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
73 void onMouseWheel(QWheelEvent *event) noexcept;
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 void onDataCacheVariableUpdated();
79 void onDataCacheVariableUpdated();
76 };
80 };
@@ -25,12 +25,17 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
25
25
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
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 // 1 variable -> n qcpplot
34 // 1 variable -> n qcpplot
31 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
35 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
32
36
33 bool m_DoSynchronize;
37 bool m_DoSynchronize;
38 bool m_IsCalibration;
34 };
39 };
35
40
36 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
41 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
@@ -52,10 +57,13 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
52 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
57 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
53 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
58 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
54 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
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 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
63 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
56 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
64 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
57 &QCPAxis::rangeChanged),
65 &QCPAxis::rangeChanged),
58 this, &VisualizationGraphWidget::onRangeChanged);
66 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
59
67
60 // Activates menu when right clicking on the graph
68 // Activates menu when right clicking on the graph
61 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
69 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -149,8 +157,7 SqpDateTime VisualizationGraphWidget::graphRange()
149
157
150 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
158 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
151 {
159 {
152 qCDebug(LOG_VisualizationGraphWidget())
160 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
153 << tr("VisualizationGraphWidget::setGraphRange START");
154 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
161 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
155 ui->widget->replot();
162 ui->widget->replot();
156 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
163 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
@@ -216,7 +223,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
216
223
217 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
224 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
218
225
219 auto zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
226 auto zoomType = impl->getZoomType(t1, t2);
220 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
227 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
221 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
228 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
222
229
@@ -240,14 +247,13 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
240 if (!variable->isInside(currentDateTime)) {
247 if (!variable->isInside(currentDateTime)) {
241 auto variableDateTime = variable->dateTime();
248 auto variableDateTime = variable->dateTime();
242 if (variable->contains(variableDateTimeWithTolerance)) {
249 if (variable->contains(variableDateTimeWithTolerance)) {
243 qCInfo(LOG_VisualizationGraphWidget())
250 qCDebug(LOG_VisualizationGraphWidget())
244 << tr("TORM: Detection zoom in that need request:");
251 << tr("TORM: Detection zoom in that need request:");
245 // add 10% tolerance for each side
252 // add 10% tolerance for each side
246 tolerance
253 tolerance
247 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
254 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
248 variableDateTimeWithTolerance.m_TStart -= tolerance;
255 variableDateTimeWithTolerance.m_TStart -= tolerance;
249 variableDateTimeWithTolerance.m_TEnd += tolerance;
256 variableDateTimeWithTolerance.m_TEnd += tolerance;
250 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
251 }
257 }
252 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
258 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
253 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
259 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
@@ -259,10 +265,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
259 tolerance
265 tolerance
260 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
266 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
261 variableDateTimeWithTolerance.m_TEnd += tolerance;
267 variableDateTimeWithTolerance.m_TEnd += tolerance;
262 zoomType = VisualizationGraphWidgetZoomType::PanRight;
263 }
268 }
264 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
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 auto diffStartToKeepDelta
271 auto diffStartToKeepDelta
267 = variableDateTime.m_TStart - currentDateTime.m_TStart;
272 = variableDateTime.m_TStart - currentDateTime.m_TStart;
268 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
273 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
@@ -271,16 +276,14 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
271 tolerance
276 tolerance
272 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
277 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
273 variableDateTimeWithTolerance.m_TStart -= tolerance;
278 variableDateTimeWithTolerance.m_TStart -= tolerance;
274 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
275 }
279 }
276 else {
280 else {
277 qCInfo(LOG_VisualizationGraphWidget())
281 qCCritical(LOG_VisualizationGraphWidget())
278 << tr("Detection anormal zoom detection: ");
282 << tr("Detection anormal zoom detection: ");
279 zoomType = VisualizationGraphWidgetZoomType::Unknown;
280 }
283 }
281 }
284 }
282 else {
285 else {
283 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
286 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
284 // add 10% tolerance for each side
287 // add 10% tolerance for each side
285 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
288 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
286 variableDateTimeWithTolerance.m_TStart -= tolerance;
289 variableDateTimeWithTolerance.m_TStart -= tolerance;
@@ -288,12 +291,12 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
288 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
291 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
289 }
292 }
290 if (!variable->contains(dateTimeRange)) {
293 if (!variable->contains(dateTimeRange)) {
291 qCInfo(LOG_VisualizationGraphWidget())
294 qCDebug(LOG_VisualizationGraphWidget())
292 << "TORM: Modif on variable datetime detected" << currentDateTime;
295 << "TORM: Modif on variable datetime detected" << currentDateTime;
293 variable->setDateTime(currentDateTime);
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 // CHangement detected, we need to ask controller to request data loading
300 // CHangement detected, we need to ask controller to request data loading
298 emit requestDataLoading(variable, variableDateTimeWithTolerance);
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 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
311 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
309 qCDebug(LOG_VisualizationGraphWidget())
312 qCDebug(LOG_VisualizationGraphWidget())
310 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
313 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
@@ -331,6 +334,16 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
331 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
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 void VisualizationGraphWidget::onDataCacheVariableUpdated()
347 void VisualizationGraphWidget::onDataCacheVariableUpdated()
335 {
348 {
336 // NOTE:
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 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
79 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
80 if (graphChild && (graphChild != graphWidget)) {
80 if (graphChild && (graphChild != graphWidget)) {
81
81
82 auto dateTimeThatKeepDelta = dateTime;
83 auto graphChildRange = graphChild->graphRange();
82 auto graphChildRange = graphChild->graphRange();
84 switch (zoomType) {
83 switch (zoomType) {
85 case VisualizationGraphWidgetZoomType::ZoomIn: {
84 case VisualizationGraphWidgetZoomType::ZoomIn: {
@@ -87,30 +86,45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
87 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
86 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
88 graphChildRange.m_TStart += deltaLeft;
87 graphChildRange.m_TStart += deltaLeft;
89 graphChildRange.m_TEnd -= deltaRight;
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 break;
97 break;
92 }
98 }
93
99
94 case VisualizationGraphWidgetZoomType::ZoomOut: {
100 case VisualizationGraphWidgetZoomType::ZoomOut: {
101 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut");
95 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
102 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
96 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
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 graphChildRange.m_TStart -= deltaLeft;
110 graphChildRange.m_TStart -= deltaLeft;
98 graphChildRange.m_TEnd += deltaRight;
111 graphChildRange.m_TEnd += deltaRight;
99 dateTimeThatKeepDelta = graphChildRange;
100 break;
112 break;
101 }
113 }
102 case VisualizationGraphWidgetZoomType::PanRight: {
114 case VisualizationGraphWidgetZoomType::PanRight: {
115 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight");
103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
116 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 graphChildRange.m_TStart += deltaRight;
117 graphChildRange.m_TStart += deltaRight;
105 graphChildRange.m_TEnd += deltaRight;
118 graphChildRange.m_TEnd += deltaRight;
106 dateTimeThatKeepDelta = graphChildRange;
119 qCCritical(LOG_VisualizationZoneWidget())
120 << tr("TORM: dt") << dateTime.m_TEnd - dateTime.m_TStart;
107 break;
121 break;
108 }
122 }
109 case VisualizationGraphWidgetZoomType::PanLeft: {
123 case VisualizationGraphWidgetZoomType::PanLeft: {
124 qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft");
110 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
125 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
111 graphChildRange.m_TStart -= deltaLeft;
126 graphChildRange.m_TStart -= deltaLeft;
112 graphChildRange.m_TEnd -= deltaLeft;
127 graphChildRange.m_TEnd -= deltaLeft;
113 dateTimeThatKeepDelta = graphChildRange;
114 break;
128 break;
115 }
129 }
116 case VisualizationGraphWidgetZoomType::Unknown: {
130 case VisualizationGraphWidgetZoomType::Unknown: {
@@ -125,7 +139,13 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
125 break;
139 break;
126 }
140 }
127 graphChild->enableSynchronize(false);
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 graphChild->enableSynchronize(true);
149 graphChild->enableSynchronize(true);
130 }
150 }
131 }
151 }
General Comments 0
You need to be logged in to leave comments. Login now