void ProfilePlotView::setProfile(Profile::Ptr profile) { m_pltDepth->clearGraphs(); m_pltDepth->clearItems(); m_cbxAuxKeys->clear(); m_cbxAuxKeys->setEnabled(false); m_curProfile = profile; if (! m_curProfile) { loadAuxPlotData(std::string()); return; } /* * Check for the "depth" key and remove it */ std::set<std::string> keys(m_curProfile->keys()); bool hasDepth = (keys.find("depth") != keys.end()); if (! hasDepth) logging::getLogger("gui.plot")->warning("Profile does not have depth data"); else keys.erase("depth"); /* * Load the Aux Key Combo Box */ std::set<std::string>::const_iterator itk; for (itk = keys.begin(); itk != keys.end(); itk++) { QString key(QString::fromStdString(* itk)); QString name(profileKeyLabel(* itk)); m_cbxAuxKeys->addItem(name, key); } /* * Load the Depth Profile */ if (hasDepth) { bool hasUnit = false; unit_t unit; try { unit = unitForQuantity(qtDepth); hasUnit = true; } catch (std::runtime_error & e) { } QVector<double> time; QVector<double> depth; unsigned int lastAlarm = 0; AlarmPlotItem * curAlarm = 0; std::list<waypoint>::const_iterator it; for (it = m_curProfile->profile().begin(); it != m_curProfile->profile().end(); it++) { time.push_back(it->time / 60.0f); if (! hasUnit) depth.push_back(it->data.at("depth")); else depth.push_back(unit.conv->fromNative(it->data.at("depth"))); if (it->alarms.size() > 0) { std::set<std::string>::const_iterator ait; // Group alarms within the same 60 seconds into one item if (((it->time - lastAlarm) > 60) || ! curAlarm) { if (curAlarm) { curAlarm->finalize(); m_pltDepth->addItem(curAlarm); } curAlarm = new AlarmPlotItem(m_pltDepth); lastAlarm = it->time; } for (ait = it->alarms.begin(); ait != it->alarms.end(); ait++) curAlarm->addAlarm(it->time, alarmLabel(* ait), QString()); } } if (curAlarm) { curAlarm->finalize(); m_pltDepth->addItem(curAlarm); } if (! hasUnit) m_pltDepth->yAxis->setLabel(tr("Depth")); else m_pltDepth->yAxis->setLabel(tr("Depth (%1)").arg(QString(unit.name).toLower())); QLinearGradient lg(0, 0, 0, 1); lg.setCoordinateMode(QGradient::StretchToDeviceMode); lg.setColorAt(0, QColor(255, 255, 255, 255)); lg.setColorAt(0.6, QColor(0, 64, 112, 255)); m_pltDepth->addGraph(); m_pltDepth->graph(0)->setBrush(lg); m_pltDepth->graph(0)->setPen(QColor(192, 192, 192, 255)); m_pltDepth->graph(0)->setData(time, depth); m_pltDepth->graph(0)->rescaleAxes(); setupTimeAxis(); setupDepthAxis(); setupAlarms(); m_pltDepth->replot(); } /* * Initialize the Aux Plot */ if ((m_cbxAuxKeys->count() == 1) || (keys.find(m_auxKey.toStdString()) == keys.end())) { setAuxKey(m_cbxAuxKeys->itemData(0).toString()); } else if (keys.find(m_auxKey.toStdString()) != keys.end()) { m_cbxAuxKeys->setCurrentIndex(m_cbxAuxKeys->findText(m_auxKey, Qt::MatchFlags())); loadAuxPlotData(m_auxKey.toStdString()); } }
std::string quantity(Quantity const& n, std::string const& singularUnit) { if (singularUnit.empty()) return graehl::to_string(n); return graehl::to_string(n) + " " + unitForQuantity(n, singularUnit); }
void ProfilePlotView::loadAuxPlotData(const std::string & key) { /* * Clear the Existing Plot Data */ m_pltAux->clearGraphs(); m_pltAux->yAxis->setLabel(QString()); m_pltAux->yAxis->setTickVector(QVector<double>()); m_pltAux->replot(); /* * Check the Key is Valid */ if (! m_curProfile || key.empty()) return; if (m_curProfile->keys().find(key) == m_curProfile->keys().end()) { logging::getLogger("gui.plot")->warning("Unknown Profile Data Key: " + key); return; } /* * Load the Value Quantity Type and Units */ unit_t unit; bool hasUnit = false; try { quantity_t q = profileKeyQuantity(key); if (q != qtUnknown) unit = unitForQuantity(q); hasUnit = true; } catch (std::runtime_error & e) { } /* * Create the Plot Vector */ QVector<double> time; QVector<double> value; std::list<waypoint>::const_iterator it; for (it = m_curProfile->profile().begin(); it != m_curProfile->profile().end(); it++) { time.push_back(it->time / 60.0f); if (! hasUnit) value.push_back(it->data.at(key)); else value.push_back(unit.conv->fromNative(it->data.at(key))); } /* * Setup the Aux Plot */ if (hasUnit) m_pltAux->yAxis->setLabel(QString::fromStdWString(unit.abbr)); m_pltAux->addGraph(); m_pltAux->graph(0)->setPen(QColor(64, 64, 64, 255)); m_pltAux->graph(0)->setData(time, value); m_pltAux->graph(0)->rescaleAxes(); setupAuxAxis(); m_pltAux->replot(); }