diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | dive.h | 2 | ||||
-rw-r--r-- | planner.c | 7 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 37 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 2 |
5 files changed, 40 insertions, 9 deletions
@@ -63,6 +63,7 @@ SOURCES = \ info.c \ main.c \ parse-xml.c \ + planner.c \ profile.c \ save-xml.c \ sha1.c \ @@ -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); @@ -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{ |