// copy the tanks from the current dive, or the default cylinder // or an unknown cylinder // setup the cylinder widget accordingly void DivePlannerPointsModel::setupCylinders() { int i; if (mode == PLAN && current_dive) { // take the displayed cylinders from the selected dive as starting point CylindersModel::instance()->copyFromDive(current_dive); copy_cylinders(current_dive, &displayed_dive, !prefs.display_unused_tanks); reset_cylinders(&displayed_dive, true); for (i = 0; i < MAX_CYLINDERS; i++) if (!cylinder_none(&(displayed_dive.cylinder[i]))) return; // We have at least one cylinder } if (!same_string(prefs.default_cylinder, "")) { fill_default_cylinder(&displayed_dive.cylinder[0]); } if (cylinder_none(&displayed_dive.cylinder[0])) { // roughly an AL80 displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData()); displayed_dive.cylinder[0].type.size.mliter = 11100; displayed_dive.cylinder[0].type.workingpressure.mbar = 207000; } reset_cylinders(&displayed_dive, false); CylindersModel::instance()->copyFromDive(&displayed_dive); }
void setupPlan(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->gfhigh = 100; dp->gflow = 100; dp->bottomsac = 0; dp->decosac = 0; struct gasmix bottomgas = { {150}, {450} }; struct gasmix ean36 = { {360}, {0} }; struct gasmix oxygen = { {1000}, {0} }; pressure_t po2 = { 1600 }; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[1].gasmix = ean36; displayed_dive.cylinder[2].gasmix = oxygen; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(79, 260) * 60 / M_OR_FT(23, 75); plan_add_segment(dp, droptime, M_OR_FT(79, 260), bottomgas, 0, 1); plan_add_segment(dp, 30*60 - droptime, M_OR_FT(79, 260), bottomgas, 0, 1); plan_add_segment(dp, 0, gas_mod(&ean36, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean36, 0, 1); plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); }
void setupPlanVpmb60m10mTx(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->gfhigh = 100; dp->gflow = 100; dp->bottomsac = prefs.bottomsac; dp->decosac = prefs.decosac; struct gasmix bottomgas = {{180}, {450}}; struct gasmix tx50_15 = {{500}, {150}}; struct gasmix oxygen = {{1000}, {0}}; pressure_t po2 = {1600}; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[0].type.size.mliter = 24000; displayed_dive.cylinder[0].type.workingpressure.mbar = 232000; displayed_dive.cylinder[1].gasmix = tx50_15; displayed_dive.cylinder[2].gasmix = oxygen; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(23, 75); plan_add_segment(dp, 0, gas_mod(tx50_15, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC); plan_add_segment(dp, 0, gas_mod(oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC); plan_add_segment(dp, droptime, M_OR_FT(60, 200), 0, 0, 1, OC); plan_add_segment(dp, 10 * 60 - droptime, M_OR_FT(60, 200), 0, 0, 1, OC); }
void setupPlanVpmb100mTo70m30min(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = 0; dp->decosac = 0; struct gasmix bottomgas = { {120}, {650} }; struct gasmix tx21_35 = { {210}, {350} }; struct gasmix ean50 = { {500}, {0} }; struct gasmix oxygen = { {1000}, {0} }; pressure_t po2 = { 1600 }; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[1].gasmix = tx21_35; displayed_dive.cylinder[2].gasmix = ean50; displayed_dive.cylinder[3].gasmix = oxygen; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(18, 60); plan_add_segment(dp, droptime, M_OR_FT(100, 330), bottomgas, 0, 1); plan_add_segment(dp, 20*60 - droptime, M_OR_FT(100, 330), bottomgas, 0, 1); plan_add_segment(dp, 3*60, M_OR_FT(70, 230), bottomgas, 0, 1); plan_add_segment(dp, (30 - 20 - 3) * 60, M_OR_FT(70, 230), bottomgas, 0, 1); plan_add_segment(dp, 0, gas_mod(&tx21_35, po2, &displayed_dive, M_OR_FT(3,10)).mm, tx21_35, 0, 1); plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); }
void setupPlanVpmb100m10min(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = prefs.bottomsac; dp->decosac = prefs.decosac; struct gasmix bottomgas = {{180}, {450}}; struct gasmix ean50 = {{500}, {0}}; struct gasmix oxygen = {{1000}, {0}}; pressure_t po2 = {1600}; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[0].type.size.mliter = 60000; displayed_dive.cylinder[0].type.workingpressure.mbar = 232000; displayed_dive.cylinder[1].gasmix = ean50; displayed_dive.cylinder[2].gasmix = oxygen; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330); plan_add_segment(dp, 0, gas_mod(ean50, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 1, 0, 1, OC); plan_add_segment(dp, 0, gas_mod(oxygen, po2, &displayed_dive, M_OR_FT(3, 10)).mm, 2, 0, 1, OC); plan_add_segment(dp, droptime, M_OR_FT(100, 330), 0, 0, 1, OC); plan_add_segment(dp, 10 * 60 - droptime, M_OR_FT(100, 330), 0, 0, 1, OC); }
// copy the tanks from the current dive, or the default cylinder // or an unknown cylinder // setup the cylinder widget accordingly void DivePlannerPointsModel::setupCylinders() { if (mode == PLAN && current_dive) { // take the used cylinders from the selected dive as starting point CylindersModel::instance()->copyFromDive(current_dive); copy_cylinders(current_dive, &displayed_dive, true); reset_cylinders(&displayed_dive, true); return; } if (!same_string(prefs.default_cylinder, "")) { fill_default_cylinder(&displayed_dive.cylinder[0]); } else { // roughly an AL80 displayed_dive.cylinder[0].type.description = strdup(tr("unknown").toUtf8().constData()); displayed_dive.cylinder[0].type.size.mliter = 11100; displayed_dive.cylinder[0].type.workingpressure.mbar = 207000; } reset_cylinders(&displayed_dive, false); CylindersModel::instance()->copyFromDive(&displayed_dive); }
void setupPlanVpmb60m30minAir(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = 0; dp->decosac = 0; struct gasmix bottomgas = { {210}, {0} }; pressure_t po2 = { 1600 }; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(60, 200) * 60 / M_OR_FT(99, 330); plan_add_segment(dp, droptime, M_OR_FT(60, 200), bottomgas, 0, 1); plan_add_segment(dp, 30*60 - droptime, M_OR_FT(60, 200), bottomgas, 0, 1); }
void setupPlanVpmb30m20min(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = prefs.bottomsac; dp->decosac = prefs.decosac; struct gasmix bottomgas = {{210}, {0}}; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[0].type.size.mliter = 36000; displayed_dive.cylinder[0].type.workingpressure.mbar = 232000; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(30, 100) * 60 / M_OR_FT(18, 60); plan_add_segment(dp, droptime, M_OR_FT(30, 100), 0, 0, 1, OC); plan_add_segment(dp, 20 * 60 - droptime, M_OR_FT(30, 100), 0, 0, 1, OC); }
void setupPlanSeveralGases(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = prefs.bottomsac; dp->decosac = prefs.decosac; struct gasmix ean36 = {{360}, {0}}; struct gasmix tx11_50 = {{110}, {500}}; displayed_dive.cylinder[0].gasmix = ean36; displayed_dive.cylinder[0].type.size.mliter = 36000; displayed_dive.cylinder[0].type.workingpressure.mbar = 232000; displayed_dive.cylinder[1].gasmix = tx11_50; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); plan_add_segment(dp, 120, 40000, 0, 0, true, OC); plan_add_segment(dp, 18 * 60, 40000, 0, 0, true, OC); plan_add_segment(dp, 10 * 60, 10000, 1, 0, true, OC); plan_add_segment(dp, 5 * 60, 10000, 0, 0, true, OC); }
void setupPlanVpmb100m60min(struct diveplan *dp) { dp->salinity = 10300; dp->surface_pressure = 1013; dp->bottomsac = 0; dp->decosac = 0; struct gasmix bottomgas = { {180}, {450} }; struct gasmix ean50 = { {500}, {0} }; struct gasmix oxygen = { {1000}, {0} }; pressure_t po2 = { 1600 }; displayed_dive.cylinder[0].gasmix = bottomgas; displayed_dive.cylinder[1].gasmix = ean50; displayed_dive.cylinder[2].gasmix = oxygen; displayed_dive.surface_pressure.mbar = 1013; reset_cylinders(&displayed_dive, true); free_dps(dp); int droptime = M_OR_FT(100, 330) * 60 / M_OR_FT(99, 330); plan_add_segment(dp, droptime, M_OR_FT(100, 330), bottomgas, 0, 1); plan_add_segment(dp, 60*60 - droptime, M_OR_FT(100, 330), bottomgas, 0, 1); plan_add_segment(dp, 0, gas_mod(&ean50, po2, &displayed_dive, M_OR_FT(3,10)).mm, ean50, 0, 1); plan_add_segment(dp, 0, gas_mod(&oxygen, po2, &displayed_dive, M_OR_FT(3,10)).mm, oxygen, 0, 1); }
void MainWindow::on_actionReplanDive_triggered() { if (!plannerStateClean()) return; if (!current_dive || !current_dive->dc.model || strcmp(current_dive->dc.model, "planned dive")) { qDebug() << "trying to replan a dive that's not a planned dive:" << current_dive->dc.model; return; } // put us in PLAN mode DivePlannerPointsModel::instance()->clear(); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); ui.newProfile->setPlanState(); ui.newProfile->clearHandlers(); ui.infoPane->setCurrentIndex(PLANNERWIDGET); ui.divePlannerWidget->setReplanButton(true); DivePlannerPointsModel::instance()->loadFromDive(current_dive); reset_cylinders(&displayed_dive, true); ui.diveListPane->setCurrentIndex(1); // switch to the plan output ui.globePane->setCurrentIndex(1); #ifdef NO_MARBLE ui.globePane->show(); #endif }
/* simply overwrite the data in the displayed_dive * return false if something goes wrong */ static void create_dive_from_plan(struct diveplan *diveplan, bool track_gas) { struct divedatapoint *dp; struct divecomputer *dc; struct sample *sample; struct gasmix oldgasmix; struct event *ev; cylinder_t *cyl; int oldpo2 = 0; int lasttime = 0; int lastdepth = 0; if (!diveplan || !diveplan->dp) return; #if DEBUG_PLAN & 4 printf("in create_dive_from_plan\n"); dump_plan(diveplan); #endif // reset the cylinders and clear out the samples and events of the // displayed dive so we can restart reset_cylinders(&displayed_dive, track_gas); dc = &displayed_dive.dc; free(dc->sample); dc->sample = NULL; dc->samples = 0; dc->alloc_samples = 0; while ((ev = dc->events)) { dc->events = dc->events->next; free(ev); } dp = diveplan->dp; cyl = &displayed_dive.cylinder[0]; oldgasmix = cyl->gasmix; sample = prepare_sample(dc); sample->po2.mbar = dp->po2; if (track_gas && cyl->type.workingpressure.mbar) sample->cylinderpressure.mbar = cyl->end.mbar; finish_sample(dc); while (dp) { struct gasmix gasmix = dp->gasmix; int po2 = dp->po2; int time = dp->time; int depth = dp->depth; if (time == 0) { /* special entries that just inform the algorithm about * additional gases that are available */ if (verify_gas_exists(gasmix) < 0) goto gas_error_exit; dp = dp->next; continue; } /* Check for SetPoint change */ if (oldpo2 != po2) { if (lasttime) /* this is a bad idea - we should get a different SAMPLE_EVENT type * reserved for this in libdivecomputer... overloading SMAPLE_EVENT_PO2 * with a different meaning will only cause confusion elsewhere in the code */ add_event(dc, lasttime, SAMPLE_EVENT_PO2, 0, po2, "SP change"); oldpo2 = po2; } /* Make sure we have the new gas, and create a gas change event */ if (gasmix_distance(&gasmix, &oldgasmix) > 0) { int idx; if ((idx = verify_gas_exists(gasmix)) < 0) goto gas_error_exit; /* need to insert a first sample for the new gas */ add_gas_switch_event(&displayed_dive, dc, lasttime + 1, idx); cyl = &displayed_dive.cylinder[idx]; sample = prepare_sample(dc); sample[-1].po2.mbar = po2; sample->time.seconds = lasttime + 1; sample->depth.mm = lastdepth; if (track_gas && cyl->type.workingpressure.mbar) sample->cylinderpressure.mbar = cyl->sample_end.mbar; finish_sample(dc); oldgasmix = gasmix; } /* Create sample */ sample = prepare_sample(dc); /* set po2 at beginning of this segment */ /* and keep it valid for last sample - where it likely doesn't matter */ sample[-1].po2.mbar = po2; sample->po2.mbar = po2; sample->time.seconds = lasttime = time; sample->depth.mm = lastdepth = depth; if (track_gas) { update_cylinder_pressure(&displayed_dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds, dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl, !dp->entered); if (cyl->type.workingpressure.mbar) sample->cylinderpressure.mbar = cyl->end.mbar; } finish_sample(dc); dp = dp->next; } #if DEBUG_PLAN & 32 save_dive(stdout, &displayed_dive); #endif return; gas_error_exit: report_error(translate("gettextFromC", "Too many gas mixes")); return; }