void DivePlannerPointsModel::createTemporaryPlan() { // Get the user-input and calculate the dive info free_dps(&diveplan); int lastIndex = -1; for (int i = 0; i < rowCount(); i++) { divedatapoint p = at(i); int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time; lastIndex = i; if (i == 0 && prefs.drop_stone_mode) { /* Okay, we add a fist segment where we go down to depth */ plan_add_segment(&diveplan, p.depth / prefs.descrate, p.depth, p.gasmix, p.setpoint, true); deltaT -= p.depth / prefs.descrate; } if (p.entered) plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.setpoint, true); } // what does the cache do??? char *cache = NULL; struct divedatapoint *dp = NULL; for (int i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = &displayed_dive.cylinder[i]; if (cyl->depth.mm) { dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0); if (diveplan.dp) { dp->next = diveplan.dp; diveplan.dp = dp; } else { dp->next = NULL; diveplan.dp = dp; } } } #if DEBUG_PLAN dump_plan(&diveplan); #endif if (recalcQ() && !diveplan_empty(&diveplan)) { plan(&diveplan, &cache, isPlanner(), false); /* TODO: * Hook this signal to the mainwindow(s), the call to MainWindow * can't be here as we are now dealing with QML too. */ //MainWindow::instance()->setPlanNotes(displayed_dive.notes); emit calculatedPlanNotes(displayed_dive.notes); } // throw away the cache free(cache); #if DEBUG_PLAN save_dive(stderr, &displayed_dive); dump_plan(&diveplan); #endif }
void DivePlannerPointsModel::createTemporaryPlan() { // Get the user-input and calculate the dive info free_dps(&diveplan); int lastIndex = -1; for (int i = 0; i < rowCount(); i++) { divedatapoint p = at(i); int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time; lastIndex = i; if (i == 0 && mode == PLAN && prefs.drop_stone_mode) { /* Okay, we add a first segment where we go down to depth */ plan_add_segment(&diveplan, p.depth.mm / prefs.descrate, p.depth.mm, p.cylinderid, p.setpoint, true); deltaT -= p.depth.mm / prefs.descrate; } if (p.entered) plan_add_segment(&diveplan, deltaT, p.depth.mm, p.cylinderid, p.setpoint, true); } // what does the cache do??? struct deco_state *cache = NULL; struct divedatapoint *dp = NULL; for (int i = 0; i < MAX_CYLINDERS; i++) { cylinder_t *cyl = &displayed_dive.cylinder[i]; if (cyl->depth.mm && cyl->cylinder_use != NOT_USED) { dp = create_dp(0, cyl->depth.mm, i, 0); if (diveplan.dp) { dp->next = diveplan.dp; diveplan.dp = dp; } else { dp->next = NULL; diveplan.dp = dp; } } } #if DEBUG_PLAN dump_plan(&diveplan); #endif if (recalcQ() && !diveplan_empty(&diveplan)) { struct decostop stoptable[60]; plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), false); computeVariations(); emit calculatedPlanNotes(); } // throw away the cache free(cache); #if DEBUG_PLAN save_dive(stderr, &displayed_dive); dump_plan(&diveplan); #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; }