mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-31 17:17:50 -05:00
1 parent
1a6922e346
commit
ac2923b8b9
6 files changed
+153
-12
No files matched your search
@@ -24,14 +24,21 @@
|
||||
|
||||
#include "RifReaderSettings.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimSurface.h"
|
||||
#include "RimSurfaceCollection.h"
|
||||
#include "RimSurfaceInView.h"
|
||||
#include "RimSurfaceInViewCollection.h"
|
||||
#include "RimTools.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
#include "RiuFileDialogTools.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicImportEclipseCaseFeature, "RicImportEclipseCaseFeature" );
|
||||
@@ -57,12 +64,139 @@ void RicImportEclipseCaseFeature::onActionTriggered( bool isChecked )
|
||||
bool createDefaultView = true;
|
||||
std::vector<int> caseIds;
|
||||
RifReaderSettings readerSettings = RiaPreferencesGrid::current()->readerSettings();
|
||||
|
||||
// Track existing views before import
|
||||
RimProject* project = RimProject::current();
|
||||
std::vector<RimEclipseView*> allViewsBefore = allEclipseViews( project );
|
||||
|
||||
openEclipseCaseFromFileNames( fileNames, createDefaultView, caseIds, readerSettings );
|
||||
|
||||
for ( const auto& f : fileNames )
|
||||
{
|
||||
RiaApplication::instance()->addToRecentFiles( f );
|
||||
}
|
||||
|
||||
// Auto-import matching PVD surface files
|
||||
if ( RimSurfaceCollection* surfColl = RimTools::surfaceCollection() )
|
||||
{
|
||||
QStringList pvdFilesToImport = findPvdFilesToImport( fileNames );
|
||||
|
||||
if ( !pvdFilesToImport.isEmpty() )
|
||||
{
|
||||
// Get count of existing surfaces before import
|
||||
auto allSurfacesBefore = surfColl->descendantsIncludingThisOfType<RimSurface>();
|
||||
|
||||
surfColl->importSurfacesFromFiles( pvdFilesToImport );
|
||||
|
||||
// Get newly imported surfaces
|
||||
auto allSurfacesAfter = surfColl->descendantsIncludingThisOfType<RimSurface>();
|
||||
std::vector<RimSurface*> newlyImportedSurfaces;
|
||||
for ( auto* surf : allSurfacesAfter )
|
||||
{
|
||||
if ( std::find( allSurfacesBefore.begin(), allSurfacesBefore.end(), surf ) == allSurfacesBefore.end() )
|
||||
{
|
||||
newlyImportedSurfaces.push_back( surf );
|
||||
}
|
||||
}
|
||||
|
||||
// Enable newly imported surfaces in new views, disable them in old views
|
||||
if ( project && !newlyImportedSurfaces.empty() )
|
||||
{
|
||||
// Process all views (both old and new)
|
||||
for ( auto* eclipseCase : project->eclipseCases() )
|
||||
{
|
||||
for ( RimEclipseView* view : eclipseCase->reservoirViews() )
|
||||
{
|
||||
if ( RimSurfaceInViewCollection* surfInViewColl = view->surfaceInViewCollection() )
|
||||
{
|
||||
// Check if this is a new view or an existing view
|
||||
bool isNewView = std::find( allViewsBefore.begin(), allViewsBefore.end(), view ) == allViewsBefore.end();
|
||||
|
||||
// Get all surface-in-view objects
|
||||
auto allSurfacesInView = surfInViewColl->descendantsIncludingThisOfType<RimSurfaceInView>();
|
||||
|
||||
for ( RimSurfaceInView* surfInView : allSurfacesInView )
|
||||
{
|
||||
if ( RimSurface* surf = surfInView->surface() )
|
||||
{
|
||||
bool isNewlyImported = std::find( newlyImportedSurfaces.begin(), newlyImportedSurfaces.end(), surf ) !=
|
||||
newlyImportedSurfaces.end();
|
||||
|
||||
if ( isNewlyImported )
|
||||
{
|
||||
// Enable newly imported surfaces only in new views
|
||||
// Disable them in old views
|
||||
surfInView->setActive( isNewView );
|
||||
}
|
||||
else if ( isNewView )
|
||||
{
|
||||
// Disable old surfaces in new views
|
||||
surfInView->setActive( false );
|
||||
}
|
||||
// Leave old surfaces in old views unchanged
|
||||
}
|
||||
}
|
||||
|
||||
surfInViewColl->updateConnectedEditors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimEclipseView*> RicImportEclipseCaseFeature::allEclipseViews( RimProject* project )
|
||||
{
|
||||
std::vector<RimEclipseView*> allViewsBefore;
|
||||
if ( project )
|
||||
{
|
||||
auto allCases = project->eclipseCases();
|
||||
for ( auto* eclipseCase : allCases )
|
||||
{
|
||||
auto views = eclipseCase->reservoirViews();
|
||||
allViewsBefore.insert( allViewsBefore.end(), views.begin(), views.end() );
|
||||
}
|
||||
}
|
||||
return allViewsBefore;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QStringList RicImportEclipseCaseFeature::findPvdFilesToImport( const QStringList& fileNames )
|
||||
{
|
||||
QStringList pvdFilesToImport;
|
||||
for ( const auto& gridFile : fileNames )
|
||||
{
|
||||
QFileInfo gridFileInfo( gridFile );
|
||||
QString baseName = gridFileInfo.completeBaseName(); // e.g., "CASE" from "CASE.EGRID"
|
||||
QString dirPath = gridFileInfo.absolutePath();
|
||||
QDir dir( dirPath );
|
||||
|
||||
// Search for PVD files with matching base name
|
||||
QStringList pvdFilters;
|
||||
pvdFilters << baseName + "*.pvd";
|
||||
|
||||
QStringList matchingPvdFiles = dir.entryList( pvdFilters, QDir::Files );
|
||||
for ( const QString& pvdFile : matchingPvdFiles )
|
||||
{
|
||||
QFileInfo pvdFileInfo( pvdFile );
|
||||
QString pvdBaseName = pvdFileInfo.completeBaseName();
|
||||
|
||||
// Skip files with exactly the same base name (e.g., CASE.EGRID should not import CASE.pvd)
|
||||
// Only import files with additional text (e.g., CASE_surface.pvd, CASE-horizon.pvd)
|
||||
if ( pvdBaseName != baseName )
|
||||
{
|
||||
QString fullPath = dir.absoluteFilePath( pvdFile );
|
||||
pvdFilesToImport << fullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pvdFilesToImport;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
|
||||
#include "RicImportGeneralDataFeature.h"
|
||||
|
||||
class RimEclipseView;
|
||||
class RimProject;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
@@ -31,4 +34,7 @@ class RicImportEclipseCaseFeature : public RicImportGeneralDataFeature
|
||||
protected:
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
static std::vector<RimEclipseView*> allEclipseViews( RimProject* project );
|
||||
static QStringList findPvdFilesToImport( const QStringList& fileNames );
|
||||
};
|
||||
Reference in new issue
Block a user