Hi everybody,

> Hmm, "Edit dive in planner"
> which begs the question... why ARE we editing the dive in the planner and
> not in the simpler dive edit mode. I'm not saying this is wrong (and I'm
> taking the patch), I'm just asking a questions…

Hmm. Dunno. Maybe „Edit profile in planner“ (and also „edit profile“ would be 
more accurate since we edit dives in all other places as well. Feel free to 
change the menu entry to something more sensible. Or are you really asking the 
question „Why are edit dive and the planner two different things?“? Maybe we 
should merge them and rather turn on planning with a checkbox?

[after writing the previous paragraph, /me actually tried out add dive/edit 
dive for the first time in quite a while. There is an obvious difference to the 
planner: In add/edit dive the main window standard tabs with notes etc are 
visible]

But maybe we should merge edit dive and edit dive in planner? Or simply get rid 
of „edit dive“ (and rather add a checkbox to the planner that turns off 
planning?

> This is 2/3 of what I was hoping for.
> I was also thinking that if the dive points go all the way back to the
> surface (which they most likely will when you just edited an existing dive
> and didn't ask the planner to get you back safely), then we shouldn't add
> the disclaimer and runtime table at all...

This is addressed in the attached patch. It only adds disclaimer and runtime 
table if the planner actually added stops.

Best
Robert
From df22a161c02dcec81b38307a7fc9551803f3933b Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <[email protected]>
Date: Sat, 9 May 2015 21:55:59 +0200
Subject: [PATCH] Only add disclaimer and runtime table if we added deco to
 replanne dive

As a side effect this changes the signature of plan(): Before it
returned an int that was supposed to be possibly an error but
we never bothered to check it. So now it's bool indicating if the
planner did add stops.

Signed-off-by: Robert C. Helling <[email protected]>
---
 dive.h                |  2 +-
 planner.c             | 12 ++++++++----
 qt-ui/diveplanner.cpp |  5 +++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/dive.h b/dive.h
index 625f650..9a26892 100644
--- a/dive.h
+++ b/dive.h
@@ -819,7 +819,7 @@ struct divedatapoint *create_dp(int time_incr, int depth, 
struct gasmix gasmix,
 #if DEBUG_PLAN
 void dump_plan(struct diveplan *diveplan);
 #endif
-int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool 
show_disclaimer);
+bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, 
bool show_disclaimer);
 void delete_single_dive(int idx);
 
 struct event *get_next_event(struct event *event, const char *name);
diff --git a/planner.c b/planner.c
index af1db50..ed7687e 100644
--- a/planner.c
+++ b/planner.c
@@ -853,7 +853,9 @@ bool enough_gas(int current_cylinder)
                return true;
 }
 
-int plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool 
show_disclaimer)
+// Work out the stops. Return value is if there were any mandatory stops.
+
+bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, 
bool show_disclaimer)
 {
        struct sample *sample;
        int po2;
@@ -876,6 +878,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, 
bool is_planner, bool s
        int breaktime = -1;
        int breakcylinder = 0;
        int error = 0;
+       bool decodive = false;
 
        set_gf(diveplan->gflow, diveplan->gfhigh, prefs.gf_low_at_maxdepth);
        if (!diveplan->surface_pressure)
@@ -912,7 +915,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, 
bool is_planner, bool s
                transitiontime = depth / 75; /* this still needs to be made 
configurable */
                plan_add_segment(diveplan, transitiontime, 0, gas, po2, false);
                create_dive_from_plan(diveplan, is_planner);
-               return(error);
+               return(false);
        }
        tissue_tolerance = tissue_at_end(&displayed_dive, cached_datap);
 
@@ -992,7 +995,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, 
bool is_planner, bool s
                free(stoplevels);
                free(gaschanges);
 
-               return(error);
+               return(false);
        }
 
        if (best_first_ascend_cylinder != current_cylinder) {
@@ -1056,6 +1059,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, 
bool is_planner, bool s
                                break; /* We did not hit the ceiling */
 
                        /* Add a minute of deco time and then try again */
+                       decodive = true;
                        if (!stopping) {
                                /* The last segment was an ascend segment.
                                 * Add a waypoint for start of this deco stop */
@@ -1116,7 +1120,7 @@ int plan(struct diveplan *diveplan, char **cached_datap, 
bool is_planner, bool s
 
        free(stoplevels);
        free(gaschanges);
-       return error;
+       return decodive;
 }
 
 /*
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index aacca8e..a5fc512 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -1310,7 +1310,7 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
        plannerModel->setRecalc(oldRecalc);
 
        //TODO: C-based function here?
-       plan(&diveplan, &cache, isPlanner(), true);
+       bool did_deco = plan(&diveplan, &cache, isPlanner(), true);
        if (!current_dive || displayed_dive.id != current_dive->id) {
                // we were planning a new dive, not re-planning an existing on
                record_dive(clone_dive(&displayed_dive));
@@ -1331,7 +1331,8 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
                        QString oldnotes(current_dive->notes);
                        if (oldnotes.indexOf(QString(disclaimer)) >= 0)
                                
oldnotes.truncate(oldnotes.indexOf(QString(disclaimer)));
-                       oldnotes.append(displayed_dive.notes);
+                       if (did_deco)
+                               oldnotes.append(displayed_dive.notes);
                        displayed_dive.notes = strdup(oldnotes.toUtf8().data());
                }
                copy_dive(&displayed_dive, current_dive);
-- 
1.9.5 (Apple Git-50.3)

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to