##// END OF EJS Templates
Add correction for delta T
perrinel -
r263:dbae8a89423a
parent child
Show More
@@ -1,82 +1,74
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the QLop Software
3 3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 ----------------------------------------------------------------------------*/
22 22 #include "MainWindow.h"
23 23 #include <QProcessEnvironment>
24 24 #include <QThread>
25 25 #include <SqpApplication.h>
26 26 #include <qglobal.h>
27 27
28 28 #include <Plugin/PluginManager.h>
29 29 #include <QDir>
30 30
31 31 namespace {
32 32
33 33 /// Name of the directory containing the plugins
34 34
35 35 #if _WIN32 || _WIN64
36 36 const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins");
37 37 #endif
38 38
39
40 #if __GNUC__
41 #if __x86_64__ || __ppc64__
42 #define ENVIRONMENT64
43 #else
44 #define ENVIRONMENT32
45 #endif
46 #endif
47 39 } // namespace
48 40
49 41 int main(int argc, char *argv[])
50 42 {
51 43 SqpApplication a{argc, argv};
52 44 SqpApplication::setOrganizationName("LPP");
53 45 SqpApplication::setOrganizationDomain("lpp.fr");
54 46 SqpApplication::setApplicationName("SciQLop");
55 47 MainWindow w;
56 48 w.show();
57 49
58 50 // Loads plugins
59 51 auto pluginDir = QDir{sqpApp->applicationDirPath()};
60 52 #if _WIN32 || _WIN64
61 53 pluginDir.mkdir(PLUGIN_DIRECTORY_NAME);
62 54 pluginDir.cd(PLUGIN_DIRECTORY_NAME);
63 55 #endif
64 56
65 57
66 58 #if __GNUC__
67 59 #if __x86_64__ || __ppc64__
68 60 if (!pluginDir.cd("../lib64/SciQlop")) {
69 61 pluginDir.cd("../lib64/sciqlop");
70 62 }
71 63 #else
72 64 __x86_64__ || __ppc64__ if (!pluginDir.cd("../lib/SciQlop")) { pluginDir.cd("../lib/sciqlop"); }
73 #endif
65 #endif
74 66 #endif
75 67 qCDebug(LOG_PluginManager())
76 68 << QObject::tr("Plugin directory: %1").arg(pluginDir.absolutePath());
77 69
78 70 PluginManager pluginManager{};
79 71 pluginManager.loadPlugins(pluginDir);
80 72
81 73 return a.exec();
82 74 }
@@ -1,205 +1,208
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationGraphHelper.h"
4 4 #include "ui_VisualizationGraphWidget.h"
5 5
6 6 #include <Data/ArrayData.h>
7 7 #include <Data/IDataSeries.h>
8 8 #include <SqpApplication.h>
9 9 #include <Variable/Variable.h>
10 10 #include <Variable/VariableController.h>
11 11
12 12 #include <unordered_map>
13 13
14 14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15 15
16 16 namespace {
17 17
18 18 /// Key pressed to enable zoom on horizontal axis
19 19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
20 20
21 21 /// Key pressed to enable zoom on vertical axis
22 22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
23 23
24 24 } // namespace
25 25
26 26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
27 27
28 28 // 1 variable -> n qcpplot
29 29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 30 m_VariableToPlotMultiMap;
31 31 };
32 32
33 33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
34 34 : QWidget{parent},
35 35 ui{new Ui::VisualizationGraphWidget},
36 36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
37 37 {
38 38 ui->setupUi(this);
39 39
40 40 // qcpplot title
41 41 ui->widget->plotLayout()->insertRow(0);
42 42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
43 43
44 44 // Set qcpplot properties :
45 45 // - Drag (on x-axis) and zoom are enabled
46 46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
47 47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
48 48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
49 49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
50 50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
51 51 &QCPAxis::rangeChanged),
52 52 this, &VisualizationGraphWidget::onRangeChanged);
53 53 }
54 54
55 55
56 56 VisualizationGraphWidget::~VisualizationGraphWidget()
57 57 {
58 58 delete ui;
59 59 }
60 60
61 61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
62 62 {
63 63 // Uses delegate to create the qcpplot components according to the variable
64 64 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
65 65
66 66 for (auto createdPlottable : qAsConst(createdPlottables)) {
67 67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
68 68 }
69 69
70 70 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
71 71 }
72 72
73 73 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
74 74 {
75 75 if (visitor) {
76 76 visitor->visit(this);
77 77 }
78 78 else {
79 79 qCCritical(LOG_VisualizationGraphWidget())
80 80 << tr("Can't visit widget : the visitor is null");
81 81 }
82 82 }
83 83
84 84 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
85 85 {
86 86 /// @todo : for the moment, a graph can always accomodate a variable
87 87 Q_UNUSED(variable);
88 88 return true;
89 89 }
90 90
91 91 void VisualizationGraphWidget::close()
92 92 {
93 93 // The main view cannot be directly closed.
94 94 return;
95 95 }
96 96
97 97 QString VisualizationGraphWidget::name() const
98 98 {
99 99 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
100 100 return title->text();
101 101 }
102 102 else {
103 103 return QString{};
104 104 }
105 105 }
106 106
107 107 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
108 108 {
109 109
110 110 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
111 111
112 112 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
113 113 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
114 114
115 115 auto variable = it->first;
116 116 qCInfo(LOG_VisualizationGraphWidget())
117 117 << tr("TORM: VisualizationGraphWidget::onRangeChanged")
118 118 << variable->dataSeries()->xAxisData()->size();
119 119 auto dateTime = SqpDateTime{t2.lower, t2.upper};
120 120
121 121 if (!variable->contains(dateTime)) {
122 122
123 123 auto variableDateTimeWithTolerance = dateTime;
124 124 if (variable->intersect(dateTime)) {
125 125 auto variableDateTime = variable->dateTime();
126 126 if (variableDateTime.m_TStart < dateTime.m_TStart) {
127 dateTime.m_TStart = variableDateTime.m_TStart;
128 // START is set to the old one. tolerance have to be added to the right
127
128 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
129 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
130 // Tolerance have to be added to the right
129 131 // add 10% tolerance for right (end) side
130 132 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
131 133 variableDateTimeWithTolerance.m_TEnd += tolerance;
132 134 }
133 135 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
134 dateTime.m_TEnd = variableDateTime.m_TEnd;
135 // END is set to the old one. tolerance have to be added to the left
136 auto diffStartToKeepDelta = dateTime.m_TStart - dateTime.m_TStart;
137 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
138 // Tolerance have to be added to the left
136 139 // add 10% tolerance for left (start) side
137 140 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
138 141 variableDateTimeWithTolerance.m_TStart -= tolerance;
139 142 }
140 143 }
141 144 else {
142 145 // add 10% tolerance for each side
143 146 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
144 147 variableDateTimeWithTolerance.m_TStart -= tolerance;
145 148 variableDateTimeWithTolerance.m_TEnd += tolerance;
146 149 }
147 150 variable->setDateTime(dateTime);
148 151
149 152 // CHangement detected, we need to ask controller to request data loading
150 153 sqpApp->variableController().requestDataLoading(variable,
151 154 variableDateTimeWithTolerance);
152 155 }
153 156 }
154 157 }
155 158
156 159 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
157 160 {
158 161 auto zoomOrientations = QFlags<Qt::Orientation>{};
159 162
160 163 // Lambda that enables a zoom orientation if the key modifier related to this orientation
161 164 // has
162 165 // been pressed
163 166 auto enableOrientation
164 167 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
165 168 auto orientationEnabled = event->modifiers().testFlag(modifier);
166 169 zoomOrientations.setFlag(orientation, orientationEnabled);
167 170 };
168 171 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
169 172 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
170 173
171 174 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
172 175 }
173 176
174 177 void VisualizationGraphWidget::onDataCacheVariableUpdated()
175 178 {
176 179 // NOTE:
177 180 // We don't want to call the method for each component of a variable unitarily, but for
178 181 // all
179 182 // its components at once (eg its three components in the case of a vector).
180 183
181 184 // The unordered_multimap does not do this easily, so the question is whether to:
182 185 // - use an ordered_multimap and the algos of std to group the values by key
183 186 // - use a map (unique keys) and store as values directly the list of components
184 187
185 188 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
186 189 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
187 190 auto variable = it->first;
188 191 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
189 192 variable->dataSeries(), variable->dateTime());
190 193 }
191 194 }
192 195
193 196 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
194 197 {
195 198 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
196 199
197 200 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
198 201
199 202 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
200 203 abstractPlotableVect.push_back(it->second);
201 204 }
202 205
203 206 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
204 207 variable->dateTime());
205 208 }
General Comments 0
You need to be logged in to leave comments. Login now