Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert cross plots into summary plots #10636

Closed
wants to merge 14 commits into from
49 changes: 43 additions & 6 deletions ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "RimMainPlotCollection.h"

#include "RiaPlotCollectionScheduler.h"
#include "RiaSummaryDefines.h"

#include "PlotBuilderCommands/RicSummaryPlotBuilder.h"

Expand All @@ -42,6 +43,8 @@
#include "RimStimPlanModelPlotCollection.h"
#include "RimSummaryAddress.h"
#include "RimSummaryCrossPlotCollection.h"
#include "RimSummaryCurve.h"
#include "RimSummaryDataSourceStepping.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
#include "RimSummaryPlotCollection.h"
Expand Down Expand Up @@ -176,17 +179,51 @@ RimMainPlotCollection* RimMainPlotCollection::current()
//--------------------------------------------------------------------------------------------------
void RimMainPlotCollection::initAfterRead()
{
std::vector<RimSummaryPlot*> plotsToMove;
for ( auto singlePlot : m_summaryPlotCollection_OBSOLETE()->plots() )
{
plotsToMove.push_back( singlePlot );
std::vector<RimSummaryPlot*> plotsToMove;
for ( auto singlePlot : m_summaryPlotCollection_OBSOLETE()->plots() )
{
plotsToMove.push_back( singlePlot );
}

for ( auto singlePlot : plotsToMove )
{
m_summaryPlotCollection_OBSOLETE()->removePlot( singlePlot );

RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlotNoAutoSettings( singlePlot );
}
}

for ( auto singlePlot : plotsToMove )
// Move cross plots into summary plot collection
auto crossPlots = m_summaryCrossPlotCollection_OBSOLETE->plots();
if ( !crossPlots.empty() )
{
m_summaryPlotCollection_OBSOLETE()->removePlot( singlePlot );
auto* summaryMultiPlot = new RimSummaryMultiPlot;
summaryMultiPlot->setMultiPlotTitle( QString( "Multi Plot %1" ).arg( m_summaryMultiPlotCollection->multiPlots().size() + 1 ) );
summaryMultiPlot->setAsPlotMdiWindow();
m_summaryMultiPlotCollection->addSummaryMultiPlot( summaryMultiPlot );

for ( auto crossPlot : crossPlots )
{
m_summaryCrossPlotCollection_OBSOLETE->removePlot( crossPlot );
summaryMultiPlot->addPlot( crossPlot );

RicSummaryPlotBuilder::createAndAppendSingleSummaryMultiPlotNoAutoSettings( singlePlot );
// We want to convert RimSummaryCrossPlot into a RimSummaryPlot. The cross plot is derived from RimSummaryPlot, but we need to
// create a new RimSummaryPlot to be able to store the PDM object as a RimSummaryPlot instead of RimSummaryCrossPlot
auto summaryPlot = new RimSummaryPlot;
summaryMultiPlot->addPlot( summaryPlot );

for ( auto curve : crossPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) )
{
crossPlot->removeCurve( curve );

if ( curve->summaryCaseX() != nullptr ) curve->setAxisTypeX( RiaDefines::HorizontalAxisType::SUMMARY_VECTOR );

summaryPlot->insertCurve( curve, size_t( 999 ) );
}

delete crossPlot;
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions ApplicationLibCode/ProjectDataModel/RimProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,11 +1422,6 @@ void RimProject::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, Q
uiTreeOrdering.add( m_mainPlotCollection->correlationPlotCollection() );
}

if ( m_mainPlotCollection->summaryCrossPlotCollection() )
{
uiTreeOrdering.add( m_mainPlotCollection->summaryCrossPlotCollection() );
}

if ( m_mainPlotCollection->summaryTableCollection() )
{
uiTreeOrdering.add( m_mainPlotCollection->summaryTableCollection() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "cafPdmUiDateEditor.h"
#include "cafPdmUiLineEditor.h"
#include "cafPdmUiSliderEditor.h"
#include "cafPdmUiSliderTools.h"
#include "cafPdmUiTextEditor.h"

#include "ExponentialRegression.hpp"
Expand Down Expand Up @@ -94,6 +95,12 @@ RimSummaryRegressionAnalysisCurve::RimSummaryRegressionAnalysisCurve()
m_expressionText.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
m_expressionText.uiCapability()->setUiReadOnly( true );
m_expressionText.xmlCapability()->disableIO();

CAF_PDM_InitField( &m_valueRangeX, "ValueRangeX", std::make_pair( 0.0, 0.0 ), "Value Range X" );
m_valueRangeX.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );

CAF_PDM_InitField( &m_valueRangeY, "ValueRangeY", std::make_pair( 0.0, 0.0 ), "Value Range Y" );
m_valueRangeY.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -110,11 +117,56 @@ RimSummaryRegressionAnalysisCurve::~RimSummaryRegressionAnalysisCurve()
//--------------------------------------------------------------------------------------------------
void RimSummaryRegressionAnalysisCurve::onLoadDataAndUpdate( bool updateParentPlot )
{
// NB! Assume that time stamps for X and Y are the same
std::vector<size_t> indicesToRemove;

auto xValues = RimSummaryCurve::valuesX();
auto timeStepsX = RimSummaryCurve::timeStepsX();
auto yValues = RimSummaryCurve::valuesY();
auto timeStepsY = RimSummaryCurve::timeStepsY();

{
auto values = xValues;
for ( size_t i = 0; i < values.size(); i++ )
{
if ( values[i] < m_valueRangeX().first || values[i] > m_valueRangeX().second )
{
indicesToRemove.push_back( i );
}
}
}

{
auto values = yValues;
for ( size_t i = 0; i < values.size(); i++ )
{
if ( values[i] < m_valueRangeY().first || values[i] > m_valueRangeY().second )
{
indicesToRemove.push_back( i );
}
}
}

// Step 2: Sort indices in descending order
std::sort( indicesToRemove.rbegin(), indicesToRemove.rend() );

// Step 3: Remove elements at the specified indices
for ( auto index : indicesToRemove )
{
if ( index < xValues.size() )
{
xValues.erase( xValues.begin() + index );
timeStepsX.erase( timeStepsX.begin() + index );
yValues.erase( yValues.begin() + index );
timeStepsY.erase( timeStepsY.begin() + index );
}
}

QString descriptionX;
std::tie( m_timeStepsX, m_valuesX, descriptionX ) = computeRegressionCurve( RimSummaryCurve::timeStepsX(), RimSummaryCurve::valuesX() );
std::tie( m_timeStepsX, m_valuesX, descriptionX ) = computeRegressionCurve( timeStepsX, xValues );

QString descriptionY;
std::tie( m_timeStepsY, m_valuesY, descriptionY ) = computeRegressionCurve( RimSummaryCurve::timeStepsY(), RimSummaryCurve::valuesY() );
std::tie( m_timeStepsY, m_valuesY, descriptionY ) = computeRegressionCurve( timeStepsY, yValues );

m_expressionText = descriptionY;

Expand Down Expand Up @@ -260,6 +312,15 @@ void RimSummaryRegressionAnalysisCurve::defineUiOrdering( QString uiConfigName,
timeSelectionGroup->add( &m_maxTimeStep );
timeSelectionGroup->add( &m_showTimeSelectionInPlot );

if ( axisTypeX() == RiaDefines::HorizontalAxisType::SUMMARY_VECTOR )
{
caf::PdmUiGroup* valueRangeXGroup = uiOrdering.addNewGroup( "Value Range X" );
valueRangeXGroup->add( &m_valueRangeX );

caf::PdmUiGroup* valueRangeYGroup = uiOrdering.addNewGroup( "Value Range Y" );
valueRangeYGroup->add( &m_valueRangeY );
}

caf::PdmUiGroup* forecastingGroup = uiOrdering.addNewGroup( "Forecasting" );
forecastingGroup->add( &m_forecastForward );
forecastingGroup->add( &m_forecastBackward );
Expand Down Expand Up @@ -288,7 +349,8 @@ void RimSummaryRegressionAnalysisCurve::fieldChangedByUi( const caf::PdmFieldHan
RimSummaryCurve::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_regressionType || changedField == &m_polynomialDegree || changedField == &m_forecastBackward ||
changedField == &m_forecastForward || changedField == &m_forecastUnit || changedField == &m_minTimeStep ||
changedField == &m_maxTimeStep || changedField == &m_showTimeSelectionInPlot )
changedField == &m_maxTimeStep || changedField == &m_showTimeSelectionInPlot || changedField == &m_valueRangeX ||
changedField == &m_valueRangeY )
{
loadAndUpdateDataAndPlot();

Expand Down Expand Up @@ -349,6 +411,32 @@ void RimSummaryRegressionAnalysisCurve::defineEditorAttribute( const caf::PdmFie
myAttr->font = font;
}
}
else if ( field == &m_valueRangeX )
{
auto myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute );
if ( myAttr )
{
auto values = RimSummaryCurve::valuesX();
if ( !values.empty() )
{
myAttr->m_minimum = *std::min_element( values.begin(), values.end() );
myAttr->m_maximum = *std::max_element( values.begin(), values.end() );
}
}
}
else if ( field == &m_valueRangeY )
{
auto myAttr = dynamic_cast<caf::PdmUiDoubleSliderEditorAttribute*>( attribute );
if ( myAttr )
{
auto values = RimSummaryCurve::valuesY();
if ( !values.empty() )
{
myAttr->m_minimum = *std::min_element( values.begin(), values.end() );
myAttr->m_maximum = *std::max_element( values.begin(), values.end() );
}
}
}
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -551,6 +639,18 @@ void RimSummaryRegressionAnalysisCurve::updateDefaultValues()
m_minTimeStep = timeSteps.front();
m_maxTimeStep = timeSteps.back();
}

auto values = RimSummaryCurve::valuesX();
if ( !values.empty() )
{
m_valueRangeX = std::make_pair( *std::min_element( values.begin(), values.end() ), *std::max_element( values.begin(), values.end() ) );
}

values = RimSummaryCurve::valuesY();
if ( !values.empty() )
{
m_valueRangeY = std::make_pair( *std::min_element( values.begin(), values.end() ), *std::max_element( values.begin(), values.end() ) );
}
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve

static void appendTimeSteps( std::vector<time_t>& destinationTimeSteps, const std::set<QDateTime>& sourceTimeSteps );

private:
caf::PdmField<caf::AppEnum<RegressionType>> m_regressionType;
caf::PdmField<time_t> m_minTimeStep;
caf::PdmField<time_t> m_maxTimeStep;
Expand All @@ -125,6 +126,9 @@ class RimSummaryRegressionAnalysisCurve : public RimSummaryCurve
caf::PdmField<int> m_forecastBackward;
caf::PdmField<caf::AppEnum<ForecastUnit>> m_forecastUnit;

caf::PdmField<std::pair<double, double>> m_valueRangeX;
caf::PdmField<std::pair<double, double>> m_valueRangeY;

caf::PdmPointer<RimTimeAxisAnnotation> m_timeRangeAnnotation;
std::vector<double> m_valuesX;
std::vector<time_t> m_timeStepsX;
Expand Down
8 changes: 8 additions & 0 deletions Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "cafPdmUiTextEditor.h"
#include "cafPdmUiTreeSelectionEditor.h"
#include "cafPdmUiTreeView.h"
#include "cafPdmUiValueRangeEditor.h"
#include "cafSelectionManager.h"

#include <QAction>
Expand Down Expand Up @@ -956,6 +957,9 @@ class DemoPdmObject : public caf::PdmObject
CAF_PDM_InitField( &m_filePath, "FilePath", QString( "" ), "Filename", "", "", "" );
CAF_PDM_InitField( &m_longText, "LongText", QString( "Test text" ), "Long Text", "", "", "" );

CAF_PDM_InitField( &m_minMaxSlider, "MinMaxSlider", std::make_pair( 2.5, 10.1 ), "Min max slider", "", "", "" );
m_minMaxSlider.uiCapability()->setUiEditorTypeName( caf::PdmUiValueRangeEditor::uiEditorTypeName() );

CAF_PDM_InitFieldNoDefault( &m_multiSelectList, "MultiSelect", "Selection List", "", "List", "This is a multi selection list" );
CAF_PDM_InitFieldNoDefault( &m_objectList, "ObjectList", "Objects list Field", "", "List", "This is a list of PdmObjects" );
CAF_PDM_InitFieldNoDefault( &m_objectListOfSameType,
Expand Down Expand Up @@ -984,6 +988,8 @@ class DemoPdmObject : public caf::PdmObject
uiOrdering.add( &m_applyAutoOnChildObjectFields );
uiOrdering.add( &m_updateAutoValues );

uiOrdering.add( &m_minMaxSlider );

uiOrdering.add( &m_objectListOfSameType );
uiOrdering.add( &m_ptrField );
uiOrdering.add( &m_boolField );
Expand Down Expand Up @@ -1041,6 +1047,8 @@ class DemoPdmObject : public caf::PdmObject

caf::PdmField<QString> m_filePath;

caf::PdmField<std::pair<double, double>> m_minMaxSlider;

caf::PdmField<QString> m_longText;
caf::PdmField<std::vector<QString>> m_multiSelectList;

Expand Down
5 changes: 5 additions & 0 deletions Fwk/AppFwk/cafUserInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(MOC_HEADER_FILES
cafPdmUiPickableLineEditor.h
cafPdmUiLabelEditor.h
cafPdmUiCheckBoxAndTextEditor.h
cafPdmUiValueRangeEditor.h
)

find_package(
Expand Down Expand Up @@ -108,6 +109,8 @@ set(PROJECT_FILES
cafPdmUiLabelEditor.cpp
cafPdmUiCheckBoxAndTextEditor.h
cafPdmUiCheckBoxAndTextEditor.cpp
cafPdmUiValueRangeEditor.h
cafPdmUiValueRangeEditor.cpp
# object editors
cafPdmUiDefaultObjectEditor.cpp
cafPdmUiDefaultObjectEditor.h
Expand Down Expand Up @@ -171,6 +174,8 @@ set(PROJECT_FILES
cafPdmUiTreeAttributes.h
cafUiAppearanceSettings.cpp
cafUiIconFactory.cpp
cafPdmUiSliderTools.h
cafPdmUiSliderTools.cpp
)

add_library(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ QWidget* PdmUiCheckBoxAndTextEditor::createEditorWidget( QWidget* parent )
{
auto* containerWidget = new QWidget( parent );

auto lineEditWidget = new PdmUiLineEdit( containerWidget );
lineEditWidget->setAvoidSendingEnterEventToParentWidget( true );

m_lineEdit = lineEditWidget;
m_lineEdit = new PdmUiLineEdit( containerWidget, true );
connect( m_lineEdit, SIGNAL( editingFinished() ), this, SLOT( slotSetValueToField() ) );

m_checkBox = new QCheckBox( "", containerWidget );
Expand Down
14 changes: 11 additions & 3 deletions Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "cafPdmUiListEditor.h"
#include "cafPdmUiTimeEditor.h"
#include "cafPdmUiTreeSelectionEditor.h"
#include "cafPdmUiValueRangeEditor.h"

#include <QGridLayout>

Expand Down Expand Up @@ -75,15 +76,22 @@ CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR( PdmUiTreeSelectionEditor, std::vector<

CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR( PdmUiFilePathEditor, FilePath );

// As the macro CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR() is not working correctly for std::pair<bool, double> the
// As the macro CAF_PDM_UI_REGISTER_DEFAULT_FIELD_EDITOR() is not working correctly for std::pair<> the
// registration of this type in the factory has to be written directly
static bool myPdmUiCheckBoxAndTextEditor73 =
static bool myPdmUiCheckBoxAndTextEditor =
caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<PdmUiCheckBoxAndTextEditor>(
QString( typeid( caf::PdmField<std::pair<bool, double>> ).name() ) );
static bool my2PdmUiCheckBoxAndTextEditor73 =
static bool myPdmUiCheckBoxAndTextEditor_proxy =
caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<PdmUiCheckBoxAndTextEditor>(
QString( typeid( caf::PdmProxyValueField<std::pair<bool, double>> ).name() ) );

static bool myPdmUiValueRangeEditor =
caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<PdmUiValueRangeEditor>(
QString( typeid( caf::PdmField<std::pair<double, double>> ).name() ) );
static bool myPdmUiValueRangeEditor_proxy =
caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance()->registerCreator<PdmUiValueRangeEditor>(
QString( typeid( caf::PdmProxyValueField<std::pair<double, double>> ).name() ) );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Loading