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 bottomsac; /* ml/min */
|
||||
int decosac; /* ml/min */
|
||||
short gflow;
|
||||
short gfhigh;
|
||||
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);
|
||||
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
|
||||
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);
|
||||
|
||||
|
|
|
@ -605,7 +605,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, c
|
|||
int gaschangenr;
|
||||
int *stoplevels;
|
||||
|
||||
set_gf(plangflow, plangfhigh);
|
||||
set_gf(diveplan->gflow, diveplan->gfhigh);
|
||||
if (!diveplan->surface_pressure)
|
||||
diveplan->surface_pressure = SURFACE_PRESSURE;
|
||||
if (*divep)
|
||||
|
|
|
@ -30,7 +30,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
|||
|
||||
depthLine = new Ruler();
|
||||
depthLine->setMinimum(0);
|
||||
depthLine->setMaximum(10);
|
||||
depthLine->setMaximum(100);
|
||||
depthLine->setTickInterval(10);
|
||||
depthLine->setLine(10, 1, 10, 90);
|
||||
depthLine->setOrientation(Qt::Vertical);
|
||||
|
@ -125,10 +125,13 @@ void DivePlannerGraphics::createDecoStops()
|
|||
// Get the user-input and calculate the dive info
|
||||
// Not sure if this is the place to create the diveplan...
|
||||
// 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);
|
||||
dp->entered = TRUE;
|
||||
plan.dp = dp;
|
||||
diveplan.dp = dp;
|
||||
diveplan.gflow = 30;
|
||||
diveplan.gfhigh = 70;
|
||||
diveplan.surface_pressure = 1013;
|
||||
DiveHandler *lastH = NULL;
|
||||
Q_FOREACH(DiveHandler *h, handles) {
|
||||
// these values need to come from the planner UI, eventually
|
||||
|
@ -137,21 +140,30 @@ void DivePlannerGraphics::createDecoStops()
|
|||
int po2 = 0;
|
||||
int deltaT = lastH ? h->sec - lastH->sec : h->sec;
|
||||
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);
|
||||
}
|
||||
#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
|
||||
|
||||
// create the dive info here.
|
||||
|
||||
// set the new 'end time' of the dive.
|
||||
// note that this is not the user end,
|
||||
// but the real end of the dive.
|
||||
timeLine->setMaximum(60);
|
||||
timeLine->updateTicks();
|
||||
|
||||
while(dp->next)
|
||||
dp = dp->next;
|
||||
if (timeLine->maximum() < dp->time / 60.0 + 5) {
|
||||
// this causes all kinds of bad things as the
|
||||
// handle that you are holding on to gets scaled out
|
||||
// when we change the maximum and things accelerate from there
|
||||
// BAD
|
||||
//
|
||||
// timeLine->setMaximum(dp->time / 60.0 + 5);
|
||||
}
|
||||
// Re-position the user generated dive handlers
|
||||
Q_FOREACH(DiveHandler *h, handles) {
|
||||
// uncomment this as soon as the posAtValue is implemented.
|
||||
|
@ -159,13 +171,22 @@ void DivePlannerGraphics::createDecoStops()
|
|||
// depthLine->posAtValue(h->depth));
|
||||
}
|
||||
|
||||
// Create all 'deco' GraphicsLineItems and put it on the canvas.This following three lines will
|
||||
// most probably need to enter on a loop.
|
||||
double xpos = timeLine->posAtValue(timeLine->maximum());
|
||||
double ypos = depthLine->posAtValue(depthLine->minimum());
|
||||
QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), xpos, ypos);
|
||||
scene()->addItem(item);
|
||||
lines << item;
|
||||
// Create all 'deco' GraphicsLineItems and put it on the canvas.
|
||||
double lastx = handles.last()->x();
|
||||
double lasty = handles.last()->y();
|
||||
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
|
||||
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);
|
||||
lines << item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
|
||||
|
|
Loading…
Add table
Reference in a new issue