mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-08 08:36:16 +00:00
This is a very timid start at making us actually use multiple sensors without the magical special case for just CCR oxygen tracking. It mainly does: - turn the "sample->sensor" index into an array of two indexes, to match the pressures themselves. - get rid of dive->{oxygen_cylinder_index,diluent_cylinder_index}, since a CCR dive should now simply set the sample->sensor[] indices correctly instead. - in a couple of places, start actually looping over the sensors rather than special-case the O2 case (although often the small "loops" are just unrolled, since it's just two cases. but in many cases we still end up only covering the zero sensor case, because the CCR O2 sensor code coverage was fairly limited. It's entirely possible (even likely) that this migth break some existing case: it tries to be a fairly direct ("stupid") translation of the old code, but unlike the preparatory patch this does actually does change some semantics. For example, right now the git loader code assumes that if the git save data contains a o2pressure entry, it just hardcodes the O2 sensor index to 1. In fact, one issue is going to simply be that our file formats do not have that multiple sensor format, but instead had very clearly encoded things as being the CCR O2 pressure sensor. But this is hopefully close to usable, and I will need feedback (and maybe test cases) from people who have existing CCR dives with pressure data. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
128 lines
3.9 KiB
C++
128 lines
3.9 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "profile-widget/tankitem.h"
|
|
#include "qt-models/diveplotdatamodel.h"
|
|
#include "profile-widget/divetextitem.h"
|
|
#include "core/profile.h"
|
|
#include <QPen>
|
|
|
|
TankItem::TankItem(QObject *parent) :
|
|
QObject(parent),
|
|
QGraphicsRectItem(),
|
|
dataModel(0),
|
|
pInfoEntry(0),
|
|
pInfoNr(0)
|
|
{
|
|
height = 3;
|
|
QColor red(PERSIANRED1);
|
|
QColor blue(AIR_BLUE);
|
|
QColor yellow(NITROX_YELLOW);
|
|
QColor green(NITROX_GREEN);
|
|
QLinearGradient nitroxGradient(QPointF(0, 0), QPointF(0, height));
|
|
nitroxGradient.setColorAt(0.0, green);
|
|
nitroxGradient.setColorAt(0.49, green);
|
|
nitroxGradient.setColorAt(0.5, yellow);
|
|
nitroxGradient.setColorAt(1.0, yellow);
|
|
nitrox = nitroxGradient;
|
|
oxygen = green;
|
|
QLinearGradient trimixGradient(QPointF(0, 0), QPointF(0, height));
|
|
trimixGradient.setColorAt(0.0, green);
|
|
trimixGradient.setColorAt(0.49, green);
|
|
trimixGradient.setColorAt(0.5, red);
|
|
trimixGradient.setColorAt(1.0, red);
|
|
trimix = trimixGradient;
|
|
air = blue;
|
|
memset(&diveCylinderStore, 0, sizeof(diveCylinderStore));
|
|
}
|
|
|
|
TankItem::~TankItem()
|
|
{
|
|
// Should this be clear_dive(diveCylinderStore)?
|
|
for (int i = 0; i < MAX_CYLINDERS; i++)
|
|
free((void *)diveCylinderStore.cylinder[i].type.description);
|
|
}
|
|
|
|
void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d)
|
|
{
|
|
free(pInfoEntry);
|
|
// the plotInfo and dive structures passed in could become invalid before we stop using them,
|
|
// so copy the data that we need
|
|
int size = plotInfo->nr * sizeof(plotInfo->entry[0]);
|
|
pInfoEntry = (struct plot_data *)malloc(size);
|
|
pInfoNr = plotInfo->nr;
|
|
memcpy(pInfoEntry, plotInfo->entry, size);
|
|
copy_cylinders(d, &diveCylinderStore, false);
|
|
dataModel = model;
|
|
connect(dataModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection);
|
|
modelDataChanged();
|
|
}
|
|
|
|
void TankItem::createBar(qreal x, qreal w, struct gasmix *gas)
|
|
{
|
|
// pick the right gradient, size, position and text
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this);
|
|
if (gasmix_is_air(gas))
|
|
rect->setBrush(air);
|
|
else if (gas->he.permille)
|
|
rect->setBrush(trimix);
|
|
else if (gas->o2.permille == 1000)
|
|
rect->setBrush(oxygen);
|
|
else
|
|
rect->setBrush(nitrox);
|
|
rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle
|
|
rects.push_back(rect);
|
|
DiveTextItem *label = new DiveTextItem(rect);
|
|
label->setText(gasname(gas));
|
|
label->setBrush(Qt::black);
|
|
label->setPos(x + 1, 0);
|
|
label->setAlignment(Qt::AlignBottom | Qt::AlignRight);
|
|
#ifdef SUBSURFACE_MOBILE
|
|
label->setPos(x + 1, -2.5);
|
|
#endif
|
|
label->setZValue(101);
|
|
}
|
|
|
|
void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
|
|
{
|
|
Q_UNUSED(topLeft);
|
|
Q_UNUSED(bottomRight);
|
|
// We don't have enougth data to calculate things, quit.
|
|
if (!dataModel || !pInfoEntry || !pInfoNr)
|
|
return;
|
|
|
|
// remove the old rectangles
|
|
foreach (QGraphicsRectItem *r, rects) {
|
|
delete(r);
|
|
}
|
|
rects.clear();
|
|
|
|
// walk the list and figure out which tanks go where
|
|
struct plot_data *entry = pInfoEntry;
|
|
struct plot_data *lastentry = pInfoEntry;
|
|
int cylIdx = entry->sensor[0];
|
|
int i = -1;
|
|
int startTime = 0;
|
|
struct gasmix *gas = &diveCylinderStore.cylinder[cylIdx].gasmix;
|
|
qreal width, left;
|
|
while (++i < pInfoNr) {
|
|
entry = &pInfoEntry[i];
|
|
lastentry = &pInfoEntry[i-1];
|
|
if (entry->sensor[0] == cylIdx)
|
|
continue;
|
|
width = hAxis->posAtValue(lastentry->sec) - hAxis->posAtValue(startTime);
|
|
left = hAxis->posAtValue(startTime);
|
|
createBar(left, width, gas);
|
|
cylIdx = entry->sensor[0];
|
|
gas = &diveCylinderStore.cylinder[cylIdx].gasmix;
|
|
startTime = lastentry->sec;
|
|
}
|
|
width = hAxis->posAtValue(entry->sec) - hAxis->posAtValue(startTime);
|
|
left = hAxis->posAtValue(startTime);
|
|
createBar(left, width, gas);
|
|
}
|
|
|
|
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
|
|
{
|
|
hAxis = horizontal;
|
|
connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged()));
|
|
modelDataChanged();
|
|
}
|