@@ -0,0 +1,46 | |||
|
1 | #ifndef SCIQLOP_METATYPES_H | |
|
2 | #define SCIQLOP_METATYPES_H | |
|
3 | ||
|
4 | #include <QMetaType> | |
|
5 | ||
|
6 | /** | |
|
7 | * Struct used to create an instance that registers a type in Qt for signals / slots mechanism | |
|
8 | * @tparam T the type to register | |
|
9 | */ | |
|
10 | template <typename T> | |
|
11 | struct MetaTypeRegistry { | |
|
12 | explicit MetaTypeRegistry() { qRegisterMetaType<T>(); } | |
|
13 | }; | |
|
14 | ||
|
15 | /** | |
|
16 | * This macro can be used to : | |
|
17 | * - declare a type as a Qt meta type | |
|
18 | * - and register it (through a static instance) at the launch of SciQlop, so it can be passed in | |
|
19 | * Qt signals/slots | |
|
20 | * | |
|
21 | * It can be used both in .h or in .cpp files | |
|
22 | * | |
|
23 | * @param NAME name of the instance under which the type will be registered (in uppercase) | |
|
24 | * @param TYPE type to register | |
|
25 | * | |
|
26 | * Example: | |
|
27 | * ~~~cpp | |
|
28 | * // The following macro : | |
|
29 | * // - declares std::shared_ptr<Variable> as a Qt meta type | |
|
30 | * // - registers it through an instance named VAR_SHARED_PTR | |
|
31 | * SCIQLOP_REGISTER_META_TYPE(VAR_SHARED_PTR, std::shared_ptr<Variable>) | |
|
32 | * | |
|
33 | * // The following macro : | |
|
34 | * // - declares a raw pointer of Variable as a Qt meta type | |
|
35 | * // - registers it through an instance named VAR_RAW_PTR | |
|
36 | * SCIQLOP_REGISTER_META_TYPE(VAR_RAW_PTR, Variable*) | |
|
37 | * ~~~ | |
|
38 | * | |
|
39 | */ | |
|
40 | // clang-format off | |
|
41 | #define SCIQLOP_REGISTER_META_TYPE(NAME, TYPE) \ | |
|
42 | Q_DECLARE_METATYPE(TYPE) \ | |
|
43 | const auto NAME = MetaTypeRegistry<TYPE>{}; \ | |
|
44 | // clang-format on | |
|
45 | ||
|
46 | #endif // SCIQLOP_METATYPES_H |
@@ -1,261 +1,259 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the SciQLop Software |
|
3 | 3 | -- Copyright (C) 2017, Plasma Physics Laboratory - CNRS |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 2 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | -------------------------------------------------------------------------------*/ |
|
19 | 19 | /*-- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | ----------------------------------------------------------------------------*/ |
|
22 | 22 | #include "MainWindow.h" |
|
23 | 23 | #include "ui_MainWindow.h" |
|
24 | 24 | |
|
25 | 25 | #include <DataSource/DataSourceController.h> |
|
26 | 26 | #include <DataSource/DataSourceWidget.h> |
|
27 | 27 | #include <SidePane/SqpSidePane.h> |
|
28 | 28 | #include <SqpApplication.h> |
|
29 | 29 | #include <Time/TimeController.h> |
|
30 | 30 | #include <TimeWidget/TimeWidget.h> |
|
31 | 31 | #include <Variable/Variable.h> |
|
32 | 32 | #include <Variable/VariableController.h> |
|
33 | 33 | #include <Visualization/VisualizationController.h> |
|
34 | 34 | |
|
35 | 35 | #include <QAction> |
|
36 | 36 | #include <QDate> |
|
37 | 37 | #include <QDateTime> |
|
38 | 38 | #include <QDir> |
|
39 | 39 | #include <QFileDialog> |
|
40 | 40 | #include <QToolBar> |
|
41 | 41 | #include <QToolButton> |
|
42 | 42 | #include <memory.h> |
|
43 | 43 | |
|
44 | 44 | //#include <omp.h> |
|
45 | 45 | //#include <network/filedownloader.h> |
|
46 | 46 | //#include <qlopdatabase.h> |
|
47 | 47 | //#include <qlopsettings.h> |
|
48 | 48 | //#include <qlopgui.h> |
|
49 | 49 | //#include <spacedata.h> |
|
50 | 50 | //#include "qlopcore.h" |
|
51 | 51 | //#include "qlopcodecmanager.h" |
|
52 | 52 | //#include "cdfcodec.h" |
|
53 | 53 | //#include "amdatxtcodec.h" |
|
54 | 54 | //#include <qlopplotmanager.h> |
|
55 | 55 | |
|
56 | 56 | #include "iostream" |
|
57 | 57 | |
|
58 | 58 | Q_LOGGING_CATEGORY(LOG_MainWindow, "MainWindow") |
|
59 | 59 | |
|
60 | 60 | namespace { |
|
61 | 61 | const auto LEFTMAININSPECTORWIDGETSPLITTERINDEX = 0; |
|
62 | 62 | const auto LEFTINSPECTORSIDEPANESPLITTERINDEX = 1; |
|
63 | 63 | const auto VIEWPLITTERINDEX = 2; |
|
64 | 64 | const auto RIGHTINSPECTORSIDEPANESPLITTERINDEX = 3; |
|
65 | 65 | const auto RIGHTMAININSPECTORWIDGETSPLITTERINDEX = 4; |
|
66 | 66 | } |
|
67 | 67 | |
|
68 | 68 | class MainWindow::MainWindowPrivate { |
|
69 | 69 | public: |
|
70 | 70 | QSize m_LastOpenLeftInspectorSize; |
|
71 | 71 | QSize m_LastOpenRightInspectorSize; |
|
72 | 72 | }; |
|
73 | 73 | |
|
74 | 74 | MainWindow::MainWindow(QWidget *parent) |
|
75 | 75 | : QMainWindow{parent}, |
|
76 | 76 | m_Ui{new Ui::MainWindow}, |
|
77 | 77 | impl{spimpl::make_unique_impl<MainWindowPrivate>()} |
|
78 | 78 | { |
|
79 | 79 | m_Ui->setupUi(this); |
|
80 | 80 | |
|
81 | 81 | m_Ui->splitter->setCollapsible(LEFTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
82 | 82 | m_Ui->splitter->setCollapsible(RIGHTINSPECTORSIDEPANESPLITTERINDEX, false); |
|
83 | 83 | |
|
84 | 84 | |
|
85 | 85 | auto leftSidePane = m_Ui->leftInspectorSidePane->sidePane(); |
|
86 | 86 | auto openLeftInspectorAction = new QAction{QIcon{ |
|
87 | 87 | ":/icones/previous.png", |
|
88 | 88 | }, |
|
89 | 89 | tr("Show/hide the left inspector"), this}; |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | auto spacerLeftTop = new QWidget{}; |
|
93 | 93 | spacerLeftTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
94 | 94 | |
|
95 | 95 | auto spacerLeftBottom = new QWidget{}; |
|
96 | 96 | spacerLeftBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
97 | 97 | |
|
98 | 98 | leftSidePane->addWidget(spacerLeftTop); |
|
99 | 99 | leftSidePane->addAction(openLeftInspectorAction); |
|
100 | 100 | leftSidePane->addWidget(spacerLeftBottom); |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | auto rightSidePane = m_Ui->rightInspectorSidePane->sidePane(); |
|
104 | 104 | auto openRightInspectorAction = new QAction{QIcon{ |
|
105 | 105 | ":/icones/next.png", |
|
106 | 106 | }, |
|
107 | 107 | tr("Show/hide the right inspector"), this}; |
|
108 | 108 | |
|
109 | 109 | auto spacerRightTop = new QWidget{}; |
|
110 | 110 | spacerRightTop->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
111 | 111 | |
|
112 | 112 | auto spacerRightBottom = new QWidget{}; |
|
113 | 113 | spacerRightBottom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
114 | 114 | |
|
115 | 115 | rightSidePane->addWidget(spacerRightTop); |
|
116 | 116 | rightSidePane->addAction(openRightInspectorAction); |
|
117 | 117 | rightSidePane->addWidget(spacerRightBottom); |
|
118 | 118 | |
|
119 | 119 | openLeftInspectorAction->setCheckable(true); |
|
120 | 120 | openRightInspectorAction->setCheckable(true); |
|
121 | 121 | |
|
122 | 122 | auto openInspector = [this](bool checked, bool right, auto action) { |
|
123 | 123 | |
|
124 | 124 | action->setIcon(QIcon{(checked xor right) ? ":/icones/next.png" : ":/icones/previous.png"}); |
|
125 | 125 | |
|
126 | 126 | auto &lastInspectorSize |
|
127 | 127 | = right ? impl->m_LastOpenRightInspectorSize : impl->m_LastOpenLeftInspectorSize; |
|
128 | 128 | |
|
129 | 129 | auto nextInspectorSize = right ? m_Ui->rightMainInspectorWidget->size() |
|
130 | 130 | : m_Ui->leftMainInspectorWidget->size(); |
|
131 | 131 | |
|
132 | 132 | // Update of the last opened geometry |
|
133 | 133 | if (checked) { |
|
134 | 134 | lastInspectorSize = nextInspectorSize; |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | auto startSize = lastInspectorSize; |
|
138 | 138 | auto endSize = startSize; |
|
139 | 139 | endSize.setWidth(0); |
|
140 | 140 | |
|
141 | 141 | auto splitterInspectorIndex |
|
142 | 142 | = right ? RIGHTMAININSPECTORWIDGETSPLITTERINDEX : LEFTMAININSPECTORWIDGETSPLITTERINDEX; |
|
143 | 143 | |
|
144 | 144 | auto currentSizes = m_Ui->splitter->sizes(); |
|
145 | 145 | if (checked) { |
|
146 | 146 | // adjust sizes individually here, e.g. |
|
147 | 147 | currentSizes[splitterInspectorIndex] -= lastInspectorSize.width(); |
|
148 | 148 | currentSizes[VIEWPLITTERINDEX] += lastInspectorSize.width(); |
|
149 | 149 | m_Ui->splitter->setSizes(currentSizes); |
|
150 | 150 | } |
|
151 | 151 | else { |
|
152 | 152 | // adjust sizes individually here, e.g. |
|
153 | 153 | currentSizes[splitterInspectorIndex] += lastInspectorSize.width(); |
|
154 | 154 | currentSizes[VIEWPLITTERINDEX] -= lastInspectorSize.width(); |
|
155 | 155 | m_Ui->splitter->setSizes(currentSizes); |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | }; |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | connect(openLeftInspectorAction, &QAction::triggered, |
|
162 | 162 | [openInspector, openLeftInspectorAction](bool checked) { |
|
163 | 163 | openInspector(checked, false, openLeftInspectorAction); |
|
164 | 164 | }); |
|
165 | 165 | connect(openRightInspectorAction, &QAction::triggered, |
|
166 | 166 | [openInspector, openRightInspectorAction](bool checked) { |
|
167 | 167 | openInspector(checked, true, openRightInspectorAction); |
|
168 | 168 | }); |
|
169 | 169 | |
|
170 | 170 | this->menuBar()->addAction(tr("File")); |
|
171 | 171 | auto mainToolBar = this->addToolBar(QStringLiteral("MainToolBar")); |
|
172 | 172 | |
|
173 | 173 | auto timeWidget = new TimeWidget{}; |
|
174 | 174 | mainToolBar->addWidget(timeWidget); |
|
175 | 175 | |
|
176 | 176 | // Widgets / controllers connections |
|
177 | 177 | |
|
178 | 178 | // DataSource |
|
179 | 179 | connect(&sqpApp->dataSourceController(), SIGNAL(dataSourceItemSet(DataSourceItem *)), |
|
180 | 180 | m_Ui->dataSourceWidget, SLOT(addDataSource(DataSourceItem *))); |
|
181 | 181 | |
|
182 | 182 | // Time |
|
183 | 183 | connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), |
|
184 | 184 | SLOT(onTimeToUpdate(SqpDateTime))); |
|
185 | 185 | |
|
186 | qRegisterMetaType<SqpDateTime>(); | |
|
187 | 186 | connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)), |
|
188 | 187 | &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime))); |
|
189 | 188 | |
|
190 | 189 | // Widgets / widgets connections |
|
191 | qRegisterMetaType<std::shared_ptr<Variable> >(); | |
|
192 | 190 | |
|
193 | 191 | // For the following connections, we use DirectConnection to allow each widget that can |
|
194 | 192 | // potentially attach a menu to the variable's menu to do so before this menu is displayed. |
|
195 | 193 | // The order of connections is also important, since it determines the order in which each |
|
196 | 194 | // widget will attach its menu |
|
197 | 195 | connect( |
|
198 | 196 | m_Ui->variableInspectorWidget, |
|
199 | 197 | SIGNAL(tableMenuAboutToBeDisplayed(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
200 | 198 | m_Ui->view, SLOT(attachVariableMenu(QMenu *, const QVector<std::shared_ptr<Variable> > &)), |
|
201 | 199 | Qt::DirectConnection); |
|
202 | 200 | |
|
203 | 201 | /* QLopGUI::registerMenuBar(menuBar()); |
|
204 | 202 | this->setWindowIcon(QIcon(":/sciqlopLOGO.svg")); |
|
205 | 203 | this->m_progressWidget = new QWidget(); |
|
206 | 204 | this->m_progressLayout = new QVBoxLayout(this->m_progressWidget); |
|
207 | 205 | this->m_progressWidget->setLayout(this->m_progressLayout); |
|
208 | 206 | this->m_progressWidget->setWindowModality(Qt::WindowModal); |
|
209 | 207 | m_progressThreadIds = (int*) malloc(OMP_THREADS*sizeof(int)); |
|
210 | 208 | for(int i=0;i<OMP_THREADS;i++) |
|
211 | 209 | { |
|
212 | 210 | this->m_progress.append(new QProgressBar(this->m_progressWidget)); |
|
213 | 211 | this->m_progress.last()->setMinimum(0); |
|
214 | 212 | this->m_progress.last()->setMaximum(100); |
|
215 | 213 | this->m_progressLayout->addWidget(this->m_progress.last()); |
|
216 | 214 | this->m_progressWidget->hide(); |
|
217 | 215 | this->m_progressThreadIds[i] = -1; |
|
218 | 216 | } |
|
219 | 217 | this->m_progressWidget->setWindowTitle("Loading File"); |
|
220 | 218 | const QList<QLopService*>ServicesToLoad=QList<QLopService*>() |
|
221 | 219 | << QLopCore::self() |
|
222 | 220 | << QLopPlotManager::self() |
|
223 | 221 | << QLopCodecManager::self() |
|
224 | 222 | << FileDownloader::self() |
|
225 | 223 | << QLopDataBase::self() |
|
226 | 224 | << SpaceData::self(); |
|
227 | 225 | |
|
228 | 226 | CDFCodec::registerToManager(); |
|
229 | 227 | AMDATXTCodec::registerToManager(); |
|
230 | 228 | |
|
231 | 229 | |
|
232 | 230 | for(int i=0;i<ServicesToLoad.count();i++) |
|
233 | 231 | { |
|
234 | 232 | qDebug()<<ServicesToLoad.at(i)->serviceName(); |
|
235 | 233 | ServicesToLoad.at(i)->initialize(); //must be called before getGUI |
|
236 | 234 | QDockWidget* wdgt=ServicesToLoad.at(i)->getGUI(); |
|
237 | 235 | if(wdgt) |
|
238 | 236 | { |
|
239 | 237 | wdgt->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
240 | 238 | this->addDockWidget(Qt::TopDockWidgetArea,wdgt); |
|
241 | 239 | } |
|
242 | 240 | PythonQt::self()->getMainModule().addObject(ServicesToLoad.at(i)->serviceName(),(QObject*)ServicesToLoad.at(i)); |
|
243 | 241 | }*/ |
|
244 | 242 | } |
|
245 | 243 | |
|
246 | 244 | MainWindow::~MainWindow() |
|
247 | 245 | { |
|
248 | 246 | } |
|
249 | 247 | |
|
250 | 248 | |
|
251 | 249 | void MainWindow::changeEvent(QEvent *e) |
|
252 | 250 | { |
|
253 | 251 | QMainWindow::changeEvent(e); |
|
254 | 252 | switch (e->type()) { |
|
255 | 253 | case QEvent::LanguageChange: |
|
256 | 254 | m_Ui->retranslateUi(this); |
|
257 | 255 | break; |
|
258 | 256 | default: |
|
259 | 257 | break; |
|
260 | 258 | } |
|
261 | 259 | } |
@@ -1,39 +1,42 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATAPROVIDER_H |
|
2 | 2 | #define SCIQLOP_IDATAPROVIDER_H |
|
3 | 3 | |
|
4 | 4 | #include <memory> |
|
5 | 5 | |
|
6 | 6 | #include <QObject> |
|
7 | 7 | |
|
8 | #include <Common/MetaTypes.h> | |
|
9 | ||
|
8 | 10 | #include <Data/SqpDateTime.h> |
|
9 | 11 | |
|
10 | 12 | class DataProviderParameters; |
|
11 | 13 | class IDataSeries; |
|
12 | 14 | |
|
13 | 15 | /** |
|
14 | 16 | * @brief The IDataProvider interface aims to declare a data provider. |
|
15 | 17 | * |
|
16 | 18 | * A data provider is an entity that generates data and returns it according to various parameters |
|
17 | 19 | * (time interval, product to retrieve the data, etc.) |
|
18 | 20 | * |
|
19 | 21 | * @sa IDataSeries |
|
20 | 22 | */ |
|
21 | 23 | class IDataProvider : public QObject { |
|
22 | 24 | |
|
23 | 25 | Q_OBJECT |
|
24 | 26 | public: |
|
25 | 27 | virtual ~IDataProvider() noexcept = default; |
|
26 | 28 | |
|
27 | 29 | virtual std::unique_ptr<IDataSeries> |
|
28 | 30 | retrieveData(const DataProviderParameters ¶meters) const = 0; |
|
29 | 31 | |
|
30 | 32 | |
|
31 | 33 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; |
|
32 | 34 | |
|
33 | 35 | signals: |
|
34 | 36 | void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime); |
|
35 | 37 | }; |
|
38 | ||
|
36 | 39 | // Required for using shared_ptr in signals/slots |
|
37 |
|
|
|
40 | SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>) | |
|
38 | 41 | |
|
39 | 42 | #endif // SCIQLOP_IDATAPROVIDER_H |
@@ -1,54 +1,54 | |||
|
1 | 1 | #ifndef SCIQLOP_IDATASERIES_H |
|
2 | 2 | #define SCIQLOP_IDATASERIES_H |
|
3 | 3 | |
|
4 | #include <Common/MetaTypes.h> | |
|
4 | 5 | |
|
5 | 6 | #include <memory> |
|
6 | 7 | |
|
7 | #include <QObject> | |
|
8 | 8 | #include <QString> |
|
9 | 9 | |
|
10 | 10 | template <int Dim> |
|
11 | 11 | class ArrayData; |
|
12 | 12 | |
|
13 | 13 | struct Unit { |
|
14 | 14 | explicit Unit(const QString &name = {}, bool timeUnit = false) |
|
15 | 15 | : m_Name{name}, m_TimeUnit{timeUnit} |
|
16 | 16 | { |
|
17 | 17 | } |
|
18 | 18 | |
|
19 | 19 | QString m_Name; ///< Unit name |
|
20 | 20 | bool m_TimeUnit; ///< The unit is a unit of time |
|
21 | 21 | }; |
|
22 | 22 | |
|
23 | 23 | /** |
|
24 | 24 | * @brief The IDataSeries aims to declare a data series. |
|
25 | 25 | * |
|
26 | 26 | * A data series is an entity that contains at least : |
|
27 | 27 | * - one dataset representing the x-axis |
|
28 | 28 | * - one dataset representing the values |
|
29 | 29 | * |
|
30 | 30 | * Each dataset is represented by an ArrayData, and is associated with a unit. |
|
31 | 31 | * |
|
32 | 32 | * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the |
|
33 | 33 | * IDataSeries. The x-axis dataset is always unidimensional. |
|
34 | 34 | * |
|
35 | 35 | * @sa ArrayData |
|
36 | 36 | */ |
|
37 | 37 | class IDataSeries { |
|
38 | 38 | public: |
|
39 | 39 | virtual ~IDataSeries() noexcept = default; |
|
40 | 40 | |
|
41 | 41 | /// Returns the x-axis dataset |
|
42 | 42 | virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0; |
|
43 | 43 | |
|
44 | 44 | virtual Unit xAxisUnit() const = 0; |
|
45 | 45 | |
|
46 | 46 | virtual Unit valuesUnit() const = 0; |
|
47 | 47 | |
|
48 | 48 | virtual void merge(IDataSeries *dataSeries) = 0; |
|
49 | 49 | }; |
|
50 | 50 | |
|
51 | 51 | // Required for using shared_ptr in signals/slots |
|
52 |
|
|
|
52 | SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>) | |
|
53 | 53 | |
|
54 | 54 | #endif // SCIQLOP_IDATASERIES_H |
@@ -1,42 +1,44 | |||
|
1 | 1 | #ifndef SCIQLOP_SQPDATETIME_H |
|
2 | 2 | #define SCIQLOP_SQPDATETIME_H |
|
3 | 3 | |
|
4 | 4 | #include <QObject> |
|
5 | 5 | |
|
6 | 6 | #include <QDateTime> |
|
7 | 7 | #include <QDebug> |
|
8 | 8 | |
|
9 | #include <Common/MetaTypes.h> | |
|
10 | ||
|
9 | 11 | /** |
|
10 | 12 | * @brief The SqpDateTime struct holds the information of time parameters |
|
11 | 13 | */ |
|
12 | 14 | struct SqpDateTime { |
|
13 | 15 | /// Start time |
|
14 | 16 | double m_TStart; |
|
15 | 17 | /// End time |
|
16 | 18 | double m_TEnd; |
|
17 | 19 | |
|
18 | 20 | bool contains(const SqpDateTime &dateTime) |
|
19 | 21 | { |
|
20 | 22 | return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd); |
|
21 | 23 | } |
|
22 | 24 | |
|
23 | 25 | bool intersect(const SqpDateTime &dateTime) |
|
24 | 26 | { |
|
25 | 27 | return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd); |
|
26 | 28 | } |
|
27 | 29 | }; |
|
28 | 30 | |
|
29 | 31 | inline QDebug operator<<(QDebug d, SqpDateTime obj) |
|
30 | 32 | { |
|
31 | 33 | auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000); |
|
32 | 34 | auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000); |
|
33 | 35 | |
|
34 | 36 | // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; |
|
35 | 37 | d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; |
|
36 | 38 | return d; |
|
37 | 39 | } |
|
38 | 40 | |
|
39 | 41 | // Required for using shared_ptr in signals/slots |
|
40 | Q_DECLARE_METATYPE(SqpDateTime) | |
|
42 | SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime) | |
|
41 | 43 | |
|
42 | 44 | #endif // SCIQLOP_SQPDATETIME_H |
@@ -1,55 +1,55 | |||
|
1 | 1 | #ifndef SCIQLOP_VARIABLE_H |
|
2 | 2 | #define SCIQLOP_VARIABLE_H |
|
3 | 3 | |
|
4 | 4 | #include <Data/SqpDateTime.h> |
|
5 | 5 | |
|
6 | ||
|
7 | 6 | #include <QLoggingCategory> |
|
8 | 7 | #include <QObject> |
|
9 | 8 | |
|
9 | #include <Common/MetaTypes.h> | |
|
10 | 10 | #include <Common/spimpl.h> |
|
11 | 11 | |
|
12 | 12 | Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) |
|
13 | 13 | |
|
14 | 14 | class IDataSeries; |
|
15 | 15 | class QString; |
|
16 | 16 | |
|
17 | 17 | /** |
|
18 | 18 | * @brief The Variable class represents a variable in SciQlop. |
|
19 | 19 | */ |
|
20 | 20 | class Variable : public QObject { |
|
21 | 21 | |
|
22 | 22 | Q_OBJECT |
|
23 | 23 | |
|
24 | 24 | public: |
|
25 | 25 | explicit Variable(const QString &name, const QString &unit, const QString &mission, |
|
26 | 26 | const SqpDateTime &dateTime); |
|
27 | 27 | |
|
28 | 28 | QString name() const noexcept; |
|
29 | 29 | QString mission() const noexcept; |
|
30 | 30 | QString unit() const noexcept; |
|
31 | 31 | SqpDateTime dateTime() const noexcept; |
|
32 | 32 | void setDateTime(const SqpDateTime &dateTime) noexcept; |
|
33 | 33 | |
|
34 | 34 | /// @return the data of the variable, nullptr if there is no data |
|
35 | 35 | IDataSeries *dataSeries() const noexcept; |
|
36 | 36 | |
|
37 | 37 | bool contains(const SqpDateTime &dateTime); |
|
38 | 38 | bool intersect(const SqpDateTime &dateTime); |
|
39 | 39 | void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept; |
|
40 | 40 | |
|
41 | 41 | public slots: |
|
42 | 42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
43 | 43 | |
|
44 | 44 | signals: |
|
45 | 45 | void updated(); |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | 48 | class VariablePrivate; |
|
49 | 49 | spimpl::unique_impl_ptr<VariablePrivate> impl; |
|
50 | 50 | }; |
|
51 | 51 | |
|
52 | 52 | // Required for using shared_ptr in signals/slots |
|
53 |
|
|
|
53 | SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>) | |
|
54 | 54 | |
|
55 | 55 | #endif // SCIQLOP_VARIABLE_H |
@@ -1,177 +1,175 | |||
|
1 | 1 | #include <Variable/Variable.h> |
|
2 | 2 | #include <Variable/VariableCacheController.h> |
|
3 | 3 | #include <Variable/VariableController.h> |
|
4 | 4 | #include <Variable/VariableModel.h> |
|
5 | 5 | |
|
6 | 6 | #include <Data/DataProviderParameters.h> |
|
7 | 7 | #include <Data/IDataProvider.h> |
|
8 | 8 | #include <Data/IDataSeries.h> |
|
9 | 9 | #include <Time/TimeController.h> |
|
10 | 10 | |
|
11 | 11 | #include <QDateTime> |
|
12 | 12 | #include <QMutex> |
|
13 | 13 | #include <QThread> |
|
14 | 14 | #include <QtCore/QItemSelectionModel> |
|
15 | 15 | |
|
16 | 16 | #include <unordered_map> |
|
17 | 17 | |
|
18 | 18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
19 | 19 | |
|
20 | 20 | namespace { |
|
21 | 21 | |
|
22 | 22 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
23 | 23 | /// will be deleted when the timerange is recovered from SciQlop |
|
24 | 24 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider, |
|
25 | 25 | const SqpDateTime &dateTime) noexcept |
|
26 | 26 | { |
|
27 | 27 | auto parameters = DataProviderParameters{dateTime}; |
|
28 | 28 | |
|
29 | 29 | return provider.retrieveData(parameters); |
|
30 | 30 | } |
|
31 | 31 | |
|
32 | 32 | } // namespace |
|
33 | 33 | |
|
34 | 34 | struct VariableController::VariableControllerPrivate { |
|
35 | 35 | explicit VariableControllerPrivate(VariableController *parent) |
|
36 | 36 | : m_WorkingMutex{}, |
|
37 | 37 | m_VariableModel{new VariableModel{parent}}, |
|
38 | 38 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
39 | 39 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | QMutex m_WorkingMutex; |
|
44 | 44 | /// Variable model. The VariableController has the ownership |
|
45 | 45 | VariableModel *m_VariableModel; |
|
46 | 46 | QItemSelectionModel *m_VariableSelectionModel; |
|
47 | 47 | |
|
48 | 48 | |
|
49 | 49 | TimeController *m_TimeController{nullptr}; |
|
50 | 50 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
51 | 51 | |
|
52 | 52 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
53 | 53 | m_VariableToProviderMap; |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 | 56 | VariableController::VariableController(QObject *parent) |
|
57 | 57 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
58 | 58 | { |
|
59 | 59 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
60 | 60 | << QThread::currentThread(); |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | VariableController::~VariableController() |
|
64 | 64 | { |
|
65 | 65 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
66 | 66 | << QThread::currentThread(); |
|
67 | 67 | this->waitForFinish(); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | VariableModel *VariableController::variableModel() noexcept |
|
71 | 71 | { |
|
72 | 72 | return impl->m_VariableModel; |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
76 | 76 | { |
|
77 | 77 | return impl->m_VariableSelectionModel; |
|
78 | 78 | } |
|
79 | 79 | |
|
80 | 80 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
81 | 81 | { |
|
82 | 82 | impl->m_TimeController = timeController; |
|
83 | 83 | } |
|
84 | 84 | |
|
85 | 85 | void VariableController::createVariable(const QString &name, |
|
86 | 86 | std::shared_ptr<IDataProvider> provider) noexcept |
|
87 | 87 | { |
|
88 | 88 | |
|
89 | 89 | if (!impl->m_TimeController) { |
|
90 | 90 | qCCritical(LOG_VariableController()) |
|
91 | 91 | << tr("Impossible to create variable: The time controller is null"); |
|
92 | 92 | return; |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | |
|
96 | 96 | /// @todo : for the moment : |
|
97 | 97 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
98 | 98 | /// it will be retained later |
|
99 | 99 | /// - default data are generated for the variable, without taking into account the timerange set |
|
100 | 100 | /// in sciqlop |
|
101 | 101 | auto dateTime = impl->m_TimeController->dateTime(); |
|
102 | 102 | if (auto newVariable = impl->m_VariableModel->createVariable( |
|
103 | 103 | name, dateTime, generateDefaultDataSeries(*provider, dateTime))) { |
|
104 | 104 | |
|
105 | 105 | // store the provider |
|
106 | 106 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
107 | qRegisterMetaType<std::shared_ptr<IDataSeries> >(); | |
|
108 | qRegisterMetaType<SqpDateTime>(); | |
|
109 | 107 | connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), |
|
110 | 108 | &Variable::onAddDataSeries); |
|
111 | 109 | |
|
112 | 110 | |
|
113 | 111 | // store in cache |
|
114 | 112 | impl->m_VariableCacheController->addDateTime(newVariable, dateTime); |
|
115 | 113 | |
|
116 | 114 | // notify the creation |
|
117 | 115 | emit variableCreated(newVariable); |
|
118 | 116 | } |
|
119 | 117 | } |
|
120 | 118 | |
|
121 | 119 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
122 | 120 | { |
|
123 | 121 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
124 | 122 | |
|
125 | 123 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
126 | 124 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
127 | 125 | selectedVariable->setDateTime(dateTime); |
|
128 | 126 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
129 | 127 | } |
|
130 | 128 | } |
|
131 | 129 | } |
|
132 | 130 | |
|
133 | 131 | |
|
134 | 132 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
135 | 133 | const SqpDateTime &dateTime) |
|
136 | 134 | { |
|
137 | 135 | // we want to load data of the variable for the dateTime. |
|
138 | 136 | // First we check if the cache contains some of them. |
|
139 | 137 | // For the other, we ask the provider to give them. |
|
140 | 138 | if (variable) { |
|
141 | 139 | |
|
142 | 140 | auto dateTimeListNotInCache |
|
143 | 141 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
144 | 142 | |
|
145 | 143 | if (!dateTimeListNotInCache.empty()) { |
|
146 | 144 | // Ask the provider for each data on the dateTimeListNotInCache |
|
147 | 145 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
148 | 146 | std::move(dateTimeListNotInCache)); |
|
149 | 147 | // store in cache |
|
150 | 148 | impl->m_VariableCacheController->addDateTime(variable, dateTime); |
|
151 | 149 | } |
|
152 | 150 | else { |
|
153 | 151 | emit variable->updated(); |
|
154 | 152 | } |
|
155 | 153 | } |
|
156 | 154 | else { |
|
157 | 155 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
158 | 156 | } |
|
159 | 157 | } |
|
160 | 158 | |
|
161 | 159 | |
|
162 | 160 | void VariableController::initialize() |
|
163 | 161 | { |
|
164 | 162 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
165 | 163 | impl->m_WorkingMutex.lock(); |
|
166 | 164 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
167 | 165 | } |
|
168 | 166 | |
|
169 | 167 | void VariableController::finalize() |
|
170 | 168 | { |
|
171 | 169 | impl->m_WorkingMutex.unlock(); |
|
172 | 170 | } |
|
173 | 171 | |
|
174 | 172 | void VariableController::waitForFinish() |
|
175 | 173 | { |
|
176 | 174 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
177 | 175 | } |
@@ -1,120 +1,118 | |||
|
1 | 1 | #include "SqpApplication.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/IDataProvider.h> |
|
4 | 4 | #include <DataSource/DataSourceController.h> |
|
5 | 5 | #include <QThread> |
|
6 | 6 | #include <Time/TimeController.h> |
|
7 | 7 | #include <Variable/Variable.h> |
|
8 | 8 | #include <Variable/VariableController.h> |
|
9 | 9 | #include <Visualization/VisualizationController.h> |
|
10 | 10 | |
|
11 | 11 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
12 | 12 | |
|
13 | 13 | class SqpApplication::SqpApplicationPrivate { |
|
14 | 14 | public: |
|
15 | 15 | SqpApplicationPrivate() |
|
16 | 16 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
17 | 17 | m_TimeController{std::make_unique<TimeController>()}, |
|
18 | 18 | m_VariableController{std::make_unique<VariableController>()}, |
|
19 | 19 | m_VisualizationController{std::make_unique<VisualizationController>()} |
|
20 | 20 | { |
|
21 | 21 | // /////////////////////////////// // |
|
22 | 22 | // Connections between controllers // |
|
23 | 23 | // /////////////////////////////// // |
|
24 | 24 | |
|
25 | 25 | // VariableController <-> DataSourceController |
|
26 | qRegisterMetaType<std::shared_ptr<IDataProvider> >(); | |
|
27 | 26 | connect(m_DataSourceController.get(), |
|
28 | 27 | SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)), |
|
29 | 28 | m_VariableController.get(), |
|
30 | 29 | SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>))); |
|
31 | 30 | |
|
32 | 31 | // VariableController <-> VisualizationController |
|
33 | qRegisterMetaType<std::shared_ptr<Variable> >(); | |
|
34 | 32 | connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)), |
|
35 | 33 | m_VisualizationController.get(), |
|
36 | 34 | SIGNAL(variableCreated(std::shared_ptr<Variable>))); |
|
37 | 35 | |
|
38 | 36 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
39 | 37 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
40 | 38 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
41 | 39 | |
|
42 | 40 | // Additionnal init |
|
43 | 41 | m_VariableController->setTimeController(m_TimeController.get()); |
|
44 | 42 | } |
|
45 | 43 | |
|
46 | 44 | virtual ~SqpApplicationPrivate() |
|
47 | 45 | { |
|
48 | 46 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); |
|
49 | 47 | m_DataSourceControllerThread.quit(); |
|
50 | 48 | m_DataSourceControllerThread.wait(); |
|
51 | 49 | |
|
52 | 50 | m_VariableControllerThread.quit(); |
|
53 | 51 | m_VariableControllerThread.wait(); |
|
54 | 52 | |
|
55 | 53 | m_VisualizationControllerThread.quit(); |
|
56 | 54 | m_VisualizationControllerThread.wait(); |
|
57 | 55 | } |
|
58 | 56 | |
|
59 | 57 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
60 | 58 | std::unique_ptr<VariableController> m_VariableController; |
|
61 | 59 | std::unique_ptr<TimeController> m_TimeController; |
|
62 | 60 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
63 | 61 | QThread m_DataSourceControllerThread; |
|
64 | 62 | QThread m_VariableControllerThread; |
|
65 | 63 | QThread m_VisualizationControllerThread; |
|
66 | 64 | }; |
|
67 | 65 | |
|
68 | 66 | |
|
69 | 67 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
70 | 68 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
71 | 69 | { |
|
72 | 70 | qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction"); |
|
73 | 71 | |
|
74 | 72 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
75 | 73 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
76 | 74 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
77 | 75 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
78 | 76 | |
|
79 | 77 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
80 | 78 | &VariableController::initialize); |
|
81 | 79 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
82 | 80 | &VariableController::finalize); |
|
83 | 81 | |
|
84 | 82 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
85 | 83 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
86 | 84 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
87 | 85 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
88 | 86 | |
|
89 | 87 | impl->m_DataSourceControllerThread.start(); |
|
90 | 88 | impl->m_VariableControllerThread.start(); |
|
91 | 89 | impl->m_VisualizationControllerThread.start(); |
|
92 | 90 | } |
|
93 | 91 | |
|
94 | 92 | SqpApplication::~SqpApplication() |
|
95 | 93 | { |
|
96 | 94 | } |
|
97 | 95 | |
|
98 | 96 | void SqpApplication::initialize() |
|
99 | 97 | { |
|
100 | 98 | } |
|
101 | 99 | |
|
102 | 100 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
103 | 101 | { |
|
104 | 102 | return *impl->m_DataSourceController; |
|
105 | 103 | } |
|
106 | 104 | |
|
107 | 105 | TimeController &SqpApplication::timeController() noexcept |
|
108 | 106 | { |
|
109 | 107 | return *impl->m_TimeController; |
|
110 | 108 | } |
|
111 | 109 | |
|
112 | 110 | VariableController &SqpApplication::variableController() noexcept |
|
113 | 111 | { |
|
114 | 112 | return *impl->m_VariableController; |
|
115 | 113 | } |
|
116 | 114 | |
|
117 | 115 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
118 | 116 | { |
|
119 | 117 | return *impl->m_VisualizationController; |
|
120 | 118 | } |
General Comments 0
You need to be logged in to leave comments.
Login now