summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-06-23 18:04:35 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-06-23 20:32:32 -0700
commit596095389ba703341839e21cbbe1b438a50622d2 (patch)
tree04992d72b1d418915b9799f3de2bbc2071525cff
parent4a184a60fcf9871c00f8130f03c1595c4003537e (diff)
downloadsubsurface-596095389ba703341839e21cbbe1b438a50622d2.tar.gz
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>
-rw-r--r--Makefile1
-rw-r--r--dive.h2
-rw-r--r--planner.c7
-rw-r--r--qt-ui/diveplanner.cpp37
-rw-r--r--qt-ui/diveplanner.h2
5 files changed, 40 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 17f1dcd1a..1a4f60ace 100644
--- a/Makefile
+++ b/Makefile
@@ -63,6 +63,7 @@ SOURCES = \
info.c \
main.c \
parse-xml.c \
+ planner.c \
profile.c \
save-xml.c \
sha1.c \
diff --git a/dive.h b/dive.h
index 39943d6c6..9dc5a3631 100644
--- a/dive.h
+++ b/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 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);
struct event *get_next_event(struct event *event, char *name);
diff --git a/planner.c b/planner.c
index a707f7552..000c4c602 100644
--- a/planner.c
+++ b/planner.c
@@ -495,6 +495,7 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
return stoplevels;
}
+#if USE_GTK_UI
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
{
char buffer[20000];
@@ -590,6 +591,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive)
}
dive->notes = strdup(buffer);
}
+#endif
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);
stopidx--;
}
- add_plan_to_notes(diveplan, dive);
#if USE_GTK_UI
+ add_plan_to_notes(diveplan, dive);
/* now make the dive visible in the dive list */
report_dives(FALSE, FALSE);
show_and_select_dive(dive);
@@ -709,6 +711,7 @@ error_exit:
free(gaschanges);
}
+#if USE_GTK_UI
/*
* 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);
return utc_mktime(local);
}
-
+#endif
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index f4f2fda06..b239e20fc 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1,4 +1,5 @@
#include "diveplanner.h"
+#include "../dive.h"
#include <cmath>
#include <QMouseEvent>
#include <QDebug>
@@ -77,9 +78,12 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event)
DiveHandler *item = new DiveHandler ();
item->setRect(-5,-5,10,10);
item->setFlag(QGraphicsItem::ItemIgnoresTransformations);
-
- double xpos = timeLine->posAtValue(rint(timeLine->valueAt(mappedPos)));
- double ypos = depthLine->posAtValue(rint(depthLine->valueAt(mappedPos)));
+ int minutes = rint(timeLine->valueAt(mappedPos));
+ int meters = 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));
scene()->addItem(item);
handles << item;
@@ -119,11 +123,27 @@ void DivePlannerGraphics::createDecoStops()
{
// This needs to be done in the following steps:
// 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) {
- // use this somewhere.
- h->time;
- h->depth;
+ // these values need to come from the planner UI, eventually
+ int o2 = 209;
+ 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.
// 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 ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos)));
-
QPointF newPos(xpos, ypos);
+ int sec = rint(timeLine->valueAt(newPos)) * 60;
+ int mm = rint(depthLine->valueAt(newPos)) * 1000;
bool moveLines = false;;
// do not allow it to move between handlers.
if (handles.count() > 1) {
@@ -233,6 +254,8 @@ void DivePlannerGraphics::moveActiveHandler(const QPointF& pos)
clearGeneratedDeco();
createDecoStops();
}
+ activeDraggedHandler->sec = sec;
+ activeDraggedHandler->mm = mm;
}
}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 041ebb2d3..8c3505f52 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -22,6 +22,8 @@ public:
QGraphicsLineItem *to;
qreal time;
qreal depth;
+ int sec;
+ int mm;
};
class Ruler : public QGraphicsLineItem{