##// END OF EJS Templates
Merge pull request 172 from SCIQLOP-Initialisation develop...
leroux -
r321:b1c50789867a merge
parent child
Show More
@@ -17,12 +17,12 struct SqpDateTime {
17 /// End time
17 /// End time
18 double m_TEnd;
18 double m_TEnd;
19
19
20 bool contains(const SqpDateTime &dateTime)
20 bool contains(const SqpDateTime &dateTime) const noexcept
21 {
21 {
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
23 }
23 }
24
24
25 bool intersect(const SqpDateTime &dateTime)
25 bool intersect(const SqpDateTime &dateTime) const noexcept
26 {
26 {
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
28 }
28 }
@@ -34,8 +34,9 public:
34 /// @return the data of the variable, nullptr if there is no data
34 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
35 IDataSeries *dataSeries() const noexcept;
36
36
37 bool contains(const SqpDateTime &dateTime);
37 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
39
40
40 public slots:
41 public slots:
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
@@ -25,12 +25,10 public:
25 * Creates a new variable in the model
25 * Creates a new variable in the model
26 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 * @return the pointer to the new variable
28 * @return the pointer to the new variable
30 */
29 */
31 std::shared_ptr<Variable>
30 std::shared_ptr<Variable> createVariable(const QString &name,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
31 const SqpDateTime &dateTime) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34
32
35 std::shared_ptr<Variable> variable(int index) const;
33 std::shared_ptr<Variable> variable(int index) const;
36
34
@@ -78,12 +78,17 IDataSeries *Variable::dataSeries() const noexcept
78 return impl->m_DataSeries.get();
78 return impl->m_DataSeries.get();
79 }
79 }
80
80
81 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
82 {
82 {
83 return impl->m_DateTime.contains(dateTime);
83 return impl->m_DateTime.contains(dateTime);
84 }
84 }
85
85
86 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
87 {
87 {
88 return impl->m_DateTime.intersect(dateTime);
88 return impl->m_DateTime.intersect(dateTime);
89 }
89 }
90
91 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
92 {
93 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
94 }
@@ -55,7 +55,7 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
56 }
56 }
57 catch (const std::out_of_range &e) {
57 catch (const std::out_of_range &e) {
58 qCWarning(LOG_VariableCacheController()) << e.what();
58 qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what();
59 }
59 }
60 }
60 }
61 }
61 }
@@ -71,13 +71,12 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable>
71 // list of date time request associated to the variable
71 // list of date time request associated to the variable
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
74
74 auto it = impl->m_VariableToSqpDateTimeListMap.find(variable);
75 try {
75 if (it != impl->m_VariableToSqpDateTimeListMap.end()) {
76 impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
76 impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart);
77 notInCache, 0, dateTime.m_TStart);
78 }
77 }
79 catch (const std::out_of_range &e) {
78 else {
80 qCWarning(LOG_VariableCacheController()) << e.what();
79 notInCache << dateTime;
81 }
80 }
82
81
83 return notInCache;
82 return notInCache;
@@ -99,17 +99,21 void VariableController::createVariable(const QString &name,
99 /// - default data are generated for the variable, without taking into account the timerange set
99 /// - default data are generated for the variable, without taking into account the timerange set
100 /// in sciqlop
100 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
102 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
104
103
105 // store the provider
104 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
105 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
108 &Variable::setDataSeries);
109
106
107 auto addDateTimeAcquired
108 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
110
109
111 // store in cache
110 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
111 newVariable->setDataSeries(dataSeriesAcquired);
112
113 };
114
115 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
116 this->onRequestDataLoading(newVariable, dateTime);
113
117
114 // notify the creation
118 // notify the creation
115 emit variableCreated(newVariable);
119 emit variableCreated(newVariable);
@@ -144,8 +148,6 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
144 // Ask the provider for each data on the dateTimeListNotInCache
148 // Ask the provider for each data on the dateTimeListNotInCache
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
149 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 std::move(dateTimeListNotInCache));
150 std::move(dateTimeListNotInCache));
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 }
151 }
150 else {
152 else {
151 emit variable->updated();
153 emit variable->updated();
@@ -52,9 +52,8 VariableModel::VariableModel(QObject *parent)
52 {
52 {
53 }
53 }
54
54
55 std::shared_ptr<Variable>
55 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
56 const SqpDateTime &dateTime) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 {
57 {
59 auto insertIndex = rowCount();
58 auto insertIndex = rowCount();
60 beginInsertRows({}, insertIndex, insertIndex);
59 beginInsertRows({}, insertIndex, insertIndex);
@@ -62,7 +61,6 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
62 /// @todo For the moment, the other data of the variable is initialized with default values
61 /// @todo For the moment, the other data of the variable is initialized with default values
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
62 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 QStringLiteral("mission"), dateTime);
63 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
66
64
67 impl->m_Variables.push_back(variable);
65 impl->m_Variables.push_back(variable);
68
66
@@ -28,6 +28,7 public:
28 virtual ~VisualizationGraphWidget();
28 virtual ~VisualizationGraphWidget();
29
29
30 void addVariable(std::shared_ptr<Variable> variable);
30 void addVariable(std::shared_ptr<Variable> variable);
31 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
31 /// Removes a variable from the graph
32 /// Removes a variable from the graph
32 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
33 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
33
34
@@ -52,7 +53,7 private slots:
52 /// Slot called when right clicking on the graph (displays a menu)
53 /// Slot called when right clicking on the graph (displays a menu)
53 void onGraphMenuRequested(const QPoint &pos) noexcept;
54 void onGraphMenuRequested(const QPoint &pos) noexcept;
54
55
55 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
56 void onRangeChanged(const QCPRange &t1);
56
57
57 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
58 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
58 void onMouseWheel(QWheelEvent *event) noexcept;
59 void onMouseWheel(QWheelEvent *event) noexcept;
@@ -42,7 +42,6 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
42 const auto &valuesData = scalarSeries.valuesData()->data();
42 const auto &valuesData = scalarSeries.valuesData()->data();
43 const auto count = xData.count();
43 const auto count = xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
46 auto xValue = QVector<double>(count);
45 auto xValue = QVector<double>(count);
47 auto vValue = QVector<double>(count);
46 auto vValue = QVector<double>(count);
48
47
@@ -63,6 +62,10 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
63 << xValue.count();
62 << xValue.count();
64
63
65 qcpGraph->setData(xValue, vValue);
64 qcpGraph->setData(xValue, vValue);
65
66 // Display all data
67 component->rescaleAxes();
68 component->parentPlot()->replot();
66 }
69 }
67 else {
70 else {
68 /// @todo DEBUG
71 /// @todo DEBUG
@@ -97,7 +100,6 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QC
97
100
98 // Display all data
101 // Display all data
99 component->rescaleAxes();
102 component->rescaleAxes();
100
101 plot.replot();
103 plot.replot();
102 }
104 }
103 else {
105 else {
@@ -49,9 +49,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
52 connect(ui->widget->xAxis,
53 &QCPAxis::rangeChanged),
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
54 this, &VisualizationGraphWidget::onRangeChanged);
54 &VisualizationGraphWidget::onRangeChanged);
55
55
56 // Activates menu when right clicking on the graph
56 // Activates menu when right clicking on the graph
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -80,6 +80,34 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
81 }
81 }
82
82
83 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
84 {
85
86 // when adding a variable, we need to set its time range to the current graph range
87 auto grapheRange = ui->widget->xAxis->range();
88 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
89 variable->setDateTime(dateTime);
90
91 auto variableDateTimeWithTolerance = dateTime;
92
93 // add 10% tolerance for each side
94 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
95 variableDateTimeWithTolerance.m_TStart -= tolerance;
96 variableDateTimeWithTolerance.m_TEnd += tolerance;
97
98 // Uses delegate to create the qcpplot components according to the variable
99 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
100
101 for (auto createdPlottable : qAsConst(createdPlottables)) {
102 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
103 }
104
105 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
106
107 // CHangement detected, we need to ask controller to request data loading
108 emit requestDataLoading(variable, variableDateTimeWithTolerance);
109 }
110
83 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
111 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
84 {
112 {
85 // Each component associated to the variable :
113 // Each component associated to the variable :
@@ -136,23 +164,23 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
136 }
164 }
137 }
165 }
138
166
139 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
167 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
140 {
168 {
141
142 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
169 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
143
170
144 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
171 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
145 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
172 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
146
173
147 auto variable = it->first;
174 auto variable = it->first;
148 auto dateTime = SqpDateTime{t2.lower, t2.upper};
175 auto dateTime = SqpDateTime{t1.lower, t1.upper};
149
176
150 if (!variable->contains(dateTime)) {
177 if (!variable->contains(dateTime)) {
151
178
152 auto variableDateTimeWithTolerance = dateTime;
179 auto variableDateTimeWithTolerance = dateTime;
153 if (variable->intersect(dateTime)) {
180 if (!variable->isInside(dateTime)) {
154 auto variableDateTime = variable->dateTime();
181 auto variableDateTime = variable->dateTime();
155 if (variableDateTime.m_TStart < dateTime.m_TStart) {
182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
183 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
156
184
157 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
185 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
158 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
186 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
@@ -161,7 +189,8 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
161 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
189 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
162 variableDateTimeWithTolerance.m_TEnd += tolerance;
190 variableDateTimeWithTolerance.m_TEnd += tolerance;
163 }
191 }
164 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
192 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
193 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
165 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
194 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
166 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
195 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
167 // Tolerance have to be added to the left
196 // Tolerance have to be added to the left
@@ -169,8 +198,13 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
169 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
198 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
170 variableDateTimeWithTolerance.m_TStart -= tolerance;
199 variableDateTimeWithTolerance.m_TStart -= tolerance;
171 }
200 }
201 else {
202 qCWarning(LOG_VisualizationGraphWidget())
203 << tr("Detection anormal zoom detection: ");
204 }
172 }
205 }
173 else {
206 else {
207 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
174 // add 10% tolerance for each side
208 // add 10% tolerance for each side
175 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
209 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
176 variableDateTimeWithTolerance.m_TStart -= tolerance;
210 variableDateTimeWithTolerance.m_TStart -= tolerance;
@@ -181,6 +215,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
181 // CHangement detected, we need to ask controller to request data loading
215 // CHangement detected, we need to ask controller to request data loading
182 emit requestDataLoading(variable, variableDateTimeWithTolerance);
216 emit requestDataLoading(variable, variableDateTimeWithTolerance);
183 }
217 }
218 else {
219 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
220 }
184 }
221 }
185 }
222 }
186
223
@@ -137,7 +137,7 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
137 if (graphWidget) {
137 if (graphWidget) {
138 impl->visitLeaf(
138 impl->visitLeaf(
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
141 }
141 }
142 else {
142 else {
143 qCCritical(LOG_GenerateVariableMenuOperation(),
143 qCCritical(LOG_GenerateVariableMenuOperation(),
General Comments 0
You need to be logged in to leave comments. Login now