mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Fix deco_mode confusion
We have two prefernces determining the deco_mode (BUEHLMANN vs VPMB vs RECREATIONAL): One for the planner (deco_mode) and one for displaying dives (display_deco_mode). The former is set in the planner settings while the latter is set in the preferences. This patch clears up a confusion which of the two to use by introducing a helper function that selects the correct variable. Signed-off-by: Robert C. Helling <helling@atdotde.de>
This commit is contained in:
		
							parent
							
								
									4e375f56a8
								
							
						
					
					
						commit
						bb4bf639c3
					
				
					 8 changed files with 36 additions and 24 deletions
				
			
		
							
								
								
									
										11
									
								
								core/deco.c
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								core/deco.c
									
										
									
									
									
								
							|  | @ -21,6 +21,7 @@ | |||
| #include "dive.h" | ||||
| #include <assert.h> | ||||
| #include "core/planner.h" | ||||
| #include "qthelperfromc.h" | ||||
| 
 | ||||
| #define cube(x) (x * x * x) | ||||
| 
 | ||||
|  | @ -258,7 +259,7 @@ double tissue_tolerance_calc(const struct dive *dive, double pressure) | |||
| 		buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / tissue_inertgas_saturation[ci]; | ||||
| 	} | ||||
| 
 | ||||
| 	if (prefs.deco_mode != VPMB) { | ||||
| 	if (decoMode() != VPMB) { | ||||
| 		for (ci = 0; ci < 16; ci++) { | ||||
| 
 | ||||
| 			/* tolerated = (tissue_inertgas_saturation - buehlmann_inertgas_a) * buehlmann_inertgas_b; */ | ||||
|  | @ -381,7 +382,7 @@ double he_factor(int period_in_seconds, int ci) | |||
| 
 | ||||
| double calc_surface_phase(double surface_pressure, double he_pressure, double n2_pressure, double he_time_constant, double n2_time_constant) | ||||
| { | ||||
| 	double inspired_n2 = (surface_pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * NITROGEN_FRACTION; | ||||
| 	double inspired_n2 = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * NITROGEN_FRACTION; | ||||
| 
 | ||||
| 	if (n2_pressure > inspired_n2) | ||||
| 		return (he_pressure / he_time_constant + (n2_pressure - inspired_n2) / n2_time_constant) / (he_pressure + n2_pressure - inspired_n2); | ||||
|  | @ -522,7 +523,7 @@ void add_segment(double pressure, const struct gasmix *gasmix, int period_in_sec | |||
| 	int ci; | ||||
| 	struct gas_pressures pressures; | ||||
| 
 | ||||
| 	fill_pressures(&pressures, pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE), | ||||
| 	fill_pressures(&pressures, pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE), | ||||
| 		       gasmix, (double) ccpo2 / 1000.0, dive->dc.divemode); | ||||
| 
 | ||||
| 	if (buehlmann_config.gf_low_at_maxdepth && pressure > gf_low_pressure_this_dive) | ||||
|  | @ -541,7 +542,7 @@ void add_segment(double pressure, const struct gasmix *gasmix, int period_in_sec | |||
| 		tissue_inertgas_saturation[ci] = tissue_n2_sat[ci] + tissue_he_sat[ci]; | ||||
| 
 | ||||
| 	} | ||||
| 	if(prefs.deco_mode == VPMB) | ||||
| 	if(decoMode() == VPMB) | ||||
| 		calc_crushing_pressure(pressure); | ||||
| 	return; | ||||
| } | ||||
|  | @ -562,7 +563,7 @@ void clear_deco(double surface_pressure) | |||
| { | ||||
| 	int ci; | ||||
| 	for (ci = 0; ci < 16; ci++) { | ||||
| 		tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (prefs.deco_mode == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000; | ||||
| 		tissue_n2_sat[ci] = (surface_pressure - ((in_planner() && (decoMode() == VPMB)) ? WV_PRESSURE_SCHREINER : WV_PRESSURE)) * N2_IN_AIR / 1000; | ||||
| 		tissue_he_sat[ci] = 0.0; | ||||
| 		max_n2_crushing_pressure[ci] = 0.0; | ||||
| 		max_he_crushing_pressure[ci] = 0.0; | ||||
|  |  | |||
|  | @ -14,6 +14,7 @@ | |||
| #include "planner.h" | ||||
| #include "gettext.h" | ||||
| #include "libdivecomputer/parser.h" | ||||
| #include "qthelperfromc.h" | ||||
| 
 | ||||
| #define TIMESTEP 2 /* second */ | ||||
| #define DECOTIMESTEP 60 /* seconds. Unit of deco stop times */ | ||||
|  | @ -173,7 +174,7 @@ unsigned int tissue_at_end(struct dive *dive, char **cached_datap) | |||
| 		 * portion of the dive. | ||||
| 		 * Remember the value for later. | ||||
| 		 */ | ||||
| 		if ((prefs.deco_mode == VPMB) && (lastdepth.mm > sample->depth.mm)) { | ||||
| 		if ((decoMode() == VPMB) && (lastdepth.mm > sample->depth.mm)) { | ||||
| 			pressure_t ceiling_pressure; | ||||
| 			nuclear_regeneration(t0.seconds); | ||||
| 			vpmb_start_gradient(); | ||||
|  | @ -548,7 +549,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool | |||
| 	plan_display_duration = prefs.display_duration; | ||||
| 	plan_display_transitions = prefs.display_transitions; | ||||
| 
 | ||||
| 	if (prefs.deco_mode == VPMB) { | ||||
| 	if (decoMode() == VPMB) { | ||||
| 		deco = "VPM-B"; | ||||
| 	} else { | ||||
| 		deco = "BUHLMANN"; | ||||
|  | @ -579,10 +580,10 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool | |||
| 	} | ||||
| 
 | ||||
| 	len = show_disclaimer ? snprintf(buffer, sz_buffer, "<div><b>%s<b></div><br>", disclaimer) : 0; | ||||
| 	if (prefs.deco_mode == BUEHLMANN){ | ||||
| 	if (decoMode() == BUEHLMANN){ | ||||
| 		snprintf(temp, sz_temp, translate("gettextFromC", "based on Bühlmann ZHL-16C with GFlow = %d and GFhigh = %d"), | ||||
| 			diveplan->gflow, diveplan->gfhigh); | ||||
| 	} else if (prefs.deco_mode == VPMB){ | ||||
| 	} else if (decoMode() == VPMB){ | ||||
| 		int temp_len; | ||||
| 		if (diveplan->vpmb_conservatism == 0) | ||||
| 			temp_len = snprintf(temp, sz_temp, "%s", translate("gettextFromC", "based on VPM-B at nominal conservatism")); | ||||
|  | @ -592,7 +593,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool | |||
| 			temp_len += snprintf(temp + temp_len, sz_temp - temp_len,  translate("gettextFromC", ", effective GF=%d/%d"), diveplan->eff_gflow | ||||
| 					     , diveplan->eff_gfhigh); | ||||
| 
 | ||||
| 	} else if (prefs.deco_mode == RECREATIONAL){ | ||||
| 	} else if (decoMode() == RECREATIONAL){ | ||||
| 		snprintf(temp, sz_temp, translate("gettextFromC", "recreational mode based on Bühlmann ZHL-16B with GFlow = %d and GFhigh = %d"), | ||||
| 			diveplan->gflow, diveplan->gfhigh); | ||||
| 	} | ||||
|  | @ -938,7 +939,7 @@ bool trial_ascent(int trial_depth, int stoplevel, int avg_depth, int bottom_time | |||
| 	// For consistency with other VPM-B implementations, we should not start the ascent while the ceiling is
 | ||||
| 	// deeper than the next stop (thus the offgasing during the ascent is ignored).
 | ||||
| 	// However, we still need to make sure we don't break the ceiling due to on-gassing during ascent.
 | ||||
| 	if (prefs.deco_mode == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive, | ||||
| 	if (decoMode() == VPMB && (deco_allowed_depth(tissue_tolerance_calc(&displayed_dive, | ||||
| 										 depth_to_bar(stoplevel, &displayed_dive)), | ||||
| 							   surface_pressure, &displayed_dive, 1) > stoplevel)) | ||||
| 		return false; | ||||
|  | @ -1096,7 +1097,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool | |||
| 	nuclear_regeneration(clock); | ||||
| 	vpmb_start_gradient(); | ||||
| 
 | ||||
| 	if(prefs.deco_mode == RECREATIONAL) { | ||||
| 	if(decoMode() == RECREATIONAL) { | ||||
| 		bool safety_stop = prefs.safetystop && max_depth >= 10000; | ||||
| 		track_ascent_gas(depth, &displayed_dive.cylinder[current_cylinder], avg_depth, bottom_time, safety_stop); | ||||
| 		// How long can we stay at the current depth and still directly ascent to the surface?
 | ||||
|  | @ -1172,7 +1173,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool | |||
| 
 | ||||
| 	//CVA
 | ||||
| 	do { | ||||
| 		is_final_plan = (prefs.deco_mode == BUEHLMANN) || (previous_deco_time - deco_time < 10);  // CVA time converges
 | ||||
| 		is_final_plan = (decoMode() == BUEHLMANN) || (previous_deco_time - deco_time < 10);  // CVA time converges
 | ||||
| 		if (deco_time != 10000000) | ||||
| 			vpmb_next_gradient(deco_time, diveplan->surface_pressure / 1000.0); | ||||
| 
 | ||||
|  | @ -1372,7 +1373,7 @@ bool plan(struct diveplan *diveplan, char **cached_datap, bool is_planner, bool | |||
| 	} while (!is_final_plan); | ||||
| 
 | ||||
| 	plan_add_segment(diveplan, clock - previous_point_time, 0, current_cylinder, po2, false); | ||||
| 	if(prefs.deco_mode == VPMB) { | ||||
| 	if(decoMode() == VPMB) { | ||||
| 		diveplan->eff_gfhigh = rint(100.0 * regressionb()); | ||||
| 		diveplan->eff_gflow = rint(100*(regressiona() * first_stop_depth + regressionb())); | ||||
| 	} | ||||
|  |  | |||
|  | @ -16,6 +16,7 @@ | |||
| #include "libdivecomputer/parser.h" | ||||
| #include "libdivecomputer/version.h" | ||||
| #include "membuffer.h" | ||||
| #include "qthelperfromc.h" | ||||
| 
 | ||||
| //#define DEBUG_GAS 1
 | ||||
| 
 | ||||
|  | @ -950,7 +951,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru | |||
| 	int deco_time = 0, prev_deco_time = 10000000; | ||||
| 	char *cache_data_initial = NULL; | ||||
| 	/* For VPM-B outside the planner, cache the initial deco state for CVA iterations */ | ||||
| 	if (prefs.deco_mode == VPMB && !in_planner()) | ||||
| 	if (decoMode() == VPMB && !in_planner()) | ||||
| 		cache_deco_state(&cache_data_initial); | ||||
| 	/* For VPM-B outside the planner, iterate until deco time converges (usually one or two iterations after the initial)
 | ||||
| 	 * Set maximum number of iterations to 10 just in case */ | ||||
|  | @ -982,7 +983,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru | |||
| 				entry->ceiling = (entry - 1)->ceiling; | ||||
| 			} else { | ||||
| 				/* Keep updating the VPM-B gradients until the start of the ascent phase of the dive. */ | ||||
| 				if (prefs.deco_mode == VPMB && !in_planner() && (entry - 1)->ceiling >= first_ceiling && first_iteration == true) { | ||||
| 				if (decoMode() == VPMB && !in_planner() && (entry - 1)->ceiling >= first_ceiling && first_iteration == true) { | ||||
| 					nuclear_regeneration(t1); | ||||
| 					vpmb_start_gradient(); | ||||
| 					/* For CVA calculations, start by guessing deco time = dive time remaining */ | ||||
|  | @ -995,7 +996,7 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru | |||
| 				else | ||||
| 					current_ceiling = entry->ceiling; | ||||
| 				/* If using VPM-B outside the planner, take first_ceiling_pressure as the deepest ceiling */ | ||||
| 				if (prefs.deco_mode == VPMB && !in_planner()) { | ||||
| 				if (decoMode() == VPMB && !in_planner()) { | ||||
| 					if  (current_ceiling > first_ceiling) { | ||||
| 						time_deep_ceiling = t1; | ||||
| 						first_ceiling = current_ceiling; | ||||
|  | @ -1027,8 +1028,8 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru | |||
| 			* We don't for print-mode because this info doesn't show up there | ||||
| 			* If the ceiling hasn't cleared by the last data point, we need tts for VPM-B CVA calculation | ||||
| 			* It is not necessary to do these calculation on the first VPMB iteration, except for the last data point */ | ||||
| 			if ((prefs.calcndltts && !print_mode && (prefs.deco_mode != VPMB || in_planner() || !first_iteration)) || | ||||
| 			    (prefs.deco_mode == VPMB && !in_planner() && i == pi->nr - 1)) { | ||||
| 			if ((prefs.calcndltts && !print_mode && (decoMode() != VPMB || in_planner() || !first_iteration)) || | ||||
| 			    (decoMode() == VPMB && !in_planner() && i == pi->nr - 1)) { | ||||
| 				/* only calculate ndl/tts on every 30 seconds */ | ||||
| 				if ((entry->sec - last_ndl_tts_calc_time) < 30 && i != pi->nr - 1) { | ||||
| 					struct plot_data *prev_entry = (entry - 1); | ||||
|  | @ -1044,14 +1045,14 @@ void calculate_deco_information(struct dive *dive, struct divecomputer *dc, stru | |||
| 				char *cache_data = NULL; | ||||
| 				cache_deco_state(&cache_data); | ||||
| 				calculate_ndl_tts(entry, dive, surface_pressure); | ||||
| 				if (prefs.deco_mode == VPMB && !in_planner() && i == pi->nr - 1) | ||||
| 				if (decoMode() == VPMB && !in_planner() && i == pi->nr - 1) | ||||
| 					final_tts = entry->tts_calc; | ||||
| 				/* Restore "real" deco state for next real time step */ | ||||
| 				restore_deco_state(cache_data); | ||||
| 				free(cache_data); | ||||
| 			} | ||||
| 		} | ||||
| 		if (prefs.deco_mode == VPMB && !in_planner()) { | ||||
| 		if (decoMode() == VPMB && !in_planner()) { | ||||
| 			prev_deco_time = deco_time; | ||||
| 			// Do we need to update deco_time?
 | ||||
| 			if (final_tts > 0) | ||||
|  |  | |||
|  | @ -1437,6 +1437,11 @@ extern "C" bool in_planner() | |||
| 	return (currentApplicationState == "PlanDive" || currentApplicationState == "EditPlannedDive"); | ||||
| } | ||||
| 
 | ||||
| extern "C" enum deco_mode decoMode() | ||||
| { | ||||
| 	return in_planner() ? prefs.deco_mode : prefs.display_deco_mode; | ||||
| } | ||||
| 
 | ||||
| void init_proxy() | ||||
| { | ||||
| 	QNetworkProxy proxy; | ||||
|  |  | |||
|  | @ -40,6 +40,7 @@ bool parseGpsText(const QString &gps_text, double *latitude, double *longitude); | |||
| QByteArray getCurrentAppState(); | ||||
| void setCurrentAppState(QByteArray state); | ||||
| extern "C" bool in_planner(); | ||||
| extern "C" enum deco_mode decoMode(); | ||||
| extern "C" void subsurface_mkdir(const char *dir); | ||||
| void init_proxy(); | ||||
| QString getUUID(); | ||||
|  |  | |||
|  | @ -18,5 +18,6 @@ char *cloud_url(); | |||
| char *hashfile_name_string(); | ||||
| char *picturedir_string(); | ||||
| const char *subsurface_user_agent(); | ||||
| enum deco_mode decoMode(); | ||||
| 
 | ||||
| #endif // QTHELPERFROMC_H
 | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ | |||
| #include <QSettings> | ||||
| #include <QGraphicsView> | ||||
| #include <QStyleOptionGraphicsItem> | ||||
| #include "core/qthelper.h" | ||||
| 
 | ||||
| void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap) | ||||
| { | ||||
|  | @ -267,7 +268,7 @@ void ToolTipItem::refresh(const QPointF &pos) | |||
| 		Q_ASSERT(view); | ||||
| 
 | ||||
| 		painter.setPen(QColor(0, 0, 0, 255)); | ||||
| 		if ((view->currentState == ProfileWidget2::PLAN && prefs.deco_mode == BUEHLMANN) || prefs.display_deco_mode == BUEHLMANN) | ||||
| 		if (decoMode() == BUEHLMANN) | ||||
| 			painter.drawLine(0, 60 - entry->gfline / 2, 16, 60 - entry->gfline / 2); | ||||
| 		painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, | ||||
| 				16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2); | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ | |||
| #include "desktop-widgets/diveplanner.h" | ||||
| #include "desktop-widgets/simplewidgets.h" | ||||
| #include "desktop-widgets/divepicturewidget.h" | ||||
| #include "core/qthelper.h" | ||||
| #endif | ||||
| 
 | ||||
| #include <libdivecomputer/parser.h> | ||||
|  | @ -558,7 +559,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force) | |||
| 		// this copies the dive and makes copies of all the relevant additional data
 | ||||
| 		copy_dive(d, &displayed_dive); | ||||
| #ifndef SUBSURFACE_MOBILE | ||||
| 		if ((currentState == PLAN && prefs.deco_mode == VPMB) || prefs.display_deco_mode == VPMB) | ||||
| 		if (decoMode() == VPMB) | ||||
| 			decoModelParameters->setText(QString("VPM-B +%1").arg(prefs.vpmb_conservatism)); | ||||
| 		else | ||||
| 			decoModelParameters->setText(QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh)); | ||||
|  | @ -570,7 +571,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force) | |||
| 			plannerModel->deleteTemporaryPlan(); | ||||
| 			return; | ||||
| 		} | ||||
| 		if ((currentState == PLAN && prefs.deco_mode == VPMB) || prefs.display_deco_mode == VPMB) | ||||
| 		if (decoMode() == VPMB) | ||||
| 			decoModelParameters->setText(QString("VPM-B +%1").arg(diveplan.vpmb_conservatism)); | ||||
| 		else | ||||
| 			decoModelParameters->setText(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh)); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue