mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#859 Added time from start of simulation option
This commit is contained in:
parent
3a0e7d098f
commit
5d04ac198b
@ -71,6 +71,14 @@ bool RifReaderEclipseSummary::open(const std::string& headerFileName, const std:
|
||||
eclSmSpec = ecl_sum_get_smspec(ecl_sum);
|
||||
assert(eclSmSpec != NULL);
|
||||
|
||||
assert(ecl_sum != NULL);
|
||||
|
||||
for ( int time_index = 0; time_index < timeStepCount(); time_index++ )
|
||||
{
|
||||
time_t sim_time = ecl_sum_iget_sim_time(ecl_sum, time_index);
|
||||
m_timeSteps.push_back(sim_time);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -241,13 +249,15 @@ const std::vector<RifEclipseSummaryAddress>& RifReaderEclipseSummary::allResultA
|
||||
bool RifReaderEclipseSummary::values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values)
|
||||
{
|
||||
assert(ecl_sum != NULL);
|
||||
|
||||
int variableIndex = indexFromAddress(resultAddress);
|
||||
|
||||
if ( variableIndex < 0 ) return false;
|
||||
|
||||
values->clear();
|
||||
int tsCount = timeStepCount();
|
||||
values->reserve(timeStepCount());
|
||||
|
||||
int variableIndex = indexFromAddress(resultAddress);
|
||||
|
||||
if(variableIndex < 0) return false;
|
||||
|
||||
const smspec_node_type * ertSumVarNode = ecl_smspec_iget_node(eclSmSpec, variableIndex);
|
||||
int paramsIndex = smspec_node_get_params_index(ertSumVarNode);
|
||||
@ -274,18 +284,11 @@ int RifReaderEclipseSummary::timeStepCount() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<time_t> RifReaderEclipseSummary::timeSteps() const
|
||||
const std::vector<time_t>& RifReaderEclipseSummary::timeSteps() const
|
||||
{
|
||||
assert(ecl_sum != NULL);
|
||||
|
||||
std::vector<time_t> steps;
|
||||
for (int time_index = 0; time_index < timeStepCount(); time_index++)
|
||||
{
|
||||
time_t sim_time = ecl_sum_iget_sim_time(ecl_sum , time_index);
|
||||
steps.push_back(sim_time);
|
||||
}
|
||||
|
||||
return steps;
|
||||
return m_timeSteps;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
|
||||
bool hasAddress(const RifEclipseSummaryAddress& resultAddress);
|
||||
const std::vector<RifEclipseSummaryAddress>& allResultAddresses();
|
||||
std::vector<time_t> timeSteps() const;
|
||||
const std::vector<time_t>& timeSteps() const;
|
||||
|
||||
bool values(const RifEclipseSummaryAddress& resultAddress, std::vector<double>* values);
|
||||
std::string unitName(const RifEclipseSummaryAddress& resultAddress);
|
||||
@ -66,6 +66,7 @@ private:
|
||||
|
||||
ecl_sum_type* ecl_sum;
|
||||
const ecl_smspec_type * eclSmSpec;
|
||||
std::vector<time_t> m_timeSteps;
|
||||
|
||||
std::vector<RifEclipseSummaryAddress> m_allResultAddresses;
|
||||
std::map<RifEclipseSummaryAddress, int> m_resultAddressToErtNodeIdx;
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
#include "RimSummaryTimeAxisProperties.h"
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimSummaryAddress, "SummaryAddress");
|
||||
@ -246,16 +247,33 @@ std::string RimSummaryCurve::unitName()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<double> RimSummaryCurve::yPlotValues() const
|
||||
std::vector<double> RimSummaryCurve::yValues() const
|
||||
{
|
||||
std::vector<QDateTime> dateTimes;
|
||||
std::vector<double> values;
|
||||
|
||||
this->curveData(&dateTimes, &values);
|
||||
RifReaderEclipseSummary* reader = summaryReader();
|
||||
|
||||
if ( !reader ) return values;
|
||||
|
||||
RifEclipseSummaryAddress addr = m_curveVariable()->address();
|
||||
reader->values(addr, &values);
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<time_t>& RimSummaryCurve::timeSteps() const
|
||||
{
|
||||
static std::vector<time_t> emptyVector;
|
||||
RifReaderEclipseSummary* reader = summaryReader();
|
||||
|
||||
if ( !reader ) return emptyVector;
|
||||
|
||||
return reader->timeSteps();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -379,20 +397,40 @@ void RimSummaryCurve::onLoadDataAndUpdate()
|
||||
|
||||
if (isCurveVisible())
|
||||
{
|
||||
std::vector<QDateTime> dateTimes;
|
||||
std::vector<double> values;
|
||||
std::vector<time_t> dateTimes = this->timeSteps();
|
||||
std::vector<double> values = this->yValues();
|
||||
|
||||
RimSummaryPlot* plot = nullptr;
|
||||
firstAncestorOrThisOfType(plot);
|
||||
bool isLogCurve = plot->isLogarithmicScaleEnabled(this->yAxis());
|
||||
|
||||
if(this->curveData(&dateTimes, &values))
|
||||
if ( dateTimes.size())
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromDateAndValues(dateTimes, values, isLogCurve);
|
||||
if ( plot->timeAxisProperties()->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(dateTimes, values, isLogCurve);
|
||||
}
|
||||
else
|
||||
{
|
||||
double timeScale = plot->timeAxisProperties()->fromTimeTToDisplayUnitScale();
|
||||
|
||||
std::vector<double> times;
|
||||
if ( dateTimes.size() )
|
||||
{
|
||||
time_t startDate = dateTimes[0];
|
||||
for ( time_t& date: dateTimes )
|
||||
{
|
||||
times.push_back(timeScale*(date - startDate));
|
||||
}
|
||||
}
|
||||
|
||||
m_qwtPlotCurve->setSamplesFromTimeAndValues(times, values, isLogCurve);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlotCurve->setSamplesFromDateAndValues(std::vector<QDateTime>(), std::vector<double>(), isLogCurve);
|
||||
m_qwtPlotCurve->setSamplesFromTimeTAndValues(std::vector<time_t>(), std::vector<double>(), isLogCurve);
|
||||
}
|
||||
|
||||
updateZoomInParentPlot();
|
||||
@ -540,3 +578,4 @@ bool RimSummaryCurve::curveData(std::vector<QDateTime>* timeSteps, std::vector<d
|
||||
RifEclipseSummaryAddress addr = m_curveVariable()->address();
|
||||
return reader->values(addr, values);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,8 @@ public:
|
||||
void setSummaryAddress(const RifEclipseSummaryAddress& address);
|
||||
std::string unitName();
|
||||
|
||||
std::vector<double> yPlotValues() const;
|
||||
std::vector<double> yValues() const;
|
||||
const std::vector<time_t>& timeSteps() const;
|
||||
|
||||
void setYAxis(RimDefines::PlotAxis plotAxis);
|
||||
RimDefines::PlotAxis yAxis() const;
|
||||
|
@ -292,7 +292,7 @@ void RimSummaryPlotYAxisRangeCalculator::computeYRange(double* min, double* max)
|
||||
{
|
||||
if (curve->isCurveVisible())
|
||||
{
|
||||
RigStatisticsCalculator::posNegClosestToZero(curve->yPlotValues(), pos, neg);
|
||||
RigStatisticsCalculator::posNegClosestToZero(curve->yValues(), pos, neg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,6 +143,14 @@ bool RimSummaryPlot::isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) co
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryTimeAxisProperties* RimSummaryPlot::timeAxisProperties()
|
||||
{
|
||||
return m_timeAxisProperties();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -163,6 +171,40 @@ void RimSummaryPlot::selectAxisInPropertyEditor(int axis)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
time_t RimSummaryPlot::firstTimeStepOfFirstCurve()
|
||||
{
|
||||
RimSummaryCurve * firstCurve = nullptr;
|
||||
|
||||
for (RimSummaryCurveFilter* curveFilter : m_curveFilters )
|
||||
{
|
||||
if (curveFilter)
|
||||
{
|
||||
std::vector<RimSummaryCurve *> curves = curveFilter->curves();
|
||||
int i = 0;
|
||||
while (firstCurve == nullptr)
|
||||
{
|
||||
firstCurve = curves[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
if (firstCurve) break;
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
while (firstCurve == nullptr)
|
||||
{
|
||||
firstCurve = m_curves[i];
|
||||
++i;
|
||||
}
|
||||
|
||||
if (firstCurve) return firstCurve->timeSteps()[0];
|
||||
else return time_t(0);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -276,6 +318,15 @@ void RimSummaryPlot::updateTimeAxis()
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_timeAxisProperties->timeMode() == RimSummaryTimeAxisProperties::DATE)
|
||||
{
|
||||
m_qwtPlot->useDateBasedTimeAxis();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_qwtPlot->useTimeBasedTimeAxis();
|
||||
}
|
||||
|
||||
m_qwtPlot->enableAxis(QwtPlot::xBottom, true);
|
||||
|
||||
{
|
||||
|
@ -79,6 +79,9 @@ public:
|
||||
|
||||
bool isLogarithmicScaleEnabled(RimDefines::PlotAxis plotAxis) const;
|
||||
|
||||
RimSummaryTimeAxisProperties* timeAxisProperties();
|
||||
time_t firstTimeStepOfFirstCurve();
|
||||
|
||||
void selectAxisInPropertyEditor(int axis);
|
||||
|
||||
virtual QWidget* viewWidget() override;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "cafPdmUiLineEditor.h"
|
||||
|
||||
#include "qwt_date.h"
|
||||
#include "cvfAssert.h"
|
||||
|
||||
|
||||
namespace caf
|
||||
@ -35,12 +36,35 @@ void caf::AppEnum< RimSummaryTimeAxisProperties::AxisTitlePositionType >::setUp(
|
||||
|
||||
setDefault(RimSummaryTimeAxisProperties::AXIS_TITLE_CENTER);
|
||||
}
|
||||
|
||||
template<>
|
||||
void caf::AppEnum< RimSummaryTimeAxisProperties::TimeModeType >::setUp()
|
||||
{
|
||||
addItem(RimSummaryTimeAxisProperties::DATE, "DATE", "Date");
|
||||
addItem(RimSummaryTimeAxisProperties::TIME_FROM_SIMULATION_START, "TIME_FROM_SIMULATION_START", "Time From Simulation Start");
|
||||
|
||||
setDefault(RimSummaryTimeAxisProperties::DATE);
|
||||
}
|
||||
|
||||
template<>
|
||||
void caf::AppEnum< RimSummaryTimeAxisProperties::TimeUnitType >::setUp()
|
||||
{
|
||||
addItem(RimSummaryTimeAxisProperties::SECONDS, "SECONDS", "Seconds");
|
||||
addItem(RimSummaryTimeAxisProperties::MINUTES, "MINUTES", "Minutes");
|
||||
addItem(RimSummaryTimeAxisProperties::HOURS, "HOURS", "Hours");
|
||||
addItem(RimSummaryTimeAxisProperties::DAYS, "DAYS ", "Days");
|
||||
addItem(RimSummaryTimeAxisProperties::YEARS, "YEARS", "Years");
|
||||
|
||||
setDefault(RimSummaryTimeAxisProperties::YEARS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
CAF_PDM_SOURCE_INIT(RimSummaryTimeAxisProperties, "SummaryTimeAxisProperties");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -57,11 +81,21 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
|
||||
CAF_PDM_InitField(&fontSize, "FontSize", 11, "Font Size", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleRangeMax, "VisibleRangeMax", "Max", "", "", "");
|
||||
m_visibleRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
CAF_PDM_InitFieldNoDefault(&m_timeMode, "TimeMode", "Time Mode", "", "", "");
|
||||
CAF_PDM_InitFieldNoDefault(&m_timeUnit, "TimeUnit", "Time Unit", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMax, "VisibleRangeMax", "Max", "", "", "");
|
||||
m_visibleDateRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleDateRangeMin, "VisibleRangeMin", "Min", "", "", "");
|
||||
m_visibleDateRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMax, "VisibleTimeModeRangeMax", "Max", "", "", "");
|
||||
m_visibleDateRangeMax.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleTimeRangeMin, "VisibleTimeModeRangeMin", "Min", "", "", "");
|
||||
m_visibleDateRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&m_visibleRangeMin, "VisibleRangeMin", "Min", "", "", "");
|
||||
m_visibleRangeMin.uiCapability()->setUiEditorTypeName(caf::PdmUiLineEditor::uiEditorTypeName());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -69,7 +103,10 @@ RimSummaryTimeAxisProperties::RimSummaryTimeAxisProperties()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::visibleRangeMin() const
|
||||
{
|
||||
return QwtDate::toDouble(m_visibleRangeMin());
|
||||
if ( m_timeMode() == DATE )
|
||||
return QwtDate::toDouble(m_visibleDateRangeMin());
|
||||
else
|
||||
return m_visibleTimeRangeMin();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -77,7 +114,10 @@ double RimSummaryTimeAxisProperties::visibleRangeMin() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::visibleRangeMax() const
|
||||
{
|
||||
return QwtDate::toDouble(m_visibleRangeMax());
|
||||
if ( m_timeMode() == DATE )
|
||||
return QwtDate::toDouble(m_visibleDateRangeMax());
|
||||
else
|
||||
return m_visibleTimeRangeMax();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -85,7 +125,16 @@ double RimSummaryTimeAxisProperties::visibleRangeMax() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleRangeMin(double value)
|
||||
{
|
||||
m_visibleRangeMin = QwtDate::toDateTime(value);
|
||||
if ( m_timeMode() == DATE )
|
||||
{
|
||||
m_visibleDateRangeMin = QwtDate::toDateTime(value);
|
||||
m_visibleTimeRangeMin = fromDateToDisplayTime(m_visibleDateRangeMin());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_visibleTimeRangeMin = value;
|
||||
m_visibleDateRangeMin = fromDisplayTimeToDate(value);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -93,9 +142,68 @@ void RimSummaryTimeAxisProperties::setVisibleRangeMin(double value)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::setVisibleRangeMax(double value)
|
||||
{
|
||||
m_visibleRangeMax = QwtDate::toDateTime(value);
|
||||
if ( m_timeMode() == DATE )
|
||||
{
|
||||
m_visibleDateRangeMax = QwtDate::toDateTime(value);
|
||||
m_visibleTimeRangeMax = fromDateToDisplayTime(m_visibleDateRangeMax());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
m_visibleTimeRangeMax = value;
|
||||
m_visibleDateRangeMax = fromDisplayTimeToDate(value);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::updateTimeVisibleRange()
|
||||
{
|
||||
m_visibleTimeRangeMax = fromDateToDisplayTime(m_visibleDateRangeMax());
|
||||
m_visibleTimeRangeMin = fromDateToDisplayTime(m_visibleDateRangeMin());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::updateDateVisibleRange()
|
||||
{
|
||||
m_visibleDateRangeMin = fromDisplayTimeToDate(m_visibleTimeRangeMin());
|
||||
m_visibleDateRangeMax = fromDisplayTimeToDate(m_visibleTimeRangeMax());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QDateTime RimSummaryTimeAxisProperties::fromDisplayTimeToDate(double displayTime)
|
||||
{
|
||||
RimSummaryPlot* rimSummaryPlot = nullptr;
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
time_t startOfSimulation = rimSummaryPlot->firstTimeStepOfFirstCurve();
|
||||
|
||||
time_t secsSinceSimulationStart = displayTime/fromTimeTToDisplayUnitScale();
|
||||
QDateTime date;
|
||||
date.setTime_t(startOfSimulation + secsSinceSimulationStart);
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::fromDateToDisplayTime(const QDateTime& displayTime)
|
||||
{
|
||||
time_t secsSinceEpoc = displayTime.toTime_t();
|
||||
|
||||
RimSummaryPlot* rimSummaryPlot = nullptr;
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
time_t startOfSimulation = rimSummaryPlot->firstTimeStepOfFirstCurve();
|
||||
|
||||
return fromTimeTToDisplayUnitScale()*(secsSinceEpoc - startOfSimulation);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -140,6 +248,62 @@ caf::PdmFieldHandle* RimSummaryTimeAxisProperties::objectToggleField()
|
||||
return &m_isActive;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double RimSummaryTimeAxisProperties::fromTimeTToDisplayUnitScale()
|
||||
{
|
||||
double scale = 1.0;
|
||||
switch (m_timeUnit())
|
||||
{
|
||||
case SECONDS:
|
||||
break;
|
||||
case MINUTES:
|
||||
scale = 1.0/60.0;
|
||||
break;
|
||||
case HOURS:
|
||||
scale = 1.0/(60.0*60.0);
|
||||
break;
|
||||
case DAYS:
|
||||
scale = 1.0/(60.0*60.0*24.0);
|
||||
break;
|
||||
case YEARS:
|
||||
scale = 1.0/31556952.0;
|
||||
break;
|
||||
default:
|
||||
CVF_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimSummaryTimeAxisProperties::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
uiOrdering.add(&showTitle);
|
||||
uiOrdering.add(&title);
|
||||
uiOrdering.add(&titlePositionEnum);
|
||||
uiOrdering.add(&fontSize);
|
||||
caf::PdmUiGroup* timeGroup = uiOrdering.addNewGroup("Time");
|
||||
timeGroup->add(&m_timeMode);
|
||||
if (m_timeMode() == DATE)
|
||||
{
|
||||
timeGroup->add( &m_visibleDateRangeMax);
|
||||
timeGroup->add(&m_visibleDateRangeMin);
|
||||
}
|
||||
else
|
||||
{
|
||||
timeGroup->add(&m_timeUnit);
|
||||
timeGroup->add(&m_visibleTimeRangeMax);
|
||||
timeGroup->add(&m_visibleTimeRangeMin);
|
||||
}
|
||||
|
||||
uiOrdering.setForgetRemainingFields(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -148,26 +312,43 @@ void RimSummaryTimeAxisProperties::fieldChangedByUi(const caf::PdmFieldHandle* c
|
||||
RimSummaryPlot* rimSummaryPlot = nullptr;
|
||||
this->firstAncestorOrThisOfType(rimSummaryPlot);
|
||||
|
||||
if (changedField == &m_visibleRangeMax)
|
||||
if (changedField == &m_visibleDateRangeMax)
|
||||
{
|
||||
QDateTime test = newValue.toDateTime();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleRangeMax = oldValue.toDateTime();
|
||||
m_visibleDateRangeMax = oldValue.toDateTime();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
rimSummaryPlot->disableAutoZoom();
|
||||
}
|
||||
else if (changedField == &m_visibleRangeMin)
|
||||
else if (changedField == &m_visibleDateRangeMin)
|
||||
{
|
||||
QDateTime test = newValue.toDateTime();
|
||||
if (!test.isValid())
|
||||
{
|
||||
m_visibleRangeMin = oldValue.toDateTime();
|
||||
m_visibleDateRangeMin = oldValue.toDateTime();
|
||||
}
|
||||
|
||||
updateTimeVisibleRange();
|
||||
rimSummaryPlot->disableAutoZoom();
|
||||
}
|
||||
else if (changedField == &m_visibleTimeRangeMin || changedField == &m_visibleTimeRangeMax)
|
||||
{
|
||||
updateDateVisibleRange();
|
||||
rimSummaryPlot->disableAutoZoom();
|
||||
}
|
||||
else if (changedField == &m_timeMode)
|
||||
{
|
||||
rimSummaryPlot->loadDataAndUpdate();
|
||||
}
|
||||
else if (changedField == &m_timeUnit)
|
||||
{
|
||||
updateTimeVisibleRange(); // Use the stored max min dates to update the visible time range to new unit
|
||||
rimSummaryPlot->loadDataAndUpdate();
|
||||
updateDateVisibleRange();
|
||||
}
|
||||
|
||||
rimSummaryPlot->updateAxes();
|
||||
}
|
||||
|
@ -43,6 +43,21 @@ public:
|
||||
AXIS_TITLE_END
|
||||
};
|
||||
|
||||
enum TimeModeType
|
||||
{
|
||||
DATE,
|
||||
TIME_FROM_SIMULATION_START
|
||||
};
|
||||
|
||||
enum TimeUnitType
|
||||
{
|
||||
SECONDS,
|
||||
MINUTES,
|
||||
HOURS,
|
||||
DAYS,
|
||||
YEARS
|
||||
};
|
||||
|
||||
public:
|
||||
RimSummaryTimeAxisProperties();
|
||||
|
||||
@ -51,6 +66,10 @@ public:
|
||||
caf::PdmField<bool> showTitle;
|
||||
caf::PdmField< caf::AppEnum< AxisTitlePositionType > > titlePositionEnum;
|
||||
|
||||
TimeModeType timeMode() const { return m_timeMode(); }
|
||||
void setTimeMode(TimeModeType val) { m_timeMode = val; }
|
||||
double fromTimeTToDisplayUnitScale();
|
||||
|
||||
double visibleRangeMin() const;
|
||||
double visibleRangeMax() const;
|
||||
|
||||
@ -63,9 +82,20 @@ protected:
|
||||
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override;
|
||||
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override;
|
||||
virtual caf::PdmFieldHandle* objectToggleField() override;
|
||||
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
|
||||
|
||||
double fromDateToDisplayTime(const QDateTime& displayTime);
|
||||
QDateTime fromDisplayTimeToDate(double displayTime);
|
||||
void updateTimeVisibleRange();
|
||||
void updateDateVisibleRange();
|
||||
|
||||
private:
|
||||
caf::PdmField<bool> m_isActive;
|
||||
caf::PdmField<QDateTime> m_visibleRangeMin;
|
||||
caf::PdmField<QDateTime> m_visibleRangeMax;
|
||||
caf::PdmField< caf::AppEnum< TimeModeType > > m_timeMode;
|
||||
caf::PdmField< caf::AppEnum< TimeUnitType > > m_timeUnit;
|
||||
|
||||
caf::PdmField<bool> m_isActive;
|
||||
caf::PdmField<QDateTime> m_visibleDateRangeMin;
|
||||
caf::PdmField<QDateTime> m_visibleDateRangeMax;
|
||||
caf::PdmField<double> m_visibleTimeRangeMin;
|
||||
caf::PdmField<double> m_visibleTimeRangeMax;
|
||||
};
|
||||
|
@ -71,8 +71,7 @@ void RiuLineSegmentQwtPlotCurve::setSamplesFromDateAndValues(const std::vector<Q
|
||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
||||
}
|
||||
|
||||
|
||||
for (size_t i = 0; i < filteredDateTimes.size(); i++)
|
||||
for ( size_t i = 0; i < filteredDateTimes.size(); i++ )
|
||||
{
|
||||
double milliSecSinceEpoch = QwtDate::toDouble(filteredDateTimes[i]);
|
||||
points << QPointF(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
||||
@ -83,6 +82,73 @@ void RiuLineSegmentQwtPlotCurve::setSamplesFromDateAndValues(const std::vector<Q
|
||||
this->setLineSegmentStartStopIndices(filteredIntervals);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::setSamplesFromTimeTAndValues(const std::vector<time_t>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues)
|
||||
{
|
||||
CVF_ASSERT(dateTimes.size() == timeHistoryValues.size());
|
||||
|
||||
QPolygonF points;
|
||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
||||
{
|
||||
std::vector<double> filteredTimeHistoryValues;
|
||||
std::vector<time_t> filteredDateTimes;
|
||||
|
||||
{
|
||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues, removeNegativeValues);
|
||||
|
||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
||||
RigCurveDataTools::getValuesByIntervals(dateTimes, intervalsOfValidValues, &filteredDateTimes);
|
||||
|
||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < filteredDateTimes.size(); i++)
|
||||
{
|
||||
double milliSecSinceEpoch = filteredDateTimes[i] * 1000; // This is kind of hack, as the c++ standard does not state what time_t is. "Almost always" secs since epoch according to cppreference.com
|
||||
points << QPointF(milliSecSinceEpoch, filteredTimeHistoryValues[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this->setSamples(points);
|
||||
this->setLineSegmentStartStopIndices(filteredIntervals);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuLineSegmentQwtPlotCurve::setSamplesFromTimeAndValues(const std::vector<double>& times, const std::vector<double>& timeHistoryValues, bool removeNegativeValues)
|
||||
{
|
||||
CVF_ASSERT(times.size() == timeHistoryValues.size());
|
||||
|
||||
QPolygonF points;
|
||||
std::vector< std::pair<size_t, size_t> > filteredIntervals;
|
||||
{
|
||||
std::vector<double> filteredTimeHistoryValues;
|
||||
std::vector<double> filteredTimes;
|
||||
|
||||
{
|
||||
std::vector< std::pair<size_t, size_t> > intervalsOfValidValues;
|
||||
RigCurveDataTools::calculateIntervalsOfValidValues(timeHistoryValues, &intervalsOfValidValues, removeNegativeValues);
|
||||
|
||||
RigCurveDataTools::getValuesByIntervals(timeHistoryValues, intervalsOfValidValues, &filteredTimeHistoryValues);
|
||||
RigCurveDataTools::getValuesByIntervals(times, intervalsOfValidValues, &filteredTimes);
|
||||
|
||||
RigCurveDataTools::computePolyLineStartStopIndices(intervalsOfValidValues, &filteredIntervals);
|
||||
}
|
||||
|
||||
for ( size_t i = 0; i < filteredTimes.size(); i++ )
|
||||
{
|
||||
points << QPointF(filteredTimes[i], filteredTimeHistoryValues[i]);
|
||||
}
|
||||
}
|
||||
|
||||
this->setSamples(points);
|
||||
this->setLineSegmentStartStopIndices(filteredIntervals);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -48,6 +48,8 @@ public:
|
||||
virtual ~RiuLineSegmentQwtPlotCurve();
|
||||
|
||||
void setSamplesFromDateAndValues(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
void setSamplesFromTimeTAndValues(const std::vector<time_t>& dateTimes, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
void setSamplesFromTimeAndValues(const std::vector<double>& times, const std::vector<double>& timeHistoryValues, bool removeNegativeValues);
|
||||
|
||||
void setLineSegmentStartStopIndices(const std::vector< std::pair<size_t, size_t> >& lineSegmentStartStopIndices);
|
||||
|
||||
|
@ -331,12 +331,7 @@ void RiuSummaryQwtPlot::setDefaults()
|
||||
|
||||
plotLayout()->setAlignCanvasToScales(true);
|
||||
|
||||
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
|
||||
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
|
||||
|
||||
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
|
||||
setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
|
||||
setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
|
||||
useDateBasedTimeAxis();
|
||||
|
||||
QFont xAxisFont = axisFont(QwtPlot::xBottom);
|
||||
xAxisFont.setPixelSize(11);
|
||||
@ -364,6 +359,30 @@ void RiuSummaryQwtPlot::setDefaults()
|
||||
this->insertLegend(legend, BottomLegend);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::useDateBasedTimeAxis()
|
||||
{
|
||||
QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC);
|
||||
scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy"));
|
||||
|
||||
QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC);
|
||||
setAxisScaleEngine(QwtPlot::xBottom, scaleEngine);
|
||||
setAxisScaleDraw(QwtPlot::xBottom, scaleDraw);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuSummaryQwtPlot::useTimeBasedTimeAxis()
|
||||
{
|
||||
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
|
||||
RimSummaryPlot* ownerPlotDefinition();
|
||||
|
||||
void useDateBasedTimeAxis();
|
||||
void useTimeBasedTimeAxis();
|
||||
|
||||
void currentVisibleWindow(QwtInterval* leftAxis,
|
||||
QwtInterval* rightAxis,
|
||||
QwtInterval* timeAxis) const;
|
||||
|
Loading…
Reference in New Issue
Block a user