mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Perform deco calculation for plan
This uses a bunch of default values that we eventually need to get from the UI, but it's a first step towards a working dive planner. This exhibits some graphical artifacts when running, but other than that appears to be mostly correct. Things go far worse if I enable the changing of the scale once the deco makes the dive longer than the displayed time window. Things quickly spiral out of control. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
596095389b
commit
ef0272f5ef
3 changed files with 45 additions and 21 deletions
3
dive.h
3
dive.h
|
@ -713,6 +713,8 @@ struct diveplan {
|
||||||
int surface_pressure; /* mbar */
|
int surface_pressure; /* mbar */
|
||||||
int bottomsac; /* ml/min */
|
int bottomsac; /* ml/min */
|
||||||
int decosac; /* ml/min */
|
int decosac; /* ml/min */
|
||||||
|
short gflow;
|
||||||
|
short gfhigh;
|
||||||
struct divedatapoint *dp;
|
struct divedatapoint *dp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -723,6 +725,7 @@ void free_dps(struct divedatapoint *dp);
|
||||||
void get_gas_string(int o2, int he, char *buf, int len);
|
void get_gas_string(int o2, int he, char *buf, int len);
|
||||||
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
|
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
|
||||||
void dump_plan(struct diveplan *diveplan);
|
void dump_plan(struct diveplan *diveplan);
|
||||||
|
void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, char **error_string_p);
|
||||||
|
|
||||||
struct event *get_next_event(struct event *event, char *name);
|
struct event *get_next_event(struct event *event, char *name);
|
||||||
|
|
||||||
|
|
|
@ -605,7 +605,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, c
|
||||||
int gaschangenr;
|
int gaschangenr;
|
||||||
int *stoplevels;
|
int *stoplevels;
|
||||||
|
|
||||||
set_gf(plangflow, plangfhigh);
|
set_gf(diveplan->gflow, diveplan->gfhigh);
|
||||||
if (!diveplan->surface_pressure)
|
if (!diveplan->surface_pressure)
|
||||||
diveplan->surface_pressure = SURFACE_PRESSURE;
|
diveplan->surface_pressure = SURFACE_PRESSURE;
|
||||||
if (*divep)
|
if (*divep)
|
||||||
|
|
|
@ -30,7 +30,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
|
|
||||||
depthLine = new Ruler();
|
depthLine = new Ruler();
|
||||||
depthLine->setMinimum(0);
|
depthLine->setMinimum(0);
|
||||||
depthLine->setMaximum(10);
|
depthLine->setMaximum(100);
|
||||||
depthLine->setTickInterval(10);
|
depthLine->setTickInterval(10);
|
||||||
depthLine->setLine(10, 1, 10, 90);
|
depthLine->setLine(10, 1, 10, 90);
|
||||||
depthLine->setOrientation(Qt::Vertical);
|
depthLine->setOrientation(Qt::Vertical);
|
||||||
|
@ -125,10 +125,13 @@ void DivePlannerGraphics::createDecoStops()
|
||||||
// Get the user-input and calculate the dive info
|
// Get the user-input and calculate the dive info
|
||||||
// Not sure if this is the place to create the diveplan...
|
// Not sure if this is the place to create the diveplan...
|
||||||
// We just start with a surface node at time = 0
|
// We just start with a surface node at time = 0
|
||||||
struct diveplan plan;
|
struct diveplan diveplan;
|
||||||
struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
|
struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
|
||||||
dp->entered = TRUE;
|
dp->entered = TRUE;
|
||||||
plan.dp = dp;
|
diveplan.dp = dp;
|
||||||
|
diveplan.gflow = 30;
|
||||||
|
diveplan.gfhigh = 70;
|
||||||
|
diveplan.surface_pressure = 1013;
|
||||||
DiveHandler *lastH = NULL;
|
DiveHandler *lastH = NULL;
|
||||||
Q_FOREACH(DiveHandler *h, handles) {
|
Q_FOREACH(DiveHandler *h, handles) {
|
||||||
// these values need to come from the planner UI, eventually
|
// these values need to come from the planner UI, eventually
|
||||||
|
@ -137,21 +140,30 @@ void DivePlannerGraphics::createDecoStops()
|
||||||
int po2 = 0;
|
int po2 = 0;
|
||||||
int deltaT = lastH ? h->sec - lastH->sec : h->sec;
|
int deltaT = lastH ? h->sec - lastH->sec : h->sec;
|
||||||
lastH = h;
|
lastH = h;
|
||||||
plan_add_segment(&plan, deltaT, h->mm, o2, he, po2);
|
plan_add_segment(&diveplan, deltaT, h->mm, o2, he, po2);
|
||||||
qDebug("time %d, depth %d", h->sec, h->mm);
|
qDebug("time %d, depth %d", h->sec, h->mm);
|
||||||
}
|
}
|
||||||
#if DEBUG_PLAN
|
#if DEBUG_PLAN
|
||||||
dump_plan(&plan);
|
dump_plan(&diveplan);
|
||||||
|
#endif
|
||||||
|
char *cache = NULL;
|
||||||
|
struct dive *dive = NULL;
|
||||||
|
char *errorString = NULL;
|
||||||
|
plan(&diveplan, &cache, &dive, &errorString);
|
||||||
|
#if DEBUG_PLAN
|
||||||
|
dump_plan(&diveplan);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// create the dive info here.
|
while(dp->next)
|
||||||
|
dp = dp->next;
|
||||||
// set the new 'end time' of the dive.
|
if (timeLine->maximum() < dp->time / 60.0 + 5) {
|
||||||
// note that this is not the user end,
|
// this causes all kinds of bad things as the
|
||||||
// but the real end of the dive.
|
// handle that you are holding on to gets scaled out
|
||||||
timeLine->setMaximum(60);
|
// when we change the maximum and things accelerate from there
|
||||||
timeLine->updateTicks();
|
// BAD
|
||||||
|
//
|
||||||
|
// timeLine->setMaximum(dp->time / 60.0 + 5);
|
||||||
|
}
|
||||||
// Re-position the user generated dive handlers
|
// Re-position the user generated dive handlers
|
||||||
Q_FOREACH(DiveHandler *h, handles) {
|
Q_FOREACH(DiveHandler *h, handles) {
|
||||||
// uncomment this as soon as the posAtValue is implemented.
|
// uncomment this as soon as the posAtValue is implemented.
|
||||||
|
@ -159,14 +171,23 @@ void DivePlannerGraphics::createDecoStops()
|
||||||
// depthLine->posAtValue(h->depth));
|
// depthLine->posAtValue(h->depth));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create all 'deco' GraphicsLineItems and put it on the canvas.This following three lines will
|
// Create all 'deco' GraphicsLineItems and put it on the canvas.
|
||||||
// most probably need to enter on a loop.
|
double lastx = handles.last()->x();
|
||||||
double xpos = timeLine->posAtValue(timeLine->maximum());
|
double lasty = handles.last()->y();
|
||||||
double ypos = depthLine->posAtValue(depthLine->minimum());
|
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
|
||||||
QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), xpos, ypos);
|
if (!dp->entered) {
|
||||||
|
// these are the nodes created by the deco
|
||||||
|
double xpos = timeLine->posAtValue(dp->time / 60.0);
|
||||||
|
double ypos = depthLine->posAtValue(dp->depth / 1000.0);
|
||||||
|
qDebug("time/depth %f/%f", dp->time / 60.0, dp->depth / 1000.0);
|
||||||
|
QGraphicsLineItem *item = new QGraphicsLineItem(lastx, lasty, xpos, ypos);
|
||||||
|
lastx = xpos;
|
||||||
|
lasty = ypos;
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
lines << item;
|
lines << item;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
|
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue