2013-10-08 14:28:01 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 15:04:57 +02:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2013-10-08 14:28:01 +02:00
//
// 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 "RiaStdInclude.h"
#include "RiaApplication.h"
#include "cafEffectCache.h"
#include "cafUtils.h"
#include "cafAppEnum.h"
2015-08-04 11:47:06 +02:00
#include "cafPdmSettings.h"
2013-10-08 14:28:01 +02:00
#include "RiaVersionInfo.h"
#include "RiaBaseDefs.h"
//
#include "RiuMainWindow.h"
#include "RiuViewer.h"
#include "RiuProcessMonitor.h"
#include "RiaPreferences.h"
//
2015-06-25 13:23:36 +02:00
#include "RimEclipseResultCase.h"
2015-06-25 13:14:04 +02:00
#include "RimEclipseInputCase.h"
2015-05-21 10:34:38 +02:00
#include "RimEclipseView.h"
2013-10-08 14:28:01 +02:00
#include "RimWellPath.h"
#include "RimWellPathCollection.h"
#include "RimOilField.h"
2015-06-25 13:36:15 +02:00
#include "RimEclipseCaseCollection.h"
2014-07-24 10:11:43 +02:00
#include "RimFaultCollection.h"
2015-06-25 13:32:00 +02:00
#include "RimEclipseFaultColors.h"
2013-10-08 14:28:01 +02:00
#include "RiaSocketServer.h"
#include "cafUiProcess.h"
//
#include "RiaImageCompareReporter.h"
#include "RiaImageFileCompare.h"
2013-12-04 12:04:42 +01:00
#include "RiaProjectModifier.h"
2013-10-08 14:28:01 +02:00
#include "cafProgressInfo.h"
#include "RigGridManager.h"
#include "RimProject.h"
2015-06-25 13:32:00 +02:00
#include "RimEclipseCellColors.h"
2013-10-08 14:28:01 +02:00
#include "RimIdenticalGridCaseGroup.h"
2015-06-25 13:14:04 +02:00
#include "RimEclipseInputPropertyCollection.h"
2013-10-08 14:28:01 +02:00
#include "RimDefines.h"
#include "RimScriptCollection.h"
#include "RimCaseCollection.h"
////////////
#include "cafPdmFieldCvfColor.h"
#include "cafPdmFieldCvfMat4d.h"
2014-07-24 14:03:17 +02:00
#include "RimReservoirCellResultsStorage.h"
2015-06-25 13:45:32 +02:00
#include "RimCellEdgeColors.h"
2013-10-08 14:28:01 +02:00
#include "RimCellRangeFilterCollection.h"
2015-06-25 13:05:28 +02:00
#include "RimEclipsePropertyFilterCollection.h"
2013-10-08 14:28:01 +02:00
#include "Rim3dOverlayInfoConfig.h"
2015-06-25 13:36:15 +02:00
#include "RimEclipseWellCollection.h"
2015-06-25 13:23:36 +02:00
#include "RimEclipseStatisticsCase.h"
2013-10-20 00:42:14 +02:00
#include "cafCeetronPlusNavigation.h"
2013-10-08 14:28:01 +02:00
2013-12-04 12:04:42 +01:00
#include "cvfProgramOptions.h"
#include "cvfqtUtils.h"
2014-07-24 10:11:43 +02:00
#include "RimCommandObject.h"
2015-04-20 09:02:33 +02:00
#include "RimGeoMechCase.h"
#include "RimGeoMechModels.h"
#include "RimGeoMechView.h"
2015-06-25 13:32:00 +02:00
#include "RimGeoMechCellColors.h"
2015-09-03 08:09:06 +02:00
#include "RimMainPlotCollection.h"
#include "RimWellLogPlotCollection.h"
#include "RimWellLogPlot.h"
2013-12-04 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
namespace caf
{
template <>
void AppEnum < RiaApplication :: RINavigationPolicy >:: setUp ()
{
addItem ( RiaApplication :: NAVIGATION_POLICY_CEETRON , "NAVIGATION_POLICY_CEETRON" , "Ceetron" );
addItem ( RiaApplication :: NAVIGATION_POLICY_CAD , "NAVIGATION_POLICY_CAD" , "CAD" );
2015-07-02 12:31:35 +02:00
addItem ( RiaApplication :: NAVIGATION_POLICY_GEOQUEST , "NAVIGATION_POLICY_GEOQUEST" , "GEOQUEST" );
addItem ( RiaApplication :: NAVIGATION_POLICY_RMS , "NAVIGATION_POLICY_RMS" , "RMS" );
2015-07-02 13:33:07 +02:00
setDefault ( RiaApplication :: NAVIGATION_POLICY_RMS );
2013-10-08 14:28:01 +02:00
}
}
namespace RegTestNames
{
const QString generatedFolderName = "RegTestGeneratedImages" ;
const QString diffFolderName = "RegTestDiffImages" ;
const QString baseFolderName = "RegTestBaseImages" ;
const QString testProjectName = "RegressionTest.rip" ;
const QString testFolderFilter = "TestCase*" ;
const QString imageCompareExeName = "compare" ;
const QString reportFileName = "ResInsightRegressionTestReport.html" ;
};
2013-12-04 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
//==================================================================================================
///
/// \class RiaApplication
///
/// Application class
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication :: RiaApplication ( int & argc , char ** argv )
: QApplication ( argc , argv )
{
// USed to get registry settings in the right place
QCoreApplication :: setOrganizationName ( RI_COMPANY_NAME );
QCoreApplication :: setApplicationName ( RI_APPLICATION_NAME );
// For idle processing
// m_idleTimerStarted = false;
installEventFilter ( this );
//cvf::Trace::enable(false);
m_preferences = new RiaPreferences ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: readFieldsFromApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
applyPreferences ();
if ( useShaders ())
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: SHADER_BASED );
}
else
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: FIXED_FUNCTION );
}
// Start with a project
m_project = new RimProject ;
setWindowIcon ( QIcon ( ":/AppLogo48x48.png" ));
m_socketServer = new RiaSocketServer ( this );
m_workerProcess = NULL ;
#ifdef WIN32
m_startupDefaultDirectory = QDir :: homePath ();
#else
m_startupDefaultDirectory = QDir :: currentPath ();
#endif
setDefaultFileDialogDirectory ( "MULTICASEIMPORT" , "/" );
// The creation of a font is time consuming, so make sure you really need your own font
// instead of using the application font
m_standardFont = new cvf :: FixedAtlasFont ( cvf :: FixedAtlasFont :: STANDARD );
m_resViewUpdateTimer = NULL ;
2015-06-26 13:44:16 +02:00
m_runningRegressionTests = false ;
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication ::~ RiaApplication ()
{
delete m_preferences ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication * RiaApplication :: instance ()
{
return static_cast < RiaApplication *> qApp ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setWindowCaptionFromAppState ()
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
// The stuff being done here should really be handled by Qt automatically as a result of
// setting applicationName and windowFilePath
// Was unable to make this work in Qt4.4.0!
QString capt = RI_APPLICATION_NAME ;
#ifdef _DEBUG
capt += " ##DEBUG##" ;
#endif
{
QString projFileName = m_project -> fileName ();
if ( projFileName . isEmpty ()) projFileName = "Untitled project" ;
capt = projFileName + QString ( "[*]" ) + QString ( " - " ) + capt ;
}
mainWnd -> setWindowTitle ( capt );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: processNonGuiEvents ()
{
processEvents ( QEventLoop :: ExcludeUserInputEvents );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const char * RiaApplication :: getVersionStringApp ( bool includeCrtInfo )
{
// Use static buf so we can return ptr
static char szBuf [ 1024 ];
cvf :: String crtInfo ;
if ( includeCrtInfo )
{
#ifdef _MT
#ifdef _DLL
crtInfo = " (DLL CRT)" ;
#else
crtInfo = " (static CRT)" ;
#endif
#endif //_MT
}
cvf :: System :: sprintf ( szBuf , 1024 , "%s%s" , STRPRODUCTVER , crtInfo . toAscii (). ptr ());
return szBuf ;
}
2013-12-04 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-12-04 12:04:42 +01:00
bool RiaApplication :: loadProject ( const QString & projectFileName , ProjectLoadAction loadAction , RiaProjectModifier * projectModifier )
2013-10-08 14:28:01 +02:00
{
// First Close the current project
if ( ! closeProject ( true )) return false ;
// Open the project file and read the serialized data.
// Will initialize itself.
if ( ! QFile :: exists ( projectFileName )) return false ;
m_project -> fileName = projectFileName ;
m_project -> readFile ();
2013-12-04 12:04:42 +01:00
// Apply any modifiactions to the loaded project before we go ahead and load actual data
if ( projectModifier )
{
projectModifier -> applyModificationsToProject ( m_project );
}
2013-10-08 14:28:01 +02:00
// Propagate possible new location of project
m_project -> setProjectFileNameAndUpdateDependencies ( projectFileName );
// On error, delete everything, and bail out.
if ( m_project -> projectFileVersionString (). isEmpty ())
{
closeProject ( false );
QString tmp = QString ( "Unknown project file version detected in file \n %1 \n\n Could not open project." ). arg ( projectFileName );
QMessageBox :: warning ( NULL , "Error when opening project file" , tmp );
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
mainWnd -> setPdmRoot ( NULL );
// Delete all object possibly generated by readFile()
delete m_project ;
m_project = new RimProject ;
onProjectOpenedOrClosed ();
return true ;
}
///////
// Load the external data, and initialize stuff that needs specific ordering
// VL check regarding specific order mentioned in comment above...
m_preferences -> lastUsedProjectFileName = projectFileName ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project -> oilFields (). size (); oilFieldIdx ++ )
{
RimOilField * oilField = m_project -> oilFields [ oilFieldIdx ];
2015-06-25 12:11:06 +02:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField -> analysisModels () : NULL ;
2013-10-08 14:28:01 +02:00
if ( analysisModels == NULL ) continue ;
for ( size_t cgIdx = 0 ; cgIdx < analysisModels -> caseGroups . size (); ++ cgIdx )
{
// Load the Main case of each IdenticalGridCaseGroup
RimIdenticalGridCaseGroup * igcg = analysisModels -> caseGroups [ cgIdx ];
igcg -> loadMainCaseAndActiveCellInfo (); // VL is this supposed to be done for each RimOilField?
}
}
// Add well paths for each oil field
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project -> oilFields (). size (); oilFieldIdx ++ )
{
RimOilField * oilField = m_project -> oilFields [ oilFieldIdx ];
if ( oilField == NULL ) continue ;
if ( oilField -> wellPathCollection == NULL )
{
//printf("Create well path collection for oil field %i in loadProject.\n", oilFieldIdx);
oilField -> wellPathCollection = new RimWellPathCollection ();
oilField -> wellPathCollection -> setProject ( m_project );
}
if ( oilField -> wellPathCollection ) oilField -> wellPathCollection -> readWellPathFiles ();
}
2013-12-04 12:04:42 +01:00
// If load action is specified to recalculate statistics, do it now.
// Apparently this needs to be done before the views are loaded, lest the number of time steps for statistics will be clamped
if ( loadAction & PLA_CALCULATE_STATISTICS )
{
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project -> oilFields (). size (); oilFieldIdx ++ )
{
RimOilField * oilField = m_project -> oilFields [ oilFieldIdx ];
2015-06-25 12:11:06 +02:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField -> analysisModels () : NULL ;
2013-12-04 12:04:42 +01:00
if ( analysisModels )
{
analysisModels -> recomputeStatisticsForAllCaseGroups ();
}
}
}
2013-10-08 14:28:01 +02:00
// Now load the ReservoirViews for the cases
// Add all "native" cases in the project
2015-05-15 18:51:49 +02:00
std :: vector < RimCase *> casesToLoad ;
2013-10-08 14:28:01 +02:00
m_project -> allCases ( casesToLoad );
2015-09-03 08:09:06 +02:00
2013-10-08 14:28:01 +02:00
caf :: ProgressInfo caseProgress ( casesToLoad . size () , "Reading Cases" );
for ( size_t cIdx = 0 ; cIdx < casesToLoad . size (); ++ cIdx )
{
2015-05-15 18:51:49 +02:00
RimCase * cas = casesToLoad [ cIdx ];
CVF_ASSERT ( cas );
2013-10-08 14:28:01 +02:00
2015-05-15 18:51:49 +02:00
caseProgress . setProgressDescription ( cas -> caseUserDescription ());
std :: vector < RimView *> views = cas -> views ();
caf :: ProgressInfo viewProgress ( views . size () , "Creating Views" );
2013-10-08 14:28:01 +02:00
size_t j ;
2015-05-15 18:51:49 +02:00
for ( j = 0 ; j < views . size (); j ++ )
2013-10-08 14:28:01 +02:00
{
2015-05-15 18:51:49 +02:00
RimView * riv = views [ j ];
2013-10-08 14:28:01 +02:00
CVF_ASSERT ( riv );
viewProgress . setProgressDescription ( riv -> name ());
riv -> loadDataAndUpdate ();
this -> setActiveReservoirView ( riv );
viewProgress . incrementProgress ();
}
caseProgress . incrementProgress ();
}
2015-09-03 08:09:06 +02:00
{
if ( m_project -> mainPlotCollection () && m_project -> mainPlotCollection () -> wellLogPlotCollection ())
{
RimWellLogPlotCollection * wlpColl = m_project -> mainPlotCollection () -> wellLogPlotCollection ();
caf :: ProgressInfo plotProgress ( wlpColl -> wellLogPlots (). size (), "Loading Plot Data" );
2013-10-08 14:28:01 +02:00
2015-09-03 08:09:06 +02:00
for ( size_t wlpIdx = 0 ; wlpIdx < wlpColl -> wellLogPlots (). size (); ++ wlpIdx )
{
wlpColl -> wellLogPlots [ wlpIdx ] -> loadDataAndUpdate ();
plotProgress . incrementProgress ();
}
}
}
2013-10-08 14:28:01 +02:00
// NB! This function must be called before executing command objects,
// because the tree view state is restored from project file and sets
// current active view ( see restoreTreeViewState() )
// Default behavior for scripts is to use current active view for data read/write
onProjectOpenedOrClosed ();
processEvents ();
// Loop over command objects and execute them
for ( size_t i = 0 ; i < m_project -> commandObjects . size (); i ++ )
{
m_commandQueue . push_back ( m_project -> commandObjects [ i ]);
}
// Lock the command queue
m_commandQueueLock . lock ();
// Execute command objects, and release the mutex when the queue is empty
executeCommandObjects ();
return true ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: loadProject ( const QString & projectFileName )
{
return loadProject ( projectFileName , PLA_NONE , NULL );
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
/// Add a list of well path file paths (JSON files) to the well path collection
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addWellPathsToModel ( QList < QString > wellPathFilePaths )
{
if ( m_project == NULL || m_project -> oilFields . size () < 1 ) return ;
RimOilField * oilField = m_project -> activeOilField ();
if ( oilField == NULL ) return ;
if ( oilField -> wellPathCollection == NULL )
{
//printf("Create well path collection.\n");
oilField -> wellPathCollection = new RimWellPathCollection ();
oilField -> wellPathCollection -> setProject ( m_project );
2015-08-12 17:46:22 +02:00
m_project -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
}
if ( oilField -> wellPathCollection ) oilField -> wellPathCollection -> addWellPaths ( wellPathFilePaths );
2015-08-12 17:46:22 +02:00
oilField -> wellPathCollection -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
}
2015-09-14 16:33:28 +02:00
//--------------------------------------------------------------------------------------------------
/// Add a list of well log file paths (LAS files) to the well path collection
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addWellLogsToModel ( const QList < QString >& wellLogFilePaths )
{
if ( m_project == NULL || m_project -> oilFields . size () < 1 ) return ;
RimOilField * oilField = m_project -> activeOilField ();
if ( oilField == NULL ) return ;
if ( oilField -> wellPathCollection == NULL )
{
oilField -> wellPathCollection = new RimWellPathCollection ();
oilField -> wellPathCollection -> setProject ( m_project );
m_project -> updateConnectedEditors ();
}
if ( oilField -> wellPathCollection ) oilField -> wellPathCollection -> addWellLogs ( wellLogFilePaths );
oilField -> wellPathCollection -> updateConnectedEditors ();
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: saveProject ()
{
CVF_ASSERT ( m_project . notNull ());
if ( ! QFile :: exists ( m_project -> fileName ()))
{
return saveProjectPromptForFileName ();
}
else
{
return saveProjectAs ( m_project -> fileName ());
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: saveProjectPromptForFileName ()
{
//if (m_project.isNull()) return true;
RiaApplication * app = RiaApplication :: instance ();
QString startPath ;
if ( ! m_project -> fileName (). isEmpty ())
{
QFileInfo fi ( m_project -> fileName ());
startPath = fi . absolutePath ();
}
else
{
startPath = app -> defaultFileDialogDirectory ( "BINARY_GRID" );
}
startPath += "/ResInsightProject.rsp" ;
QString fileName = QFileDialog :: getSaveFileName ( NULL , tr ( "Save File" ), startPath , tr ( "Project Files (*.rsp);;All files(*.*)" ));
if ( fileName . isEmpty ())
{
return false ;
}
// Remember the directory to next time
app -> setDefaultFileDialogDirectory ( "BINARY_GRID" , QFileInfo ( fileName ). absolutePath ());
bool bSaveOk = saveProjectAs ( fileName );
setWindowCaptionFromAppState ();
return bSaveOk ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: saveProjectAs ( const QString & fileName )
{
m_project -> fileName = fileName ;
m_project -> writeFile ();
m_preferences -> lastUsedProjectFileName = fileName ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: closeProject ( bool askToSaveIfDirty )
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
terminateProcess ();
if ( false )
{
QMessageBox msgBox ( mainWnd );
msgBox . setIcon ( QMessageBox :: Warning );
msgBox . setText ( "The project being closed has been modified." );
msgBox . setInformativeText ( "Do you want to save your changes?" );
msgBox . setStandardButtons ( QMessageBox :: Save | QMessageBox :: Discard | QMessageBox :: Cancel );
//msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox . exec ();
if ( ret == QMessageBox :: Save )
{
//m_sceneManager->saveAll();
}
else if ( ret == QMessageBox :: Cancel )
{
return false ;
}
}
mainWnd -> cleanupGuiBeforeProjectClose ();
caf :: EffectGenerator :: clearEffectCache ();
m_project -> close ();
m_commandQueue . clear ();
onProjectOpenedOrClosed ();
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: onProjectOpenedOrClosed ()
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
mainWnd -> initializeGuiNewProjectLoaded ();
//mainWnd->redrawAllViews();
setWindowCaptionFromAppState ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: currentProjectFileName () const
{
return m_project -> fileName ();
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
/// Create an absolute path from a path that is specified relative to the project directory
///
/// If the path specified in \a projectRelativePath is already absolute, no changes will be made
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: createAbsolutePathFromProjectRelativePath ( QString projectRelativePath )
{
// Check if path is already absolute
if ( QDir :: isAbsolutePath ( projectRelativePath ))
{
return projectRelativePath ;
}
if ( m_project && ! m_project -> fileName (). isEmpty ())
{
QString absoluteProjectPath = QFileInfo ( m_project -> fileName ()). absolutePath ();
QDir projectDir ( absoluteProjectPath );
return projectDir . absoluteFilePath ( projectRelativePath );
}
else
{
return projectRelativePath ;
}
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openEclipseCaseFromFile ( const QString & fileName )
{
if ( ! QFile :: exists ( fileName )) return false ;
QFileInfo gridFileName ( fileName );
QString caseName = gridFileName . completeBaseName ();
return openEclipseCase ( caseName , fileName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openEclipseCase ( const QString & caseName , const QString & caseFileName )
{
2015-06-25 11:56:18 +02:00
RimEclipseResultCase * rimResultReservoir = new RimEclipseResultCase ();
2013-10-08 14:28:01 +02:00
rimResultReservoir -> setCaseInfo ( caseName , caseFileName );
2015-06-25 12:11:06 +02:00
RimEclipseCaseCollection * analysisModels = m_project -> activeOilField () ? m_project -> activeOilField () -> analysisModels () : NULL ;
2013-10-08 14:28:01 +02:00
if ( analysisModels == NULL ) return false ;
analysisModels -> cases . push_back ( rimResultReservoir );
2015-05-21 10:05:33 +02:00
RimEclipseView * riv = rimResultReservoir -> createAndAddReservoirView ();
2013-10-08 14:28:01 +02:00
// Select SOIL as default result variable
riv -> cellResult () -> setResultType ( RimDefines :: DYNAMIC_NATIVE );
2014-10-24 11:38:47 +02:00
if ( m_preferences -> loadAndShowSoil )
{
riv -> cellResult () -> setResultVariable ( "SOIL" );
}
2015-06-09 16:18:11 +02:00
riv -> hasUserRequestedAnimation = true ;
2013-10-08 14:28:01 +02:00
riv -> loadDataAndUpdate ();
if ( ! riv -> cellResult () -> hasResult ())
{
riv -> cellResult () -> setResultVariable ( RimDefines :: undefinedResultName ());
}
2015-08-13 21:28:09 +02:00
analysisModels -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
RiuMainWindow :: instance () -> setCurrentObjectInTreeView ( riv -> cellResult ());
2015-08-10 18:22:54 +02:00
2013-10-08 14:28:01 +02:00
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openInputEclipseCaseFromFileNames ( const QStringList & fileNames )
{
2015-06-25 11:50:13 +02:00
RimEclipseInputCase * rimInputReservoir = new RimEclipseInputCase ();
2013-10-08 14:28:01 +02:00
m_project -> assignCaseIdToCase ( rimInputReservoir );
rimInputReservoir -> openDataFileSet ( fileNames );
2015-06-25 12:11:06 +02:00
RimEclipseCaseCollection * analysisModels = m_project -> activeOilField () ? m_project -> activeOilField () -> analysisModels () : NULL ;
2013-10-08 14:28:01 +02:00
if ( analysisModels == NULL ) return false ;
analysisModels -> cases . push_back ( rimInputReservoir );
2015-05-21 10:05:33 +02:00
RimEclipseView * riv = rimInputReservoir -> createAndAddReservoirView ();
2013-10-08 14:28:01 +02:00
riv -> cellResult () -> setResultType ( RimDefines :: INPUT_PROPERTY );
2015-06-09 16:18:11 +02:00
riv -> hasUserRequestedAnimation = true ;
2013-10-08 14:28:01 +02:00
riv -> loadDataAndUpdate ();
if ( ! riv -> cellResult () -> hasResult ())
{
riv -> cellResult () -> setResultVariable ( RimDefines :: undefinedResultName ());
}
2015-08-13 21:28:09 +02:00
analysisModels -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
RiuMainWindow :: instance () -> setCurrentObjectInTreeView ( riv -> cellResult ());
return true ;
}
2015-04-20 09:02:33 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openOdbCaseFromFile ( const QString & fileName )
{
if ( ! QFile :: exists ( fileName )) return false ;
QFileInfo gridFileName ( fileName );
QString caseName = gridFileName . completeBaseName ();
RimGeoMechCase * geoMechCase = new RimGeoMechCase ();
2015-04-25 08:57:34 +02:00
geoMechCase -> setFileName ( fileName );
2015-04-20 09:02:33 +02:00
geoMechCase -> caseUserDescription = caseName ;
RimGeoMechModels * geoMechModelCollection = m_project -> activeOilField () ? m_project -> activeOilField () -> geoMechModels () : NULL ;
// Create the geoMech model container if it is not there already
if ( geoMechModelCollection == NULL )
{
geoMechModelCollection = new RimGeoMechModels ();
m_project -> activeOilField () -> geoMechModels = geoMechModelCollection ;
}
geoMechModelCollection -> cases . push_back ( geoMechCase );
RimGeoMechView * riv = geoMechCase -> createAndAddReservoirView ();
2015-05-29 12:14:40 +02:00
caf :: ProgressInfo progress ( 11 , "Loading Case" );
progress . setNextProgressIncrement ( 10 );
2015-04-20 09:02:33 +02:00
2015-04-20 16:56:26 +02:00
riv -> loadDataAndUpdate ();
2015-04-20 09:02:33 +02:00
//if (!riv->cellResult()->hasResult())
//{
// riv->cellResult()->setResultVariable(RimDefines::undefinedResultName());
//}
2015-05-29 12:14:40 +02:00
progress . incrementProgress ();
progress . setProgressDescription ( "Loading results information" );
2015-04-20 09:02:33 +02:00
2015-08-13 21:28:09 +02:00
m_project -> updateConnectedEditors ();
2015-04-20 09:02:33 +02:00
RiuMainWindow :: instance () -> setCurrentObjectInTreeView ( riv -> cellResult ());
2015-05-29 12:14:40 +02:00
2015-04-20 09:02:33 +02:00
return true ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createMockModel ()
{
2013-10-28 07:30:00 +01:00
openEclipseCase ( RimDefines :: mockModelBasic (), RimDefines :: mockModelBasic ());
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createResultsMockModel ()
{
2013-10-28 07:30:00 +01:00
openEclipseCase ( RimDefines :: mockModelBasicWithResults (), RimDefines :: mockModelBasicWithResults ());
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createLargeResultsMockModel ()
{
2013-10-28 07:30:00 +01:00
openEclipseCase ( RimDefines :: mockModelLargeWithResults (), RimDefines :: mockModelLargeWithResults ());
2013-10-08 14:28:01 +02:00
}
2013-10-28 10:32:24 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createMockModelCustomized ()
{
openEclipseCase ( RimDefines :: mockModelCustomized (), RimDefines :: mockModelCustomized ());
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createInputMockModel ()
{
2013-10-28 10:32:24 +01:00
openInputEclipseCaseFromFileNames ( QStringList ( RimDefines :: mockModelBasicInputCase ()));
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-05-08 14:13:26 +02:00
const RimView * RiaApplication :: activeReservoirView () const
2013-10-08 14:28:01 +02:00
{
return m_activeReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-05-08 14:13:26 +02:00
RimView * RiaApplication :: activeReservoirView ()
2013-10-08 14:28:01 +02:00
{
return m_activeReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-05-08 14:13:26 +02:00
void RiaApplication :: setActiveReservoirView ( RimView * rv )
2013-10-08 14:28:01 +02:00
{
m_activeReservoirView = rv ;
}
2015-09-10 08:14:28 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setActiveWellLogPlot ( RimWellLogPlot * wlp )
{
m_activeWellLogPlot = wlp ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogPlot * RiaApplication :: activeWellLogPlot ()
{
return m_activeWellLogPlot ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setUseShaders ( bool enable )
{
m_preferences -> useShaders = enable ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: useShaders () const
{
if ( ! m_preferences -> useShaders ) return false ;
bool isShadersSupported = caf :: Viewer :: isShadersSupported ();
if ( ! isShadersSupported ) return false ;
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication :: RINavigationPolicy RiaApplication :: navigationPolicy () const
{
return m_preferences -> navigationPolicy ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setShowPerformanceInfo ( bool enable )
{
m_preferences -> showHud = enable ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: showPerformanceInfo () const
{
return m_preferences -> showHud ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: parseArguments ()
{
cvf :: ProgramOptions progOpt ;
2013-12-19 10:06:56 +01:00
progOpt . registerOption ( "last" , "" , "Open last used project." );
progOpt . registerOption ( "project" , "<filename>" , "Open project file <filename>." , cvf :: ProgramOptions :: SINGLE_VALUE );
progOpt . registerOption ( "case" , "<casename>" , "Import Eclipse case <casename> (do not include the .GRID/.EGRID extension.)" , cvf :: ProgramOptions :: MULTI_VALUE );
progOpt . registerOption ( "startdir" , "<folder>" , "Set startup directory." , cvf :: ProgramOptions :: SINGLE_VALUE );
progOpt . registerOption ( "savesnapshots" , "" , "Save snapshot of all views to 'snapshots' folder. Application closes after snapshots have been written." );
progOpt . registerOption ( "size" , "<width> <height>" , "Set size of the main application window." , cvf :: ProgramOptions :: MULTI_VALUE );
progOpt . registerOption ( "replaceCase" , "[<caseId>] <newGridFile>" , "Replace grid in <caseId> or first case with <newgridFile>." , cvf :: ProgramOptions :: MULTI_VALUE );
progOpt . registerOption ( "replaceSourceCases" , "[<caseGroupId>] <gridListFile>" , "Replace source cases in <caseGroupId> or first grid case group with the grid files listed in the <gridListFile> file." , cvf :: ProgramOptions :: MULTI_VALUE );
progOpt . registerOption ( "multiCaseSnapshots" , "<gridListFile>" , "For each grid file listed in the <gridListFile> file, replace the first case in the project and save snapshot of all views." , cvf :: ProgramOptions :: SINGLE_VALUE );
progOpt . registerOption ( "help" , "" , "Displays help text." );
progOpt . registerOption ( "?" , "" , "Displays help text." );
2013-12-04 12:04:42 +01:00
progOpt . registerOption ( "regressiontest" , "<folder>" , "" , cvf :: ProgramOptions :: SINGLE_VALUE );
progOpt . registerOption ( "updateregressiontestbase" , "<folder>" , "" , cvf :: ProgramOptions :: SINGLE_VALUE );
progOpt . setOptionPrefix ( cvf :: ProgramOptions :: DOUBLE_DASH );
2013-12-19 10:45:15 +01:00
m_helpText = QString ( " \n %1 v. %2 \n " ). arg ( RI_APPLICATION_NAME ). arg ( getVersionStringApp ( false ));
2014-09-24 07:21:26 +02:00
m_helpText += "Copyright Statoil ASA, Ceetron Solution AS, Ceetron AS \n\n " ;
2013-12-19 10:45:15 +01:00
const cvf :: String usageText = progOpt . usageText ( 110 , 30 );
m_helpText += cvfqt :: Utils :: toQString ( usageText );
2013-12-04 12:04:42 +01:00
QStringList arguments = QCoreApplication :: arguments ();
bool parseOk = progOpt . parse ( cvfqt :: Utils :: toStringVector ( arguments ));
2014-06-05 07:34:34 +02:00
// If positional parameter functionality is to be supported, the test for existence of positionalParameters must be removed
// This is based on a pull request by @andlaus https://github.com/OPM/ResInsight/pull/162
if ( ! parseOk ||
progOpt . hasOption ( "help" ) ||
progOpt . hasOption ( "?" ) ||
progOpt . positionalParameters (). size () > 0 )
2013-12-04 12:04:42 +01:00
{
#if defined(_MSC_VER) && defined(_WIN32)
2013-12-19 10:45:15 +01:00
showFormattedTextInMessageBox ( m_helpText );
2013-12-04 12:04:42 +01:00
#else
2013-12-19 11:06:59 +01:00
fprintf ( stdout , "%s \n " , m_helpText . toAscii (). data ());
2013-12-04 12:04:42 +01:00
fflush ( stdout );
#endif
return false ;
}
// Handling of the actual command line options
// --------------------------------------------------------
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "regressiontest" ))
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
CVF_ASSERT ( o . valueCount () == 1 );
QString regressionTestPath = cvfqt :: Utils :: toQString ( o . value ( 0 ));
2013-12-04 12:04:42 +01:00
executeRegressionTests ( regressionTestPath );
return false ;
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "updateregressiontestbase" ))
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
CVF_ASSERT ( o . valueCount () == 1 );
QString regressionTestPath = cvfqt :: Utils :: toQString ( o . value ( 0 ));
2013-12-04 12:04:42 +01:00
updateRegressionTest ( regressionTestPath );
return false ;
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "startdir" ))
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
CVF_ASSERT ( o . valueCount () == 1 );
m_startupDefaultDirectory = cvfqt :: Utils :: toQString ( o . value ( 0 ));
2013-12-04 12:04:42 +01:00
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "size" ))
2013-12-04 12:04:42 +01:00
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
2013-12-04 14:56:04 +01:00
int width = o . safeValue ( 0 ). toInt ( - 1 );
int height = o . safeValue ( 1 ). toInt ( - 1 );
2013-12-04 12:04:42 +01:00
if ( mainWnd && width > 0 && height > 0 )
{
mainWnd -> resize ( width , height );
}
}
QString projectFileName ;
if ( progOpt . hasOption ( "last" ))
{
projectFileName = m_preferences -> lastUsedProjectFileName ;
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "project" ))
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
CVF_ASSERT ( o . valueCount () == 1 );
projectFileName = cvfqt :: Utils :: toQString ( o . value ( 0 ));
2013-12-04 12:04:42 +01:00
}
2013-12-04 14:56:04 +01:00
if ( ! projectFileName . isEmpty ())
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "multiCaseSnapshots" ))
{
QString gridListFile = cvfqt :: Utils :: toQString ( o . safeValue ( 0 ));
std :: vector < QString > gridFiles = readFileListFromTextFile ( gridListFile );
runMultiCaseSnapshots ( projectFileName , gridFiles , "multiCaseSnapshots" );
return false ;
}
2013-12-04 12:04:42 +01:00
}
if ( ! projectFileName . isEmpty ())
{
cvf :: ref < RiaProjectModifier > projectModifier ;
ProjectLoadAction projectLoadAction = PLA_NONE ;
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "replaceCase" ))
2013-12-04 12:04:42 +01:00
{
if ( projectModifier . isNull ()) projectModifier = new RiaProjectModifier ;
2013-12-04 14:56:04 +01:00
const int caseId = o . safeValue ( 0 ). toInt ( - 1 );
if ( caseId != - 1 && o . valueCount () > 1 )
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
QString gridFileName = cvfqt :: Utils :: toQString ( o . value ( 1 ));
projectModifier -> setReplaceCase ( caseId , gridFileName );
2013-12-04 12:04:42 +01:00
}
else
{
2013-12-04 14:56:04 +01:00
QString gridFileName = cvfqt :: Utils :: toQString ( o . safeValue ( 0 ));
projectModifier -> setReplaceCaseFirstOccurence ( gridFileName );
2013-12-04 12:04:42 +01:00
}
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "replaceSourceCases" ))
2013-12-04 12:04:42 +01:00
{
if ( projectModifier . isNull ()) projectModifier = new RiaProjectModifier ;
2013-12-04 14:56:04 +01:00
const int caseGroupId = o . safeValue ( 0 ). toInt ( - 1 );
if ( caseGroupId != - 1 && o . valueCount () > 1 )
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
std :: vector < QString > gridFileNames = readFileListFromTextFile ( cvfqt :: Utils :: toQString ( o . value ( 1 )));
projectModifier -> setReplaceSourceCasesById ( caseGroupId , gridFileNames );
2013-12-04 12:04:42 +01:00
}
else
{
2013-12-04 14:56:04 +01:00
std :: vector < QString > gridFileNames = readFileListFromTextFile ( cvfqt :: Utils :: toQString ( o . safeValue ( 0 )));
projectModifier -> setReplaceSourceCasesFirstOccurence ( gridFileNames );
2013-12-04 12:04:42 +01:00
}
projectLoadAction = PLA_CALCULATE_STATISTICS ;
}
loadProject ( projectFileName , projectLoadAction , projectModifier . p ());
}
2013-12-04 14:56:04 +01:00
if ( cvf :: Option o = progOpt . option ( "case" ))
2013-12-04 12:04:42 +01:00
{
2013-12-04 14:56:04 +01:00
QStringList caseNames = cvfqt :: Utils :: toQStringList ( o . values ());
2013-12-04 12:04:42 +01:00
foreach ( QString caseName , caseNames )
{
QString caseFileNameWithExt = caseName + ".EGRID" ;
if ( QFile :: exists ( caseFileNameWithExt ))
{
openEclipseCaseFromFile ( caseFileNameWithExt );
}
else
{
caseFileNameWithExt = caseName + ".GRID" ;
if ( QFile :: exists ( caseFileNameWithExt ))
{
openEclipseCaseFromFile ( caseFileNameWithExt );
}
}
}
}
if ( progOpt . hasOption ( "savesnapshots" ))
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( m_project . notNull () && ! m_project -> fileName (). isEmpty () && mainWnd )
{
mainWnd -> hideAllDockWindows ();
// Will be saved relative to current directory
saveSnapshotForAllViews ( "snapshots" );
mainWnd -> loadWinGeoAndDockToolBarLayout ();
}
// Returning false will exit the application
return false ;
}
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std :: vector < QString > RiaApplication :: readFileListFromTextFile ( QString listFileName )
{
std :: vector < QString > fileList ;
QFile file ( listFileName );
if ( ! file . open ( QIODevice :: ReadOnly | QIODevice :: Text ))
{
return fileList ;
}
QTextStream in ( & file );
QString line = in . readLine ();
while ( ! line . isNull ())
{
line = line . trimmed ();
if ( ! line . isEmpty ())
{
fileList . push_back ( line );
}
line = in . readLine ();
}
return fileList ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: scriptDirectories () const
{
return m_preferences -> scriptDirectories ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: scriptEditorPath () const
{
return m_preferences -> scriptEditorExecutable ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: octavePath () const
{
return m_preferences -> octaveExecutable ();
}
2014-07-22 12:11:48 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaApplication :: octaveArguments () const
{
// http://www.gnu.org/software/octave/doc/interpreter/Command-Line-Options.html#Command-Line-Options
// -p path
// Add path to the head of the search path for function files. The value of path specified on the command line
// will override any value of OCTAVE_PATH found in the environment, but not any commands in the system or
// user startup files that set the internal load path through one of the path functions.
QStringList arguments ;
arguments . append ( "--path" );
arguments << QApplication :: applicationDirPath ();
if ( ! m_preferences -> octaveShowHeaderInfoWhenExecutingScripts )
{
// -q
// Don't print the usual greeting and version message at startup.
arguments . append ( "-q" );
}
return arguments ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: slotWorkerProcessFinished ( int exitCode , QProcess :: ExitStatus exitStatus )
{
RiuMainWindow :: instance () -> processMonitor () -> stopMonitorWorkProcess ();
// Execute delete later so that other slots that are hooked up
// get a chance to run before we delete the object
if ( m_workerProcess )
{
m_workerProcess -> close ();
}
m_workerProcess = NULL ;
// Either the work process crashed or was aborted by the user
if ( exitStatus == QProcess :: CrashExit )
{
// MFLog::error("Simulation execution crashed or was aborted.");
return ;
}
executeCommandObjects ();
// Exit code != 0 means we have an error
if ( exitCode != 0 )
{
// MFLog::error(QString("Simulation execution failed (exit code %1).").arg(exitCode));
return ;
}
// If multiple cases are present, invoke launchProcess() which will set next current case, and run script on this case
if ( m_currentCaseIds . size () > 0 )
{
launchProcess ( m_currentProgram , m_currentArguments );
}
else
{
// Disable concept of current case
m_socketServer -> setCurrentCaseId ( - 1 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: launchProcess ( const QString & program , const QStringList & arguments )
{
if ( m_workerProcess == NULL )
{
// If multiple cases are present, pop the first case ID from the list and set as current case
if ( m_currentCaseIds . size () > 0 )
{
int nextCaseId = m_currentCaseIds . front ();
m_currentCaseIds . pop_front ();
m_socketServer -> setCurrentCaseId ( nextCaseId );
}
else
{
// Disable current case concept
m_socketServer -> setCurrentCaseId ( - 1 );
}
m_workerProcess = new caf :: UiProcess ( this );
QProcessEnvironment penv = QProcessEnvironment :: systemEnvironment ();
2014-01-02 14:31:10 +01:00
#ifdef WIN32
// Octave plugins compiled by ResInsight are dependent on Qt (currently Qt 32-bit only)
// Some Octave installations for Windows have included Qt, and some don't. To make sure these plugins always can be executed,
// the path to octave_plugin_dependencies is added to global path
QString pathString = penv . value ( "PATH" , "" );
if ( pathString == "" ) pathString = QApplication :: applicationDirPath () + " \\ octave_plugin_dependencies" ;
else pathString = QApplication :: applicationDirPath () + " \\ octave_plugin_dependencies" + ";" + pathString ;
penv . insert ( "PATH" , pathString );
#else
// Set the LD_LIBRARY_PATH to make the octave plugins find the embedded Qt
QString ldPath = penv . value ( "LD_LIBRARY_PATH" , "" );
if ( ldPath == "" ) ldPath = QApplication :: applicationDirPath ();
else ldPath = QApplication :: applicationDirPath () + ":" + ldPath ;
penv . insert ( "LD_LIBRARY_PATH" , ldPath );
#endif
2013-10-08 14:28:01 +02:00
m_workerProcess -> setProcessEnvironment ( penv );
connect ( m_workerProcess , SIGNAL ( finished ( int , QProcess :: ExitStatus )), SLOT ( slotWorkerProcessFinished ( int , QProcess :: ExitStatus )));
RiuMainWindow :: instance () -> processMonitor () -> startMonitorWorkProcess ( m_workerProcess );
m_workerProcess -> start ( program , arguments );
if ( ! m_workerProcess -> waitForStarted ( 1000 ))
{
m_workerProcess -> close ();
m_workerProcess = NULL ;
RiuMainWindow :: instance () -> processMonitor () -> stopMonitorWorkProcess ();
QMessageBox :: warning ( RiuMainWindow :: instance (), "Script execution" , "Failed to start script executable located at \n " + program );
return false ;
}
return true ;
}
else
{
QMessageBox :: warning ( NULL , "Script execution" , "An Octave process is still running. Please stop this process before executing a new script." );
return false ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: launchProcessForMultipleCases ( const QString & program , const QStringList & arguments , const std :: vector < int >& caseIds )
{
m_currentCaseIds . clear ();
std :: copy ( caseIds . begin (), caseIds . end (), std :: back_inserter ( m_currentCaseIds ) );
m_currentProgram = program ;
m_currentArguments = arguments ;
return launchProcess ( m_currentProgram , m_currentArguments );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaPreferences * RiaApplication :: preferences ()
{
return m_preferences ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: applyPreferences ()
{
if ( m_activeReservoirView && m_activeReservoirView -> viewer ())
{
2015-07-02 12:44:57 +02:00
m_activeReservoirView -> viewer () -> updateNavigationPolicy ();
2013-10-08 14:28:01 +02:00
m_activeReservoirView -> viewer () -> enablePerfInfoHud ( m_preferences -> showHud ());
}
if ( useShaders ())
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: SHADER_BASED );
}
else
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: FIXED_FUNCTION );
}
if ( this -> project ())
{
this -> project () -> setScriptDirectories ( m_preferences -> scriptDirectories ());
2015-08-13 21:28:09 +02:00
this -> project () -> scriptCollection () -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: terminateProcess ()
{
if ( m_workerProcess )
{
m_workerProcess -> close ();
}
m_workerProcess = NULL ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: defaultFileDialogDirectory ( const QString & dialogName )
{
QString defaultDirectory = m_startupDefaultDirectory ;
std :: map < QString , QString >:: iterator it ;
it = m_fileDialogDefaultDirectories . find ( dialogName );
if ( it != m_fileDialogDefaultDirectories . end ())
{
defaultDirectory = it -> second ;
}
return defaultDirectory ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setDefaultFileDialogDirectory ( const QString & dialogName , const QString & defaultDirectory )
{
m_fileDialogDefaultDirectories [ dialogName ] = defaultDirectory ;
}
2013-12-04 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: saveSnapshotPromtpForFilename ()
{
QString startPath ;
if ( ! m_project -> fileName (). isEmpty ())
{
QFileInfo fi ( m_project -> fileName ());
startPath = fi . absolutePath ();
}
else
{
startPath = defaultFileDialogDirectory ( "IMAGE_SNAPSHOT" );
}
startPath += "/image.png" ;
QString fileName = QFileDialog :: getSaveFileName ( NULL , tr ( "Save File" ), startPath , tr ( "Image files (*.bmp *.png * *.jpg)" ));
if ( fileName . isEmpty ())
{
return ;
}
// Remember the directory to next time
setDefaultFileDialogDirectory ( "IMAGE_SNAPSHOT" , QFileInfo ( fileName ). absolutePath ());
saveSnapshotAs ( fileName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: saveSnapshotAs ( const QString & fileName )
{
QImage image = grabFrameBufferImage ();
if ( ! image . isNull ())
{
if ( image . save ( fileName ))
{
qDebug () << "Saved snapshot image to " << fileName ;
}
else
{
qDebug () << "Error when trying to save snapshot image to " << fileName ;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: copySnapshotToClipboard ()
{
QClipboard * clipboard = QApplication :: clipboard ();
if ( clipboard )
{
QImage image = grabFrameBufferImage ();
if ( ! image . isNull ())
{
clipboard -> setImage ( image );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: saveSnapshotForAllViews ( const QString & snapshotFolderName )
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
if ( m_project . isNull ()) return ;
2013-12-04 12:04:42 +01:00
QDir snapshotPath ( snapshotFolderName );
if ( ! snapshotPath . exists ())
2013-10-08 14:28:01 +02:00
{
2013-12-04 12:04:42 +01:00
if ( ! snapshotPath . mkpath ( "." )) return ;
2013-10-08 14:28:01 +02:00
}
2013-12-04 12:04:42 +01:00
const QString absSnapshotPath = snapshotPath . absolutePath ();
2013-10-08 14:28:01 +02:00
2015-05-15 18:51:49 +02:00
std :: vector < RimCase *> projectCases ;
2013-10-08 14:28:01 +02:00
m_project -> allCases ( projectCases );
for ( size_t i = 0 ; i < projectCases . size (); i ++ )
{
2015-05-15 18:51:49 +02:00
RimCase * cas = projectCases [ i ];
if ( ! cas ) continue ;
std :: vector < RimView *> views = cas -> views ();
2013-10-08 14:28:01 +02:00
2015-05-15 18:51:49 +02:00
for ( size_t j = 0 ; j < views . size (); j ++ )
2013-10-08 14:28:01 +02:00
{
2015-05-15 18:51:49 +02:00
RimView * riv = views [ j ];
2013-10-08 14:28:01 +02:00
if ( riv && riv -> viewer ())
{
setActiveReservoirView ( riv );
RiuViewer * viewer = riv -> viewer ();
2015-09-02 15:53:49 +02:00
mainWnd -> setActiveViewer ( viewer -> layoutWidget ());
2013-10-08 14:28:01 +02:00
// Process all events to avoid a black image when grabbing frame buffer
QCoreApplication :: processEvents ();
2015-05-15 18:51:49 +02:00
QString fileName = cas -> caseUserDescription () + "-" + riv -> name ();
2014-01-23 09:25:22 +01:00
fileName . replace ( " " , "_" );
2013-10-08 14:28:01 +02:00
2013-12-04 12:04:42 +01:00
QString absoluteFileName = caf :: Utils :: constructFullFileName ( absSnapshotPath , fileName , ".png" );
2013-10-08 14:28:01 +02:00
saveSnapshotAs ( absoluteFileName );
}
}
}
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: runMultiCaseSnapshots ( const QString & templateProjectFileName , std :: vector < QString > gridFileNames , const QString & snapshotFolderName )
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
mainWnd -> hideAllDockWindows ();
const size_t numGridFiles = gridFileNames . size ();
for ( size_t i = 0 ; i < numGridFiles ; i ++ )
{
QString gridFn = gridFileNames [ i ];
RiaProjectModifier modifier ;
modifier . setReplaceCaseFirstOccurence ( gridFn );
bool loadOk = loadProject ( templateProjectFileName , PLA_NONE , & modifier );
if ( loadOk )
{
saveSnapshotForAllViews ( snapshotFolderName );
}
}
mainWnd -> loadWinGeoAndDockToolBarLayout ();
}
2013-10-08 14:28:01 +02:00
void removeDirectoryWithContent ( QDir dirToDelete )
{
QStringList files = dirToDelete . entryList ();
for ( int fIdx = 0 ; fIdx < files . size (); ++ fIdx )
{
dirToDelete . remove ( files [ fIdx ]);
}
dirToDelete . rmdir ( "." );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: runRegressionTest ( const QString & testRootPath )
{
2015-06-26 13:44:16 +02:00
m_runningRegressionTests = true ;
2013-10-08 14:28:01 +02:00
QString generatedFolderName = RegTestNames :: generatedFolderName ;
QString diffFolderName = RegTestNames :: diffFolderName ;
QString baseFolderName = RegTestNames :: baseFolderName ;
QString regTestProjectName = RegTestNames :: testProjectName ;
QString regTestFolderFilter = RegTestNames :: testFolderFilter ;
// Find all sub folders
QDir testDir ( testRootPath ); // If string is empty it will end up as cwd
testDir . setFilter ( QDir :: Dirs );
QStringList dirNameFilter ;
dirNameFilter . append ( regTestFolderFilter );
testDir . setNameFilters ( dirNameFilter );
QFileInfoList folderList = testDir . entryInfoList ();
// delete diff and generated images
for ( int i = 0 ; i < folderList . size (); ++ i )
{
QDir testCaseFolder ( folderList [ i ]. filePath ());
QDir genDir ( testCaseFolder . filePath ( generatedFolderName ));
removeDirectoryWithContent ( genDir );
QDir diffDir ( testCaseFolder . filePath ( diffFolderName ));
removeDirectoryWithContent ( diffDir );
QDir baseDir ( testCaseFolder . filePath ( baseFolderName ));
}
// Generate html report
RiaImageCompareReporter imageCompareReporter ;
for ( int dirIdx = 0 ; dirIdx < folderList . size (); ++ dirIdx )
{
QDir testCaseFolder ( folderList [ dirIdx ]. filePath ());
QString testFolderName = testCaseFolder . dirName ();
QString reportBaseFolderName = testCaseFolder . filePath ( baseFolderName );
QString reportGeneratedFolderName = testCaseFolder . filePath ( generatedFolderName );
QString reportDiffFolderName = testCaseFolder . filePath ( diffFolderName );
imageCompareReporter . addImageDirectoryComparisonSet ( testFolderName . toStdString (), reportBaseFolderName . toStdString (), reportGeneratedFolderName . toStdString (), reportDiffFolderName . toStdString ());
}
QString htmlReportFileName = testDir . filePath ( RegTestNames :: reportFileName );
imageCompareReporter . generateHTMLReport ( htmlReportFileName . toStdString ());
// Open HTML report
QDesktopServices :: openUrl ( htmlReportFileName );
2014-01-23 13:17:49 +01:00
// Keep current preferences values to be able to restore when regression tests are completed
std :: vector < QVariant > preferencesValues ;
{
std :: vector < caf :: PdmFieldHandle *> fields ;
this -> preferences () -> fields ( fields );
for ( size_t i = 0 ; i < fields . size (); i ++ )
{
2015-08-05 13:27:36 +02:00
QVariant v = fields [ i ] -> uiCapability () -> uiValue ();
2014-01-23 13:17:49 +01:00
preferencesValues . push_back ( v );
}
}
// Set preferences to make sure regression tests behave identical
this -> preferences () -> configureForRegressionTests ();
2013-10-08 14:28:01 +02:00
for ( int dirIdx = 0 ; dirIdx < folderList . size (); ++ dirIdx )
{
QDir testCaseFolder ( folderList [ dirIdx ]. filePath ());
if ( testCaseFolder . exists ( regTestProjectName ))
{
loadProject ( testCaseFolder . filePath ( regTestProjectName ));
// Wait until all command objects have completed
while ( ! m_commandQueueLock . tryLock ())
{
processEvents ();
}
m_commandQueueLock . unlock ();
2014-01-23 13:17:49 +01:00
regressionTestConfigureProject ();
2013-10-08 14:28:01 +02:00
2013-12-04 12:04:42 +01:00
QString fullPathGeneratedFolder = testCaseFolder . absoluteFilePath ( generatedFolderName );
saveSnapshotForAllViews ( fullPathGeneratedFolder );
2013-10-08 14:28:01 +02:00
QDir baseDir ( testCaseFolder . filePath ( baseFolderName ));
QDir genDir ( testCaseFolder . filePath ( generatedFolderName ));
QDir diffDir ( testCaseFolder . filePath ( diffFolderName ));
if ( ! diffDir . exists ()) testCaseFolder . mkdir ( diffFolderName );
baseDir . setFilter ( QDir :: Files );
QStringList baseImageFileNames = baseDir . entryList ();
for ( int fIdx = 0 ; fIdx < baseImageFileNames . size (); ++ fIdx )
{
QString fileName = baseImageFileNames [ fIdx ];
RiaImageFileCompare imgComparator ( RegTestNames :: imageCompareExeName );
bool ok = imgComparator . runComparison ( genDir . filePath ( fileName ), baseDir . filePath ( fileName ), diffDir . filePath ( fileName ));
if ( ! ok )
{
qDebug () << "Error comparing :" << imgComparator . errorMessage () << " \n " << imgComparator . errorDetails ();
}
}
closeProject ( false );
}
2014-01-23 13:17:49 +01:00
// Restore preferences
{
std :: vector < caf :: PdmFieldHandle *> fields ;
this -> preferences () -> fields ( fields );
CVF_ASSERT ( fields . size () == preferencesValues . size ());
for ( size_t i = 0 ; i < preferencesValues . size (); i ++ )
{
2015-08-05 13:27:36 +02:00
fields [ i ] -> uiCapability () -> setValueFromUi ( preferencesValues [ i ]);
2014-01-23 13:17:49 +01:00
}
}
2013-10-08 14:28:01 +02:00
}
2015-06-26 13:44:16 +02:00
m_runningRegressionTests = false ;
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: updateRegressionTest ( const QString & testRootPath )
{
// Find all sub folders
QDir testDir ( testRootPath ); // If string is empty it will end up as cwd
testDir . setFilter ( QDir :: Dirs );
QStringList dirNameFilter ;
dirNameFilter . append ( RegTestNames :: testFolderFilter );
testDir . setNameFilters ( dirNameFilter );
QFileInfoList folderList = testDir . entryInfoList ();
for ( int i = 0 ; i < folderList . size (); ++ i )
{
QDir testCaseFolder ( folderList [ i ]. filePath ());
QDir baseDir ( testCaseFolder . filePath ( RegTestNames :: baseFolderName ));
removeDirectoryWithContent ( baseDir );
testCaseFolder . mkdir ( RegTestNames :: baseFolderName );
QDir genDir ( testCaseFolder . filePath ( RegTestNames :: generatedFolderName ));
QStringList imageFileNames = genDir . entryList ();
for ( int fIdx = 0 ; fIdx < imageFileNames . size (); ++ fIdx )
{
QString fileName = imageFileNames [ fIdx ];
QFile :: copy ( genDir . filePath ( fileName ), baseDir . filePath ( fileName ));
}
}
}
//--------------------------------------------------------------------------------------------------
/// Make sure changes in this functions is validated to RimIdenticalGridCaseGroup::initAfterRead()
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: addEclipseCases ( const QStringList & fileNames )
{
if ( fileNames . size () == 0 ) return true ;
// First file is read completely including grid.
// The main grid from the first case is reused directly in for the other cases.
// When reading active cell info, only the total cell count is tested for consistency
2015-06-25 11:56:18 +02:00
RimEclipseResultCase * mainResultCase = NULL ;
2013-10-08 14:28:01 +02:00
std :: vector < std :: vector < int > > mainCaseGridDimensions ;
RimIdenticalGridCaseGroup * gridCaseGroup = NULL ;
{
QString firstFileName = fileNames [ 0 ];
QFileInfo gridFileName ( firstFileName );
QString caseName = gridFileName . completeBaseName ();
2015-06-25 11:56:18 +02:00
RimEclipseResultCase * rimResultReservoir = new RimEclipseResultCase ();
2013-10-08 14:28:01 +02:00
rimResultReservoir -> setCaseInfo ( caseName , firstFileName );
if ( ! rimResultReservoir -> openEclipseGridFile ())
{
delete rimResultReservoir ;
return false ;
}
rimResultReservoir -> readGridDimensions ( mainCaseGridDimensions );
mainResultCase = rimResultReservoir ;
RimOilField * oilField = m_project -> activeOilField ();
if ( oilField && oilField -> analysisModels ())
{
gridCaseGroup = oilField -> analysisModels -> createIdenticalCaseGroupFromMainCase ( mainResultCase );
}
}
caf :: ProgressInfo info ( fileNames . size (), "Reading Active Cell data" );
for ( int i = 1 ; i < fileNames . size (); i ++ )
{
QString caseFileName = fileNames [ i ];
QFileInfo gridFileName ( caseFileName );
QString caseName = gridFileName . completeBaseName ();
2015-06-25 11:56:18 +02:00
RimEclipseResultCase * rimResultReservoir = new RimEclipseResultCase ();
2013-10-08 14:28:01 +02:00
rimResultReservoir -> setCaseInfo ( caseName , caseFileName );
std :: vector < std :: vector < int > > caseGridDimensions ;
rimResultReservoir -> readGridDimensions ( caseGridDimensions );
bool identicalGrid = RigGridManager :: isGridDimensionsEqual ( mainCaseGridDimensions , caseGridDimensions );
if ( identicalGrid )
{
if ( rimResultReservoir -> openAndReadActiveCellData ( mainResultCase -> reservoirData ()))
{
RimOilField * oilField = m_project -> activeOilField ();
if ( oilField && oilField -> analysisModels ())
{
oilField -> analysisModels () -> insertCaseInCaseGroup ( gridCaseGroup , rimResultReservoir );
}
}
else
{
delete rimResultReservoir ;
}
}
else
{
delete rimResultReservoir ;
}
info . setProgress ( i );
}
2014-10-28 18:33:23 +01:00
if ( gridCaseGroup )
{
// Create placeholder results and propagate results info from main case to all other cases
gridCaseGroup -> loadMainCaseAndActiveCellInfo ();
}
2015-08-13 21:28:09 +02:00
m_project -> activeOilField () -> analysisModels () -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
if ( gridCaseGroup -> statisticsCaseCollection () -> reservoirs . size () > 0 )
{
RiuMainWindow :: instance () -> setCurrentObjectInTreeView ( gridCaseGroup -> statisticsCaseCollection () -> reservoirs [ 0 ]);
}
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf :: Font * RiaApplication :: standardFont ()
{
CVF_ASSERT ( m_standardFont . notNull ());
// The creation of a font is time consuming, so make sure you really need your own font
// instead of using the application font
return m_standardFont . p ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QImage RiaApplication :: grabFrameBufferImage ()
{
QImage image ;
if ( m_activeReservoirView && m_activeReservoirView -> viewer ())
{
m_activeReservoirView -> viewer () -> repaint ();
GLint currentReadBuffer ;
glGetIntegerv ( GL_READ_BUFFER , & currentReadBuffer );
glReadBuffer ( GL_FRONT );
image = m_activeReservoirView -> viewer () -> grabFrameBuffer ();
glReadBuffer ( currentReadBuffer );
}
return image ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimProject * RiaApplication :: project ()
{
return m_project ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: showFormattedTextInMessageBox ( const QString & text )
{
QString helpText = text ;
QMessageBox msgBox ;
msgBox . setIcon ( QMessageBox :: Information );
msgBox . setWindowTitle ( "ResInsight" );
helpText . replace ( "&" , "&" );
helpText . replace ( "<" , "<" );
helpText . replace ( ">" , ">" );
helpText = QString ( "<pre>%1</pre>" ). arg ( helpText );
msgBox . setText ( helpText );
msgBox . exec ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: commandLineParameterHelp () const
{
2013-12-19 10:45:15 +01:00
return m_helpText ;
/*
2013-10-08 14:28:01 +02:00
QString text = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(getVersionStringApp(false));
text += "Copyright Statoil ASA, Ceetron AS 2011, 2012\n\n";
text +=
"\nParameter Description\n"
"-----------------------------------------------------------------\n"
"-last Open last used project\n"
"\n"
"-project <filename> Open project file <filename>\n"
"\n"
2013-10-18 16:23:31 +02:00
"-case <casename> Import Eclipse case <casename>\n"
2013-10-08 14:28:01 +02:00
" (do not include .GRID/.EGRID)\n"
"\n"
"-savesnapshots Save snapshot of all views to 'snapshots' folder in project file folder\n"
" Application closes after snapshots are written to file\n"
"\n"
"-regressiontest <folder> Run a regression test on all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n"
" " + RegTestNames::testProjectName + " files in the sub-folders will be opened and \n"
" snapshots of all the views is written to the sub-sub-folder " + RegTestNames::generatedFolderName + ". \n"
" Then difference images is generated in the sub-sub-folder " + RegTestNames::diffFolderName + " based \n"
" on the images in sub-sub-folder " + RegTestNames::baseFolderName + ".\n"
" The results are presented in " + RegTestNames::reportFileName + " that is\n"
" written in the given folder.\n"
"\n"
"-updateregressiontestbase <folder> For all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n"
" Copy the images in the sub-sub-folder " + RegTestNames::generatedFolderName + " to the sub-sub-folder\n"
" " + RegTestNames::baseFolderName + " after deleting " + RegTestNames::baseFolderName + " completely.\n"
"\n"
"-help, -? Displays help text\n"
"-----------------------------------------------------------------";
return text;
2013-12-19 10:45:15 +01:00
*/
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
/// Schedule a creation of the Display model and redraw of the reservoir view
/// The redraw will happen as soon as the event loop is entered
//--------------------------------------------------------------------------------------------------
2015-04-30 10:34:15 +02:00
void RiaApplication :: scheduleDisplayModelUpdateAndRedraw ( RimView * resViewToUpdate )
2013-10-08 14:28:01 +02:00
{
m_resViewsToUpdate . push_back ( resViewToUpdate );
if ( ! m_resViewUpdateTimer )
{
m_resViewUpdateTimer = new QTimer ( this );
connect ( m_resViewUpdateTimer , SIGNAL ( timeout ()), this , SLOT ( slotUpdateScheduledDisplayModels ()));
}
if ( ! m_resViewUpdateTimer -> isActive ())
{
m_resViewUpdateTimer -> setSingleShot ( true );
m_resViewUpdateTimer -> start ( 0 );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: slotUpdateScheduledDisplayModels ()
{
// Compress to remove duplicates
2015-04-30 10:34:15 +02:00
std :: set < RimView *> resViewsToUpdate ;
2013-10-08 14:28:01 +02:00
for ( size_t i = 0 ; i < m_resViewsToUpdate . size (); ++ i )
{
resViewsToUpdate . insert ( m_resViewsToUpdate [ i ]);
}
2015-04-30 10:34:15 +02:00
for ( std :: set < RimView *>:: iterator it = resViewsToUpdate . begin (); it != resViewsToUpdate . end (); ++ it )
2013-10-08 14:28:01 +02:00
{
if ( * it )
{
( * it ) -> createDisplayModelAndRedraw ();
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setCacheDataObject ( const QString & key , const QVariant & dataObject )
{
m_sessionCache [ key ] = dataObject ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QVariant RiaApplication :: cacheDataObject ( const QString & key ) const
{
QMap < QString , QVariant >:: const_iterator it = m_sessionCache . find ( key );
if ( it != m_sessionCache . end ())
{
return it . value ();
}
return QVariant ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addCommandObject ( RimCommandObject * commandObject )
{
m_commandQueue . push_back ( commandObject );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: executeCommandObjects ()
{
std :: list < RimCommandObject * >:: iterator it = m_commandQueue . begin ();
while ( it != m_commandQueue . end ())
{
RimCommandObject * toBeRemoved = * it ;
if ( ! toBeRemoved -> isAsyncronous ())
{
toBeRemoved -> redo ();
it ++ ;
m_commandQueue . remove ( toBeRemoved );
}
else
{
it ++ ;
}
}
if ( m_commandQueue . size () > 0 )
{
std :: list < RimCommandObject * >:: iterator it = m_commandQueue . begin ();
RimCommandObject * first = * it ;
first -> redo ();
m_commandQueue . pop_front ();
}
else
{
// Unlock the command queue lock when the command queue is empty
m_commandQueueLock . unlock ();
}
}
2015-06-26 13:44:16 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: isRunningRegressionTests () const
{
return m_runningRegressionTests ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: executeRegressionTests ( const QString & regressionTestPath )
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( mainWnd )
{
mainWnd -> hideAllDockWindows ();
mainWnd -> setDefaultWindowSize ();
runRegressionTest ( regressionTestPath );
mainWnd -> loadWinGeoAndDockToolBarLayout ();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2014-01-23 13:17:49 +01:00
void RiaApplication :: regressionTestConfigureProject ()
2013-10-08 14:28:01 +02:00
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
if ( m_project . isNull ()) return ;
2015-05-15 18:51:49 +02:00
std :: vector < RimCase *> projectCases ;
2013-10-08 14:28:01 +02:00
m_project -> allCases ( projectCases );
2015-05-15 18:51:49 +02:00
2013-10-08 14:28:01 +02:00
for ( size_t i = 0 ; i < projectCases . size (); i ++ )
{
2015-05-15 18:51:49 +02:00
RimCase * cas = projectCases [ i ];
if ( ! cas ) continue ;
std :: vector < RimView *> views = cas -> views ();
2013-10-08 14:28:01 +02:00
2015-05-15 18:51:49 +02:00
for ( size_t j = 0 ; j < views . size (); j ++ )
2013-10-08 14:28:01 +02:00
{
2015-05-15 18:51:49 +02:00
RimView * riv = views [ j ];
2013-10-08 14:28:01 +02:00
if ( riv && riv -> viewer ())
{
// This size is set to match the regression test reference images
riv -> viewer () -> setFixedSize ( 1000 , 745 );
}
2014-01-23 13:17:49 +01:00
2015-05-21 10:05:33 +02:00
RimEclipseView * resvView = dynamic_cast < RimEclipseView *> ( riv );
2015-05-15 18:51:49 +02:00
if ( resvView )
{
resvView -> faultCollection -> setShowFaultsOutsideFilters ( false );
2015-07-31 18:58:23 +02:00
2015-08-05 12:34:07 +02:00
caf :: PdmUiFieldHandle * uiFieldHandle = resvView -> faultResultSettings -> showCustomFaultResult . uiCapability ();
2015-07-31 18:58:23 +02:00
if ( uiFieldHandle )
{
uiFieldHandle -> setValueFromUi ( false );
}
2015-05-15 18:51:49 +02:00
}
2013-10-08 14:28:01 +02:00
}
}
}