#7481 Usability : Open grid model from summary case and summary curve

This commit is contained in:
Magne Sjaastad 2021-03-10 18:58:28 +01:00
parent df53e80913
commit 4099662cbc
9 changed files with 319 additions and 1 deletions

View File

@ -43,7 +43,8 @@ public:
static bool addEclipseCases( const QStringList& fileNames, RimIdenticalGridCaseGroup** resultingCaseGroup = nullptr );
private:
static int openEclipseCaseFromFile( const QString& fileName );
private:
static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter );
};

View File

@ -78,6 +78,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewPressureTableItemFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeletePressureTableItemFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCaseFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCurveFeature.h
)
@ -160,6 +162,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewCustomObjectiveFunctionWeightFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewPressureTableItemFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeletePressureTableItemFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportGridModelFromSummaryCurveFeature.cpp
)
if(Qt5Charts_FOUND)

View File

@ -0,0 +1,143 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 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 "RicImportGridModelFromSummaryCaseFeature.h"
#include "RiaEclipseFileNameTools.h"
#include "RiaImportEclipseCaseTools.h"
#include "RiaLogging.h"
#include "RimEclipseCase.h"
#include "RimFileSummaryCase.h"
#include "RimGridView.h"
#include "RimProject.h"
#include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction>
#include <QFileInfo>
CAF_CMD_SOURCE_INIT( RicImportGridModelFromSummaryCaseFeature, "RicImportGridModelFromSummaryCaseFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportGridModelFromSummaryCaseFeature::openOrImportGridModelFromSummaryCase( const RimFileSummaryCase* summaryCase )
{
if ( !summaryCase ) return false;
if ( findAndActivateFirstView( summaryCase ) ) return true;
QString summaryFileName = summaryCase->summaryHeaderFilename();
RiaEclipseFileNameTools fileHelper( summaryFileName );
auto candidateGridFileName = fileHelper.findRelatedGridFile();
if ( QFileInfo::exists( candidateGridFileName ) )
{
auto id = RiaImportEclipseCaseTools::openEclipseCaseFromFile( candidateGridFileName );
if ( id > -1 )
{
RiaLogging::info( QString( "Imported %1" ).arg( candidateGridFileName ) );
return true;
}
}
RiaLogging::info( QString( "No grid case found based on summary file %1" ).arg( summaryFileName ) );
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportGridModelFromSummaryCaseFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGridModelFromSummaryCaseFeature::onActionTriggered( bool isChecked )
{
RimFileSummaryCase* summaryCase = caf::SelectionManager::instance()->selectedItemOfType<RimFileSummaryCase>();
openOrImportGridModelFromSummaryCase( summaryCase );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGridModelFromSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/3DWindow.svg" ) );
RimFileSummaryCase* summaryCase = caf::SelectionManager::instance()->selectedItemOfType<RimFileSummaryCase>();
auto gridCase = gridModelFromSummaryCase( summaryCase );
if ( gridCase )
{
actionToSetup->setText( "Open Grid Model View" );
}
else
{
actionToSetup->setText( "Import Grid Model" );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportGridModelFromSummaryCaseFeature::findAndActivateFirstView( const RimFileSummaryCase* summaryCase )
{
auto gridCase = gridModelFromSummaryCase( summaryCase );
if ( gridCase )
{
if ( !gridCase->gridViews().empty() )
{
Riu3DMainWindowTools::selectAsCurrentItem( gridCase->gridViews().front() );
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase* RicImportGridModelFromSummaryCaseFeature::gridModelFromSummaryCase( const RimFileSummaryCase* summaryCase )
{
if ( summaryCase )
{
QString summaryFileName = summaryCase->summaryHeaderFilename();
RiaEclipseFileNameTools fileHelper( summaryFileName );
auto candidateGridFileName = fileHelper.findRelatedGridFile();
RimProject* project = RimProject::current();
auto gridCase = project->eclipseCaseFromGridFileName( candidateGridFileName );
return gridCase;
}
return nullptr;
}

View File

@ -0,0 +1,43 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 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 "cafCmdFeature.h"
class RimEclipseCase;
class RimFileSummaryCase;
//==================================================================================================
///
//==================================================================================================
class RicImportGridModelFromSummaryCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static bool openOrImportGridModelFromSummaryCase( const RimFileSummaryCase* summaryCase );
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
static bool findAndActivateFirstView( const RimFileSummaryCase* summaryCase );
static RimEclipseCase* gridModelFromSummaryCase( const RimFileSummaryCase* summaryCase );
};

View File

@ -0,0 +1,77 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 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 "RicImportGridModelFromSummaryCurveFeature.h"
#include "RicImportGridModelFromSummaryCaseFeature.h"
#include "RimFileSummaryCase.h"
#include "RimProject.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicImportGridModelFromSummaryCurveFeature, "RicImportGridModelFromSummaryCurveFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportGridModelFromSummaryCurveFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGridModelFromSummaryCurveFeature::onActionTriggered( bool isChecked )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<int>() )
{
int summaryCaseId = userData.value<int>();
auto sumCases = RimProject::current()->allSummaryCases();
for ( auto sumCase : sumCases )
{
if ( sumCase->caseId() == summaryCaseId )
{
auto fileSummaryCase = dynamic_cast<RimFileSummaryCase*>( sumCase );
if ( fileSummaryCase )
{
RicImportGridModelFromSummaryCaseFeature::openOrImportGridModelFromSummaryCase( fileSummaryCase );
return;
}
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportGridModelFromSummaryCurveFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/3DWindow.svg" ) );
// No action text is given here, as the custom text is defined in
// RiuSummaryQwtPlot::contextMenuEvent
}

View File

@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 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 "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicImportGridModelFromSummaryCurveFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -760,6 +760,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicNewDefaultSummaryPlotFeature";
menuBuilder << "RicNewSummaryCrossPlotFeature";
menuBuilder.addSeparator();
menuBuilder << "RicImportGridModelFromSummaryCaseFeature";
if ( !dynamic_cast<RimObservedSummaryData*>( firstUiItem ) )
{

View File

@ -254,6 +254,19 @@ void RiuSummaryQwtPlot::contextMenuEvent( QContextMenuEvent* event )
}
}
{
auto summaryCase = summaryCurve->summaryCaseY();
if ( summaryCase )
{
int summaryCaseId = summaryCase->caseId();
QVariant summaryCaseIdVariant( summaryCaseId );
menuBuilder.addCmdFeatureWithUserData( "RicImportGridModelFromSummaryCurveFeature",
"Open Grid Model",
summaryCaseIdVariant );
}
}
if ( !curveClicked )
{
RimSummaryPlot* summaryPlot = static_cast<RimSummaryPlot*>( plotDefinition() );

View File

@ -82,6 +82,8 @@ CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::operator<<( const QString& command
//--------------------------------------------------------------------------------------------------
CmdFeatureMenuBuilder& CmdFeatureMenuBuilder::addCmdFeature( const QString commandId, const QString& uiText )
{
CAF_ASSERT( !commandId.isEmpty() );
MenuItem i;
i.itemType = MenuItem::COMMAND;
i.itemName = commandId;