@@ -1,244 +1,256 | |||||
1 | #include "Visualization/VisualizationZoneWidget.h" |
|
1 | #include "Visualization/VisualizationZoneWidget.h" | |
2 |
|
2 | |||
3 |
|
3 | |||
4 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
4 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
5 | #include "Visualization/VisualizationGraphWidget.h" |
|
5 | #include "Visualization/VisualizationGraphWidget.h" | |
6 | #include "ui_VisualizationZoneWidget.h" |
|
6 | #include "ui_VisualizationZoneWidget.h" | |
7 |
|
7 | |||
8 | #include <Data/SqpRange.h> |
|
8 | #include <Data/SqpRange.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <QUuid> |
|
12 | #include <QUuid> | |
13 | #include <SqpApplication.h> |
|
13 | #include <SqpApplication.h> | |
14 |
|
14 | |||
15 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") |
|
15 | Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget") | |
16 |
|
16 | |||
17 | namespace { |
|
17 | namespace { | |
18 |
|
18 | |||
19 | /// Minimum height for graph added in zones (in pixels) |
|
19 | /// Minimum height for graph added in zones (in pixels) | |
20 | const auto GRAPH_MINIMUM_HEIGHT = 300; |
|
20 | const auto GRAPH_MINIMUM_HEIGHT = 300; | |
21 |
|
21 | |||
22 | /// Generates a default name for a new graph, according to the number of graphs already displayed in |
|
22 | /// Generates a default name for a new graph, according to the number of graphs already displayed in | |
23 | /// the zone |
|
23 | /// the zone | |
24 | QString defaultGraphName(const QLayout &layout) |
|
24 | QString defaultGraphName(const QLayout &layout) | |
25 | { |
|
25 | { | |
26 | auto count = 0; |
|
26 | auto count = 0; | |
27 | for (auto i = 0; i < layout.count(); ++i) { |
|
27 | for (auto i = 0; i < layout.count(); ++i) { | |
28 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { |
|
28 | if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) { | |
29 | count++; |
|
29 | count++; | |
30 | } |
|
30 | } | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | return QObject::tr("Graph %1").arg(count + 1); |
|
33 | return QObject::tr("Graph %1").arg(count + 1); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | } // namespace |
|
36 | } // namespace | |
37 |
|
37 | |||
38 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { |
|
38 | struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate { | |
39 |
|
39 | |||
40 | explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {} |
|
40 | explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {} | |
41 | QUuid m_SynchronisationGroupId; |
|
41 | QUuid m_SynchronisationGroupId; | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) |
|
44 | VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent) | |
45 | : QWidget{parent}, |
|
45 | : QWidget{parent}, | |
46 | ui{new Ui::VisualizationZoneWidget}, |
|
46 | ui{new Ui::VisualizationZoneWidget}, | |
47 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} |
|
47 | impl{spimpl::make_unique_impl<VisualizationZoneWidgetPrivate>()} | |
48 | { |
|
48 | { | |
49 | ui->setupUi(this); |
|
49 | ui->setupUi(this); | |
50 |
|
50 | |||
51 | ui->zoneNameLabel->setText(name); |
|
51 | ui->zoneNameLabel->setText(name); | |
52 |
|
52 | |||
53 | // 'Close' options : widget is deleted when closed |
|
53 | // 'Close' options : widget is deleted when closed | |
54 | setAttribute(Qt::WA_DeleteOnClose); |
|
54 | setAttribute(Qt::WA_DeleteOnClose); | |
55 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); |
|
55 | connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationZoneWidget::close); | |
56 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); |
|
56 | ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton)); | |
57 |
|
57 | |||
58 | // Synchronisation id |
|
58 | // Synchronisation id | |
59 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", |
|
59 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronizationGroupId", | |
60 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
60 | Qt::QueuedConnection, Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | VisualizationZoneWidget::~VisualizationZoneWidget() |
|
63 | VisualizationZoneWidget::~VisualizationZoneWidget() | |
64 | { |
|
64 | { | |
65 | delete ui; |
|
65 | delete ui; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) |
|
68 | void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget) | |
69 | { |
|
69 | { | |
70 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); |
|
70 | ui->visualizationZoneFrame->layout()->addWidget(graphWidget); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) |
|
73 | VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable) | |
74 | { |
|
74 | { | |
75 | auto graphWidget = new VisualizationGraphWidget{ |
|
75 | auto graphWidget = new VisualizationGraphWidget{ | |
76 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; |
|
76 | defaultGraphName(*ui->visualizationZoneFrame->layout()), this}; | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | // Set graph properties |
|
79 | // Set graph properties | |
80 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); |
|
80 | graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | |
81 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); |
|
81 | graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT); | |
82 |
|
82 | |||
83 |
|
83 | |||
84 | // Lambda to synchronize zone widget |
|
84 | // Lambda to synchronize zone widget | |
85 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, |
|
85 | auto synchronizeZoneWidget = [this, graphWidget](const SqpRange &graphRange, | |
86 | const SqpRange &oldGraphRange) { |
|
86 | const SqpRange &oldGraphRange) { | |
87 |
|
87 | |||
88 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
88 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
89 | auto frameLayout = ui->visualizationZoneFrame->layout(); |
|
89 | auto frameLayout = ui->visualizationZoneFrame->layout(); | |
90 | for (auto i = 0; i < frameLayout->count(); ++i) { |
|
90 | for (auto i = 0; i < frameLayout->count(); ++i) { | |
91 | auto graphChild |
|
91 | auto graphChild | |
92 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); |
|
92 | = dynamic_cast<VisualizationGraphWidget *>(frameLayout->itemAt(i)->widget()); | |
93 | if (graphChild && (graphChild != graphWidget)) { |
|
93 | if (graphChild && (graphChild != graphWidget)) { | |
94 |
|
94 | |||
95 | auto graphChildRange = graphChild->graphRange(); |
|
95 | auto graphChildRange = graphChild->graphRange(); | |
96 | switch (zoomType) { |
|
96 | switch (zoomType) { | |
97 | case AcquisitionZoomType::ZoomIn: { |
|
97 | case AcquisitionZoomType::ZoomIn: { | |
98 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
98 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
99 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
99 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
100 | graphChildRange.m_TStart += deltaLeft; |
|
100 | graphChildRange.m_TStart += deltaLeft; | |
101 | graphChildRange.m_TEnd -= deltaRight; |
|
101 | graphChildRange.m_TEnd -= deltaRight; | |
102 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); |
|
102 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomIn"); | |
103 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
103 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
104 | << deltaLeft; |
|
104 | << deltaLeft; | |
105 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
105 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
106 | << deltaRight; |
|
106 | << deltaRight; | |
107 | qCCritical(LOG_VisualizationZoneWidget()) |
|
107 | qCCritical(LOG_VisualizationZoneWidget()) | |
108 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
108 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
109 |
|
109 | |||
110 | break; |
|
110 | break; | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | case AcquisitionZoomType::ZoomOut: { |
|
113 | case AcquisitionZoomType::ZoomOut: { | |
114 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); |
|
114 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: ZoomOut"); | |
115 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
115 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
116 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
116 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
117 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") |
|
117 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaLeft") | |
118 | << deltaLeft; |
|
118 | << deltaLeft; | |
119 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") |
|
119 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: deltaRight") | |
120 | << deltaRight; |
|
120 | << deltaRight; | |
121 | qCCritical(LOG_VisualizationZoneWidget()) |
|
121 | qCCritical(LOG_VisualizationZoneWidget()) | |
122 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
122 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
123 | graphChildRange.m_TStart -= deltaLeft; |
|
123 | graphChildRange.m_TStart -= deltaLeft; | |
124 | graphChildRange.m_TEnd += deltaRight; |
|
124 | graphChildRange.m_TEnd += deltaRight; | |
125 | break; |
|
125 | break; | |
126 | } |
|
126 | } | |
127 | case AcquisitionZoomType::PanRight: { |
|
127 | case AcquisitionZoomType::PanRight: { | |
128 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); |
|
128 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanRight"); | |
129 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
129 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
130 | graphChildRange.m_TStart += deltaRight; |
|
130 | graphChildRange.m_TStart += deltaRight; | |
131 | graphChildRange.m_TEnd += deltaRight; |
|
131 | graphChildRange.m_TEnd += deltaRight; | |
132 | qCCritical(LOG_VisualizationZoneWidget()) |
|
132 | qCCritical(LOG_VisualizationZoneWidget()) | |
133 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; |
|
133 | << tr("TORM: dt") << graphRange.m_TEnd - graphRange.m_TStart; | |
134 | break; |
|
134 | break; | |
135 | } |
|
135 | } | |
136 | case AcquisitionZoomType::PanLeft: { |
|
136 | case AcquisitionZoomType::PanLeft: { | |
137 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); |
|
137 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: PanLeft"); | |
138 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
138 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
139 | graphChildRange.m_TStart -= deltaLeft; |
|
139 | graphChildRange.m_TStart -= deltaLeft; | |
140 | graphChildRange.m_TEnd -= deltaLeft; |
|
140 | graphChildRange.m_TEnd -= deltaLeft; | |
141 | break; |
|
141 | break; | |
142 | } |
|
142 | } | |
143 | case AcquisitionZoomType::Unknown: { |
|
143 | case AcquisitionZoomType::Unknown: { | |
144 | qCCritical(LOG_VisualizationZoneWidget()) |
|
144 | qCCritical(LOG_VisualizationZoneWidget()) | |
145 | << tr("Impossible to synchronize: zoom type unknown"); |
|
145 | << tr("Impossible to synchronize: zoom type unknown"); | |
146 | break; |
|
146 | break; | |
147 | } |
|
147 | } | |
148 | default: |
|
148 | default: | |
149 | qCCritical(LOG_VisualizationZoneWidget()) |
|
149 | qCCritical(LOG_VisualizationZoneWidget()) | |
150 | << tr("Impossible to synchronize: zoom type not take into account"); |
|
150 | << tr("Impossible to synchronize: zoom type not take into account"); | |
151 | // No action |
|
151 | // No action | |
152 | break; |
|
152 | break; | |
153 | } |
|
153 | } | |
154 | graphChild->enableAcquisition(false); |
|
154 | graphChild->enableAcquisition(false); | |
155 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") |
|
155 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range before: ") | |
156 | << graphChild->graphRange(); |
|
156 | << graphChild->graphRange(); | |
157 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") |
|
157 | qCCritical(LOG_VisualizationZoneWidget()) << tr("TORM: Range after : ") | |
158 | << graphChildRange; |
|
158 | << graphChildRange; | |
159 | qCCritical(LOG_VisualizationZoneWidget()) |
|
159 | qCCritical(LOG_VisualizationZoneWidget()) | |
160 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; |
|
160 | << tr("TORM: child dt") << graphChildRange.m_TEnd - graphChildRange.m_TStart; | |
161 | graphChild->setGraphRange(graphChildRange); |
|
161 | graphChild->setGraphRange(graphChildRange); | |
162 | graphChild->enableAcquisition(true); |
|
162 | graphChild->enableAcquisition(true); | |
163 | } |
|
163 | } | |
164 | } |
|
164 | } | |
165 | }; |
|
165 | }; | |
166 |
|
166 | |||
167 | // connection for synchronization |
|
167 | // connection for synchronization | |
168 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); |
|
168 | connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget); | |
169 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, |
|
169 | connect(graphWidget, &VisualizationGraphWidget::variableAdded, this, | |
170 | &VisualizationZoneWidget::onVariableAdded); |
|
170 | &VisualizationZoneWidget::onVariableAdded); | |
171 |
|
171 | |||
172 | auto range = SqpRange{}; |
|
172 | auto range = SqpRange{}; | |
173 |
|
173 | |||
174 | // Apply visitor to graph children |
|
174 | // Apply visitor to graph children | |
175 | auto layout = ui->visualizationZoneFrame->layout(); |
|
175 | auto layout = ui->visualizationZoneFrame->layout(); | |
176 | if (layout->count() > 0) { |
|
176 | if (layout->count() > 0) { | |
177 | // Case of a new graph in a existant zone |
|
177 | // Case of a new graph in a existant zone | |
178 | if (auto visualizationGraphWidget |
|
178 | if (auto visualizationGraphWidget | |
179 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
179 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
180 | range = visualizationGraphWidget->graphRange(); |
|
180 | range = visualizationGraphWidget->graphRange(); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 | else { |
|
183 | else { | |
184 | // Case of a new graph as the first of the zone |
|
184 | // Case of a new graph as the first of the zone | |
185 | range = variable->range(); |
|
185 | range = variable->range(); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | this->addGraph(graphWidget); |
|
188 | this->addGraph(graphWidget); | |
189 |
|
189 | |||
190 | graphWidget->addVariable(variable, range); |
|
190 | graphWidget->addVariable(variable, range); | |
191 | // TODO: get y using variable range |
|
191 | ||
192 | graphWidget->setYRange(SqpRange{-10, 10}); |
|
192 | // get y using variable range | |
|
193 | if (auto dataSeries = variable->dataSeries()) { | |||
|
194 | auto valuesBounds = dataSeries->valuesBounds(range.m_TStart, range.m_TEnd); | |||
|
195 | auto end = dataSeries->cend(); | |||
|
196 | if (valuesBounds.first != end && valuesBounds.second != end) { | |||
|
197 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |||
|
198 | ||||
|
199 | auto minValue = rangeValue(valuesBounds.first->minValue()); | |||
|
200 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); | |||
|
201 | ||||
|
202 | graphWidget->setYRange(SqpRange{minValue, maxValue}); | |||
|
203 | } | |||
|
204 | } | |||
193 |
|
205 | |||
194 | return graphWidget; |
|
206 | return graphWidget; | |
195 | } |
|
207 | } | |
196 |
|
208 | |||
197 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
209 | void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor) | |
198 | { |
|
210 | { | |
199 | if (visitor) { |
|
211 | if (visitor) { | |
200 | visitor->visitEnter(this); |
|
212 | visitor->visitEnter(this); | |
201 |
|
213 | |||
202 | // Apply visitor to graph children |
|
214 | // Apply visitor to graph children | |
203 | auto layout = ui->visualizationZoneFrame->layout(); |
|
215 | auto layout = ui->visualizationZoneFrame->layout(); | |
204 | for (auto i = 0; i < layout->count(); ++i) { |
|
216 | for (auto i = 0; i < layout->count(); ++i) { | |
205 | if (auto item = layout->itemAt(i)) { |
|
217 | if (auto item = layout->itemAt(i)) { | |
206 | // Widgets different from graphs are not visited (no action) |
|
218 | // Widgets different from graphs are not visited (no action) | |
207 | if (auto visualizationGraphWidget |
|
219 | if (auto visualizationGraphWidget | |
208 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { |
|
220 | = dynamic_cast<VisualizationGraphWidget *>(item->widget())) { | |
209 | visualizationGraphWidget->accept(visitor); |
|
221 | visualizationGraphWidget->accept(visitor); | |
210 | } |
|
222 | } | |
211 | } |
|
223 | } | |
212 | } |
|
224 | } | |
213 |
|
225 | |||
214 | visitor->visitLeave(this); |
|
226 | visitor->visitLeave(this); | |
215 | } |
|
227 | } | |
216 | else { |
|
228 | else { | |
217 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); |
|
229 | qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null"); | |
218 | } |
|
230 | } | |
219 | } |
|
231 | } | |
220 |
|
232 | |||
221 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const |
|
233 | bool VisualizationZoneWidget::canDrop(const Variable &variable) const | |
222 | { |
|
234 | { | |
223 | // A tab can always accomodate a variable |
|
235 | // A tab can always accomodate a variable | |
224 | Q_UNUSED(variable); |
|
236 | Q_UNUSED(variable); | |
225 | return true; |
|
237 | return true; | |
226 | } |
|
238 | } | |
227 |
|
239 | |||
228 | bool VisualizationZoneWidget::contains(const Variable &variable) const |
|
240 | bool VisualizationZoneWidget::contains(const Variable &variable) const | |
229 | { |
|
241 | { | |
230 | Q_UNUSED(variable); |
|
242 | Q_UNUSED(variable); | |
231 | return false; |
|
243 | return false; | |
232 | } |
|
244 | } | |
233 |
|
245 | |||
234 | QString VisualizationZoneWidget::name() const |
|
246 | QString VisualizationZoneWidget::name() const | |
235 | { |
|
247 | { | |
236 | return ui->zoneNameLabel->text(); |
|
248 | return ui->zoneNameLabel->text(); | |
237 | } |
|
249 | } | |
238 |
|
250 | |||
239 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) |
|
251 | void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable) | |
240 | { |
|
252 | { | |
241 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", |
|
253 | QMetaObject::invokeMethod(&sqpApp->variableController(), "onAddSynchronized", | |
242 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), |
|
254 | Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable), | |
243 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); |
|
255 | Q_ARG(QUuid, impl->m_SynchronisationGroupId)); | |
244 | } |
|
256 | } |
@@ -1,197 +1,197 | |||||
1 | #include "AmdaProvider.h" |
|
1 | #include "AmdaProvider.h" | |
2 | #include "AmdaResultParser.h" |
|
2 | #include "AmdaResultParser.h" | |
3 |
|
3 | |||
4 | #include "SqpApplication.h" |
|
4 | #include "SqpApplication.h" | |
5 | #include <Data/DataSeries.h> |
|
5 | #include <Data/DataSeries.h> | |
6 | #include <Data/IDataSeries.h> |
|
6 | #include <Data/IDataSeries.h> | |
7 | #include <Data/ScalarSeries.h> |
|
7 | #include <Data/ScalarSeries.h> | |
8 | #include <Time/TimeController.h> |
|
8 | #include <Time/TimeController.h> | |
9 | #include <Variable/Variable.h> |
|
9 | #include <Variable/Variable.h> | |
10 | #include <Variable/VariableController.h> |
|
10 | #include <Variable/VariableController.h> | |
11 |
|
11 | |||
12 | #include <QObject> |
|
12 | #include <QObject> | |
13 | #include <QtTest> |
|
13 | #include <QtTest> | |
14 |
|
14 | |||
15 | #include <memory> |
|
15 | #include <memory> | |
16 |
|
16 | |||
17 | // TEST with REF: |
|
17 | // TEST with REF: | |
18 | // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00 |
|
18 | // AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00 | |
19 | // imf(0) - Type : Local Parameter @ CDPP/AMDA - |
|
19 | // imf(0) - Type : Local Parameter @ CDPP/AMDA - | |
20 | // Name : bx_gse - Units : nT - Size : 1 - |
|
20 | // Name : bx_gse - Units : nT - Size : 1 - | |
21 | // Frame : GSE - Mission : ACE - |
|
21 | // Frame : GSE - Mission : ACE - | |
22 | // Instrument : MFI - Dataset : mfi_final-prelim |
|
22 | // Instrument : MFI - Dataset : mfi_final-prelim | |
23 | // REFERENCE DOWNLOAD FILE = |
|
23 | // REFERENCE DOWNLOAD FILE = | |
24 | // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00¶meterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0 |
|
24 | // http://amda.irap.omp.eu/php/rest/getParameter.php?startTime=2012-01-01T12:00:00&stopTime=2012-01-03T12:00:00¶meterID=imf(0)&outputFormat=ASCII&timeFormat=ISO8601&gzip=0 | |
25 |
|
25 | |||
26 | namespace { |
|
26 | namespace { | |
27 |
|
27 | |||
28 | /// Path for the tests |
|
28 | /// Path for the tests | |
29 | const auto TESTS_RESOURCES_PATH |
|
29 | const auto TESTS_RESOURCES_PATH | |
30 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath(); |
|
30 | = QFileInfo{QString{AMDA_TESTS_RESOURCES_DIR}, "TestAmdaAcquisition"}.absoluteFilePath(); | |
31 |
|
31 | |||
32 | const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"}; |
|
32 | const auto TESTS_AMDA_REF_FILE = QString{"AmdaData-2012-01-01-12-00-00_2012-01-03-12-00-00.txt"}; | |
33 |
|
33 | |||
34 | template <typename T> |
|
34 | template <typename T> | |
35 | bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange, |
|
35 | bool compareDataSeries(std::shared_ptr<IDataSeries> candidate, SqpRange candidateCacheRange, | |
36 | std::shared_ptr<IDataSeries> reference) |
|
36 | std::shared_ptr<IDataSeries> reference) | |
37 | { |
|
37 | { | |
38 | auto compareLambda = [](const auto &it1, const auto &it2) { |
|
38 | auto compareLambda = [](const auto &it1, const auto &it2) { | |
39 | return (it1.x() == it2.x()) && (it1.value() == it2.value()); |
|
39 | return (it1.x() == it2.x()) && (it1.value() == it2.value()); | |
40 | }; |
|
40 | }; | |
41 |
|
41 | |||
42 | auto candidateDS = std::dynamic_pointer_cast<T>(candidate); |
|
42 | auto candidateDS = std::dynamic_pointer_cast<T>(candidate); | |
43 | auto referenceDS = std::dynamic_pointer_cast<T>(reference); |
|
43 | auto referenceDS = std::dynamic_pointer_cast<T>(reference); | |
44 |
|
44 | |||
45 | if (candidateDS && referenceDS) { |
|
45 | if (candidateDS && referenceDS) { | |
46 |
|
46 | |||
47 | auto itRefs |
|
47 | auto itRefs | |
48 |
= referenceDS-> |
|
48 | = referenceDS->xAxisRange(candidateCacheRange.m_TStart, candidateCacheRange.m_TEnd); | |
49 | qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend()) |
|
49 | qDebug() << " DISTANCE" << std::distance(candidateDS->cbegin(), candidateDS->cend()) | |
50 | << std::distance(itRefs.first, itRefs.second); |
|
50 | << std::distance(itRefs.first, itRefs.second); | |
51 |
|
51 | |||
52 | // auto xcValue = candidateDS->valuesData()->data(); |
|
52 | // auto xcValue = candidateDS->valuesData()->data(); | |
53 | // auto dist = std::distance(itRefs.first, itRefs.second); |
|
53 | // auto dist = std::distance(itRefs.first, itRefs.second); | |
54 | // auto it = itRefs.first; |
|
54 | // auto it = itRefs.first; | |
55 | // for (auto i = 0; i < dist - 1; ++i) { |
|
55 | // for (auto i = 0; i < dist - 1; ++i) { | |
56 | // ++it; |
|
56 | // ++it; | |
57 | // qInfo() << "END:" << it->value(); |
|
57 | // qInfo() << "END:" << it->value(); | |
58 | // } |
|
58 | // } | |
59 | // qDebug() << "END:" << it->value() << xcValue.last(); |
|
59 | // qDebug() << "END:" << it->value() << xcValue.last(); | |
60 |
|
60 | |||
61 | return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second, |
|
61 | return std::equal(candidateDS->cbegin(), candidateDS->cend(), itRefs.first, itRefs.second, | |
62 | compareLambda); |
|
62 | compareLambda); | |
63 | } |
|
63 | } | |
64 | else { |
|
64 | else { | |
65 | return false; |
|
65 | return false; | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | class TestAmdaAcquisition : public QObject { |
|
70 | class TestAmdaAcquisition : public QObject { | |
71 | Q_OBJECT |
|
71 | Q_OBJECT | |
72 |
|
72 | |||
73 | private slots: |
|
73 | private slots: | |
74 | void testAcquisition(); |
|
74 | void testAcquisition(); | |
75 | }; |
|
75 | }; | |
76 |
|
76 | |||
77 | void TestAmdaAcquisition::testAcquisition() |
|
77 | void TestAmdaAcquisition::testAcquisition() | |
78 | { |
|
78 | { | |
79 | // READ the ref file: |
|
79 | // READ the ref file: | |
80 | auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath(); |
|
80 | auto filePath = QFileInfo{TESTS_RESOURCES_PATH, TESTS_AMDA_REF_FILE}.absoluteFilePath(); | |
81 | auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR); |
|
81 | auto results = AmdaResultParser::readTxt(filePath, AmdaResultParser::ValueType::SCALAR); | |
82 |
|
82 | |||
83 | auto provider = std::make_shared<AmdaProvider>(); |
|
83 | auto provider = std::make_shared<AmdaProvider>(); | |
84 | auto timeController = std::make_unique<TimeController>(); |
|
84 | auto timeController = std::make_unique<TimeController>(); | |
85 |
|
85 | |||
86 | auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}}; |
|
86 | auto varRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 3, 0, 0}}; | |
87 | auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}}; |
|
87 | auto varRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}}; | |
88 |
|
88 | |||
89 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; |
|
89 | auto sqpR = SqpRange{DateUtils::secondsSinceEpoch(varRS), DateUtils::secondsSinceEpoch(varRE)}; | |
90 |
|
90 | |||
91 | timeController->onTimeToUpdate(sqpR); |
|
91 | timeController->onTimeToUpdate(sqpR); | |
92 |
|
92 | |||
93 | QVariantHash metaData; |
|
93 | QVariantHash metaData; | |
94 | metaData.insert("dataType", "scalar"); |
|
94 | metaData.insert("dataType", "scalar"); | |
95 | metaData.insert("xml:id", "imf(0)"); |
|
95 | metaData.insert("xml:id", "imf(0)"); | |
96 |
|
96 | |||
97 | VariableController vc; |
|
97 | VariableController vc; | |
98 | vc.setTimeController(timeController.get()); |
|
98 | vc.setTimeController(timeController.get()); | |
99 |
|
99 | |||
100 | auto var = vc.createVariable("bx_gse", metaData, provider); |
|
100 | auto var = vc.createVariable("bx_gse", metaData, provider); | |
101 |
|
101 | |||
102 | // 1 : Variable creation |
|
102 | // 1 : Variable creation | |
103 | QCOMPARE(var->range().m_TStart, sqpR.m_TStart); |
|
103 | QCOMPARE(var->range().m_TStart, sqpR.m_TStart); | |
104 | QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd); |
|
104 | QCOMPARE(var->range().m_TEnd, sqpR.m_TEnd); | |
105 |
|
105 | |||
106 | qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime(); |
|
106 | qDebug() << " 1: TIMECONTROLLER" << timeController->dateTime(); | |
107 | qDebug() << " 1: RANGE " << var->range(); |
|
107 | qDebug() << " 1: RANGE " << var->range(); | |
108 | qDebug() << " 1: CACHERANGE" << var->cacheRange(); |
|
108 | qDebug() << " 1: CACHERANGE" << var->cacheRange(); | |
109 |
|
109 | |||
110 | // wait for 10 sec before asking next request toi permit asynchrone process to finish. |
|
110 | // wait for 10 sec before asking next request toi permit asynchrone process to finish. | |
111 | auto timeToWaitMs = 10000; |
|
111 | auto timeToWaitMs = 10000; | |
112 |
|
112 | |||
113 | QEventLoop loop; |
|
113 | QEventLoop loop; | |
114 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); |
|
114 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); | |
115 | loop.exec(); |
|
115 | loop.exec(); | |
116 |
|
116 | |||
117 | // Tests on acquisition operation |
|
117 | // Tests on acquisition operation | |
118 |
|
118 | |||
119 | int count = 1; |
|
119 | int count = 1; | |
120 |
|
120 | |||
121 | auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) { |
|
121 | auto requestDataLoading = [&vc, var, timeToWaitMs, results, &count](auto tStart, auto tEnd) { | |
122 | ++count; |
|
122 | ++count; | |
123 |
|
123 | |||
124 | auto nextSqpR |
|
124 | auto nextSqpR | |
125 | = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)}; |
|
125 | = SqpRange{DateUtils::secondsSinceEpoch(tStart), DateUtils::secondsSinceEpoch(tEnd)}; | |
126 | vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR, |
|
126 | vc.onRequestDataLoading(QVector<std::shared_ptr<Variable> >{} << var, nextSqpR, | |
127 | var->range(), true); |
|
127 | var->range(), true); | |
128 |
|
128 | |||
129 | QEventLoop loop; |
|
129 | QEventLoop loop; | |
130 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); |
|
130 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); | |
131 | loop.exec(); |
|
131 | loop.exec(); | |
132 |
|
132 | |||
133 | qDebug() << count << "RANGE " << var->range(); |
|
133 | qDebug() << count << "RANGE " << var->range(); | |
134 | qDebug() << count << "CACHERANGE" << var->cacheRange(); |
|
134 | qDebug() << count << "CACHERANGE" << var->cacheRange(); | |
135 |
|
135 | |||
136 | QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart); |
|
136 | QCOMPARE(var->range().m_TStart, nextSqpR.m_TStart); | |
137 | QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd); |
|
137 | QCOMPARE(var->range().m_TEnd, nextSqpR.m_TEnd); | |
138 |
|
138 | |||
139 | // Verify dataserie |
|
139 | // Verify dataserie | |
140 | QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results)); |
|
140 | QVERIFY(compareDataSeries<ScalarSeries>(var->dataSeries(), var->cacheRange(), results)); | |
141 |
|
141 | |||
142 | }; |
|
142 | }; | |
143 |
|
143 | |||
144 | // 2 : pan (jump) left for one hour |
|
144 | // 2 : pan (jump) left for one hour | |
145 | auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}}; |
|
145 | auto nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 1, 0, 0}}; | |
146 | auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}}; |
|
146 | auto nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 2, 0, 0}}; | |
147 | // requestDataLoading(nextVarRS, nextVarRE); |
|
147 | // requestDataLoading(nextVarRS, nextVarRE); | |
148 |
|
148 | |||
149 |
|
149 | |||
150 | // 3 : pan (jump) right for one hour |
|
150 | // 3 : pan (jump) right for one hour | |
151 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}}; |
|
151 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}}; | |
152 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; |
|
152 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; | |
153 | requestDataLoading(nextVarRS, nextVarRE); |
|
153 | requestDataLoading(nextVarRS, nextVarRE); | |
154 |
|
154 | |||
155 | // 4 : pan (overlay) right for 30 min |
|
155 | // 4 : pan (overlay) right for 30 min | |
156 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}}; |
|
156 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}}; | |
157 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}}; |
|
157 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 30, 0}}; | |
158 | // requestDataLoading(nextVarRS, nextVarRE); |
|
158 | // requestDataLoading(nextVarRS, nextVarRE); | |
159 |
|
159 | |||
160 | // 5 : pan (overlay) left for 30 min |
|
160 | // 5 : pan (overlay) left for 30 min | |
161 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}}; |
|
161 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 0, 0}}; | |
162 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; |
|
162 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; | |
163 | // requestDataLoading(nextVarRS, nextVarRE); |
|
163 | // requestDataLoading(nextVarRS, nextVarRE); | |
164 |
|
164 | |||
165 | // 6 : pan (overlay) left for 30 min - BIS |
|
165 | // 6 : pan (overlay) left for 30 min - BIS | |
166 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}}; |
|
166 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 30, 0}}; | |
167 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}}; |
|
167 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 30, 0}}; | |
168 | // requestDataLoading(nextVarRS, nextVarRE); |
|
168 | // requestDataLoading(nextVarRS, nextVarRE); | |
169 |
|
169 | |||
170 | // 7 : Zoom in Inside 20 min range |
|
170 | // 7 : Zoom in Inside 20 min range | |
171 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}}; |
|
171 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 50, 0}}; | |
172 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}}; |
|
172 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 5, 10, 0}}; | |
173 | // requestDataLoading(nextVarRS, nextVarRE); |
|
173 | // requestDataLoading(nextVarRS, nextVarRE); | |
174 |
|
174 | |||
175 | // 8 : Zoom out Inside 2 hours range |
|
175 | // 8 : Zoom out Inside 2 hours range | |
176 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}}; |
|
176 | nextVarRS = QDateTime{QDate{2012, 01, 02}, QTime{2, 4, 0, 0}}; | |
177 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; |
|
177 | nextVarRE = QDateTime{QDate{2012, 01, 02}, QTime{2, 6, 0, 0}}; | |
178 | // requestDataLoading(nextVarRS, nextVarRE); |
|
178 | // requestDataLoading(nextVarRS, nextVarRE); | |
179 |
|
179 | |||
180 |
|
180 | |||
181 | // Close the app after 10 sec |
|
181 | // Close the app after 10 sec | |
182 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); |
|
182 | QTimer::singleShot(timeToWaitMs, &loop, &QEventLoop::quit); | |
183 | loop.exec(); |
|
183 | loop.exec(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | int main(int argc, char *argv[]) |
|
186 | int main(int argc, char *argv[]) | |
187 | { |
|
187 | { | |
188 | SqpApplication app(argc, argv); |
|
188 | SqpApplication app(argc, argv); | |
189 | app.setAttribute(Qt::AA_Use96Dpi, true); |
|
189 | app.setAttribute(Qt::AA_Use96Dpi, true); | |
190 | TestAmdaAcquisition tc; |
|
190 | TestAmdaAcquisition tc; | |
191 | QTEST_SET_MAIN_SOURCE_PATH |
|
191 | QTEST_SET_MAIN_SOURCE_PATH | |
192 | return QTest::qExec(&tc, argc, argv); |
|
192 | return QTest::qExec(&tc, argc, argv); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | // QTEST_MAIN(TestAmdaAcquisition) |
|
195 | // QTEST_MAIN(TestAmdaAcquisition) | |
196 |
|
196 | |||
197 | #include "TestAmdaAcquisition.moc" |
|
197 | #include "TestAmdaAcquisition.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now