mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Print gas changes at the correct lines in diveplan
This is a pain. We plan with segments but the plan shows waypoints. If after a constant depth segment the gaschange (or setpoint chenge for that matter) appears, the _next_ line should get the info about the new gas (i.e. change _after_ the constant depth segment). If, however, the gas is changed after a transition, the final waypoint of the transition gets the gas printed. And all is different for a verbatim plan, where the gas change is an event rather than part of a segment. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									3f0159b734
								
							
						
					
					
						commit
						61961b11ad
					
				
					 1 changed files with 28 additions and 13 deletions
				
			
		
							
								
								
									
										29
									
								
								planner.c
									
										
									
									
									
								
							
							
						
						
									
										29
									
								
								planner.c
									
										
									
									
									
								
							| 
						 | 
					@ -514,9 +514,9 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops,
 | 
				
			||||||
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
 | 
					static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char buffer[20000], temp[1000];
 | 
						char buffer[20000], temp[1000];
 | 
				
			||||||
	int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1;
 | 
						int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0;
 | 
				
			||||||
	struct divedatapoint *dp = diveplan->dp;
 | 
						struct divedatapoint *dp = diveplan->dp;
 | 
				
			||||||
	bool gaschange = !plan_verbatim;
 | 
						bool gaschange = !plan_verbatim, postponed = plan_verbatim;
 | 
				
			||||||
	struct divedatapoint *nextdp = NULL;
 | 
						struct divedatapoint *nextdp = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	disclaimer =  translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
 | 
						disclaimer =  translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
 | 
				
			||||||
| 
						 | 
					@ -577,13 +577,14 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 | 
				
			||||||
		    nextdp &&
 | 
							    nextdp &&
 | 
				
			||||||
		    dp->setpoint == nextdp->setpoint &&
 | 
							    dp->setpoint == nextdp->setpoint &&
 | 
				
			||||||
		    dp->depth != lastdepth &&
 | 
							    dp->depth != lastdepth &&
 | 
				
			||||||
		    nextdp->depth != dp->depth)
 | 
							    nextdp->depth != dp->depth
 | 
				
			||||||
 | 
							    && !gaschange)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		if (dp->time - lasttime < 10 && !(gaschange && dp->next && dp->depth != dp->next->depth))
 | 
							if (dp->time - lasttime < 10 && !(gaschange && dp->next && dp->depth != dp->next->depth))
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		len = strlen(buffer);
 | 
							len = strlen(buffer);
 | 
				
			||||||
		if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != lastsetpoint))
 | 
							if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != nextdp->setpoint))
 | 
				
			||||||
			gaschange = true;
 | 
								gaschange = true;
 | 
				
			||||||
		if (plan_verbatim) {
 | 
							if (plan_verbatim) {
 | 
				
			||||||
			if (dp->depth != lastdepth) {
 | 
								if (dp->depth != lastdepth) {
 | 
				
			||||||
| 
						 | 
					@ -604,6 +605,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 | 
				
			||||||
							 gasname(&gasmix));
 | 
												 gasname(&gasmix));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
										len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
				
			||||||
 | 
										newdepth = dp->depth;
 | 
				
			||||||
					lasttime = dp->time;
 | 
										lasttime = dp->time;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
| 
						 | 
					@ -623,6 +625,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 | 
				
			||||||
								gasname(&gasmix));
 | 
													gasname(&gasmix));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
											len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
				
			||||||
 | 
										newdepth = dp->depth;
 | 
				
			||||||
					lasttime = dp->time;
 | 
										lasttime = dp->time;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
| 
						 | 
					@ -638,7 +641,11 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 | 
				
			||||||
					snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60);
 | 
										snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60);
 | 
				
			||||||
					len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
 | 
										len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (gaschange) {
 | 
									if (gaschange) {
 | 
				
			||||||
 | 
										if(dp->depth == lastdepth && !postponed) {
 | 
				
			||||||
 | 
											postponed = true;
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
						if (dp->setpoint) {
 | 
											if (dp->setpoint) {
 | 
				
			||||||
							snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
 | 
												snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
 | 
				
			||||||
							len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
 | 
												len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
 | 
				
			||||||
| 
						 | 
					@ -647,29 +654,37 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
 | 
				
			||||||
							len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix));
 | 
												len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix));
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						gaschange = false;
 | 
											gaschange = false;
 | 
				
			||||||
 | 
											postponed = false;
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					len += snprintf(buffer + len, sizeof(buffer) - len, "<td> </td>");
 | 
										len += snprintf(buffer + len, sizeof(buffer) - len, "<td> </td>");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				len += snprintf(buffer + len, sizeof(buffer) - len, "</tr>");
 | 
									len += snprintf(buffer + len, sizeof(buffer) - len, "</tr>");
 | 
				
			||||||
 | 
									newdepth = dp->depth;
 | 
				
			||||||
				lasttime = dp->time;
 | 
									lasttime = dp->time;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (gaschange) {
 | 
							if (gaschange) {
 | 
				
			||||||
 | 
								if(dp->depth == lastdepth && !postponed) {
 | 
				
			||||||
 | 
									postponed = true;
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
			// gas switch at this waypoint
 | 
								// gas switch at this waypoint
 | 
				
			||||||
			if (plan_verbatim) {
 | 
								if (plan_verbatim) {
 | 
				
			||||||
				if (lastsetpoint >= 0) {
 | 
									if (lastsetpoint >= 0) {
 | 
				
			||||||
					if (dp->setpoint)
 | 
										if (nextdp && nextdp->setpoint)
 | 
				
			||||||
						snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) dp->setpoint / 1000.0);
 | 
											snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) nextdp->setpoint / 1000.0);
 | 
				
			||||||
					else
 | 
										else
 | 
				
			||||||
						snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix));
 | 
											snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
										len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				gaschange = false;
 | 
									gaschange = false;
 | 
				
			||||||
 | 
									postponed = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			gasmix = newgasmix;
 | 
								gasmix = newgasmix;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		lastdepth = dp->depth;
 | 
							}
 | 
				
			||||||
 | 
							lastdepth = newdepth;
 | 
				
			||||||
		lastsetpoint = dp->setpoint;
 | 
							lastsetpoint = dp->setpoint;
 | 
				
			||||||
	} while ((dp = nextdp) != NULL);
 | 
						} while ((dp = nextdp) != NULL);
 | 
				
			||||||
	len += snprintf(buffer + len, sizeof(buffer) - len, "</tbody></table></div>");
 | 
						len += snprintf(buffer + len, sizeof(buffer) - len, "</tbody></table></div>");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue