@@ -32,7 +32,7 struct VisualizationGraphHelper { | |||
|
32 | 32 | */ |
|
33 | 33 | static PlottablesMap create(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept; |
|
34 | 34 | |
|
35 |
static void updateData(PlottablesMap &plottables, std::shared_ptr< |
|
|
35 | static void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, | |
|
36 | 36 | const SqpRange &dateTime); |
|
37 | 37 | |
|
38 | 38 | static void setYAxisRange(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept; |
@@ -25,7 +25,7 public: | |||
|
25 | 25 | */ |
|
26 | 26 | template <typename T, typename Enabled = void> |
|
27 | 27 | struct PlottablesCreator { |
|
28 |
static PlottablesMap createPlottables( |
|
|
28 | static PlottablesMap createPlottables(QCustomPlot &) | |
|
29 | 29 | { |
|
30 | 30 | qCCritical(LOG_DataSeries()) |
|
31 | 31 | << QObject::tr("Can't create plottables: unmanaged data series type"); |
@@ -33,26 +33,12 struct PlottablesCreator { | |||
|
33 | 33 | } |
|
34 | 34 | }; |
|
35 | 35 | |
|
36 | /** | |
|
37 | * Specialization of PlottablesCreator for scalars and vectors | |
|
38 | * @sa ScalarSeries | |
|
39 | * @sa VectorSeries | |
|
40 | */ | |
|
41 | template <typename T> | |
|
42 | struct PlottablesCreator<T, | |
|
43 | typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value | |
|
44 | or std::is_base_of<VectorSeries, T>::value> > { | |
|
45 | static PlottablesMap createPlottables(T &dataSeries, QCustomPlot &plot) | |
|
36 | PlottablesMap createGraphs(QCustomPlot &plot, int nbGraphs) | |
|
46 | 37 | { |
|
47 | 38 |
|
|
48 | 39 | |
|
49 | // Gets the number of components of the data series | |
|
50 | dataSeries.lockRead(); | |
|
51 | auto componentCount = dataSeries.valuesData()->componentCount(); | |
|
52 | dataSeries.unlock(); | |
|
53 | ||
|
54 | // For each component of the data series, creates a QCPGraph to add to the plot | |
|
55 | for (auto i = 0; i < componentCount; ++i) { | |
|
40 | // Creates {nbGraphs} QCPGraph to add to the plot | |
|
41 | for (auto i = 0; i < nbGraphs; ++i) { | |
|
56 | 42 |
|
|
57 | 43 |
|
|
58 | 44 |
|
@@ -61,6 +47,23 struct PlottablesCreator<T, | |||
|
61 | 47 | |
|
62 | 48 |
|
|
63 | 49 | } |
|
50 | ||
|
51 | /** | |
|
52 | * Specialization of PlottablesCreator for scalars | |
|
53 | * @sa ScalarSeries | |
|
54 | */ | |
|
55 | template <typename T> | |
|
56 | struct PlottablesCreator<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value> > { | |
|
57 | static PlottablesMap createPlottables(QCustomPlot &plot) { return createGraphs(plot, 1); } | |
|
58 | }; | |
|
59 | ||
|
60 | /** | |
|
61 | * Specialization of PlottablesCreator for vectors | |
|
62 | * @sa VectorSeries | |
|
63 | */ | |
|
64 | template <typename T> | |
|
65 | struct PlottablesCreator<T, typename std::enable_if_t<std::is_base_of<VectorSeries, T>::value> > { | |
|
66 | static PlottablesMap createPlottables(QCustomPlot &plot) { return createGraphs(plot, 3); } | |
|
64 | 67 | }; |
|
65 | 68 | |
|
66 | 69 | /** |
@@ -70,7 +73,7 struct PlottablesCreator<T, | |||
|
70 | 73 | template <typename T> |
|
71 | 74 | struct PlottablesCreator<T, |
|
72 | 75 | typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > { |
|
73 |
static PlottablesMap createPlottables( |
|
|
76 | static PlottablesMap createPlottables(QCustomPlot &plot) | |
|
74 | 77 | { |
|
75 | 78 | PlottablesMap result{}; |
|
76 | 79 | result.insert({0, new QCPColorMap{plot.xAxis, plot.yAxis}}); |
@@ -264,41 +267,59 struct IPlottablesHelper { | |||
|
264 | 267 | */ |
|
265 | 268 | template <typename T> |
|
266 | 269 | struct PlottablesHelper : public IPlottablesHelper { |
|
267 |
explicit PlottablesHelper(T |
|
|
270 | explicit PlottablesHelper(std::shared_ptr<T> dataSeries) : m_DataSeries{dataSeries} {} | |
|
268 | 271 | |
|
269 | 272 | PlottablesMap create(QCustomPlot &plot) const override |
|
270 | 273 | { |
|
271 |
return PlottablesCreator<T>::createPlottables( |
|
|
274 | return PlottablesCreator<T>::createPlottables(plot); | |
|
272 | 275 | } |
|
273 | 276 | |
|
274 | 277 | void update(PlottablesMap &plottables, const SqpRange &range, bool rescaleAxes) const override |
|
275 | 278 | { |
|
276 | PlottablesUpdater<T>::updatePlottables(m_DataSeries, plottables, range, rescaleAxes); | |
|
279 | if (m_DataSeries) { | |
|
280 | PlottablesUpdater<T>::updatePlottables(*m_DataSeries, plottables, range, rescaleAxes); | |
|
281 | } | |
|
282 | else { | |
|
283 | qCCritical(LOG_VisualizationGraphHelper()) << "Can't update plottables: inconsistency " | |
|
284 | "between the type of data series and the " | |
|
285 | "type supposed"; | |
|
286 | } | |
|
277 | 287 | } |
|
278 | 288 | |
|
279 | 289 | void setYAxisRange(const SqpRange &xAxisRange, QCustomPlot &plot) const override |
|
280 | 290 | { |
|
281 | return PlottablesUpdater<T>::setPlotYAxisRange(m_DataSeries, xAxisRange, plot); | |
|
291 | if (m_DataSeries) { | |
|
292 | PlottablesUpdater<T>::setPlotYAxisRange(*m_DataSeries, xAxisRange, plot); | |
|
293 | } | |
|
294 | else { | |
|
295 | qCCritical(LOG_VisualizationGraphHelper()) << "Can't update plottables: inconsistency " | |
|
296 | "between the type of data series and the " | |
|
297 | "type supposed"; | |
|
298 | } | |
|
282 | 299 | } |
|
283 | 300 | |
|
284 |
T |
|
|
301 | std::shared_ptr<T> m_DataSeries; | |
|
285 | 302 | }; |
|
286 | 303 | |
|
287 |
/// Creates IPlottablesHelper according to |
|
|
288 |
std::unique_ptr<IPlottablesHelper> createHelper(std::shared_ptr< |
|
|
304 | /// Creates IPlottablesHelper according to the type of data series a variable holds | |
|
305 | std::unique_ptr<IPlottablesHelper> createHelper(std::shared_ptr<Variable> variable) noexcept | |
|
289 | 306 | { |
|
290 | if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) { | |
|
291 | return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries); | |
|
292 | } | |
|
293 |
|
|
|
294 | return std::make_unique<PlottablesHelper<SpectrogramSeries> >(*spectrogramSeries); | |
|
295 | } | |
|
296 |
|
|
|
297 | return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries); | |
|
298 | } | |
|
299 | else { | |
|
300 | return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries); | |
|
307 | switch (variable->type()) { | |
|
308 | case DataSeriesType::SCALAR: | |
|
309 | return std::make_unique<PlottablesHelper<ScalarSeries> >( | |
|
310 | std::dynamic_pointer_cast<ScalarSeries>(variable->dataSeries())); | |
|
311 | case DataSeriesType::SPECTROGRAM: | |
|
312 | return std::make_unique<PlottablesHelper<SpectrogramSeries> >( | |
|
313 | std::dynamic_pointer_cast<SpectrogramSeries>(variable->dataSeries())); | |
|
314 | case DataSeriesType::VECTOR: | |
|
315 | return std::make_unique<PlottablesHelper<VectorSeries> >( | |
|
316 | std::dynamic_pointer_cast<VectorSeries>(variable->dataSeries())); | |
|
317 | default: | |
|
318 | // Creates default helper | |
|
319 | break; | |
|
301 | 320 | } |
|
321 | ||
|
322 | return std::make_unique<PlottablesHelper<IDataSeries> >(nullptr); | |
|
302 | 323 | } |
|
303 | 324 | |
|
304 | 325 | } // namespace |
@@ -307,7 +328,7 PlottablesMap VisualizationGraphHelper::create(std::shared_ptr<Variable> variabl | |||
|
307 | 328 | QCustomPlot &plot) noexcept |
|
308 | 329 | { |
|
309 | 330 | if (variable) { |
|
310 |
auto helper = createHelper(variable |
|
|
331 | auto helper = createHelper(variable); | |
|
311 | 332 | auto plottables = helper->create(plot); |
|
312 | 333 | return plottables; |
|
313 | 334 | } |
@@ -322,7 +343,7 void VisualizationGraphHelper::setYAxisRange(std::shared_ptr<Variable> variable, | |||
|
322 | 343 | QCustomPlot &plot) noexcept |
|
323 | 344 | { |
|
324 | 345 | if (variable) { |
|
325 |
auto helper = createHelper(variable |
|
|
346 | auto helper = createHelper(variable); | |
|
326 | 347 | helper->setYAxisRange(variable->range(), plot); |
|
327 | 348 | } |
|
328 | 349 | else { |
@@ -332,9 +353,9 void VisualizationGraphHelper::setYAxisRange(std::shared_ptr<Variable> variable, | |||
|
332 | 353 | } |
|
333 | 354 | |
|
334 | 355 | void VisualizationGraphHelper::updateData(PlottablesMap &plottables, |
|
335 |
std::shared_ptr< |
|
|
356 | std::shared_ptr<Variable> variable, | |
|
336 | 357 | const SqpRange &dateTime) |
|
337 | 358 | { |
|
338 |
auto helper = createHelper( |
|
|
359 | auto helper = createHelper(variable); | |
|
339 | 360 | helper->update(plottables, dateTime); |
|
340 | 361 | } |
@@ -65,10 +65,10 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||
|
65 | 65 | { |
|
66 | 66 | } |
|
67 | 67 | |
|
68 |
void updateData(PlottablesMap &plottables, std::shared_ptr< |
|
|
68 | void updateData(PlottablesMap &plottables, std::shared_ptr<Variable> variable, | |
|
69 | 69 | const SqpRange &range) |
|
70 | 70 | { |
|
71 |
VisualizationGraphHelper::updateData(plottables, |
|
|
71 | VisualizationGraphHelper::updateData(plottables, variable, range); | |
|
72 | 72 | |
|
73 | 73 | // Prevents that data has changed to update rendering |
|
74 | 74 | m_RenderingDelegate->onPlotUpdated(); |
@@ -989,7 +989,7 void VisualizationGraphWidget::onDataCacheVariableUpdated() | |||
|
989 | 989 | qCDebug(LOG_VisualizationGraphWidget()) |
|
990 | 990 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
991 | 991 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
992 |
impl->updateData(variableEntry.second, variable |
|
|
992 | impl->updateData(variableEntry.second, variable, variable->range()); | |
|
993 | 993 | } |
|
994 | 994 | } |
|
995 | 995 | } |
@@ -999,6 +999,6 void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> v | |||
|
999 | 999 | { |
|
1000 | 1000 | auto it = impl->m_VariableToPlotMultiMap.find(variable); |
|
1001 | 1001 | if (it != impl->m_VariableToPlotMultiMap.end()) { |
|
1002 |
impl->updateData(it->second, variable |
|
|
1002 | impl->updateData(it->second, variable, range); | |
|
1003 | 1003 | } |
|
1004 | 1004 | } |
General Comments 0
You need to be logged in to leave comments.
Login now