[PATCH 14/15] Read planner preferences when we use them

Read and use the last_stop preference in the plan function.  Read the plan
notes preferences and set variables (plan_verbatim, plan_display_runtime,
plan_display_duration, and plan_display_transitions) in the
add_plan_to_notes function.  Don't read the preferences and set variables
otherwise.  Both plan and add_plan_to_notes functions are called on data
change.

Previous behaviour was:
        Set variables on declaration
        Reset variables in plan function (even variables that only relate
to planner notes output)
        Changing a preference triggered set_xxx function which sets
variable, then plan function, which sets variable again.
Apart from being inefficient, the previous behaviour made it difficult to
track down where and when variables were set.


[PATCH 15/15] Planner deco stops are at 10ft increments when measured
 in feet

When using feet as depth unit, deco stop levels should be at 10 ft rather
than 3 m increments.  For shallow stops, rounding means the difference is
not apparent.  However, with stops deeper than 30 feet, using 3 m
increments leads stops at 39ft, 49ft, ..., 98ft, etc.

Apart from making plans look messy, the old behaviour makes it harder to
benchmark the planner against published profiles in imperial units.
From d02ef9c2137f6120fd79c0fd8469be845c1b34a8 Mon Sep 17 00:00:00 2001
From: Rick Walsh <[email protected]>
Date: Sat, 4 Jul 2015 22:14:10 +1000
Subject: [PATCH 14/15] Read planner preferences when we use them

Read and use the last_stop preference in the plan function.  Read the plan notes preferences and set variables (plan_verbatim, plan_display_runtime, plan_display_duration, and plan_display_transitions) in the add_plan_to_notes function.  Don't read the preferences and set variables otherwise.  Both plan and add_plan_to_notes functions are called on data change.

Previous behaviour was:
        Set variables on declaration
        Reset variables in plan function (even variables that only relate to planner notes output)
        Changing a preference triggered set_xxx function which sets variable, then plan function, which sets variable again.
Apart from being inefficient, the previous behaviour made it difficult to track down where and when variables were set.

Signed-off-by: Rick Walsh <[email protected]>
---
 planner.c                      | 48 +++++++++---------------------------------
 qt-models/diveplannermodel.cpp |  5 -----
 2 files changed, 10 insertions(+), 43 deletions(-)

diff --git a/planner.c b/planner.c
index 83e4757..606fd1a 100644
--- a/planner.c
+++ b/planner.c
@@ -24,7 +24,7 @@ int decostoplevels[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000,
 				  180000, 190000, 200000, 220000, 240000, 260000, 280000, 300000,
 				  320000, 340000, 360000, 380000 };
 double plangflow, plangfhigh;
-bool plan_verbatim = false, plan_display_runtime = true, plan_display_duration = false, plan_display_transitions = false;
+bool plan_verbatim, plan_display_runtime, plan_display_duration, plan_display_transitions;
 
 const char *disclaimer;
 
@@ -66,34 +66,6 @@ bool diveplan_empty(struct diveplan *diveplan)
 	return true;
 }
 
-void set_last_stop(bool last_stop_6m)
-{
-	if (last_stop_6m == true)
-		decostoplevels[1] = 6000;
-	else
-		decostoplevels[1] = 3000;
-}
-
-void set_verbatim(bool verbatim)
-{
-	plan_verbatim = verbatim;
-}
-
-void set_display_runtime(bool display)
-{
-	plan_display_runtime = display;
-}
-
-void set_display_duration(bool display)
-{
-	plan_display_duration = display;
-}
-
-void set_display_transitions(bool display)
-{
-	plan_display_transitions = display;
-}
-
 /* get the gas at a certain time during the dive */
 void get_gas_at_time(struct dive *dive, struct divecomputer *dc, duration_t time, struct gasmix *gas)
 {
@@ -528,6 +500,11 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 	bool gaschange_before;
 	struct divedatapoint *nextdp = NULL;
 
+	plan_verbatim = prefs.verbatim_plan;
+	plan_display_runtime = prefs.display_runtime;
+	plan_display_duration = prefs.display_duration;
+	plan_display_transitions = prefs.display_transitions;
+
 	disclaimer =  translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
 				"ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT WHICH HAS "
 				"RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO "
@@ -906,16 +883,11 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
 		diveplan->surface_pressure = SURFACE_PRESSURE;
 	create_dive_from_plan(diveplan, is_planner);
 
-	if (prefs.verbatim_plan)
-		plan_verbatim = true;
-	if (prefs.display_runtime)
-		plan_display_runtime = true;
-	if (prefs.display_duration)
-		plan_display_duration = true;
-	if (prefs.display_transitions)
-		plan_display_transitions = true;
-	if (prefs.last_stop)
+	if (prefs.last_stop) {
 		decostoplevels[1] = 6000;
+	} else {
+		decostoplevels[1] = 3000;
+	}
 
 	/* Let's start at the last 'sample', i.e. the last manually entered waypoint. */
 	sample = &displayed_dive.dc.sample[displayed_dive.dc.samples - 1];
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index e28b4d1..439e7a4 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -416,35 +416,30 @@ int DivePlannerPointsModel::getSurfacePressure()
 
 void DivePlannerPointsModel::setLastStop6m(bool value)
 {
-	set_last_stop(value);
 	prefs.last_stop = value;
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
 }
 
 void DivePlannerPointsModel::setVerbatim(bool value)
 {
-	set_verbatim(value);
 	prefs.verbatim_plan = value;
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
 }
 
 void DivePlannerPointsModel::setDisplayRuntime(bool value)
 {
-	set_display_runtime(value);
 	prefs.display_runtime = value;
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
 }
 
 void DivePlannerPointsModel::setDisplayDuration(bool value)
 {
-	set_display_duration(value);
 	prefs.display_duration = value;
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
 }
 
 void DivePlannerPointsModel::setDisplayTransitions(bool value)
 {
-	set_display_transitions(value);
 	prefs.display_transitions = value;
 	emit dataChanged(createIndex(0, 0), createIndex(rowCount() - 1, COLUMNS - 1));
 }
-- 
2.4.3

From 46728f10664e81a4b547cbab7a47d793e4799f19 Mon Sep 17 00:00:00 2001
From: Rick Walsh <[email protected]>
Date: Sat, 4 Jul 2015 23:10:34 +1000
Subject: [PATCH 15/15] Planner deco stops are at 10ft increments when measured
 in feet

When using feet as depth unit, deco stop levels should be at 10 ft rather than 3 m increments.  For shallow stops, rounding means the difference is not apparent.  However, with stops deeper than 30 feet, using 3 m increments leads stops at 39ft, 49ft, ..., 98ft, etc.

Apart from making plans look messy, the old behaviour makes it harder to benchmark the planner against published profiles in imperial units.

Signed-off-by: Rick Walsh <[email protected]>
---
 planner.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/planner.c b/planner.c
index 606fd1a..01775f1 100644
--- a/planner.c
+++ b/planner.c
@@ -17,12 +17,20 @@
 #define TIMESTEP 2 /* second */
 #define DECOTIMESTEP 60 /* seconds. Unit of deco stop times */
 
-int decostoplevels[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 27000,
+int decostoplevels_metric[] = { 0, 3000, 6000, 9000, 12000, 15000, 18000, 21000, 24000, 27000,
 				  30000, 33000, 36000, 39000, 42000, 45000, 48000, 51000, 54000, 57000,
 				  60000, 63000, 66000, 69000, 72000, 75000, 78000, 81000, 84000, 87000,
 				  90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000,
 				  180000, 190000, 200000, 220000, 240000, 260000, 280000, 300000,
 				  320000, 340000, 360000, 380000 };
+int decostoplevels_imperial[] = { 0, 3048, 6096, 9144, 12192, 15240, 18288, 21336, 24384, 27432,
+				30480, 33528, 36576, 39624, 42672, 45720, 48768, 51816, 54864, 57912,
+				60960, 64008, 67056, 70104, 73152, 76200, 79248, 82296, 85344, 88392,
+				91440, 101600, 111760, 121920, 132080, 142240, 152400, 162560, 172720,
+				182880, 193040, 203200, 223520, 243840, 264160, 284480, 304800,
+				325120, 345440, 365760, 386080 };
+int decostoplevels[51];
+
 double plangflow, plangfhigh;
 bool plan_verbatim, plan_display_runtime, plan_display_duration, plan_display_transitions;
 
@@ -884,9 +892,17 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool
 	create_dive_from_plan(diveplan, is_planner);
 
 	if (prefs.last_stop) {
-		decostoplevels[1] = 6000;
+		decostoplevels_metric[1] = 6000;
+		decostoplevels_imperial[1] = 6080;
+	} else {
+		decostoplevels_metric[1] = 3000;
+		decostoplevels_imperial[1] = 3040;
+	}
+
+	if (prefs.units.length == METERS ) {
+		memcpy(decostoplevels, decostoplevels_metric, sizeof(decostoplevels_metric));
 	} else {
-		decostoplevels[1] = 3000;
+		memcpy(decostoplevels, decostoplevels_imperial, sizeof(decostoplevels_imperial));
 	}
 
 	/* Let's start at the last 'sample', i.e. the last manually entered waypoint. */
-- 
2.4.3

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

Reply via email to