-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Grid Ensemble: add menu item for importing grid ensemble.
- Loading branch information
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
ApplicationLibCode/Commands/EclipseCommands/RicCreateGridCaseEnsemblesFromFilesFeature.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2024- 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 "RicCreateGridCaseEnsemblesFromFilesFeature.h" | ||
|
||
#include "RiaApplication.h" | ||
#include "RiaImportEclipseCaseTools.h" | ||
|
||
#include "RicCreateGridCaseGroupFromFilesFeature.h" | ||
#include "RicRecursiveFileSearchDialog.h" | ||
|
||
#include "RimEclipseCaseCollection.h" | ||
#include "RimEclipseCaseEnsemble.h" | ||
#include "RimEclipseResultCase.h" | ||
|
||
#include "RimOilField.h" | ||
#include "RimProject.h" | ||
#include "cafProgressInfo.h" | ||
#include "cafSelectionManager.h" | ||
|
||
#include <QAction> | ||
#include <QFileInfo> | ||
|
||
CAF_CMD_SOURCE_INIT( RicCreateGridCaseEnsemblesFromFilesFeature, "RicCreateGridCaseEnsemblesFromFilesFeature" ); | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
void RicCreateGridCaseEnsemblesFromFilesFeature::onActionTriggered( bool isChecked ) | ||
{ | ||
QString pathCacheName = "INPUT_FILES"; | ||
auto [fileNames, groupByEnsemble] = runRecursiveFileSearchDialog( "Import Grid Ensembles", pathCacheName ); | ||
|
||
if ( groupByEnsemble == RiaEnsembleNameTools::EnsembleGroupingMode::NONE ) | ||
{ | ||
importSingleGridCaseEnsemble( fileNames ); | ||
} | ||
else | ||
{ | ||
std::vector<QStringList> groupedByEnsemble = RiaEnsembleNameTools::groupFilesByEnsemble( fileNames, groupByEnsemble ); | ||
for ( const QStringList& groupedFileNames : groupedByEnsemble ) | ||
{ | ||
importSingleGridCaseEnsemble( groupedFileNames ); | ||
} | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
void RicCreateGridCaseEnsemblesFromFilesFeature::setupActionLook( QAction* actionToSetup ) | ||
{ | ||
actionToSetup->setIcon( QIcon( ":/CreateGridCaseGroup16x16.png" ) ); | ||
actionToSetup->setText( "&Create Grid Case Ensembles" ); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
void RicCreateGridCaseEnsemblesFromFilesFeature::importSingleGridCaseEnsemble( const QStringList& fileNames ) | ||
{ | ||
auto eclipseCaseEnsemble = new RimEclipseCaseEnsemble; | ||
QString ensembleNameSuggestion = | ||
RiaEnsembleNameTools::findSuitableEnsembleName( fileNames, RiaEnsembleNameTools::EnsembleGroupingMode::FMU_FOLDER_STRUCTURE ); | ||
eclipseCaseEnsemble->setName( ensembleNameSuggestion ); | ||
|
||
caf::ProgressInfo progInfo( fileNames.size() + 1, "Creating Grid Ensembles" ); | ||
|
||
RimProject* project = RimProject::current(); | ||
CVF_ASSERT( project ); | ||
|
||
RimOilField* oilfield = project->activeOilField(); | ||
if ( !oilfield ) return; | ||
|
||
for ( auto caseFileName : fileNames ) | ||
{ | ||
auto task = progInfo.task( "Loading files", 1 ); | ||
|
||
QFileInfo gridFileName( caseFileName ); | ||
|
||
QString caseName = gridFileName.completeBaseName(); | ||
|
||
auto* rimResultReservoir = new RimEclipseResultCase(); | ||
rimResultReservoir->setCaseInfo( caseName, caseFileName ); | ||
eclipseCaseEnsemble->addCase( rimResultReservoir ); | ||
} | ||
|
||
oilfield->analysisModels()->caseEnsembles.push_back( eclipseCaseEnsemble ); | ||
oilfield->analysisModels()->updateConnectedEditors(); | ||
} | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
/// | ||
//-------------------------------------------------------------------------------------------------- | ||
std::pair<QStringList, RiaEnsembleNameTools::EnsembleGroupingMode> | ||
RicCreateGridCaseEnsemblesFromFilesFeature::runRecursiveFileSearchDialog( const QString& dialogTitle, const QString& pathCacheName ) | ||
{ | ||
RiaApplication* app = RiaApplication::instance(); | ||
QString defaultDir = app->lastUsedDialogDirectory( pathCacheName ); | ||
|
||
RicRecursiveFileSearchDialogResult result = | ||
RicRecursiveFileSearchDialog::runRecursiveSearchDialog( nullptr, | ||
dialogTitle, | ||
defaultDir, | ||
m_pathFilter, | ||
m_fileNameFilter, | ||
{ RicRecursiveFileSearchDialog::FileType::EGRID } ); | ||
|
||
// Remember filters | ||
m_pathFilter = result.pathFilter; | ||
m_fileNameFilter = result.fileNameFilter; | ||
|
||
if ( !result.ok ) return std::make_pair( QStringList(), RiaEnsembleNameTools::EnsembleGroupingMode::NONE ); | ||
|
||
// Remember the path to next time | ||
app->setLastUsedDialogDirectory( pathCacheName, QFileInfo( result.rootDir ).absoluteFilePath() ); | ||
|
||
return std::make_pair( result.files, result.groupingMode ); | ||
} |
51 changes: 51 additions & 0 deletions
51
ApplicationLibCode/Commands/EclipseCommands/RicCreateGridCaseEnsemblesFromFilesFeature.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
///////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright (C) 2024- 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" | ||
|
||
#include "RiaEnsembleNameTools.h" | ||
|
||
#include <vector> | ||
|
||
//================================================================================================== | ||
/// | ||
//================================================================================================== | ||
class RicCreateGridCaseEnsemblesFromFilesFeature : public caf::CmdFeature | ||
{ | ||
CAF_CMD_HEADER_INIT; | ||
|
||
RicCreateGridCaseEnsemblesFromFilesFeature() | ||
: m_pathFilter( "*" ) | ||
, m_fileNameFilter( "*" ) | ||
{ | ||
} | ||
|
||
protected: | ||
void onActionTriggered( bool isChecked ) override; | ||
void setupActionLook( QAction* actionToSetup ) override; | ||
|
||
void importSingleGridCaseEnsemble( const QStringList& fileNames ); | ||
std::pair<QStringList, RiaEnsembleNameTools::EnsembleGroupingMode> runRecursiveFileSearchDialog( const QString& dialogTitle, | ||
const QString& pathCacheName ); | ||
|
||
private: | ||
QString m_pathFilter; | ||
QString m_fileNameFilter; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters