@@ -0,0 +1,54 | |||||
|
1 | import sys | |||
|
2 | import os | |||
|
3 | if not hasattr(sys, 'argv'): | |||
|
4 | sys.argv = [''] | |||
|
5 | current_script_path = os.path.dirname(os.path.realpath(__file__)) | |||
|
6 | sys.path.append(current_script_path) | |||
|
7 | import amda | |||
|
8 | import pytestamda | |||
|
9 | ||||
|
10 | import numpy as np | |||
|
11 | import datetime | |||
|
12 | import time | |||
|
13 | import unittest | |||
|
14 | import ddt | |||
|
15 | ||||
|
16 | def wait_for_downloads(): | |||
|
17 | while pytestamda.VariableController.hasPendingDownloads(): | |||
|
18 | time.sleep(0.1) | |||
|
19 | ||||
|
20 | def extract_vector(variable): | |||
|
21 | return zip(*[(pt.x, pt.value(0), pt.value(1), pt.value(2)) for pt in variable]) | |||
|
22 | ||||
|
23 | def compare_with_ref(var, ref): | |||
|
24 | t_ref, x_ref, y_ref, z_ref = ref | |||
|
25 | t,x,y,z = extract_vector(var) | |||
|
26 | return all([ | |||
|
27 | all([t_ref[i].astype(float)/1000000 == t[i] for i in range(len(t))]), | |||
|
28 | all([x_ref[i] == x[i] for i in range(len(x))]), | |||
|
29 | all([y_ref[i] == y[i] for i in range(len(y))]), | |||
|
30 | all([z_ref[i] == z[i] for i in range(len(z))]) | |||
|
31 | ]) | |||
|
32 | ||||
|
33 | @ddt.ddt | |||
|
34 | class FunctionalTests(unittest.TestCase): | |||
|
35 | def setUp(self): | |||
|
36 | pass | |||
|
37 | ||||
|
38 | @ddt.data( | |||
|
39 | (datetime.datetime(2012,10,20,8,10,00),datetime.datetime(2012,10,20,12,0,0)), | |||
|
40 | (datetime.datetime(2025,1,1,15,0,0),datetime.datetime(2025,1,1,16,0,0)), | |||
|
41 | (datetime.datetime(2000,1,1,0,0,0),datetime.datetime(2000,1,1,12,0,0)) | |||
|
42 | ) | |||
|
43 | def test_simple_download(self, case): | |||
|
44 | tstart = case[0] | |||
|
45 | tstop = case[1] | |||
|
46 | pytestamda.TimeController.setTime(pytestamda.SqpRange(tstart, tstop)) | |||
|
47 | variable = pytestamda.VariableController.createVariable("bx_gse",pytestamda.amda_provider()) | |||
|
48 | wait_for_downloads() | |||
|
49 | t_ref, x_ref, y_ref, z_ref = amda.generate_data(np.datetime64(tstart), np.datetime64(tstop), 4) | |||
|
50 | self.assertTrue( compare_with_ref(variable,(t_ref, x_ref, y_ref, z_ref) ) ) | |||
|
51 | ||||
|
52 | ||||
|
53 | if __name__ == '__main__': | |||
|
54 | unittest.main(exit=False) |
@@ -0,0 +1,39 | |||||
|
1 | import sys | |||
|
2 | import os | |||
|
3 | if not hasattr(sys, 'argv'): | |||
|
4 | sys.argv = [''] | |||
|
5 | current_script_path = os.path.dirname(os.path.realpath(__file__)) | |||
|
6 | sys.path.append(current_script_path) | |||
|
7 | import pytestamda | |||
|
8 | import amda | |||
|
9 | ||||
|
10 | import numpy as np | |||
|
11 | import datetime | |||
|
12 | import time | |||
|
13 | import unittest | |||
|
14 | import ddt | |||
|
15 | ||||
|
16 | path = current_script_path+'/../tests-resources/TestAmdaResultParser/ValidScalar1.txt' | |||
|
17 | ||||
|
18 | @ddt.ddt | |||
|
19 | class FunctionalTests(unittest.TestCase): | |||
|
20 | def setUp(self): | |||
|
21 | pass | |||
|
22 | ||||
|
23 | @ddt.data( | |||
|
24 | current_script_path+'/../tests-resources/TestAmdaResultParser/ValidScalar1.txt' | |||
|
25 | ) | |||
|
26 | def test_correct_scalars(self, case): | |||
|
27 | scalar_sciqlop = pytestamda.AmdaResultParser.readScalarTxt(case) | |||
|
28 | scalar_ref = amda.load_scalar(case) | |||
|
29 | self.assertTrue(len(scalar_ref) == len(scalar_sciqlop)) | |||
|
30 | self.assertTrue(all( | |||
|
31 | [scalar_ref[i][1] == scalar_sciqlop[i].value() | |||
|
32 | for i in range(len(scalar_sciqlop))])) | |||
|
33 | self.assertTrue(all( | |||
|
34 | [scalar_ref[i][0].timestamp() == scalar_sciqlop[i].x | |||
|
35 | for i in range(len(scalar_sciqlop))])) | |||
|
36 | ||||
|
37 | ||||
|
38 | if __name__ == '__main__': | |||
|
39 | unittest.main(exit=False) |
@@ -0,0 +1,29 | |||||
|
1 | import sys | |||
|
2 | import os | |||
|
3 | import numpy as np | |||
|
4 | import datetime | |||
|
5 | import time | |||
|
6 | ||||
|
7 | os.environ['TZ'] = 'UTC' | |||
|
8 | epoch_2000 = np.datetime64('2000-01-01T00:00:00',tzinfo=datetime.timezone.utc) | |||
|
9 | ||||
|
10 | def load_scalar(fname): | |||
|
11 | with open(fname, "r") as f: | |||
|
12 | return [[ | |||
|
13 | datetime.datetime(*(time.strptime(line.split()[0], '%Y-%m-%dT%H:%M:%S.%f')[0:6]), | |||
|
14 | tzinfo=datetime.timezone.utc), | |||
|
15 | float(line.split()[1])] | |||
|
16 | for line in f if "#" not in line] | |||
|
17 | ||||
|
18 | """ | |||
|
19 | Copied from myAMDA should be factored in somehow | |||
|
20 | """ | |||
|
21 | def generate_data(tstart, tstop, dt): | |||
|
22 | delta = np.timedelta64(dt, 's') | |||
|
23 | vector_size = int(np.round((tstop-tstart)/delta)) + 1 | |||
|
24 | t = [tstart+i*delta for i in range(vector_size)] | |||
|
25 | x0 = tstart-epoch_2000 | |||
|
26 | x = [(x0 + i * delta).astype('float')/1000000 for i in range(vector_size)] | |||
|
27 | y = [(x0 + (i+1) * delta).astype('float')/1000000 for i in range(vector_size)] | |||
|
28 | z = [(x0 + (i+2) * delta).astype('float')/1000000 for i in range(vector_size)] | |||
|
29 | return t,x,y,z |
@@ -1,144 +1,148 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include "CoreGlobal.h" |
|
4 | #include "CoreGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/AcquisitionDataPacket.h> |
|
6 | #include <Data/AcquisitionDataPacket.h> | |
7 | #include <Data/SqpRange.h> |
|
7 | #include <Data/SqpRange.h> | |
8 |
|
8 | |||
9 | #include <QLoggingCategory> |
|
9 | #include <QLoggingCategory> | |
10 | #include <QObject> |
|
10 | #include <QObject> | |
11 | #include <QUuid> |
|
11 | #include <QUuid> | |
12 |
|
12 | |||
13 | #include <Common/spimpl.h> |
|
13 | #include <Common/spimpl.h> | |
14 |
|
14 | |||
15 | class IDataProvider; |
|
15 | class IDataProvider; | |
16 | class QItemSelectionModel; |
|
16 | class QItemSelectionModel; | |
17 | class TimeController; |
|
17 | class TimeController; | |
18 | class Variable; |
|
18 | class Variable; | |
19 | class VariableModel; |
|
19 | class VariableModel; | |
20 |
|
20 | |||
21 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
21 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | /** |
|
24 | /** | |
25 | * Possible types of zoom operation |
|
25 | * Possible types of zoom operation | |
26 | */ |
|
26 | */ | |
27 | enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; |
|
27 | enum class AcquisitionZoomType { ZoomOut, ZoomIn, PanRight, PanLeft, Unknown }; | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | /** |
|
30 | /** | |
31 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
31 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
32 | */ |
|
32 | */ | |
33 | class SCIQLOP_CORE_EXPORT VariableController : public QObject { |
|
33 | class SCIQLOP_CORE_EXPORT VariableController : public QObject { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | explicit VariableController(QObject *parent = 0); |
|
36 | explicit VariableController(QObject *parent = 0); | |
37 | virtual ~VariableController(); |
|
37 | virtual ~VariableController(); | |
38 |
|
38 | |||
39 | VariableModel *variableModel() noexcept; |
|
39 | VariableModel *variableModel() noexcept; | |
40 | QItemSelectionModel *variableSelectionModel() noexcept; |
|
40 | QItemSelectionModel *variableSelectionModel() noexcept; | |
41 |
|
41 | |||
42 | void setTimeController(TimeController *timeController) noexcept; |
|
42 | void setTimeController(TimeController *timeController) noexcept; | |
43 |
|
43 | |||
44 | /** |
|
44 | /** | |
45 | * Clones the variable passed in parameter and adds the duplicate to the controller |
|
45 | * Clones the variable passed in parameter and adds the duplicate to the controller | |
46 | * @param variable the variable to duplicate |
|
46 | * @param variable the variable to duplicate | |
47 | * @return the duplicate created, nullptr if the variable couldn't be created |
|
47 | * @return the duplicate created, nullptr if the variable couldn't be created | |
48 | */ |
|
48 | */ | |
49 | std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept; |
|
49 | std::shared_ptr<Variable> cloneVariable(std::shared_ptr<Variable> variable) noexcept; | |
50 |
|
50 | |||
51 | /// Returns the MIME data associated to a list of variables |
|
51 | /// Returns the MIME data associated to a list of variables | |
52 | QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const; |
|
52 | QByteArray mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const; | |
53 |
|
53 | |||
54 | /// Returns the list of variables contained in a MIME data |
|
54 | /// Returns the list of variables contained in a MIME data | |
55 | QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const; |
|
55 | QList<std::shared_ptr<Variable> > variablesForMimeData(const QByteArray &mimeData) const; | |
56 |
|
56 | |||
57 | static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange); |
|
57 | static AcquisitionZoomType getZoomType(const SqpRange &range, const SqpRange &oldRange); | |
|
58 | ||||
|
59 | /// Returns True if there are pending downloads | |||
|
60 | bool hasPendingDownloads(); | |||
58 | signals: |
|
61 | signals: | |
59 | /// Signal emitted when a variable is about to be deleted from the controller |
|
62 | /// Signal emitted when a variable is about to be deleted from the controller | |
60 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
63 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
61 |
|
64 | |||
62 | /// Signal emitted when a data acquisition is requested on a range for a variable |
|
65 | /// Signal emitted when a data acquisition is requested on a range for a variable | |
63 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
66 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); | |
64 |
|
67 | |||
65 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed |
|
68 | /// Signal emitted when a sub range of the cacheRange of the variable can be displayed | |
66 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); |
|
69 | void updateVarDisplaying(std::shared_ptr<Variable> variable, const SqpRange &range); | |
67 |
|
70 | |||
68 | /// Signal emitted when all acquisitions related to the variables have been completed (whether |
|
71 | /// Signal emitted when all acquisitions related to the variables have been completed (whether | |
69 | /// validated, canceled, or failed) |
|
72 | /// validated, canceled, or failed) | |
70 | void acquisitionFinished(); |
|
73 | void acquisitionFinished(); | |
71 |
|
74 | |||
72 | void variableAdded(const std::shared_ptr<Variable> &variable); |
|
75 | void variableAdded(const std::shared_ptr<Variable> &variable); | |
73 |
|
76 | |||
74 | public slots: |
|
77 | public slots: | |
75 | /** |
|
78 | /** | |
76 | * Deletes from the controller the variable passed in parameter. |
|
79 | * Deletes from the controller the variable passed in parameter. | |
77 | * |
|
80 | * | |
78 | * Delete a variable includes: |
|
81 | * Delete a variable includes: | |
79 | * - the deletion of the various references to the variable in SciQlop |
|
82 | * - the deletion of the various references to the variable in SciQlop | |
80 | * - the deletion of the model variable |
|
83 | * - the deletion of the model variable | |
81 | * - the deletion of the provider associated with the variable |
|
84 | * - the deletion of the provider associated with the variable | |
82 | * - removing the cache associated with the variable |
|
85 | * - removing the cache associated with the variable | |
83 | * |
|
86 | * | |
84 | * @param variable the variable to delete from the controller. |
|
87 | * @param variable the variable to delete from the controller. | |
85 | */ |
|
88 | */ | |
86 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
89 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
87 |
|
90 | |||
88 | /** |
|
91 | /** | |
89 | * Deletes from the controller the variables passed in parameter. |
|
92 | * Deletes from the controller the variables passed in parameter. | |
90 | * @param variables the variables to delete from the controller. |
|
93 | * @param variables the variables to delete from the controller. | |
91 | * @sa deleteVariable() |
|
94 | * @sa deleteVariable() | |
92 | */ |
|
95 | */ | |
93 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
96 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |
94 |
|
97 | |||
95 | /// Request the data loading of the variable whithin range |
|
98 | /// Request the data loading of the variable whithin range | |
96 | void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range, |
|
99 | void onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, const SqpRange &range, | |
97 | bool synchronise); |
|
100 | bool synchronise); | |
98 | /** |
|
101 | /** | |
99 | * Creates a new variable and adds it to the model |
|
102 | * Creates a new variable and adds it to the model | |
100 | * @param name the name of the new variable |
|
103 | * @param name the name of the new variable | |
101 | * @param metadata the metadata of the new variable |
|
104 | * @param metadata the metadata of the new variable | |
102 | * @param provider the data provider for the new variable |
|
105 | * @param provider the data provider for the new variable | |
103 | * @return the pointer to the new variable or nullptr if the creation failed |
|
106 | * @return the pointer to the new variable or nullptr if the creation failed | |
104 | */ |
|
107 | */ | |
105 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, |
|
108 | std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, | |
106 | std::shared_ptr<IDataProvider> provider) noexcept; |
|
109 | std::shared_ptr<IDataProvider> provider) noexcept; | |
107 |
|
110 | |||
108 | /// Update the temporal parameters of every selected variable to dateTime |
|
111 | /// Update the temporal parameters of every selected variable to dateTime | |
109 | void onDateTimeOnSelection(const SqpRange &dateTime); |
|
112 | void onDateTimeOnSelection(const SqpRange &dateTime); | |
110 |
|
113 | |||
111 | /// Update the temporal parameters of the specified variable |
|
114 | /// Update the temporal parameters of the specified variable | |
112 | void onUpdateDateTime(std::shared_ptr<Variable> variable, const SqpRange &dateTime); |
|
115 | void onUpdateDateTime(std::shared_ptr<Variable> variable, const SqpRange &dateTime); | |
113 |
|
116 | |||
114 |
|
117 | |||
115 | void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
118 | void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, | |
116 | const SqpRange &cacheRangeRequested, |
|
119 | const SqpRange &cacheRangeRequested, | |
117 | QVector<AcquisitionDataPacket> dataAcquired); |
|
120 | QVector<AcquisitionDataPacket> dataAcquired); | |
118 |
|
121 | |||
119 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); |
|
122 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); | |
120 |
|
123 | |||
121 | /// Cancel the current request for the variable |
|
124 | /// Cancel the current request for the variable | |
122 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); |
|
125 | void onAbortProgressRequested(std::shared_ptr<Variable> variable); | |
123 | void onAbortAcquisitionRequested(QUuid vIdentifier); |
|
126 | void onAbortAcquisitionRequested(QUuid vIdentifier); | |
124 |
|
127 | |||
125 | // synchronization group methods |
|
128 | // synchronization group methods | |
126 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); |
|
129 | void onAddSynchronizationGroupId(QUuid synchronizationGroupId); | |
127 | void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); |
|
130 | void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId); | |
128 | void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
131 | void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); | |
129 |
|
132 | |||
130 | /// Desynchronizes the variable of the group whose identifier is passed in parameter |
|
133 | /// Desynchronizes the variable of the group whose identifier is passed in parameter | |
131 | /// @remarks the method does nothing if the variable is not part of the group |
|
134 | /// @remarks the method does nothing if the variable is not part of the group | |
132 | void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); |
|
135 | void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId); | |
133 |
|
136 | |||
134 | void initialize(); |
|
137 | void initialize(); | |
135 | void finalize(); |
|
138 | void finalize(); | |
136 |
|
139 | |||
137 | private: |
|
140 | private: | |
138 | void waitForFinish(); |
|
141 | void waitForFinish(); | |
139 |
|
142 | |||
140 | class VariableControllerPrivate; |
|
143 | class VariableControllerPrivate; | |
141 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
144 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
142 | }; |
|
145 | }; | |
143 |
|
146 | |||
|
147 | ||||
144 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
148 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,1104 +1,1114 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableAcquisitionWorker.h> |
|
2 | #include <Variable/VariableAcquisitionWorker.h> | |
3 | #include <Variable/VariableCacheStrategy.h> |
|
3 | #include <Variable/VariableCacheStrategy.h> | |
4 | #include <Variable/VariableCacheStrategyFactory.h> |
|
4 | #include <Variable/VariableCacheStrategyFactory.h> | |
5 | #include <Variable/VariableController.h> |
|
5 | #include <Variable/VariableController.h> | |
6 | #include <Variable/VariableModel.h> |
|
6 | #include <Variable/VariableModel.h> | |
7 | #include <Variable/VariableSynchronizationGroup.h> |
|
7 | #include <Variable/VariableSynchronizationGroup.h> | |
8 |
|
8 | |||
9 | #include <Data/DataProviderParameters.h> |
|
9 | #include <Data/DataProviderParameters.h> | |
10 | #include <Data/IDataProvider.h> |
|
10 | #include <Data/IDataProvider.h> | |
11 | #include <Data/IDataSeries.h> |
|
11 | #include <Data/IDataSeries.h> | |
12 | #include <Data/VariableRequest.h> |
|
12 | #include <Data/VariableRequest.h> | |
13 | #include <Time/TimeController.h> |
|
13 | #include <Time/TimeController.h> | |
14 |
|
14 | |||
15 | #include <QDataStream> |
|
15 | #include <QDataStream> | |
16 | #include <QMutex> |
|
16 | #include <QMutex> | |
17 | #include <QThread> |
|
17 | #include <QThread> | |
18 | #include <QUuid> |
|
18 | #include <QUuid> | |
19 | #include <QtCore/QItemSelectionModel> |
|
19 | #include <QtCore/QItemSelectionModel> | |
20 |
|
20 | |||
21 | #include <deque> |
|
21 | #include <deque> | |
22 | #include <set> |
|
22 | #include <set> | |
23 | #include <unordered_map> |
|
23 | #include <unordered_map> | |
24 |
|
24 | |||
25 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
25 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
26 |
|
26 | |||
27 | namespace { |
|
27 | namespace { | |
28 |
|
28 | |||
29 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, |
|
29 | SqpRange computeSynchroRangeRequested(const SqpRange &varRange, const SqpRange &graphRange, | |
30 | const SqpRange &oldGraphRange) |
|
30 | const SqpRange &oldGraphRange) | |
31 | { |
|
31 | { | |
32 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); |
|
32 | auto zoomType = VariableController::getZoomType(graphRange, oldGraphRange); | |
33 |
|
33 | |||
34 | auto varRangeRequested = varRange; |
|
34 | auto varRangeRequested = varRange; | |
35 | switch (zoomType) { |
|
35 | switch (zoomType) { | |
36 | case AcquisitionZoomType::ZoomIn: { |
|
36 | case AcquisitionZoomType::ZoomIn: { | |
37 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
37 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
38 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
38 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
39 | varRangeRequested.m_TStart += deltaLeft; |
|
39 | varRangeRequested.m_TStart += deltaLeft; | |
40 | varRangeRequested.m_TEnd -= deltaRight; |
|
40 | varRangeRequested.m_TEnd -= deltaRight; | |
41 | break; |
|
41 | break; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | case AcquisitionZoomType::ZoomOut: { |
|
44 | case AcquisitionZoomType::ZoomOut: { | |
45 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
45 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
46 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
46 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
47 | varRangeRequested.m_TStart -= deltaLeft; |
|
47 | varRangeRequested.m_TStart -= deltaLeft; | |
48 | varRangeRequested.m_TEnd += deltaRight; |
|
48 | varRangeRequested.m_TEnd += deltaRight; | |
49 | break; |
|
49 | break; | |
50 | } |
|
50 | } | |
51 | case AcquisitionZoomType::PanRight: { |
|
51 | case AcquisitionZoomType::PanRight: { | |
52 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; |
|
52 | auto deltaLeft = graphRange.m_TStart - oldGraphRange.m_TStart; | |
53 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; |
|
53 | auto deltaRight = graphRange.m_TEnd - oldGraphRange.m_TEnd; | |
54 | varRangeRequested.m_TStart += deltaLeft; |
|
54 | varRangeRequested.m_TStart += deltaLeft; | |
55 | varRangeRequested.m_TEnd += deltaRight; |
|
55 | varRangeRequested.m_TEnd += deltaRight; | |
56 | break; |
|
56 | break; | |
57 | } |
|
57 | } | |
58 | case AcquisitionZoomType::PanLeft: { |
|
58 | case AcquisitionZoomType::PanLeft: { | |
59 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; |
|
59 | auto deltaLeft = oldGraphRange.m_TStart - graphRange.m_TStart; | |
60 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; |
|
60 | auto deltaRight = oldGraphRange.m_TEnd - graphRange.m_TEnd; | |
61 | varRangeRequested.m_TStart -= deltaLeft; |
|
61 | varRangeRequested.m_TStart -= deltaLeft; | |
62 | varRangeRequested.m_TEnd -= deltaRight; |
|
62 | varRangeRequested.m_TEnd -= deltaRight; | |
63 | break; |
|
63 | break; | |
64 | } |
|
64 | } | |
65 | case AcquisitionZoomType::Unknown: { |
|
65 | case AcquisitionZoomType::Unknown: { | |
66 | qCCritical(LOG_VariableController()) |
|
66 | qCCritical(LOG_VariableController()) | |
67 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); |
|
67 | << VariableController::tr("Impossible to synchronize: zoom type unknown"); | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 | default: |
|
70 | default: | |
71 | qCCritical(LOG_VariableController()) << VariableController::tr( |
|
71 | qCCritical(LOG_VariableController()) << VariableController::tr( | |
72 | "Impossible to synchronize: zoom type not take into account"); |
|
72 | "Impossible to synchronize: zoom type not take into account"); | |
73 | // No action |
|
73 | // No action | |
74 | break; |
|
74 | break; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | return varRangeRequested; |
|
77 | return varRangeRequested; | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | enum class VariableRequestHandlerState { OFF, RUNNING, PENDING }; |
|
81 | enum class VariableRequestHandlerState { OFF, RUNNING, PENDING }; | |
82 |
|
82 | |||
83 | struct VariableRequestHandler { |
|
83 | struct VariableRequestHandler { | |
84 |
|
84 | |||
85 | VariableRequestHandler() |
|
85 | VariableRequestHandler() | |
86 | { |
|
86 | { | |
87 | m_CanUpdate = false; |
|
87 | m_CanUpdate = false; | |
88 | m_State = VariableRequestHandlerState::OFF; |
|
88 | m_State = VariableRequestHandlerState::OFF; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | QUuid m_VarId; |
|
91 | QUuid m_VarId; | |
92 | VariableRequest m_RunningVarRequest; |
|
92 | VariableRequest m_RunningVarRequest; | |
93 | VariableRequest m_PendingVarRequest; |
|
93 | VariableRequest m_PendingVarRequest; | |
94 | VariableRequestHandlerState m_State; |
|
94 | VariableRequestHandlerState m_State; | |
95 | bool m_CanUpdate; |
|
95 | bool m_CanUpdate; | |
96 | }; |
|
96 | }; | |
97 |
|
97 | |||
98 | struct VariableController::VariableControllerPrivate { |
|
98 | struct VariableController::VariableControllerPrivate { | |
99 | explicit VariableControllerPrivate(VariableController *parent) |
|
99 | explicit VariableControllerPrivate(VariableController *parent) | |
100 | : m_WorkingMutex{}, |
|
100 | : m_WorkingMutex{}, | |
101 | m_VariableModel{new VariableModel{parent}}, |
|
101 | m_VariableModel{new VariableModel{parent}}, | |
102 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
102 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
103 | // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, |
|
103 | // m_VariableCacheStrategy{std::make_unique<VariableCacheStrategy>()}, | |
104 | m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy( |
|
104 | m_VariableCacheStrategy{VariableCacheStrategyFactory::createCacheStrategy( | |
105 | CacheStrategy::SingleThreshold)}, |
|
105 | CacheStrategy::SingleThreshold)}, | |
106 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, |
|
106 | m_VariableAcquisitionWorker{std::make_unique<VariableAcquisitionWorker>()}, | |
107 | q{parent} |
|
107 | q{parent} | |
108 | { |
|
108 | { | |
109 |
|
109 | |||
110 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); |
|
110 | m_VariableAcquisitionWorker->moveToThread(&m_VariableAcquisitionWorkerThread); | |
111 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); |
|
111 | m_VariableAcquisitionWorkerThread.setObjectName("VariableAcquisitionWorkerThread"); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 |
|
114 | |||
115 | virtual ~VariableControllerPrivate() |
|
115 | virtual ~VariableControllerPrivate() | |
116 | { |
|
116 | { | |
117 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); |
|
117 | qCDebug(LOG_VariableController()) << tr("VariableControllerPrivate destruction"); | |
118 | m_VariableAcquisitionWorkerThread.quit(); |
|
118 | m_VariableAcquisitionWorkerThread.quit(); | |
119 | m_VariableAcquisitionWorkerThread.wait(); |
|
119 | m_VariableAcquisitionWorkerThread.wait(); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested, |
|
123 | void processRequest(std::shared_ptr<Variable> var, const SqpRange &rangeRequested, | |
124 | QUuid varRequestId); |
|
124 | QUuid varRequestId); | |
125 |
|
125 | |||
126 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); |
|
126 | std::shared_ptr<Variable> findVariable(QUuid vIdentifier); | |
127 | std::shared_ptr<IDataSeries> |
|
127 | std::shared_ptr<IDataSeries> | |
128 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); |
|
128 | retrieveDataSeries(const QVector<AcquisitionDataPacket> acqDataPacketVector); | |
129 |
|
129 | |||
130 | void registerProvider(std::shared_ptr<IDataProvider> provider); |
|
130 | void registerProvider(std::shared_ptr<IDataProvider> provider); | |
131 |
|
131 | |||
132 | void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); |
|
132 | void storeVariableRequest(QUuid varId, QUuid varRequestId, const VariableRequest &varRequest); | |
133 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries); |
|
133 | QUuid acceptVariableRequest(QUuid varId, std::shared_ptr<IDataSeries> dataSeries); | |
134 | void updateVariables(QUuid varRequestId); |
|
134 | void updateVariables(QUuid varRequestId); | |
135 | void updateVariableRequest(QUuid varRequestId); |
|
135 | void updateVariableRequest(QUuid varRequestId); | |
136 | void cancelVariableRequest(QUuid varRequestId); |
|
136 | void cancelVariableRequest(QUuid varRequestId); | |
137 | void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest); |
|
137 | void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest); | |
138 |
|
138 | bool hasPendingDownloads(); | ||
139 | template <typename VariableIterator> |
|
139 | template <typename VariableIterator> | |
140 | void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId); |
|
140 | void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId); | |
141 |
|
141 | |||
142 | QMutex m_WorkingMutex; |
|
142 | QMutex m_WorkingMutex; | |
143 | /// Variable model. The VariableController has the ownership |
|
143 | /// Variable model. The VariableController has the ownership | |
144 | VariableModel *m_VariableModel; |
|
144 | VariableModel *m_VariableModel; | |
145 | QItemSelectionModel *m_VariableSelectionModel; |
|
145 | QItemSelectionModel *m_VariableSelectionModel; | |
146 |
|
146 | |||
147 |
|
147 | |||
148 | TimeController *m_TimeController{nullptr}; |
|
148 | TimeController *m_TimeController{nullptr}; | |
149 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; |
|
149 | std::unique_ptr<VariableCacheStrategy> m_VariableCacheStrategy; | |
150 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; |
|
150 | std::unique_ptr<VariableAcquisitionWorker> m_VariableAcquisitionWorker; | |
151 | QThread m_VariableAcquisitionWorkerThread; |
|
151 | QThread m_VariableAcquisitionWorkerThread; | |
152 |
|
152 | |||
153 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
153 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
154 | m_VariableToProviderMap; |
|
154 | m_VariableToProviderMap; | |
155 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; |
|
155 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap; | |
156 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > |
|
156 | std::map<QUuid, std::shared_ptr<VariableSynchronizationGroup> > | |
157 | m_GroupIdToVariableSynchronizationGroupMap; |
|
157 | m_GroupIdToVariableSynchronizationGroupMap; | |
158 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; |
|
158 | std::map<QUuid, QUuid> m_VariableIdGroupIdMap; | |
159 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; |
|
159 | std::set<std::shared_ptr<IDataProvider> > m_ProviderSet; | |
160 |
|
160 | |||
161 | std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds; |
|
161 | std::map<QUuid, std::list<QUuid> > m_VarGroupIdToVarIds; | |
162 | std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler; |
|
162 | std::map<QUuid, std::unique_ptr<VariableRequestHandler> > m_VarIdToVarRequestHandler; | |
163 |
|
163 | |||
164 | VariableController *q; |
|
164 | VariableController *q; | |
165 | }; |
|
165 | }; | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | VariableController::VariableController(QObject *parent) |
|
168 | VariableController::VariableController(QObject *parent) | |
169 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
169 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
170 | { |
|
170 | { | |
171 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
171 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
172 | << QThread::currentThread(); |
|
172 | << QThread::currentThread(); | |
173 |
|
173 | |||
174 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, |
|
174 | connect(impl->m_VariableModel, &VariableModel::abortProgessRequested, this, | |
175 | &VariableController::onAbortProgressRequested); |
|
175 | &VariableController::onAbortProgressRequested); | |
176 |
|
176 | |||
177 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
177 | connect(impl->m_VariableAcquisitionWorker.get(), | |
178 | &VariableAcquisitionWorker::variableCanceledRequested, this, |
|
178 | &VariableAcquisitionWorker::variableCanceledRequested, this, | |
179 | &VariableController::onAbortAcquisitionRequested); |
|
179 | &VariableController::onAbortAcquisitionRequested); | |
180 |
|
180 | |||
181 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, |
|
181 | connect(impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::dataProvided, this, | |
182 | &VariableController::onDataProvided); |
|
182 | &VariableController::onDataProvided); | |
183 | connect(impl->m_VariableAcquisitionWorker.get(), |
|
183 | connect(impl->m_VariableAcquisitionWorker.get(), | |
184 | &VariableAcquisitionWorker::variableRequestInProgress, this, |
|
184 | &VariableAcquisitionWorker::variableRequestInProgress, this, | |
185 | &VariableController::onVariableRetrieveDataInProgress); |
|
185 | &VariableController::onVariableRetrieveDataInProgress); | |
186 |
|
186 | |||
187 |
|
187 | |||
188 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, |
|
188 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::started, | |
189 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); |
|
189 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::initialize); | |
190 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, |
|
190 | connect(&impl->m_VariableAcquisitionWorkerThread, &QThread::finished, | |
191 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); |
|
191 | impl->m_VariableAcquisitionWorker.get(), &VariableAcquisitionWorker::finalize); | |
192 |
|
192 | |||
193 | connect(impl->m_VariableModel, &VariableModel::requestVariableRangeUpdate, this, |
|
193 | connect(impl->m_VariableModel, &VariableModel::requestVariableRangeUpdate, this, | |
194 | &VariableController::onUpdateDateTime); |
|
194 | &VariableController::onUpdateDateTime); | |
195 |
|
195 | |||
196 | impl->m_VariableAcquisitionWorkerThread.start(); |
|
196 | impl->m_VariableAcquisitionWorkerThread.start(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | VariableController::~VariableController() |
|
199 | VariableController::~VariableController() | |
200 | { |
|
200 | { | |
201 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
201 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
202 | << QThread::currentThread(); |
|
202 | << QThread::currentThread(); | |
203 | this->waitForFinish(); |
|
203 | this->waitForFinish(); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | VariableModel *VariableController::variableModel() noexcept |
|
206 | VariableModel *VariableController::variableModel() noexcept | |
207 | { |
|
207 | { | |
208 | return impl->m_VariableModel; |
|
208 | return impl->m_VariableModel; | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
211 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
212 | { |
|
212 | { | |
213 | return impl->m_VariableSelectionModel; |
|
213 | return impl->m_VariableSelectionModel; | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
216 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
217 | { |
|
217 | { | |
218 | impl->m_TimeController = timeController; |
|
218 | impl->m_TimeController = timeController; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | std::shared_ptr<Variable> |
|
221 | std::shared_ptr<Variable> | |
222 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept |
|
222 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept | |
223 | { |
|
223 | { | |
224 | if (impl->m_VariableModel->containsVariable(variable)) { |
|
224 | if (impl->m_VariableModel->containsVariable(variable)) { | |
225 | // Clones variable |
|
225 | // Clones variable | |
226 | auto duplicate = variable->clone(); |
|
226 | auto duplicate = variable->clone(); | |
227 |
|
227 | |||
228 | // Adds clone to model |
|
228 | // Adds clone to model | |
229 | impl->m_VariableModel->addVariable(duplicate); |
|
229 | impl->m_VariableModel->addVariable(duplicate); | |
230 |
|
230 | |||
231 | // Generates clone identifier |
|
231 | // Generates clone identifier | |
232 | impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); |
|
232 | impl->m_VariableToIdentifierMap[duplicate] = QUuid::createUuid(); | |
233 |
|
233 | |||
234 | // Registers provider |
|
234 | // Registers provider | |
235 | auto variableProvider = impl->m_VariableToProviderMap.at(variable); |
|
235 | auto variableProvider = impl->m_VariableToProviderMap.at(variable); | |
236 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; |
|
236 | auto duplicateProvider = variableProvider != nullptr ? variableProvider->clone() : nullptr; | |
237 |
|
237 | |||
238 | impl->m_VariableToProviderMap[duplicate] = duplicateProvider; |
|
238 | impl->m_VariableToProviderMap[duplicate] = duplicateProvider; | |
239 | if (duplicateProvider) { |
|
239 | if (duplicateProvider) { | |
240 | impl->registerProvider(duplicateProvider); |
|
240 | impl->registerProvider(duplicateProvider); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | return duplicate; |
|
243 | return duplicate; | |
244 | } |
|
244 | } | |
245 | else { |
|
245 | else { | |
246 | qCCritical(LOG_VariableController()) |
|
246 | qCCritical(LOG_VariableController()) | |
247 | << tr("Can't create duplicate of variable %1: variable not registered in the model") |
|
247 | << tr("Can't create duplicate of variable %1: variable not registered in the model") | |
248 | .arg(variable->name()); |
|
248 | .arg(variable->name()); | |
249 | return nullptr; |
|
249 | return nullptr; | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
253 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
254 | { |
|
254 | { | |
255 | if (!variable) { |
|
255 | if (!variable) { | |
256 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
256 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
257 | return; |
|
257 | return; | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
260 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
261 | // make some treatments before the deletion |
|
261 | // make some treatments before the deletion | |
262 | emit variableAboutToBeDeleted(variable); |
|
262 | emit variableAboutToBeDeleted(variable); | |
263 |
|
263 | |||
264 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); |
|
264 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); | |
265 | Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend()); |
|
265 | Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend()); | |
266 |
|
266 | |||
267 | auto variableId = variableIt->second; |
|
267 | auto variableId = variableIt->second; | |
268 |
|
268 | |||
269 | // Removes variable's handler |
|
269 | // Removes variable's handler | |
270 | impl->m_VarIdToVarRequestHandler.erase(variableId); |
|
270 | impl->m_VarIdToVarRequestHandler.erase(variableId); | |
271 |
|
271 | |||
272 | // Desynchronizes variable (if the variable is in a sync group) |
|
272 | // Desynchronizes variable (if the variable is in a sync group) | |
273 | auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId); |
|
273 | auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId); | |
274 | if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
274 | if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) { | |
275 | impl->desynchronize(variableIt, syncGroupIt->second); |
|
275 | impl->desynchronize(variableIt, syncGroupIt->second); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | // Deletes identifier |
|
278 | // Deletes identifier | |
279 | impl->m_VariableToIdentifierMap.erase(variableIt); |
|
279 | impl->m_VariableToIdentifierMap.erase(variableIt); | |
280 |
|
280 | |||
281 | // Deletes provider |
|
281 | // Deletes provider | |
282 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
282 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
283 | qCDebug(LOG_VariableController()) |
|
283 | qCDebug(LOG_VariableController()) | |
284 | << tr("Number of providers deleted for variable %1: %2") |
|
284 | << tr("Number of providers deleted for variable %1: %2") | |
285 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
285 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
286 |
|
286 | |||
287 |
|
287 | |||
288 | // Deletes from model |
|
288 | // Deletes from model | |
289 | impl->m_VariableModel->deleteVariable(variable); |
|
289 | impl->m_VariableModel->deleteVariable(variable); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void VariableController::deleteVariables( |
|
292 | void VariableController::deleteVariables( | |
293 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
293 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
294 | { |
|
294 | { | |
295 | for (auto variable : qAsConst(variables)) { |
|
295 | for (auto variable : qAsConst(variables)) { | |
296 | deleteVariable(variable); |
|
296 | deleteVariable(variable); | |
297 | } |
|
297 | } | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | QByteArray |
|
300 | QByteArray | |
301 | VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const |
|
301 | VariableController::mimeDataForVariables(const QList<std::shared_ptr<Variable> > &variables) const | |
302 | { |
|
302 | { | |
303 | auto encodedData = QByteArray{}; |
|
303 | auto encodedData = QByteArray{}; | |
304 |
|
304 | |||
305 | QVariantList ids; |
|
305 | QVariantList ids; | |
306 | for (auto &var : variables) { |
|
306 | for (auto &var : variables) { | |
307 | auto itVar = impl->m_VariableToIdentifierMap.find(var); |
|
307 | auto itVar = impl->m_VariableToIdentifierMap.find(var); | |
308 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { |
|
308 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { | |
309 | qCCritical(LOG_VariableController()) |
|
309 | qCCritical(LOG_VariableController()) | |
310 | << tr("Impossible to find the data for an unknown variable."); |
|
310 | << tr("Impossible to find the data for an unknown variable."); | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | ids << itVar->second.toByteArray(); |
|
313 | ids << itVar->second.toByteArray(); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; |
|
316 | QDataStream stream{&encodedData, QIODevice::WriteOnly}; | |
317 | stream << ids; |
|
317 | stream << ids; | |
318 |
|
318 | |||
319 | return encodedData; |
|
319 | return encodedData; | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | QList<std::shared_ptr<Variable> > |
|
322 | QList<std::shared_ptr<Variable> > | |
323 | VariableController::variablesForMimeData(const QByteArray &mimeData) const |
|
323 | VariableController::variablesForMimeData(const QByteArray &mimeData) const | |
324 | { |
|
324 | { | |
325 | auto variables = QList<std::shared_ptr<Variable> >{}; |
|
325 | auto variables = QList<std::shared_ptr<Variable> >{}; | |
326 | QDataStream stream{mimeData}; |
|
326 | QDataStream stream{mimeData}; | |
327 |
|
327 | |||
328 | QVariantList ids; |
|
328 | QVariantList ids; | |
329 | stream >> ids; |
|
329 | stream >> ids; | |
330 |
|
330 | |||
331 | for (auto id : ids) { |
|
331 | for (auto id : ids) { | |
332 | auto uuid = QUuid{id.toByteArray()}; |
|
332 | auto uuid = QUuid{id.toByteArray()}; | |
333 | auto var = impl->findVariable(uuid); |
|
333 | auto var = impl->findVariable(uuid); | |
334 | variables << var; |
|
334 | variables << var; | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | return variables; |
|
337 | return variables; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | std::shared_ptr<Variable> |
|
340 | std::shared_ptr<Variable> | |
341 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, |
|
341 | VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
342 | std::shared_ptr<IDataProvider> provider) noexcept |
|
342 | std::shared_ptr<IDataProvider> provider) noexcept | |
343 | { |
|
343 | { | |
344 | if (!impl->m_TimeController) { |
|
344 | if (!impl->m_TimeController) { | |
345 | qCCritical(LOG_VariableController()) |
|
345 | qCCritical(LOG_VariableController()) | |
346 | << tr("Impossible to create variable: The time controller is null"); |
|
346 | << tr("Impossible to create variable: The time controller is null"); | |
347 | return nullptr; |
|
347 | return nullptr; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | auto range = impl->m_TimeController->dateTime(); |
|
350 | auto range = impl->m_TimeController->dateTime(); | |
351 |
|
351 | |||
352 | if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) { |
|
352 | if (auto newVariable = impl->m_VariableModel->createVariable(name, metadata)) { | |
353 | auto varId = QUuid::createUuid(); |
|
353 | auto varId = QUuid::createUuid(); | |
354 |
|
354 | |||
355 | // Create the handler |
|
355 | // Create the handler | |
356 | auto varRequestHandler = std::make_unique<VariableRequestHandler>(); |
|
356 | auto varRequestHandler = std::make_unique<VariableRequestHandler>(); | |
357 | varRequestHandler->m_VarId = varId; |
|
357 | varRequestHandler->m_VarId = varId; | |
358 |
|
358 | |||
359 | impl->m_VarIdToVarRequestHandler.insert( |
|
359 | impl->m_VarIdToVarRequestHandler.insert( | |
360 | std::make_pair(varId, std::move(varRequestHandler))); |
|
360 | std::make_pair(varId, std::move(varRequestHandler))); | |
361 |
|
361 | |||
362 | // store the provider |
|
362 | // store the provider | |
363 | impl->registerProvider(provider); |
|
363 | impl->registerProvider(provider); | |
364 |
|
364 | |||
365 | // Associate the provider |
|
365 | // Associate the provider | |
366 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
366 | impl->m_VariableToProviderMap[newVariable] = provider; | |
367 | impl->m_VariableToIdentifierMap[newVariable] = varId; |
|
367 | impl->m_VariableToIdentifierMap[newVariable] = varId; | |
368 |
|
368 | |||
369 | this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false); |
|
369 | this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{newVariable}, range, false); | |
370 |
|
370 | |||
371 | // auto varRequestId = QUuid::createUuid(); |
|
371 | // auto varRequestId = QUuid::createUuid(); | |
372 | // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId; |
|
372 | // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId; | |
373 | // impl->processRequest(newVariable, range, varRequestId); |
|
373 | // impl->processRequest(newVariable, range, varRequestId); | |
374 | // impl->updateVariableRequest(varRequestId); |
|
374 | // impl->updateVariableRequest(varRequestId); | |
375 |
|
375 | |||
376 | emit variableAdded(newVariable); |
|
376 | emit variableAdded(newVariable); | |
377 |
|
377 | |||
378 | return newVariable; |
|
378 | return newVariable; | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | qCCritical(LOG_VariableController()) << tr("Impossible to create variable"); |
|
381 | qCCritical(LOG_VariableController()) << tr("Impossible to create variable"); | |
382 | return nullptr; |
|
382 | return nullptr; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) |
|
385 | void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) | |
386 | { |
|
386 | { | |
387 | // NOTE: Even if acquisition request is aborting, the graphe range will be changed |
|
387 | // NOTE: Even if acquisition request is aborting, the graphe range will be changed | |
388 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
388 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
389 | << QThread::currentThread()->objectName(); |
|
389 | << QThread::currentThread()->objectName(); | |
390 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
390 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
391 |
|
391 | |||
392 | // NOTE we only permit the time modification for one variable |
|
392 | // NOTE we only permit the time modification for one variable | |
393 | // DEPRECATED |
|
393 | // DEPRECATED | |
394 | // auto variables = QVector<std::shared_ptr<Variable> >{}; |
|
394 | // auto variables = QVector<std::shared_ptr<Variable> >{}; | |
395 | // for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
395 | // for (const auto &selectedRow : qAsConst(selectedRows)) { | |
396 | // if (auto selectedVariable = |
|
396 | // if (auto selectedVariable = | |
397 | // impl->m_VariableModel->variable(selectedRow.row())) { |
|
397 | // impl->m_VariableModel->variable(selectedRow.row())) { | |
398 | // variables << selectedVariable; |
|
398 | // variables << selectedVariable; | |
399 |
|
399 | |||
400 | // // notify that rescale operation has to be done |
|
400 | // // notify that rescale operation has to be done | |
401 | // emit rangeChanged(selectedVariable, dateTime); |
|
401 | // emit rangeChanged(selectedVariable, dateTime); | |
402 | // } |
|
402 | // } | |
403 | // } |
|
403 | // } | |
404 | // if (!variables.isEmpty()) { |
|
404 | // if (!variables.isEmpty()) { | |
405 | // this->onRequestDataLoading(variables, dateTime, synchro); |
|
405 | // this->onRequestDataLoading(variables, dateTime, synchro); | |
406 | // } |
|
406 | // } | |
407 | if (selectedRows.size() == 1) { |
|
407 | if (selectedRows.size() == 1) { | |
408 |
|
408 | |||
409 | if (auto selectedVariable |
|
409 | if (auto selectedVariable | |
410 | = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) { |
|
410 | = impl->m_VariableModel->variable(qAsConst(selectedRows).first().row())) { | |
411 |
|
411 | |||
412 | onUpdateDateTime(selectedVariable, dateTime); |
|
412 | onUpdateDateTime(selectedVariable, dateTime); | |
413 | } |
|
413 | } | |
414 | } |
|
414 | } | |
415 | else if (selectedRows.size() > 1) { |
|
415 | else if (selectedRows.size() > 1) { | |
416 | qCCritical(LOG_VariableController()) |
|
416 | qCCritical(LOG_VariableController()) | |
417 | << tr("Impossible to set time for more than 1 variable in the same time"); |
|
417 | << tr("Impossible to set time for more than 1 variable in the same time"); | |
418 | } |
|
418 | } | |
419 | else { |
|
419 | else { | |
420 | qCWarning(LOG_VariableController()) |
|
420 | qCWarning(LOG_VariableController()) | |
421 | << tr("There is no variable selected to set the time one"); |
|
421 | << tr("There is no variable selected to set the time one"); | |
422 | } |
|
422 | } | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void VariableController::onUpdateDateTime(std::shared_ptr<Variable> variable, |
|
425 | void VariableController::onUpdateDateTime(std::shared_ptr<Variable> variable, | |
426 | const SqpRange &dateTime) |
|
426 | const SqpRange &dateTime) | |
427 | { |
|
427 | { | |
428 | auto itVar = impl->m_VariableToIdentifierMap.find(variable); |
|
428 | auto itVar = impl->m_VariableToIdentifierMap.find(variable); | |
429 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { |
|
429 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { | |
430 | qCCritical(LOG_VariableController()) |
|
430 | qCCritical(LOG_VariableController()) | |
431 | << tr("Impossible to onDateTimeOnSelection request for unknown variable"); |
|
431 | << tr("Impossible to onDateTimeOnSelection request for unknown variable"); | |
432 | return; |
|
432 | return; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | // notify that rescale operation has to be done |
|
435 | // notify that rescale operation has to be done | |
436 | emit rangeChanged(variable, dateTime); |
|
436 | emit rangeChanged(variable, dateTime); | |
437 |
|
437 | |||
438 | auto synchro |
|
438 | auto synchro | |
439 | = impl->m_VariableIdGroupIdMap.find(itVar->second) != impl->m_VariableIdGroupIdMap.cend(); |
|
439 | = impl->m_VariableIdGroupIdMap.find(itVar->second) != impl->m_VariableIdGroupIdMap.cend(); | |
440 |
|
440 | |||
441 | this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{variable}, dateTime, synchro); |
|
441 | this->onRequestDataLoading(QVector<std::shared_ptr<Variable> >{variable}, dateTime, synchro); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, |
|
444 | void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, | |
445 | const SqpRange &cacheRangeRequested, |
|
445 | const SqpRange &cacheRangeRequested, | |
446 | QVector<AcquisitionDataPacket> dataAcquired) |
|
446 | QVector<AcquisitionDataPacket> dataAcquired) | |
447 | { |
|
447 | { | |
448 | qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread(); |
|
448 | qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread(); | |
449 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); |
|
449 | auto retrievedDataSeries = impl->retrieveDataSeries(dataAcquired); | |
450 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); |
|
450 | auto varRequestId = impl->acceptVariableRequest(vIdentifier, retrievedDataSeries); | |
451 | if (!varRequestId.isNull()) { |
|
451 | if (!varRequestId.isNull()) { | |
452 | impl->updateVariables(varRequestId); |
|
452 | impl->updateVariables(varRequestId); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
456 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
457 | { |
|
457 | { | |
458 | qCDebug(LOG_VariableController()) |
|
458 | qCDebug(LOG_VariableController()) | |
459 | << "TORM: variableController::onVariableRetrieveDataInProgress" |
|
459 | << "TORM: variableController::onVariableRetrieveDataInProgress" | |
460 | << QThread::currentThread()->objectName() << progress; |
|
460 | << QThread::currentThread()->objectName() << progress; | |
461 | if (auto var = impl->findVariable(identifier)) { |
|
461 | if (auto var = impl->findVariable(identifier)) { | |
462 | impl->m_VariableModel->setDataProgress(var, progress); |
|
462 | impl->m_VariableModel->setDataProgress(var, progress); | |
463 | } |
|
463 | } | |
464 | else { |
|
464 | else { | |
465 | qCCritical(LOG_VariableController()) |
|
465 | qCCritical(LOG_VariableController()) | |
466 | << tr("Impossible to notify progression of a null variable"); |
|
466 | << tr("Impossible to notify progression of a null variable"); | |
467 | } |
|
467 | } | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) |
|
470 | void VariableController::onAbortProgressRequested(std::shared_ptr<Variable> variable) | |
471 | { |
|
471 | { | |
472 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested" |
|
472 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortProgressRequested" | |
473 | << QThread::currentThread()->objectName() << variable->name(); |
|
473 | << QThread::currentThread()->objectName() << variable->name(); | |
474 |
|
474 | |||
475 | auto itVar = impl->m_VariableToIdentifierMap.find(variable); |
|
475 | auto itVar = impl->m_VariableToIdentifierMap.find(variable); | |
476 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { |
|
476 | if (itVar == impl->m_VariableToIdentifierMap.cend()) { | |
477 | qCCritical(LOG_VariableController()) |
|
477 | qCCritical(LOG_VariableController()) | |
478 | << tr("Impossible to onAbortProgressRequested request for unknown variable"); |
|
478 | << tr("Impossible to onAbortProgressRequested request for unknown variable"); | |
479 | return; |
|
479 | return; | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | auto varId = itVar->second; |
|
482 | auto varId = itVar->second; | |
483 |
|
483 | |||
484 | auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId); |
|
484 | auto itVarHandler = impl->m_VarIdToVarRequestHandler.find(varId); | |
485 | if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) { |
|
485 | if (itVarHandler == impl->m_VarIdToVarRequestHandler.cend()) { | |
486 | qCCritical(LOG_VariableController()) |
|
486 | qCCritical(LOG_VariableController()) | |
487 | << tr("Impossible to onAbortProgressRequested for variable with unknown handler"); |
|
487 | << tr("Impossible to onAbortProgressRequested for variable with unknown handler"); | |
488 | return; |
|
488 | return; | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | auto varHandler = itVarHandler->second.get(); |
|
491 | auto varHandler = itVarHandler->second.get(); | |
492 |
|
492 | |||
493 | // case where a variable has a running request |
|
493 | // case where a variable has a running request | |
494 | if (varHandler->m_State != VariableRequestHandlerState::OFF) { |
|
494 | if (varHandler->m_State != VariableRequestHandlerState::OFF) { | |
495 | impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId); |
|
495 | impl->cancelVariableRequest(varHandler->m_RunningVarRequest.m_VariableGroupId); | |
496 | } |
|
496 | } | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) |
|
499 | void VariableController::onAbortAcquisitionRequested(QUuid vIdentifier) | |
500 | { |
|
500 | { | |
501 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested" |
|
501 | qCDebug(LOG_VariableController()) << "TORM: variableController::onAbortAcquisitionRequested" | |
502 | << QThread::currentThread()->objectName() << vIdentifier; |
|
502 | << QThread::currentThread()->objectName() << vIdentifier; | |
503 |
|
503 | |||
504 | if (auto var = impl->findVariable(vIdentifier)) { |
|
504 | if (auto var = impl->findVariable(vIdentifier)) { | |
505 | this->onAbortProgressRequested(var); |
|
505 | this->onAbortProgressRequested(var); | |
506 | } |
|
506 | } | |
507 | else { |
|
507 | else { | |
508 | qCCritical(LOG_VariableController()) |
|
508 | qCCritical(LOG_VariableController()) | |
509 | << tr("Impossible to abort Acquisition Requestof a null variable"); |
|
509 | << tr("Impossible to abort Acquisition Requestof a null variable"); | |
510 | } |
|
510 | } | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) |
|
513 | void VariableController::onAddSynchronizationGroupId(QUuid synchronizationGroupId) | |
514 | { |
|
514 | { | |
515 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" |
|
515 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronizationGroupId" | |
516 | << QThread::currentThread()->objectName() |
|
516 | << QThread::currentThread()->objectName() | |
517 | << synchronizationGroupId; |
|
517 | << synchronizationGroupId; | |
518 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); |
|
518 | auto vSynchroGroup = std::make_shared<VariableSynchronizationGroup>(); | |
519 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( |
|
519 | impl->m_GroupIdToVariableSynchronizationGroupMap.insert( | |
520 | std::make_pair(synchronizationGroupId, vSynchroGroup)); |
|
520 | std::make_pair(synchronizationGroupId, vSynchroGroup)); | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) |
|
523 | void VariableController::onRemoveSynchronizationGroupId(QUuid synchronizationGroupId) | |
524 | { |
|
524 | { | |
525 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); |
|
525 | impl->m_GroupIdToVariableSynchronizationGroupMap.erase(synchronizationGroupId); | |
526 | } |
|
526 | } | |
527 |
|
527 | |||
528 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, |
|
528 | void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable, | |
529 | QUuid synchronizationGroupId) |
|
529 | QUuid synchronizationGroupId) | |
530 |
|
530 | |||
531 | { |
|
531 | { | |
532 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" |
|
532 | qCDebug(LOG_VariableController()) << "TORM: VariableController::onAddSynchronized" | |
533 | << synchronizationGroupId; |
|
533 | << synchronizationGroupId; | |
534 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); |
|
534 | auto varToVarIdIt = impl->m_VariableToIdentifierMap.find(variable); | |
535 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { |
|
535 | if (varToVarIdIt != impl->m_VariableToIdentifierMap.cend()) { | |
536 | auto groupIdToVSGIt |
|
536 | auto groupIdToVSGIt | |
537 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); |
|
537 | = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId); | |
538 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
538 | if (groupIdToVSGIt != impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) { | |
539 | impl->m_VariableIdGroupIdMap.insert( |
|
539 | impl->m_VariableIdGroupIdMap.insert( | |
540 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); |
|
540 | std::make_pair(varToVarIdIt->second, synchronizationGroupId)); | |
541 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); |
|
541 | groupIdToVSGIt->second->addVariableId(varToVarIdIt->second); | |
542 | } |
|
542 | } | |
543 | else { |
|
543 | else { | |
544 | qCCritical(LOG_VariableController()) |
|
544 | qCCritical(LOG_VariableController()) | |
545 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") |
|
545 | << tr("Impossible to synchronize a variable with an unknown sycnhronization group") | |
546 | << variable->name(); |
|
546 | << variable->name(); | |
547 | } |
|
547 | } | |
548 | } |
|
548 | } | |
549 | else { |
|
549 | else { | |
550 | qCCritical(LOG_VariableController()) |
|
550 | qCCritical(LOG_VariableController()) | |
551 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); |
|
551 | << tr("Impossible to synchronize a variable with no identifier") << variable->name(); | |
552 | } |
|
552 | } | |
553 | } |
|
553 | } | |
554 |
|
554 | |||
555 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, |
|
555 | void VariableController::desynchronize(std::shared_ptr<Variable> variable, | |
556 | QUuid synchronizationGroupId) |
|
556 | QUuid synchronizationGroupId) | |
557 | { |
|
557 | { | |
558 | // Gets variable id |
|
558 | // Gets variable id | |
559 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); |
|
559 | auto variableIt = impl->m_VariableToIdentifierMap.find(variable); | |
560 | if (variableIt == impl->m_VariableToIdentifierMap.cend()) { |
|
560 | if (variableIt == impl->m_VariableToIdentifierMap.cend()) { | |
561 | qCCritical(LOG_VariableController()) |
|
561 | qCCritical(LOG_VariableController()) | |
562 | << tr("Can't desynchronize variable %1: variable identifier not found") |
|
562 | << tr("Can't desynchronize variable %1: variable identifier not found") | |
563 | .arg(variable->name()); |
|
563 | .arg(variable->name()); | |
564 | return; |
|
564 | return; | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | impl->desynchronize(variableIt, synchronizationGroupId); |
|
567 | impl->desynchronize(variableIt, synchronizationGroupId); | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, |
|
570 | void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables, | |
571 | const SqpRange &range, bool synchronise) |
|
571 | const SqpRange &range, bool synchronise) | |
572 | { |
|
572 | { | |
573 | // variables is assumed synchronized |
|
573 | // variables is assumed synchronized | |
574 | // TODO: Asser variables synchronization |
|
574 | // TODO: Asser variables synchronization | |
575 | // we want to load data of the variable for the dateTime. |
|
575 | // we want to load data of the variable for the dateTime. | |
576 | if (variables.isEmpty()) { |
|
576 | if (variables.isEmpty()) { | |
577 | return; |
|
577 | return; | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | auto varRequestId = QUuid::createUuid(); |
|
580 | auto varRequestId = QUuid::createUuid(); | |
581 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
581 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
582 | << QThread::currentThread()->objectName() << varRequestId |
|
582 | << QThread::currentThread()->objectName() << varRequestId | |
583 | << range << synchronise; |
|
583 | << range << synchronise; | |
584 |
|
584 | |||
585 | if (!synchronise) { |
|
585 | if (!synchronise) { | |
586 | auto varIds = std::list<QUuid>{}; |
|
586 | auto varIds = std::list<QUuid>{}; | |
587 | for (const auto &var : variables) { |
|
587 | for (const auto &var : variables) { | |
588 | auto vId = impl->m_VariableToIdentifierMap.at(var); |
|
588 | auto vId = impl->m_VariableToIdentifierMap.at(var); | |
589 | varIds.push_back(vId); |
|
589 | varIds.push_back(vId); | |
590 | } |
|
590 | } | |
591 | impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); |
|
591 | impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); | |
592 | for (const auto &var : variables) { |
|
592 | for (const auto &var : variables) { | |
593 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId |
|
593 | qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId | |
594 | << varIds.size(); |
|
594 | << varIds.size(); | |
595 | impl->processRequest(var, range, varRequestId); |
|
595 | impl->processRequest(var, range, varRequestId); | |
596 | } |
|
596 | } | |
597 | } |
|
597 | } | |
598 | else { |
|
598 | else { | |
599 | auto vId = impl->m_VariableToIdentifierMap.at(variables.first()); |
|
599 | auto vId = impl->m_VariableToIdentifierMap.at(variables.first()); | |
600 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); |
|
600 | auto varIdToGroupIdIt = impl->m_VariableIdGroupIdMap.find(vId); | |
601 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { |
|
601 | if (varIdToGroupIdIt != impl->m_VariableIdGroupIdMap.cend()) { | |
602 | auto groupId = varIdToGroupIdIt->second; |
|
602 | auto groupId = varIdToGroupIdIt->second; | |
603 |
|
603 | |||
604 | auto vSynchronizationGroup |
|
604 | auto vSynchronizationGroup | |
605 | = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId); |
|
605 | = impl->m_GroupIdToVariableSynchronizationGroupMap.at(groupId); | |
606 | auto vSyncIds = vSynchronizationGroup->getIds(); |
|
606 | auto vSyncIds = vSynchronizationGroup->getIds(); | |
607 |
|
607 | |||
608 | auto varIds = std::list<QUuid>{}; |
|
608 | auto varIds = std::list<QUuid>{}; | |
609 | for (auto vId : vSyncIds) { |
|
609 | for (auto vId : vSyncIds) { | |
610 | varIds.push_back(vId); |
|
610 | varIds.push_back(vId); | |
611 | } |
|
611 | } | |
612 | impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); |
|
612 | impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); | |
613 |
|
613 | |||
614 | for (auto vId : vSyncIds) { |
|
614 | for (auto vId : vSyncIds) { | |
615 | auto var = impl->findVariable(vId); |
|
615 | auto var = impl->findVariable(vId); | |
616 |
|
616 | |||
617 | // Don't process already processed var |
|
617 | // Don't process already processed var | |
618 | if (var != nullptr) { |
|
618 | if (var != nullptr) { | |
619 | qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name() |
|
619 | qCDebug(LOG_VariableController()) << "processRequest synchro for" << var->name() | |
620 | << varRequestId; |
|
620 | << varRequestId; | |
621 | auto vSyncRangeRequested |
|
621 | auto vSyncRangeRequested | |
622 | = variables.contains(var) |
|
622 | = variables.contains(var) | |
623 | ? range |
|
623 | ? range | |
624 | : computeSynchroRangeRequested(var->range(), range, |
|
624 | : computeSynchroRangeRequested(var->range(), range, | |
625 | variables.first()->range()); |
|
625 | variables.first()->range()); | |
626 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; |
|
626 | qCDebug(LOG_VariableController()) << "synchro RR" << vSyncRangeRequested; | |
627 | impl->processRequest(var, vSyncRangeRequested, varRequestId); |
|
627 | impl->processRequest(var, vSyncRangeRequested, varRequestId); | |
628 | } |
|
628 | } | |
629 | else { |
|
629 | else { | |
630 | qCCritical(LOG_VariableController()) |
|
630 | qCCritical(LOG_VariableController()) | |
631 |
|
631 | |||
632 | << tr("Impossible to synchronize a null variable"); |
|
632 | << tr("Impossible to synchronize a null variable"); | |
633 | } |
|
633 | } | |
634 | } |
|
634 | } | |
635 | } |
|
635 | } | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | impl->updateVariables(varRequestId); |
|
638 | impl->updateVariables(varRequestId); | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 |
|
641 | |||
642 | void VariableController::initialize() |
|
642 | void VariableController::initialize() | |
643 | { |
|
643 | { | |
644 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
644 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
645 | impl->m_WorkingMutex.lock(); |
|
645 | impl->m_WorkingMutex.lock(); | |
646 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
646 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
647 | } |
|
647 | } | |
648 |
|
648 | |||
649 | void VariableController::finalize() |
|
649 | void VariableController::finalize() | |
650 | { |
|
650 | { | |
651 | impl->m_WorkingMutex.unlock(); |
|
651 | impl->m_WorkingMutex.unlock(); | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | void VariableController::waitForFinish() |
|
654 | void VariableController::waitForFinish() | |
655 | { |
|
655 | { | |
656 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
656 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
657 | } |
|
657 | } | |
658 |
|
658 | |||
|
659 | bool VariableController::hasPendingDownloads() | |||
|
660 | { | |||
|
661 | return impl->hasPendingDownloads(); | |||
|
662 | } | |||
|
663 | ||||
659 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) |
|
664 | AcquisitionZoomType VariableController::getZoomType(const SqpRange &range, const SqpRange &oldRange) | |
660 | { |
|
665 | { | |
661 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd |
|
666 | // t1.m_TStart <= t2.m_TStart && t2.m_TEnd <= t1.m_TEnd | |
662 | auto zoomType = AcquisitionZoomType::Unknown; |
|
667 | auto zoomType = AcquisitionZoomType::Unknown; | |
663 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { |
|
668 | if (range.m_TStart <= oldRange.m_TStart && oldRange.m_TEnd <= range.m_TEnd) { | |
664 | qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut"; |
|
669 | qCDebug(LOG_VariableController()) << "zoomtype: ZoomOut"; | |
665 | zoomType = AcquisitionZoomType::ZoomOut; |
|
670 | zoomType = AcquisitionZoomType::ZoomOut; | |
666 | } |
|
671 | } | |
667 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { |
|
672 | else if (range.m_TStart > oldRange.m_TStart && range.m_TEnd > oldRange.m_TEnd) { | |
668 | qCDebug(LOG_VariableController()) << "zoomtype: PanRight"; |
|
673 | qCDebug(LOG_VariableController()) << "zoomtype: PanRight"; | |
669 | zoomType = AcquisitionZoomType::PanRight; |
|
674 | zoomType = AcquisitionZoomType::PanRight; | |
670 | } |
|
675 | } | |
671 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { |
|
676 | else if (range.m_TStart < oldRange.m_TStart && range.m_TEnd < oldRange.m_TEnd) { | |
672 | qCDebug(LOG_VariableController()) << "zoomtype: PanLeft"; |
|
677 | qCDebug(LOG_VariableController()) << "zoomtype: PanLeft"; | |
673 | zoomType = AcquisitionZoomType::PanLeft; |
|
678 | zoomType = AcquisitionZoomType::PanLeft; | |
674 | } |
|
679 | } | |
675 | else if (range.m_TStart >= oldRange.m_TStart && oldRange.m_TEnd >= range.m_TEnd) { |
|
680 | else if (range.m_TStart >= oldRange.m_TStart && oldRange.m_TEnd >= range.m_TEnd) { | |
676 | qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn"; |
|
681 | qCDebug(LOG_VariableController()) << "zoomtype: ZoomIn"; | |
677 | zoomType = AcquisitionZoomType::ZoomIn; |
|
682 | zoomType = AcquisitionZoomType::ZoomIn; | |
678 | } |
|
683 | } | |
679 | else { |
|
684 | else { | |
680 | qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected"; |
|
685 | qCDebug(LOG_VariableController()) << "getZoomType: Unknown type detected"; | |
681 | } |
|
686 | } | |
682 | return zoomType; |
|
687 | return zoomType; | |
683 | } |
|
688 | } | |
684 |
|
689 | |||
685 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, |
|
690 | void VariableController::VariableControllerPrivate::processRequest(std::shared_ptr<Variable> var, | |
686 | const SqpRange &rangeRequested, |
|
691 | const SqpRange &rangeRequested, | |
687 | QUuid varRequestId) |
|
692 | QUuid varRequestId) | |
688 | { |
|
693 | { | |
689 | auto itVar = m_VariableToIdentifierMap.find(var); |
|
694 | auto itVar = m_VariableToIdentifierMap.find(var); | |
690 | if (itVar == m_VariableToIdentifierMap.cend()) { |
|
695 | if (itVar == m_VariableToIdentifierMap.cend()) { | |
691 | qCCritical(LOG_VariableController()) |
|
696 | qCCritical(LOG_VariableController()) | |
692 | << tr("Impossible to process request for unknown variable"); |
|
697 | << tr("Impossible to process request for unknown variable"); | |
693 | return; |
|
698 | return; | |
694 | } |
|
699 | } | |
695 |
|
700 | |||
696 | auto varId = itVar->second; |
|
701 | auto varId = itVar->second; | |
697 |
|
702 | |||
698 | auto itVarHandler = m_VarIdToVarRequestHandler.find(varId); |
|
703 | auto itVarHandler = m_VarIdToVarRequestHandler.find(varId); | |
699 | if (itVarHandler == m_VarIdToVarRequestHandler.cend()) { |
|
704 | if (itVarHandler == m_VarIdToVarRequestHandler.cend()) { | |
700 | qCCritical(LOG_VariableController()) |
|
705 | qCCritical(LOG_VariableController()) | |
701 | << tr("Impossible to process request for variable with unknown handler"); |
|
706 | << tr("Impossible to process request for variable with unknown handler"); | |
702 | return; |
|
707 | return; | |
703 | } |
|
708 | } | |
704 |
|
709 | |||
705 | auto oldRange = var->range(); |
|
710 | auto oldRange = var->range(); | |
706 |
|
711 | |||
707 | auto varHandler = itVarHandler->second.get(); |
|
712 | auto varHandler = itVarHandler->second.get(); | |
708 |
|
713 | |||
709 | if (varHandler->m_State != VariableRequestHandlerState::OFF) { |
|
714 | if (varHandler->m_State != VariableRequestHandlerState::OFF) { | |
710 | oldRange = varHandler->m_RunningVarRequest.m_RangeRequested; |
|
715 | oldRange = varHandler->m_RunningVarRequest.m_RangeRequested; | |
711 | } |
|
716 | } | |
712 |
|
717 | |||
713 | auto varRequest = VariableRequest{}; |
|
718 | auto varRequest = VariableRequest{}; | |
714 | varRequest.m_VariableGroupId = varRequestId; |
|
719 | varRequest.m_VariableGroupId = varRequestId; | |
715 | auto varStrategyRangesRequested |
|
720 | auto varStrategyRangesRequested | |
716 | = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested); |
|
721 | = m_VariableCacheStrategy->computeRange(oldRange, rangeRequested); | |
717 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; |
|
722 | varRequest.m_RangeRequested = varStrategyRangesRequested.first; | |
718 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; |
|
723 | varRequest.m_CacheRangeRequested = varStrategyRangesRequested.second; | |
719 |
|
724 | |||
720 | switch (varHandler->m_State) { |
|
725 | switch (varHandler->m_State) { | |
721 | case VariableRequestHandlerState::OFF: { |
|
726 | case VariableRequestHandlerState::OFF: { | |
722 | qCDebug(LOG_VariableController()) << tr("Process Request OFF") |
|
727 | qCDebug(LOG_VariableController()) << tr("Process Request OFF") | |
723 | << varRequest.m_RangeRequested |
|
728 | << varRequest.m_RangeRequested | |
724 | << varRequest.m_CacheRangeRequested; |
|
729 | << varRequest.m_CacheRangeRequested; | |
725 | varHandler->m_RunningVarRequest = varRequest; |
|
730 | varHandler->m_RunningVarRequest = varRequest; | |
726 | varHandler->m_State = VariableRequestHandlerState::RUNNING; |
|
731 | varHandler->m_State = VariableRequestHandlerState::RUNNING; | |
727 | executeVarRequest(var, varRequest); |
|
732 | executeVarRequest(var, varRequest); | |
728 | break; |
|
733 | break; | |
729 | } |
|
734 | } | |
730 | case VariableRequestHandlerState::RUNNING: { |
|
735 | case VariableRequestHandlerState::RUNNING: { | |
731 | qCDebug(LOG_VariableController()) << tr("Process Request RUNNING") |
|
736 | qCDebug(LOG_VariableController()) << tr("Process Request RUNNING") | |
732 | << varRequest.m_RangeRequested |
|
737 | << varRequest.m_RangeRequested | |
733 | << varRequest.m_CacheRangeRequested; |
|
738 | << varRequest.m_CacheRangeRequested; | |
734 | varHandler->m_State = VariableRequestHandlerState::PENDING; |
|
739 | varHandler->m_State = VariableRequestHandlerState::PENDING; | |
735 | varHandler->m_PendingVarRequest = varRequest; |
|
740 | varHandler->m_PendingVarRequest = varRequest; | |
736 | break; |
|
741 | break; | |
737 | } |
|
742 | } | |
738 | case VariableRequestHandlerState::PENDING: { |
|
743 | case VariableRequestHandlerState::PENDING: { | |
739 | qCDebug(LOG_VariableController()) << tr("Process Request PENDING") |
|
744 | qCDebug(LOG_VariableController()) << tr("Process Request PENDING") | |
740 | << varRequest.m_RangeRequested |
|
745 | << varRequest.m_RangeRequested | |
741 | << varRequest.m_CacheRangeRequested; |
|
746 | << varRequest.m_CacheRangeRequested; | |
742 | auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId; |
|
747 | auto variableGroupIdToCancel = varHandler->m_PendingVarRequest.m_VariableGroupId; | |
743 | cancelVariableRequest(variableGroupIdToCancel); |
|
748 | cancelVariableRequest(variableGroupIdToCancel); | |
744 | // Cancel variable can make state downgrade |
|
749 | // Cancel variable can make state downgrade | |
745 | varHandler->m_State = VariableRequestHandlerState::PENDING; |
|
750 | varHandler->m_State = VariableRequestHandlerState::PENDING; | |
746 | varHandler->m_PendingVarRequest = varRequest; |
|
751 | varHandler->m_PendingVarRequest = varRequest; | |
747 |
|
752 | |||
748 | break; |
|
753 | break; | |
749 | } |
|
754 | } | |
750 | default: |
|
755 | default: | |
751 | qCCritical(LOG_VariableController()) |
|
756 | qCCritical(LOG_VariableController()) | |
752 | << QObject::tr("Unknown VariableRequestHandlerState"); |
|
757 | << QObject::tr("Unknown VariableRequestHandlerState"); | |
753 | } |
|
758 | } | |
754 | } |
|
759 | } | |
755 |
|
760 | |||
756 | std::shared_ptr<Variable> |
|
761 | std::shared_ptr<Variable> | |
757 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) |
|
762 | VariableController::VariableControllerPrivate::findVariable(QUuid vIdentifier) | |
758 | { |
|
763 | { | |
759 | std::shared_ptr<Variable> var; |
|
764 | std::shared_ptr<Variable> var; | |
760 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; |
|
765 | auto findReply = [vIdentifier](const auto &entry) { return vIdentifier == entry.second; }; | |
761 |
|
766 | |||
762 | auto end = m_VariableToIdentifierMap.cend(); |
|
767 | auto end = m_VariableToIdentifierMap.cend(); | |
763 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); |
|
768 | auto it = std::find_if(m_VariableToIdentifierMap.cbegin(), end, findReply); | |
764 | if (it != end) { |
|
769 | if (it != end) { | |
765 | var = it->first; |
|
770 | var = it->first; | |
766 | } |
|
771 | } | |
767 | else { |
|
772 | else { | |
768 | qCCritical(LOG_VariableController()) |
|
773 | qCCritical(LOG_VariableController()) | |
769 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; |
|
774 | << tr("Impossible to find the variable with the identifier: ") << vIdentifier; | |
770 | } |
|
775 | } | |
771 |
|
776 | |||
772 | return var; |
|
777 | return var; | |
773 | } |
|
778 | } | |
774 |
|
779 | |||
775 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( |
|
780 | std::shared_ptr<IDataSeries> VariableController::VariableControllerPrivate::retrieveDataSeries( | |
776 | const QVector<AcquisitionDataPacket> acqDataPacketVector) |
|
781 | const QVector<AcquisitionDataPacket> acqDataPacketVector) | |
777 | { |
|
782 | { | |
778 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") |
|
783 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size") | |
779 | << acqDataPacketVector.size(); |
|
784 | << acqDataPacketVector.size(); | |
780 | std::shared_ptr<IDataSeries> dataSeries; |
|
785 | std::shared_ptr<IDataSeries> dataSeries; | |
781 | if (!acqDataPacketVector.isEmpty()) { |
|
786 | if (!acqDataPacketVector.isEmpty()) { | |
782 | dataSeries = acqDataPacketVector[0].m_DateSeries; |
|
787 | dataSeries = acqDataPacketVector[0].m_DateSeries; | |
783 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { |
|
788 | for (int i = 1; i < acqDataPacketVector.size(); ++i) { | |
784 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); |
|
789 | dataSeries->merge(acqDataPacketVector[i].m_DateSeries.get()); | |
785 | } |
|
790 | } | |
786 | } |
|
791 | } | |
787 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") |
|
792 | qCDebug(LOG_VariableController()) << tr("TORM: retrieveDataSeries acqDataPacketVector size END") | |
788 | << acqDataPacketVector.size(); |
|
793 | << acqDataPacketVector.size(); | |
789 | return dataSeries; |
|
794 | return dataSeries; | |
790 | } |
|
795 | } | |
791 |
|
796 | |||
792 | void VariableController::VariableControllerPrivate::registerProvider( |
|
797 | void VariableController::VariableControllerPrivate::registerProvider( | |
793 | std::shared_ptr<IDataProvider> provider) |
|
798 | std::shared_ptr<IDataProvider> provider) | |
794 | { |
|
799 | { | |
795 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { |
|
800 | if (m_ProviderSet.find(provider) == m_ProviderSet.end()) { | |
796 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") |
|
801 | qCDebug(LOG_VariableController()) << tr("Registering of a new provider") | |
797 | << provider->objectName(); |
|
802 | << provider->objectName(); | |
798 | m_ProviderSet.insert(provider); |
|
803 | m_ProviderSet.insert(provider); | |
799 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), |
|
804 | connect(provider.get(), &IDataProvider::dataProvided, m_VariableAcquisitionWorker.get(), | |
800 | &VariableAcquisitionWorker::onVariableDataAcquired); |
|
805 | &VariableAcquisitionWorker::onVariableDataAcquired); | |
801 | connect(provider.get(), &IDataProvider::dataProvidedProgress, |
|
806 | connect(provider.get(), &IDataProvider::dataProvidedProgress, | |
802 | m_VariableAcquisitionWorker.get(), |
|
807 | m_VariableAcquisitionWorker.get(), | |
803 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); |
|
808 | &VariableAcquisitionWorker::onVariableRetrieveDataInProgress); | |
804 | connect(provider.get(), &IDataProvider::dataProvidedFailed, |
|
809 | connect(provider.get(), &IDataProvider::dataProvidedFailed, | |
805 | m_VariableAcquisitionWorker.get(), |
|
810 | m_VariableAcquisitionWorker.get(), | |
806 | &VariableAcquisitionWorker::onVariableAcquisitionFailed); |
|
811 | &VariableAcquisitionWorker::onVariableAcquisitionFailed); | |
807 | } |
|
812 | } | |
808 | else { |
|
813 | else { | |
809 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); |
|
814 | qCDebug(LOG_VariableController()) << tr("Cannot register provider, it already exists "); | |
810 | } |
|
815 | } | |
811 | } |
|
816 | } | |
812 |
|
817 | |||
813 | QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( |
|
818 | QUuid VariableController::VariableControllerPrivate::acceptVariableRequest( | |
814 | QUuid varId, std::shared_ptr<IDataSeries> dataSeries) |
|
819 | QUuid varId, std::shared_ptr<IDataSeries> dataSeries) | |
815 | { |
|
820 | { | |
816 | auto itVarHandler = m_VarIdToVarRequestHandler.find(varId); |
|
821 | auto itVarHandler = m_VarIdToVarRequestHandler.find(varId); | |
817 | if (itVarHandler == m_VarIdToVarRequestHandler.cend()) { |
|
822 | if (itVarHandler == m_VarIdToVarRequestHandler.cend()) { | |
818 | return QUuid(); |
|
823 | return QUuid(); | |
819 | } |
|
824 | } | |
820 |
|
825 | |||
821 | auto varHandler = itVarHandler->second.get(); |
|
826 | auto varHandler = itVarHandler->second.get(); | |
822 | if (varHandler->m_State == VariableRequestHandlerState::OFF) { |
|
827 | if (varHandler->m_State == VariableRequestHandlerState::OFF) { | |
823 | qCCritical(LOG_VariableController()) |
|
828 | qCCritical(LOG_VariableController()) | |
824 | << tr("acceptVariableRequest impossible on a variable with OFF state"); |
|
829 | << tr("acceptVariableRequest impossible on a variable with OFF state"); | |
825 | } |
|
830 | } | |
826 |
|
831 | |||
827 | varHandler->m_RunningVarRequest.m_DataSeries = dataSeries; |
|
832 | varHandler->m_RunningVarRequest.m_DataSeries = dataSeries; | |
828 | varHandler->m_CanUpdate = true; |
|
833 | varHandler->m_CanUpdate = true; | |
829 |
|
834 | |||
830 | // Element traité, on a déjà toutes les données necessaires |
|
835 | // Element traité, on a déjà toutes les données necessaires | |
831 | auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId; |
|
836 | auto varGroupId = varHandler->m_RunningVarRequest.m_VariableGroupId; | |
832 | qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId |
|
837 | qCDebug(LOG_VariableController()) << "Variable::acceptVariableRequest" << varGroupId | |
833 | << m_VarGroupIdToVarIds.size(); |
|
838 | << m_VarGroupIdToVarIds.size(); | |
834 |
|
839 | |||
835 | return varHandler->m_RunningVarRequest.m_VariableGroupId; |
|
840 | return varHandler->m_RunningVarRequest.m_VariableGroupId; | |
836 | } |
|
841 | } | |
837 |
|
842 | |||
838 | void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId) |
|
843 | void VariableController::VariableControllerPrivate::updateVariables(QUuid varRequestId) | |
839 | { |
|
844 | { | |
840 | qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables" |
|
845 | qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables" | |
841 | << QThread::currentThread()->objectName() << varRequestId; |
|
846 | << QThread::currentThread()->objectName() << varRequestId; | |
842 |
|
847 | |||
843 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); |
|
848 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); | |
844 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { |
|
849 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { | |
845 | qCWarning(LOG_VariableController()) |
|
850 | qCWarning(LOG_VariableController()) | |
846 | << tr("Impossible to updateVariables of unknown variables") << varRequestId; |
|
851 | << tr("Impossible to updateVariables of unknown variables") << varRequestId; | |
847 | return; |
|
852 | return; | |
848 | } |
|
853 | } | |
849 |
|
854 | |||
850 | auto &varIds = varGroupIdToVarIdsIt->second; |
|
855 | auto &varIds = varGroupIdToVarIdsIt->second; | |
851 | auto varIdsEnd = varIds.end(); |
|
856 | auto varIdsEnd = varIds.end(); | |
852 | bool processVariableUpdate = true; |
|
857 | bool processVariableUpdate = true; | |
853 | qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables" |
|
858 | qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables" | |
854 | << varRequestId << varIds.size(); |
|
859 | << varRequestId << varIds.size(); | |
855 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate; |
|
860 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate; | |
856 | ++varIdsIt) { |
|
861 | ++varIdsIt) { | |
857 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); |
|
862 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); | |
858 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { |
|
863 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { | |
859 | processVariableUpdate &= itVarHandler->second->m_CanUpdate; |
|
864 | processVariableUpdate &= itVarHandler->second->m_CanUpdate; | |
860 | } |
|
865 | } | |
861 | } |
|
866 | } | |
862 |
|
867 | |||
863 | if (processVariableUpdate) { |
|
868 | if (processVariableUpdate) { | |
864 | qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size(); |
|
869 | qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size(); | |
865 | for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) { |
|
870 | for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) { | |
866 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); |
|
871 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); | |
867 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { |
|
872 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { | |
868 | if (auto var = findVariable(*varIdsIt)) { |
|
873 | if (auto var = findVariable(*varIdsIt)) { | |
869 | auto &varRequest = itVarHandler->second->m_RunningVarRequest; |
|
874 | auto &varRequest = itVarHandler->second->m_RunningVarRequest; | |
870 | var->setRange(varRequest.m_RangeRequested); |
|
875 | var->setRange(varRequest.m_RangeRequested); | |
871 | var->setCacheRange(varRequest.m_CacheRangeRequested); |
|
876 | var->setCacheRange(varRequest.m_CacheRangeRequested); | |
872 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") |
|
877 | qCDebug(LOG_VariableController()) << tr("1: onDataProvided") | |
873 | << varRequest.m_RangeRequested |
|
878 | << varRequest.m_RangeRequested | |
874 | << varRequest.m_CacheRangeRequested; |
|
879 | << varRequest.m_CacheRangeRequested; | |
875 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before") |
|
880 | qCDebug(LOG_VariableController()) << tr("2: onDataProvided var points before") | |
876 | << var->nbPoints() |
|
881 | << var->nbPoints() | |
877 | << varRequest.m_DataSeries->nbPoints(); |
|
882 | << varRequest.m_DataSeries->nbPoints(); | |
878 | var->mergeDataSeries(varRequest.m_DataSeries); |
|
883 | var->mergeDataSeries(varRequest.m_DataSeries); | |
879 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after") |
|
884 | qCDebug(LOG_VariableController()) << tr("3: onDataProvided var points after") | |
880 | << var->nbPoints(); |
|
885 | << var->nbPoints(); | |
881 |
|
886 | |||
882 | emit var->updated(); |
|
887 | emit var->updated(); | |
883 | qCDebug(LOG_VariableController()) << tr("Update OK"); |
|
888 | qCDebug(LOG_VariableController()) << tr("Update OK"); | |
884 | } |
|
889 | } | |
885 | else { |
|
890 | else { | |
886 | qCCritical(LOG_VariableController()) |
|
891 | qCCritical(LOG_VariableController()) | |
887 | << tr("Impossible to update data to a null variable"); |
|
892 | << tr("Impossible to update data to a null variable"); | |
888 | } |
|
893 | } | |
889 | } |
|
894 | } | |
890 | } |
|
895 | } | |
891 | updateVariableRequest(varRequestId); |
|
896 | updateVariableRequest(varRequestId); | |
892 |
|
897 | |||
893 | // cleaning varRequestId |
|
898 | // cleaning varRequestId | |
894 | qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId; |
|
899 | qCDebug(LOG_VariableController()) << tr("m_VarGroupIdToVarIds erase") << varRequestId; | |
895 | m_VarGroupIdToVarIds.erase(varRequestId); |
|
900 | m_VarGroupIdToVarIds.erase(varRequestId); | |
896 | if (m_VarGroupIdToVarIds.empty()) { |
|
901 | if (m_VarGroupIdToVarIds.empty()) { | |
897 | emit q->acquisitionFinished(); |
|
902 | emit q->acquisitionFinished(); | |
898 | } |
|
903 | } | |
899 | } |
|
904 | } | |
900 | } |
|
905 | } | |
901 |
|
906 | |||
902 |
|
907 | |||
903 | void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) |
|
908 | void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid varRequestId) | |
904 | { |
|
909 | { | |
905 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); |
|
910 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); | |
906 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { |
|
911 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { | |
907 | qCCritical(LOG_VariableController()) << QObject::tr( |
|
912 | qCCritical(LOG_VariableController()) << QObject::tr( | |
908 | "Impossible to updateVariableRequest since varGroupdId isn't here anymore"); |
|
913 | "Impossible to updateVariableRequest since varGroupdId isn't here anymore"); | |
909 |
|
914 | |||
910 | return; |
|
915 | return; | |
911 | } |
|
916 | } | |
912 |
|
917 | |||
913 | auto &varIds = varGroupIdToVarIdsIt->second; |
|
918 | auto &varIds = varGroupIdToVarIdsIt->second; | |
914 | auto varIdsEnd = varIds.end(); |
|
919 | auto varIdsEnd = varIds.end(); | |
915 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { |
|
920 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { | |
916 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); |
|
921 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); | |
917 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { |
|
922 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { | |
918 |
|
923 | |||
919 | auto varHandler = itVarHandler->second.get(); |
|
924 | auto varHandler = itVarHandler->second.get(); | |
920 | varHandler->m_CanUpdate = false; |
|
925 | varHandler->m_CanUpdate = false; | |
921 |
|
926 | |||
922 |
|
927 | |||
923 | switch (varHandler->m_State) { |
|
928 | switch (varHandler->m_State) { | |
924 | case VariableRequestHandlerState::OFF: { |
|
929 | case VariableRequestHandlerState::OFF: { | |
925 | qCCritical(LOG_VariableController()) |
|
930 | qCCritical(LOG_VariableController()) | |
926 | << QObject::tr("Impossible to update a variable with handler in OFF state"); |
|
931 | << QObject::tr("Impossible to update a variable with handler in OFF state"); | |
927 | } break; |
|
932 | } break; | |
928 | case VariableRequestHandlerState::RUNNING: { |
|
933 | case VariableRequestHandlerState::RUNNING: { | |
929 | varHandler->m_State = VariableRequestHandlerState::OFF; |
|
934 | varHandler->m_State = VariableRequestHandlerState::OFF; | |
930 | varHandler->m_RunningVarRequest = VariableRequest{}; |
|
935 | varHandler->m_RunningVarRequest = VariableRequest{}; | |
931 | break; |
|
936 | break; | |
932 | } |
|
937 | } | |
933 | case VariableRequestHandlerState::PENDING: { |
|
938 | case VariableRequestHandlerState::PENDING: { | |
934 | varHandler->m_State = VariableRequestHandlerState::RUNNING; |
|
939 | varHandler->m_State = VariableRequestHandlerState::RUNNING; | |
935 | varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest; |
|
940 | varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest; | |
936 | varHandler->m_PendingVarRequest = VariableRequest{}; |
|
941 | varHandler->m_PendingVarRequest = VariableRequest{}; | |
937 | auto var = findVariable(itVarHandler->first); |
|
942 | auto var = findVariable(itVarHandler->first); | |
938 | executeVarRequest(var, varHandler->m_RunningVarRequest); |
|
943 | executeVarRequest(var, varHandler->m_RunningVarRequest); | |
939 | updateVariables(varHandler->m_RunningVarRequest.m_VariableGroupId); |
|
944 | updateVariables(varHandler->m_RunningVarRequest.m_VariableGroupId); | |
940 | break; |
|
945 | break; | |
941 | } |
|
946 | } | |
942 | default: |
|
947 | default: | |
943 | qCCritical(LOG_VariableController()) |
|
948 | qCCritical(LOG_VariableController()) | |
944 | << QObject::tr("Unknown VariableRequestHandlerState"); |
|
949 | << QObject::tr("Unknown VariableRequestHandlerState"); | |
945 | } |
|
950 | } | |
946 | } |
|
951 | } | |
947 | } |
|
952 | } | |
948 | } |
|
953 | } | |
949 |
|
954 | |||
950 |
|
955 | |||
951 | void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) |
|
956 | void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid varRequestId) | |
952 | { |
|
957 | { | |
953 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId; |
|
958 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest") << varRequestId; | |
954 |
|
959 | |||
955 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); |
|
960 | auto varGroupIdToVarIdsIt = m_VarGroupIdToVarIds.find(varRequestId); | |
956 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { |
|
961 | if (varGroupIdToVarIdsIt == m_VarGroupIdToVarIds.end()) { | |
957 | qCCritical(LOG_VariableController()) |
|
962 | qCCritical(LOG_VariableController()) | |
958 | << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId; |
|
963 | << tr("Impossible to cancelVariableRequest for unknown varGroupdId") << varRequestId; | |
959 | return; |
|
964 | return; | |
960 | } |
|
965 | } | |
961 |
|
966 | |||
962 | auto &varIds = varGroupIdToVarIdsIt->second; |
|
967 | auto &varIds = varGroupIdToVarIdsIt->second; | |
963 | auto varIdsEnd = varIds.end(); |
|
968 | auto varIdsEnd = varIds.end(); | |
964 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { |
|
969 | for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { | |
965 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); |
|
970 | auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); | |
966 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { |
|
971 | if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { | |
967 |
|
972 | |||
968 | auto varHandler = itVarHandler->second.get(); |
|
973 | auto varHandler = itVarHandler->second.get(); | |
969 | varHandler->m_VarId = QUuid{}; |
|
974 | varHandler->m_VarId = QUuid{}; | |
970 | switch (varHandler->m_State) { |
|
975 | switch (varHandler->m_State) { | |
971 | case VariableRequestHandlerState::OFF: { |
|
976 | case VariableRequestHandlerState::OFF: { | |
972 | qCWarning(LOG_VariableController()) |
|
977 | qCWarning(LOG_VariableController()) | |
973 | << QObject::tr("Impossible to cancel a variable with no running request"); |
|
978 | << QObject::tr("Impossible to cancel a variable with no running request"); | |
974 | break; |
|
979 | break; | |
975 | } |
|
980 | } | |
976 | case VariableRequestHandlerState::RUNNING: { |
|
981 | case VariableRequestHandlerState::RUNNING: { | |
977 |
|
982 | |||
978 | if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) { |
|
983 | if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) { | |
979 | auto var = findVariable(itVarHandler->first); |
|
984 | auto var = findVariable(itVarHandler->first); | |
980 | auto varProvider = m_VariableToProviderMap.at(var); |
|
985 | auto varProvider = m_VariableToProviderMap.at(var); | |
981 | if (varProvider != nullptr) { |
|
986 | if (varProvider != nullptr) { | |
982 | m_VariableAcquisitionWorker->abortProgressRequested( |
|
987 | m_VariableAcquisitionWorker->abortProgressRequested( | |
983 | itVarHandler->first); |
|
988 | itVarHandler->first); | |
984 | } |
|
989 | } | |
985 | m_VariableModel->setDataProgress(var, 0.0); |
|
990 | m_VariableModel->setDataProgress(var, 0.0); | |
986 | varHandler->m_CanUpdate = false; |
|
991 | varHandler->m_CanUpdate = false; | |
987 | varHandler->m_State = VariableRequestHandlerState::OFF; |
|
992 | varHandler->m_State = VariableRequestHandlerState::OFF; | |
988 | varHandler->m_RunningVarRequest = VariableRequest{}; |
|
993 | varHandler->m_RunningVarRequest = VariableRequest{}; | |
989 | } |
|
994 | } | |
990 | else { |
|
995 | else { | |
991 | // TODO: log Impossible to cancel the running variable request beacause its |
|
996 | // TODO: log Impossible to cancel the running variable request beacause its | |
992 | // varRequestId isn't not the canceled one |
|
997 | // varRequestId isn't not the canceled one | |
993 | } |
|
998 | } | |
994 | break; |
|
999 | break; | |
995 | } |
|
1000 | } | |
996 | case VariableRequestHandlerState::PENDING: { |
|
1001 | case VariableRequestHandlerState::PENDING: { | |
997 | if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) { |
|
1002 | if (varHandler->m_RunningVarRequest.m_VariableGroupId == varRequestId) { | |
998 | auto var = findVariable(itVarHandler->first); |
|
1003 | auto var = findVariable(itVarHandler->first); | |
999 | auto varProvider = m_VariableToProviderMap.at(var); |
|
1004 | auto varProvider = m_VariableToProviderMap.at(var); | |
1000 | if (varProvider != nullptr) { |
|
1005 | if (varProvider != nullptr) { | |
1001 | m_VariableAcquisitionWorker->abortProgressRequested( |
|
1006 | m_VariableAcquisitionWorker->abortProgressRequested( | |
1002 | itVarHandler->first); |
|
1007 | itVarHandler->first); | |
1003 | } |
|
1008 | } | |
1004 | m_VariableModel->setDataProgress(var, 0.0); |
|
1009 | m_VariableModel->setDataProgress(var, 0.0); | |
1005 | varHandler->m_CanUpdate = false; |
|
1010 | varHandler->m_CanUpdate = false; | |
1006 | varHandler->m_State = VariableRequestHandlerState::RUNNING; |
|
1011 | varHandler->m_State = VariableRequestHandlerState::RUNNING; | |
1007 | varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest; |
|
1012 | varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest; | |
1008 | varHandler->m_PendingVarRequest = VariableRequest{}; |
|
1013 | varHandler->m_PendingVarRequest = VariableRequest{}; | |
1009 | executeVarRequest(var, varHandler->m_RunningVarRequest); |
|
1014 | executeVarRequest(var, varHandler->m_RunningVarRequest); | |
1010 | } |
|
1015 | } | |
1011 | else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) { |
|
1016 | else if (varHandler->m_PendingVarRequest.m_VariableGroupId == varRequestId) { | |
1012 | varHandler->m_State = VariableRequestHandlerState::RUNNING; |
|
1017 | varHandler->m_State = VariableRequestHandlerState::RUNNING; | |
1013 | varHandler->m_PendingVarRequest = VariableRequest{}; |
|
1018 | varHandler->m_PendingVarRequest = VariableRequest{}; | |
1014 | } |
|
1019 | } | |
1015 | else { |
|
1020 | else { | |
1016 | // TODO: log Impossible to cancel the variable request beacause its |
|
1021 | // TODO: log Impossible to cancel the variable request beacause its | |
1017 | // varRequestId isn't not the canceled one |
|
1022 | // varRequestId isn't not the canceled one | |
1018 | } |
|
1023 | } | |
1019 | break; |
|
1024 | break; | |
1020 | } |
|
1025 | } | |
1021 | default: |
|
1026 | default: | |
1022 | qCCritical(LOG_VariableController()) |
|
1027 | qCCritical(LOG_VariableController()) | |
1023 | << QObject::tr("Unknown VariableRequestHandlerState"); |
|
1028 | << QObject::tr("Unknown VariableRequestHandlerState"); | |
1024 | } |
|
1029 | } | |
1025 | } |
|
1030 | } | |
1026 | } |
|
1031 | } | |
1027 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId; |
|
1032 | qCDebug(LOG_VariableController()) << tr("cancelVariableRequest: erase") << varRequestId; | |
1028 | m_VarGroupIdToVarIds.erase(varRequestId); |
|
1033 | m_VarGroupIdToVarIds.erase(varRequestId); | |
1029 | if (m_VarGroupIdToVarIds.empty()) { |
|
1034 | if (m_VarGroupIdToVarIds.empty()) { | |
1030 | emit q->acquisitionFinished(); |
|
1035 | emit q->acquisitionFinished(); | |
1031 | } |
|
1036 | } | |
1032 | } |
|
1037 | } | |
1033 |
|
1038 | |||
1034 | void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var, |
|
1039 | void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr<Variable> var, | |
1035 | VariableRequest &varRequest) |
|
1040 | VariableRequest &varRequest) | |
1036 | { |
|
1041 | { | |
1037 | qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest"); |
|
1042 | qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest"); | |
1038 |
|
1043 | |||
1039 | auto varIdIt = m_VariableToIdentifierMap.find(var); |
|
1044 | auto varIdIt = m_VariableToIdentifierMap.find(var); | |
1040 | if (varIdIt == m_VariableToIdentifierMap.cend()) { |
|
1045 | if (varIdIt == m_VariableToIdentifierMap.cend()) { | |
1041 | qCWarning(LOG_VariableController()) << tr( |
|
1046 | qCWarning(LOG_VariableController()) << tr( | |
1042 | "Can't execute request of a variable that is not registered (may has been deleted)"); |
|
1047 | "Can't execute request of a variable that is not registered (may has been deleted)"); | |
1043 | return; |
|
1048 | return; | |
1044 | } |
|
1049 | } | |
1045 |
|
1050 | |||
1046 | auto varId = varIdIt->second; |
|
1051 | auto varId = varIdIt->second; | |
1047 |
|
1052 | |||
1048 | auto varCacheRange = var->cacheRange(); |
|
1053 | auto varCacheRange = var->cacheRange(); | |
1049 | auto varCacheRangeRequested = varRequest.m_CacheRangeRequested; |
|
1054 | auto varCacheRangeRequested = varRequest.m_CacheRangeRequested; | |
1050 | auto notInCacheRangeList |
|
1055 | auto notInCacheRangeList | |
1051 | = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested); |
|
1056 | = Variable::provideNotInCacheRangeList(varCacheRange, varCacheRangeRequested); | |
1052 | auto inCacheRangeList |
|
1057 | auto inCacheRangeList | |
1053 | = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested); |
|
1058 | = Variable::provideInCacheRangeList(varCacheRange, varCacheRangeRequested); | |
1054 |
|
1059 | |||
1055 | if (!notInCacheRangeList.empty()) { |
|
1060 | if (!notInCacheRangeList.empty()) { | |
1056 |
|
1061 | |||
1057 | auto varProvider = m_VariableToProviderMap.at(var); |
|
1062 | auto varProvider = m_VariableToProviderMap.at(var); | |
1058 | if (varProvider != nullptr) { |
|
1063 | if (varProvider != nullptr) { | |
1059 | qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested |
|
1064 | qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested | |
1060 | << varRequest.m_CacheRangeRequested; |
|
1065 | << varRequest.m_CacheRangeRequested; | |
1061 | m_VariableAcquisitionWorker->pushVariableRequest( |
|
1066 | m_VariableAcquisitionWorker->pushVariableRequest( | |
1062 | varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested, |
|
1067 | varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested, | |
1063 | varRequest.m_CacheRangeRequested, |
|
1068 | varRequest.m_CacheRangeRequested, | |
1064 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, |
|
1069 | DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, | |
1065 | varProvider); |
|
1070 | varProvider); | |
1066 | } |
|
1071 | } | |
1067 | else { |
|
1072 | else { | |
1068 | qCCritical(LOG_VariableController()) |
|
1073 | qCCritical(LOG_VariableController()) | |
1069 | << "Impossible to provide data with a null provider"; |
|
1074 | << "Impossible to provide data with a null provider"; | |
1070 | } |
|
1075 | } | |
1071 |
|
1076 | |||
1072 | if (!inCacheRangeList.empty()) { |
|
1077 | if (!inCacheRangeList.empty()) { | |
1073 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); |
|
1078 | emit q->updateVarDisplaying(var, inCacheRangeList.first()); | |
1074 | } |
|
1079 | } | |
1075 | } |
|
1080 | } | |
1076 | else { |
|
1081 | else { | |
1077 | acceptVariableRequest(varId, |
|
1082 | acceptVariableRequest(varId, | |
1078 | var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested)); |
|
1083 | var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested)); | |
1079 | } |
|
1084 | } | |
1080 | } |
|
1085 | } | |
1081 |
|
1086 | |||
|
1087 | bool VariableController::VariableControllerPrivate::hasPendingDownloads() | |||
|
1088 | { | |||
|
1089 | return !m_VarGroupIdToVarIds.empty(); | |||
|
1090 | } | |||
|
1091 | ||||
1082 | template <typename VariableIterator> |
|
1092 | template <typename VariableIterator> | |
1083 | void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt, |
|
1093 | void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt, | |
1084 | const QUuid &syncGroupId) |
|
1094 | const QUuid &syncGroupId) | |
1085 | { |
|
1095 | { | |
1086 | const auto &variable = variableIt->first; |
|
1096 | const auto &variable = variableIt->first; | |
1087 | const auto &variableId = variableIt->second; |
|
1097 | const auto &variableId = variableIt->second; | |
1088 |
|
1098 | |||
1089 | // Gets synchronization group |
|
1099 | // Gets synchronization group | |
1090 | auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId); |
|
1100 | auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId); | |
1091 | if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) { |
|
1101 | if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) { | |
1092 | qCCritical(LOG_VariableController()) |
|
1102 | qCCritical(LOG_VariableController()) | |
1093 | << tr("Can't desynchronize variable %1: unknown synchronization group") |
|
1103 | << tr("Can't desynchronize variable %1: unknown synchronization group") | |
1094 | .arg(variable->name()); |
|
1104 | .arg(variable->name()); | |
1095 | return; |
|
1105 | return; | |
1096 | } |
|
1106 | } | |
1097 |
|
1107 | |||
1098 | // Removes variable from synchronization group |
|
1108 | // Removes variable from synchronization group | |
1099 | auto synchronizationGroup = groupIt->second; |
|
1109 | auto synchronizationGroup = groupIt->second; | |
1100 | synchronizationGroup->removeVariableId(variableId); |
|
1110 | synchronizationGroup->removeVariableId(variableId); | |
1101 |
|
1111 | |||
1102 | // Removes link between variable and synchronization group |
|
1112 | // Removes link between variable and synchronization group | |
1103 | m_VariableIdGroupIdMap.erase(variableId); |
|
1113 | m_VariableIdGroupIdMap.erase(variableId); | |
1104 | } |
|
1114 | } |
@@ -1,62 +1,73 | |||||
1 | include_directories(include) |
|
1 | include_directories(include) | |
2 | FILE (GLOB_RECURSE amdaplugin_SRCS |
|
2 | FILE (GLOB_RECURSE amdaplugin_SRCS | |
3 | include/*.h |
|
3 | include/*.h | |
4 | src/*.cpp |
|
4 | src/*.cpp | |
5 | resources/*.qrc |
|
5 | resources/*.qrc | |
6 | ) |
|
6 | ) | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | set(AMDA_server_type hybrid CACHE STRING "AMDA server type selected at CMake configure time") |
|
9 | set(AMDA_server_type hybrid CACHE STRING "AMDA server type selected at CMake configure time") | |
10 |
|
10 | |||
11 | set(AMDA_SERVER_TYPE "hybrid;amdatest;localhost" CACHE STRING |
|
11 | set(AMDA_SERVER_TYPE "hybrid;amdatest;localhost" CACHE STRING | |
12 | "List of possible for AMDA server type") |
|
12 | "List of possible for AMDA server type") | |
13 |
|
13 | |||
14 | set_property(CACHE AMDA_server_type PROPERTY STRINGS ${AMDA_SERVER_TYPE}) |
|
14 | set_property(CACHE AMDA_server_type PROPERTY STRINGS ${AMDA_SERVER_TYPE}) | |
15 | add_definitions(-DSCIQLOP_AMDA_SERVER="${AMDA_server_type}") |
|
15 | add_definitions(-DSCIQLOP_AMDA_SERVER="${AMDA_server_type}") | |
16 |
|
16 | |||
17 | add_definitions(-DQT_PLUGIN) |
|
17 | add_definitions(-DQT_PLUGIN) | |
18 | add_definitions(-DSCIQLOP_PLUGIN_JSON_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/amda.json") |
|
18 | add_definitions(-DSCIQLOP_PLUGIN_JSON_FILE_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/amda.json") | |
19 | if(NOT BUILD_SHARED_LIBS) |
|
19 | if(NOT BUILD_SHARED_LIBS) | |
20 | add_definitions(-DQT_STATICPLUGIN) |
|
20 | add_definitions(-DQT_STATICPLUGIN) | |
21 | endif() |
|
21 | endif() | |
22 |
|
22 | |||
23 | add_library(amdaplugin ${amdaplugin_SRCS}) |
|
23 | add_library(amdaplugin ${amdaplugin_SRCS}) | |
24 | SET_TARGET_PROPERTIES(amdaplugin PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) |
|
24 | SET_TARGET_PROPERTIES(amdaplugin PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE) | |
25 |
|
25 | |||
26 | target_link_libraries(amdaplugin PUBLIC sciqlopgui) |
|
26 | target_link_libraries(amdaplugin PUBLIC sciqlopgui) | |
27 |
|
27 | |||
28 | install(TARGETS amdaplugin |
|
28 | install(TARGETS amdaplugin | |
29 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop |
|
29 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop | |
30 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop |
|
30 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/SciQlop | |
31 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) |
|
31 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) | |
32 |
|
32 | |||
33 | include(sciqlop_tests) |
|
33 | include(sciqlop_tests) | |
34 |
|
34 | |||
35 | add_definitions(-DAMDA_TESTS_RESOURCES_DIR="${CMAKE_CURRENT_LIST_DIR}/tests-resources") |
|
35 | add_definitions(-DAMDA_TESTS_RESOURCES_DIR="${CMAKE_CURRENT_LIST_DIR}/tests-resources") | |
36 |
|
36 | |||
37 | declare_test(TestAmdaParser TestAmdaParser tests/TestAmdaParser.cpp "amdaplugin;Qt5::Test") |
|
37 | declare_test(TestAmdaParser TestAmdaParser tests/TestAmdaParser.cpp "amdaplugin;Qt5::Test") | |
38 | declare_test(TestAmdaResultParser TestAmdaResultParser tests/TestAmdaResultParser.cpp "amdaplugin;Qt5::Test") |
|
38 | declare_test(TestAmdaResultParser TestAmdaResultParser tests/TestAmdaResultParser.cpp "amdaplugin;Qt5::Test") | |
39 | declare_test(TestAmdaAcquisition TestAmdaAcquisition tests/TestAmdaAcquisition.cpp "amdaplugin;Qt5::Test") |
|
39 | declare_test(TestAmdaAcquisition TestAmdaAcquisition tests/TestAmdaAcquisition.cpp "amdaplugin;Qt5::Test") | |
40 | declare_test(TestAmdaFuzzing TestAmdaFuzzing "tests/TestAmdaFuzzing.cpp;tests/FuzzingValidators.cpp;tests/FuzzingUtils.cpp;tests/FuzzingOperations.cpp;tests/FuzzingDefs.cpp" "amdaplugin;Qt5::Test") |
|
40 | declare_test(TestAmdaFuzzing TestAmdaFuzzing "tests/TestAmdaFuzzing.cpp;tests/FuzzingValidators.cpp;tests/FuzzingUtils.cpp;tests/FuzzingOperations.cpp;tests/FuzzingDefs.cpp" "amdaplugin;Qt5::Test") | |
41 |
|
41 | |||
42 | pybind11_add_module(pytestamda tests/PyTestAmdaWrapper.cpp) |
|
42 | pybind11_add_module(pytestamda tests/PyTestAmdaWrapper.cpp) | |
43 | target_link_libraries(pytestamda PUBLIC amdaplugin) |
|
43 | target_link_libraries(pytestamda PUBLIC amdaplugin) | |
44 |
|
44 | |||
45 | #pybind11_add_module(pytestamdalib SHARED tests/PyTestAmdaWrapper.cpp) |
|
45 | #pybind11_add_module(pytestamdalib SHARED tests/PyTestAmdaWrapper.cpp) | |
46 | add_library(pytestamdalib tests/PyTestAmdaWrapper.cpp) |
|
46 | add_library(pytestamdalib tests/PyTestAmdaWrapper.cpp) | |
47 | target_link_libraries(pytestamdalib PUBLIC pybind11::module) |
|
47 | target_link_libraries(pytestamdalib PUBLIC pybind11::module) | |
48 | target_link_libraries(pytestamdalib PUBLIC pybind11::embed) |
|
48 | target_link_libraries(pytestamdalib PUBLIC pybind11::embed) | |
49 | target_link_libraries(pytestamdalib PUBLIC amdaplugin) |
|
49 | target_link_libraries(pytestamdalib PUBLIC amdaplugin) | |
50 |
|
50 | |||
51 |
declare_test(Test |
|
51 | declare_test(TestAmdaFileParserEmbed TestAmdaFileParserEmbed "tests/PyTestAmdaWrapperExe.cpp" "amdaplugin;pytestamdalib") | |
52 |
target_compile_definitions(Test |
|
52 | target_compile_definitions(TestAmdaFileParserEmbed PRIVATE -DPYTESTAMDA_SCRIPT="${CMAKE_CURRENT_LIST_DIR}/tests/TestAmdaFileParser.py") | |
|
53 | ||||
|
54 | declare_test(TestAmdaDownloadEmbed TestAmdaDownloadEmbed "tests/PyTestAmdaWrapperExe.cpp" "amdaplugin;pytestamdalib") | |||
|
55 | target_compile_definitions(TestAmdaDownloadEmbed PRIVATE -DPYTESTAMDA_SCRIPT="${CMAKE_CURRENT_LIST_DIR}/tests/TestAmdaDownload.py") | |||
|
56 | ||||
53 |
|
57 | |||
54 | find_package(PythonInterp 3 REQUIRED) |
|
58 | find_package(PythonInterp 3 REQUIRED) | |
55 |
|
59 | |||
56 |
add_test(NAME |
|
60 | add_test(NAME TestAmdaFileParser | |
|
61 | COMMAND ${PYTHON_EXECUTABLE} | |||
|
62 | ${CMAKE_CURRENT_LIST_DIR}/tests/TestAmdaFileParser.py | |||
|
63 | TestAmdaFileParser) | |||
|
64 | set_tests_properties(TestAmdaFileParser PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}) | |||
|
65 | ||||
|
66 | ||||
|
67 | add_test(NAME TestAmdaDownload | |||
57 | COMMAND ${PYTHON_EXECUTABLE} |
|
68 | COMMAND ${PYTHON_EXECUTABLE} | |
58 |
${CMAKE_CURRENT_LIST_DIR}/tests/ |
|
69 | ${CMAKE_CURRENT_LIST_DIR}/tests/TestAmdaDownload.py | |
59 | pyamdatests) |
|
70 | TestAmdaDownload) | |
|
71 | set_tests_properties(TestAmdaDownload PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}) | |||
60 |
|
72 | |||
61 | set_tests_properties(pyamdatests PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}) |
|
|||
62 |
|
73 |
@@ -1,164 +1,244 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLOP Software |
|
2 | -- This file is a part of the SciQLOP Software | |
3 | -- Copyright (C) 2018, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2018, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include <string> |
|
22 | #include <string> | |
23 | #include <sstream> |
|
23 | #include <sstream> | |
24 | #include <memory> |
|
24 | #include <memory> | |
25 |
|
25 | |||
26 | #include <pybind11/pybind11.h> |
|
26 | #include <pybind11/pybind11.h> | |
27 | #include <pybind11/operators.h> |
|
27 | #include <pybind11/operators.h> | |
28 | #include <pybind11/embed.h> |
|
28 | #include <pybind11/embed.h> | |
|
29 | #include <pybind11/numpy.h> | |||
|
30 | #include <pybind11/chrono.h> | |||
29 |
|
31 | |||
30 | #include <SqpApplication.h> |
|
32 | #include <SqpApplication.h> | |
31 | #include <Variable/VariableController.h> |
|
33 | #include <Variable/VariableController.h> | |
32 | #include <Time/TimeController.h> |
|
34 | #include <Time/TimeController.h> | |
33 | #include <Data/SqpRange.h> |
|
35 | #include <Data/SqpRange.h> | |
34 | #include <Data/DataSeriesType.h> |
|
36 | #include <Data/DataSeriesType.h> | |
35 | #include <Common/DateUtils.h> |
|
37 | #include <Common/DateUtils.h> | |
36 | #include <Variable/Variable.h> |
|
38 | #include <Variable/Variable.h> | |
37 | #include <Data/ScalarSeries.h> |
|
39 | #include <Data/ScalarSeries.h> | |
|
40 | #include <Data/VectorSeries.h> | |||
38 |
|
41 | |||
39 | #include <AmdaProvider.h> |
|
42 | #include <AmdaProvider.h> | |
40 | #include <AmdaResultParser.h> |
|
43 | #include <AmdaResultParser.h> | |
41 |
|
44 | |||
42 | #include <QDate> |
|
45 | #include <QDate> | |
43 | #include <QTime> |
|
46 | #include <QTime> | |
44 | #include <QUuid> |
|
47 | #include <QUuid> | |
45 | #include <QString> |
|
48 | #include <QString> | |
46 | #include <QFile> |
|
49 | #include <QFile> | |
47 |
|
50 | |||
|
51 | using namespace std::chrono; | |||
48 | namespace py = pybind11; |
|
52 | namespace py = pybind11; | |
49 |
|
53 | |||
50 | std::ostream &operator <<(std::ostream& os, const Unit& u) |
|
54 | std::ostream &operator <<(std::ostream& os, const Unit& u) | |
51 | { |
|
55 | { | |
52 | os << "=========================" << std::endl |
|
56 | os << "=========================" << std::endl | |
53 | << "Unit:" << std::endl |
|
57 | << "Unit:" << std::endl | |
54 |
<< "Name:" |
|
58 | << " Name: " << u.m_Name.toStdString() << std::endl | |
55 | << "Is_TimeUnit: " << u.m_TimeUnit << std::endl; |
|
59 | << " Is_TimeUnit: " << u.m_TimeUnit << std::endl; | |
56 | return os; |
|
60 | return os; | |
57 | } |
|
61 | } | |
58 |
|
62 | |||
59 | std::ostream &operator <<(std::ostream& os, const IDataSeries& ds) |
|
63 | std::ostream &operator <<(std::ostream& os, const IDataSeries& ds) | |
60 | { |
|
64 | { | |
61 | os << "=========================" << std::endl |
|
65 | os << "=========================" << std::endl | |
62 | << "DataSerie:" << std::endl |
|
66 | << "DataSerie:" << std::endl | |
63 | << "Number of points:" << ds.nbPoints() << std::endl |
|
67 | << " Number of points:" << ds.nbPoints() << std::endl | |
64 | << "X Axis Unit:" << std::endl << ds.xAxisUnit() << std::endl |
|
68 | << " X Axis Unit:" << std::endl << ds.xAxisUnit() << std::endl | |
65 | << "Y Axis Unit:" << std::endl << ds.yAxisUnit()<< std::endl |
|
69 | << " Y Axis Unit:" << std::endl << ds.yAxisUnit()<< std::endl | |
66 | << "Values Axis Unit:" << std::endl << ds.valuesUnit()<< std::endl; |
|
70 | << " Values Axis Unit:" << std::endl << ds.valuesUnit()<< std::endl; | |
|
71 | return os; | |||
|
72 | } | |||
|
73 | ||||
|
74 | std::ostream &operator <<(std::ostream& os, const SqpRange& range) | |||
|
75 | { | |||
|
76 | os << "=========================" << std::endl | |||
|
77 | << "SqpRange:" << std::endl | |||
|
78 | << " Start date: " << DateUtils::dateTime(range.m_TStart).toString().toStdString() << std::endl | |||
|
79 | << " Stop date: " << DateUtils::dateTime(range.m_TEnd).toString().toStdString() << std::endl; | |||
|
80 | return os; | |||
|
81 | } | |||
|
82 | ||||
|
83 | std::ostream &operator <<(std::ostream& os, const Variable& variable) | |||
|
84 | { | |||
|
85 | os << "=========================" << std::endl | |||
|
86 | << "Variable:" << std::endl | |||
|
87 | << " Name: " << variable.name().toStdString() << std::endl | |||
|
88 | << " range: " << std::endl << variable.range() << std::endl | |||
|
89 | << " cache range: " << std::endl << variable.cacheRange() << std::endl; | |||
67 | return os; |
|
90 | return os; | |
68 | } |
|
91 | } | |
69 |
|
92 | |||
70 | template <typename T> |
|
93 | template <typename T> | |
71 | std::string __repr__(const T& obj) |
|
94 | std::string __repr__(const T& obj) | |
72 | { |
|
95 | { | |
73 | std::stringstream sstr; |
|
96 | std::stringstream sstr; | |
74 | sstr << obj; |
|
97 | sstr << obj; | |
75 | return sstr.str(); |
|
98 | return sstr.str(); | |
76 | } |
|
99 | } | |
77 |
|
100 | |||
78 |
|
101 | |||
|
102 | ||||
|
103 | ||||
79 | PYBIND11_MODULE(pytestamda, m){ |
|
104 | PYBIND11_MODULE(pytestamda, m){ | |
|
105 | int argc = 0; | |||
|
106 | char ** argv=nullptr; | |||
|
107 | SqpApplication::setOrganizationName("LPP"); | |||
|
108 | SqpApplication::setOrganizationDomain("lpp.fr"); | |||
|
109 | SqpApplication::setApplicationName("SciQLop"); | |||
|
110 | static SqpApplication app(argc, argv); | |||
|
111 | ||||
80 | m.doc() = "hello"; |
|
112 | m.doc() = "hello"; | |
81 |
|
113 | |||
|
114 | auto amda_provider = std::make_shared<AmdaProvider>(); | |||
|
115 | m.def("amda_provider",[amda_provider](){return amda_provider;}, py::return_value_policy::copy); | |||
|
116 | ||||
82 | py::enum_<DataSeriesType>(m, "DataSeriesType") |
|
117 | py::enum_<DataSeriesType>(m, "DataSeriesType") | |
83 | .value("SCALAR", DataSeriesType::SCALAR) |
|
118 | .value("SCALAR", DataSeriesType::SCALAR) | |
84 | .value("SPECTROGRAM", DataSeriesType::SPECTROGRAM) |
|
119 | .value("SPECTROGRAM", DataSeriesType::SPECTROGRAM) | |
85 | .value("UNKNOWN", DataSeriesType::UNKNOWN) |
|
120 | .value("UNKNOWN", DataSeriesType::UNKNOWN) | |
86 | .export_values(); |
|
121 | .export_values(); | |
87 |
|
122 | |||
88 | py::class_<Unit>(m, "Unit") |
|
123 | py::class_<Unit>(m, "Unit") | |
89 | .def_readwrite("name", &Unit::m_Name) |
|
124 | .def_readwrite("name", &Unit::m_Name) | |
90 | .def_readwrite("time_unit", &Unit::m_TimeUnit) |
|
125 | .def_readwrite("time_unit", &Unit::m_TimeUnit) | |
91 | .def(py::self == py::self) |
|
126 | .def(py::self == py::self) | |
92 | .def(py::self != py::self) |
|
127 | .def(py::self != py::self) | |
93 | .def("__repr__",__repr__<Unit>); |
|
128 | .def("__repr__",__repr__<Unit>); | |
94 |
|
129 | |||
|
130 | py::class_<DataSeriesIteratorValue>(m,"DataSeriesIteratorValue") | |||
|
131 | .def_property_readonly("x", &DataSeriesIteratorValue::x) | |||
|
132 | .def("value", py::overload_cast<>(&DataSeriesIteratorValue::value, py::const_)) | |||
|
133 | .def("value", py::overload_cast<int>(&DataSeriesIteratorValue::value, py::const_)); | |||
|
134 | ||||
95 | py::class_<IDataSeries, std::shared_ptr<IDataSeries>>(m, "IDataSeries") |
|
135 | py::class_<IDataSeries, std::shared_ptr<IDataSeries>>(m, "IDataSeries") | |
96 | .def("nbPoints", &IDataSeries::nbPoints) |
|
136 | .def("nbPoints", &IDataSeries::nbPoints) | |
97 | .def_property_readonly("xAxisUnit", &IDataSeries::xAxisUnit) |
|
137 | .def_property_readonly("xAxisUnit", &IDataSeries::xAxisUnit) | |
98 | .def_property_readonly("yAxisUnit", &IDataSeries::yAxisUnit) |
|
138 | .def_property_readonly("yAxisUnit", &IDataSeries::yAxisUnit) | |
99 | .def_property_readonly("valuesUnit", &IDataSeries::valuesUnit) |
|
139 | .def_property_readonly("valuesUnit", &IDataSeries::valuesUnit) | |
|
140 | .def("__getitem__", [](IDataSeries& serie, int key) { | |||
|
141 | return *(serie.begin()+key); | |||
|
142 | }, py::is_operator()) | |||
|
143 | .def("__len__", &IDataSeries::nbPoints) | |||
|
144 | .def("__iter__", [](IDataSeries& serie) { | |||
|
145 | return py::make_iterator(serie.begin(), serie.end()); | |||
|
146 | }, py::keep_alive<0, 1>()) | |||
100 | .def("__repr__",__repr__<IDataSeries>); |
|
147 | .def("__repr__",__repr__<IDataSeries>); | |
101 |
|
148 | |||
102 |
|
||||
103 |
|
||||
104 | py::class_<ScalarSeries, std::shared_ptr<ScalarSeries>, IDataSeries>(m, "ScalarSeries") |
|
149 | py::class_<ScalarSeries, std::shared_ptr<ScalarSeries>, IDataSeries>(m, "ScalarSeries") | |
105 | .def("nbPoints", &ScalarSeries::nbPoints); |
|
150 | .def("nbPoints", &ScalarSeries::nbPoints); | |
106 |
|
151 | |||
|
152 | py::class_<VectorSeries, std::shared_ptr<VectorSeries>, IDataSeries>(m, "VectorSeries") | |||
|
153 | .def("nbPoints", &VectorSeries::nbPoints); | |||
|
154 | ||||
107 | py::class_<QString>(m, "QString") |
|
155 | py::class_<QString>(m, "QString") | |
108 | .def(py::init([](const std::string& value){return QString::fromStdString(value);})) |
|
156 | .def(py::init([](const std::string& value){return QString::fromStdString(value);})) | |
109 | .def("__repr__", &QString::toStdString); |
|
157 | .def("__repr__", &QString::toStdString); | |
110 |
|
158 | |||
111 |
py::class_<VariableController>(m, "VariableController") |
|
159 | py::class_<VariableController>(m, "VariableController") | |
|
160 | .def_static("createVariable",[](const QString &name, | |||
|
161 | std::shared_ptr<IDataProvider> provider){ | |||
|
162 | return sqpApp->variableController().createVariable(name, {{"dataType", "vector"}, {"xml:id", "c1_b"}}, provider); | |||
|
163 | }) | |||
|
164 | .def_static("hasPendingDownloads", | |||
|
165 | [](){return sqpApp->variableController().hasPendingDownloads();} | |||
|
166 | ); | |||
112 |
|
167 | |||
113 |
py::class_< |
|
168 | py::class_<TimeController>(m,"TimeController") | |
|
169 | .def_static("setTime", [](SqpRange range){sqpApp->timeController().onTimeToUpdate(range);}); | |||
|
170 | ||||
|
171 | py::class_<IDataProvider, std::shared_ptr<IDataProvider>>(m, "IDataProvider"); | |||
|
172 | ||||
|
173 | py::class_<AmdaProvider, std::shared_ptr<AmdaProvider>, IDataProvider>(m, "AmdaProvider"); | |||
114 |
|
174 | |||
115 | py::class_<AmdaResultParser>(m, "AmdaResultParser") |
|
175 | py::class_<AmdaResultParser>(m, "AmdaResultParser") | |
116 | .def_static("readTxt", AmdaResultParser::readTxt) |
|
176 | .def_static("readTxt", AmdaResultParser::readTxt) | |
117 | .def("readScalarTxt", [](const QString& path){ |
|
177 | .def("readScalarTxt", [](const QString& path){ | |
118 | return std::dynamic_pointer_cast<ScalarSeries>(AmdaResultParser::readTxt(path, DataSeriesType::SCALAR)); |
|
178 | return std::dynamic_pointer_cast<ScalarSeries>(AmdaResultParser::readTxt(path, DataSeriesType::SCALAR)); | |
119 | }, py::return_value_policy::copy); |
|
179 | }, py::return_value_policy::copy); | |
120 |
|
180 | |||
121 | py::class_<Variable>(m, "Variable") |
|
181 | py::class_<Variable,std::shared_ptr<Variable>>(m, "Variable") | |
122 | .def(py::init<const QString&>()) |
|
182 | .def(py::init<const QString&>()) | |
123 | .def_property("name", &Variable::name, &Variable::setName) |
|
183 | .def_property("name", &Variable::name, &Variable::setName) | |
124 | .def_property("range", &Variable::range, &Variable::setRange) |
|
184 | .def_property("range", &Variable::range, &Variable::setRange) | |
125 |
.def_property("cacheRange", &Variable::cacheRange, &Variable::setCacheRange) |
|
185 | .def_property("cacheRange", &Variable::cacheRange, &Variable::setCacheRange) | |
|
186 | .def_property_readonly("nbPoints", &Variable::nbPoints) | |||
|
187 | .def_property_readonly("dataSeries", &Variable::dataSeries) | |||
|
188 | .def("__len__", [](Variable& variable) { | |||
|
189 | auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd); | |||
|
190 | return std::distance(rng.first,rng.second); | |||
|
191 | }) | |||
|
192 | .def("__iter__", [](Variable& variable) { | |||
|
193 | auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd); | |||
|
194 | return py::make_iterator(rng.first, rng.second); | |||
|
195 | }, py::keep_alive<0, 1>()) | |||
|
196 | .def("__getitem__", [](Variable& variable, int key) { | |||
|
197 | //insane and slow! | |||
|
198 | auto rng = variable.dataSeries()->xAxisRange(variable.range().m_TStart,variable.range().m_TEnd); | |||
|
199 | if(key<0) | |||
|
200 | return *(rng.second+key); | |||
|
201 | else | |||
|
202 | return *(rng.first+key); | |||
|
203 | }) | |||
|
204 | .def("__repr__",__repr__<Variable>); | |||
126 |
|
205 | |||
127 | py::implicitly_convertible<std::string, QString>(); |
|
206 | py::implicitly_convertible<std::string, QString>(); | |
128 |
|
207 | |||
129 | py::class_<TimeController>(m,"TimeController"); |
|
|||
130 |
|
208 | |||
131 | py::class_<SqpRange>(m,"SqpRange") |
|
209 | py::class_<SqpRange>(m,"SqpRange") | |
132 | .def("fromDateTime", &SqpRange::fromDateTime, py::return_value_policy::move) |
|
210 | .def("fromDateTime", &SqpRange::fromDateTime, py::return_value_policy::move) | |
133 | .def(py::init([](double start, double stop){return SqpRange{start, stop};})) |
|
211 | .def(py::init([](double start, double stop){return SqpRange{start, stop};})) | |
134 | .def("__repr__", [](const SqpRange& range){ |
|
212 | .def(py::init([](system_clock::time_point start, system_clock::time_point stop) | |
135 | QString repr = QString("SqpRange:\n Start date: %1\n Stop date: %2") |
|
213 | { | |
136 | .arg(DateUtils::dateTime(range.m_TStart).toString()) |
|
214 | double start_ = 0.001 * duration_cast<milliseconds>(start.time_since_epoch()).count(); | |
137 | .arg(DateUtils::dateTime(range.m_TEnd).toString()); |
|
215 | double stop_ = 0.001 * duration_cast<milliseconds>(stop.time_since_epoch()).count(); | |
138 | return repr.toStdString(); |
|
216 | return SqpRange{start_, stop_}; | |
139 | }); |
|
217 | })) | |
|
218 | .def_property_readonly("start", [](const SqpRange& range){ | |||
|
219 | return system_clock::from_time_t(range.m_TStart); | |||
|
220 | }) | |||
|
221 | .def_property_readonly("stop", [](const SqpRange& range){ | |||
|
222 | return system_clock::from_time_t(range.m_TEnd); | |||
|
223 | }) | |||
|
224 | .def("__repr__", __repr__<SqpRange>); | |||
140 |
|
225 | |||
141 | py::class_<QUuid>(m,"QUuid"); |
|
226 | py::class_<QUuid>(m,"QUuid"); | |
142 |
|
227 | |||
143 | py::class_<QDate>(m,"QDate") |
|
228 | py::class_<QDate>(m,"QDate") | |
144 | .def(py::init<int,int,int>()); |
|
229 | .def(py::init<int,int,int>()); | |
145 |
|
230 | |||
146 | py::class_<QTime>(m,"QTime") |
|
231 | py::class_<QTime>(m,"QTime") | |
147 | .def(py::init<int,int,int>()); |
|
232 | .def(py::init<int,int,int>()); | |
148 |
|
233 | |||
149 | } |
|
234 | } | |
150 |
|
235 | |||
151 |
|
236 | |||
152 |
int pytestamda_test( |
|
237 | int pytestamda_test(const char* testScriptPath ) | |
153 | { |
|
238 | { | |
154 | SqpApplication::setOrganizationName("LPP"); |
|
|||
155 | SqpApplication::setOrganizationDomain("lpp.fr"); |
|
|||
156 | SqpApplication::setApplicationName("SciQLop"); |
|
|||
157 | SqpApplication app(argc, argv); |
|
|||
158 | py::scoped_interpreter guard{}; |
|
239 | py::scoped_interpreter guard{}; | |
159 |
|
||||
160 | py::globals()["__file__"] = py::str(testScriptPath); |
|
240 | py::globals()["__file__"] = py::str(testScriptPath); | |
161 | py::eval_file(testScriptPath); |
|
241 | py::eval_file(testScriptPath); | |
162 | return 0; |
|
242 | return 0; | |
163 | } |
|
243 | } | |
164 |
|
244 |
@@ -1,33 +1,33 | |||||
1 | /*------------------------------------------------------------------------------ |
|
1 | /*------------------------------------------------------------------------------ | |
2 | -- This file is a part of the SciQLOP Software |
|
2 | -- This file is a part of the SciQLOP Software | |
3 | -- Copyright (C) 2018, Plasma Physics Laboratory - CNRS |
|
3 | -- Copyright (C) 2018, Plasma Physics Laboratory - CNRS | |
4 | -- |
|
4 | -- | |
5 | -- This program is free software; you can redistribute it and/or modify |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
6 | -- it under the terms of the GNU General Public License as published by |
|
6 | -- it under the terms of the GNU General Public License as published by | |
7 | -- the Free Software Foundation; either version 2 of the License, or |
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |
8 | -- (at your option) any later version. |
|
8 | -- (at your option) any later version. | |
9 | -- |
|
9 | -- | |
10 | -- This program is distributed in the hope that it will be useful, |
|
10 | -- This program is distributed in the hope that it will be useful, | |
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | -- GNU General Public License for more details. |
|
13 | -- GNU General Public License for more details. | |
14 | -- |
|
14 | -- | |
15 | -- You should have received a copy of the GNU General Public License |
|
15 | -- You should have received a copy of the GNU General Public License | |
16 | -- along with this program; if not, write to the Free Software |
|
16 | -- along with this program; if not, write to the Free Software | |
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | -------------------------------------------------------------------------------*/ |
|
18 | -------------------------------------------------------------------------------*/ | |
19 | /*-- Author : Alexis Jeandet |
|
19 | /*-- Author : Alexis Jeandet | |
20 | -- Mail : alexis.jeandet@member.fsf.org |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
21 | ----------------------------------------------------------------------------*/ |
|
21 | ----------------------------------------------------------------------------*/ | |
22 | #include <QString> |
|
22 | #include <QString> | |
23 |
extern int pytestamda_test( |
|
23 | extern int pytestamda_test(const char* testScriptPath ); | |
24 |
|
24 | |||
25 | int main(int argc, char** argv) |
|
25 | int main(int argc, char** argv) | |
26 | { |
|
26 | { | |
27 |
pytestamda_test( |
|
27 | pytestamda_test(PYTESTAMDA_SCRIPT); | |
28 | return 0; |
|
28 | return 0; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 |
|
31 | |||
32 |
|
32 | |||
33 |
|
33 |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now