mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Profile: switch pressure-accessing functions to indexes
Continue with replacing pointers to struct plot_data entries by indexes. Thus the pressure data can be kept in its own array and can by dynamically sized. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
		
							parent
							
								
									459f9acc67
								
							
						
					
					
						commit
						fe6d3c8c38
					
				
					 4 changed files with 33 additions and 37 deletions
				
			
		| 
						 | 
				
			
			@ -350,10 +350,8 @@ static inline int calc_pressure_time(struct dive *dive, struct plot_data *a, str
 | 
			
		|||
static void debug_print_pressures(struct plot_info *pi)
 | 
			
		||||
{
 | 
			
		||||
	int i;
 | 
			
		||||
	for (i = 0; i < pi->nr; i++) {
 | 
			
		||||
		struct plot_data *entry = pi->entry + i;
 | 
			
		||||
		printf("%5d |%9d | %9d |\n", i, get_plot_sensor_pressure(entry), get_plot_interpolated_pressure(entry));
 | 
			
		||||
	}
 | 
			
		||||
	for (i = 0; i < pi->nr; i++)
 | 
			
		||||
		printf("%5d |%9d | %9d |\n", i, get_plot_sensor_pressure(pi, i), get_plot_interpolated_pressure(pi, i));
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -386,8 +384,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
 | 
			
		|||
	/* Get a rough range of where we have any pressures at all */
 | 
			
		||||
	first = last = -1;
 | 
			
		||||
	for (int i = 0; i < pi->nr; i++) {
 | 
			
		||||
		struct plot_data *entry = pi->entry + i;
 | 
			
		||||
		int pressure = get_plot_sensor_pressure(entry, sensor);
 | 
			
		||||
		int pressure = get_plot_sensor_pressure(pi, i, sensor);
 | 
			
		||||
 | 
			
		||||
		if (!pressure)
 | 
			
		||||
			continue;
 | 
			
		||||
| 
						 | 
				
			
			@ -416,7 +413,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
 | 
			
		|||
 | 
			
		||||
	for (int i = first; i <= last; i++) {
 | 
			
		||||
		struct plot_data *entry = pi->entry + i;
 | 
			
		||||
		int pressure = get_plot_sensor_pressure(entry, sensor);
 | 
			
		||||
		int pressure = get_plot_sensor_pressure(pi, i, sensor);
 | 
			
		||||
		int time = entry->sec;
 | 
			
		||||
 | 
			
		||||
		while (ev && ev->time.seconds <= time) {   // Find 1st gaschange event after 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1322,8 +1322,8 @@ static void debug_print_profiledata(struct plot_info *pi)
 | 
			
		|||
		fprintf(f1, "id t1 gas gasint t2 t3 dil dilint t4 t5 setpoint sensor1 sensor2 sensor3 t6 po2 fo2\n");
 | 
			
		||||
		for (i = 0; i < pi->nr; i++) {
 | 
			
		||||
			entry = pi->entry + i;
 | 
			
		||||
			fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, get_plot_sensor_pressure(entry),
 | 
			
		||||
				get_plot_interpolated_pressure(entry), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
 | 
			
		||||
			fprintf(f1, "%d gas=%8d %8d ; dil=%8d %8d ; o2_sp= %d %d %d %d PO2= %f\n", i, get_plot_sensor_pressure(pi, i),
 | 
			
		||||
				get_plot_interpolated_pressure(pi, i), O2CYLINDER_PRESSURE(entry), INTERPOLATED_O2CYLINDER_PRESSURE(entry),
 | 
			
		||||
				entry->o2pressure.mbar, entry->o2sensor[0].mbar, entry->o2sensor[1].mbar, entry->o2sensor[2].mbar, entry->pressures.o2);
 | 
			
		||||
		}
 | 
			
		||||
		fclose(f1);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,9 +102,9 @@ extern int get_maxtime(struct plot_info *pi);
 | 
			
		|||
 * partial pressure graphs */
 | 
			
		||||
extern int get_maxdepth(struct plot_info *pi);
 | 
			
		||||
 | 
			
		||||
static inline int get_plot_pressure_data(const struct plot_data *entry, enum plot_pressure sensor, int idx)
 | 
			
		||||
static inline int get_plot_pressure_data(const struct plot_info *pi, int idx, enum plot_pressure sensor, int cylinder)
 | 
			
		||||
{
 | 
			
		||||
	return entry->pressure[idx][sensor];
 | 
			
		||||
	return pi->entry[idx].pressure[cylinder][sensor];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void set_plot_pressure_data(struct plot_data *entry, enum plot_pressure sensor, int idx, int value)
 | 
			
		||||
| 
						 | 
				
			
			@ -112,21 +112,20 @@ static inline void set_plot_pressure_data(struct plot_data *entry, enum plot_pre
 | 
			
		|||
	entry->pressure[idx][sensor] = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int get_plot_sensor_pressure(const struct plot_data *entry, int idx)
 | 
			
		||||
static inline int get_plot_sensor_pressure(const struct plot_info *pi, int idx, int cylinder)
 | 
			
		||||
{
 | 
			
		||||
	return get_plot_pressure_data(entry, SENSOR_PR, idx);
 | 
			
		||||
	return get_plot_pressure_data(pi, idx, SENSOR_PR, cylinder);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int get_plot_interpolated_pressure(const struct plot_data *entry, int idx)
 | 
			
		||||
static inline int get_plot_interpolated_pressure(const struct plot_info *pi, int idx, int cylinder)
 | 
			
		||||
{
 | 
			
		||||
	return get_plot_pressure_data(entry, INTERPOLATED_PR, idx);
 | 
			
		||||
	return get_plot_pressure_data(pi, idx, INTERPOLATED_PR, cylinder);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int get_plot_pressure(const struct plot_info *pi, int idx, int cylinder)
 | 
			
		||||
{
 | 
			
		||||
	const struct plot_data *entry = pi->entry + idx;
 | 
			
		||||
	int res = get_plot_sensor_pressure(entry, cylinder);
 | 
			
		||||
	return res ? res : get_plot_interpolated_pressure(entry, cylinder);
 | 
			
		||||
	int res = get_plot_sensor_pressure(pi, idx, cylinder);
 | 
			
		||||
	return res ? res : get_plot_interpolated_pressure(pi, idx, cylinder);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1379,18 +1379,16 @@ bool ProfileWidget2::isPlanner()
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
#if 0 // TODO::: FINISH OR DISABLE
 | 
			
		||||
struct plot_data *ProfileWidget2::getEntryFromPos(QPointF pos)
 | 
			
		||||
struct int ProfileWidget2::getEntryFromPos(QPointF pos)
 | 
			
		||||
{
 | 
			
		||||
	// find the time stamp corresponding to the mouse position
 | 
			
		||||
	int seconds = lrint(timeAxis->valueAt(pos));
 | 
			
		||||
	struct plot_data *entry = NULL;
 | 
			
		||||
 | 
			
		||||
	for (int i = 0; i < plotInfo.nr; i++) {
 | 
			
		||||
		entry = plotInfo.entry + i;
 | 
			
		||||
		if ((int)entry->sec >= seconds)
 | 
			
		||||
			break;
 | 
			
		||||
		if (plotInfo.entry[i].sec >= seconds)
 | 
			
		||||
			return i;
 | 
			
		||||
	}
 | 
			
		||||
	return entry;
 | 
			
		||||
	return plotInfo.nr - 1;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1513,37 +1511,39 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
 | 
			
		|||
		}
 | 
			
		||||
#if 0 // TODO::: FINISH OR DISABLE
 | 
			
		||||
		QPointF scenePos = mapToScene(event->pos());
 | 
			
		||||
		struct plot_data *entry = getEntryFromPos(scenePos);
 | 
			
		||||
		int idx = getEntryFromPos(scenePos);
 | 
			
		||||
		// this shows how to figure out if we should ask the user if they want adjust interpolated pressures
 | 
			
		||||
		// at either side of a gas change
 | 
			
		||||
		if (dcEvent->type == SAMPLE_EVENT_GASCHANGE || dcEvent->type == SAMPLE_EVENT_GASCHANGE2) {
 | 
			
		||||
			qDebug() << "figure out if there are interpolated pressures";
 | 
			
		||||
			struct plot_data *gasChangeEntry = entry;
 | 
			
		||||
			struct plot_data *newGasEntry;
 | 
			
		||||
			while (gasChangeEntry > plotInfo.entry) {
 | 
			
		||||
				--gasChangeEntry;
 | 
			
		||||
				if (gasChangeEntry->sec <= dcEvent->time.seconds)
 | 
			
		||||
			int gasChangeIdx = idx;
 | 
			
		||||
			while (gasChangeIdx > 0) {
 | 
			
		||||
				--gasChangeIdx;
 | 
			
		||||
				if (plotInfo.entry[gasChangeIdx].sec <= dcEvent->time.seconds)
 | 
			
		||||
					break;
 | 
			
		||||
			}
 | 
			
		||||
			qDebug() << "at gas change at" << gasChangeEntry->sec << ": sensor pressure" << gasChangeEntry->pressure[0] << "interpolated" << gasChangeEntry->pressure[1];
 | 
			
		||||
			const struct plot_data &gasChangeEntry = plotInfo.entry[newGasIdx];
 | 
			
		||||
			qDebug() << "at gas change at" << gasChangeEntry->sec << ": sensor pressure" << get_plot_sensor_pressure(&plotInfo, newGasIdx)
 | 
			
		||||
				 << "interpolated" << ;get_plot_sensor_pressure(&plotInfo, newGasIdx);
 | 
			
		||||
			// now gasChangeEntry points at the gas change, that entry has the final pressure of
 | 
			
		||||
			// the old tank, the next entry has the starting pressure of the next tank
 | 
			
		||||
			if (gasChangeEntry + 1 <= plotInfo.entry + plotInfo.nr) {
 | 
			
		||||
				newGasEntry = gasChangeEntry + 1;
 | 
			
		||||
			if (gasChangeIdx < plotInfo.nr - 1) {
 | 
			
		||||
				int newGasIdx = gasChangeIdx + 1;
 | 
			
		||||
				const struct plot_data &newGasEntry = plotInfo.entry[newGasIdx];
 | 
			
		||||
				qDebug() << "after gas change at " << newGasEntry->sec << ": sensor pressure" << newGasEntry->pressure[0] << "interpolated" << newGasEntry->pressure[1];
 | 
			
		||||
				if (get_plot_sensor_pressure(gasChangeEntry) == 0 || displayed_dive.cylinder[gasChangeEntry->sensor[0]].sample_start.mbar == 0) {
 | 
			
		||||
				if (get_plot_sensor_pressure(&plotInfo, gasChangeIdx) == 0 || displayed_dive.cylinder[gasChangeEntry->sensor[0]].sample_start.mbar == 0) {
 | 
			
		||||
					// if we have no sensorpressure or if we have no pressure from samples we can assume that
 | 
			
		||||
					// we only have interpolated pressure (the pressure in the entry may be stored in the sensor
 | 
			
		||||
					// pressure field if this is the first or last entry for this tank... see details in gaspressures.c
 | 
			
		||||
					pressure_t pressure;
 | 
			
		||||
					pressure.mbar = get_plot_interpolated_pressure(gasChangeEntry) ? : get_plot_sensor_pressure(gasChangeEntry);
 | 
			
		||||
					pressure.mbar = get_plot_interpolated_pressure(&plotInfo, gasChangeIdx) ? : get_plot_sensor_pressure(&plotInfo, gasChangeIdx);
 | 
			
		||||
					QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
 | 
			
		||||
										 .arg(gasChangeEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
 | 
			
		||||
				}
 | 
			
		||||
				if (get_plot_sensor_pressure(newGasEntry) == 0 || displayed_dive.cylinder[newGasEntry->sensor[0]].sample_start.mbar == 0) {
 | 
			
		||||
				if (get_plot_sensor_pressure(&plotInfo, newGasIdx) == 0 || displayed_dive.cylinder[newGasEntry->sensor[0]].sample_start.mbar == 0) {
 | 
			
		||||
					// we only have interpolated press -- see commend above
 | 
			
		||||
					pressure_t pressure;
 | 
			
		||||
					pressure.mbar = get_plot_interpolated_pressure(newGasEntry) ? : get_plot_sensor_pressure(newGasEntry);
 | 
			
		||||
					pressure.mbar = get_plot_interpolated_pressure(&plotInfo, newGasIdx) ? : get_plot_sensor_pressure(&plotInfo, newGasIdx);
 | 
			
		||||
					QAction *adjustOldPressure = m.addAction(tr("Adjust pressure of cyl. %1 (currently interpolated as %2)")
 | 
			
		||||
										 .arg(newGasEntry->sensor[0] + 1).arg(get_pressure_string(pressure)));
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue