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

@@ -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++)
WellSelectionPage* wellSelectionPage = dynamic_cast<WellSelectionPage*>(page(m_wellSelectionPageId));
std::vector<DownloadEntity> downloadEntities;
wellSelectionPage->selectedWellPathEntries(downloadEntities, NULL);
for (size_t i = 0; i < downloadEntities.size(); i++)
{
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;
urlToFile.requestUrl = wellPathEntry->requestUrl;
urlToFile.responseFilename = wellPathEntry->wellPathFilePath;
m_wellRequestQueue.push_back(urlToFile);
}
}
}
}
}
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)
{
if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath))
{
filePaths += oilField->wells[wIdx]->wellPathFilePath;
}
}
}
}
}
for (size_t i = 0; i < downloadEntities.size(); i++)
{
if (QFile::exists(downloadEntities[i].responseFilename))
{
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
FieldSelectionPage::~FieldSelectionPage()
{
public:
ObjectGroupWithHeaders() : caf::PdmObjectGroup()
{
m_propertyView->showProperties(NULL);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
virtual void defineObjectEditorAttribute(QString uiConfigName, caf::PdmUiEditorAttribute * attribute)
{
caf::PdmUiTreeViewEditorAttribute* myAttr = dynamic_cast<caf::PdmUiTreeViewEditorAttribute*>(attribute);
if (myAttr)
{
QStringList colHeaders;
colHeaders << "Wells";
myAttr->columnHeaders = colHeaders;
}
}
};
@@ -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++)
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 i = 0; i < downloadEntities.size(); i++)
{
RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx];
if (oilRegion->selected)
if (QFile::exists(downloadEntities[i].responseFilename))
{
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);
for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++)
{
RimWellPathEntry* wellPathEntry = oilField->wells[wIdx];
if (wellPathEntry->selected)
{
if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath))
{
wellPathCount++;
}
else
{
errorString += QString("Failed to get file '%1' from well '%2'\n").arg(oilField->wells[wIdx]->wellPathFilePath).arg(oilField->wells[wIdx]->name);
}
m_objectGroup->objects.push_back(wellPathEntry);
}
}
}
}
wellPathCount++;
}
else
{
errorString += QString("Failed to get file '%1' from well '%2'\n").arg(downloadEntities[i].responseFilename).arg(downloadEntities[i].requestUrl);
}
}
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", "", "", "", "");
}