2013-10-08 14:28:01 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
2014-09-23 15:04:57 +02:00
// Copyright (C) 2011- Statoil ASA
// Copyright (C) 2013- Ceetron Solutions AS
// Copyright (C) 2011-2012 Ceetron AS
2013-10-08 14:28:01 +02:00
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaApplication.h"
2018-01-12 11:31:01 +01:00
#include "RiaArgumentParser.h"
2013-10-08 14:28:01 +02:00
#include "RiaBaseDefs.h"
2018-04-20 10:03:07 +02:00
#include "RiaFilePathTools.h"
2017-08-25 06:51:56 +02:00
#include "RiaImportEclipseCaseTools.h"
2017-02-23 14:24:18 +01:00
#include "RiaLogging.h"
2015-09-25 15:57:43 +02:00
#include "RiaPreferences.h"
2013-12-04 12:04:42 +01:00
#include "RiaProjectModifier.h"
2015-09-25 15:57:43 +02:00
#include "RiaSocketServer.h"
#include "RiaVersionInfo.h"
2018-01-12 11:31:01 +01:00
#include "RiaViewRedrawScheduler.h"
2013-10-08 14:28:01 +02:00
2018-03-08 10:10:15 +01:00
#include "RicImportInputEclipseCaseFeature.h"
2018-03-19 11:02:22 +01:00
#include "RicImportSummaryCasesFeature.h"
2018-03-08 10:10:15 +01:00
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
2017-10-03 15:31:45 +02:00
2018-01-23 14:23:28 +01:00
#include "Rim2dIntersectionViewCollection.h"
2013-10-08 14:28:01 +02:00
#include "RimCellRangeFilterCollection.h"
2015-09-25 15:57:43 +02:00
#include "RimCommandObject.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseView.h"
2017-02-17 09:29:46 +01:00
#include "RimFlowPlotCollection.h"
2016-10-06 10:33:57 +02:00
#include "RimFormationNamesCollection.h"
2018-03-08 10:10:15 +01:00
#include "RimFractureTemplateCollection.h"
2015-04-20 09:02:33 +02:00
#include "RimGeoMechCase.h"
2015-09-25 15:57:43 +02:00
#include "RimGeoMechCellColors.h"
2015-04-20 09:02:33 +02:00
#include "RimGeoMechModels.h"
#include "RimGeoMechView.h"
2018-03-08 10:10:15 +01:00
#include "RimGeoMechView.h"
2015-09-25 15:57:43 +02:00
#include "RimIdenticalGridCaseGroup.h"
2015-09-03 08:09:06 +02:00
#include "RimMainPlotCollection.h"
2017-10-03 15:31:45 +02:00
#include "RimObservedData.h"
2017-09-14 15:44:01 +02:00
#include "RimObservedDataCollection.h"
2015-09-25 15:57:43 +02:00
#include "RimOilField.h"
2018-03-08 10:10:15 +01:00
#include "RimPltPlotCollection.h"
2015-09-25 15:57:43 +02:00
#include "RimProject.h"
2018-03-08 10:10:15 +01:00
#include "RimRftPlotCollection.h"
#include "RimStimPlanColors.h"
2016-06-24 15:10:18 +02:00
#include "RimSummaryCase.h"
2017-09-06 16:32:46 +02:00
#include "RimSummaryCaseMainCollection.h"
2017-11-07 20:40:45 +01:00
#include "RimSummaryCrossPlotCollection.h"
2016-06-24 15:10:18 +02:00
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
2015-10-23 14:13:14 +02:00
#include "RimViewLinker.h"
#include "RimViewLinkerCollection.h"
2017-10-20 14:05:42 +02:00
#include "RimWellLogFile.h"
2015-09-03 08:09:06 +02:00
#include "RimWellLogPlot.h"
2015-09-25 15:57:43 +02:00
#include "RimWellLogPlotCollection.h"
#include "RimWellPathCollection.h"
2018-03-08 10:10:15 +01:00
#include "RimWellPathFracture.h"
2017-10-23 13:57:01 +02:00
#include "RimWellPltPlot.h"
2018-03-08 10:10:15 +01:00
#include "RimWellRftPlot.h"
2015-09-25 15:57:43 +02:00
2018-04-26 20:05:42 +02:00
#include "RiuDockWidgetTools.h"
2018-04-27 06:28:08 +02:00
#include "RiuPlotMainWindow.h"
2015-09-25 15:57:43 +02:00
#include "RiuMainWindow.h"
#include "RiuProcessMonitor.h"
2016-10-05 08:23:07 +02:00
#include "RiuRecentFileActionProvider.h"
2015-11-09 19:05:00 +01:00
#include "RiuSelectionManager.h"
2015-09-25 15:57:43 +02:00
#include "RiuViewer.h"
2016-08-09 13:09:08 +02:00
2015-09-25 15:57:43 +02:00
#include "cafAppEnum.h"
2018-03-08 10:10:15 +01:00
#include "cafEffectGenerator.h"
#include "cafFixedAtlasFont.h"
2015-09-25 15:57:43 +02:00
#include "cafPdmSettings.h"
2017-04-20 08:07:47 +02:00
#include "cafPdmUiModelChangeDetector.h"
2015-09-18 19:24:02 +02:00
#include "cafPdmUiTreeView.h"
2015-09-25 15:57:43 +02:00
#include "cafProgressInfo.h"
2017-10-03 14:50:06 +02:00
#include "cafQTreeViewStateSerializer.h"
2015-09-25 15:57:43 +02:00
#include "cafUiProcess.h"
#include "cafUtils.h"
2017-04-20 08:07:47 +02:00
2015-09-25 15:57:43 +02:00
#include "cvfProgramOptions.h"
#include "cvfqtUtils.h"
#include <QDir>
#include <QFileDialog>
2015-10-23 14:13:14 +02:00
#include <QMdiSubWindow>
2015-09-25 15:57:43 +02:00
#include <QMessageBox>
2017-04-20 11:02:05 +02:00
#include <QTreeView>
2015-09-25 15:57:43 +02:00
2018-03-08 10:31:21 +01:00
#ifndef WIN32
2018-03-12 11:12:39 +01:00
#include <unistd.h> // for usleep
2018-03-08 10:31:21 +01:00
#endif //WIN32
2018-03-08 10:10:15 +01:00
#ifdef USE_UNIT_TESTS
2015-10-05 16:09:51 +02:00
#include "gtest/gtest.h"
2018-03-08 10:10:15 +01:00
#endif // USE_UNIT_TESTS
2017-02-23 14:24:18 +01:00
2013-10-08 14:28:01 +02:00
namespace caf
{
template <>
void AppEnum < RiaApplication :: RINavigationPolicy >:: setUp ()
{
addItem ( RiaApplication :: NAVIGATION_POLICY_CEETRON , "NAVIGATION_POLICY_CEETRON" , "Ceetron" );
addItem ( RiaApplication :: NAVIGATION_POLICY_CAD , "NAVIGATION_POLICY_CAD" , "CAD" );
2015-07-02 12:31:35 +02:00
addItem ( RiaApplication :: NAVIGATION_POLICY_GEOQUEST , "NAVIGATION_POLICY_GEOQUEST" , "GEOQUEST" );
addItem ( RiaApplication :: NAVIGATION_POLICY_RMS , "NAVIGATION_POLICY_RMS" , "RMS" );
2015-07-02 13:33:07 +02:00
setDefault ( RiaApplication :: NAVIGATION_POLICY_RMS );
2013-10-08 14:28:01 +02:00
}
}
2013-12-04 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
//==================================================================================================
///
/// \class RiaApplication
///
/// Application class
///
//==================================================================================================
2018-05-03 09:53:54 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: notify ( QObject * receiver , QEvent * event )
{
// Pre-allocating a memory exhaustion message
// Doing som e trickery to avoid deadlock, as creating a messagebox actually triggers a call to this notify method.
static QMessageBox * memoryExhaustedBox = nullptr ;
static bool allocatingMessageBox = false ;
if ( ! memoryExhaustedBox && ! allocatingMessageBox )
{
allocatingMessageBox = true ;
memoryExhaustedBox = new QMessageBox ( QMessageBox :: Critical ,
"ResInsight Exhausted Memory" ,
"Memory is Exhausted! \n ResInsight could not allocate the memory needed, and is now unstable and will probably crash soon." );
}
bool done = true ;
try
{
done = QApplication :: notify ( receiver , event );
}
catch ( const std :: bad_alloc & )
{
if ( memoryExhaustedBox ) memoryExhaustedBox -> exec ();
std :: cout << "ResInsight: Memory is Exhausted! \n ResInsight could not allocate the memory needed, and is now unstable and will probably crash soon." << std :: endl ;
// If we really want to crash instead of limping forward:
// throw;
}
return done ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 15:46:25 +02:00
caf :: PdmSettings :: readFieldsFromApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
applyPreferences ();
if ( useShaders ())
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: SHADER_BASED );
}
else
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: FIXED_FUNCTION );
}
// Start with a project
m_project = new RimProject ;
setWindowIcon ( QIcon ( ":/AppLogo48x48.png" ));
m_socketServer = new RiaSocketServer ( this );
2018-02-18 18:56:43 +01:00
m_workerProcess = nullptr ;
2013-10-08 14:28:01 +02:00
#ifdef WIN32
m_startupDefaultDirectory = QDir :: homePath ();
#else
m_startupDefaultDirectory = QDir :: currentPath ();
#endif
2016-09-21 09:46:17 +02:00
setLastUsedDialogDirectory ( "MULTICASEIMPORT" , "/" );
2013-10-08 14:28:01 +02: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 13:09:08 +02:00
m_standardFont = new caf :: FixedAtlasFont ( caf :: FixedAtlasFont :: POINT_SIZE_8 );
2017-07-31 11:10:22 +02:00
m_runningWorkerProcess = false ;
2017-06-20 16:15:47 +02:00
m_mainPlotWindow = nullptr ;
2016-10-05 08:23:07 +02:00
m_recentFileActionProvider = std :: unique_ptr < RiuRecentFileActionProvider > ( new RiuRecentFileActionProvider );
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication ::~ RiaApplication ()
{
2018-04-26 20:05:42 +02:00
RiuDockWidgetTools :: instance () -> saveDockWidgetsState ();
2016-06-27 15:27:18 +02:00
deleteMainPlotWindow ();
2013-10-08 14:28:01 +02:00
delete m_preferences ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication * RiaApplication :: instance ()
{
return static_cast < RiaApplication *> qApp ;
}
2015-12-03 10:33:38 +01: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 14:28:01 +02: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 12:04:42 +01:00
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-12-04 12:04:42 +01:00
bool RiaApplication :: loadProject ( const QString & projectFileName , ProjectLoadAction loadAction , RiaProjectModifier * projectModifier )
2013-10-08 14:28:01 +02:00
{
// First Close the current project
2016-10-04 11:02:56 +02:00
closeProject ();
2013-10-08 14:28:01 +02:00
2017-02-27 13:17:32 +01:00
RiaLogging :: info ( QString ( "Starting to open project file : '%1'" ). arg ( projectFileName ));
2017-02-23 14:24:18 +01:00
2018-03-06 11:27:08 +01:00
// Create a absolute path file name, as this is required for update of file references in the project modifier object
QString fullPathProjectFileName = caf :: Utils :: absoluteFileName ( projectFileName );
if ( ! caf :: Utils :: fileExists ( fullPathProjectFileName ))
2017-02-23 14:24:18 +01:00
{
2018-03-06 11:27:08 +01:00
RiaLogging :: info ( QString ( "File does not exist : '%1'" ). arg ( fullPathProjectFileName ));
2017-02-23 14:24:18 +01:00
return false ;
}
2013-10-08 14:28:01 +02:00
2018-03-06 11:27:08 +01:00
m_project -> fileName = fullPathProjectFileName ;
2013-10-08 14:28:01 +02:00
m_project -> readFile ();
2016-10-04 14:23:34 +02:00
// Apply any modifications to the loaded project before we go ahead and load actual data
2013-12-04 12:04:42 +01:00
if ( projectModifier )
{
projectModifier -> applyModificationsToProject ( m_project );
}
2013-10-08 14:28:01 +02:00
// Propagate possible new location of project
2018-03-06 11:27:08 +01:00
m_project -> setProjectFileNameAndUpdateDependencies ( fullPathProjectFileName );
2013-10-08 14:28:01 +02:00
// On error, delete everything, and bail out.
if ( m_project -> projectFileVersionString (). isEmpty ())
{
2016-10-04 11:02:56 +02:00
closeProject ();
2013-10-08 14:28:01 +02:00
2018-03-06 11:27:08 +01:00
QString tmp = QString ( "Unknown project file version detected in file \n %1 \n\n Could not open project." ). arg ( fullPathProjectFileName );
2018-02-18 18:56:43 +01:00
QMessageBox :: warning ( nullptr , "Error when opening project file" , tmp );
2013-10-08 14:28:01 +02:00
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
2018-02-18 18:56:43 +01:00
mainWnd -> setPdmRoot ( nullptr );
2013-10-08 14:28:01 +02:00
// Delete all object possibly generated by readFile()
delete m_project ;
m_project = new RimProject ;
onProjectOpenedOrClosed ();
return true ;
}
2016-10-04 14:23:34 +02:00
if ( m_project -> show3DWindow ())
{
RiuMainWindow :: instance () -> show ();
}
else
{
2016-10-06 15:01:27 +02:00
RiuMainWindow :: instance () -> hide ();
2016-10-04 14:23:34 +02:00
}
if ( m_project -> showPlotWindow ())
{
2016-11-10 09:26:53 +01:00
if ( ! m_mainPlotWindow )
{
createMainPlotWindow ();
}
else
{
m_mainPlotWindow -> show ();
m_mainPlotWindow -> raise ();
}
2016-10-04 14:23:34 +02:00
}
else if ( mainPlotWindow ())
{
2016-10-06 15:01:27 +02:00
mainPlotWindow () -> hide ();
2016-10-04 14:23:34 +02:00
}
2013-10-08 14:28:01 +02:00
///////
// Load the external data, and initialize stuff that needs specific ordering
// VL check regarding specific order mentioned in comment above...
2018-03-06 11:27:08 +01:00
m_preferences -> lastUsedProjectFileName = fullPathProjectFileName ;
2015-08-04 11:47:06 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project -> oilFields (). size (); oilFieldIdx ++ )
{
RimOilField * oilField = m_project -> oilFields [ oilFieldIdx ];
2018-02-18 18:56:43 +01:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField -> analysisModels () : nullptr ;
if ( analysisModels == nullptr ) continue ;
2013-10-08 14:28:01 +02:00
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 08:30:12 +02:00
// Load the formation names
for ( RimOilField * oilField : m_project -> oilFields )
{
2018-02-18 18:56:43 +01:00
if ( oilField == nullptr ) continue ;
if ( oilField -> formationNamesCollection () != nullptr )
2016-08-24 08:30:12 +02:00
{
oilField -> formationNamesCollection () -> readAllFormationNames ();
}
}
2013-10-08 14:28:01 +02: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 ];
2018-02-18 18:56:43 +01:00
if ( oilField == nullptr ) continue ;
if ( oilField -> wellPathCollection == nullptr )
2013-10-08 14:28:01 +02:00
{
//printf("Create well path collection for oil field %i in loadProject.\n", oilFieldIdx);
oilField -> wellPathCollection = new RimWellPathCollection ();
}
2017-11-24 10:01:05 +01:00
if ( oilField -> wellPathCollection )
{
oilField -> wellPathCollection -> readWellPathFiles ();
oilField -> wellPathCollection -> readWellPathFormationFiles ();
}
2013-10-08 14:28:01 +02:00
}
2016-05-31 13:42:27 +02:00
for ( RimOilField * oilField : m_project -> oilFields )
{
2018-02-18 18:56:43 +01:00
if ( oilField == nullptr ) continue ;
2016-05-31 13:42:27 +02:00
// Temporary
2017-09-06 16:32:46 +02:00
if ( ! oilField -> summaryCaseMainCollection ())
2016-05-31 13:42:27 +02:00
{
2017-09-06 16:32:46 +02:00
oilField -> summaryCaseMainCollection = new RimSummaryCaseMainCollection ();
2016-05-31 13:42:27 +02:00
}
2017-09-06 16:32:46 +02:00
oilField -> summaryCaseMainCollection () -> createSummaryCasesFromRelevantEclipseResultCases ();
oilField -> summaryCaseMainCollection () -> loadAllSummaryCaseData ();
2017-02-17 09:29:46 +01:00
2017-09-14 15:44:01 +02:00
if ( ! oilField -> observedDataCollection ())
{
oilField -> observedDataCollection = new RimObservedDataCollection ();
}
2017-09-22 14:26:54 +02:00
for ( auto observedCases : oilField -> observedDataCollection () -> allObservedData ())
{
observedCases -> createSummaryReaderInterface ();
2017-10-03 15:31:45 +02:00
RimObservedData * rimObservedData = dynamic_cast < RimObservedData *> ( observedCases );
if ( rimObservedData )
{
rimObservedData -> updateMetaData ();
}
2017-09-22 14:26:54 +02:00
}
2018-02-01 15:37:05 +01:00
2017-02-17 09:29:46 +01:00
oilField -> fractureDefinitionCollection () -> loadAndUpdateData ();
2018-02-27 12:05:37 +01:00
oilField -> fractureDefinitionCollection () -> createAndAssignTemplateCopyForNonMatchingUnit ();
2017-08-14 22:16:03 +02:00
{
std :: vector < RimWellPathFracture *> wellPathFractures ;
oilField -> wellPathCollection -> descendantsIncludingThisOfType ( wellPathFractures );
for ( auto fracture : wellPathFractures )
{
fracture -> loadDataAndUpdate ();
}
}
2016-05-31 13:42:27 +02:00
}
2013-12-04 12:04:42 +01:00
// If load action is specified to recalculate statistics, do it now.
// Apparently this needs to be done before the views are loaded, lest the number of time steps for statistics will be clamped
if ( loadAction & PLA_CALCULATE_STATISTICS )
{
for ( size_t oilFieldIdx = 0 ; oilFieldIdx < m_project -> oilFields (). size (); oilFieldIdx ++ )
{
RimOilField * oilField = m_project -> oilFields [ oilFieldIdx ];
2018-02-18 18:56:43 +01:00
RimEclipseCaseCollection * analysisModels = oilField ? oilField -> analysisModels () : nullptr ;
2013-12-04 12:04:42 +01:00
if ( analysisModels )
{
analysisModels -> recomputeStatisticsForAllCaseGroups ();
}
}
}
2018-02-01 15:37:05 +01:00
2013-10-08 14:28:01 +02:00
// Now load the ReservoirViews for the cases
// Add all "native" cases in the project
2015-05-15 18:51:49 +02:00
std :: vector < RimCase *> casesToLoad ;
2013-10-08 14:28:01 +02:00
m_project -> allCases ( casesToLoad );
{
2015-09-28 08:21:51 +02:00
caf :: ProgressInfo caseProgress ( casesToLoad . size (), "Reading Cases" );
2013-10-08 14:28:01 +02:00
2015-09-28 08:21:51 +02:00
for ( size_t cIdx = 0 ; cIdx < casesToLoad . size (); ++ cIdx )
2013-10-08 14:28:01 +02:00
{
2015-09-28 08:21:51 +02:00
RimCase * cas = casesToLoad [ cIdx ];
CVF_ASSERT ( cas );
2013-10-08 14:28:01 +02:00
2015-09-28 08:21:51 +02:00
caseProgress . setProgressDescription ( cas -> caseUserDescription ());
2018-01-09 10:11:28 +01:00
std :: vector < Rim3dView *> views = cas -> views ();
2017-12-08 16:38:58 +01:00
{ // To delete the view progress before incrementing the caseProgress
caf :: ProgressInfo viewProgress ( views . size (), "Creating Views" );
2013-10-08 14:28:01 +02:00
2017-12-08 16:38:58 +01:00
size_t j ;
for ( j = 0 ; j < views . size (); j ++ )
{
2018-01-09 10:11:28 +01:00
Rim3dView * riv = views [ j ];
2017-12-08 16:38:58 +01:00
CVF_ASSERT ( riv );
2013-10-08 14:28:01 +02:00
2017-12-08 16:38:58 +01:00
viewProgress . setProgressDescription ( riv -> name ());
2015-09-28 08:21:51 +02:00
2018-02-01 15:37:05 +01:00
if ( m_project -> isProjectFileVersionEqualOrOlderThan ( "2018.1.0.103" ))
{
std :: vector < RimStimPlanColors *> stimPlanColors ;
riv -> descendantsIncludingThisOfType ( stimPlanColors );
if ( stimPlanColors . size () == 1 )
{
stimPlanColors [ 0 ] -> updateConductivityResultName ();
}
}
2017-12-08 16:38:58 +01:00
riv -> loadDataAndUpdate ();
this -> setActiveReservoirView ( riv );
2015-10-28 12:23:24 +01:00
2018-01-15 14:52:22 +01:00
RimGridView * rigv = dynamic_cast < RimGridView *> ( riv );
if ( rigv ) rigv -> rangeFilterCollection () -> updateIconState ();
2015-10-28 12:23:24 +01:00
2017-12-08 16:38:58 +01:00
viewProgress . incrementProgress ();
}
2015-09-28 08:21:51 +02:00
}
caseProgress . incrementProgress ();
}
2013-10-08 14:28:01 +02:00
}
2015-10-22 16:02:28 +02:00
2015-10-22 16:46:58 +02:00
if ( m_project -> viewLinkerCollection () && m_project -> viewLinkerCollection () -> viewLinker ())
2015-10-22 16:02:28 +02:00
{
m_project -> viewLinkerCollection () -> viewLinker () -> updateOverrides ();
}
2018-01-23 14:23:28 +01:00
// Intersection Views: Sync from intersections in the case.
for ( RimCase * cas : casesToLoad )
{
cas -> intersectionViewCollection () -> syncFromExistingIntersections ( false );
}
2015-10-22 16:02:28 +02:00
2016-10-05 10:04:41 +02:00
loadAndUpdatePlotData ();
2013-10-08 14:28:01 +02:00
// NB! This function must be called before executing command objects,
// because the tree view state is restored from project file and sets
// current active view ( see restoreTreeViewState() )
// Default behavior for scripts is to use current active view for data read/write
onProjectOpenedOrClosed ();
processEvents ();
// Loop over command objects and execute them
for ( size_t i = 0 ; i < m_project -> commandObjects . size (); i ++ )
{
m_commandQueue . push_back ( m_project -> commandObjects [ i ]);
}
// Lock the command queue
m_commandQueueLock . lock ();
// Execute command objects, and release the mutex when the queue is empty
executeCommandObjects ();
2017-02-27 13:17:32 +01:00
RiaLogging :: info ( QString ( "Completed open of project file : '%1'" ). arg ( projectFileName ));
2017-02-23 14:24:18 +01:00
2013-10-08 14:28:01 +02:00
return true ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: loadProject ( const QString & projectFileName )
{
2018-02-18 18:56:43 +01:00
return loadProject ( projectFileName , PLA_NONE , nullptr );
2013-12-04 12:04:42 +01:00
}
2016-10-05 10:04:41 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: loadAndUpdatePlotData ()
{
RimWellLogPlotCollection * wlpColl = nullptr ;
RimSummaryPlotCollection * spColl = nullptr ;
2017-11-07 20:40:45 +01:00
RimSummaryCrossPlotCollection * scpColl = nullptr ;
2017-01-13 13:32:02 +01:00
RimFlowPlotCollection * flowColl = nullptr ;
2017-10-03 08:19:38 +02:00
RimRftPlotCollection * rftColl = nullptr ;
2017-10-23 13:57:01 +02:00
RimPltPlotCollection * pltColl = nullptr ;
2016-10-05 10:04:41 +02: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-11-07 20:40:45 +01:00
if ( m_project -> mainPlotCollection () && m_project -> mainPlotCollection () -> summaryCrossPlotCollection ())
{
scpColl = m_project -> mainPlotCollection () -> summaryCrossPlotCollection ();
}
2017-01-13 13:32:02 +01:00
if ( m_project -> mainPlotCollection () && m_project -> mainPlotCollection () -> flowPlotCollection ())
{
flowColl = m_project -> mainPlotCollection () -> flowPlotCollection ();
}
2017-10-03 08:19:38 +02:00
if ( m_project -> mainPlotCollection () && m_project -> mainPlotCollection () -> rftPlotCollection ())
{
rftColl = m_project -> mainPlotCollection () -> rftPlotCollection ();
}
2017-10-23 13:57:01 +02:00
if ( m_project -> mainPlotCollection () && m_project -> mainPlotCollection () -> pltPlotCollection ())
{
pltColl = m_project -> mainPlotCollection () -> pltPlotCollection ();
}
2017-01-13 13:32:02 +01:00
2016-10-05 10:04:41 +02:00
size_t plotCount = 0 ;
plotCount += wlpColl ? wlpColl -> wellLogPlots (). size () : 0 ;
2017-01-13 09:51:37 +01:00
plotCount += spColl ? spColl -> summaryPlots (). size () : 0 ;
2017-11-07 20:40:45 +01:00
plotCount += scpColl ? scpColl -> summaryPlots (). size () : 0 ;
2017-02-13 14:49:52 +01:00
plotCount += flowColl ? flowColl -> plotCount () : 0 ;
2017-10-03 08:19:38 +02:00
plotCount += rftColl ? rftColl -> rftPlots (). size () : 0 ;
2017-10-23 13:57:01 +02:00
plotCount += pltColl ? pltColl -> pltPlots (). size () : 0 ;
2016-10-05 10:04:41 +02: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 09:51:37 +01:00
for ( size_t wlpIdx = 0 ; wlpIdx < spColl -> summaryPlots (). size (); ++ wlpIdx )
2016-10-05 10:04:41 +02:00
{
2017-01-13 09:51:37 +01:00
spColl -> summaryPlots [ wlpIdx ] -> loadDataAndUpdate ();
2016-10-05 10:04:41 +02:00
plotProgress . incrementProgress ();
}
}
2017-02-13 14:49:52 +01:00
2017-11-14 14:01:19 +01:00
if ( scpColl )
{
for ( auto plot : scpColl -> summaryPlots ())
{
plot -> loadDataAndUpdate ();
plotProgress . incrementProgress ();
}
}
2017-01-13 13:32:02 +01:00
if ( flowColl )
{
2017-02-24 16:00:56 +01:00
plotProgress . setNextProgressIncrement ( flowColl -> plotCount ());
2017-03-07 12:19:54 +01:00
flowColl -> loadDataAndUpdate ();
plotProgress . incrementProgress ();
2017-01-13 13:32:02 +01:00
}
2017-10-03 08:19:38 +02:00
if ( rftColl )
{
for ( const auto & rftPlot : rftColl -> rftPlots ())
{
rftPlot -> loadDataAndUpdate ();
plotProgress . incrementProgress ();
2017-10-23 13:57:01 +02:00
}
}
if ( pltColl )
{
for ( const auto & pltPlot : pltColl -> pltPlots ())
{
pltPlot -> loadDataAndUpdate ();
plotProgress . incrementProgress ();
2017-10-03 08:19:38 +02:00
}
}
2016-10-05 10:04:41 +02:00
}
2013-12-04 12:04:42 +01:00
2017-04-20 11:02:05 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: storeTreeViewState ()
{
{
if ( mainPlotWindow () && mainPlotWindow () -> projectTreeView ())
{
caf :: PdmUiTreeView * projectTreeView = mainPlotWindow () -> projectTreeView ();
QString treeViewState ;
2017-09-06 13:06:37 +02:00
caf :: QTreeViewStateSerializer :: storeTreeViewStateToString ( projectTreeView -> treeView (), treeViewState );
2017-04-20 11:02:05 +02:00
QModelIndex mi = projectTreeView -> treeView () -> currentIndex ();
QString encodedModelIndexString ;
2017-09-06 13:06:37 +02:00
caf :: QTreeViewStateSerializer :: encodeStringFromModelIndex ( mi , encodedModelIndexString );
2017-04-20 11:02:05 +02:00
project () -> plotWindowTreeViewState = treeViewState ;
project () -> plotWindowCurrentModelIndexPath = encodedModelIndexString ;
}
}
{
caf :: PdmUiTreeView * projectTreeView = RiuMainWindow :: instance () -> projectTreeView ();
if ( projectTreeView )
{
QString treeViewState ;
2017-09-06 13:06:37 +02:00
caf :: QTreeViewStateSerializer :: storeTreeViewStateToString ( projectTreeView -> treeView (), treeViewState );
2017-04-20 11:02:05 +02:00
QModelIndex mi = projectTreeView -> treeView () -> currentIndex ();
QString encodedModelIndexString ;
2017-09-06 13:06:37 +02:00
caf :: QTreeViewStateSerializer :: encodeStringFromModelIndex ( mi , encodedModelIndexString );
2017-04-20 11:02:05 +02:00
project () -> mainWindowTreeViewState = treeViewState ;
project () -> mainWindowCurrentModelIndexPath = encodedModelIndexString ;
}
}
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
/// Add a list of well path file paths (JSON files) to the well path collection
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addWellPathsToModel ( QList < QString > wellPathFilePaths )
{
2018-02-18 18:56:43 +01:00
if ( m_project == nullptr || m_project -> oilFields . size () < 1 ) return ;
2013-10-08 14:28:01 +02:00
RimOilField * oilField = m_project -> activeOilField ();
2018-02-18 18:56:43 +01:00
if ( oilField == nullptr ) return ;
2013-10-08 14:28:01 +02:00
2018-02-18 18:56:43 +01:00
if ( oilField -> wellPathCollection == nullptr )
2013-10-08 14:28:01 +02:00
{
//printf("Create well path collection.\n");
oilField -> wellPathCollection = new RimWellPathCollection ();
2015-08-12 17:46:22 +02:00
m_project -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
}
if ( oilField -> wellPathCollection ) oilField -> wellPathCollection -> addWellPaths ( wellPathFilePaths );
2015-08-12 17:46:22 +02:00
oilField -> wellPathCollection -> updateConnectedEditors ();
2013-10-08 14:28:01 +02:00
}
2017-11-24 10:01:05 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addWellPathFormationsToModel ( QList < QString > wellPathFormationsFilePaths )
{
if ( m_project == nullptr || m_project -> oilFields . size () < 1 ) return ;
RimOilField * oilField = m_project -> activeOilField ();
if ( oilField == nullptr ) return ;
if ( oilField -> wellPathCollection == nullptr )
{
oilField -> wellPathCollection = new RimWellPathCollection ();
m_project -> updateConnectedEditors ();
}
2017-11-27 10:33:41 +01:00
if ( oilField -> wellPathCollection )
{
oilField -> wellPathCollection -> addWellPathFormations ( wellPathFormationsFilePaths );
}
2017-11-24 10:01:05 +01:00
oilField -> wellPathCollection -> updateConnectedEditors ();
}
2015-09-14 16:33:28 +02:00
//--------------------------------------------------------------------------------------------------
/// Add a list of well log file paths (LAS files) to the well path collection
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addWellLogsToModel ( const QList < QString >& wellLogFilePaths )
{
2017-10-20 14:05:42 +02:00
if ( m_project == nullptr || m_project -> oilFields . size () < 1 ) return ;
2015-09-14 16:33:28 +02:00
RimOilField * oilField = m_project -> activeOilField ();
2017-10-20 14:05:42 +02:00
if ( oilField == nullptr ) return ;
2015-09-14 16:33:28 +02:00
2017-10-20 14:05:42 +02:00
if ( oilField -> wellPathCollection == nullptr )
2015-09-14 16:33:28 +02:00
{
oilField -> wellPathCollection = new RimWellPathCollection ();
m_project -> updateConnectedEditors ();
}
2017-10-20 14:05:42 +02:00
RimWellLogFile * wellLogFile = oilField -> wellPathCollection -> addWellLogs ( wellLogFilePaths );
2015-09-14 16:33:28 +02:00
oilField -> wellPathCollection -> updateConnectedEditors ();
2017-10-20 14:05:42 +02:00
RiuMainWindow :: instance () -> selectAsCurrentItem ( wellLogFile );
2015-09-14 16:33:28 +02:00
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: saveProject ()
{
CVF_ASSERT ( m_project . notNull ());
2017-05-11 09:23:13 +02:00
if ( ! caf :: Utils :: fileExists ( m_project -> fileName ()))
2013-10-08 14:28:01 +02: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 18:48:29 +02:00
startPath = m_project -> fileName ();
2013-10-08 14:28:01 +02:00
}
else
{
2016-09-21 09:46:17 +02:00
startPath = app -> lastUsedDialogDirectory ( "BINARY_GRID" );
2015-09-18 18:48:29 +02:00
startPath += "/ResInsightProject.rsp" ;
2013-10-08 14:28:01 +02:00
}
2018-02-18 18:56:43 +01:00
QString fileName = QFileDialog :: getSaveFileName ( nullptr , tr ( "Save File" ), startPath , tr ( "Project Files (*.rsp);;All files(*.*)" ));
2013-10-08 14:28:01 +02:00
if ( fileName . isEmpty ())
{
return false ;
}
// Remember the directory to next time
2016-09-21 09:46:17 +02:00
app -> setLastUsedDialogDirectory ( "BINARY_GRID" , QFileInfo ( fileName ). absolutePath ());
2013-10-08 14:28:01 +02:00
bool bSaveOk = saveProjectAs ( fileName );
setWindowCaptionFromAppState ();
return bSaveOk ;
}
2017-04-20 08:07:47 +02: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 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: saveProjectAs ( const QString & fileName )
{
2018-04-20 10:03:07 +02:00
// Make sure we always store path with forward slash to avoid issues when opening the project file on Linux
m_project -> fileName = RiaFilePathTools :: toInternalSeparator ( fileName );
2015-11-20 10:50:23 +01:00
2017-04-20 11:02:05 +02:00
storeTreeViewState ();
2015-11-20 10:50:23 +01:00
if ( ! m_project -> writeFile ())
{
2018-02-18 18:56:43 +01:00
QMessageBox :: warning ( nullptr , "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 ));
2015-11-20 10:50:23 +01:00
return false ;
}
2013-10-08 14:28:01 +02:00
m_preferences -> lastUsedProjectFileName = fileName ;
2015-10-23 15:46:25 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
2016-10-05 08:23:07 +02:00
m_recentFileActionProvider -> addFileName ( fileName );
2015-11-20 10:50:23 +01:00
2017-04-20 08:07:47 +02:00
caf :: PdmUiModelChangeDetector :: instance () -> reset ();
2013-10-08 14:28:01 +02:00
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-10-04 11:02:56 +02:00
void RiaApplication :: closeProject ()
2013-10-08 14:28:01 +02:00
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
2018-01-12 11:31:01 +01:00
RiaViewRedrawScheduler :: instance () -> clearViewsScheduledForUpdate ();
2015-10-23 14:13:14 +02:00
2013-10-08 14:28:01 +02:00
terminateProcess ();
2015-11-09 19:05:00 +01:00
RiuSelectionManager :: instance () -> deleteAllItems ();
2013-10-08 14:28:01 +02:00
mainWnd -> cleanupGuiBeforeProjectClose ();
2016-06-27 11:07:01 +02:00
if ( m_mainPlotWindow )
{
m_mainPlotWindow -> cleanupGuiBeforeProjectClose ();
}
2016-06-24 15:10:18 +02:00
2013-10-08 14:28:01 +02:00
caf :: EffectGenerator :: clearEffectCache ();
m_project -> close ();
m_commandQueue . clear ();
onProjectOpenedOrClosed ();
2015-10-28 15:30:20 +01:00
// Make sure all project windows are closed down properly before returning
processEvents ();
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: onProjectOpenedOrClosed ()
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
2016-06-24 15:53:04 +02:00
if ( mainWnd )
{
mainWnd -> initializeGuiNewProjectLoaded ();
}
2016-06-27 11:07:01 +02:00
if ( m_mainPlotWindow )
2016-06-24 15:53:04 +02:00
{
2016-06-27 11:07:01 +02:00
m_mainPlotWindow -> initializeGuiNewProjectLoaded ();
2016-06-24 15:53:04 +02:00
}
2013-10-08 14:28:01 +02:00
setWindowCaptionFromAppState ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 09:46:17 +02:00
QString RiaApplication :: currentProjectPath () const
2013-10-08 14:28:01 +02:00
{
2016-09-21 09:46:17 +02:00
QString projectFolder ;
if ( m_project )
{
QString projectFileName = m_project -> fileName ();
2013-10-08 14:28:01 +02:00
2016-09-21 09:46:17 +02:00
if ( ! projectFileName . isEmpty ())
{
QFileInfo fi ( projectFileName );
projectFolder = fi . absolutePath ();
}
}
2013-10-08 14:28:01 +02:00
2016-09-21 09:46:17 +02:00
return projectFolder ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
/// Create an absolute path from a path that is specified relative to the project directory
///
/// If the path specified in \a projectRelativePath is already absolute, no changes will be made
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: createAbsolutePathFromProjectRelativePath ( QString projectRelativePath )
{
// Check if path is already absolute
if ( QDir :: isAbsolutePath ( projectRelativePath ))
{
return projectRelativePath ;
}
2017-02-14 14:59:08 +01:00
QString absolutePath ;
2013-12-04 12:04:42 +01:00
if ( m_project && ! m_project -> fileName (). isEmpty ())
{
2017-02-14 14:59:08 +01:00
absolutePath = QFileInfo ( m_project -> fileName ()). absolutePath ();
2013-12-04 12:04:42 +01:00
}
else
{
2017-02-14 14:59:08 +01:00
absolutePath = this -> lastUsedDialogDirectory ( "BINARY_GRID" );
2013-12-04 12:04:42 +01:00
}
2017-02-14 14:59:08 +01:00
QDir projectDir ( absolutePath );
return projectDir . absoluteFilePath ( projectRelativePath );
2013-12-04 12:04:42 +01:00
}
2015-04-20 09:02:33 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openOdbCaseFromFile ( const QString & fileName )
{
2017-05-11 09:23:13 +02:00
if ( ! caf :: Utils :: fileExists ( fileName )) return false ;
2015-04-20 09:02:33 +02:00
QFileInfo gridFileName ( fileName );
QString caseName = gridFileName . completeBaseName ();
RimGeoMechCase * geoMechCase = new RimGeoMechCase ();
2015-04-25 08:57:34 +02:00
geoMechCase -> setFileName ( fileName );
2015-04-20 09:02:33 +02:00
geoMechCase -> caseUserDescription = caseName ;
2018-02-18 18:56:43 +01:00
RimGeoMechModels * geoMechModelCollection = m_project -> activeOilField () ? m_project -> activeOilField () -> geoMechModels () : nullptr ;
2015-04-20 09:02:33 +02:00
// Create the geoMech model container if it is not there already
2018-02-18 18:56:43 +01:00
if ( geoMechModelCollection == nullptr )
2015-04-20 09:02:33 +02:00
{
geoMechModelCollection = new RimGeoMechModels ();
m_project -> activeOilField () -> geoMechModels = geoMechModelCollection ;
}
geoMechModelCollection -> cases . push_back ( geoMechCase );
RimGeoMechView * riv = geoMechCase -> createAndAddReservoirView ();
2015-05-29 12:14:40 +02:00
caf :: ProgressInfo progress ( 11 , "Loading Case" );
progress . setNextProgressIncrement ( 10 );
2015-04-20 09:02:33 +02:00
2015-04-20 16:56:26 +02:00
riv -> loadDataAndUpdate ();
2015-04-20 09:02:33 +02:00
//if (!riv->cellResult()->hasResult())
//{
2017-08-14 10:47:44 +02:00
// riv->cellResult()->setResultVariable(RiaDefines::undefinedResultName());
2015-04-20 09:02:33 +02:00
//}
2015-05-29 12:14:40 +02:00
progress . incrementProgress ();
progress . setProgressDescription ( "Loading results information" );
2015-04-20 09:02:33 +02:00
2015-08-13 21:28:09 +02:00
m_project -> updateConnectedEditors ();
2015-04-20 09:02:33 +02:00
2015-12-07 10:07:51 +01:00
RiuMainWindow :: instance () -> selectAsCurrentItem ( riv -> cellResult ());
2015-05-29 12:14:40 +02:00
2015-04-20 09:02:33 +02:00
return true ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createMockModel ()
{
2017-08-25 06:51:56 +02:00
RiaImportEclipseCaseTools :: openMockModel ( RiaDefines :: mockModelBasic ());
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createResultsMockModel ()
{
2017-08-25 06:51:56 +02:00
RiaImportEclipseCaseTools :: openMockModel ( RiaDefines :: mockModelBasicWithResults ());
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createLargeResultsMockModel ()
{
2017-08-25 06:51:56 +02:00
RiaImportEclipseCaseTools :: openMockModel ( RiaDefines :: mockModelLargeWithResults ());
2013-10-08 14:28:01 +02:00
}
2013-10-28 10:32:24 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createMockModelCustomized ()
{
2017-08-25 06:51:56 +02:00
RiaImportEclipseCaseTools :: openMockModel ( RiaDefines :: mockModelCustomized ());
2013-10-28 10:32:24 +01:00
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createInputMockModel ()
{
2017-08-25 06:51:56 +02:00
RicImportInputEclipseCaseFeature :: openInputEclipseCaseFromFileNames ( QStringList ( RiaDefines :: mockModelBasicInputCase ()));
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-09 10:11:28 +01:00
const Rim3dView * RiaApplication :: activeReservoirView () const
2013-10-08 14:28:01 +02:00
{
return m_activeReservoirView ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-09 10:11:28 +01:00
Rim3dView * RiaApplication :: activeReservoirView ()
2013-10-08 14:28:01 +02:00
{
return m_activeReservoirView ;
}
2018-01-15 14:52:22 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimGridView * RiaApplication :: activeGridView ()
{
return dynamic_cast < RimGridView *> ( m_activeReservoirView . p ());
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-03-31 15:10:39 +02:00
RimViewWindow * RiaApplication :: activePlotWindow () const
2016-06-28 10:58:22 +02:00
{
2017-03-31 15:10:39 +02:00
RimViewWindow * viewWindow = nullptr ;
2016-06-28 10:58:22 +02:00
2017-03-31 15:10:39 +02: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 10:58:22 +02:00
2017-03-31 15:10:39 +02:00
return viewWindow ;
2017-01-13 13:32:02 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-01-09 10:11:28 +01:00
void RiaApplication :: setActiveReservoirView ( Rim3dView * rv )
2017-01-13 13:32:02 +01:00
{
2017-03-31 15:10:39 +02:00
m_activeReservoirView = rv ;
2018-04-26 20:05:42 +02:00
RiuDockWidgetTools :: instance () -> changeDockWidgetVisibilityBasedOnView ( rv );
2017-01-13 13:32:02 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2013-10-08 14:28:01 +02:00
void RiaApplication :: setUseShaders ( bool enable )
{
m_preferences -> useShaders = enable ;
2015-10-23 15:46:25 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: useShaders () const
{
if ( ! m_preferences -> useShaders ) return false ;
bool isShadersSupported = caf :: Viewer :: isShadersSupported ();
if ( ! isShadersSupported ) return false ;
return true ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaApplication :: RINavigationPolicy RiaApplication :: navigationPolicy () const
{
return m_preferences -> navigationPolicy ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setShowPerformanceInfo ( bool enable )
{
m_preferences -> showHud = enable ;
2015-10-23 15:46:25 +02:00
caf :: PdmSettings :: writeFieldsToApplicationStore ( m_preferences );
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: showPerformanceInfo () const
{
return m_preferences -> showHud ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: parseArguments ()
{
2017-08-29 09:38:41 +02:00
bool result = RiaArgumentParser :: parseArguments ();
if ( ! result )
2013-12-04 12:04:42 +01:00
{
2017-07-26 16:41:17 +02:00
closeAllWindows ();
processEvents ();
}
2017-08-29 09:38:41 +02:00
return result ;
2013-12-04 12:04:42 +01:00
}
2015-10-05 16:09:51 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-12-03 10:33:38 +01:00
int RiaApplication :: launchUnitTests ()
2015-10-05 16:09:51 +02:00
{
2015-12-03 11:38:59 +01:00
#ifdef USE_UNIT_TESTS
2015-10-05 16:09:51 +02:00
cvf :: Assert :: setReportMode ( cvf :: Assert :: CONSOLE );
int argc = QCoreApplication :: argc ();
testing :: InitGoogleTest ( & argc , QCoreApplication :: argv ());
2015-12-03 10:33:38 +01: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 11:38:59 +01:00
#else
return - 1 ;
#endif
2015-10-05 16:09:51 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2015-12-03 10:33:38 +01:00
int RiaApplication :: launchUnitTestsWithConsole ()
2015-10-05 16:09:51 +02: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 15:11:42 +02:00
FILE * consoleFilePointer ;
2015-10-05 16:09:51 +02:00
2016-05-04 15:11:42 +02:00
freopen_s ( & consoleFilePointer , "CONOUT$" , "w" , stdout );
freopen_s ( & consoleFilePointer , "CONOUT$" , "w" , stderr );
2015-10-05 16:09:51 +02: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 10:33:38 +01:00
return launchUnitTests ();
2015-10-05 16:09:51 +02:00
}
2013-12-04 12:04:42 +01:00
2016-06-27 11:07:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: createMainPlotWindow ()
{
2018-02-18 18:56:43 +01:00
CVF_ASSERT ( m_mainPlotWindow == nullptr );
2016-06-27 11:07:01 +02:00
2018-04-27 06:28:08 +02:00
m_mainPlotWindow = new RiuPlotMainWindow ;
2016-06-27 11:07:01 +02:00
2016-06-29 14:15:39 +02:00
m_mainPlotWindow -> setWindowTitle ( "Plots - ResInsight" );
2016-06-27 11:07:01 +02:00
m_mainPlotWindow -> setDefaultWindowSize ();
m_mainPlotWindow -> loadWinGeoAndDockToolBarLayout ();
m_mainPlotWindow -> showWindow ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: deleteMainPlotWindow ()
{
2016-06-29 14:15:39 +02:00
if ( m_mainPlotWindow )
{
m_mainPlotWindow -> deleteLater ();
2018-02-18 18:56:43 +01:00
m_mainPlotWindow = nullptr ;
2016-06-29 14:15:39 +02:00
}
2016-06-27 11:07:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-27 06:28:08 +02:00
RiuPlotMainWindow * RiaApplication :: getOrCreateAndShowMainPlotWindow ()
2016-06-27 11:07:01 +02:00
{
if ( ! m_mainPlotWindow )
{
createMainPlotWindow ();
2017-08-21 13:09:06 +02:00
m_mainPlotWindow -> initializeGuiNewProjectLoaded ();
2016-10-05 10:04:41 +02:00
loadAndUpdatePlotData ();
2016-06-27 11:07:01 +02:00
}
2016-11-24 14:47:20 +01:00
if ( m_mainPlotWindow -> isMinimized ())
{
m_mainPlotWindow -> showNormal ();
m_mainPlotWindow -> update ();
}
else
{
m_mainPlotWindow -> show ();
}
2016-10-04 09:29:45 +02:00
m_mainPlotWindow -> raise ();
2016-06-27 14:00:19 +02:00
2016-06-27 11:07:01 +02:00
return m_mainPlotWindow ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2018-04-27 06:28:08 +02:00
RiuPlotMainWindow * RiaApplication :: mainPlotWindow ()
2016-06-27 11:07:01 +02:00
{
return m_mainPlotWindow ;
}
2016-08-31 17:34:31 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2017-01-17 13:06:57 +01: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 17:34:31 +02:00
RimViewWindow * RiaApplication :: activeViewWindow ()
{
2018-02-18 18:56:43 +01:00
RimViewWindow * viewWindow = nullptr ;
2016-08-31 17:34:31 +02:00
2017-03-31 15:10:39 +02:00
QWidget * mainWindowWidget = RiaApplication :: activeWindow ();
2016-08-31 17:34:31 +02:00
2017-03-31 15:10:39 +02:00
if ( dynamic_cast < RiuMainWindow *> ( mainWindowWidget ))
2016-08-31 17:34:31 +02:00
{
viewWindow = RiaApplication :: instance () -> activeReservoirView ();
}
2018-04-27 06:28:08 +02:00
else if ( dynamic_cast < RiuPlotMainWindow *> ( mainWindowWidget ))
2016-08-31 17:34:31 +02:00
{
2018-04-27 06:28:08 +02:00
RiuPlotMainWindow * mainPlotWindow = dynamic_cast < RiuPlotMainWindow *> ( mainWindowWidget );
2017-03-31 15:10:39 +02:00
2016-08-31 17:34:31 +02:00
QList < QMdiSubWindow *> subwindows = mainPlotWindow -> subWindowList ( QMdiArea :: StackingOrder );
if ( subwindows . size () > 0 )
{
2017-03-31 15:10:39 +02:00
viewWindow = RiuInterfaceToViewWindow :: viewWindowFromWidget ( subwindows . back () -> widget ());
2016-08-31 17:34:31 +02:00
}
}
return viewWindow ;
}
2017-04-25 15:01:31 +02: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 09:29:45 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: tryCloseMainWindow ()
{
RiuMainWindow * mainWindow = RiuMainWindow :: instance ();
if ( mainWindow && ! mainWindow -> isVisible ())
{
mainWindow -> close ();
return true ;
}
return false ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: tryClosePlotWindow ()
{
2016-10-04 13:14:39 +02:00
if ( ! m_mainPlotWindow )
{
return true ;
}
2016-10-04 09:29:45 +02:00
if ( m_mainPlotWindow && ! m_mainPlotWindow -> isVisible ())
{
m_mainPlotWindow -> close ();
return true ;
}
return false ;
}
2016-10-05 08:23:07 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: addToRecentFiles ( const QString & fileName )
{
m_recentFileActionProvider -> addFileName ( fileName );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std :: vector < QAction *> RiaApplication :: recentFileActions () const
{
return m_recentFileActionProvider -> actions ();
}
2017-07-26 16:57:43 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setStartDir ( const QString & startDir )
{
m_startupDefaultDirectory = startDir ;
}
2013-12-04 12:04:42 +01: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 ;
}
2018-03-08 10:10:15 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: waitUntilCommandObjectsHasBeenProcessed ()
{
2018-03-12 11:12:39 +01:00
// Wait until all command objects have completed
while ( ! m_commandQueueLock . tryLock ())
{
processEvents ();
}
m_commandQueueLock . unlock ();
2018-03-08 10:10:15 +01:00
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: scriptDirectories () const
{
return m_preferences -> scriptDirectories ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: scriptEditorPath () const
{
return m_preferences -> scriptEditorExecutable ();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaApplication :: octavePath () const
{
return m_preferences -> octaveExecutable ();
}
2014-07-22 12:11:48 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QStringList RiaApplication :: octaveArguments () const
{
// http://www.gnu.org/software/octave/doc/interpreter/Command-Line-Options.html#Command-Line-Options
// -p path
// Add path to the head of the search path for function files. The value of path specified on the command line
// will override any value of OCTAVE_PATH found in the environment, but not any commands in the system or
// user startup files that set the internal load path through one of the path functions.
QStringList arguments ;
arguments . append ( "--path" );
arguments << QApplication :: applicationDirPath ();
if ( ! m_preferences -> octaveShowHeaderInfoWhenExecutingScripts )
{
// -q
// Don't print the usual greeting and version message at startup.
arguments . append ( "-q" );
}
return arguments ;
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: slotWorkerProcessFinished ( int exitCode , QProcess :: ExitStatus exitStatus )
{
RiuMainWindow :: instance () -> processMonitor () -> stopMonitorWorkProcess ();
// Execute delete later so that other slots that are hooked up
// get a chance to run before we delete the object
if ( m_workerProcess )
{
m_workerProcess -> close ();
}
2018-02-18 18:56:43 +01:00
m_workerProcess = nullptr ;
2013-10-08 14:28:01 +02:00
// 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 11:10:22 +02:00
m_runningWorkerProcess = false ;
2013-10-08 14:28:01 +02: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 11:10:22 +02:00
m_runningWorkerProcess = false ;
2013-10-08 14:28:01 +02:00
return ;
}
// If multiple cases are present, invoke launchProcess() which will set next current case, and run script on this case
2015-11-27 16:37:26 +01:00
if ( ! m_currentCaseIds . empty ())
2013-10-08 14:28:01 +02:00
{
launchProcess ( m_currentProgram , m_currentArguments );
}
else
{
// Disable concept of current case
m_socketServer -> setCurrentCaseId ( - 1 );
2017-07-31 11:10:22 +02:00
m_runningWorkerProcess = false ;
2013-10-08 14:28:01 +02:00
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: launchProcess ( const QString & program , const QStringList & arguments )
{
2018-02-18 18:56:43 +01:00
if ( m_workerProcess == nullptr )
2013-10-08 14:28:01 +02:00
{
// If multiple cases are present, pop the first case ID from the list and set as current case
2015-11-27 16:37:26 +01:00
if ( ! m_currentCaseIds . empty ())
2013-10-08 14:28:01 +02: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 11:10:22 +02:00
m_runningWorkerProcess = true ;
2013-10-08 14:28:01 +02:00
m_workerProcess = new caf :: UiProcess ( this );
QProcessEnvironment penv = QProcessEnvironment :: systemEnvironment ();
2014-01-02 14:31:10 +01:00
#ifdef WIN32
// Octave plugins compiled by ResInsight are dependent on Qt (currently Qt 32-bit only)
// Some Octave installations for Windows have included Qt, and some don't. To make sure these plugins always can be executed,
// the path to octave_plugin_dependencies is added to global path
QString pathString = penv . value ( "PATH" , "" );
if ( pathString == "" ) pathString = QApplication :: applicationDirPath () + " \\ octave_plugin_dependencies" ;
else pathString = QApplication :: applicationDirPath () + " \\ octave_plugin_dependencies" + ";" + pathString ;
penv . insert ( "PATH" , pathString );
#else
// Set the LD_LIBRARY_PATH to make the octave plugins find the embedded Qt
QString ldPath = penv . value ( "LD_LIBRARY_PATH" , "" );
if ( ldPath == "" ) ldPath = QApplication :: applicationDirPath ();
else ldPath = QApplication :: applicationDirPath () + ":" + ldPath ;
penv . insert ( "LD_LIBRARY_PATH" , ldPath );
#endif
2013-10-08 14:28:01 +02:00
m_workerProcess -> setProcessEnvironment ( penv );
connect ( m_workerProcess , SIGNAL ( finished ( int , QProcess :: ExitStatus )), SLOT ( slotWorkerProcessFinished ( int , QProcess :: ExitStatus )));
RiuMainWindow :: instance () -> processMonitor () -> startMonitorWorkProcess ( m_workerProcess );
m_workerProcess -> start ( program , arguments );
if ( ! m_workerProcess -> waitForStarted ( 1000 ))
{
m_workerProcess -> close ();
2018-02-18 18:56:43 +01:00
m_workerProcess = nullptr ;
2017-07-31 11:10:22 +02:00
m_runningWorkerProcess = false ;
2013-10-08 14:28:01 +02: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
{
2018-02-18 18:56:43 +01:00
QMessageBox :: warning ( nullptr , "Script execution" , "An Octave process is still running. Please stop this process before executing a new script." );
2013-10-08 14:28:01 +02:00
return false ;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: launchProcessForMultipleCases ( const QString & program , const QStringList & arguments , const std :: vector < int >& caseIds )
{
m_currentCaseIds . clear ();
std :: copy ( caseIds . begin (), caseIds . end (), std :: back_inserter ( m_currentCaseIds ) );
m_currentProgram = program ;
m_currentArguments = arguments ;
return launchProcess ( m_currentProgram , m_currentArguments );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaPreferences * RiaApplication :: preferences ()
{
return m_preferences ;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: applyPreferences ()
{
if ( m_activeReservoirView && m_activeReservoirView -> viewer ())
{
2015-07-02 12:44:57 +02:00
m_activeReservoirView -> viewer () -> updateNavigationPolicy ();
2013-10-08 14:28:01 +02:00
m_activeReservoirView -> viewer () -> enablePerfInfoHud ( m_preferences -> showHud ());
}
if ( useShaders ())
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: SHADER_BASED );
}
else
{
caf :: EffectGenerator :: setRenderingMode ( caf :: EffectGenerator :: FIXED_FUNCTION );
}
2015-09-18 19:24:02 +02:00
if ( RiuMainWindow :: instance () && RiuMainWindow :: instance () -> projectTreeView ())
{
RiuMainWindow :: instance () -> projectTreeView () -> enableAppendOfClassNameToUiItemText ( m_preferences -> appendClassNameToUiText ());
2017-01-19 17:35:47 +01:00
if ( mainPlotWindow ()) mainPlotWindow () -> projectTreeView () -> enableAppendOfClassNameToUiItemText ( m_preferences -> appendClassNameToUiText ());
2015-09-18 19:24:02 +02:00
}
2016-08-09 13:09:08 +02: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 14:28:01 +02:00
if ( this -> project ())
{
this -> project () -> setScriptDirectories ( m_preferences -> scriptDirectories ());
2015-09-18 19:24:02 +02:00
this -> project () -> updateConnectedEditors ();
2016-08-09 13:09:08 +02:00
2018-01-09 10:11:28 +01:00
std :: vector < Rim3dView *> visibleViews ;
2016-08-09 13:09:08 +02:00
this -> project () -> allVisibleViews ( visibleViews );
for ( auto view : visibleViews )
{
RimEclipseView * eclipseView = dynamic_cast < RimEclipseView *> ( view );
if ( eclipseView )
{
eclipseView -> scheduleReservoirGridGeometryRegen ();
}
view -> scheduleCreateDisplayModelAndRedraw ();
}
2013-10-08 14:28:01 +02:00
}
2017-11-08 11:29:35 +01:00
caf :: PdmUiItem :: enableExtraDebugText ( m_preferences -> appendFieldKeywordToToolTipText ());
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: terminateProcess ()
{
if ( m_workerProcess )
{
m_workerProcess -> close ();
}
2017-07-31 11:10:22 +02:00
m_runningWorkerProcess = false ;
2018-02-18 18:56:43 +01:00
m_workerProcess = nullptr ;
2013-10-08 14:28:01 +02:00
}
2017-07-31 11:10:22 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: waitForProcess () const
{
while ( m_runningWorkerProcess )
{
2017-07-31 11:26:21 +02:00
#ifdef WIN32
2017-07-31 11:10:22 +02:00
Sleep ( 100 );
2017-07-31 11:26:21 +02:00
#else
usleep ( 100000 );
#endif
2017-08-03 11:31:12 +02:00
processEvents ();
2017-07-31 11:10:22 +02:00
}
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 09:46:17 +02:00
QString RiaApplication :: lastUsedDialogDirectory ( const QString & dialogName )
2013-10-08 14:28:01 +02:00
{
2016-09-21 09:46:17 +02: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 14:28:01 +02:00
{
2016-09-21 09:46:17 +02:00
lastUsedDirectory = it -> second ;
2013-10-08 14:28:01 +02:00
}
2016-09-21 09:46:17 +02:00
return lastUsedDirectory ;
2013-10-08 14:28:01 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2016-09-21 09:46:17 +02:00
void RiaApplication :: setLastUsedDialogDirectory ( const QString & dialogName , const QString & directory )
2013-10-08 14:28:01 +02:00
{
2016-09-21 09:46:17 +02:00
m_fileDialogDefaultDirectories [ dialogName ] = directory ;
2013-10-08 14:28:01 +02:00
}
2013-12-04 12:04:42 +01:00
2016-10-05 10:42:08 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaApplication :: openFile ( const QString & fileName )
{
2017-05-11 09:23:13 +02:00
if ( ! caf :: Utils :: fileExists ( fileName )) return false ;
2016-11-24 10:51:20 +01:00
2016-10-05 10:42:08 +02:00
bool loadingSucceded = false ;
2017-04-20 08:07:47 +02:00
if ( RiaApplication :: hasValidProjectFileExtension ( fileName ))
2016-10-05 10:42:08 +02:00
{
loadingSucceded = loadProject ( fileName );
}
else if ( fileName . contains ( ".egrid" , Qt :: CaseInsensitive ) || fileName . contains ( ".grid" , Qt :: CaseInsensitive ))
{
2018-04-13 13:17:44 +02:00
loadingSucceded = RiaImportEclipseCaseTools :: openEclipseCasesFromFile ( QStringList ({ fileName }));
2016-10-05 10:42:08 +02:00
}
2016-11-28 07:25:04 +01:00
else if ( fileName . contains ( ".grdecl" , Qt :: CaseInsensitive ))
{
2017-08-25 06:51:56 +02:00
loadingSucceded = RicImportInputEclipseCaseFeature :: openInputEclipseCaseFromFileNames ( QStringList ( fileName ));
2016-11-28 07:25:04 +01:00
}
2016-10-05 10:42:08 +02:00
else if ( fileName . contains ( ".odb" , Qt :: CaseInsensitive ))
{
loadingSucceded = openOdbCaseFromFile ( fileName );
}
2016-10-06 10:33:57 +02:00
else if ( fileName . contains ( ".smspec" , Qt :: CaseInsensitive ))
{
2018-03-20 11:25:54 +01:00
loadingSucceded = RicImportSummaryCasesFeature :: createAndAddSummaryCasesFromFiles ( QStringList ({ fileName }));
2016-10-06 10:33:57 +02:00
if ( loadingSucceded )
{
getOrCreateAndShowMainPlotWindow ();
2016-10-24 16:01:19 +02:00
std :: vector < RimCase *> cases ;
m_project -> allCases ( cases );
if ( cases . size () == 0 )
{
RiuMainWindow :: instance () -> close ();
}
2016-10-06 10:33:57 +02:00
m_project -> updateConnectedEditors ();
}
}
2016-10-05 10:42:08 +02:00
2017-04-20 08:07:47 +02:00
if ( loadingSucceded && ! RiaApplication :: hasValidProjectFileExtension ( fileName ))
{
caf :: PdmUiModelChangeDetector :: instance () -> setModelChanged ();
}
2016-10-05 10:42:08 +02:00
return loadingSucceded ;
}
2013-12-04 12:04:42 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: runMultiCaseSnapshots ( const QString & templateProjectFileName , std :: vector < QString > gridFileNames , const QString & snapshotFolderName )
{
RiuMainWindow * mainWnd = RiuMainWindow :: instance ();
if ( ! mainWnd ) return ;
mainWnd -> hideAllDockWindows ();
const size_t numGridFiles = gridFileNames . size ();
for ( size_t i = 0 ; i < numGridFiles ; i ++ )
{
QString gridFn = gridFileNames [ i ];
RiaProjectModifier modifier ;
2016-11-25 14:21:40 +01:00
modifier . setReplaceCaseFirstOccurrence ( gridFn );
2013-12-04 12:04:42 +01:00
bool loadOk = loadProject ( templateProjectFileName , PLA_NONE , & modifier );
if ( loadOk )
{
2017-08-04 11:25:17 +02:00
RicSnapshotAllViewsToFileFeature :: exportSnapshotOfAllViewsIntoFolder ( snapshotFolderName );
2013-12-04 12:04:42 +01:00
}
}
mainWnd -> loadWinGeoAndDockToolBarLayout ();
}
2013-10-08 14:28:01 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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 13:09:08 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf :: Font * RiaApplication :: customFont ()
{
CVF_ASSERT ( m_customFont . notNull ());
return m_customFont . p ();
}
2013-10-08 14:28:01 +02: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 10:45:15 +01:00
return m_helpText ;
/*
2013-10-08 14:28:01 +02:00
QString text = QString("\n%1 v. %2\n").arg(RI_APPLICATION_NAME).arg(getVersionStringApp(false));
text += "Copyright Statoil ASA, Ceetron AS 2011, 2012\n\n";
text +=
"\nParameter Description\n"
"-----------------------------------------------------------------\n"
"-last Open last used project\n"
"\n"
"-project <filename> Open project file <filename>\n"
"\n"
2013-10-18 16:23:31 +02:00
"-case <casename> Import Eclipse case <casename>\n"
2013-10-08 14:28:01 +02:00
" (do not include .GRID/.EGRID)\n"
"\n"
"-savesnapshots Save snapshot of all views to 'snapshots' folder in project file folder\n"
" Application closes after snapshots are written to file\n"
"\n"
"-regressiontest <folder> Run a regression test on all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n"
" " + RegTestNames::testProjectName + " files in the sub-folders will be opened and \n"
" snapshots of all the views is written to the sub-sub-folder " + RegTestNames::generatedFolderName + ". \n"
" Then difference images is generated in the sub-sub-folder " + RegTestNames::diffFolderName + " based \n"
" on the images in sub-sub-folder " + RegTestNames::baseFolderName + ".\n"
" The results are presented in " + RegTestNames::reportFileName + " that is\n"
" written in the given folder.\n"
"\n"
"-updateregressiontestbase <folder> For all sub-folders starting with \"" + RegTestNames::testFolderFilter + "\" of the given folder: \n"
" Copy the images in the sub-sub-folder " + RegTestNames::generatedFolderName + " to the sub-sub-folder\n"
" " + RegTestNames::baseFolderName + " after deleting " + RegTestNames::baseFolderName + " completely.\n"
"\n"
"-help, -? Displays help text\n"
"-----------------------------------------------------------------";
return text;
2013-12-19 10:45:15 +01:00
*/
2013-10-08 14:28:01 +02:00
}
2017-06-20 16:15:47 +02:00
2013-10-08 14:28:01 +02: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 16:37:26 +01:00
++ it ;
2013-10-08 14:28:01 +02:00
m_commandQueue . remove ( toBeRemoved );
}
else
{
2015-11-27 16:37:26 +01:00
++ it ;
2013-10-08 14:28:01 +02:00
}
}
2015-11-27 16:37:26 +01:00
if ( ! m_commandQueue . empty ())
2013-10-08 14:28:01 +02: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 ();
}
}
2017-08-29 09:38:41 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaApplication :: setHelpText ( const QString & helpText )
{
m_helpText = helpText ;
}