bool GasMixture_Impl::setGas(unsigned index, const std::string& type, double fraction) { if ((index > numGases()) || (index >= 4)) { LOG(Info,"Cannot set the gas at index " << index << " in GasMixture " << briefDescription() << ". The current number of gases is " << numGases() << ", and the maximum is 4."); return false; } if (index == numGases() && index < 4) { return addGas(type,fraction); } bool result = true; unsigned typeIndex = mf_getGasTypeFieldIndex(index); unsigned fractionIndex = mf_getGasFractionFieldIndex(index); OptionalString oldType = getString(typeIndex,true); result = setString(typeIndex,type); if (!result) { return false; } result = setDouble(fractionIndex,fraction); if (!result) { if (oldType) { setString(typeIndex,*oldType); } else { setString(typeIndex,""); } } return result; }
void Economics::addGas( BuildingType buildingType, OptionalDouble use, OptionalDouble cost, OptionalDouble inflation ) { double _use = 0, _cost = 0, _inflation = 0; if(use) _use = *use; if(cost) _cost = *cost; if(inflation) _inflation = *inflation; addGas( buildingType, _use, _cost, _inflation ); }
int DivePlannerPointsModel::addStop(int milimeters, int seconds, gasmix *gas_in, int ccpoint, bool entered) { struct gasmix air = { 0 }; struct gasmix gas = { 0 }; bool usePrevious = false; if (gas_in) gas = *gas_in; else usePrevious = true; if (recalcQ()) removeDeco(); int row = divepoints.count(); if (seconds == 0 && milimeters == 0 && row != 0) { /* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */ const divedatapoint t = divepoints.at(lastEnteredPoint()); milimeters = t.depth; seconds = t.time + 600; // 10 minutes. gas = t.gasmix; ccpoint = t.setpoint; } else if (seconds == 0 && milimeters == 0 && row == 0) { milimeters = M_OR_FT(5, 15); // 5m / 15ft seconds = 600; // 10 min //Default to the first defined gas, if we got one. cylinder_t *cyl = &displayed_dive.cylinder[0]; if (cyl) gas = cyl->gasmix; } if (!usePrevious) if (!addGas(gas)) qDebug("addGas failed"); // FIXME add error propagation // check if there's already a new stop before this one: for (int i = 0; i < row; i++) { const divedatapoint &dp = divepoints.at(i); if (dp.time == seconds) { row = i; beginRemoveRows(QModelIndex(), row, row); divepoints.remove(row); endRemoveRows(); break; } if (dp.time > seconds) { row = i; break; } } // Previous, actually means next as we are typically subdiving a segment and the gas for // the segment is determined by the waypoint at the end. if (usePrevious) { if (row < divepoints.count()) { gas = divepoints.at(row).gasmix; } else if (row > 0) { gas = divepoints.at(row - 1).gasmix; } else { if (!addGas(air)) qDebug("addGas failed"); // FIXME add error propagation } } // add the new stop beginInsertRows(QModelIndex(), row, row); divedatapoint point; point.depth = milimeters; point.time = seconds; point.gasmix = gas; point.setpoint = ccpoint; point.entered = entered; point.next = NULL; divepoints.append(point); std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan); endInsertRows(); return row; }