mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-27 15:41:00 -05:00
#12457 Move management of time axis annotations
Use RimTimeAxisAnnotationUpdater for management of annotation objects.
This commit is contained in:
1 parent
14294e400e
commit
fa61fbb78b
14 files changed
+284
-166
No files matched your search
@@ -15,6 +15,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPolylineTarget.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotationUpdater.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEquilibriumAxisAnnotation.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotRectAnnotation.h
|
||||
)
|
||||
@@ -36,6 +37,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPolylineTarget.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotAxisAnnotation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimTimeAxisAnnotationUpdater.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimEquilibriumAxisAnnotation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimPlotRectAnnotation.cpp
|
||||
)
|
||||
|
||||
@@ -33,6 +33,21 @@
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimTimeAxisAnnotation, "RimTimeAxisAnnotation" );
|
||||
|
||||
namespace internal
|
||||
{
|
||||
|
||||
QString defaultDateTimeFormatString()
|
||||
{
|
||||
auto dateFormatString = RiaQDateTimeTools::dateFormatString( RiaPreferences::current()->dateFormat(),
|
||||
RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
|
||||
auto timeFormatString = RiaQDateTimeTools::timeFormatString( RiaPreferences::current()->timeFormat(),
|
||||
RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE );
|
||||
|
||||
return QString( "%1 %2" ).arg( dateFormatString ).arg( timeFormatString );
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -44,6 +59,31 @@ RimTimeAxisAnnotation::RimTimeAxisAnnotation()
|
||||
m_value.uiCapability()->setUiHidden( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimTimeAxisAnnotation* RimTimeAxisAnnotation::createTimeAnnotation( time_t time, const cvf::Color3f& color, const QString& dateTimeFormatString )
|
||||
{
|
||||
RimTimeAxisAnnotation* annotation = new RimTimeAxisAnnotation();
|
||||
annotation->setTime( time, dateTimeFormatString );
|
||||
annotation->setColor( color );
|
||||
return annotation;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimTimeAxisAnnotation* RimTimeAxisAnnotation::createTimeRangeAnnotation( time_t startTime,
|
||||
time_t endTime,
|
||||
const cvf::Color3f& color,
|
||||
const QString& dateTimeFormatString )
|
||||
{
|
||||
RimTimeAxisAnnotation* annotation = new RimTimeAxisAnnotation();
|
||||
annotation->setTimeRange( startTime, endTime, dateTimeFormatString );
|
||||
annotation->setColor( color );
|
||||
return annotation;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -51,18 +91,7 @@ void RimTimeAxisAnnotation::setTime( time_t time, const QString& dateTimeFormatS
|
||||
{
|
||||
m_value = RiaTimeTTools::toDouble( time );
|
||||
|
||||
QString formatString = dateTimeFormatString;
|
||||
|
||||
if ( formatString.isEmpty() )
|
||||
{
|
||||
QString dateFormatString = RiaQDateTimeTools::dateFormatString( RiaPreferences::current()->dateFormat(),
|
||||
RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
|
||||
QString timeFormatString = RiaQDateTimeTools::timeFormatString( RiaPreferences::current()->timeFormat(),
|
||||
RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE );
|
||||
|
||||
QString dateTimeFormatString = QString( "%1 %2" ).arg( dateFormatString ).arg( timeFormatString );
|
||||
}
|
||||
QString formatString = dateTimeFormatString.isEmpty() ? internal::defaultDateTimeFormatString() : dateTimeFormatString;
|
||||
|
||||
m_name = RiaQDateTimeTools::toStringUsingApplicationLocale( RiaQDateTimeTools::fromTime_t( time ), formatString );
|
||||
|
||||
@@ -72,22 +101,16 @@ void RimTimeAxisAnnotation::setTime( time_t time, const QString& dateTimeFormatS
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimTimeAxisAnnotation::setTimeRange( time_t startTime, time_t endTime )
|
||||
void RimTimeAxisAnnotation::setTimeRange( time_t startTime, time_t endTime, const QString& dateTimeFormatString )
|
||||
{
|
||||
m_rangeStart = RiaTimeTTools::toDouble( startTime );
|
||||
m_rangeEnd = RiaTimeTTools::toDouble( endTime );
|
||||
|
||||
QString dateFormatString = RiaQDateTimeTools::dateFormatString( RiaPreferences::current()->dateFormat(),
|
||||
RiaDefines::DateFormatComponents::DATE_FORMAT_YEAR_MONTH_DAY );
|
||||
|
||||
QString timeFormatString = RiaQDateTimeTools::timeFormatString( RiaPreferences::current()->timeFormat(),
|
||||
RiaDefines::TimeFormatComponents::TIME_FORMAT_HOUR_MINUTE );
|
||||
|
||||
QString dateTimeFormatString = QString( "%1 %2" ).arg( dateFormatString ).arg( timeFormatString );
|
||||
QString formatString = dateTimeFormatString.isEmpty() ? internal::defaultDateTimeFormatString() : dateTimeFormatString;
|
||||
|
||||
m_name = QString( "%0 - %1" )
|
||||
.arg( RiaQDateTimeTools::toStringUsingApplicationLocale( RiaQDateTimeTools::fromTime_t( startTime ), dateTimeFormatString ) )
|
||||
.arg( RiaQDateTimeTools::toStringUsingApplicationLocale( RiaQDateTimeTools::fromTime_t( endTime ), dateTimeFormatString ) );
|
||||
.arg( RiaQDateTimeTools::toStringUsingApplicationLocale( RiaQDateTimeTools::fromTime_t( startTime ), formatString ) )
|
||||
.arg( RiaQDateTimeTools::toStringUsingApplicationLocale( RiaQDateTimeTools::fromTime_t( endTime ), formatString ) );
|
||||
|
||||
setAnnotationType( AnnotationType::RANGE );
|
||||
}
|
||||
|
||||
@@ -38,12 +38,20 @@ class RimTimeAxisAnnotation : public RimPlotAxisAnnotation
|
||||
public:
|
||||
RimTimeAxisAnnotation();
|
||||
|
||||
void setTime( time_t time, const QString& dateTimeFormatString );
|
||||
void setTimeRange( time_t startTime, time_t endTime );
|
||||
static RimTimeAxisAnnotation*
|
||||
createTimeAnnotation( time_t time, const cvf::Color3f& color, const QString& dateTimeFormatString = QString() );
|
||||
|
||||
static RimTimeAxisAnnotation* createTimeRangeAnnotation( time_t startTime,
|
||||
time_t endTime,
|
||||
const cvf::Color3f& color,
|
||||
const QString& dateTimeFormatString = QString() );
|
||||
|
||||
private:
|
||||
void setTime( time_t time, const QString& dateTimeFormatString = QString() );
|
||||
void setTimeRange( time_t startTime, time_t endTime, const QString& dateTimeFormatString = QString() );
|
||||
|
||||
void setDefaultColor();
|
||||
|
||||
protected:
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
void initAfterRead() override;
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RimTimeAxisAnnotationUpdater.h"
|
||||
|
||||
#include "RimEnsembleCurveSet.h"
|
||||
#include "RimSummaryDeclineCurve.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RimSummaryRegressionAnalysisCurve.h"
|
||||
#include "RimSummaryTimeAxisProperties.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimTimeAxisAnnotation*> RimTimeAxisAnnotationUpdater::createTimeAnnotations( const RimSummaryPlot* summaryPlot )
|
||||
{
|
||||
if ( !summaryPlot ) return {};
|
||||
|
||||
std::vector<RimTimeAxisAnnotation*> timeAnnotations;
|
||||
|
||||
for ( auto curve : summaryPlot->allCurves() )
|
||||
{
|
||||
if ( auto declineCurve = dynamic_cast<RimSummaryDeclineCurve*>( curve ) )
|
||||
{
|
||||
auto annotations = declineCurve->createTimeAnnotations();
|
||||
timeAnnotations.insert( timeAnnotations.end(), annotations.begin(), annotations.end() );
|
||||
}
|
||||
else if ( auto regressionCurve = dynamic_cast<RimSummaryRegressionAnalysisCurve*>( curve ) )
|
||||
{
|
||||
auto annotations = regressionCurve->createTimeAnnotations();
|
||||
timeAnnotations.insert( timeAnnotations.end(), annotations.begin(), annotations.end() );
|
||||
}
|
||||
}
|
||||
|
||||
for ( auto curveSet : summaryPlot->curveSets() )
|
||||
{
|
||||
auto annotations = curveSet->createTimeAnnotations();
|
||||
timeAnnotations.insert( timeAnnotations.end(), annotations.begin(), annotations.end() );
|
||||
}
|
||||
|
||||
return timeAnnotations;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimTimeAxisAnnotationUpdater::updateTimeAnnotationObjects( RimSummaryPlot* summaryPlot )
|
||||
{
|
||||
if ( !summaryPlot ) return;
|
||||
|
||||
if ( auto axisProps = summaryPlot->timeAxisProperties() )
|
||||
{
|
||||
axisProps->removeAllAnnotations();
|
||||
|
||||
for ( auto annotation : createTimeAnnotations( summaryPlot ) )
|
||||
{
|
||||
axisProps->appendAnnotation( annotation );
|
||||
}
|
||||
summaryPlot->updateAxes();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2025 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
class RimEnsembleCurveSet;
|
||||
class RimSummaryDeclineCurve;
|
||||
class RimSummaryPlot;
|
||||
class RimTimeAxisAnnotation;
|
||||
|
||||
namespace RimTimeAxisAnnotationUpdater
|
||||
{
|
||||
void updateTimeAnnotationObjects( RimSummaryPlot* summaryPlot );
|
||||
std::vector<RimTimeAxisAnnotation*> createTimeAnnotations( const RimSummaryPlot* summaryPlot );
|
||||
}; // namespace RimTimeAxisAnnotationUpdater
|
||||
Reference in new issue
Block a user