Example #1
0
QVariant DiveTripModel::headerData(int section, Qt::Orientation orientation, int role) const
{
	QVariant ret;
	if (orientation == Qt::Vertical)
		return ret;

	switch(role){
		case Qt::FontRole :
			ret = defaultModelFont(); break;
		case Qt::DisplayRole :
			switch (section) {
			case NR:		ret = tr("#"); break;
			case DATE:		ret = tr("Date"); break;
			case RATING:	ret = UTF8_BLACKSTAR; break;
			case DEPTH:		ret = (get_units()->length == units::METERS) ? tr("m") : tr("ft"); break;
			case DURATION:	ret = tr("min"); break;
			case TEMPERATURE:ret = QString("%1%2").arg(UTF8_DEGREE).arg((get_units()->temperature == units::CELSIUS) ? "C" : "F"); break;
			case TOTALWEIGHT:ret = (get_units()->weight == units::KG) ? tr("kg") : tr("lbs"); break;
			case SUIT:		ret = tr("Suit"); break;
			case CYLINDER:	ret = tr("Cyl"); break;
			case NITROX:	ret = QString("O%1%").arg(UTF8_SUBSCRIPT_2); break;
			case SAC:		ret = tr("SAC"); break;
			case OTU:		ret = tr("OTU"); break;
			case MAXCNS:	ret = tr("maxCNS"); break;
			case LOCATION:	ret = tr("Location"); break;
			}break;
	}

	return ret;
}
int main(int argc, char *argv[])
{

    char variable[10];
    char cdf_name[200];
    char *units;

    float X, Y, Z;

    int count = 0;
    float n;

    float missing = -10000.0;
    float delta_x, delta_y, delta_z;
    float interp_value1, sample_factor, x2;

    if (argc != 8)
    {
        printf("ERROR:this example program requires 7 arguments - (1)full path and file name of data file (2) VARIABLE NAME (3) x1 position (4) y1 position (5) z1 position (6) delta x (7) x2 \n");
        exit( EXIT_FAILURE);
    }

    strcpy(cdf_name, argv[1]);
    strcpy(variable, argv[2]);

    X = atof(argv[3]);
    Y = atof(argv[4]);
    Z = atof(argv[5]);

    sample_factor = atof(argv[6]);
    x2 = atof(argv[7]);

    open_cdf(cdf_name, 0);

    /************************** example for new get_units() function ***************************
     **	takes variable name as argument and return a pointer to the string of units	**
     *******************************************************************************************/

    units = get_units(variable);
    printf("units for %s = %s\n", variable, units);

    for (n = X; n <= x2; n+=sample_factor)
    {

        interp_value1 = interpolate_batsrus_cdf(variable, n, Y, Z, 0, 1,
                missing, &delta_x, &delta_y, &delta_z);
        printf("\t%s [ %f, %f, %f ]\t%g %s\tdelta %f %s\n", variable, n, Y, Z,
                interp_value1, get_units(variable), delta_x, get_units("x") );
        count++;
    }

    close_cdf();

    return 1;

}
Example #3
0
QString DiveItem::displayDepth() const
{
	const int scale = 1000;
	QString fract, str;
	if (get_units()->length == units::METERS) {
		fract = QString::number((unsigned)(dive->maxdepth.mm % scale) / 100);
		str = QString("%1.%2").arg((unsigned)(dive->maxdepth.mm / scale)).arg(fract, 1, QChar('0'));
	}
	if (get_units()->length == units::FEET) {
		str = QString::number(mm_to_feet(dive->maxdepth.mm),'f',0);
	}
	return str;
}
Example #4
0
static int open(struct widget *w)
{
    struct widget_priv *priv;

    priv = (struct widget_priv*) widget_malloc(sizeof(struct widget_priv));
    if (priv == NULL)
        return -1;

    w->priv = priv;

    priv->home = get_home_data();

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            priv->range = 20*5;
            break;
        case UNITS_IMPERIAL:
            priv->range = 100*5;
            break;
    }

    add_mavlink_callback(MAVLINK_MSG_ID_GPS_RAW_INT, mav_callback, CALLBACK_WIDGET, w);
    w->ca.width = X_SIZE;
    w->ca.height = Y_SIZE;
    return 0;
}
Example #5
0
static void mav_callback(mavlink_message_t *msg, mavlink_status_t *status, void *d)
{
    struct widget *w = d;
    struct widget_priv *priv = w->priv;
    float altitude;
    
    switch (w->cfg->props.mode) {
        case 0:
        default:
            altitude = mavlink_msg_gps_raw_int_get_alt(msg) / 1000.0;
            break;
        case 1:
            if (priv->home->lock == HOME_LOCKED)
                altitude = (long) priv->home->altitude;
            else
                altitude = 0;
            break;
    }

    if (get_units(w->cfg) == UNITS_IMPERIAL)
        altitude *= M2FEET;
    
    priv->altitude = (long) altitude;
    schedule_widget(w);
}
Example #6
0
double get_volume_units(unsigned int ml, int *frac, const char **units)
{
	int decimals;
	double vol;
	const char *unit;
	struct units *units_p = get_units();

	switch (units_p->volume) {
	case LITER:
		vol = ml / 1000.0;
		unit = _("l");
		decimals = 1;
		break;
	case CUFT:
		vol = ml_to_cuft(ml);
		unit = _("cuft");
		decimals = 2;
		break;
	}
	if (frac)
		*frac = decimals;
	if (units)
		*units = unit;
	return vol;
}
Example #7
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };
    struct point arrow_points[7] = { {1, -10}, {1, -3}, {4, -4}, {0, 0},
                                     {-4, -4}, {-1, -3}, {-1, -10} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    move_polygon(&uav, ca->width >> 1, ca->height >> 1);
    draw_polygon(&uav, 3, ca);
    move_polygon(&uav, -1, -1);
    draw_polygon(&uav, 1, ca);


    move_polygon(&arrow, 0, -11);
    transform_polygon(&arrow, ca->width >> 1, ca->height >> 1, priv->direction - priv->heading);
    draw_polygon(&arrow, 3, ca);
    move_polygon(&arrow, -1, -1);
    draw_polygon(&arrow, 1, ca);

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            sprintf(buf, "%dkm/h", (int) ((priv->speed * 3600) / 1000));
            break;
        case UNITS_IMPERIAL:
            sprintf(buf, "%dmph", (int) ((priv->speed * 3600) * M2MILE));
            break;
        case UNITS_CUSTOM_1:
            sprintf(buf, "%dm/s", (int) (priv->speed));
            break;
        case UNITS_CUSTOM_2:
            sprintf(buf, "%df/s", (int) (priv->speed * M2FEET));
            break;
        case UNITS_CUSTOM_3:
            sprintf(buf, "%dkn", (int) ((priv->speed * 3600 * 1.852) / 1000));
            break;
    }
    draw_str(buf, 0, 0, ca, 0);
}


const struct widget_ops wind_widget_ops = {
    .name = "Wind information",
    .mavname = "WINDINF",
    .id = WIDGET_WIND_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Example #8
0
static void
cmd_sd(void)
{
   real sd, variance;
   int units;
   unsigned long qmask, m;
   int quantity;
   qmask = get_qlist(BIT(Q_DECLINATION));
   if (!qmask) return; /* no quantities found - error already reported */

   if (qmask == BIT(Q_DEFAULT)) {
      default_grade(pcs);
      return;
   }
   sd = read_numeric(fFalse, NULL);
   if (sd <= (real)0.0) {
      compile_error_skip(-/*Standard deviation must be positive*/48);
      return;
   }
   units = get_units(qmask, fFalse);
   if (units == UNITS_NULL) return;

   sd *= factor_tab[units];
   variance = sqrd(sd);

   for (quantity = 0, m = BIT(quantity); m <= qmask; quantity++, m <<= 1)
      if (qmask & m) pcs->Var[quantity] = variance;
}
Example #9
0
double get_depth_units(unsigned int mm, int *frac, const char **units)
{
	int decimals;
	double d;
	const char *unit;
	struct units *units_p = get_units();

	switch (units_p->length) {
	case METERS:
		d = mm / 1000.0;
		unit = _("m");
		decimals = d < 20;
		break;
	case FEET:
		d = mm_to_feet(mm);
		unit = _("ft");
		decimals = 0;
		break;
	}
	if (frac)
		*frac = decimals;
	if (units)
		*units = unit;
	return d;
}
Example #10
0
static void
cmd_units(void)
{
   int units, quantity;
   unsigned long qmask;
   unsigned long m; /* mask with bit x set to indicate quantity x specified */
   real factor;

   qmask = get_qlist(0);
   if (!qmask) return;
   if (qmask == BIT(Q_DEFAULT)) {
      default_units(pcs);
      return;
   }

   factor = read_numeric(fTrue, NULL);
   if (factor == 0.0) {
      compile_error_skip(-/**UNITS factor must be non-zero*/200);
      return;
   }
   if (factor == HUGE_REAL) factor = (real)1.0;

   units = get_units(qmask, fTrue);
   if (units == UNITS_NULL) return;
   if (TSTBIT(qmask, Q_GRADIENT))
      pcs->f_clino_percent = (units == UNITS_PERCENT);
   if (TSTBIT(qmask, Q_BACKGRADIENT))
      pcs->f_backclino_percent = (units == UNITS_PERCENT);

   factor *= factor_tab[units];

   for (quantity = 0, m = BIT(quantity); m <= qmask; quantity++, m <<= 1)
      if (qmask & m) pcs->units[quantity] = factor;
}
Example #11
0
void PlannerSettingsWidget::settingsChanged()
{
	QString vs;
	// don't recurse into setting the value from the ui when setting the ui from the value
	ui.bottomSAC->blockSignals(true);
	ui.decoStopSAC->blockSignals(true);
	if (get_units()->length == units::FEET) {
		vs.append(tr("ft/min"));
		ui.lastStop->setText(tr("Last stop at 20ft"));
		ui.asc50to6->setText(tr("50% avg. depth to 20ft"));
		ui.asc6toSurf->setText(tr("20ft to surface"));
	} else {
		vs.append(tr("m/min"));
		ui.lastStop->setText(tr("Last stop at 6m"));
		ui.asc50to6->setText(tr("50% avg. depth to 6m"));
		ui.asc6toSurf->setText(tr("6m to surface"));
	}
	if(get_units()->volume == units::CUFT) {
		ui.bottomSAC->setSuffix(tr("cuft/min"));
		ui.decoStopSAC->setSuffix(tr("cuft/min"));
		ui.bottomSAC->setDecimals(2);
		ui.bottomSAC->setSingleStep(0.1);
		ui.decoStopSAC->setDecimals(2);
		ui.decoStopSAC->setSingleStep(0.1);
		ui.bottomSAC->setValue(ml_to_cuft(prefs.bottomsac));
		ui.decoStopSAC->setValue(ml_to_cuft(prefs.decosac));
	} else {
		ui.bottomSAC->setSuffix(tr("ℓ/min"));
		ui.decoStopSAC->setSuffix(tr("ℓ/min"));
		ui.bottomSAC->setDecimals(0);
		ui.bottomSAC->setSingleStep(1);
		ui.decoStopSAC->setDecimals(0);
		ui.decoStopSAC->setSingleStep(1);
		ui.bottomSAC->setValue((double) prefs.bottomsac / 1000.0);
		ui.decoStopSAC->setValue((double) prefs.decosac / 1000.0);
	}
	ui.bottomSAC->blockSignals(false);
	ui.decoStopSAC->blockSignals(false);
	updateUnitsUI();
	ui.ascRate75->setSuffix(vs);
	ui.ascRate50->setSuffix(vs);
	ui.ascRateStops->setSuffix(vs);
	ui.ascRateLast6m->setSuffix(vs);
	ui.descRate->setSuffix(vs);
}
Example #12
0
QString DiveItem::displaySac() const
{
	QString str;
	if (get_units()->volume == units::LITER)
		str = QString::number(dive->sac / 1000.0, 'f', 1).append(tr(" l/min"));
	else
		str = QString::number(ml_to_cuft(dive->sac), 'f', 2).append(tr(" cuft/min"));
	return str;
}
Example #13
0
QString get_weight_string(weight_t weight, bool showunit)
{
	QString str = weight_string (weight.grams);
	if (get_units()->weight == units::KG) {
		str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","kg") : "");
	} else {
		str = QString ("%1%2").arg(str).arg(showunit ? translate("gettextFromC","lbs") : "");
	}
	return (str);
}
Example #14
0
QString DiveItem::displayTemperature() const
{
	QString str;
	if (!dive->watertemp.mkelvin)
		return str;
	if (get_units()->temperature == units::CELSIUS)
		str = QString::number(mkelvin_to_C(dive->watertemp.mkelvin), 'f', 1);
	else
		str = QString::number(mkelvin_to_F(dive->watertemp.mkelvin), 'f', 1);
	return str;
}
Example #15
0
static void render(struct widget *w)
{
    struct home_data *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[50];
    float d, a;
    struct point arrow_points[7] = { {-3, 0}, {-3, -6}, {3, -6}, {3, 0},
                                     {6, 0}, {0, 6}, {-6, 0} };
    struct polygon arrow = {
        .len = 7,
        .points = arrow_points,
    };

    if (priv->lock != HOME_LOCKED) {
        sprintf(buf, "No Home");
        draw_str(buf, 0, 0, ca, 2);
    } else {
        switch (get_units(w->cfg)) {
            case UNITS_METRIC:
            default:
                sprintf(buf, "Alt %dm\nDis %dm\n%d",
                        priv->altitude,
                        (unsigned int) priv->distance,
                        priv->direction);
                break;
            case UNITS_IMPERIAL:
                a = (float) priv->altitude * M2FEET;
                d = (float) priv->distance * M2FEET;
                sprintf(buf, "Alt %df\nDis %df\n%d",
                        (unsigned int) a,
                        (unsigned int) d,
                        priv->direction);
                break;
        }

        draw_str(buf, 0, 0, ca, 1);

        transform_polygon(&arrow, 50, 34, priv->direction + 180);
        draw_polygon(&arrow, 3, ca);
        move_polygon(&arrow, -1, -1);
        draw_polygon(&arrow, 1, ca);
    }
}


const struct widget_ops home_info_widget_ops = {
    .name = "Home info",
    .mavname = "HOMEINF",
    .id = WIDGET_HOME_INFO_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};
Example #16
0
void DivePlannerWidget::settingsChanged()
{
	// Adopt units
	if (get_units()->length == units::FEET) {
		ui.atmHeight->setSuffix("ft");
	} else {
		ui.atmHeight->setSuffix(("m"));
	}
	ui.atmHeight->blockSignals(true);
	ui.atmHeight->setValue((int) get_depth_units((int) (log(1013.0 / plannerModel->getSurfacePressure()) * 7800000), NULL,NULL));
	ui.atmHeight->blockSignals(false);
}
Example #17
0
/** Render the number of credits */
void credits_render (void)
{
#ifdef FREE_ONLY
	sprintf ("FREE ONLY");
#else
	if (price_config.free_play)
		sprintf ("FREE PLAY");
	else
	{
		if (get_units () != 0)
		{
			U8 units = get_units ();
			U8 units_per_credit = price_config.units_per_credit;

			/* There are fractional credits.  Reduce to the
			 * lowest common denominator before printing. */

			reduce_unit_fraction (&units, &units_per_credit);

			if (get_credits () == 0)
				sprintf ("%d/%d CREDIT", units, units_per_credit);
			else
				sprintf ("%d %d/%d CREDITS",
					get_credits (), units, units_per_credit);
		}
		else
		{
			if (get_credits () == 1)
				sprintf ("%d CREDIT", get_credits ());
			else
				sprintf ("%d CREDITS", get_credits ());
		}
	}
#endif
	if (diag_get_error_count ())
	{
		sprintf ("%E.");
	}
}
Example #18
0
QString DiveItem::displayWeight() const
{
	QString str;

	if (get_units()->weight == units::KG) {
		int gr = weight() % 1000;
		int kg = weight() / 1000;
		str = QString("%1.%2").arg(kg).arg((unsigned)(gr) / 100);
	} else {
		str = QString("%1").arg((unsigned)(grams_to_lbs(weight())));
	}

	return str;
}
Example #19
0
static void render(struct widget *w)
{
    struct canvas *ca = &w->ca;
    char buf[10];
    mavlink_scaled_pressure_t *sp = mavdata_get(MAVLINK_MSG_ID_SCALED_PRESSURE);
    float temperature = sp->temperature / 100.0;
    char unit_char = 'C';

    if (get_units(w->cfg) == UNITS_IMPERIAL) {
        temperature = temperature * 1.8 + 32;
        unit_char = 'F';
    }
    
    sprintf(buf, "%.2f%c", (double) temperature, unit_char);
    draw_jstr(buf, X_SIZE, Y_SIZE/2, JUST_RIGHT | JUST_VCENTER, ca, 2);
}
Example #20
0
double get_temp_units(unsigned int mk, const char **units)
{
	double deg;
	const char *unit;
	struct units *units_p = get_units();

	if (units_p->temperature == FAHRENHEIT) {
		deg = mkelvin_to_F(mk);
		unit = UTF8_DEGREE "F";
	} else {
		deg = mkelvin_to_C(mk);
		unit = UTF8_DEGREE "C";
	}
	if (units)
		*units = unit;
	return deg;
}
Example #21
0
QString weight_string(int weight_in_grams)
{
	QString str;
	if (get_units()->weight == units::KG) {
		int gr = weight_in_grams % 1000;
		int kg = weight_in_grams / 1000;
		if (kg >= 20.0) {
			str = QString("0");
		} else {
			str = QString("%1.%2").arg(kg).arg((unsigned)(gr) / 100);
		}
	} else {
		double lbs = grams_to_lbs(weight_in_grams);
		str = QString("%1").arg(lbs, 0, 'f', lbs >= 40.0 ? 0 : 1);
	}
	return (str);
}
Example #22
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10], text[5];
    int speed_i;

    switch (get_units(w->cfg)) {
        case UNITS_METRIC:
        default:
            speed_i = (int) ((priv->speed * 3600) / 1000);
            strcpy(text, "km/h");
            break;
        case UNITS_IMPERIAL:
            speed_i = (int) ((priv->speed * 3600) * M2MILE);
            strcpy(text, "mph");
            break;
        case UNITS_CUSTOM_1:
            speed_i = (int) (priv->speed);
            strcpy(text, "m/s");
            break;
        case UNITS_CUSTOM_2:
            speed_i = (int) (priv->speed * M2FEET);
            strcpy(text, "f/s");
            break;
        case UNITS_CUSTOM_3:
            speed_i = (int) ((priv->speed * 3600 * 1.852) / 1000);
            strcpy(text, "kn");
            break;
    }
    
    switch (w->cfg->props.mode) {
        case 0:
        default:
            render_gauge(w, speed_i);
            break;
        case 1:
            snprintf(buf, 10, "%d%s", speed_i, text);
            draw_jstr(buf, X_SIZE_TEXT - 1, 10, JUST_RIGHT | JUST_VCENTER, ca, 1);
            break;
    }
}
void TestUnitConversion::testUnitConversions()
{
	QCOMPARE(IS_FP_SAME(grams_to_lbs(1000), 2.204586), true);
	QCOMPARE(lbs_to_grams(1), 454);
	QCOMPARE(IS_FP_SAME(ml_to_cuft(1000), 0.0353147), true);
	QCOMPARE(IS_FP_SAME(cuft_to_l(1), 28.316847), true);
	QCOMPARE(IS_FP_SAME(mm_to_feet(1000), 3.280840), true);
	QCOMPARE(feet_to_mm(1), (long unsigned int) 305);
	QCOMPARE(to_feet((depth_t){ 1000 }), 3);
	QCOMPARE(IS_FP_SAME(mkelvin_to_C(647000), 373.85), true);
	QCOMPARE(IS_FP_SAME(mkelvin_to_F(647000), 704.93), true);
	QCOMPARE(F_to_mkelvin(704.93), (unsigned long)647000);
	QCOMPARE(C_to_mkelvin(373.85), (unsigned long)647000);
	QCOMPARE(IS_FP_SAME(psi_to_bar(14.6959488), 1.01325), true);
	QCOMPARE(psi_to_mbar(14.6959488), (long)1013);
	QCOMPARE(to_PSI((pressure_t){ 1013 }), (int)15);
	QCOMPARE(IS_FP_SAME(bar_to_atm(1.013), 1.0), true);
	QCOMPARE(IS_FP_SAME(mbar_to_atm(1013), 1.0), true);
	QCOMPARE(mbar_to_PSI(1013), (int)15);
	get_units();
}
Example #24
0
void PlannerSettingsWidget::settingsChanged()
{
	QString vs;
	if (get_units()->length == units::FEET) {
		vs.append(tr("ft/min"));
		ui.lastStop->setText(tr("Last stop at 20ft"));
		ui.asc50to6->setText(tr("50% avg. depth to 20ft"));
		ui.asc6toSurf->setText(tr("20ft to surface"));
	} else {
		vs.append(tr("m/min"));
		ui.lastStop->setText(tr("Last stop at 6m"));
		ui.asc50to6->setText(tr("50% avg. depth to 6m"));
		ui.asc6toSurf->setText(tr("6m to surface"));
	}
	updateUnitsUI();
	ui.ascRate75->setSuffix(vs);
	ui.ascRate50->setSuffix(vs);
	ui.ascRateStops->setSuffix(vs);
	ui.ascRateLast6m->setSuffix(vs);
	ui.descRate->setSuffix(vs);
}
Example #25
0
double get_weight_units(unsigned int grams, int *frac, const char **units)
{
	int decimals;
	double value;
	const char* unit;
	struct units *units_p = get_units();

	if (units_p->weight == LBS) {
		value = grams_to_lbs(grams);
		unit = _("lbs");
		decimals = 0;
	} else {
		value = grams / 1000.0;
		unit = _("kg");
		decimals = 1;
	}
	if (frac)
		*frac = decimals;
	if (units)
		*units = unit;
	return value;
}
Example #26
0
double get_vertical_speed_units(unsigned int mms, int *frac, const char **units)
{
	double d;
	const char *unit;
	const struct units *units_p = get_units();
	const double time_factor = units_p->vertical_speed_time == MINUTES ? 60.0 : 1.0;

	switch (units_p->length) {
	case METERS:
		d = mms / 1000.0 * time_factor;
		unit = translate("gettextFromC",(units_p->vertical_speed_time == MINUTES) ? "m/min" : "m/s");
		break;
	case FEET:
		d = mm_to_feet(mms) * time_factor;
		unit = translate("gettextFromC",(units_p->vertical_speed_time == MINUTES) ? "ft/min" : "ft/s");
		break;
	}
	if (frac)
		*frac = d < 10;
	if (units)
		*units = unit;
	return d;
}
Example #27
0
int get_pressure_units(unsigned int mb, const char **units)
{
	int pressure;
	const char* unit;
	struct units *units_p = get_units();

	switch (units_p->pressure) {
	case PASCAL:
		pressure = mb * 100;
		unit = _("pascal");
		break;
	case BAR:
		pressure = (mb + 500) / 1000;
		unit = _("bar");
		break;
	case PSI:
		pressure = mbar_to_PSI(mb);
		unit = _("psi");
		break;
	}
	if (units)
		*units = unit;
	return pressure;
}
Example #28
0
int main(int argc, char *argv[])
{

    char cdf_name[250];

    /***************** declared local pointers to store returned attribute value pointers ************/

    char *char_attribute_valuePtr;
    int *int_attribute_valuePtr;
    float *float_attribute_valuePtr;

    if (argc != 2)
    {
        printf("ERROR:this example program requires 1 argument - full path and file name of data file\n");
        exit( EXIT_FAILURE);
    }

    strcpy(cdf_name, argv[1]);

    open_cdf(cdf_name, 0);

    printf("Open %s complete...\n", cdf_name);

    /*** get the README GLOBAL ATTRIBUTE value ***/

    if (attribute_exists("README") )
        char_attribute_valuePtr = gattribute_get("README");
    if (attribute_exists("README") )
    {
        printf("\n\nREADME attribute = %s\n", char_attribute_valuePtr);
    }

    /*** get the grid_system_count global attribute value ***/

    if (attribute_exists("grid_system_count") )
        int_attribute_valuePtr = gattribute_get("grid_system_count");
    if (attribute_exists("grid_system_count") )
    {
        printf("\ngrid_system_count attribute = %d\n\n",
                *int_attribute_valuePtr);
    }

    /*** test for the existence of gattributes ***/

    printf("attribute_exists( \"model_name\" ) = %d\n",
            attribute_exists("model_name") );
    printf("attribute_exists( \"model_type\" ) = %d\n",
            attribute_exists("model_type") );
    printf("attribute_exists( \"elapsed_time_in_seconds\") = %d\n",
            attribute_exists("elapsed_time_in_seconds") );
    printf("attribute_exists( \"horse_power\") = %d\n",
            attribute_exists("horse_power") );
    printf("attribute_exists( \"units\") = %d\n", attribute_exists("units") );

    /*** get the elapsed_time_in_seconds global attribute value ***/

    if (attribute_exists("elapsed_time_in_seconds") )
        float_attribute_valuePtr = gattribute_get("elapsed_time_in_seconds");
    if (attribute_exists("elapsed_time_in_seconds") )
    {
        printf("\nelapsed_time_in_seconds attribute = %f\n",
                *float_attribute_valuePtr);
    }

    /*** get the description variable ATTRIBUTE value for x ***/

    if (var_exists("x") && attribute_exists("description") )
        char_attribute_valuePtr = vattribute_get("x", "description");
    if (var_exists("x") && attribute_exists("description") )
    {
        printf("\ndescription attribute = %s\n", char_attribute_valuePtr);
    }

    /*** get the is_vector_component variable attribute value for bx ***/

    if (var_exists("bx") && attribute_exists("is_vector_component") )
        int_attribute_valuePtr = vattribute_get("bx", "is_vector_component");
    if (var_exists("bx") && attribute_exists("is_vector_component") )
    {
        printf("\nis_vector_component attribute = %d\n",
                *int_attribute_valuePtr);
    }

    /*** get the valid_min variable attribute value for rho***/

    if (var_exists("rho") && attribute_exists("valid_min") )
        float_attribute_valuePtr = vattribute_get("rho", "valid_min");
    if (var_exists("rho") && attribute_exists("valid_min") )
    {
        printf("\nvalid_min attribute = %f\n", *float_attribute_valuePtr);
    }

    /*** get the units variable attribute value for rho***/

    if (var_exists("rho") && attribute_exists("units") )
        char_attribute_valuePtr = vattribute_get("rho", "units");
    if (var_exists("rho") && attribute_exists("units") )
    {
        printf("\nunits attribute = %s\n", char_attribute_valuePtr);
    }

    printf("DEBUG\tlegacy stuff\n\n\n\n");

    /********** legacy routines... before generic *attribute_get routines were available ***/

    /** char * get_units( "variable_name" ); **/

    if (var_exists("x") && attribute_exists("units") )
        printf(
                "\nAN example of using the get_units() routine:  units for X = %s\n",
                get_units("x") );

    /*** float gattribute_float_get( "global_attribute_name" ); **/

    if (attribute_exists("elapsed_time_in_seconds") )
        printf(
                "\nAN example of using the gattribute_float_get() routine:  elapsed_time_in_seconds %f\n",
                gattribute_float_get("elapsed_time_in_seconds") );

    /*** char * gattribute_char_get( "global_attribute_name" ); **/

    if (attribute_exists("model_name") )
        printf(
                "\nAN example of using the gattribute_char_get() routine, model_name = %s\n",
                gattribute_char_get("model_name") );

    return 1;
}
Example #29
0
QVariant ProfilePrintModel::data(const QModelIndex &index, int role) const
{
	const int row = index.row();
	const int col = index.column();

	switch (role) {
	case Qt::DisplayRole: {
		struct DiveItem di;
		di.dive = dive;
		char buf[80];

		const QString unknown = tr("unknown");

		// dive# + date, depth, location, duration
		if (row == 0) {
			if (col == 0)
				return tr("Dive #%1 - %2").arg(dive->number).arg(di.displayDate());
			if (col == 5) {
				QString unit = (get_units()->length == units::METERS) ? "m" : "ft";
				return tr("Max depth: %1 %2").arg(di.displayDepth()).arg(unit);
			}
		}
		if (row == 1) {
			if (col == 0)
				return truncateString(dive->location, 32);
			if (col == 5)
				return QString(tr("Duration: %1 min")).arg(di.displayDuration());
		}
		// cylinder headings
		if (row == 2) {
			if (col == 0)
				return tr("Cylinder");
			if (col == 1)
				return tr("Gasmix");
			if (col == 2)
				return tr("Gas Used");
		}
		// cylinder data
		if (row > 2 && row < 10 && row - 3 < MAX_CYLINDERS) {
			cylinder_t *cyl = &dive->cylinder[row - 3];
			if (cyl->type.description) { // how do we check if a cylinder is added?
				if (col == 0) {
					if (cyl->type.description[0] != '\0')
						return QString(cyl->type.description);
					return unknown;
				}
				if (col == 1) {
					get_gas_string(cyl->gasmix.o2.permille, cyl->gasmix.he.permille, buf, sizeof(buf));
					return QString(buf);
				}
				if (col == 2) {
					return get_cylinder_used_gas_string(cyl, true);
				}
			}
		}
		// dive notes
		if (row == 10 && col == 0)
			return truncateString(dive->notes, 640);
		// sac, cns, otu - headings
		if (col == 3) {
			if (row == 2)
				return tr("SAC");
			if (row == 4)
				return tr("Max. CNS");
			if (row == 6)
				return tr("OTU");
		}
		// sac, cns, otu - data
		if (col == 4) {
			if (row == 2)
				return di.displaySac();
			if (row == 4)
				return QString::number(dive->maxcns);
			if (row == 6)
				return QString::number(dive->otu);
		}
		// weights heading
		if (row == 2 && col == 5)
			return tr("Weights");
		// total weight
		if (row == 9) {
			weight_t tw = { total_weight(dive) };
			if (tw.grams) {
				if (col == 5)
					return tr("Total weight");
				if (col == 6)
					return get_weight_string(tw, true);
			}
		}
		// weight data
		if (row > 2 && row < 10 && row - 3 < MAX_WEIGHTSYSTEMS) {
			weightsystem_t *ws = &dive->weightsystem[row - 3];
			if (ws->weight.grams) {
				if (col == 5) {
					if (ws->description && ws->description[0] != '\0')
						return QString(ws->description);
					return unknown;
				}
				if (col == 6) {
					return get_weight_string(ws->weight, true);
				}
			}
		}
		return QString();
	}
	case Qt::FontRole: {
		QFont font;
		const int baseSize = 9;
		// dive #
		if (row == 0 && col == 0) {
			font.setBold(true);
			font.setPixelSize(baseSize + 1);
			return QVariant::fromValue(font);
		}
		// dive location
		if (row == 1 && col == 0) {
			font.setPixelSize(baseSize);
			font.setBold(true);
			return QVariant::fromValue(font);
		}
		// depth/duration
		if ((row == 0 || row == 1) && col == 5) {
			font.setPixelSize(baseSize);
			return QVariant::fromValue(font);
		}
		// notes
		if (row == 9 && col == 0) {
			font.setPixelSize(baseSize + 1);
			return QVariant::fromValue(font);
		}
		font.setPixelSize(baseSize);
		return QVariant::fromValue(font);
	}
	case Qt::TextAlignmentRole: {
		unsigned int align = Qt::AlignCenter;
		// dive #, location, notes
		if ((row < 2 || row == 10) && col == 0)
			align = Qt::AlignLeft | Qt::AlignVCenter;
		// depth, duration
		if (row < 2 && col == 5)
			align = Qt::AlignRight | Qt::AlignVCenter;
		return QVariant::fromValue(align);
	}
	} // switch (role)
	return QVariant();
}
Example #30
0
static void render(struct widget *w)
{
    struct widget_priv *priv = w->priv;
    struct canvas *ca = &w->ca;
    char buf[10];
    unsigned long d = (unsigned long) priv->home->distance;
    unsigned int r = (w->ca.width/2)-2;
    int x, y;
    int min_increment;
    long i, scale;
    struct point ils_points[5] = { {-4, -6}, {-4, 6}, {0, 10}, {4, 6}, {4, -6} };
    struct polygon ils = {
        .len = 5,
        .points = ils_points,
    };
    struct point uav_points[4] = { {0, 0}, {6, 8}, {0, -8}, {-6, 8} };
    struct polygon uav = {
        .len = 4,
        .points = uav_points,
    };

    struct polygon *p;

    x = (w->ca.width/2)-1;
    y = (w->ca.height/2)-1;


    draw_vline(x, 0, r*2, 2, ca);
    draw_hline(0, r*2, y, 2, ca);

    //draw_circle(x, y, r+1, 3, ca);
    draw_circle(x, y, r  , 2, ca);


    /* auto scale */
    switch (get_units(w->cfg)) {
    default:
    case UNITS_METRIC:
        min_increment = 500;
        scale = ((d / min_increment) + 1) * min_increment;
        sprintf(buf, "%um", (unsigned int) scale);
        break;
    case UNITS_IMPERIAL:
        d *= M2FEET;
        min_increment = 1000;
        scale = ((d / min_increment) + 1) * min_increment;
        if (d > 5000) {
            d = (d * 1000) / MILE2FEET;
            scale /= 1000;
            sprintf(buf, "%umi", (unsigned int) scale);
        } else {
            sprintf(buf, "%uf", (unsigned int) scale);
        }
        break;
    }

    draw_str(buf, 0, 0, ca, 0);

    i = (long) d * r;
    i /= scale;

    switch (w->cfg->props.mode >> 1) {
    case 0:
    default:
        /* radar fixed at uav heading, home moves */
        x += sin(DEG2RAD(priv->home->direction)) * i;
        y -= cos(DEG2RAD(priv->home->direction)) * i;
        transform_polygon(&ils, x, y, priv->stats->launch_heading - priv->heading - 180);
        p = &ils;
        break;
    case 1:
        /* radar always facing north, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    case 2:
        /* radar always facing launch direction, uav moves */
        x += sin(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing - priv->stats->launch_heading)) * i;
        transform_polygon(&uav, x, y, priv->heading - priv->stats->launch_heading);
        p = &uav;
        break;
    case 3:
        /* testing waypoints */
        /* radar always facing north, uav moves with waypoints */
        if (priv->wp_seq > 0) {
            long i_wp = (long) priv->wp_distance * r;
            i_wp /= scale;
            int x_wp = x, y_wp = y;
            x_wp += sin(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            y_wp -= cos(DEG2RAD(priv->wp_target_bearing - priv->heading)) * i_wp;
            sprintf(buf, "%d", priv->wp_seq);
            draw_str(buf, x_wp, y_wp, ca, 0);
        }
        x += sin(DEG2RAD(priv->home->uav_bearing)) * i;
        y -= cos(DEG2RAD(priv->home->uav_bearing)) * i;
        transform_polygon(&uav, x, y, priv->heading);
        p = &uav;
        break;
    }

    draw_polygon(p, 3, ca);
    move_polygon(p, -1, -1);
    draw_polygon(p, 1, ca);
}


const struct widget_ops radar_widget_ops = {
    .name = "Radar",
    .mavname = "RADAR",
    .id = WIDGET_RADAR_ID,
    .init = NULL,
    .open = open,
    .render = render,
    .close = NULL,
};