Skip to content

Commit

Permalink
#9773 Add context menu for importing Reveal csv summary data.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Mar 8, 2023
1 parent d6260a2 commit ccb947c
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ApplicationLibCode/Commands/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicDeleteUncheckedSubItemsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicRenameSummaryCaseFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicImportRevealSummaryCaseFeature.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -177,6 +178,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicDeleteUncheckedSubItemsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicRenameSummaryCaseFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportPressureDepthDataFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicImportRevealSummaryCaseFeature.cpp
)

if(RESINSIGHT_USE_QT_CHARTS)
Expand Down
81 changes: 81 additions & 0 deletions ApplicationLibCode/Commands/RicImportRevealSummaryCaseFeature.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicImportRevealSummaryCaseFeature.h"

#include "RiaApplication.h"

#include "RimCsvSummaryCase.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "RimSummaryCaseCollection.h"
#include "RimSummaryCaseMainCollection.h"

#include "RiuFileDialogTools.h"

#include <QAction>

CAF_CMD_SOURCE_INIT( RicImportRevealSummaryCaseFeature, "RicImportRevealSummaryCaseFeature" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportRevealSummaryCaseFeature::isCommandEnabled()
{
return true;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportRevealSummaryCaseFeature::onActionTriggered( bool isChecked )
{
RiaApplication* app = RiaApplication::instance();
RimProject* project = app->project();

RimSummaryCaseMainCollection* sumCaseColl = project->activeOilField() ? project->activeOilField()->summaryCaseMainCollection() : nullptr;
if ( !sumCaseColl ) return;

std::vector<RimSummaryCase*> sumCases;
QString pattern = "Reveal Summary Files (*.csv)";
QString defaultDir = app->lastUsedDialogDirectory( "" );
QStringList filePaths = RiuFileDialogTools::getOpenFileNames( nullptr, "Import Data File", defaultDir, pattern );
for ( const QString& filePath : filePaths )
{
auto newSumCase = new RimCsvSummaryCase();

newSumCase->setSummaryHeaderFileName( filePath );
newSumCase->updateOptionSensitivity();
project->assignCaseIdToSummaryCase( newSumCase );

sumCaseColl->addCase( newSumCase );
sumCases.push_back( newSumCase );
}

sumCaseColl->loadAllSummaryCaseData();
sumCaseColl->updateConnectedEditors();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportRevealSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setIcon( QIcon( ":/SummaryCase.svg" ) );
actionToSetup->setText( "Import Reveal Summary Case" );
}
34 changes: 34 additions & 0 deletions ApplicationLibCode/Commands/RicImportRevealSummaryCaseFeature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "cafCmdFeature.h"

//==================================================================================================
///
//==================================================================================================
class RicImportRevealSummaryCaseFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;

protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
else if ( dynamic_cast<RimSummaryCaseMainCollection*>( firstUiItem ) )
{
menuBuilder << "RicImportSummaryCaseFeature";
menuBuilder << "RicImportRevealSummaryCaseFeature";
menuBuilder << "RicImportSummaryCasesFeature";
menuBuilder << "RicImportSummaryGroupFeature";
menuBuilder << "RicImportEnsembleFeature";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleCurveInfoTextProvider.h
${CMAKE_CURRENT_LIST_DIR}/RimSummaryAddressModifier.h
${CMAKE_CURRENT_LIST_DIR}/RimRftCase.h
${CMAKE_CURRENT_LIST_DIR}/RimCsvSummaryCase.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand Down Expand Up @@ -94,6 +95,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RimEnsembleCurveInfoTextProvider.cpp
${CMAKE_CURRENT_LIST_DIR}/RimSummaryAddressModifier.cpp
${CMAKE_CURRENT_LIST_DIR}/RimRftCase.cpp
${CMAKE_CURRENT_LIST_DIR}/RimCsvSummaryCase.cpp
)

list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
Expand Down
85 changes: 85 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Summary/RimCsvSummaryCase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RimCsvSummaryCase.h"

#include "RiaLogging.h"

#include "RifRevealCsvSummaryReader.h"
#include "RifSummaryReaderInterface.h"

#include "RimTools.h"

#include "cafPdmUiTextEditor.h"
#include "cafUtils.h"

#include <QFileInfo>

CAF_PDM_ABSTRACT_SOURCE_INIT( RimCsvSummaryCase, "CsvSummaryCase" );

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimCsvSummaryCase::RimCsvSummaryCase()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimCsvSummaryCase::caseName() const
{
QFileInfo caseFileName( this->summaryHeaderFilename() );

return caseFileName.completeBaseName();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCsvSummaryCase::createSummaryReaderInterface()
{
m_summaryReader = nullptr;

if ( caf::Utils::fileExists( this->summaryHeaderFilename() ) )
{
auto reader = new RifRevealCsvSummaryReader;
QString errorMessage;
if ( reader->parse( summaryHeaderFilename(), &errorMessage ) )
{
m_summaryReader = reader;
}
else
{
RiaLogging::error( "Failed to read Reveal summary file" );
RiaLogging::error( errorMessage );
}
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifSummaryReaderInterface* RimCsvSummaryCase::summaryReader()
{
if ( m_summaryReader.isNull() )
{
createSummaryReaderInterface();
}
return m_summaryReader.p();
}
44 changes: 44 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Summary/RimCsvSummaryCase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////

#pragma once

#include "RimSummaryCase.h"

#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cvfObject.h"

//==================================================================================================
//
//==================================================================================================
class RimCsvSummaryCase : public RimSummaryCase
{
CAF_PDM_HEADER_INIT;

public:
RimCsvSummaryCase();

QString caseName() const override;

void createSummaryReaderInterface() override;
RifSummaryReaderInterface* summaryReader() override;

private:
cvf::ref<RifSummaryReaderInterface> m_summaryReader;
};

0 comments on commit ccb947c

Please sign in to comment.