(#645) Convert step names to dates for plotting in Result Plot

This commit is contained in:
Magne Sjaastad 2015-11-24 11:35:04 +01:00
parent 419fd28b02
commit c588a1fe69
3 changed files with 77 additions and 8 deletions

View File

@ -213,3 +213,58 @@ cvf::BoundingBox RimGeoMechCase::allCellsBoundingBox() const
return cvf::BoundingBox();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QDateTime> RimGeoMechCase::dateTimeVectorFromTimeStepStrings(const QStringList& timeStepStrings)
{
std::vector<QDateTime> dates;
QString dateFormat = "ddMMyyyy";
for (int i = 0; i < timeStepStrings.size(); i++)
{
QString timeStepString = timeStepStrings[i];
QString dateStr = subStringOfDigits(timeStepString, dateFormat.size());
QDateTime dateTime = QDateTime::fromString(dateStr, dateFormat);
if (dateTime.isValid())
{
dates.push_back(dateTime);
}
}
return dates;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimGeoMechCase::subStringOfDigits(const QString& inputString, int numberOfDigitsToFind)
{
for (int j = 0; j < inputString.size(); j++)
{
if (inputString.at(j).isDigit())
{
QString digitString;
for (int k = 0; k < numberOfDigitsToFind; k++)
{
if (j + k < inputString.size() && inputString.at(j + k).isDigit())
{
digitString += inputString.at(j + k);
}
}
if (digitString.size() == numberOfDigitsToFind)
{
return digitString;
}
}
}
return "";
}

View File

@ -28,6 +28,8 @@
#include "cvfObject.h"
#include <QDateTime>
class RimGeoMechView;
class RigGeoMechCaseData;
class RifGeoMechReaderInterface;
@ -65,8 +67,12 @@ public:
// Fields:
caf::PdmChildArrayField<RimGeoMechView*> geoMechViews;
static std::vector<QDateTime> dateTimeVectorFromTimeStepStrings(const QStringList& timeStepStrings);
private:
virtual void initAfterRead();
static QString subStringOfDigits(const QString& timeStepString, int numberOfDigitsToFind);
private:
cvf::ref<RigGeoMechCaseData> m_geoMechCaseData;
caf::PdmField<QString> m_caseFileName;

View File

@ -156,15 +156,23 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuGeoMechSelec
curveName.append(timeHistResultAccessor.topologyText());
std::vector<double> timeHistoryValues = timeHistResultAccessor.timeHistoryValues();
std::vector<double> frameTimes;
for (size_t i = 0; i < timeHistoryValues.size(); i++)
{
frameTimes.push_back(i);
}
CVF_ASSERT(frameTimes.size() == timeHistoryValues.size());
RiuMainWindow::instance()->resultPlot()->addCurve(curveName, geomSelectionItem->m_color, frameTimes, timeHistoryValues);
QStringList stepNames = geoMechView->geoMechCase()->timeStepStrings();
std::vector<QDateTime> dates = RimGeoMechCase::dateTimeVectorFromTimeStepStrings(stepNames);
if (dates.size() == timeHistoryValues.size())
{
RiuMainWindow::instance()->resultPlot()->addCurve(curveName, geomSelectionItem->m_color, dates, timeHistoryValues);
}
else
{
std::vector<double> dummyStepTimes;
for (size_t i = 0; i < timeHistoryValues.size(); i++)
{
dummyStepTimes.push_back(i);
}
RiuMainWindow::instance()->resultPlot()->addCurve(curveName, geomSelectionItem->m_color, dummyStepTimes, timeHistoryValues);
}
}
}