Files
ResInsight/ApplicationLibCode/Commands/SummaryPlotCommands/RicCreateRegressionAnalysisCurveFeature.cpp

166 lines
5.9 KiB
C++
Raw Normal View History

2023-05-12 16:02:56 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2023- 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 "RicCreateRegressionAnalysisCurveFeature.h"
#include "RiaColorTables.h"
#include "RiaColorTools.h"
2023-05-12 16:02:56 +02:00
#include "RiaSummaryTools.h"
#include "RimEnsembleCurveSet.h"
2023-05-12 16:02:56 +02:00
#include "RimSummaryCurve.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryPlot.h"
#include "RimSummaryRegressionAnalysisCurve.h"
2023-05-12 16:02:56 +02:00
#include "RiuPlotMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include "cvfAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicCreateRegressionAnalysisCurveFeature, "RicCreateRegressionAnalysisCurveFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateRegressionAnalysisCurveFeature::isCommandEnabled() const
2023-05-12 16:02:56 +02:00
{
return caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
2023-05-12 16:02:56 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateRegressionAnalysisCurveFeature::onActionTriggered( bool isChecked )
{
RimSummaryRegressionAnalysisCurve* newCurve = nullptr;
if ( auto summaryCurve = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryCurve>() )
{
newCurve = createRegressionAnalysisCurveAndAddToPlot( summaryCurve );
}
if ( auto curveSet = caf::firstAncestorOfTypeFromSelectedObject<RimEnsembleCurveSet>() )
2023-05-12 16:02:56 +02:00
{
newCurve = createRegressionAnalysisCurveAndAddToPlot( curveSet );
}
2023-05-12 16:02:56 +02:00
if ( newCurve )
{
2023-05-12 16:02:56 +02:00
RiuPlotMainWindowTools::showPlotMainWindow();
RiuPlotMainWindowTools::selectAsCurrentItem( newCurve );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateRegressionAnalysisCurveFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Create Regression Analysis Curve" );
actionToSetup->setIcon( QIcon( ":/regression-curve.svg" ) );
2023-05-12 16:02:56 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryRegressionAnalysisCurve*
RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimSummaryCurve* sourceCurve )
{
auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
2023-05-12 16:02:56 +02:00
auto newCurve = new RimSummaryRegressionAnalysisCurve();
RiaSummaryTools::copyCurveDataSources( *newCurve, *sourceCurve );
2023-05-12 16:02:56 +02:00
auto candidates = RiaColorTables::summaryCurveDefaultPaletteColors();
auto contrastColor = RiaColorTools::selectContrastColorFromCandiates( sourceCurve->color(), candidates.color3fArray() );
newCurve->setColor( contrastColor );
newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT );
newCurve->setSymbolSkipDistance( 50 );
2023-05-12 16:02:56 +02:00
summaryPlot->addCurveAndUpdate( newCurve );
RiaSummaryTools::copyCurveAxisData( *newCurve, *sourceCurve );
newCurve->loadDataAndUpdate( true );
newCurve->updateConnectedEditors();
auto* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>();
if ( summaryMultiPlot )
{
summaryMultiPlot->updatePlotTitles();
}
else
{
summaryPlot->updatePlotTitle();
}
summaryPlot->updateAllRequiredEditors();
return newCurve;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryRegressionAnalysisCurve*
RicCreateRegressionAnalysisCurveFeature::createRegressionAnalysisCurveAndAddToPlot( RimEnsembleCurveSet* sourceCurveSet )
{
auto* summaryPlot = caf::firstAncestorOfTypeFromSelectedObject<RimSummaryPlot>();
auto newCurve = new RimSummaryRegressionAnalysisCurve();
newCurve->setEnsembleCurveSet( sourceCurveSet );
auto color = RiaColorTools::fromQColorTo3f( sourceCurveSet->mainEnsembleColor() );
auto candidates = RiaColorTables::summaryCurveDefaultPaletteColors();
auto contrastColor = RiaColorTools::selectContrastColorFromCandiates( color, candidates.color3fArray() );
newCurve->setColor( contrastColor );
newCurve->setSymbol( RiuPlotCurveSymbol::PointSymbolEnum::SYMBOL_RECT );
newCurve->setSymbolSkipDistance( 50 );
summaryPlot->addCurveAndUpdate( newCurve );
newCurve->setAxisTypeX( sourceCurveSet->xAxisType() );
newCurve->setTopOrBottomAxisX( sourceCurveSet->axisX() );
newCurve->setLeftOrRightAxisY( sourceCurveSet->axisY() );
2023-05-12 16:02:56 +02:00
newCurve->loadDataAndUpdate( true );
newCurve->updateConnectedEditors();
auto* summaryMultiPlot = summaryPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>();
2023-05-12 16:02:56 +02:00
if ( summaryMultiPlot )
{
summaryMultiPlot->updatePlotTitles();
}
else
{
summaryPlot->updatePlotTitle();
}
summaryPlot->updateAllRequiredEditors();
return newCurve;
}