From 3c9e1bab5c2f60992afae486dd0ca2f4e480bc3d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 12 Aug 2015 18:44:03 +0200 Subject: [PATCH] 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 --- .../UserInterface/RiuMainWindow.cpp | 36 +-- .../RiuWellImportWizard.cpp | 266 ++++++++++-------- .../RiuWellImportWizard.h | 74 +++-- 3 files changed, 219 insertions(+), 157 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index d266fdd4a7..623d1438bc 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -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 > 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; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp index 4d10cf0d38..bf02032490 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp @@ -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(page(m_wellSelectionPageId)); + std::vector 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(page(m_wellSelectionPageId)); + std::vector 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(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& downloadEntities, caf::PdmObjectHandle* objHandle) +{ + if (objHandle == NULL) + { + objHandle = m_regionsWithVisibleWells; + } + + std::vector childFields; + objHandle->fields(childFields); + for (size_t i = 0; i < childFields.size(); i++) + { + std::vector childObjects; + childFields[i]->childObjects(&childObjects); + + for (size_t j = 0; j < childObjects.size(); j++) + { + RimWellPathEntry* wellPathEntry = (dynamic_cast(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(wizard()); + WellSelectionPage* wellSelectionPage = dynamic_cast(wiz->page(wiz->wellSelectionPageId())); + std::vector 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(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", "", "", "", ""); + +} diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h index aea5bee92e..4585086a48 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h @@ -18,21 +18,26 @@ #pragma once -#include -#include -#include -#include +#include "cafPdmChildArrayField.h" +#include "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmObjectGroup.h" + #include +#include #include +#include +#include +#include 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 requestUrl; + caf::PdmField responseFilename; +}; //-------------------------------------------------------------------------------------------------- /// @@ -90,6 +132,9 @@ public: virtual void initializePage(); void buildWellTreeView(); + + void selectedWellPathEntries(std::vector& 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 &errors);