mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Start hooking in the deco calculations
I expanded the DiveHandler to include the actual time / depth of each node on the graph - this way things will stay consistent if we need to rescale the graph. One thing that this makes obvious is that the whole design for the planner so far assumes metric data. We need to make sure this works well with feet instead of meters as well (and that it uses the information in the units settings). With this change we actually create a dive based on the plan input and add the deco stops (if needed) to it - but we don't do anything with the results of those calculations, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4a184a60fc
commit
596095389b
5 changed files with 40 additions and 9 deletions
1
Makefile
1
Makefile
|
@ -63,6 +63,7 @@ SOURCES = \
|
||||||
info.c \
|
info.c \
|
||||||
main.c \
|
main.c \
|
||||||
parse-xml.c \
|
parse-xml.c \
|
||||||
|
planner.c \
|
||||||
profile.c \
|
profile.c \
|
||||||
save-xml.c \
|
save-xml.c \
|
||||||
sha1.c \
|
sha1.c \
|
||||||
|
|
2
dive.h
2
dive.h
|
@ -721,6 +721,8 @@ void add_depth_to_nth_dp(struct diveplan *diveplan, int idx, int depth);
|
||||||
void add_gas_to_nth_dp(struct diveplan *diveplan, int idx, int o2, int he);
|
void add_gas_to_nth_dp(struct diveplan *diveplan, int idx, int o2, int he);
|
||||||
void free_dps(struct divedatapoint *dp);
|
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);
|
||||||
|
void dump_plan(struct diveplan *diveplan);
|
||||||
|
|
||||||
struct event *get_next_event(struct event *event, char *name);
|
struct event *get_next_event(struct event *event, char *name);
|
||||||
|
|
||||||
|
|
|
@ -495,6 +495,7 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
|
||||||
return stoplevels;
|
return stoplevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_GTK_UI
|
||||||
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
||||||
{
|
{
|
||||||
char buffer[20000];
|
char buffer[20000];
|
||||||
|
@ -590,6 +591,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
|
||||||
}
|
}
|
||||||
dive->notes = strdup(buffer);
|
dive->notes = strdup(buffer);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, char **error_string_p)
|
void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, char **error_string_p)
|
||||||
{
|
{
|
||||||
|
@ -698,8 +700,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, c
|
||||||
record_dive(dive);
|
record_dive(dive);
|
||||||
stopidx--;
|
stopidx--;
|
||||||
}
|
}
|
||||||
add_plan_to_notes(diveplan, dive);
|
|
||||||
#if USE_GTK_UI
|
#if USE_GTK_UI
|
||||||
|
add_plan_to_notes(diveplan, dive);
|
||||||
/* now make the dive visible in the dive list */
|
/* now make the dive visible in the dive list */
|
||||||
report_dives(FALSE, FALSE);
|
report_dives(FALSE, FALSE);
|
||||||
show_and_select_dive(dive);
|
show_and_select_dive(dive);
|
||||||
|
@ -709,6 +711,7 @@ error_exit:
|
||||||
free(gaschanges);
|
free(gaschanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USE_GTK_UI
|
||||||
/*
|
/*
|
||||||
* Get a value in tenths (so "10.2" == 102, "9" = 90)
|
* Get a value in tenths (so "10.2" == 102, "9" = 90)
|
||||||
*
|
*
|
||||||
|
@ -1013,4 +1016,4 @@ timestamp_t current_time_notz(void)
|
||||||
struct tm *local = localtime(&now);
|
struct tm *local = localtime(&now);
|
||||||
return utc_mktime(local);
|
return utc_mktime(local);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "diveplanner.h"
|
#include "diveplanner.h"
|
||||||
|
#include "../dive.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -77,9 +78,12 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
DiveHandler *item = new DiveHandler ();
|
DiveHandler *item = new DiveHandler ();
|
||||||
item->setRect(-5,-5,10,10);
|
item->setRect(-5,-5,10,10);
|
||||||
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
|
int minutes = rint(timeLine->valueAt(mappedPos));
|
||||||
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(mappedPos)));
|
int meters = rint(depthLine->valueAt(mappedPos));
|
||||||
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(mappedPos)));
|
item->sec = minutes * 60;
|
||||||
|
item->mm = meters * 1000;
|
||||||
|
double xpos = timeLine->posAtValue(minutes);
|
||||||
|
double ypos = depthLine->posAtValue(meters);
|
||||||
item->setPos(QPointF(xpos, ypos));
|
item->setPos(QPointF(xpos, ypos));
|
||||||
scene()->addItem(item);
|
scene()->addItem(item);
|
||||||
handles << item;
|
handles << item;
|
||||||
|
@ -119,11 +123,27 @@ void DivePlannerGraphics::createDecoStops()
|
||||||
{
|
{
|
||||||
// This needs to be done in the following steps:
|
// This needs to be done in the following steps:
|
||||||
// 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...
|
||||||
|
// We just start with a surface node at time = 0
|
||||||
|
struct diveplan plan;
|
||||||
|
struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
|
||||||
|
dp->entered = TRUE;
|
||||||
|
plan.dp = dp;
|
||||||
|
DiveHandler *lastH = NULL;
|
||||||
Q_FOREACH(DiveHandler *h, handles) {
|
Q_FOREACH(DiveHandler *h, handles) {
|
||||||
// use this somewhere.
|
// these values need to come from the planner UI, eventually
|
||||||
h->time;
|
int o2 = 209;
|
||||||
h->depth;
|
int he = 0;
|
||||||
|
int po2 = 0;
|
||||||
|
int deltaT = lastH ? h->sec - lastH->sec : h->sec;
|
||||||
|
lastH = h;
|
||||||
|
plan_add_segment(&plan, deltaT, h->mm, o2, he, po2);
|
||||||
|
qDebug("time %d, depth %d", h->sec, h->mm);
|
||||||
}
|
}
|
||||||
|
#if DEBUG_PLAN
|
||||||
|
dump_plan(&plan);
|
||||||
|
#endif
|
||||||
|
|
||||||
// create the dive info here.
|
// create the dive info here.
|
||||||
|
|
||||||
// set the new 'end time' of the dive.
|
// set the new 'end time' of the dive.
|
||||||
|
@ -193,8 +213,9 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
|
||||||
|
|
||||||
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
|
double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos)));
|
||||||
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
|
double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
|
||||||
|
|
||||||
QPointF newPos(xpos, ypos);
|
QPointF newPos(xpos, ypos);
|
||||||
|
int sec = rint(timeLine->valueAt(newPos)) * 60;
|
||||||
|
int mm = rint(depthLine->valueAt(newPos)) * 1000;
|
||||||
bool moveLines = false;;
|
bool moveLines = false;;
|
||||||
// do not allow it to move between handlers.
|
// do not allow it to move between handlers.
|
||||||
if (handles.count() > 1) {
|
if (handles.count() > 1) {
|
||||||
|
@ -233,6 +254,8 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
|
||||||
clearGeneratedDeco();
|
clearGeneratedDeco();
|
||||||
createDecoStops();
|
createDecoStops();
|
||||||
}
|
}
|
||||||
|
activeDraggedHandler->sec = sec;
|
||||||
|
activeDraggedHandler->mm = mm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
QGraphicsLineItem *to;
|
QGraphicsLineItem *to;
|
||||||
qreal time;
|
qreal time;
|
||||||
qreal depth;
|
qreal depth;
|
||||||
|
int sec;
|
||||||
|
int mm;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Ruler : public QGraphicsLineItem{
|
class Ruler : public QGraphicsLineItem{
|
||||||
|
|
Loading…
Add table
Reference in a new issue