Files
ResInsight/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp
T
Magne Sjaastad 694b689e8a Fix crash in split multi plot when a curve has no case
Skip curves without a summary case when splitting a multi plot.

Call stack:
[0] performCrashLogging at ResInsight/ApplicationExeCode/RiaMainTools.cpp:178
[1] manageSegFailureSA(int, siginfo_t*, void*) at ResInsight/ApplicationExeCode/RiaMainTools.cpp:310
[3] RimSummaryCase::caseId() const at ResInsight/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCase.cpp:453
[4] RicSplitMultiPlotFeature::onActionTriggered(bool) at ResInsight/ApplicationLibCode/Commands/PlotBuilderCommands/RicSplitMultiPlotFeature.cpp:62
[5] caf::CmdFeature::actionTriggered(bool) at ResInsight/Fwk/AppFwk/cafCommand/cafCmdFeature.cpp:176
[14] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[20] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[32] RiuMainWindow::customMenuRequested(QPoint const&) at ResInsight/ApplicationLibCode/UserInterface/RiuMainWindow.cpp:2094
[40] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[45] RiaGuiApplication::notify(QObject*, QEvent*) at ResInsight/ApplicationLibCode/Application/RiaGuiApplication.cpp:1879
[56] main at ResInsight/ApplicationExeCode/RiaMain.cpp:267
[57] __libc_start_main at :0
2026-11-09 10:22:43 +01:00

119 lines
3.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 "RicSplitMultiPlotFeature.h"
#include "Summary/RiaSummaryPlotTools.h"
#include "RimEnsembleCurveSet.h"
#include "RimSummaryAddress.h"
#include "RimSummaryCase.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicSplitMultiPlotFeature, "RicSplitMultiPlotFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSplitMultiPlotFeature::isCommandEnabled() const
{
RimSummaryPlot* plot = getSelectedPlot();
if ( plot )
{
return ( ( plot->summaryCurves().size() > 1 ) || ( plot->curveSets().size() > 1 ) );
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSplitMultiPlotFeature::onActionTriggered( bool isChecked )
{
RimSummaryPlot* plot = getSelectedPlot();
if ( plot == nullptr ) return;
std::vector<caf::PdmObjectHandle*> objects = {};
for ( auto curve : plot->summaryCurves() )
{
// The case is null if it has been deleted
auto summaryCase = curve->summaryCaseY();
if ( !summaryCase ) continue;
RimSummaryAddress* addr = RimSummaryAddress::wrapFileReaderAddress( curve->summaryAddressY() );
addr->setCaseId( summaryCase->caseId() );
objects.push_back( addr );
}
for ( auto curveSet : plot->curveSets() )
{
RimSummaryAddress* addr = RimSummaryAddress::wrapFileReaderAddress( curveSet->summaryAddressY() );
addr->setEnsembleId( curveSet->ensembleId() );
objects.push_back( addr );
}
if ( objects.empty() ) return;
RiaSummaryPlotTools::createAndAppendSummaryMultiPlot( objects );
for ( auto object : objects )
delete object;
return;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSplitMultiPlotFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Split Into Single Curve Plots" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicSplitMultiPlotFeature::getSelectedPlot() const
{
RimSummaryPlot* plot = nullptr;
if ( sender() )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<void*>() )
{
plot = static_cast<RimSummaryPlot*>( userData.value<void*>() );
}
}
if ( plot == nullptr )
{
const auto selectedItems = caf::SelectionManager::instance()->selectedItems();
if ( !selectedItems.empty() ) plot = dynamic_cast<RimSummaryPlot*>( selectedItems[0] );
}
return plot;
}