void DivePlannerPointsModel::createPlan() { // Ok, so, here the diveplan creates a dive char *cache = NULL; bool oldRecalc = plannerModel->setRecalc(false); removeDeco(); createTemporaryPlan(); plannerModel->setRecalc(oldRecalc); //TODO: C-based function here? plan(&diveplan, &cache, isPlanner(), true); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table fixup_dive(&displayed_dive); copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
void DivePlannerPointsModel::createPlan(bool replanCopy) { // Ok, so, here the diveplan creates a dive struct deco_state *cache = NULL; bool oldRecalc = setRecalc(false); removeDeco(); createTemporaryPlan(); setRecalc(oldRecalc); //TODO: C-based function here? struct decostop stoptable[60]; plan(&diveplan, &displayed_dive, DECOTIMESTEP, stoptable, &cache, isPlanner(), true); free(cache); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table displayed_dive.maxdepth.mm = 0; displayed_dive.dc.maxdepth.mm = 0; fixup_dive(&displayed_dive); // Try to identify old planner output and remove only this part // Treat user provided text as plain text. QTextDocument notesDocument; notesDocument.setHtml(current_dive->notes); QString oldnotes(notesDocument.toPlainText()); int disclaimerPosition = oldnotes.indexOf(disclaimer); if (disclaimerPosition == 0) oldnotes.clear(); else if (disclaimerPosition >= 1) oldnotes.truncate(disclaimerPosition-1); // Deal with line breaks oldnotes.replace("\n", "<br>"); oldnotes.append(displayed_dive.notes); displayed_dive.notes = strdup(oldnotes.toUtf8().data()); // If we save as new create a copy of the dive here if (replanCopy) { struct dive *copy = alloc_dive(); copy_dive(current_dive, copy); copy->id = 0; copy->selected = false; copy->divetrip = NULL; if (current_dive->divetrip) add_dive_to_trip(copy, current_dive->divetrip); record_dive(copy); } copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
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::createSimpleDive() { struct gasmix gas = { 0 }; // initialize the start time in the plan diveplan.when = displayed_dive.when; if (isPlanner()) // let's use the gas from the first cylinder gas = displayed_dive.cylinder[0].gasmix; // If we're in drop_stone_mode, don't add a first point. // It will be added implicit. if (!prefs.drop_stone_mode) addStop(M_OR_FT(15, 45), 1 * 60, &gas, 0, true); addStop(M_OR_FT(15, 45), 20 * 60, &gas, 0, true); if (!isPlanner()) { addStop(M_OR_FT(5, 15), 42 * 60, &gas, 0, true); addStop(M_OR_FT(5, 15), 45 * 60, &gas, 0, true); } }
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 }
void DivePlannerPointsModel::createPlan(bool replanCopy) { // Ok, so, here the diveplan creates a dive char *cache = NULL; bool oldRecalc = setRecalc(false); removeDeco(); createTemporaryPlan(); setRecalc(oldRecalc); //TODO: C-based function here? bool did_deco = plan(&diveplan, &cache, isPlanner(), true); free(cache); if (!current_dive || displayed_dive.id != current_dive->id) { // we were planning a new dive, not re-planning an existing on record_dive(clone_dive(&displayed_dive)); } else if (current_dive && displayed_dive.id == current_dive->id) { // we are replanning a dive - make sure changes are reflected // correctly in the dive structure and copy it back into the dive table displayed_dive.maxdepth.mm = 0; displayed_dive.dc.maxdepth.mm = 0; fixup_dive(&displayed_dive); if (replanCopy) { struct dive *copy = alloc_dive(); copy_dive(current_dive, copy); copy->id = 0; copy->selected = false; copy->divetrip = NULL; if (current_dive->divetrip) add_dive_to_trip(copy, current_dive->divetrip); record_dive(copy); QString oldnotes(current_dive->notes); if (oldnotes.indexOf(QString(disclaimer)) >= 0) oldnotes.truncate(oldnotes.indexOf(QString(disclaimer))); if (did_deco) oldnotes.append(displayed_dive.notes); displayed_dive.notes = strdup(oldnotes.toUtf8().data()); } copy_dive(&displayed_dive, current_dive); } mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. free_dps(&diveplan); setPlanMode(NOTHING); planCreated(); }
void DivePlannerPointsModel::createSimpleDive() { // initialize the start time in the plan diveplan.when = displayed_dive.when; // Use gas from the first cylinder int cylinderid = 0; // If we're in drop_stone_mode, don't add a first point. // It will be added implicit. if (!prefs.drop_stone_mode) addStop(M_OR_FT(15, 45), 1 * 60, cylinderid, 0, true); addStop(M_OR_FT(15, 45), 20 * 60, 0, 0, true); if (!isPlanner()) { addStop(M_OR_FT(5, 15), 42 * 60, 0, cylinderid, true); addStop(M_OR_FT(5, 15), 45 * 60, 0, cylinderid, true); } updateMaxDepth(); }
void DivePlannerPointsModel::createPlan() { // Ok, so, here the diveplan creates a dive char *cache = NULL; bool oldRecalc = plannerModel->setRecalc(false); removeDeco(); createTemporaryPlan(); plannerModel->setRecalc(oldRecalc); //TODO: C-based function here? plan(&diveplan, &cache, isPlanner(), true); record_dive(clone_dive(&displayed_dive)); mark_divelist_changed(true); // Remove and clean the diveplan, so we don't delete // the dive by mistake. diveplan.dp = NULL; setPlanMode(NOTHING); planCreated(); }