##// END OF EJS Templates
Add synchronization that keep delta
perrinel -
r444:c857efd82181
parent child
Show More
@@ -16,6 +16,11 class QCPRange;
16 class SqpDateTime;
16 class SqpDateTime;
17 class Variable;
17 class Variable;
18
18
19 /**
20 * Possible types of zoom operation
21 */
22 enum class VisualizationGraphWidgetZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown };
23
19 namespace Ui {
24 namespace Ui {
20 class VisualizationGraphWidget;
25 class VisualizationGraphWidget;
21 } // namespace Ui
26 } // namespace Ui
@@ -27,13 +32,16 public:
27 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
32 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
28 virtual ~VisualizationGraphWidget();
33 virtual ~VisualizationGraphWidget();
29
34
35 void enableSynchronize(bool enable);
36
30 void addVariable(std::shared_ptr<Variable> variable);
37 void addVariable(std::shared_ptr<Variable> variable);
31 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
38 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
32 /// Removes a variable from the graph
39 /// Removes a variable from the graph
33 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
40 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
34
41
35 /// Rescale the X axe to range parameter
36 void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range);
42 void setRange(std::shared_ptr<Variable> variable, const SqpDateTime &range);
43 SqpDateTime graphRange();
44 void setGraphRange(const SqpDateTime &range);
37
45
38 // IVisualizationWidget interface
46 // IVisualizationWidget interface
39 void accept(IVisualizationWidgetVisitor *visitor) override;
47 void accept(IVisualizationWidgetVisitor *visitor) override;
@@ -41,8 +49,11 public:
41 bool contains(const Variable &variable) const override;
49 bool contains(const Variable &variable) const override;
42 QString name() const override;
50 QString name() const override;
43
51
52
44 signals:
53 signals:
45 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
54 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
55 void synchronize(const SqpDateTime &dateTime, const SqpDateTime &oldDateTime,
56 VisualizationGraphWidgetZoomType zoomType);
46
57
47
58
48 private:
59 private:
@@ -55,7 +66,8 private slots:
55 /// Slot called when right clicking on the graph (displays a menu)
66 /// Slot called when right clicking on the graph (displays a menu)
56 void onGraphMenuRequested(const QPoint &pos) noexcept;
67 void onGraphMenuRequested(const QPoint &pos) noexcept;
57
68
58 void onRangeChanged(const QCPRange &t1);
69 /// Rescale the X axe to range parameter
70 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
59
71
60 /// 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
61 void onMouseWheel(QWheelEvent *event) noexcept;
73 void onMouseWheel(QWheelEvent *event) noexcept;
@@ -25,8 +25,12 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) {}
29
28 // 1 variable -> n qcpplot
30 // 1 variable -> n qcpplot
29 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
31 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
32
33 bool m_DoSynchronize;
30 };
34 };
31
35
32 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
36 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
@@ -49,9 +53,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
53 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
54 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
55 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 connect(ui->widget->xAxis,
56 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
57 &QCPAxis::rangeChanged),
54 &VisualizationGraphWidget::onRangeChanged);
58 this, &VisualizationGraphWidget::onRangeChanged);
55
59
56 // Activates menu when right clicking on the graph
60 // Activates menu when right clicking on the graph
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
61 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -68,6 +72,11 VisualizationGraphWidget::~VisualizationGraphWidget()
68 delete ui;
72 delete ui;
69 }
73 }
70
74
75 void VisualizationGraphWidget::enableSynchronize(bool enable)
76 {
77 impl->m_DoSynchronize = enable;
78 }
79
71 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
80 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
72 {
81 {
73 // Uses delegate to create the qcpplot components according to the variable
82 // Uses delegate to create the qcpplot components according to the variable
@@ -129,6 +138,22 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable,
129 // for (auto it = componentsIt.first; it != componentsIt.second;) {
138 // for (auto it = componentsIt.first; it != componentsIt.second;) {
130 // }
139 // }
131 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
140 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
141 ui->widget->replot();
142 }
143
144 SqpDateTime VisualizationGraphWidget::graphRange()
145 {
146 auto grapheRange = ui->widget->xAxis->range();
147 return SqpDateTime{grapheRange.lower, grapheRange.upper};
148 }
149
150 void VisualizationGraphWidget::setGraphRange(const SqpDateTime &range)
151 {
152 qCDebug(LOG_VisualizationGraphWidget())
153 << tr("VisualizationGraphWidget::setGraphRange START");
154 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
155 ui->widget->replot();
156 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
132 }
157 }
133
158
134 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
159 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
@@ -184,77 +209,107 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
184 }
209 }
185 }
210 }
186
211
187 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
212 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
188 {
213 {
189 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
214 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
190 << QThread::currentThread()->objectName();
215 << QThread::currentThread()->objectName();
191
216
217 auto dateTimeRange = SqpDateTime{t1.lower, t1.upper};
218
219 auto zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
192 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
220 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
193 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
221 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
194
222
195 auto variable = it->first;
223 auto variable = it->first;
196 auto dateTime = SqpDateTime{t1.lower, t1.upper};
224 auto currentDateTime = dateTimeRange;
197 auto dateTimeRange = dateTime;
198
225
199 auto toleranceFactor = 0.2;
226 auto toleranceFactor = 0.2;
200 auto tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
227 auto tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
201 auto variableDateTimeWithTolerance = dateTime;
228 auto variableDateTimeWithTolerance = currentDateTime;
202 variableDateTimeWithTolerance.m_TStart -= tolerance;
229 variableDateTimeWithTolerance.m_TStart -= tolerance;
203 variableDateTimeWithTolerance.m_TEnd += tolerance;
230 variableDateTimeWithTolerance.m_TEnd += tolerance;
204
231
205 qCDebug(LOG_VisualizationGraphWidget()) << "v" << dateTime;
232 qCDebug(LOG_VisualizationGraphWidget()) << "r" << currentDateTime;
206 qCDebug(LOG_VisualizationGraphWidget()) << "vtol" << variableDateTimeWithTolerance;
233 qCDebug(LOG_VisualizationGraphWidget()) << "t" << variableDateTimeWithTolerance;
234 qCDebug(LOG_VisualizationGraphWidget()) << "v" << variable->dateTime();
207 // If new range with tol is upper than variable datetime parameters. we need to request new
235 // If new range with tol is upper than variable datetime parameters. we need to request new
208 // data
236 // data
209 if (!variable->contains(variableDateTimeWithTolerance)) {
237 if (!variable->contains(variableDateTimeWithTolerance)) {
210
238
211 auto variableDateTimeWithTolerance = dateTime;
239 auto variableDateTimeWithTolerance = currentDateTime;
212 if (!variable->isInside(dateTime)) {
240 if (!variable->isInside(currentDateTime)) {
213 auto variableDateTime = variable->dateTime();
241 auto variableDateTime = variable->dateTime();
214 if (variableDateTime.m_TStart < dateTime.m_TStart) {
242 if (variable->contains(variableDateTimeWithTolerance)) {
215 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
243 qCInfo(LOG_VisualizationGraphWidget())
244 << tr("TORM: Detection zoom in that need request:");
245 // add 10% tolerance for each side
246 tolerance
247 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
248 variableDateTimeWithTolerance.m_TStart -= tolerance;
249 variableDateTimeWithTolerance.m_TEnd += tolerance;
250 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
251 }
252 else if (variableDateTime.m_TStart < currentDateTime.m_TStart) {
253 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to right:");
216
254
217 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
255 auto diffEndToKeepDelta = currentDateTime.m_TEnd - variableDateTime.m_TEnd;
218 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
256 currentDateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
219 // Tolerance have to be added to the right
257 // Tolerance have to be added to the right
220 // add tolerance for right (end) side
258 // add tolerance for right (end) side
221 tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
259 tolerance
260 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
222 variableDateTimeWithTolerance.m_TEnd += tolerance;
261 variableDateTimeWithTolerance.m_TEnd += tolerance;
262 zoomType = VisualizationGraphWidgetZoomType::PanRight;
223 }
263 }
224 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
264 else if (variableDateTime.m_TEnd > currentDateTime.m_TEnd) {
225 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
265 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection pan to left: ");
226 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
266 auto diffStartToKeepDelta
227 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
267 = variableDateTime.m_TStart - currentDateTime.m_TStart;
268 currentDateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
228 // Tolerance have to be added to the left
269 // Tolerance have to be added to the left
229 // add tolerance for left (start) side
270 // add tolerance for left (start) side
230 tolerance = toleranceFactor * (dateTime.m_TEnd - dateTime.m_TStart);
271 tolerance
272 = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
231 variableDateTimeWithTolerance.m_TStart -= tolerance;
273 variableDateTimeWithTolerance.m_TStart -= tolerance;
274 zoomType = VisualizationGraphWidgetZoomType::PanLeft;
232 }
275 }
233 else {
276 else {
234 qCDebug(LOG_VisualizationGraphWidget())
277 qCInfo(LOG_VisualizationGraphWidget())
235 << tr("Detection anormal zoom detection: ");
278 << tr("Detection anormal zoom detection: ");
279 zoomType = VisualizationGraphWidgetZoomType::Unknown;
236 }
280 }
237 }
281 }
238 else {
282 else {
239 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
283 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Detection zoom out: ");
240 // add 10% tolerance for each side
284 // add 10% tolerance for each side
241 tolerance = 0.2 * (dateTime.m_TEnd - dateTime.m_TStart);
285 tolerance = toleranceFactor * (currentDateTime.m_TEnd - currentDateTime.m_TStart);
242 variableDateTimeWithTolerance.m_TStart -= tolerance;
286 variableDateTimeWithTolerance.m_TStart -= tolerance;
243 variableDateTimeWithTolerance.m_TEnd += tolerance;
287 variableDateTimeWithTolerance.m_TEnd += tolerance;
288 zoomType = VisualizationGraphWidgetZoomType::ZoomOut;
244 }
289 }
245 if (!variable->contains(dateTimeRange)) {
290 if (!variable->contains(dateTimeRange)) {
246 qCDebug(LOG_VisualizationGraphWidget())
291 qCInfo(LOG_VisualizationGraphWidget())
247 << "TORM: Modif on variable datetime detected" << dateTime;
292 << "TORM: Modif on variable datetime detected" << currentDateTime;
248 variable->setDateTime(dateTime);
293 variable->setDateTime(currentDateTime);
249 }
294 }
250
295
251 qCDebug(LOG_VisualizationGraphWidget()) << tr("Request data detection: ");
296 qCInfo(LOG_VisualizationGraphWidget()) << tr("TORM: Request data detection: ");
252 // CHangement detected, we need to ask controller to request data loading
297 // CHangement detected, we need to ask controller to request data loading
253 emit requestDataLoading(variable, variableDateTimeWithTolerance);
298 emit requestDataLoading(variable, variableDateTimeWithTolerance);
254 }
299 }
255 else {
300 else {
256 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
301 qCInfo(LOG_VisualizationGraphWidget())
302 << tr("TORM: Detection zoom in that doesn't need request: ");
303 zoomType = VisualizationGraphWidgetZoomType::ZoomIn;
304 }
257 }
305 }
306
307 if (impl->m_DoSynchronize) {
308 auto oldDateTime = SqpDateTime{t2.lower, t2.upper};
309 qCDebug(LOG_VisualizationGraphWidget())
310 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
311 << QThread::currentThread()->objectName();
312 emit synchronize(dateTimeRange, oldDateTime, zoomType);
258 }
313 }
259 }
314 }
260
315
@@ -1,8 +1,11
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
3 #include "Data/SqpDateTime.h"
4
2 #include "Visualization/IVisualizationWidgetVisitor.h"
5 #include "Visualization/IVisualizationWidgetVisitor.h"
6 #include "Visualization/VisualizationGraphWidget.h"
3 #include "ui_VisualizationZoneWidget.h"
7 #include "ui_VisualizationZoneWidget.h"
4
8
5 #include "Visualization/VisualizationGraphWidget.h"
6
9
7 #include <SqpApplication.h>
10 #include <SqpApplication.h>
8
11
@@ -57,6 +60,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
57 auto graphWidget = new VisualizationGraphWidget{
60 auto graphWidget = new VisualizationGraphWidget{
58 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
61 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
59
62
63
60 // Set graph properties
64 // Set graph properties
61 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
65 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
62 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
66 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
@@ -65,6 +69,71 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
65
69
66 graphWidget->addVariable(variable);
70 graphWidget->addVariable(variable);
67
71
72 // Lambda to synchronize zone widget
73 auto synchronizeZoneWidget = [this, graphWidget](const SqpDateTime &dateTime,
74 const SqpDateTime &oldDateTime,
75 VisualizationGraphWidgetZoomType zoomType) {
76 auto frameLayout = ui->visualizationZoneFrame->layout();
77 for (auto i = 0; i < frameLayout->count(); ++i) {
78 auto graphChild
79 = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget());
80 if (graphChild && (graphChild != graphWidget)) {
81
82 auto dateTimeThatKeepDelta = dateTime;
83 auto graphChildRange = graphChild->graphRange();
84 switch (zoomType) {
85 case VisualizationGraphWidgetZoomType::ZoomIn: {
86 auto deltaLeft = dateTime.m_TStart - oldDateTime.m_TStart;
87 auto deltaRight = oldDateTime.m_TEnd - dateTime.m_TEnd;
88 graphChildRange.m_TStart += deltaLeft;
89 graphChildRange.m_TEnd -= deltaRight;
90 dateTimeThatKeepDelta = graphChildRange;
91 break;
92 }
93
94 case VisualizationGraphWidgetZoomType::ZoomOut: {
95 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
96 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
97 graphChildRange.m_TStart -= deltaLeft;
98 graphChildRange.m_TEnd += deltaRight;
99 dateTimeThatKeepDelta = graphChildRange;
100 break;
101 }
102 case VisualizationGraphWidgetZoomType::PanRight: {
103 auto deltaRight = dateTime.m_TEnd - oldDateTime.m_TEnd;
104 graphChildRange.m_TStart += deltaRight;
105 graphChildRange.m_TEnd += deltaRight;
106 dateTimeThatKeepDelta = graphChildRange;
107 break;
108 }
109 case VisualizationGraphWidgetZoomType::PanLeft: {
110 auto deltaLeft = oldDateTime.m_TStart - dateTime.m_TStart;
111 graphChildRange.m_TStart -= deltaLeft;
112 graphChildRange.m_TEnd -= deltaLeft;
113 dateTimeThatKeepDelta = graphChildRange;
114 break;
115 }
116 case VisualizationGraphWidgetZoomType::Unknown: {
117 qCCritical(LOG_VisualizationZoneWidget())
118 << tr("Impossible to synchronize: zoom type unknown");
119 break;
120 }
121 default:
122 qCCritical(LOG_VisualizationZoneWidget())
123 << tr("Impossible to synchronize: zoom type not take into account");
124 // No action
125 break;
126 }
127 graphChild->enableSynchronize(false);
128 graphChild->setGraphRange(dateTimeThatKeepDelta);
129 graphChild->enableSynchronize(true);
130 }
131 }
132 };
133
134 // connection for synchronization
135 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
136
68 return graphWidget;
137 return graphWidget;
69 }
138 }
70
139
General Comments 0
You need to be logged in to leave comments. Login now