2013-10-08 07:28:01 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 08:04:57 -05:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2013-10-08 07:28:01 -05: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 "RiaApplication.h"
# include "RiaBaseDefs.h"
# include "RiaImageCompareReporter.h"
# include "RiaImageFileCompare.h"
2017-08-24 23:51:56 -05:00
# include "RiaImportEclipseCaseTools.h"
2017-02-23 07:24:18 -06:00
# include "RiaLogging.h"
2015-09-25 08:57:43 -05:00
# include "RiaPreferences.h"
2013-12-04 05:04:42 -06:00
# include "RiaProjectModifier.h"
2015-09-25 08:57:43 -05:00
# include "RiaSocketServer.h"
# include "RiaVersionInfo.h"
2017-08-29 02:38:41 -05:00
# include "RiaArgumentParser.h"
2013-10-08 07:28:01 -05:00
2015-09-25 08:57:43 -05:00
# include "RigGridManager.h"
2017-02-22 02:31:10 -06:00
# include "RigEclipseCaseData.h"
2013-10-08 07:28:01 -05:00
2017-10-03 08:31:45 -05:00
2015-09-25 08:57:43 -05:00
# include "Rim3dOverlayInfoConfig.h"
2013-10-08 07:28:01 -05:00
# include "RimCaseCollection.h"
2015-06-25 06:45:32 -05:00
# include "RimCellEdgeColors.h"
2013-10-08 07:28:01 -05:00
# include "RimCellRangeFilterCollection.h"
2015-09-25 08:57:43 -05:00
# include "RimCommandObject.h"
2017-10-03 08:31:45 -05:00
# include "RimEclipseCase.h"
2015-09-25 08:57:43 -05:00
# include "RimEclipseCaseCollection.h"
# include "RimEclipseView.h"
2017-10-15 14:20:03 -05:00
# include "RimFaultInViewCollection.h"
2017-03-28 16:30:01 -05:00
# include "RimFlowCharacteristicsPlot.h"
2017-02-17 02:29:46 -06:00
# include "RimFlowPlotCollection.h"
2016-10-06 03:33:57 -05:00
# include "RimFormationNamesCollection.h"
2017-10-03 01:19:38 -05:00
# include "RimRftPlotCollection.h"
# include "RimEclipseCase.h"
2015-04-20 02:02:33 -05:00
# include "RimGeoMechCase.h"
2015-09-25 08:57:43 -05:00
# include "RimGeoMechCellColors.h"
2015-04-20 02:02:33 -05:00
# include "RimGeoMechModels.h"
# include "RimGeoMechView.h"
2015-09-25 08:57:43 -05:00
# include "RimIdenticalGridCaseGroup.h"
2015-09-03 01:09:06 -05:00
# include "RimMainPlotCollection.h"
2017-10-03 08:31:45 -05:00
# include "RimObservedData.h"
2017-09-14 08:44:01 -05:00
# include "RimObservedDataCollection.h"
2015-09-25 08:57:43 -05:00
# include "RimOilField.h"
# include "RimProject.h"
# include "RimReservoirCellResultsStorage.h"
# include "RimScriptCollection.h"
2016-06-24 08:10:18 -05:00
# include "RimSummaryCase.h"
2017-09-06 09:32:46 -05:00
# include "RimSummaryCaseMainCollection.h"
2016-11-07 08:57:21 -06:00
# include "RimSummaryCurve.h"
2016-06-24 08:10:18 -05:00
# include "RimSummaryPlot.h"
# include "RimSummaryPlotCollection.h"
2015-10-23 07:13:14 -05:00
# include "RimViewLinker.h"
# include "RimViewLinkerCollection.h"
2017-01-13 06:32:02 -06:00
# include "RimWellAllocationPlot.h"
2015-09-03 01:09:06 -05:00
# include "RimWellLogPlot.h"
2015-09-25 08:57:43 -05:00
# include "RimWellLogPlotCollection.h"
# include "RimWellPath.h"
# include "RimWellPathCollection.h"
2017-10-03 01:19:38 -05:00
# include "RimRftPlotCollection.h"
# include "RimWellRftPlot.h"
2015-09-25 08:57:43 -05:00
2016-06-24 08:10:18 -05:00
# include "RiuMainPlotWindow.h"
2015-09-25 08:57:43 -05:00
# include "RiuMainWindow.h"
# include "RiuProcessMonitor.h"
2016-10-05 01:23:07 -05:00
# include "RiuRecentFileActionProvider.h"
2015-11-09 12:05:00 -06:00
# include "RiuSelectionManager.h"
2016-09-01 06:01:17 -05:00
# include "RiuSummaryQwtPlot.h"
2015-09-25 08:57:43 -05:00
# include "RiuViewer.h"
2016-09-01 06:01:17 -05:00
# include "RiuWellLogPlot.h"
2017-02-13 08:47:24 -06:00
# include "RiuWellAllocationPlot.h"
2017-03-28 16:30:01 -05:00
# include "RiuFlowCharacteristicsPlot.h"
2015-09-25 08:57:43 -05:00
2017-08-22 04:38:31 -05:00
# ifdef USE_PROTOTYPE_FEATURE_FRACTURES
# include "RimFractureTemplateCollection.h"
# include "RimWellPathFracture.h"
# endif // USE_PROTOTYPE_FEATURE_FRACTURES
2017-08-24 23:51:56 -05:00
# include "RicImportInputEclipseCaseFeature.h"
2016-10-06 03:33:57 -05:00
# include "RicImportSummaryCaseFeature.h"
2017-08-03 09:22:02 -05:00
# include "ExportCommands/RicSnapshotViewToFileFeature.h"
# include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
2017-08-04 04:25:17 -05:00
# include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
2016-06-30 06:21:04 -05:00
# include "SummaryPlotCommands/RicNewSummaryPlotFeature.h"
2017-07-26 09:41:17 -05:00
# include "RicfCommandFileExecutor.h"
2016-08-09 06:09:08 -05:00
# include "cafFixedAtlasFont.h"
2015-09-25 08:57:43 -05:00
# include "cafAppEnum.h"
# include "cafCeetronPlusNavigation.h"
# include "cafEffectCache.h"
# include "cafPdmFieldCvfColor.h"
# include "cafPdmFieldCvfMat4d.h"
# include "cafPdmSettings.h"
2017-04-20 01:07:47 -05:00
# include "cafPdmUiModelChangeDetector.h"
2015-09-18 12:24:02 -05:00
# include "cafPdmUiTreeView.h"
2015-09-25 08:57:43 -05:00
# include "cafProgressInfo.h"
2017-10-03 07:50:06 -05:00
# include "cafQTreeViewStateSerializer.h"
2015-09-25 08:57:43 -05:00
# include "cafUiProcess.h"
# include "cafUtils.h"
2017-04-20 01:07:47 -05:00
2015-09-25 08:57:43 -05:00
# include "cvfProgramOptions.h"
# include "cvfqtUtils.h"
2016-10-05 01:23:07 -05:00
# include <QAction>
2015-09-25 08:57:43 -05:00
# include <QDesktopServices>
# include <QDir>
# include <QFileDialog>
2015-10-23 07:13:14 -05:00
# include <QMdiSubWindow>
2015-09-25 08:57:43 -05:00
# include <QMessageBox>
# include <QTimer>
# include <QUrl>
2017-04-20 04:02:05 -05:00
# include <QTreeView>
2015-09-25 08:57:43 -05:00
2015-10-05 09:09:51 -05:00
# include "gtest/gtest.h"
# ifdef WIN32
# include <fcntl.h>
# endif
2013-12-04 05:04:42 -06:00
2017-02-23 07:24:18 -06:00
2013-10-08 07:28:01 -05: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 05:31:35 -05:00
addItem ( RiaApplication : : NAVIGATION_POLICY_GEOQUEST , " NAVIGATION_POLICY_GEOQUEST " , " GEOQUEST " ) ;
addItem ( RiaApplication : : NAVIGATION_POLICY_RMS , " NAVIGATION_POLICY_RMS " , " RMS " ) ;
2015-07-02 06:33:07 -05:00
setDefault ( RiaApplication : : NAVIGATION_POLICY_RMS ) ;
2013-10-08 07:28:01 -05:00
}
}
namespace RegTestNames
{
const QString generatedFolderName = " RegTestGeneratedImages " ;
const QString diffFolderName = " RegTestDiffImages " ;
const QString baseFolderName = " RegTestBaseImages " ;
2017-04-20 14:21:12 -05:00
const QString testProjectName = " RegressionTest " ;
2013-10-08 07:28:01 -05:00
const QString testFolderFilter = " TestCase* " ;
const QString imageCompareExeName = " compare " ;
const QString reportFileName = " ResInsightRegressionTestReport.html " ;
} ;
2013-12-04 05:04:42 -06:00
2013-10-08 07:28:01 -05: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-10-23 08:46:25 -05:00
caf : : PdmSettings : : readFieldsFromApplicationStore ( m_preferences ) ;
2013-10-08 07:28:01 -05: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
2016-09-21 02:46:17 -05:00
setLastUsedDialogDirectory ( " MULTICASEIMPORT " , " / " ) ;
2013-10-08 07:28:01 -05:00
// The creation of a font is time consuming, so make sure you really need your own font
// instead of using the application font
2016-08-09 06:09:08 -05:00
m_standardFont = new caf : : FixedAtlasFont ( caf : : FixedAtlasFont : : POINT_SIZE_8 ) ;
2017-06-20 09:15:47 -05:00
m_resViewUpdateTimer = nullptr ;
m_recalculateCompletionTypeTimer = nullptr ;
2015-06-26 06:44:16 -05:00
m_runningRegressionTests = false ;
2016-06-27 04:07:01 -05:00
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2017-06-20 09:15:47 -05:00
m_mainPlotWindow = nullptr ;
2016-10-05 01:23:07 -05:00
m_recentFileActionProvider = std : : unique_ptr < RiuRecentFileActionProvider > ( new RiuRecentFileActionProvider ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication : : ~ RiaApplication ( )
{
2016-06-27 08:27:18 -05:00
deleteMainPlotWindow ( ) ;
2013-10-08 07:28:01 -05:00
delete m_preferences ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication * RiaApplication : : instance ( )
{
return static_cast < RiaApplication * > qApp ;
}
2015-12-03 03:33:38 -06:00
//--------------------------------------------------------------------------------------------------
/// Return -1 if unit test is not executed, returns 0 if test passed, returns 1 if tests failed
//--------------------------------------------------------------------------------------------------
int RiaApplication : : parseArgumentsAndRunUnitTestsIfRequested ( )
{
cvf : : ProgramOptions progOpt ;
progOpt . registerOption ( " unittest " , " " , " Execute unit tests " ) ;
progOpt . setOptionPrefix ( cvf : : ProgramOptions : : DOUBLE_DASH ) ;
QStringList arguments = QCoreApplication : : arguments ( ) ;
bool parseOk = progOpt . parse ( cvfqt : : Utils : : toStringVector ( arguments ) ) ;
if ( ! parseOk )
{
return - 1 ;
}
// Unit testing
// --------------------------------------------------------
if ( cvf : : Option o = progOpt . option ( " unittest " ) )
{
int testReturnValue = launchUnitTestsWithConsole ( ) ;
return testReturnValue ;
}
return - 1 ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 05:04:42 -06:00
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-12-04 05:04:42 -06:00
bool RiaApplication : : loadProject ( const QString & projectFileName , ProjectLoadAction loadAction , RiaProjectModifier * projectModifier )
2013-10-08 07:28:01 -05:00
{
// First Close the current project
2016-10-04 04:02:56 -05:00
closeProject ( ) ;
2013-10-08 07:28:01 -05:00
2017-02-27 06:17:32 -06:00
RiaLogging : : info ( QString ( " Starting to open project file : '%1' " ) . arg ( projectFileName ) ) ;
2017-02-23 07:24:18 -06:00
2013-10-08 07:28:01 -05:00
// Open the project file and read the serialized data.
// Will initialize itself.
2017-05-11 02:23:13 -05:00
if ( ! caf : : Utils : : fileExists ( projectFileName ) )
2017-02-23 07:24:18 -06:00
{
2017-02-27 06:17:32 -06:00
RiaLogging : : info ( QString ( " File does not exist : '%1' " ) . arg ( projectFileName ) ) ;
2017-02-23 07:24:18 -06:00
return false ;
}
2013-10-08 07:28:01 -05:00
m_project - > fileName = projectFileName ;
m_project - > readFile ( ) ;
2016-10-04 07:23:34 -05:00
// Apply any modifications to the loaded project before we go ahead and load actual data
2013-12-04 05:04:42 -06:00
if ( projectModifier )
{
projectModifier - > applyModificationsToProject ( m_project ) ;
}
2013-10-08 07:28:01 -05:00
// Propagate possible new location of project
m_project - > setProjectFileNameAndUpdateDependencies ( projectFileName ) ;
// On error, delete everything, and bail out.
if ( m_project - > projectFileVersionString ( ) . isEmpty ( ) )
{
2016-10-04 04:02:56 -05:00
closeProject ( ) ;
2013-10-08 07:28:01 -05:00
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 ;
}
2016-10-04 07:23:34 -05:00
if ( m_project - > show3DWindow ( ) )
{
RiuMainWindow : : instance ( ) - > show ( ) ;
}
else
{
2016-10-06 08:01:27 -05:00
RiuMainWindow : : instance ( ) - > hide ( ) ;
2016-10-04 07:23:34 -05:00
}
if ( m_project - > showPlotWindow ( ) )
{
2016-11-10 02:26:53 -06:00
if ( ! m_mainPlotWindow )
{
createMainPlotWindow ( ) ;
}
else
{
m_mainPlotWindow - > show ( ) ;
m_mainPlotWindow - > raise ( ) ;
}
2016-10-04 07:23:34 -05:00
}
else if ( mainPlotWindow ( ) )
{
2016-10-06 08:01:27 -05:00
mainPlotWindow ( ) - > hide ( ) ;
2016-10-04 07:23:34 -05:00
}
2013-10-08 07:28:01 -05:00
///////
// 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 04:47:06 -05:00
caf : : PdmSettings : : writeFieldsToApplicationStore ( m_preferences ) ;
2013-10-08 07:28:01 -05:00
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project - > oilFields ( ) . size ( ) ; oilFieldIdx + + )
{
RimOilField * oilField = m_project - > oilFields [ oilFieldIdx ] ;
2015-06-25 05:11:06 -05:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField - > analysisModels ( ) : NULL ;
2013-10-08 07:28:01 -05: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?
}
}
2016-08-24 01:30:12 -05:00
// Load the formation names
for ( RimOilField * oilField : m_project - > oilFields )
{
if ( oilField = = NULL ) continue ;
if ( oilField - > formationNamesCollection ( ) ! = NULL )
{
oilField - > formationNamesCollection ( ) - > readAllFormationNames ( ) ;
}
}
2013-10-08 07:28:01 -05:00
// 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 ( ) ;
}
if ( oilField - > wellPathCollection ) oilField - > wellPathCollection - > readWellPathFiles ( ) ;
}
2016-05-31 06:42:27 -05:00
for ( RimOilField * oilField : m_project - > oilFields )
{
if ( oilField = = NULL ) continue ;
// Temporary
2017-09-06 09:32:46 -05:00
if ( ! oilField - > summaryCaseMainCollection ( ) )
2016-05-31 06:42:27 -05:00
{
2017-09-06 09:32:46 -05:00
oilField - > summaryCaseMainCollection = new RimSummaryCaseMainCollection ( ) ;
2016-05-31 06:42:27 -05:00
}
2017-09-06 09:32:46 -05:00
oilField - > summaryCaseMainCollection ( ) - > createSummaryCasesFromRelevantEclipseResultCases ( ) ;
oilField - > summaryCaseMainCollection ( ) - > loadAllSummaryCaseData ( ) ;
2017-02-17 02:29:46 -06:00
2017-09-14 08:44:01 -05:00
if ( ! oilField - > observedDataCollection ( ) )
{
oilField - > observedDataCollection = new RimObservedDataCollection ( ) ;
}
2017-09-22 07:26:54 -05:00
for ( auto observedCases : oilField - > observedDataCollection ( ) - > allObservedData ( ) )
{
observedCases - > createSummaryReaderInterface ( ) ;
2017-10-03 08:31:45 -05:00
RimObservedData * rimObservedData = dynamic_cast < RimObservedData * > ( observedCases ) ;
if ( rimObservedData )
{
rimObservedData - > updateMetaData ( ) ;
}
2017-09-22 07:26:54 -05:00
}
2017-09-14 08:44:01 -05:00
2017-08-21 08:24:20 -05:00
# ifdef USE_PROTOTYPE_FEATURE_FRACTURES
2017-02-17 02:29:46 -06:00
oilField - > fractureDefinitionCollection ( ) - > loadAndUpdateData ( ) ;
2017-08-14 15:16:03 -05:00
{
std : : vector < RimWellPathFracture * > wellPathFractures ;
oilField - > wellPathCollection - > descendantsIncludingThisOfType ( wellPathFractures ) ;
for ( auto fracture : wellPathFractures )
{
fracture - > loadDataAndUpdate ( ) ;
}
}
2017-08-21 08:24:20 -05:00
# endif // USE_PROTOTYPE_FEATURE_FRACTURES
2017-08-14 15:16:03 -05:00
2016-05-31 06:42:27 -05:00
}
2013-12-04 05:04:42 -06: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 05:11:06 -05:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField - > analysisModels ( ) : NULL ;
2013-12-04 05:04:42 -06:00
if ( analysisModels )
{
analysisModels - > recomputeStatisticsForAllCaseGroups ( ) ;
}
}
}
2013-10-08 07:28:01 -05:00
// Now load the ReservoirViews for the cases
// Add all "native" cases in the project
2015-05-15 11:51:49 -05:00
std : : vector < RimCase * > casesToLoad ;
2013-10-08 07:28:01 -05:00
m_project - > allCases ( casesToLoad ) ;
{
2015-09-28 01:21:51 -05:00
caf : : ProgressInfo caseProgress ( casesToLoad . size ( ) , " Reading Cases " ) ;
2013-10-08 07:28:01 -05:00
2015-09-28 01:21:51 -05:00
for ( size_t cIdx = 0 ; cIdx < casesToLoad . size ( ) ; + + cIdx )
2013-10-08 07:28:01 -05:00
{
2015-09-28 01:21:51 -05:00
RimCase * cas = casesToLoad [ cIdx ] ;
CVF_ASSERT ( cas ) ;
2013-10-08 07:28:01 -05:00
2015-09-28 01:21:51 -05:00
caseProgress . setProgressDescription ( cas - > caseUserDescription ( ) ) ;
std : : vector < RimView * > views = cas - > views ( ) ;
caf : : ProgressInfo viewProgress ( views . size ( ) , " Creating Views " ) ;
2013-10-08 07:28:01 -05:00
2015-09-28 01:21:51 -05:00
size_t j ;
for ( j = 0 ; j < views . size ( ) ; j + + )
{
RimView * riv = views [ j ] ;
CVF_ASSERT ( riv ) ;
2013-10-08 07:28:01 -05:00
2015-09-28 01:21:51 -05:00
viewProgress . setProgressDescription ( riv - > name ( ) ) ;
riv - > loadDataAndUpdate ( ) ;
this - > setActiveReservoirView ( riv ) ;
2015-10-28 06:23:24 -05:00
riv - > rangeFilterCollection ( ) - > updateIconState ( ) ;
2015-09-28 01:21:51 -05:00
viewProgress . incrementProgress ( ) ;
}
caseProgress . incrementProgress ( ) ;
}
2013-10-08 07:28:01 -05:00
}
2015-10-22 09:02:28 -05:00
2015-10-22 09:46:58 -05:00
if ( m_project - > viewLinkerCollection ( ) & & m_project - > viewLinkerCollection ( ) - > viewLinker ( ) )
2015-10-22 09:02:28 -05:00
{
m_project - > viewLinkerCollection ( ) - > viewLinker ( ) - > updateOverrides ( ) ;
}
2016-10-05 03:04:41 -05:00
loadAndUpdatePlotData ( ) ;
2013-10-08 07:28:01 -05: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 ( ) ;
2017-02-27 06:17:32 -06:00
RiaLogging : : info ( QString ( " Completed open of project file : '%1' " ) . arg ( projectFileName ) ) ;
2017-02-23 07:24:18 -06:00
2013-10-08 07:28:01 -05:00
return true ;
}
2013-12-04 05:04:42 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : loadProject ( const QString & projectFileName )
{
return loadProject ( projectFileName , PLA_NONE , NULL ) ;
}
2016-10-05 03:04:41 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : loadAndUpdatePlotData ( )
{
RimWellLogPlotCollection * wlpColl = nullptr ;
RimSummaryPlotCollection * spColl = nullptr ;
2017-01-13 06:32:02 -06:00
RimFlowPlotCollection * flowColl = nullptr ;
2017-10-03 01:19:38 -05:00
RimRftPlotCollection * rftColl = nullptr ;
2016-10-05 03:04:41 -05:00
if ( m_project - > mainPlotCollection ( ) & & m_project - > mainPlotCollection ( ) - > wellLogPlotCollection ( ) )
{
wlpColl = m_project - > mainPlotCollection ( ) - > wellLogPlotCollection ( ) ;
}
if ( m_project - > mainPlotCollection ( ) & & m_project - > mainPlotCollection ( ) - > summaryPlotCollection ( ) )
{
spColl = m_project - > mainPlotCollection ( ) - > summaryPlotCollection ( ) ;
}
2017-01-13 06:32:02 -06:00
if ( m_project - > mainPlotCollection ( ) & & m_project - > mainPlotCollection ( ) - > flowPlotCollection ( ) )
{
flowColl = m_project - > mainPlotCollection ( ) - > flowPlotCollection ( ) ;
}
2017-10-03 01:19:38 -05:00
if ( m_project - > mainPlotCollection ( ) & & m_project - > mainPlotCollection ( ) - > rftPlotCollection ( ) )
{
rftColl = m_project - > mainPlotCollection ( ) - > rftPlotCollection ( ) ;
}
2017-01-13 06:32:02 -06:00
2016-10-05 03:04:41 -05:00
size_t plotCount = 0 ;
plotCount + = wlpColl ? wlpColl - > wellLogPlots ( ) . size ( ) : 0 ;
2017-01-13 02:51:37 -06:00
plotCount + = spColl ? spColl - > summaryPlots ( ) . size ( ) : 0 ;
2017-02-13 07:49:52 -06:00
plotCount + = flowColl ? flowColl - > plotCount ( ) : 0 ;
2017-10-03 01:19:38 -05:00
plotCount + = rftColl ? rftColl - > rftPlots ( ) . size ( ) : 0 ;
2016-10-05 03:04:41 -05:00
caf : : ProgressInfo plotProgress ( plotCount , " Loading Plot Data " ) ;
if ( wlpColl )
{
for ( size_t wlpIdx = 0 ; wlpIdx < wlpColl - > wellLogPlots ( ) . size ( ) ; + + wlpIdx )
{
wlpColl - > wellLogPlots [ wlpIdx ] - > loadDataAndUpdate ( ) ;
plotProgress . incrementProgress ( ) ;
}
}
if ( spColl )
{
2017-01-13 02:51:37 -06:00
for ( size_t wlpIdx = 0 ; wlpIdx < spColl - > summaryPlots ( ) . size ( ) ; + + wlpIdx )
2016-10-05 03:04:41 -05:00
{
2017-01-13 02:51:37 -06:00
spColl - > summaryPlots [ wlpIdx ] - > loadDataAndUpdate ( ) ;
2016-10-05 03:04:41 -05:00
plotProgress . incrementProgress ( ) ;
}
}
2017-02-13 07:49:52 -06:00
2017-01-13 06:32:02 -06:00
if ( flowColl )
{
2017-02-24 09:00:56 -06:00
plotProgress . setNextProgressIncrement ( flowColl - > plotCount ( ) ) ;
2017-03-07 05:19:54 -06:00
flowColl - > loadDataAndUpdate ( ) ;
plotProgress . incrementProgress ( ) ;
2017-01-13 06:32:02 -06:00
}
2017-10-03 01:19:38 -05:00
if ( rftColl )
{
for ( const auto & rftPlot : rftColl - > rftPlots ( ) )
{
rftPlot - > loadDataAndUpdate ( ) ;
plotProgress . incrementProgress ( ) ;
}
}
2016-10-05 03:04:41 -05:00
}
2013-12-04 05:04:42 -06:00
2017-04-20 04:02:05 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : storeTreeViewState ( )
{
{
if ( mainPlotWindow ( ) & & mainPlotWindow ( ) - > projectTreeView ( ) )
{
caf : : PdmUiTreeView * projectTreeView = mainPlotWindow ( ) - > projectTreeView ( ) ;
QString treeViewState ;
2017-09-06 06:06:37 -05:00
caf : : QTreeViewStateSerializer : : storeTreeViewStateToString ( projectTreeView - > treeView ( ) , treeViewState ) ;
2017-04-20 04:02:05 -05:00
QModelIndex mi = projectTreeView - > treeView ( ) - > currentIndex ( ) ;
QString encodedModelIndexString ;
2017-09-06 06:06:37 -05:00
caf : : QTreeViewStateSerializer : : encodeStringFromModelIndex ( mi , encodedModelIndexString ) ;
2017-04-20 04:02:05 -05:00
project ( ) - > plotWindowTreeViewState = treeViewState ;
project ( ) - > plotWindowCurrentModelIndexPath = encodedModelIndexString ;
}
}
{
caf : : PdmUiTreeView * projectTreeView = RiuMainWindow : : instance ( ) - > projectTreeView ( ) ;
if ( projectTreeView )
{
QString treeViewState ;
2017-09-06 06:06:37 -05:00
caf : : QTreeViewStateSerializer : : storeTreeViewStateToString ( projectTreeView - > treeView ( ) , treeViewState ) ;
2017-04-20 04:02:05 -05:00
QModelIndex mi = projectTreeView - > treeView ( ) - > currentIndex ( ) ;
QString encodedModelIndexString ;
2017-09-06 06:06:37 -05:00
caf : : QTreeViewStateSerializer : : encodeStringFromModelIndex ( mi , encodedModelIndexString ) ;
2017-04-20 04:02:05 -05:00
project ( ) - > mainWindowTreeViewState = treeViewState ;
project ( ) - > mainWindowCurrentModelIndexPath = encodedModelIndexString ;
}
}
}
2013-10-08 07:28:01 -05: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 ( ) ;
2015-08-12 10:46:22 -05:00
m_project - > updateConnectedEditors ( ) ;
2013-10-08 07:28:01 -05:00
}
if ( oilField - > wellPathCollection ) oilField - > wellPathCollection - > addWellPaths ( wellPathFilePaths ) ;
2015-08-12 10:46:22 -05:00
oilField - > wellPathCollection - > updateConnectedEditors ( ) ;
2013-10-08 07:28:01 -05:00
}
2015-09-14 09:33:28 -05: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 ( ) ;
m_project - > updateConnectedEditors ( ) ;
}
if ( oilField - > wellPathCollection ) oilField - > wellPathCollection - > addWellLogs ( wellLogFilePaths ) ;
oilField - > wellPathCollection - > updateConnectedEditors ( ) ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : saveProject ( )
{
CVF_ASSERT ( m_project . notNull ( ) ) ;
2017-05-11 02:23:13 -05:00
if ( ! caf : : Utils : : fileExists ( m_project - > fileName ( ) ) )
2013-10-08 07:28:01 -05:00
{
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 ( ) )
{
2015-09-18 11:48:29 -05:00
startPath = m_project - > fileName ( ) ;
2013-10-08 07:28:01 -05:00
}
else
{
2016-09-21 02:46:17 -05:00
startPath = app - > lastUsedDialogDirectory ( " BINARY_GRID " ) ;
2015-09-18 11:48:29 -05:00
startPath + = " /ResInsightProject.rsp " ;
2013-10-08 07:28:01 -05:00
}
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
2016-09-21 02:46:17 -05:00
app - > setLastUsedDialogDirectory ( " BINARY_GRID " , QFileInfo ( fileName ) . absolutePath ( ) ) ;
2013-10-08 07:28:01 -05:00
bool bSaveOk = saveProjectAs ( fileName ) ;
setWindowCaptionFromAppState ( ) ;
return bSaveOk ;
}
2017-04-20 01:07:47 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : hasValidProjectFileExtension ( const QString & fileName )
{
if ( fileName . contains ( " .rsp " , Qt : : CaseInsensitive ) | | fileName . contains ( " .rip " , Qt : : CaseInsensitive ) )
{
return true ;
}
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : askUserToSaveModifiedProject ( )
{
if ( caf : : PdmUiModelChangeDetector : : instance ( ) - > isModelChanged ( ) )
{
QMessageBox msgBox ;
msgBox . setIcon ( QMessageBox : : Question ) ;
QString questionText ;
questionText = QString ( " The current project is modified. \n \n Do you want to save the changes? " ) ;
msgBox . setText ( questionText ) ;
msgBox . setStandardButtons ( QMessageBox : : Yes | QMessageBox : : No | QMessageBox : : Cancel ) ;
int ret = msgBox . exec ( ) ;
if ( ret = = QMessageBox : : Cancel )
{
return false ;
}
else if ( ret = = QMessageBox : : Yes )
{
if ( ! saveProject ( ) )
{
return false ;
}
}
else
{
caf : : PdmUiModelChangeDetector : : instance ( ) - > reset ( ) ;
}
}
return true ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : saveProjectAs ( const QString & fileName )
{
m_project - > fileName = fileName ;
2015-11-20 03:50:23 -06:00
2017-04-20 04:02:05 -05:00
storeTreeViewState ( ) ;
2015-11-20 03:50:23 -06:00
if ( ! m_project - > writeFile ( ) )
{
QMessageBox : : warning ( NULL , " Error when saving project file " , QString ( " Not possible to save project file. Make sure you have sufficient access rights. \n \n Project file location : %1 " ) . arg ( fileName ) ) ;
return false ;
}
2013-10-08 07:28:01 -05:00
m_preferences - > lastUsedProjectFileName = fileName ;
2015-10-23 08:46:25 -05:00
caf : : PdmSettings : : writeFieldsToApplicationStore ( m_preferences ) ;
2013-10-08 07:28:01 -05:00
2016-10-05 01:23:07 -05:00
m_recentFileActionProvider - > addFileName ( fileName ) ;
2015-11-20 03:50:23 -06:00
2017-04-20 01:07:47 -05:00
caf : : PdmUiModelChangeDetector : : instance ( ) - > reset ( ) ;
2013-10-08 07:28:01 -05:00
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-10-04 04:02:56 -05:00
void RiaApplication : : closeProject ( )
2013-10-08 07:28:01 -05:00
{
RiuMainWindow * mainWnd = RiuMainWindow : : instance ( ) ;
2015-10-23 07:13:14 -05:00
clearViewsScheduledForUpdate ( ) ;
2013-10-08 07:28:01 -05:00
terminateProcess ( ) ;
2015-11-09 12:05:00 -06:00
RiuSelectionManager : : instance ( ) - > deleteAllItems ( ) ;
2013-10-08 07:28:01 -05:00
mainWnd - > cleanupGuiBeforeProjectClose ( ) ;
2016-06-27 04:07:01 -05:00
if ( m_mainPlotWindow )
{
m_mainPlotWindow - > cleanupGuiBeforeProjectClose ( ) ;
}
2016-06-24 08:10:18 -05:00
2013-10-08 07:28:01 -05:00
caf : : EffectGenerator : : clearEffectCache ( ) ;
m_project - > close ( ) ;
m_commandQueue . clear ( ) ;
onProjectOpenedOrClosed ( ) ;
2015-10-28 09:30:20 -05:00
// Make sure all project windows are closed down properly before returning
processEvents ( ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : onProjectOpenedOrClosed ( )
{
RiuMainWindow * mainWnd = RiuMainWindow : : instance ( ) ;
2016-06-24 08:53:04 -05:00
if ( mainWnd )
{
mainWnd - > initializeGuiNewProjectLoaded ( ) ;
}
2016-06-27 04:07:01 -05:00
if ( m_mainPlotWindow )
2016-06-24 08:53:04 -05:00
{
2016-06-27 04:07:01 -05:00
m_mainPlotWindow - > initializeGuiNewProjectLoaded ( ) ;
2016-06-24 08:53:04 -05:00
}
2013-10-08 07:28:01 -05:00
setWindowCaptionFromAppState ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 02:46:17 -05:00
QString RiaApplication : : currentProjectPath ( ) const
2013-10-08 07:28:01 -05:00
{
2016-09-21 02:46:17 -05:00
QString projectFolder ;
if ( m_project )
{
QString projectFileName = m_project - > fileName ( ) ;
2013-10-08 07:28:01 -05:00
2016-09-21 02:46:17 -05:00
if ( ! projectFileName . isEmpty ( ) )
{
QFileInfo fi ( projectFileName ) ;
projectFolder = fi . absolutePath ( ) ;
}
}
2013-10-08 07:28:01 -05:00
2016-09-21 02:46:17 -05:00
return projectFolder ;
}
2013-12-04 05:04:42 -06: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 ;
}
2017-02-14 07:59:08 -06:00
QString absolutePath ;
2013-12-04 05:04:42 -06:00
if ( m_project & & ! m_project - > fileName ( ) . isEmpty ( ) )
{
2017-02-14 07:59:08 -06:00
absolutePath = QFileInfo ( m_project - > fileName ( ) ) . absolutePath ( ) ;
2013-12-04 05:04:42 -06:00
}
else
{
2017-02-14 07:59:08 -06:00
absolutePath = this - > lastUsedDialogDirectory ( " BINARY_GRID " ) ;
2013-12-04 05:04:42 -06:00
}
2017-02-14 07:59:08 -06:00
QDir projectDir ( absolutePath ) ;
return projectDir . absoluteFilePath ( projectRelativePath ) ;
2013-12-04 05:04:42 -06:00
}
2015-04-20 02:02:33 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : openOdbCaseFromFile ( const QString & fileName )
{
2017-05-11 02:23:13 -05:00
if ( ! caf : : Utils : : fileExists ( fileName ) ) return false ;
2015-04-20 02:02:33 -05:00
QFileInfo gridFileName ( fileName ) ;
QString caseName = gridFileName . completeBaseName ( ) ;
RimGeoMechCase * geoMechCase = new RimGeoMechCase ( ) ;
2015-04-25 01:57:34 -05:00
geoMechCase - > setFileName ( fileName ) ;
2015-04-20 02:02:33 -05: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 05:14:40 -05:00
caf : : ProgressInfo progress ( 11 , " Loading Case " ) ;
progress . setNextProgressIncrement ( 10 ) ;
2015-04-20 02:02:33 -05:00
2015-04-20 09:56:26 -05:00
riv - > loadDataAndUpdate ( ) ;
2015-04-20 02:02:33 -05:00
//if (!riv->cellResult()->hasResult())
//{
2017-08-14 03:47:44 -05:00
// riv->cellResult()->setResultVariable(RiaDefines::undefinedResultName());
2015-04-20 02:02:33 -05:00
//}
2015-05-29 05:14:40 -05:00
progress . incrementProgress ( ) ;
progress . setProgressDescription ( " Loading results information " ) ;
2015-04-20 02:02:33 -05:00
2015-08-13 14:28:09 -05:00
m_project - > updateConnectedEditors ( ) ;
2015-04-20 02:02:33 -05:00
2015-12-07 03:07:51 -06:00
RiuMainWindow : : instance ( ) - > selectAsCurrentItem ( riv - > cellResult ( ) ) ;
2015-05-29 05:14:40 -05:00
2015-04-20 02:02:33 -05:00
return true ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createMockModel ( )
{
2017-08-24 23:51:56 -05:00
RiaImportEclipseCaseTools : : openMockModel ( RiaDefines : : mockModelBasic ( ) ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createResultsMockModel ( )
{
2017-08-24 23:51:56 -05:00
RiaImportEclipseCaseTools : : openMockModel ( RiaDefines : : mockModelBasicWithResults ( ) ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createLargeResultsMockModel ( )
{
2017-08-24 23:51:56 -05:00
RiaImportEclipseCaseTools : : openMockModel ( RiaDefines : : mockModelLargeWithResults ( ) ) ;
2013-10-08 07:28:01 -05:00
}
2013-10-28 04:32:24 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createMockModelCustomized ( )
{
2017-08-24 23:51:56 -05:00
RiaImportEclipseCaseTools : : openMockModel ( RiaDefines : : mockModelCustomized ( ) ) ;
2013-10-28 04:32:24 -05:00
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createInputMockModel ( )
{
2017-08-24 23:51:56 -05:00
RicImportInputEclipseCaseFeature : : openInputEclipseCaseFromFileNames ( QStringList ( RiaDefines : : mockModelBasicInputCase ( ) ) ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-05-08 07:13:26 -05:00
const RimView * RiaApplication : : activeReservoirView ( ) const
2013-10-08 07:28:01 -05:00
{
return m_activeReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-05-08 07:13:26 -05:00
RimView * RiaApplication : : activeReservoirView ( )
2013-10-08 07:28:01 -05:00
{
return m_activeReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-31 08:10:39 -05:00
RimViewWindow * RiaApplication : : activePlotWindow ( ) const
2016-06-28 03:58:22 -05:00
{
2017-03-31 08:10:39 -05:00
RimViewWindow * viewWindow = nullptr ;
2016-06-28 03:58:22 -05:00
2017-03-31 08:10:39 -05:00
if ( m_mainPlotWindow )
{
QList < QMdiSubWindow * > subwindows = m_mainPlotWindow - > subWindowList ( QMdiArea : : StackingOrder ) ;
if ( subwindows . size ( ) > 0 )
{
viewWindow = RiuInterfaceToViewWindow : : viewWindowFromWidget ( subwindows . back ( ) - > widget ( ) ) ;
}
}
2016-06-28 03:58:22 -05:00
2017-03-31 08:10:39 -05:00
return viewWindow ;
2017-01-13 06:32:02 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-31 08:10:39 -05:00
void RiaApplication : : setActiveReservoirView ( RimView * rv )
2017-01-13 06:32:02 -06:00
{
2017-03-31 08:10:39 -05:00
m_activeReservoirView = rv ;
2017-01-13 06:32:02 -06:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-10-08 07:28:01 -05:00
void RiaApplication : : setUseShaders ( bool enable )
{
m_preferences - > useShaders = enable ;
2015-10-23 08:46:25 -05:00
caf : : PdmSettings : : writeFieldsToApplicationStore ( m_preferences ) ;
2013-10-08 07:28:01 -05: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-10-23 08:46:25 -05:00
caf : : PdmSettings : : writeFieldsToApplicationStore ( m_preferences ) ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : showPerformanceInfo ( ) const
{
return m_preferences - > showHud ;
}
2013-12-04 05:04:42 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : parseArguments ( )
{
2017-08-29 02:38:41 -05:00
bool result = RiaArgumentParser : : parseArguments ( ) ;
if ( ! result )
2013-12-04 05:04:42 -06:00
{
2017-07-26 09:41:17 -05:00
closeAllWindows ( ) ;
processEvents ( ) ;
}
2017-08-29 02:38:41 -05:00
return result ;
2013-12-04 05:04:42 -06:00
}
2015-10-05 09:09:51 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-12-03 03:33:38 -06:00
int RiaApplication : : launchUnitTests ( )
2015-10-05 09:09:51 -05:00
{
2015-12-03 04:38:59 -06:00
# ifdef USE_UNIT_TESTS
2015-10-05 09:09:51 -05:00
cvf : : Assert : : setReportMode ( cvf : : Assert : : CONSOLE ) ;
int argc = QCoreApplication : : argc ( ) ;
testing : : InitGoogleTest ( & argc , QCoreApplication : : argv ( ) ) ;
2015-12-03 03:33:38 -06:00
// Use this macro in main() to run all tests. It returns 0 if all
// tests are successful, or 1 otherwise.
//
// RUN_ALL_TESTS() should be invoked after the command line has been
// parsed by InitGoogleTest().
return RUN_ALL_TESTS ( ) ;
2015-12-03 04:38:59 -06:00
# else
return - 1 ;
# endif
2015-10-05 09:09:51 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-12-03 03:33:38 -06:00
int RiaApplication : : launchUnitTestsWithConsole ( )
2015-10-05 09:09:51 -05:00
{
// Following code is taken from cvfAssert.cpp
# ifdef WIN32
{
// Allocate a new console for this app
// Only one console can be associated with an app, so should fail if a console is already present.
AllocConsole ( ) ;
2016-05-04 08:11:42 -05:00
FILE * consoleFilePointer ;
2015-10-05 09:09:51 -05:00
2016-05-04 08:11:42 -05:00
freopen_s ( & consoleFilePointer , " CONOUT$ " , " w " , stdout ) ;
freopen_s ( & consoleFilePointer , " CONOUT$ " , " w " , stderr ) ;
2015-10-05 09:09:51 -05:00
// Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well
std : : ios : : sync_with_stdio ( ) ;
}
# endif
2015-12-03 03:33:38 -06:00
return launchUnitTests ( ) ;
2015-10-05 09:09:51 -05:00
}
2013-12-04 05:04:42 -06:00
2016-06-27 04:07:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : createMainPlotWindow ( )
{
CVF_ASSERT ( m_mainPlotWindow = = NULL ) ;
m_mainPlotWindow = new RiuMainPlotWindow ;
2016-06-29 07:15:39 -05:00
m_mainPlotWindow - > setWindowTitle ( " Plots - ResInsight " ) ;
2016-06-27 04:07:01 -05:00
m_mainPlotWindow - > setDefaultWindowSize ( ) ;
m_mainPlotWindow - > loadWinGeoAndDockToolBarLayout ( ) ;
m_mainPlotWindow - > showWindow ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : deleteMainPlotWindow ( )
{
2016-06-29 07:15:39 -05:00
if ( m_mainPlotWindow )
{
m_mainPlotWindow - > deleteLater ( ) ;
m_mainPlotWindow = NULL ;
}
2016-06-27 04:07:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-06-27 07:00:19 -05:00
RiuMainPlotWindow * RiaApplication : : getOrCreateAndShowMainPlotWindow ( )
2016-06-27 04:07:01 -05:00
{
if ( ! m_mainPlotWindow )
{
createMainPlotWindow ( ) ;
2017-08-21 06:09:06 -05:00
m_mainPlotWindow - > initializeGuiNewProjectLoaded ( ) ;
2016-10-05 03:04:41 -05:00
loadAndUpdatePlotData ( ) ;
2016-06-27 04:07:01 -05:00
}
2016-11-24 07:47:20 -06:00
if ( m_mainPlotWindow - > isMinimized ( ) )
{
m_mainPlotWindow - > showNormal ( ) ;
m_mainPlotWindow - > update ( ) ;
}
else
{
m_mainPlotWindow - > show ( ) ;
}
2016-10-04 02:29:45 -05:00
m_mainPlotWindow - > raise ( ) ;
2016-06-27 07:00:19 -05:00
2016-06-27 04:07:01 -05:00
return m_mainPlotWindow ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuMainPlotWindow * RiaApplication : : mainPlotWindow ( )
{
return m_mainPlotWindow ;
}
2016-08-31 10:34:31 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-01-17 06:06:57 -06:00
RiuMainWindowBase * RiaApplication : : mainWindowByID ( int mainWindowID )
{
if ( mainWindowID = = 0 ) return RiuMainWindow : : instance ( ) ;
else if ( mainWindowID = = 1 ) return m_mainPlotWindow ;
else return nullptr ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-08-31 10:34:31 -05:00
RimViewWindow * RiaApplication : : activeViewWindow ( )
{
RimViewWindow * viewWindow = NULL ;
2017-03-31 08:10:39 -05:00
QWidget * mainWindowWidget = RiaApplication : : activeWindow ( ) ;
2016-08-31 10:34:31 -05:00
2017-03-31 08:10:39 -05:00
if ( dynamic_cast < RiuMainWindow * > ( mainWindowWidget ) )
2016-08-31 10:34:31 -05:00
{
viewWindow = RiaApplication : : instance ( ) - > activeReservoirView ( ) ;
}
2017-03-31 08:10:39 -05:00
else if ( dynamic_cast < RiuMainPlotWindow * > ( mainWindowWidget ) )
2016-08-31 10:34:31 -05:00
{
2017-03-31 08:10:39 -05:00
RiuMainPlotWindow * mainPlotWindow = dynamic_cast < RiuMainPlotWindow * > ( mainWindowWidget ) ;
2016-08-31 10:34:31 -05:00
QList < QMdiSubWindow * > subwindows = mainPlotWindow - > subWindowList ( QMdiArea : : StackingOrder ) ;
if ( subwindows . size ( ) > 0 )
{
2017-03-31 08:10:39 -05:00
viewWindow = RiuInterfaceToViewWindow : : viewWindowFromWidget ( subwindows . back ( ) - > widget ( ) ) ;
2016-08-31 10:34:31 -05:00
}
}
return viewWindow ;
}
2017-04-25 08:01:31 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : isMain3dWindowVisible ( ) const
{
return RiuMainWindow : : instance ( ) - > isVisible ( ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : isMainPlotWindowVisible ( ) const
{
if ( ! m_mainPlotWindow ) return false ;
return m_mainPlotWindow - > isVisible ( ) ;
}
2016-10-04 02:29:45 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : tryCloseMainWindow ( )
{
RiuMainWindow * mainWindow = RiuMainWindow : : instance ( ) ;
if ( mainWindow & & ! mainWindow - > isVisible ( ) )
{
mainWindow - > close ( ) ;
return true ;
}
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : tryClosePlotWindow ( )
{
2016-10-04 06:14:39 -05:00
if ( ! m_mainPlotWindow )
{
return true ;
}
2016-10-04 02:29:45 -05:00
if ( m_mainPlotWindow & & ! m_mainPlotWindow - > isVisible ( ) )
{
m_mainPlotWindow - > close ( ) ;
return true ;
}
return false ;
}
2016-10-05 01:23:07 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : addToRecentFiles ( const QString & fileName )
{
m_recentFileActionProvider - > addFileName ( fileName ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std : : vector < QAction * > RiaApplication : : recentFileActions ( ) const
{
return m_recentFileActionProvider - > actions ( ) ;
}
2017-07-26 09:57:43 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : setStartDir ( const QString & startDir )
{
m_startupDefaultDirectory = startDir ;
}
2013-12-04 05:04:42 -06:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 07:28:01 -05: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 05:11:48 -05: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 07:28:01 -05: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.");
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2013-10-08 07:28:01 -05:00
return ;
}
executeCommandObjects ( ) ;
// Exit code != 0 means we have an error
if ( exitCode ! = 0 )
{
// MFLog::error(QString("Simulation execution failed (exit code %1).").arg(exitCode));
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2013-10-08 07:28:01 -05:00
return ;
}
// If multiple cases are present, invoke launchProcess() which will set next current case, and run script on this case
2015-11-27 09:37:26 -06:00
if ( ! m_currentCaseIds . empty ( ) )
2013-10-08 07:28:01 -05:00
{
launchProcess ( m_currentProgram , m_currentArguments ) ;
}
else
{
// Disable concept of current case
m_socketServer - > setCurrentCaseId ( - 1 ) ;
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2013-10-08 07:28:01 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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
2015-11-27 09:37:26 -06:00
if ( ! m_currentCaseIds . empty ( ) )
2013-10-08 07:28:01 -05:00
{
int nextCaseId = m_currentCaseIds . front ( ) ;
m_currentCaseIds . pop_front ( ) ;
m_socketServer - > setCurrentCaseId ( nextCaseId ) ;
}
else
{
// Disable current case concept
m_socketServer - > setCurrentCaseId ( - 1 ) ;
}
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = true ;
2013-10-08 07:28:01 -05:00
m_workerProcess = new caf : : UiProcess ( this ) ;
QProcessEnvironment penv = QProcessEnvironment : : systemEnvironment ( ) ;
2014-01-02 07:31:10 -06: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 07:28:01 -05: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 ;
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2013-10-08 07:28:01 -05:00
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 05:44:57 -05:00
m_activeReservoirView - > viewer ( ) - > updateNavigationPolicy ( ) ;
2013-10-08 07:28:01 -05: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 ) ;
}
2015-09-18 12:24:02 -05:00
if ( RiuMainWindow : : instance ( ) & & RiuMainWindow : : instance ( ) - > projectTreeView ( ) )
{
RiuMainWindow : : instance ( ) - > projectTreeView ( ) - > enableAppendOfClassNameToUiItemText ( m_preferences - > appendClassNameToUiText ( ) ) ;
2017-01-19 10:35:47 -06:00
if ( mainPlotWindow ( ) ) mainPlotWindow ( ) - > projectTreeView ( ) - > enableAppendOfClassNameToUiItemText ( m_preferences - > appendClassNameToUiText ( ) ) ;
2015-09-18 12:24:02 -05:00
}
2016-08-09 06:09:08 -05:00
caf : : FixedAtlasFont : : FontSize fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_16 ;
if ( m_preferences - > fontSizeInScene ( ) = = " 8 " )
{
fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_8 ;
}
else if ( m_preferences - > fontSizeInScene ( ) = = " 12 " )
{
fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_12 ;
}
else if ( m_preferences - > fontSizeInScene ( ) = = " 16 " )
{
fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_16 ;
}
else if ( m_preferences - > fontSizeInScene ( ) = = " 24 " )
{
fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_24 ;
}
else if ( m_preferences - > fontSizeInScene ( ) = = " 32 " )
{
fontSizeType = caf : : FixedAtlasFont : : POINT_SIZE_32 ;
}
m_customFont = new caf : : FixedAtlasFont ( fontSizeType ) ;
2013-10-08 07:28:01 -05:00
if ( this - > project ( ) )
{
this - > project ( ) - > setScriptDirectories ( m_preferences - > scriptDirectories ( ) ) ;
2015-09-18 12:24:02 -05:00
this - > project ( ) - > updateConnectedEditors ( ) ;
2016-08-09 06:09:08 -05:00
std : : vector < RimView * > visibleViews ;
this - > project ( ) - > allVisibleViews ( visibleViews ) ;
for ( auto view : visibleViews )
{
RimEclipseView * eclipseView = dynamic_cast < RimEclipseView * > ( view ) ;
if ( eclipseView )
{
eclipseView - > scheduleReservoirGridGeometryRegen ( ) ;
}
view - > scheduleCreateDisplayModelAndRedraw ( ) ;
}
2013-10-08 07:28:01 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : terminateProcess ( )
{
if ( m_workerProcess )
{
m_workerProcess - > close ( ) ;
}
2017-07-31 04:10:22 -05:00
m_runningWorkerProcess = false ;
2013-10-08 07:28:01 -05:00
m_workerProcess = NULL ;
}
2017-07-31 04:10:22 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : waitForProcess ( ) const
{
while ( m_runningWorkerProcess )
{
2017-07-31 04:26:21 -05:00
# ifdef WIN32
2017-07-31 04:10:22 -05:00
Sleep ( 100 ) ;
2017-07-31 04:26:21 -05:00
# else
usleep ( 100000 ) ;
# endif
2017-08-03 04:31:12 -05:00
processEvents ( ) ;
2017-07-31 04:10:22 -05:00
}
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 02:46:17 -05:00
QString RiaApplication : : lastUsedDialogDirectory ( const QString & dialogName )
2013-10-08 07:28:01 -05:00
{
2016-09-21 02:46:17 -05:00
QString lastUsedDirectory = m_startupDefaultDirectory ;
auto it = m_fileDialogDefaultDirectories . find ( dialogName ) ;
if ( it ! = m_fileDialogDefaultDirectories . end ( ) )
{
lastUsedDirectory = it - > second ;
}
return lastUsedDirectory ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication : : lastUsedDialogDirectoryWithFallback ( const QString & dialogName , const QString & fallbackDirectory )
{
QString lastUsedDirectory = m_startupDefaultDirectory ;
if ( ! fallbackDirectory . isEmpty ( ) )
{
lastUsedDirectory = fallbackDirectory ;
}
auto it = m_fileDialogDefaultDirectories . find ( dialogName ) ;
if ( it ! = m_fileDialogDefaultDirectories . end ( ) )
2013-10-08 07:28:01 -05:00
{
2016-09-21 02:46:17 -05:00
lastUsedDirectory = it - > second ;
2013-10-08 07:28:01 -05:00
}
2016-09-21 02:46:17 -05:00
return lastUsedDirectory ;
2013-10-08 07:28:01 -05:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 02:46:17 -05:00
void RiaApplication : : setLastUsedDialogDirectory ( const QString & dialogName , const QString & directory )
2013-10-08 07:28:01 -05:00
{
2016-09-21 02:46:17 -05:00
m_fileDialogDefaultDirectories [ dialogName ] = directory ;
2013-10-08 07:28:01 -05:00
}
2013-12-04 05:04:42 -06:00
2016-10-05 03:42:08 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : openFile ( const QString & fileName )
{
2017-05-11 02:23:13 -05:00
if ( ! caf : : Utils : : fileExists ( fileName ) ) return false ;
2016-11-24 03:51:20 -06:00
2016-10-05 03:42:08 -05:00
bool loadingSucceded = false ;
2017-04-20 01:07:47 -05:00
if ( RiaApplication : : hasValidProjectFileExtension ( fileName ) )
2016-10-05 03:42:08 -05:00
{
loadingSucceded = loadProject ( fileName ) ;
}
else if ( fileName . contains ( " .egrid " , Qt : : CaseInsensitive ) | | fileName . contains ( " .grid " , Qt : : CaseInsensitive ) )
{
2017-08-24 23:51:56 -05:00
loadingSucceded = RiaImportEclipseCaseTools : : openEclipseCaseFromFile ( fileName ) ;
2016-10-05 03:42:08 -05:00
}
2016-11-28 00:25:04 -06:00
else if ( fileName . contains ( " .grdecl " , Qt : : CaseInsensitive ) )
{
2017-08-24 23:51:56 -05:00
loadingSucceded = RicImportInputEclipseCaseFeature : : openInputEclipseCaseFromFileNames ( QStringList ( fileName ) ) ;
2016-11-28 00:25:04 -06:00
}
2016-10-05 03:42:08 -05:00
else if ( fileName . contains ( " .odb " , Qt : : CaseInsensitive ) )
{
loadingSucceded = openOdbCaseFromFile ( fileName ) ;
}
2016-10-06 03:33:57 -05:00
else if ( fileName . contains ( " .smspec " , Qt : : CaseInsensitive ) )
{
loadingSucceded = RicImportSummaryCaseFeature : : createAndAddSummaryCaseFromFile ( fileName ) ;
if ( loadingSucceded )
{
getOrCreateAndShowMainPlotWindow ( ) ;
2016-10-24 09:01:19 -05:00
std : : vector < RimCase * > cases ;
m_project - > allCases ( cases ) ;
if ( cases . size ( ) = = 0 )
{
RiuMainWindow : : instance ( ) - > close ( ) ;
}
2016-10-06 03:33:57 -05:00
m_project - > updateConnectedEditors ( ) ;
}
}
2016-10-05 03:42:08 -05:00
2017-04-20 01:07:47 -05:00
if ( loadingSucceded & & ! RiaApplication : : hasValidProjectFileExtension ( fileName ) )
{
caf : : PdmUiModelChangeDetector : : instance ( ) - > setModelChanged ( ) ;
}
2016-10-05 03:42:08 -05:00
return loadingSucceded ;
}
2013-12-04 05:04:42 -06: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 ;
2016-11-25 07:21:40 -06:00
modifier . setReplaceCaseFirstOccurrence ( gridFn ) ;
2013-12-04 05:04:42 -06:00
bool loadOk = loadProject ( templateProjectFileName , PLA_NONE , & modifier ) ;
if ( loadOk )
{
2017-08-04 04:25:17 -05:00
RicSnapshotAllViewsToFileFeature : : exportSnapshotOfAllViewsIntoFolder ( snapshotFolderName ) ;
2013-12-04 05:04:42 -06:00
}
}
mainWnd - > loadWinGeoAndDockToolBarLayout ( ) ;
}
2016-10-27 01:35:57 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-10-08 07:28:01 -05:00
void removeDirectoryWithContent ( QDir dirToDelete )
{
QStringList files = dirToDelete . entryList ( ) ;
for ( int fIdx = 0 ; fIdx < files . size ( ) ; + + fIdx )
{
dirToDelete . remove ( files [ fIdx ] ) ;
}
dirToDelete . rmdir ( " . " ) ;
}
2017-04-20 15:34:15 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void logInfoTextWithTimeInSeconds ( const QTime & time , const QString & msg )
{
double timeRunning = time . elapsed ( ) / 1000.0 ;
QString timeText = QString ( " (%1 s) " ) . arg ( timeRunning , 0 , ' f ' , 1 ) ;
RiaLogging : : info ( timeText + msg ) ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : runRegressionTest ( const QString & testRootPath )
{
2015-06-26 06:44:16 -05:00
m_runningRegressionTests = true ;
2013-10-08 07:28:01 -05: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 ;
2016-01-11 00:59:44 -06:00
// Minor workaround
// Use registry to define if interactive diff images should be created
// Defined by user in RiaRegressionTest
{
QSettings settings ;
bool useInteractiveDiff = settings . value ( " showInteractiveDiffImages " ) . toBool ( ) ;
if ( useInteractiveDiff )
{
imageCompareReporter . showInteractiveOnly ( ) ;
}
}
2017-04-20 15:34:15 -05:00
QTime timeStamp ;
timeStamp . start ( ) ;
logInfoTextWithTimeInSeconds ( timeStamp , " Starting regression tests \n " ) ;
2013-10-08 07:28:01 -05:00
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 ) ;
for ( int dirIdx = 0 ; dirIdx < folderList . size ( ) ; + + dirIdx )
{
QDir testCaseFolder ( folderList [ dirIdx ] . filePath ( ) ) ;
2017-04-20 14:21:12 -05:00
QString projectFileName ;
if ( testCaseFolder . exists ( regTestProjectName + " .rip " ) )
{
projectFileName = regTestProjectName + " .rip " ;
}
if ( testCaseFolder . exists ( regTestProjectName + " .rsp " ) )
2013-10-08 07:28:01 -05:00
{
2017-04-20 14:21:12 -05:00
projectFileName = regTestProjectName + " .rsp " ;
}
if ( ! projectFileName . isEmpty ( ) )
2013-10-08 07:28:01 -05:00
{
2017-04-20 15:34:15 -05:00
logInfoTextWithTimeInSeconds ( timeStamp , " Initializing test : " + testCaseFolder . absolutePath ( ) ) ;
loadProject ( testCaseFolder . filePath ( projectFileName ) ) ;
// Wait until all command objects have completed
while ( ! m_commandQueueLock . tryLock ( ) )
{
processEvents ( ) ;
}
m_commandQueueLock . unlock ( ) ;
regressionTestConfigureProject ( ) ;
2017-04-24 02:39:54 -05:00
resizeMaximizedPlotWindows ( ) ;
2017-04-20 15:34:15 -05:00
QString fullPathGeneratedFolder = testCaseFolder . absoluteFilePath ( generatedFolderName ) ;
2017-08-04 04:25:17 -05:00
RicSnapshotAllViewsToFileFeature : : exportSnapshotOfAllViewsIntoFolder ( fullPathGeneratedFolder ) ;
2017-04-20 15:34:15 -05:00
RicSnapshotAllPlotsToFileFeature : : exportSnapshotOfAllPlotsIntoFolder ( fullPathGeneratedFolder ) ;
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 )
{
2013-10-08 07:28:01 -05:00
qDebug ( ) < < " Error comparing : " < < imgComparator . errorMessage ( ) < < " \n " < < imgComparator . errorDetails ( ) ;
2017-04-20 15:34:15 -05:00
}
}
2013-10-08 07:28:01 -05:00
2017-04-20 15:34:15 -05:00
closeProject ( ) ;
logInfoTextWithTimeInSeconds ( timeStamp , " Completed test : " + testCaseFolder . absolutePath ( ) ) ;
2013-10-08 07:28:01 -05:00
}
}
2015-06-26 06:44:16 -05:00
2017-04-20 15:34:15 -05:00
RiaLogging : : info ( " \n " ) ;
logInfoTextWithTimeInSeconds ( timeStamp , " Completed regression tests " ) ;
2015-06-26 06:44:16 -05:00
m_runningRegressionTests = false ;
2013-10-08 07:28:01 -05:00
}
2017-04-24 02:39:54 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : resizeMaximizedPlotWindows ( )
{
std : : vector < RimViewWindow * > viewWindows ;
2017-04-24 14:40:46 -05:00
m_project - > mainPlotCollection ( ) - > descendantsIncludingThisOfType ( viewWindows ) ;
2017-04-24 02:39:54 -05:00
for ( auto viewWindow : viewWindows )
{
if ( viewWindow - > isMdiWindow ( ) )
{
RimMdiWindowGeometry wndGeo = viewWindow - > mdiWindowGeometry ( ) ;
if ( wndGeo . isMaximized )
{
QWidget * viewWidget = viewWindow - > viewWidget ( ) ;
if ( viewWidget )
{
QMdiSubWindow * mdiWindow = m_mainPlotWindow - > findMdiSubWindow ( viewWidget ) ;
if ( mdiWindow )
{
mdiWindow - > showNormal ( ) ;
viewWidget - > resize ( RiaApplication : : regressionDefaultImageSize ( ) ) ;
}
}
}
}
}
}
2013-10-08 07:28:01 -05: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 ) ) ;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 ( ) ;
}
2016-08-09 06:09:08 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf : : Font * RiaApplication : : customFont ( )
{
CVF_ASSERT ( m_customFont . notNull ( ) ) ;
return m_customFont . p ( ) ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
2015-10-23 07:13:14 -05:00
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : clearViewsScheduledForUpdate ( )
{
if ( m_resViewUpdateTimer )
{
while ( m_resViewUpdateTimer - > isActive ( ) )
{
QCoreApplication : : processEvents ( ) ;
}
}
m_resViewsToUpdate . clear ( ) ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 03:45:15 -06:00
return m_helpText ;
/*
2013-10-08 07:28:01 -05: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 + =
" \n Parameter Description \n "
" ----------------------------------------------------------------- \n "
" -last Open last used project \n "
" \n "
" -project <filename> Open project file <filename> \n "
" \n "
2013-10-18 09:23:31 -05:00
" -case <casename> Import Eclipse case <casename> \n "
2013-10-08 07:28:01 -05: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 03:45:15 -06:00
*/
2013-10-08 07:28:01 -05: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 03:34:15 -05:00
void RiaApplication : : scheduleDisplayModelUpdateAndRedraw ( RimView * resViewToUpdate )
2013-10-08 07:28:01 -05: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 ) ;
}
}
2017-06-20 09:15:47 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-06-21 04:06:38 -05:00
void RiaApplication : : scheduleRecalculateCompletionTypeAndRedrawAllViews ( )
2017-06-20 09:15:47 -05:00
{
2017-06-21 04:06:38 -05:00
for ( RimEclipseCase * eclipseCase : project ( ) - > activeOilField ( ) - > analysisModels - > cases ( ) )
{
m_eclipseCasesToRecalculate . push_back ( eclipseCase ) ;
}
if ( ! m_recalculateCompletionTypeTimer )
{
m_recalculateCompletionTypeTimer = new QTimer ( this ) ;
m_recalculateCompletionTypeTimer - > setSingleShot ( true ) ;
connect ( m_recalculateCompletionTypeTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( slotRecaulculateCompletionType ( ) ) ) ;
}
m_recalculateCompletionTypeTimer - > start ( 500 ) ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : scheduleRecalculateCompletionTypeAndRedrawEclipseCase ( RimEclipseCase * eclipseCase )
{
m_eclipseCasesToRecalculate . push_back ( eclipseCase ) ;
2017-06-20 09:15:47 -05:00
if ( ! m_recalculateCompletionTypeTimer )
{
m_recalculateCompletionTypeTimer = new QTimer ( this ) ;
m_recalculateCompletionTypeTimer - > setSingleShot ( true ) ;
connect ( m_recalculateCompletionTypeTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( slotRecaulculateCompletionType ( ) ) ) ;
}
m_recalculateCompletionTypeTimer - > start ( 500 ) ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : slotUpdateScheduledDisplayModels ( )
{
// Compress to remove duplicates
2015-09-18 10:02:24 -05:00
// and update dependent views after independent views
std : : set < RimView * > independent3DViewsToUpdate ;
std : : set < RimView * > dependent3DViewsToUpdate ;
2013-10-08 07:28:01 -05:00
for ( size_t i = 0 ; i < m_resViewsToUpdate . size ( ) ; + + i )
{
2015-10-23 07:13:14 -05:00
if ( ! m_resViewsToUpdate [ i ] ) continue ;
2015-09-25 04:01:41 -05:00
if ( m_resViewsToUpdate [ i ] - > viewController ( ) )
2015-09-18 10:02:24 -05:00
dependent3DViewsToUpdate . insert ( m_resViewsToUpdate [ i ] ) ;
else
independent3DViewsToUpdate . insert ( m_resViewsToUpdate [ i ] ) ;
}
for ( std : : set < RimView * > : : iterator it = independent3DViewsToUpdate . begin ( ) ; it ! = independent3DViewsToUpdate . end ( ) ; + + it )
{
if ( * it )
{
( * it ) - > createDisplayModelAndRedraw ( ) ;
}
2013-10-08 07:28:01 -05:00
}
2015-09-18 10:02:24 -05:00
for ( std : : set < RimView * > : : iterator it = dependent3DViewsToUpdate . begin ( ) ; it ! = dependent3DViewsToUpdate . end ( ) ; + + it )
2013-10-08 07:28:01 -05:00
{
if ( * it )
{
( * it ) - > createDisplayModelAndRedraw ( ) ;
}
}
2015-09-21 08:06:11 -05:00
m_resViewsToUpdate . clear ( ) ;
2013-10-08 07:28:01 -05:00
}
2017-06-20 09:15:47 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : slotRecaulculateCompletionType ( )
{
2017-06-21 04:06:38 -05:00
std : : set < RimEclipseCase * > uniqueCases ( m_eclipseCasesToRecalculate . begin ( ) , m_eclipseCasesToRecalculate . end ( ) ) ;
for ( RimEclipseCase * eclipseCase : uniqueCases )
2017-06-20 09:15:47 -05:00
{
eclipseCase - > recalculateCompletionTypeAndRedrawAllViews ( ) ;
}
2017-06-21 04:06:38 -05:00
m_eclipseCasesToRecalculate . clear ( ) ;
2017-06-20 09:15:47 -05:00
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 ( ) ;
2015-11-27 09:37:26 -06:00
+ + it ;
2013-10-08 07:28:01 -05:00
m_commandQueue . remove ( toBeRemoved ) ;
}
else
{
2015-11-27 09:37:26 -06:00
+ + it ;
2013-10-08 07:28:01 -05:00
}
}
2015-11-27 09:37:26 -06:00
if ( ! m_commandQueue . empty ( ) )
2013-10-08 07:28:01 -05:00
{
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 06:44:16 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication : : isRunningRegressionTests ( ) const
{
return m_runningRegressionTests ;
}
2013-10-08 07:28:01 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : executeRegressionTests ( const QString & regressionTestPath )
{
RiuMainWindow * mainWnd = RiuMainWindow : : instance ( ) ;
if ( mainWnd )
{
mainWnd - > hideAllDockWindows ( ) ;
mainWnd - > setDefaultWindowSize ( ) ;
runRegressionTest ( regressionTestPath ) ;
mainWnd - > loadWinGeoAndDockToolBarLayout ( ) ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2014-01-23 06:17:49 -06:00
void RiaApplication : : regressionTestConfigureProject ( )
2013-10-08 07:28:01 -05:00
{
RiuMainWindow * mainWnd = RiuMainWindow : : instance ( ) ;
if ( ! mainWnd ) return ;
if ( m_project . isNull ( ) ) return ;
2015-05-15 11:51:49 -05:00
std : : vector < RimCase * > projectCases ;
2013-10-08 07:28:01 -05:00
m_project - > allCases ( projectCases ) ;
for ( size_t i = 0 ; i < projectCases . size ( ) ; i + + )
{
2015-05-15 11:51:49 -05:00
RimCase * cas = projectCases [ i ] ;
if ( ! cas ) continue ;
std : : vector < RimView * > views = cas - > views ( ) ;
2013-10-08 07:28:01 -05:00
2015-05-15 11:51:49 -05:00
for ( size_t j = 0 ; j < views . size ( ) ; j + + )
2013-10-08 07:28:01 -05:00
{
2015-05-15 11:51:49 -05:00
RimView * riv = views [ j ] ;
2013-10-08 07:28:01 -05:00
if ( riv & & riv - > viewer ( ) )
{
2015-10-23 07:13:14 -05:00
// Make sure all views are maximized for snapshotting
QMdiSubWindow * subWnd = mainWnd - > findMdiSubWindow ( riv - > viewer ( ) - > layoutWidget ( ) ) ;
if ( subWnd )
{
subWnd - > showMaximized ( ) ;
}
2013-10-08 07:28:01 -05:00
// This size is set to match the regression test reference images
2017-04-24 02:23:32 -05:00
riv - > viewer ( ) - > setFixedSize ( RiaApplication : : regressionDefaultImageSize ( ) ) ;
2013-10-08 07:28:01 -05:00
}
}
}
}
2017-04-24 02:23:32 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QSize RiaApplication : : regressionDefaultImageSize ( )
{
return QSize ( 1000 , 745 ) ;
}
2017-08-29 02:38:41 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication : : setHelpText ( const QString & helpText )
{
m_helpText = helpText ;
}