diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-04 18:44:57 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-09 19:19:04 +0100 |
commit | 7c9f46acd202121e67557bb634961ef17a9f6c1f (patch) | |
tree | f21b6ff42a930cc97c31db9f20c03f1613e70291 /profile-widget | |
parent | cd4f66014f7b5269dff9e088c9d7d38241c03156 (diff) | |
download | subsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz |
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.
Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.
One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r-- | profile-widget/diveprofileitem.cpp | 26 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 6 | ||||
-rw-r--r-- | profile-widget/tankitem.cpp | 2 |
3 files changed, 17 insertions, 17 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index bc74f7f40..3d0ba2e7a 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -659,17 +659,17 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo if (!shouldCalculateStuff(topLeft, bottomRight)) return; - std::vector<int> plotted_cyl(MAX_CYLINDERS, false); - std::vector<int> last_plotted(MAX_CYLINDERS, 0); - std::vector<QPolygonF> poly(MAX_CYLINDERS); + const struct plot_info *pInfo = &dataModel->data(); + std::vector<int> plotted_cyl(pInfo->nr_cylinders, false); + std::vector<int> last_plotted(pInfo->nr_cylinders, 0); + std::vector<QPolygonF> poly(pInfo->nr_cylinders); QPolygonF boundingPoly; polygons.clear(); - const struct plot_info *pInfo = &dataModel->data(); for (int i = 0, count = dataModel->rowCount(); i < count; i++) { const struct plot_data *entry = pInfo->entry + i; - for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) { int mbar = get_plot_pressure(pInfo, i, cyl); int time = entry->sec; @@ -698,7 +698,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo } } - for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) { if (!plotted_cyl[cyl]) continue; polygons.append(poly[cyl]); @@ -708,9 +708,9 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo qDeleteAll(texts); texts.clear(); - std::vector<int> seen_cyl(MAX_CYLINDERS, false); - std::vector<int> last_pressure(MAX_CYLINDERS, 0); - std::vector<int> last_time(MAX_CYLINDERS, 0); + std::vector<int> seen_cyl(pInfo->nr_cylinders, false); + std::vector<int> last_pressure(pInfo->nr_cylinders, 0); + std::vector<int> last_time(pInfo->nr_cylinders, 0); // These are offset values used to print the gas lables and pressures on a // dive profile at appropriate Y-coordinates. We alternate aligning the @@ -721,7 +721,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo // pressures. QFlags<Qt::AlignmentFlag> alignVar = Qt::AlignTop; - std::vector<QFlags<Qt::AlignmentFlag>> align(MAX_CYLINDERS); + std::vector<QFlags<Qt::AlignmentFlag>> align(pInfo->nr_cylinders); double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar double axisLog = log10(log10(axisRange)); @@ -729,7 +729,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo for (int i = 0, count = dataModel->rowCount(); i < count; i++) { const struct plot_data *entry = pInfo->entry + i; - for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) { int mbar = get_plot_pressure(pInfo, i, cyl); if (!mbar) @@ -748,7 +748,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo label_y_offset = -7 * axisLog; } plotPressureValue(mbar, entry->sec, alignVar, value_y_offset); - plotGasValue(mbar, entry->sec, displayed_dive.cylinder[cyl].gasmix, alignVar, label_y_offset); + plotGasValue(mbar, entry->sec, displayed_dive.cylinders.cylinders[cyl].gasmix, alignVar, label_y_offset); seen_cyl[cyl] = true; /* Alternate alignment as we see cylinder use.. */ @@ -761,7 +761,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo } // For each cylinder, on right hand side of profile, write cylinder pressure - for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) { if (last_time[cyl]) { double value_y_offset = -0.5; plotPressureValue(last_pressure[cyl], last_time[cyl], align[cyl] | Qt::AlignLeft, value_y_offset); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index e065361d3..01cd733be 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1536,7 +1536,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) int newGasIdx = gasChangeIdx + 1; const struct plot_data &newGasEntry = plotInfo.entry[newGasIdx]; qDebug() << "after gas change at " << newGasEntry->sec << ": sensor pressure" << newGasEntry->pressure[0] << "interpolated" << newGasEntry->pressure[1]; - if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || displayed_dive.cylinder[gasChangeEntry->sensor[0]].sample_start.mbar == 0) { + if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || displayed_dive.cylinders.cylinders[gasChangeEntry->sensor[0]].sample_start.mbar == 0) { // if we have no sensorpressure or if we have no pressure from samples we can assume that // we only have interpolated pressure (the pressure in the entry may be stored in the sensor // pressure field if this is the first or last entry for this tank... see details in gaspressures.c @@ -1545,7 +1545,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)") .arg(gasChangeEntry->sensor[0] + 1).arg(get_pressure_string(pressure))); } - if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || displayed_dive.cylinder[newGasEntry->sensor[0]].sample_start.mbar == 0) { + if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || displayed_dive.cylinders.cylinders[newGasEntry->sensor[0]].sample_start.mbar == 0) { // we only have interpolated press -- see commend above pressure_t pressure; pressure.mbar = get_plot_interpolated_pressure(&plotInfo, newGasIdx) ? : get_plot_sensor_pressure(&plotInfo, newGasIdx); @@ -1882,7 +1882,7 @@ void ProfileWidget2::repositionDiveHandlers() QLineF line(p1, p2); QPointF pos = line.pointAt(0.5); gases[i]->setPos(pos); - gases[i]->setText(get_gas_string(displayed_dive.cylinder[datapoint.cylinderid].gasmix)); + gases[i]->setText(get_gas_string(displayed_dive.cylinders.cylinders[datapoint.cylinderid].gasmix)); gases[i]->setVisible(datapoint.entered && (i == 0 || gases[i]->text() != gases[i-1]->text())); } diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index f40baa357..8cd53b5d4 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -98,7 +98,7 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&) // start with the first gasmix and at the start of the dive int cyl = explicit_first_cylinder(&displayed_dive, dc); - struct gasmix gasmix = displayed_dive.cylinder[cyl].gasmix; + struct gasmix gasmix = displayed_dive.cylinders.cylinders[cyl].gasmix; int startTime = 0; // work through all the gas changes and add the rectangle for each gas while it was used |