#4509 Guard access to gui application code in import and well path code to avoid crashes in console mode

This commit is contained in:
Gaute Lindkvist
2019-07-25 15:54:20 +02:00
parent d6d1ebd25d
commit 000ce6db52
8 changed files with 113 additions and 47 deletions

View File

@@ -180,10 +180,7 @@ bool RiaImportEclipseCaseTools::openEclipseCasesFromFile(const QStringList& file
project->activeOilField()->completionTemplateCollection()->setDefaultUnitSystemBasedOnLoadedCases(); project->activeOilField()->completionTemplateCollection()->setDefaultUnitSystemBasedOnLoadedCases();
if (RiaGuiApplication::isRunning()) RiuPlotMainWindowTools::refreshToolbars();
{
RiuPlotMainWindowTools::refreshToolbars();
}
if (openedFilesOut) if (openedFilesOut)
{ {

View File

@@ -18,6 +18,7 @@
#include "RifWellPathFormationReader.h" #include "RifWellPathFormationReader.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h" #include "RiaLogging.h"
#include "Riu3DMainWindowTools.h" #include "Riu3DMainWindowTools.h"
@@ -63,16 +64,22 @@ std::map<QString, cvf::ref<RigWellPathFormations>>
if (wellNames.empty() || formationNames.empty()) if (wellNames.empty() || formationNames.empty())
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), "Import failure", if (RiaGuiApplication::isRunning())
QString("Failed to parse %1 as a well pick file").arg(filePath)); {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), "Import failure",
QString("Failed to parse %1 as a well pick file").arg(filePath));
}
RiaLogging::error(QString("Failed to parse %1 as a well pick file").arg(filePath)); RiaLogging::error(QString("Failed to parse %1 as a well pick file").arg(filePath));
return result; return result;
} }
else if (!(mdIsPresent || tvdIsPresent)) else if (!(mdIsPresent || tvdIsPresent))
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), "Import failure", if (RiaGuiApplication::isRunning())
QString("Failed to parse %1 as a well pick file. Neither MD or TVD is present.").arg(filePath)); {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), "Import failure",
QString("Failed to parse %1 as a well pick file. Neither MD or TVD is present.").arg(filePath));
}
RiaLogging::error(QString("Failed to parse %1 as a well pick file. Neither MD or TVD is present.").arg(filePath)); RiaLogging::error(QString("Failed to parse %1 as a well pick file. Neither MD or TVD is present.").arg(filePath));
return result; return result;

View File

@@ -142,9 +142,13 @@ void RimGeoMechView::onLoadDataAndUpdate()
{ {
QString displayMessage = errorMessage.empty() ? "Could not open the Odb file: \n" + m_geomechCase->caseFileName() : QString::fromStdString(errorMessage); QString displayMessage = errorMessage.empty() ? "Could not open the Odb file: \n" + m_geomechCase->caseFileName() : QString::fromStdString(errorMessage);
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), if (RiaGuiApplication::isRunning())
"File open error", {
displayMessage); QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
displayMessage);
}
RiaLogging::error(displayMessage);
} }
m_geomechCase = nullptr; m_geomechCase = nullptr;

View File

@@ -20,6 +20,9 @@
#include "RimIdenticalGridCaseGroup.h" #include "RimIdenticalGridCaseGroup.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RigActiveCellInfo.h" #include "RigActiveCellInfo.h"
#include "RigCaseCellResultsData.h" #include "RigCaseCellResultsData.h"
#include "RigEclipseCaseData.h" #include "RigEclipseCaseData.h"
@@ -173,11 +176,15 @@ void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo()
RimEclipseCase* mainCase = caseCollection()->reservoirs[0]; RimEclipseCase* mainCase = caseCollection()->reservoirs[0];
if (!mainCase->openReserviorCase()) if (!mainCase->openReserviorCase())
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), QString errorMessage = QString("Could not open the Eclipse Grid file: \n") + mainCase->gridFileName() + "\n" +
"Error when opening project file", "Current working directory is: \n" + QDir::currentPath();
"Could not open the Eclipse Grid file: \n"+ mainCase->gridFileName() + "\n"+
"Current working directory is: \n" + if (RiaGuiApplication::isRunning())
QDir::currentPath()); {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"Error when opening project file", errorMessage);
}
RiaLogging::error(errorMessage);
return; return;
} }

View File

@@ -19,6 +19,9 @@
#include "RimWellLogFile.h" #include "RimWellLogFile.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h"
#include "RiaDateStringParser.h" #include "RiaDateStringParser.h"
#include "RiaFieldHandleTools.h" #include "RiaFieldHandleTools.h"
#include "RiaQDateTimeTools.h" #include "RiaQDateTimeTools.h"
@@ -123,9 +126,13 @@ RimWellLogFile* RimWellLogFile::readWellLogFile(const QString& logFilePath)
displayMessage += errorMessage; displayMessage += errorMessage;
} }
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), if (RiaGuiApplication::isRunning())
"File open error", {
displayMessage); QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
displayMessage);
}
RiaLogging::warning(errorMessage);
delete wellLogFile; delete wellLogFile;
wellLogFile = nullptr; wellLogFile = nullptr;

View File

@@ -22,6 +22,7 @@
#include "RiaApplication.h" #include "RiaApplication.h"
#include "RiaColorTables.h" #include "RiaColorTables.h"
#include "RiaGuiApplication.h"
#include "RiaLogging.h" #include "RiaLogging.h"
#include "RiaPreferences.h" #include "RiaPreferences.h"
#include "RiaWellNameComparer.h" #include "RiaWellNameComparer.h"
@@ -144,9 +145,13 @@ void RimWellPathCollection::loadDataAndUpdate()
QString errorMessage; QString errorMessage;
if ( !fWPath->readWellPathFile(&errorMessage, m_wellPathImporter) ) if ( !fWPath->readWellPathFile(&errorMessage, m_wellPathImporter) )
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), if (RiaGuiApplication::isRunning())
"File open error", {
errorMessage); QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
errorMessage);
}
RiaLogging::warning(errorMessage);
} }
} }
@@ -165,9 +170,13 @@ void RimWellPathCollection::loadDataAndUpdate()
displayMessage += errorMessage; displayMessage += errorMessage;
} }
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), RiaLogging::warning(errorMessage);
"File open error", if (RiaGuiApplication::isRunning())
displayMessage); {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
displayMessage);
}
} }
} }
} }
@@ -373,7 +382,10 @@ void RimWellPathCollection::addWellPathFormations(const QStringList& filePaths)
if (fileReadSuccess) if (fileReadSuccess)
{ {
QMessageBox::information(Riu3DMainWindowTools::mainWindowWidget(), "Well Picks Import", outputMessage); if (RiaGuiApplication::isRunning())
{
QMessageBox::information(Riu3DMainWindowTools::mainWindowWidget(), "Well Picks Import", outputMessage);
}
RiaLogging::info(outputMessage); RiaLogging::info(outputMessage);
} }
@@ -511,9 +523,13 @@ void RimWellPathCollection::readWellPathFormationFiles()
QString errorMessage; QString errorMessage;
if (!wellPaths[wpIdx]->readWellPathFormationsFile(&errorMessage, m_wellPathFormationsImporter)) if (!wellPaths[wpIdx]->readWellPathFormationsFile(&errorMessage, m_wellPathFormationsImporter))
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), if (RiaGuiApplication::isRunning())
"File open error", {
errorMessage); QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
errorMessage);
}
RiaLogging::warning(errorMessage);
} }
progress.setProgressDescription(QString("Reading formation file %1").arg(wpIdx)); progress.setProgressDescription(QString("Reading formation file %1").arg(wpIdx));
@@ -533,9 +549,13 @@ void RimWellPathCollection::reloadAllWellPathFormations()
QString errorMessage; QString errorMessage;
if (!wellPaths[wpIdx]->reloadWellPathFormationsFile(&errorMessage, m_wellPathFormationsImporter)) if (!wellPaths[wpIdx]->reloadWellPathFormationsFile(&errorMessage, m_wellPathFormationsImporter))
{ {
QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(), if (RiaGuiApplication::isRunning())
"File open error", {
errorMessage); QMessageBox::warning(Riu3DMainWindowTools::mainWindowWidget(),
"File open error",
errorMessage);
}
RiaLogging::warning(errorMessage);
} }
progress.setProgressDescription(QString("Reloading formation file %1").arg(wpIdx)); progress.setProgressDescription(QString("Reloading formation file %1").arg(wpIdx));

View File

@@ -33,7 +33,10 @@ QWidget* Riu3DMainWindowTools::mainWindowWidget()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Riu3DMainWindowTools::setActiveViewer(QWidget* subWindow) void Riu3DMainWindowTools::setActiveViewer(QWidget* subWindow)
{ {
RiuMainWindow::instance()->setActiveViewer(subWindow); if (RiuMainWindow::instance())
{
RiuMainWindow::instance()->setActiveViewer(subWindow);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -41,7 +44,10 @@ void Riu3DMainWindowTools::setActiveViewer(QWidget* subWindow)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Riu3DMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expanded /*= true*/) void Riu3DMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expanded /*= true*/)
{ {
RiuMainWindow::instance()->setExpanded(uiItem, expanded); if (RiuMainWindow::instance())
{
RiuMainWindow::instance()->setExpanded(uiItem, expanded);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -49,7 +55,10 @@ void Riu3DMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expand
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void Riu3DMainWindowTools::selectAsCurrentItem(const caf::PdmObject* object, bool allowActiveViewChange /*= true*/) void Riu3DMainWindowTools::selectAsCurrentItem(const caf::PdmObject* object, bool allowActiveViewChange /*= true*/)
{ {
RiuMainWindow::instance()->selectAsCurrentItem(object, allowActiveViewChange); if (RiuMainWindow::instance())
{
RiuMainWindow::instance()->selectAsCurrentItem(object, allowActiveViewChange);
}
} }

View File

@@ -25,7 +25,10 @@
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::showPlotMainWindow() void RiuPlotMainWindowTools::showPlotMainWindow()
{ {
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow(); if (RiaGuiApplication::isRunning())
{
RiaGuiApplication::instance()->getOrCreateAndShowMainPlotWindow();
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -33,9 +36,12 @@ void RiuPlotMainWindowTools::showPlotMainWindow()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::setActiveViewer(QWidget* subWindow) void RiuPlotMainWindowTools::setActiveViewer(QWidget* subWindow)
{ {
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow(); if (RiaGuiApplication::isRunning())
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
if (mpw) mpw->setActiveViewer(subWindow); if (mpw) mpw->setActiveViewer(subWindow);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -43,9 +49,12 @@ void RiuPlotMainWindowTools::setActiveViewer(QWidget* subWindow)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expanded /*= true*/) void RiuPlotMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expanded /*= true*/)
{ {
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow(); if (RiaGuiApplication::isRunning())
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
if (mpw) mpw->setExpanded(uiItem, expanded); if (mpw) mpw->setExpanded(uiItem, expanded);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -53,9 +62,12 @@ void RiuPlotMainWindowTools::setExpanded(const caf::PdmUiItem* uiItem, bool expa
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::selectAsCurrentItem(const caf::PdmObject* object, bool allowActiveViewChange /*= true*/) void RiuPlotMainWindowTools::selectAsCurrentItem(const caf::PdmObject* object, bool allowActiveViewChange /*= true*/)
{ {
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow(); if (RiaGuiApplication::isRunning())
{
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
if (mpw) mpw->selectAsCurrentItem(object, allowActiveViewChange); if (mpw) mpw->selectAsCurrentItem(object, allowActiveViewChange);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -63,12 +75,15 @@ void RiuPlotMainWindowTools::selectAsCurrentItem(const caf::PdmObject* object, b
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuPlotMainWindowTools::refreshToolbars() void RiuPlotMainWindowTools::refreshToolbars()
{ {
RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow(); if (RiaGuiApplication::isRunning())
if (mpw)
{ {
mpw->updateSummaryPlotToolBar(); RiuPlotMainWindow* mpw = RiaGuiApplication::instance()->mainPlotWindow();
mpw->updateWellLogPlotToolBar();
if (mpw)
{
mpw->updateSummaryPlotToolBar();
mpw->updateWellLogPlotToolBar();
}
} }
} }