#7929 Python : Avoid creation of new view when opening case

This commit is contained in:
Magne Sjaastad 2021-09-01 08:25:22 +02:00 committed by GitHub
parent 638f926429
commit be29b278f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 30 deletions

View File

@ -70,6 +70,7 @@
///
//--------------------------------------------------------------------------------------------------
bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& fileNames,
bool createView,
FileCaseIdMap* openedFilesOut,
bool noDialog )
{
@ -87,7 +88,7 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& fil
// Import eclipse case files
for ( const QString& gridCaseFile : selector.gridCaseFiles() )
{
int caseId = RiaImportEclipseCaseTools::openEclipseCaseFromFile( gridCaseFile );
int caseId = RiaImportEclipseCaseTools::openEclipseCaseFromFile( gridCaseFile, createView );
if ( caseId >= 0 )
{
openedFiles.insert( std::make_pair( gridCaseFile, caseId ) );
@ -223,11 +224,11 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile( const QStringList& fil
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaImportEclipseCaseTools::openEclipseCaseFromFile( const QString& fileName )
int RiaImportEclipseCaseTools::openEclipseCaseFromFile( const QString& fileName, bool createView )
{
if ( !caf::Utils::fileExists( fileName ) ) return -1;
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, false );
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, createView, false );
}
//--------------------------------------------------------------------------------------------------
@ -237,7 +238,8 @@ bool RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilter( const QString
{
if ( !caf::Utils::fileExists( fileName ) ) return false;
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, true ) >= 0;
bool createView = true;
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( fileName, createView, true ) >= 0;
}
//--------------------------------------------------------------------------------------------------
@ -294,13 +296,16 @@ int RiaImportEclipseCaseTools::openEclipseInputCaseFromFileNames( const QStringL
//--------------------------------------------------------------------------------------------------
bool RiaImportEclipseCaseTools::openMockModel( const QString& name )
{
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( name, false );
bool createView = true;
return RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( name, createView, false );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter )
int RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( const QString& fileName,
bool showTimeStepFilter,
bool createView )
{
QFileInfo gridFileName( fileName );
QString caseName = gridFileName.completeBaseName();
@ -335,21 +340,33 @@ int RiaImportEclipseCaseTools::openEclipseCaseShowTimeStepFilterImpl( const QStr
return -1;
}
RimEclipseView* riv = rimResultReservoir->createAndAddReservoirView();
riv->loadDataAndUpdate();
if ( !riv->cellResult()->hasResult() )
if ( createView )
{
riv->cellResult()->setResultVariable( RiaResultNames::undefinedResultName() );
RimEclipseView* riv = rimResultReservoir->createAndAddReservoirView();
riv->loadDataAndUpdate();
if ( !riv->cellResult()->hasResult() )
{
riv->cellResult()->setResultVariable( RiaResultNames::undefinedResultName() );
}
analysisModels->updateConnectedEditors();
if ( RiaGuiApplication::isRunning() )
{
RiuMainWindow::instance()->selectAsCurrentItem( riv->cellResult() );
}
}
else
{
// Make sure the placeholder result entries are created, as this functionality is triggered when creating a
// view. See RimEclipseView::onLoadDataAndUpdate() and the call to openReserviorCase()
rimResultReservoir->openReserviorCase();
analysisModels->updateConnectedEditors();
}
analysisModels->updateConnectedEditors();
if ( RiaGuiApplication::isRunning() )
{
RiuMainWindow::instance()->selectAsCurrentItem( riv->cellResult() );
}
return rimResultReservoir->caseId();
}

View File

@ -34,8 +34,10 @@ public:
typedef std::map<QString, int> FileCaseIdMap;
static bool openEclipseCasesFromFile( const QStringList& fileNames,
bool createView,
FileCaseIdMap* openedFilesOut = nullptr,
bool noDialog = false );
static bool openEclipseCaseShowTimeStepFilter( const QString& fileName );
static int openEclipseInputCaseFromFileNames( const QStringList& fileNames, QString* fileContainingGrid = nullptr );
@ -43,8 +45,8 @@ public:
static bool addEclipseCases( const QStringList& fileNames, RimIdenticalGridCaseGroup** resultingCaseGroup = nullptr );
static int openEclipseCaseFromFile( const QString& fileName );
static int openEclipseCaseFromFile( const QString& fileName, bool createView );
private:
static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter );
static int openEclipseCaseShowTimeStepFilterImpl( const QString& fileName, bool showTimeStepFilter, bool createView );
};

View File

@ -56,16 +56,16 @@ caf::PdmScriptResponse RicfCreateView::execute()
if ( eclipseCase )
{
RimEclipseView* view = eclipseCase->createAndAddReservoirView();
viewId = view->id();
view->loadDataAndUpdate();
viewId = view->id();
eclipseCase->updateConnectedEditors();
Riu3DMainWindowTools::setExpanded( view );
}
else if ( geoMechCase )
{
RimGeoMechView* view = geoMechCase->createAndAddReservoirView();
viewId = view->id();
view->loadDataAndUpdate();
viewId = view->id();
geoMechCase->updateConnectedEditors();
Riu3DMainWindowTools::setExpanded( view );
}

View File

@ -64,7 +64,12 @@ caf::PdmScriptResponse RicfLoadCase::execute()
}
RiaImportEclipseCaseTools::FileCaseIdMap fileCaseIdMap;
bool ok = RiaImportEclipseCaseTools::openEclipseCasesFromFile( QStringList( { absolutePath } ), &fileCaseIdMap, true );
bool createView = false;
bool doNotShowDialog = true;
bool ok = RiaImportEclipseCaseTools::openEclipseCasesFromFile( QStringList( { absolutePath } ),
createView,
&fileCaseIdMap,
doNotShowDialog );
if ( !ok )
{
QString error = QString( "loadCase: Unable to load case from %1" ).arg( absolutePath );

View File

@ -51,7 +51,8 @@ bool RicImportGridModelFromSummaryCaseFeature::openOrImportGridModelFromSummaryC
if ( QFileInfo::exists( candidateGridFileName ) )
{
auto id = RiaImportEclipseCaseTools::openEclipseCaseFromFile( candidateGridFileName );
bool createView = true;
auto id = RiaImportEclipseCaseTools::openEclipseCaseFromFile( candidateGridFileName, createView );
if ( id > -1 )
{
RiaLogging::info( QString( "Imported %1" ).arg( candidateGridFileName ) );

View File

@ -935,7 +935,7 @@ void RimEnsembleFractureStatistics::sampleAllGrids( const std::vector<cvf::cref<
const std::vector<double>& samplesY,
std::vector<std::vector<double>>& samples )
{
const int ny = samplesY.size();
const int ny = static_cast<int>( samplesY.size() );
#pragma omp parallel for
for ( int y = 0; y < ny; y++ )
{

View File

@ -905,10 +905,8 @@ void RimEclipseCase::setFilesContainingFaults( const std::vector<QString>& pathS
//--------------------------------------------------------------------------------------------------
bool RimEclipseCase::ensureReservoirCaseIsOpen()
{
if ( m_rigEclipseCase.notNull() )
{
return true;
}
// Call openReserviorCase, as this is a cheap method to call multiple times
// Add extra testing here if performance issues are seen
return openReserviorCase();
}

View File

@ -17,6 +17,7 @@ path_name = os.path.join(
test_models_path, "TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
)
case = resinsight.project.load_case(path_name)
case.create_view()
# Print out lots of information from the case object
print("Case id: " + str(case.id))

View File

@ -101,7 +101,8 @@ def test_10k_PoroPermX(rips_instance, initialize_test):
def test_exportPropertyInView(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
rips_instance.project.load_case(case_path)
case = rips_instance.project.load_case(case_path)
case.create_view()
with tempfile.TemporaryDirectory(prefix="rips") as tmpdirname:
print("Temporary folder: ", tmpdirname)
rips_instance.set_export_folder(export_type="PROPERTIES", path=tmpdirname)

View File

@ -10,6 +10,7 @@ import dataroot
def test_10k(rips_instance, initialize_test):
case_path = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"
case = rips_instance.project.load_case(path=case_path)
case.create_view()
assert len(case.grids()) == 2
cell_count_info = case.cell_count()