Several refactoring of well import wizard

Keep original copy of RimWellPathImport object as Xml instead of copy
using PdmObjectGroup
Added destructor for cleanup of wizard pages
Simplified info communication between pages
This commit is contained in:
Magne Sjaastad 2015-08-12 18:44:03 +02:00
parent c2fe5f3a16
commit 3c9e1bab5c
3 changed files with 219 additions and 157 deletions

View File

@ -72,6 +72,7 @@
#include "cafSelectionManager.h"
#include "cvfTimer.h"
#include "cafPdmDefaultObjectFactory.h"
//==================================================================================================
@ -1981,32 +1982,24 @@ void RiuMainWindow::slotImportWellPathsFromSSIHub()
wellPathsFolderPath += "_wellpaths";
QDir::root().mkpath(wellPathsFolderPath);
RimWellPathImport* copyOfWellPathImport = NULL;
// Create a copy of the object
// MODTODO: Verify that behaviour is correct
{
caf::PdmObjectGroup objGroup;
objGroup.addObject(app->project()->wellPathImport);
// Keep a copy of the import settings, and restore if cancel is pressed in the import wizard
QString copyOfOriginalObject = xmlObj(app->project()->wellPathImport())->writeObjectToXmlString();
std::vector<caf::PdmPointer<RimWellPathImport> > typedObjects;
objGroup.createCopyByType(&typedObjects, caf::PdmDefaultObjectFactory::instance());
if (typedObjects.size() == 1)
{
copyOfWellPathImport = typedObjects[0];
}
}
RiuWellImportWizard wellImportwizard(app->preferences()->ssihubAddress, wellPathsFolderPath, copyOfWellPathImport, this);
RimWellPathImport* wellPathObjectToBeDeleted = NULL;
RiuWellImportWizard wellImportwizard(app->preferences()->ssihubAddress, wellPathsFolderPath, app->project()->wellPathImport(), this);
// Get password/username from application cache
{
QString ssihubUsername = app->cacheDataObject("ssihub_username").toString();
QString ssihubPassword = app->cacheDataObject("ssihub_password").toString();
#ifdef _DEBUG
// Valid credentials for ssihubfake received in mail from Håkon
ssihubUsername = "admin";
ssihubPassword = "resinsight";
#endif
wellImportwizard.setCredentials(ssihubUsername, ssihubPassword);
}
@ -2019,18 +2012,13 @@ void RiuMainWindow::slotImportWellPathsFromSSIHub()
app->project()->createDisplayModelAndRedrawAllViews();
}
wellPathObjectToBeDeleted = app->project()->wellPathImport;
app->project()->wellPathImport = copyOfWellPathImport;
app->setCacheDataObject("ssihub_username", wellImportwizard.field("username"));
app->setCacheDataObject("ssihub_password", wellImportwizard.field("password"));
}
else
{
wellPathObjectToBeDeleted = copyOfWellPathImport;
xmlObj(app->project()->wellPathImport())->readObjectFromXmlString(copyOfOriginalObject, caf::PdmDefaultObjectFactory::instance());
}
delete wellPathObjectToBeDeleted;
}
//--------------------------------------------------------------------------------------------------

View File

@ -22,6 +22,7 @@
#include "RimWellPathImport.h"
#include "cafPdmDocument.h"
#include "cafPdmObject.h"
#include "cafPdmObjectGroup.h"
#include "cafPdmUiListView.h"
#include "cafPdmUiListViewEditor.h"
@ -66,6 +67,13 @@ RiuWellImportWizard::RiuWellImportWizard(const QString& webServiceAddress, const
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellImportWizard::~RiuWellImportWizard()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -427,38 +435,18 @@ void RiuWellImportWizard::downloadWells()
checkDownloadQueueAndIssueRequests();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::downloadWellPaths()
{
for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++)
{
RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx];
if (oilRegion->selected)
{
for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++)
{
RimOilFieldEntry* oilField = oilRegion->fields[fIdx];
if (oilField->selected)
{
for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++)
{
RimWellPathEntry* wellPathEntry = oilField->wells[wIdx];
if (wellPathEntry->selected && wellPathEntry->isWellPathValid())
{
DownloadEntity urlToFile;
WellSelectionPage* wellSelectionPage = dynamic_cast<WellSelectionPage*>(page(m_wellSelectionPageId));
std::vector<DownloadEntity> downloadEntities;
wellSelectionPage->selectedWellPathEntries(downloadEntities, NULL);
urlToFile.requestUrl = wellPathEntry->requestUrl;
urlToFile.responseFilename = wellPathEntry->wellPathFilePath;
m_wellRequestQueue.push_back(urlToFile);
}
}
}
}
}
for (size_t i = 0; i < downloadEntities.size(); i++)
{
m_wellRequestQueue.push_back(downloadEntities[i]);
}
m_currentDownloadState = DOWNLOAD_WELL_PATH;
@ -543,31 +531,15 @@ QStringList RiuWellImportWizard::absoluteFilePathsToWellPaths() const
{
QStringList filePaths;
for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++)
{
RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx];
if (oilRegion->selected)
{
for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++)
{
RimOilFieldEntry* oilField = oilRegion->fields[fIdx];
if (oilField->selected)
{
for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++)
{
RimWellPathEntry* wellPathEntry = oilField->wells[wIdx];
WellSelectionPage* wellSelectionPage = dynamic_cast<WellSelectionPage*>(page(m_wellSelectionPageId));
std::vector<DownloadEntity> downloadEntities;
wellSelectionPage->selectedWellPathEntries(downloadEntities, NULL);
QString wellStatus;
if (wellPathEntry->selected)
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath))
if (QFile::exists(downloadEntities[i].responseFilename))
{
filePaths += oilField->wells[wIdx]->wellPathFilePath;
}
}
}
}
}
filePaths.push_back(downloadEntities[i].responseFilename);
}
}
@ -708,6 +680,15 @@ void RiuWellImportWizard::setCredentials(const QString& username, const QString&
setField("password", password);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RiuWellImportWizard::wellSelectionPageId()
{
return m_wellSelectionPageId;
}
@ -781,9 +762,9 @@ FieldSelectionPage::FieldSelectionPage(RimWellPathImport* wellPathImport, QWidge
// Property view
caf::PdmUiPropertyView* propertyView = new caf::PdmUiPropertyView(this);
layout->addWidget(propertyView);
propertyView->showProperties(wellPathImport);
m_propertyView = new caf::PdmUiPropertyView(this);
layout->addWidget(m_propertyView);
m_propertyView->showProperties(wellPathImport);
setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
}
@ -797,36 +778,19 @@ void FieldSelectionPage::initializePage()
wiz->downloadFields();
}
//--------------------------------------------------------------------------------------------------
/// Helper class used to define column headers
//--------------------------------------------------------------------------------------------------
class ObjectGroupWithHeaders : public caf::PdmObjectGroup
{
public:
ObjectGroupWithHeaders() : caf::PdmObjectGroup()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
FieldSelectionPage::~FieldSelectionPage()
{
caf::PdmUiTreeViewEditorAttribute* myAttr = dynamic_cast<caf::PdmUiTreeViewEditorAttribute*>(attribute);
if (myAttr)
{
QStringList colHeaders;
colHeaders << "Wells";
myAttr->columnHeaders = colHeaders;
m_propertyView->showProperties(NULL);
}
}
};
@ -849,6 +813,7 @@ WellSelectionPage::WellSelectionPage(RimWellPathImport* wellPathImport, QWidget*
m_wellPathImportObject = wellPathImport;
m_regionsWithVisibleWells = new ObjectGroupWithHeaders;
m_regionsWithVisibleWells->objects.uiCapability()->setUiHidden(true);
}
//--------------------------------------------------------------------------------------------------
@ -888,14 +853,16 @@ void WellSelectionPage::buildWellTreeView()
}
// Delete all temporary pdm object groups
m_regionsWithVisibleWells->deleteObjects();
m_regionsWithVisibleWells->objects.deleteAllChildObjects();
for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++)
{
RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx];
if (oilRegion->selected)
{
caf::PdmObjectGroup* regGroup = new caf::PdmObjectGroup;
caf::PdmGuardedObjects* regGroup = new caf::PdmGuardedObjects;
regGroup->objects.uiCapability()->setUiHidden(true);
regGroup->setUiName(oilRegion->userDescriptionField()->uiCapability()->uiValue().toString());
m_regionsWithVisibleWells->objects.push_back(regGroup);
@ -905,7 +872,9 @@ void WellSelectionPage::buildWellTreeView()
RimOilFieldEntry* oilField = oilRegion->fields[fIdx];
if (oilField->selected)
{
caf::PdmObjectGroup* fieldGroup = new caf::PdmObjectGroup;
caf::PdmGuardedObjects* fieldGroup = new caf::PdmGuardedObjects;
fieldGroup->objects.uiCapability()->setUiHidden(true);
fieldGroup->setUiName(oilField->userDescriptionField()->uiCapability()->uiValue().toString());
regGroup->objects.push_back(fieldGroup);
@ -913,7 +882,14 @@ void WellSelectionPage::buildWellTreeView()
for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++)
{
RimWellPathEntry* wellPathEntry = oilField->wells[wIdx];
fieldGroup->objects.push_back(wellPathEntry);
// Create a copy of the PdmObject, as it is not supported to have multiple parents of any objects
QString objStr = xmlObj(wellPathEntry)->writeObjectToXmlString();
RimWellPathEntry* wellPathCopy = new RimWellPathEntry;
xmlObj(wellPathCopy)->readObjectFromXmlString(objStr, caf::PdmDefaultObjectFactory::instance());
fieldGroup->objects.push_back(wellPathCopy);
}
}
}
@ -931,10 +907,55 @@ void WellSelectionPage::buildWellTreeView()
//--------------------------------------------------------------------------------------------------
WellSelectionPage::~WellSelectionPage()
{
if (m_wellSelectionTreeView)
{
m_wellSelectionTreeView->setPdmItem(NULL);
}
delete m_regionsWithVisibleWells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void WellSelectionPage::selectedWellPathEntries(std::vector<DownloadEntity>& downloadEntities, caf::PdmObjectHandle* objHandle)
{
if (objHandle == NULL)
{
objHandle = m_regionsWithVisibleWells;
}
std::vector<caf::PdmFieldHandle*> childFields;
objHandle->fields(childFields);
for (size_t i = 0; i < childFields.size(); i++)
{
std::vector<caf::PdmObjectHandle*> childObjects;
childFields[i]->childObjects(&childObjects);
for (size_t j = 0; j < childObjects.size(); j++)
{
RimWellPathEntry* wellPathEntry = (dynamic_cast<RimWellPathEntry*>(childObjects[j]));
if (wellPathEntry)
{
if (wellPathEntry->selected && wellPathEntry->isWellPathValid())
{
DownloadEntity urlToFile;
urlToFile.requestUrl = wellPathEntry->requestUrl;
urlToFile.responseFilename = wellPathEntry->wellPathFilePath;
downloadEntities.push_back(urlToFile);
}
}
else
{
selectedWellPathEntries(downloadEntities, childObjects[j]);
}
}
}
}
//--------------------------------------------------------------------------------------------------
@ -961,7 +982,7 @@ WellSummaryPage::WellSummaryPage(RimWellPathImport* wellPathImport, QWidget* par
layout->addWidget(m_listView);
m_listView->hide();
m_objectGroup = new caf::PdmObjectGroup;
m_objectGroup = new caf::PdmGuardedObjects;
setButtonText(QWizard::FinishButton, "Import");
}
@ -987,41 +1008,28 @@ void WellSummaryPage::updateSummaryPage()
size_t wellPathCount = 0;
QString errorString;
for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++)
{
RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx];
if (oilRegion->selected)
{
for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++)
{
RimOilFieldEntry* oilField = oilRegion->fields[fIdx];
if (oilField->selected)
{
QString oilFieldText = QString("\nRegion : %1 - Field : %2").arg(oilRegion->name).arg(oilField->name);
m_textEdit->append(oilFieldText);
RiuWellImportWizard* wiz = dynamic_cast<RiuWellImportWizard*>(wizard());
WellSelectionPage* wellSelectionPage = dynamic_cast<WellSelectionPage*>(wiz->page(wiz->wellSelectionPageId()));
std::vector<DownloadEntity> downloadEntities;
wellSelectionPage->selectedWellPathEntries(downloadEntities, NULL);
for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++)
for (size_t i = 0; i < downloadEntities.size(); i++)
{
RimWellPathEntry* wellPathEntry = oilField->wells[wIdx];
if (wellPathEntry->selected)
{
if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath))
if (QFile::exists(downloadEntities[i].responseFilename))
{
wellPathCount++;
}
else
{
errorString += QString("Failed to get file '%1' from well '%2'\n").arg(oilField->wells[wIdx]->wellPathFilePath).arg(oilField->wells[wIdx]->name);
errorString += QString("Failed to get file '%1' from well '%2'\n").arg(downloadEntities[i].responseFilename).arg(downloadEntities[i].requestUrl);
}
m_objectGroup->objects.push_back(wellPathEntry);
}
}
}
}
}
}
SummaryPageDownloadEntity* sumPageEntity = new SummaryPageDownloadEntity;
sumPageEntity->responseFilename = downloadEntities[i].responseFilename;
sumPageEntity->requestUrl = downloadEntities[i].requestUrl;
m_objectGroup->objects().push_back(sumPageEntity);
}
m_textEdit->setText(QString("Downloaded successfully %1 well paths.\nPlease push 'Import' button to import well paths into ResInsight.\n\n").arg(wellPathCount));
if (!errorString.isEmpty())
@ -1050,3 +1058,33 @@ void WellSummaryPage::slotShowDetails()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void ObjectGroupWithHeaders::defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
{
caf::PdmUiTreeViewEditorAttribute* myAttr = dynamic_cast<caf::PdmUiTreeViewEditorAttribute*>(attribute);
if (myAttr)
{
QStringList colHeaders;
colHeaders << "Wells";
myAttr->columnHeaders = colHeaders;
}
}
CAF_PDM_SOURCE_INIT(SummaryPageDownloadEntity, "SummaryPageDownloadEntity");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
SummaryPageDownloadEntity::SummaryPageDownloadEntity()
{
CAF_PDM_InitObject("SummaryPageDownloadEntity", "", "", "");
CAF_PDM_InitFieldNoDefault(&requestUrl, "RequestUrl", "", "", "", "");
CAF_PDM_InitFieldNoDefault(&responseFilename, "ResponseFilename", "", "", "", "");
}

View File

@ -18,21 +18,26 @@
#pragma once
#include <QString>
#include <QWizard>
#include <QNetworkAccessManager>
#include <QUrl>
#include "cafPdmChildArrayField.h"
#include "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmObjectGroup.h"
#include <QItemSelection>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QString>
#include <QUrl>
#include <QWizard>
class QFile;
class QProgressDialog;
class QLabel;
class QTextEdit;
class RimWellPathImport;
class RimOilFieldEntry;
class RimWellPathEntry;
namespace caf
@ -40,7 +45,8 @@ namespace caf
class UiTreeModelPdm;
class PdmUiTreeView;
class PdmUiListView;
class PdmObjectGroup;
class PdmUiPropertyView;
class PdmGuardedObjects;
}
@ -67,14 +73,50 @@ class FieldSelectionPage : public QWizardPage
public:
FieldSelectionPage(RimWellPathImport* wellPathImport, QWidget* parent = 0);
~FieldSelectionPage();
virtual void initializePage();
private:
caf::PdmUiPropertyView* m_propertyView;
};
class ObjectGroupWithHeaders;
//--------------------------------------------------------------------------------------------------
/// Container class used to define column headers
//--------------------------------------------------------------------------------------------------
class ObjectGroupWithHeaders : public caf::PdmGuardedObjects
{
public:
ObjectGroupWithHeaders() {};
virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute);
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class DownloadEntity
{
public:
QString requestUrl;
QString responseFilename;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class SummaryPageDownloadEntity : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
SummaryPageDownloadEntity();
caf::PdmField<QString> requestUrl;
caf::PdmField<QString> responseFilename;
};
//--------------------------------------------------------------------------------------------------
///
@ -90,6 +132,9 @@ public:
virtual void initializePage();
void buildWellTreeView();
void selectedWellPathEntries(std::vector<DownloadEntity>& downloadEntities, caf::PdmObjectHandle* objHandle);
private:
ObjectGroupWithHeaders* m_regionsWithVisibleWells;
RimWellPathImport* m_wellPathImportObject;
@ -119,20 +164,10 @@ private:
RimWellPathImport* m_wellPathImportObject;
QTextEdit* m_textEdit;
caf::PdmUiListView* m_listView;
caf::PdmObjectGroup*m_objectGroup;
caf::PdmGuardedObjects* m_objectGroup;
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class DownloadEntity
{
public:
QString requestUrl;
QString responseFilename;
};
//--------------------------------------------------------------------------------------------------
///
@ -146,12 +181,12 @@ public:
public:
RiuWellImportWizard(const QString& webServiceAddress, const QString& downloadFolder, RimWellPathImport* wellPathImportObject, QWidget *parent = 0);
~RiuWellImportWizard();
void setCredentials(const QString& username, const QString& password);
QStringList absoluteFilePathsToWellPaths() const;
// Methods used from the wizard pages
caf::PdmObjectGroup* wellCollection();
void resetAuthenticationCount();
public slots:
@ -169,6 +204,7 @@ public slots:
void slotAuthenticationRequired(QNetworkReply* networkReply, QAuthenticator* authenticator);
int wellSelectionPageId();
#ifndef QT_NO_OPENSSL
void sslErrors(QNetworkReply*,const QList<QSslError> &errors);