##// END OF EJS Templates
Intialization of network controller
perrinel -
r339:39fcfe63cb2d
parent child
Show More
@@ -0,0 +1,30
1 #ifndef SCIQLOP_NETWORKCONTROLLER_H
2 #define SCIQLOP_NETWORKCONTROLLER_H
3
4 #include <QLoggingCategory>
5 #include <QObject>
6
7 #include <Common/spimpl.h>
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_NetworkController)
10
11 /**
12 * @brief The NetworkController class aims to handle all network connection of SciQlop.
13 */
14 class NetworkController : public QObject {
15 Q_OBJECT
16 public:
17 explicit NetworkController(QObject *parent = 0);
18
19
20 void initialize();
21 void finalize();
22
23 private:
24 void waitForFinish();
25
26 class NetworkControllerPrivate;
27 spimpl::unique_impl_ptr<NetworkControllerPrivate> impl;
28 };
29
30 #endif // SCIQLOP_NETWORKCONTROLLER_H
@@ -0,0 +1,33
1 #include "Network/NetworkController.h"
2
3 #include <QMutex>
4 #include <QThread>
5
6 Q_LOGGING_CATEGORY(LOG_NetworkController, "NetworkController")
7
8 struct NetworkController::NetworkControllerPrivate {
9 explicit NetworkControllerPrivate(NetworkController *parent) : m_WorkingMutex{} {}
10 QMutex m_WorkingMutex;
11 };
12
13 NetworkController::NetworkController(QObject *parent)
14 : QObject(parent), impl{spimpl::make_unique_impl<NetworkControllerPrivate>(this)}
15 {
16 }
17
18 void NetworkController::initialize()
19 {
20 qCDebug(LOG_NetworkController()) << tr("NetworkController init") << QThread::currentThread();
21 impl->m_WorkingMutex.lock();
22 qCDebug(LOG_NetworkController()) << tr("NetworkController init END");
23 }
24
25 void NetworkController::finalize()
26 {
27 impl->m_WorkingMutex.unlock();
28 }
29
30 void NetworkController::waitForFinish()
31 {
32 QMutexLocker locker{&impl->m_WorkingMutex};
33 }
@@ -1,42 +1,38
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include <memory>
4 #include <memory>
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 #include <Common/MetaTypes.h>
8 #include <Common/MetaTypes.h>
9
9
10 #include <Data/SqpDateTime.h>
10 #include <Data/SqpDateTime.h>
11
11
12 class DataProviderParameters;
12 class DataProviderParameters;
13 class IDataSeries;
13 class IDataSeries;
14
14
15 /**
15 /**
16 * @brief The IDataProvider interface aims to declare a data provider.
16 * @brief The IDataProvider interface aims to declare a data provider.
17 *
17 *
18 * A data provider is an entity that generates data and returns it according to various parameters
18 * A data provider is an entity that generates data and returns it according to various parameters
19 * (time interval, product to retrieve the data, etc.)
19 * (time interval, product to retrieve the data, etc.)
20 *
20 *
21 * @sa IDataSeries
21 * @sa IDataSeries
22 */
22 */
23 class IDataProvider : public QObject {
23 class IDataProvider : public QObject {
24
24
25 Q_OBJECT
25 Q_OBJECT
26 public:
26 public:
27 virtual ~IDataProvider() noexcept = default;
27 virtual ~IDataProvider() noexcept = default;
28
28
29 virtual std::shared_ptr<IDataSeries>
30 retrieveData(const DataProviderParameters &parameters) const = 0;
31
32
33 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
29 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
34
30
35 signals:
31 signals:
36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
32 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
37 };
33 };
38
34
39 // Required for using shared_ptr in signals/slots
35 // Required for using shared_ptr in signals/slots
40 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
36 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
41
37
42 #endif // SCIQLOP_IDATAPROVIDER_H
38 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,177 +1,163
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
26 {
27 auto parameters = DataProviderParameters{dateTime};
28
29 return provider.retrieveData(parameters);
30 }
31
32 } // namespace
33
34 struct VariableController::VariableControllerPrivate {
20 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
21 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
22 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
23 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
24 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
25 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
26 {
41 }
27 }
42
28
43 QMutex m_WorkingMutex;
29 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
30 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
31 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
32 QItemSelectionModel *m_VariableSelectionModel;
47
33
48
34
49 TimeController *m_TimeController{nullptr};
35 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
36 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
37
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
38 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
39 m_VariableToProviderMap;
54 };
40 };
55
41
56 VariableController::VariableController(QObject *parent)
42 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
43 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
44 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
45 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
46 << QThread::currentThread();
61 }
47 }
62
48
63 VariableController::~VariableController()
49 VariableController::~VariableController()
64 {
50 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
51 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
52 << QThread::currentThread();
67 this->waitForFinish();
53 this->waitForFinish();
68 }
54 }
69
55
70 VariableModel *VariableController::variableModel() noexcept
56 VariableModel *VariableController::variableModel() noexcept
71 {
57 {
72 return impl->m_VariableModel;
58 return impl->m_VariableModel;
73 }
59 }
74
60
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
61 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
62 {
77 return impl->m_VariableSelectionModel;
63 return impl->m_VariableSelectionModel;
78 }
64 }
79
65
80 void VariableController::setTimeController(TimeController *timeController) noexcept
66 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
67 {
82 impl->m_TimeController = timeController;
68 impl->m_TimeController = timeController;
83 }
69 }
84
70
85 void VariableController::createVariable(const QString &name,
71 void VariableController::createVariable(const QString &name,
86 std::shared_ptr<IDataProvider> provider) noexcept
72 std::shared_ptr<IDataProvider> provider) noexcept
87 {
73 {
88
74
89 if (!impl->m_TimeController) {
75 if (!impl->m_TimeController) {
90 qCCritical(LOG_VariableController())
76 qCCritical(LOG_VariableController())
91 << tr("Impossible to create variable: The time controller is null");
77 << tr("Impossible to create variable: The time controller is null");
92 return;
78 return;
93 }
79 }
94
80
95
81
96 /// @todo : for the moment :
82 /// @todo : for the moment :
97 /// - the provider is only used to retrieve data from the variable for its initialization, but
83 /// - the provider is only used to retrieve data from the variable for its initialization, but
98 /// it will be retained later
84 /// it will be retained later
99 /// - default data are generated for the variable, without taking into account the timerange set
85 /// - default data are generated for the variable, without taking into account the timerange set
100 /// in sciqlop
86 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
87 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
88 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
103
89
104 // store the provider
90 // store the provider
105 impl->m_VariableToProviderMap[newVariable] = provider;
91 impl->m_VariableToProviderMap[newVariable] = provider;
106
92
107 auto addDateTimeAcquired
93 auto addDateTimeAcquired
108 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
94 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
109
95
110 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
96 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
111 newVariable->setDataSeries(dataSeriesAcquired);
97 newVariable->setDataSeries(dataSeriesAcquired);
112
98
113 };
99 };
114
100
115 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
101 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
116 this->onRequestDataLoading(newVariable, dateTime);
102 this->onRequestDataLoading(newVariable, dateTime);
117
103
118 // notify the creation
104 // notify the creation
119 emit variableCreated(newVariable);
105 emit variableCreated(newVariable);
120 }
106 }
121 }
107 }
122
108
123 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
109 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
124 {
110 {
125 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
111 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
126
112
127 for (const auto &selectedRow : qAsConst(selectedRows)) {
113 for (const auto &selectedRow : qAsConst(selectedRows)) {
128 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
114 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
129 selectedVariable->setDateTime(dateTime);
115 selectedVariable->setDateTime(dateTime);
130 this->onRequestDataLoading(selectedVariable, dateTime);
116 this->onRequestDataLoading(selectedVariable, dateTime);
131 }
117 }
132 }
118 }
133 }
119 }
134
120
135
121
136 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
122 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
137 const SqpDateTime &dateTime)
123 const SqpDateTime &dateTime)
138 {
124 {
139 // we want to load data of the variable for the dateTime.
125 // we want to load data of the variable for the dateTime.
140 // First we check if the cache contains some of them.
126 // First we check if the cache contains some of them.
141 // For the other, we ask the provider to give them.
127 // For the other, we ask the provider to give them.
142 if (variable) {
128 if (variable) {
143
129
144 auto dateTimeListNotInCache
130 auto dateTimeListNotInCache
145 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
131 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
146
132
147 if (!dateTimeListNotInCache.empty()) {
133 if (!dateTimeListNotInCache.empty()) {
148 // Ask the provider for each data on the dateTimeListNotInCache
134 // Ask the provider for each data on the dateTimeListNotInCache
149 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
135 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
150 std::move(dateTimeListNotInCache));
136 std::move(dateTimeListNotInCache));
151 }
137 }
152 else {
138 else {
153 emit variable->updated();
139 emit variable->updated();
154 }
140 }
155 }
141 }
156 else {
142 else {
157 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
143 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
158 }
144 }
159 }
145 }
160
146
161
147
162 void VariableController::initialize()
148 void VariableController::initialize()
163 {
149 {
164 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
150 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
165 impl->m_WorkingMutex.lock();
151 impl->m_WorkingMutex.lock();
166 qCDebug(LOG_VariableController()) << tr("VariableController init END");
152 qCDebug(LOG_VariableController()) << tr("VariableController init END");
167 }
153 }
168
154
169 void VariableController::finalize()
155 void VariableController::finalize()
170 {
156 {
171 impl->m_WorkingMutex.unlock();
157 impl->m_WorkingMutex.unlock();
172 }
158 }
173
159
174 void VariableController::waitForFinish()
160 void VariableController::waitForFinish()
175 {
161 {
176 QMutexLocker locker{&impl->m_WorkingMutex};
162 QMutexLocker locker{&impl->m_WorkingMutex};
177 }
163 }
@@ -1,50 +1,52
1 #ifndef SCIQLOP_SQPAPPLICATION_H
1 #ifndef SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
2 #define SCIQLOP_SQPAPPLICATION_H
3
3
4 #include "SqpApplication.h"
4 #include "SqpApplication.h"
5
5
6 #include <QApplication>
6 #include <QApplication>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
10
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_SqpApplication)
12
12
13 #if defined(sqpApp)
13 #if defined(sqpApp)
14 #undef sqpApp
14 #undef sqpApp
15 #endif
15 #endif
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
16 #define sqpApp (static_cast<SqpApplication *>(QCoreApplication::instance()))
17
17
18 class DataSourceController;
18 class DataSourceController;
19 class NetworkController;
19 class TimeController;
20 class TimeController;
20 class VariableController;
21 class VariableController;
21 class VisualizationController;
22 class VisualizationController;
22
23
23 /**
24 /**
24 * @brief The SqpApplication class aims to make the link between SciQlop
25 * @brief The SqpApplication class aims to make the link between SciQlop
25 * and its plugins. This is the intermediate class that SciQlop has to use
26 * and its plugins. This is the intermediate class that SciQlop has to use
26 * in the way to connect a data source. Please first use load method to initialize
27 * in the way to connect a data source. Please first use load method to initialize
27 * a plugin specified by its metadata name (JSON plugin source) then others specifics
28 * a plugin specified by its metadata name (JSON plugin source) then others specifics
28 * method will be able to access it.
29 * method will be able to access it.
29 * You can load a data source driver plugin then create a data source.
30 * You can load a data source driver plugin then create a data source.
30 */
31 */
31
32
32 class SqpApplication : public QApplication {
33 class SqpApplication : public QApplication {
33 Q_OBJECT
34 Q_OBJECT
34 public:
35 public:
35 explicit SqpApplication(int &argc, char **argv);
36 explicit SqpApplication(int &argc, char **argv);
36 virtual ~SqpApplication();
37 virtual ~SqpApplication();
37 void initialize();
38 void initialize();
38
39
39 /// Accessors for the differents sciqlop controllers
40 /// Accessors for the differents sciqlop controllers
40 DataSourceController &dataSourceController() noexcept;
41 DataSourceController &dataSourceController() noexcept;
42 NetworkController &networkController() noexcept;
41 TimeController &timeController() noexcept;
43 TimeController &timeController() noexcept;
42 VariableController &variableController() noexcept;
44 VariableController &variableController() noexcept;
43 VisualizationController &visualizationController() noexcept;
45 VisualizationController &visualizationController() noexcept;
44
46
45 private:
47 private:
46 class SqpApplicationPrivate;
48 class SqpApplicationPrivate;
47 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
49 spimpl::unique_impl_ptr<SqpApplicationPrivate> impl;
48 };
50 };
49
51
50 #endif // SCIQLOP_SQPAPPLICATION_H
52 #endif // SCIQLOP_SQPAPPLICATION_H
@@ -1,118 +1,137
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <Data/IDataProvider.h>
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <Network/NetworkController.h>
5 #include <QThread>
6 #include <QThread>
6 #include <Time/TimeController.h>
7 #include <Time/TimeController.h>
7 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
8 #include <Variable/VariableController.h>
9 #include <Variable/VariableController.h>
9 #include <Visualization/VisualizationController.h>
10 #include <Visualization/VisualizationController.h>
10
11
11 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
12
13
13 class SqpApplication::SqpApplicationPrivate {
14 class SqpApplication::SqpApplicationPrivate {
14 public:
15 public:
15 SqpApplicationPrivate()
16 SqpApplicationPrivate()
16 : m_DataSourceController{std::make_unique<DataSourceController>()},
17 : m_DataSourceController{std::make_unique<DataSourceController>()},
18 m_NetworkController{std::make_unique<NetworkController>()},
17 m_TimeController{std::make_unique<TimeController>()},
19 m_TimeController{std::make_unique<TimeController>()},
18 m_VariableController{std::make_unique<VariableController>()},
20 m_VariableController{std::make_unique<VariableController>()},
19 m_VisualizationController{std::make_unique<VisualizationController>()}
21 m_VisualizationController{std::make_unique<VisualizationController>()}
20 {
22 {
21 // /////////////////////////////// //
23 // /////////////////////////////// //
22 // Connections between controllers //
24 // Connections between controllers //
23 // /////////////////////////////// //
25 // /////////////////////////////// //
24
26
25 // VariableController <-> DataSourceController
27 // VariableController <-> DataSourceController
26 connect(m_DataSourceController.get(),
28 connect(m_DataSourceController.get(),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
28 m_VariableController.get(),
30 m_VariableController.get(),
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
31 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
30
32
31 // VariableController <-> VisualizationController
33 // VariableController <-> VisualizationController
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
34 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
35 m_VisualizationController.get(),
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
36 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
35
37
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
38 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
39 m_NetworkController->moveToThread(&m_NetworkControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
40 m_VariableController->moveToThread(&m_VariableControllerThread);
38 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
41 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
39
42
40 // Additionnal init
43 // Additionnal init
41 m_VariableController->setTimeController(m_TimeController.get());
44 m_VariableController->setTimeController(m_TimeController.get());
42 }
45 }
43
46
44 virtual ~SqpApplicationPrivate()
47 virtual ~SqpApplicationPrivate()
45 {
48 {
46 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
49 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
47 m_DataSourceControllerThread.quit();
50 m_DataSourceControllerThread.quit();
48 m_DataSourceControllerThread.wait();
51 m_DataSourceControllerThread.wait();
49
52
53 m_NetworkControllerThread.quit();
54 m_NetworkControllerThread.wait();
55
50 m_VariableControllerThread.quit();
56 m_VariableControllerThread.quit();
51 m_VariableControllerThread.wait();
57 m_VariableControllerThread.wait();
52
58
53 m_VisualizationControllerThread.quit();
59 m_VisualizationControllerThread.quit();
54 m_VisualizationControllerThread.wait();
60 m_VisualizationControllerThread.wait();
55 }
61 }
56
62
57 std::unique_ptr<DataSourceController> m_DataSourceController;
63 std::unique_ptr<DataSourceController> m_DataSourceController;
58 std::unique_ptr<VariableController> m_VariableController;
64 std::unique_ptr<VariableController> m_VariableController;
59 std::unique_ptr<TimeController> m_TimeController;
65 std::unique_ptr<TimeController> m_TimeController;
66 std::unique_ptr<NetworkController> m_NetworkController;
60 std::unique_ptr<VisualizationController> m_VisualizationController;
67 std::unique_ptr<VisualizationController> m_VisualizationController;
61 QThread m_DataSourceControllerThread;
68 QThread m_DataSourceControllerThread;
69 QThread m_NetworkControllerThread;
62 QThread m_VariableControllerThread;
70 QThread m_VariableControllerThread;
63 QThread m_VisualizationControllerThread;
71 QThread m_VisualizationControllerThread;
64 };
72 };
65
73
66
74
67 SqpApplication::SqpApplication(int &argc, char **argv)
75 SqpApplication::SqpApplication(int &argc, char **argv)
68 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
76 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
69 {
77 {
70 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
78 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
71
79
72 connect(&impl->m_DataSourceControllerThread, &QThread::started,
80 connect(&impl->m_DataSourceControllerThread, &QThread::started,
73 impl->m_DataSourceController.get(), &DataSourceController::initialize);
81 impl->m_DataSourceController.get(), &DataSourceController::initialize);
74 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
82 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
75 impl->m_DataSourceController.get(), &DataSourceController::finalize);
83 impl->m_DataSourceController.get(), &DataSourceController::finalize);
76
84
85 connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(),
86 &NetworkController::initialize);
87 connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(),
88 &NetworkController::finalize);
89
77 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
90 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
78 &VariableController::initialize);
91 &VariableController::initialize);
79 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
92 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
80 &VariableController::finalize);
93 &VariableController::finalize);
81
94
82 connect(&impl->m_VisualizationControllerThread, &QThread::started,
95 connect(&impl->m_VisualizationControllerThread, &QThread::started,
83 impl->m_VisualizationController.get(), &VisualizationController::initialize);
96 impl->m_VisualizationController.get(), &VisualizationController::initialize);
84 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
97 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
85 impl->m_VisualizationController.get(), &VisualizationController::finalize);
98 impl->m_VisualizationController.get(), &VisualizationController::finalize);
86
99
87 impl->m_DataSourceControllerThread.start();
100 impl->m_DataSourceControllerThread.start();
101 impl->m_NetworkControllerThread.start();
88 impl->m_VariableControllerThread.start();
102 impl->m_VariableControllerThread.start();
89 impl->m_VisualizationControllerThread.start();
103 impl->m_VisualizationControllerThread.start();
90 }
104 }
91
105
92 SqpApplication::~SqpApplication()
106 SqpApplication::~SqpApplication()
93 {
107 {
94 }
108 }
95
109
96 void SqpApplication::initialize()
110 void SqpApplication::initialize()
97 {
111 {
98 }
112 }
99
113
100 DataSourceController &SqpApplication::dataSourceController() noexcept
114 DataSourceController &SqpApplication::dataSourceController() noexcept
101 {
115 {
102 return *impl->m_DataSourceController;
116 return *impl->m_DataSourceController;
103 }
117 }
104
118
119 NetworkController &SqpApplication::networkController() noexcept
120 {
121 return *impl->m_NetworkController;
122 }
123
105 TimeController &SqpApplication::timeController() noexcept
124 TimeController &SqpApplication::timeController() noexcept
106 {
125 {
107 return *impl->m_TimeController;
126 return *impl->m_TimeController;
108 }
127 }
109
128
110 VariableController &SqpApplication::variableController() noexcept
129 VariableController &SqpApplication::variableController() noexcept
111 {
130 {
112 return *impl->m_VariableController;
131 return *impl->m_VariableController;
113 }
132 }
114
133
115 VisualizationController &SqpApplication::visualizationController() noexcept
134 VisualizationController &SqpApplication::visualizationController() noexcept
116 {
135 {
117 return *impl->m_VisualizationController;
136 return *impl->m_VisualizationController;
118 }
137 }
@@ -1,155 +1,153
1 #include "Visualization/VisualizationGraphHelper.h"
1 #include "Visualization/VisualizationGraphHelper.h"
2 #include "Visualization/qcustomplot.h"
2 #include "Visualization/qcustomplot.h"
3
3
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7
7
8 #include <QElapsedTimer>
8 #include <QElapsedTimer>
9
9
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
10 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
11
11
12 namespace {
12 namespace {
13
13
14 /// Format for datetimes on a axis
14 /// Format for datetimes on a axis
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
16
16
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
18 /// non-time data
18 /// non-time data
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
20 {
20 {
21 if (isTimeAxis) {
21 if (isTimeAxis) {
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
24
24
25 return dateTicker;
25 return dateTicker;
26 }
26 }
27 else {
27 else {
28 // default ticker
28 // default ticker
29 return QSharedPointer<QCPAxisTicker>::create();
29 return QSharedPointer<QCPAxisTicker>::create();
30 }
30 }
31 }
31 }
32
32
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
34 const SqpDateTime &dateTime)
35 {
35 {
36 QElapsedTimer timer;
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
36 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
37 // Clean the graph
40 // NAIVE approch
38 // NAIVE approch
41 const auto &xData = scalarSeries.xAxisData()->data();
39 const auto xData = scalarSeries.xAxisData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
40 const auto valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
41 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
42 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45 auto xValue = QVector<double>(count);
43 auto xValue = QVector<double>(count);
46 auto vValue = QVector<double>(count);
44 auto vValue = QVector<double>(count);
47
45
48 int n = 0;
46 int n = 0;
49 for (auto i = 0; i < count; ++i) {
47 for (auto i = 0; i < count; ++i) {
50 const auto x = xData[i];
48 const auto x = xData[i];
51 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
49 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
52 xValue[n] = x;
50 xValue[n] = x;
53 vValue[n] = valuesData[i];
51 vValue[n] = valuesData[i];
54 ++n;
52 ++n;
55 }
53 }
56 }
54 }
57
55
58 xValue.resize(n);
56 xValue.resize(n);
59 vValue.resize(n);
57 vValue.resize(n);
60
58
61 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
59 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
62 << xValue.count();
60 << xValue.count();
63
61
64 qcpGraph->setData(xValue, vValue);
62 qcpGraph->setData(xValue, vValue);
65
63
66 // Display all data
64 // Display all data
67 component->rescaleAxes();
65 component->rescaleAxes();
68 component->parentPlot()->replot();
66 component->parentPlot()->replot();
69 }
67 }
70 else {
68 else {
71 /// @todo DEBUG
69 /// @todo DEBUG
72 }
70 }
73 }
71 }
74
72
75 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
73 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
76 const SqpDateTime &dateTime)
74 const SqpDateTime &dateTime)
77 {
75 {
78 auto component = plot.addGraph();
76 auto component = plot.addGraph();
79
77
80 if (component) {
78 if (component) {
81 // // Graph data
79 // // Graph data
82 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
80 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
83 true);
81 true);
84
82
85 updateScalarData(component, scalarSeries, dateTime);
83 updateScalarData(component, scalarSeries, dateTime);
86
84
87 // Axes properties
85 // Axes properties
88 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
86 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
89 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
87 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
90
88
91 auto setAxisProperties = [](auto axis, const auto &unit) {
89 auto setAxisProperties = [](auto axis, const auto &unit) {
92 // label (unit name)
90 // label (unit name)
93 axis->setLabel(unit.m_Name);
91 axis->setLabel(unit.m_Name);
94
92
95 // ticker (depending on the type of unit)
93 // ticker (depending on the type of unit)
96 axis->setTicker(axisTicker(unit.m_TimeUnit));
94 axis->setTicker(axisTicker(unit.m_TimeUnit));
97 };
95 };
98 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
96 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
99 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
97 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
100
98
101 // Display all data
99 // Display all data
102 component->rescaleAxes();
100 component->rescaleAxes();
103 plot.replot();
101 plot.replot();
104 }
102 }
105 else {
103 else {
106 qCDebug(LOG_VisualizationGraphHelper())
104 qCDebug(LOG_VisualizationGraphHelper())
107 << QObject::tr("Can't create graph for the scalar series");
105 << QObject::tr("Can't create graph for the scalar series");
108 }
106 }
109
107
110 return component;
108 return component;
111 }
109 }
112
110
113 } // namespace
111 } // namespace
114
112
115 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
113 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
116 QCustomPlot &plot) noexcept
114 QCustomPlot &plot) noexcept
117 {
115 {
118 auto result = QVector<QCPAbstractPlottable *>{};
116 auto result = QVector<QCPAbstractPlottable *>{};
119
117
120 if (variable) {
118 if (variable) {
121 // Gets the data series of the variable to call the creation of the right components
119 // Gets the data series of the variable to call the creation of the right components
122 // according to its type
120 // according to its type
123 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
121 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
124 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
122 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
125 }
123 }
126 else {
124 else {
127 qCDebug(LOG_VisualizationGraphHelper())
125 qCDebug(LOG_VisualizationGraphHelper())
128 << QObject::tr("Can't create graph plottables : unmanaged data series type");
126 << QObject::tr("Can't create graph plottables : unmanaged data series type");
129 }
127 }
130 }
128 }
131 else {
129 else {
132 qCDebug(LOG_VisualizationGraphHelper())
130 qCDebug(LOG_VisualizationGraphHelper())
133 << QObject::tr("Can't create graph plottables : the variable is null");
131 << QObject::tr("Can't create graph plottables : the variable is null");
134 }
132 }
135
133
136 return result;
134 return result;
137 }
135 }
138
136
139 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
137 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
140 IDataSeries *dataSeries, const SqpDateTime &dateTime)
138 IDataSeries *dataSeries, const SqpDateTime &dateTime)
141 {
139 {
142 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
140 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
143 if (plotableVect.size() == 1) {
141 if (plotableVect.size() == 1) {
144 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
142 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
145 }
143 }
146 else {
144 else {
147 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
145 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
148 "Can't update Data of a scalarSeries because there is not only one component "
146 "Can't update Data of a scalarSeries because there is not only one component "
149 "associated");
147 "associated");
150 }
148 }
151 }
149 }
152 else {
150 else {
153 /// @todo DEBUG
151 /// @todo DEBUG
154 }
152 }
155 }
153 }
@@ -1,26 +1,24
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
9
10 /**
10 /**
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
12 */
12 */
13 class CosinusProvider : public IDataProvider {
13 class CosinusProvider : public IDataProvider {
14 public:
14 public:
15 /// @sa IDataProvider::retrieveData()
16 std::shared_ptr<IDataSeries>
17 retrieveData(const DataProviderParameters &parameters) const override;
18
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
15 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
20
16
21
17
22 private:
18 private:
19 /// @sa IDataProvider::retrieveData()
20 std::shared_ptr<IDataSeries> retrieveData(const DataProviderParameters &parameters) const;
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
21 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
24 };
22 };
25
23
26 #endif // SCIQLOP_COSINUSPROVIDER_H
24 #endif // SCIQLOP_COSINUSPROVIDER_H
General Comments 0
You need to be logged in to leave comments. Login now