Пример #1
0
void DiveEventItem::setupToolTipString()
{
	// we display the event on screen - so translate
	QString name = gettextFromC::instance()->tr(internalEvent->name);
	int value = internalEvent->value;
	int type = internalEvent->type;
	if (value) {
		if (type == SAMPLE_EVENT_GASCHANGE || type == SAMPLE_EVENT_GASCHANGE2) {
			struct gasmix *g = get_gasmix_from_event(internalEvent);
			name += ": ";
			name += gasname(g);
		} else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
			name += QString(":%1").arg((double)value / 1000);
		} else {
			name += QString(":%1").arg(value);
		}
	} else if (type == SAMPLE_EVENT_PO2 && name == "SP change") {
		// this is a bad idea - we are abusing an existing event type that is supposed to
		// warn of high or low PO2 and are turning it into a set point change event
		name += "\n" + tr("Bailing out to OC");
	} else {
		name += internalEvent->flags == SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
								     internalEvent->flags == SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
	}
	// qDebug() << name;
	setToolTip(name);
}
Пример #2
0
void get_gas_from_events(struct divecomputer *dc, int time, struct gasmix *gas)
{
	// we don't modify the values passed in if nothing is found
	// so don't call with uninitialized gasmix !
	struct event *event = dc->events;
	while (event && event->time.seconds <= time) {
		if (!strcmp(event->name, "gaschange"))
			*gas = *get_gasmix_from_event(event);
		event = event->next;
	}
}
Пример #3
0
/*
 * If the event has an explicit cylinder index,
 * we return that. If it doesn't, we return the best
 * match based on the gasmix.
 *
 * Some dive computers give cylinder indexes, some
 * give just the gas mix.
 */
int get_cylinder_index(struct dive *dive, struct event *ev)
{
	int best;
	struct gasmix *mix;

	if (ev->gas.index >= 0)
		return ev->gas.index;

	/*
	 * This should no longer happen!
	 *
	 * We now match up gas change events with their cylinders at dive
	 * event fixup time.
	 */
	fprintf(stderr, "Still looking up cylinder based on gas mix in get_cylinder_index()!\n");

	mix = get_gasmix_from_event(dive, ev);
	best = find_best_gasmix_match(mix, dive->cylinder, 0);
	return best < 0 ? 0 : best;
}
Пример #4
0
void TankItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
	Q_UNUSED(topLeft);
	Q_UNUSED(bottomRight);
	// We don't have enougth data to calculate things, quit.
	if (!dataModel || !pInfoEntry || !pInfoNr)
		return;

	// remove the old rectangles
	foreach (QGraphicsRectItem *r, rects) {
		delete(r);
	}
	rects.clear();

	qreal width, left;

	// Find correct end of the dive plot for correct end of the tankbar
	struct plot_data *last_entry = &pInfoEntry[pInfoNr-1];

	// get the information directly from the displayed_dive (the dc always exists)
	struct divecomputer *dc = get_dive_dc(&displayed_dive, dc_number);

	// start with the first gasmix and at the start of the dive
	int cyl = explicit_first_cylinder(&displayed_dive, dc);
	struct gasmix *gasmix = &displayed_dive.cylinder[cyl].gasmix;
	int startTime = 0;

	// work through all the gas changes and add the rectangle for each gas while it was used
	struct event *ev = get_next_event(dc->events, "gaschange");
	while (ev && ev->time.seconds < last_entry->sec) {
		width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime);
		left = hAxis->posAtValue(startTime);
		createBar(left, width, gasmix);
		startTime = ev->time.seconds;
		gasmix = get_gasmix_from_event(&displayed_dive, ev);
		ev = get_next_event(ev->next, "gaschange");
	}
	width = hAxis->posAtValue(last_entry->sec) - hAxis->posAtValue(startTime);
	left = hAxis->posAtValue(startTime);
	createBar(left, width, gasmix);
}
Пример #5
0
/* look at all dive computers and figure out if this cylinder is used anywhere
 * d has to be a valid dive (test before calling)
 * cyl does not have to be a cylinder that is part of this dive structure */
bool cylinder_is_used(struct dive *d, cylinder_t *cyl)
{
	struct divecomputer *dc = &d->dc;
	bool same_as_first = gasmix_distance(&cyl->gasmix, &d->cylinder[0].gasmix) < 200;
	while (dc) {
		struct event *ev = get_next_event(dc->events, "gaschange");
		if (same_as_first && (!ev || ev->time.seconds > 30)) {
			// unless there is a gas change in the first 30 seconds we can
			// always mark the first cylinder as used
			return true;
		}
		while (ev) {
			if (gasmix_distance(&cyl->gasmix, get_gasmix_from_event(ev)) < 200)
				return true;

			ev = get_next_event(ev->next, "gaschange");
		}
		dc = dc->next;
	}
	return false;
}
Пример #6
0
/*
 * If the event has an explicit cylinder index,
 * we return that. If it doesn't, we return the best
 * match based on the gasmix.
 *
 * Some dive computers give cylinder indexes, some
 * give just the gas mix.
 */
int get_cylinder_index(struct dive *dive, struct event *ev)
{
	int i;
	int best = 0, score = INT_MAX;
	int target_o2, target_he;
	struct gasmix *g;

	if (ev->gas.index >= 0)
		return ev->gas.index;

	g = get_gasmix_from_event(ev);
	target_o2 = get_o2(g);
	target_he = get_he(g);

	/*
	 * Try to find a cylinder that best matches the target gas
	 * mix.
	 */
	for (i = 0; i < MAX_CYLINDERS; i++) {
		cylinder_t *cyl = dive->cylinder + i;
		int delta_o2, delta_he, distance;

		if (cylinder_nodata(cyl))
			continue;

		delta_o2 = get_o2(&cyl->gasmix) - target_o2;
		delta_he = get_he(&cyl->gasmix) - target_he;
		distance = delta_o2 * delta_o2;
		distance += delta_he * delta_he;

		if (distance >= score)
			continue;
		score = distance;
		best = i;
	}
	return best;
}