From 86f5e6017d83c74290683a7518442d53564012bd Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 6 Sep 2013 13:06:39 +0200 Subject: [PATCH] Integrated well import wizard in project file p4#: 22331 --- ApplicationCode/CMakeLists.txt | 1 + .../ProjectDataModel/RimProject.cpp | 4 + ApplicationCode/ProjectDataModel/RimProject.h | 2 + .../UserInterface/RiuMainWindow.cpp | 37 +++++++ .../RiuWellImportWizard.cpp | 96 +++++++++++++------ .../RiuWellImportWizard.h | 8 +- 6 files changed, 118 insertions(+), 30 deletions(-) diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index b62f8ecfcd..cae9ec2048 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -19,6 +19,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/UserInterface ${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel ${CMAKE_CURRENT_SOURCE_DIR}/ReservoirDataModel + ${CMAKE_CURRENT_SOURCE_DIR}/WellPathImportSsihub ${CMAKE_BINARY_DIR}/Generated ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/ApplicationCode/ProjectDataModel/RimProject.cpp b/ApplicationCode/ProjectDataModel/RimProject.cpp index 2d1a26c047..c4691b5449 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.cpp +++ b/ApplicationCode/ProjectDataModel/RimProject.cpp @@ -71,6 +71,10 @@ RimProject::RimProject(void) CAF_PDM_InitFieldNoDefault(&treeViewState, "TreeViewState", "", "", "", ""); treeViewState.setUiHidden(true); + CAF_PDM_InitFieldNoDefault(&wellPathImport, "WellPathImport", "WellPathImport", "", "", ""); + wellPathImport = new RimWellPathImport(); + wellPathImport.setUiHidden(true); + CAF_PDM_InitFieldNoDefault(¤tModelIndexPath, "TreeViewCurrentModelIndexPath", "", "", "", ""); currentModelIndexPath.setUiHidden(true); diff --git a/ApplicationCode/ProjectDataModel/RimProject.h b/ApplicationCode/ProjectDataModel/RimProject.h index ec59db3b98..8b1b1b8735 100644 --- a/ApplicationCode/ProjectDataModel/RimProject.h +++ b/ApplicationCode/ProjectDataModel/RimProject.h @@ -19,6 +19,7 @@ #pragma once #include "cafPdmDocument.h" +#include "RimWellPathImport.h" class RimOilField; class RimCase; @@ -43,6 +44,7 @@ public: caf::PdmPointersField oilFields; caf::PdmField scriptCollection; + caf::PdmField wellPathImport; caf::PdmField treeViewState; caf::PdmField currentModelIndexPath; caf::PdmField nextValidCaseId; // Unique case ID within a project, used to identify a case from Octave scripts diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 8f00ae1c94..c559428325 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -58,6 +58,7 @@ #include "RimCellEdgeResultSlot.h" #include "RimCellRangeFilterCollection.h" #include "Rim3dOverlayInfoConfig.h" +#include "RiuWellImportWizard.h" @@ -1597,6 +1598,42 @@ void RiuMainWindow::selectedCases(std::vector& cases) //-------------------------------------------------------------------------------------------------- void RiuMainWindow::slotImportWellPathsFromSSIHub() { + RiaApplication* app = RiaApplication::instance(); + if (!app->project()) + { + return; + } + + if (!QFile::exists(app->project()->fileName())) + { + return; + } + + QString wellPathsFolderPath; + QString projectFileName = app->project()->fileName(); + QFileInfo fileInfo(projectFileName); + wellPathsFolderPath = fileInfo.canonicalPath(); + QString wellPathFolderName = fileInfo.completeBaseName() + "_wellpaths"; + + QDir projFolder(wellPathsFolderPath); + projFolder.mkdir(wellPathFolderName); + + wellPathsFolderPath += "/" + wellPathFolderName; + + app->project()->wellPathImport; + + + RiuWellImportWizard wellImportwizard(app->preferences()->ssihubAddress, wellPathsFolderPath, app->project()->wellPathImport, this); + if (QDialog::Accepted == wellImportwizard.exec()) + { + QStringList wellPaths = wellImportwizard.absoluteFilePathsToWellPaths(); + if (wellPaths.size() > 0) + { + app->addWellPathsToModel(wellPaths); + app->project()->createDisplayModelAndRedrawAllViews(); + } + } + /* CVF_ASSERT(m_ssihubInterface); diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp index 4b33564b73..9c26a79b80 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.cpp @@ -34,8 +34,6 @@ #include "ssihubDialog.h" #include "RifJsonEncodeDecode.h" -#include "RimWellCollection.h" - //-------------------------------------------------------------------------------------------------- /// @@ -43,7 +41,7 @@ RiuWellImportWizard::RiuWellImportWizard(const QString& webServiceAddress, const QString& downloadFolder, RimWellPathImport* wellPathImportObject, QWidget *parent /*= 0*/) : QWizard(parent) { - m_wellPathImport = wellPathImportObject; + m_wellPathImportObject = wellPathImportObject; m_destinationFolder = downloadFolder; m_webServiceAddress = webServiceAddress; @@ -51,9 +49,9 @@ RiuWellImportWizard::RiuWellImportWizard(const QString& webServiceAddress, const addPage(new AuthenticationPage(webServiceAddress, this)); - addPage(new FieldSelectionPage(m_wellPathImport, this)); - addPage(new WellSelectionPage(m_wellPathImport, this)); - m_wellSummaryPageId = addPage(new WellSummaryPage(m_wellPathImport, this)); + addPage(new FieldSelectionPage(m_wellPathImportObject, this)); + addPage(new WellSelectionPage(m_wellPathImportObject, this)); + m_wellSummaryPageId = addPage(new WellSummaryPage(m_wellPathImportObject, this)); m_statusLabel = new QLabel(tr("Status : idle")); @@ -61,7 +59,7 @@ RiuWellImportWizard::RiuWellImportWizard(const QString& webServiceAddress, const m_progressDialog = new QProgressDialog(this); - m_wellCollection = new RimWellCollection; + m_wellCollection = new caf::PdmObjectGroup; m_firstTimeRequestingAuthentication = true; @@ -98,7 +96,7 @@ void RiuWellImportWizard::setJsonDestinationFolder(const QString& folder) //-------------------------------------------------------------------------------------------------- void RiuWellImportWizard::setWellPathImportObject(RimWellPathImport* wellPathImportObject) { - m_wellPathImport = wellPathImportObject; + m_wellPathImportObject = wellPathImportObject; } //-------------------------------------------------------------------------------------------------- @@ -129,8 +127,8 @@ void RiuWellImportWizard::downloadFields() QFile::remove(wellFileName); } - m_wellPathImport->regions.deleteAllChildObjects(); - m_wellPathImport->updateConnectedEditors(); + m_wellPathImportObject->regions.deleteAllChildObjects(); + m_wellPathImportObject->updateConnectedEditors(); QString completeUrlText = m_webServiceAddress + "/resinsight/projects"; QString destinationFileName = jsonFieldsFilePath(); @@ -562,8 +560,8 @@ void RiuWellImportWizard::updateFieldsModel() } } - m_wellPathImport->updateRegions(regions, fields, edmIds); - m_wellPathImport->updateConnectedEditors(); + m_wellPathImportObject->updateRegions(regions, fields, edmIds); + m_wellPathImportObject->updateConnectedEditors(); } } @@ -572,9 +570,9 @@ void RiuWellImportWizard::updateFieldsModel() //-------------------------------------------------------------------------------------------------- void RiuWellImportWizard::downloadWells() { - for (size_t rIdx = 0; rIdx < m_wellPathImport->regions.size(); rIdx++) + for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++) { - RimOilRegionEntry* oilRegion = m_wellPathImport->regions[rIdx]; + RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx]; if (oilRegion->selected) { for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++) @@ -585,7 +583,7 @@ void RiuWellImportWizard::downloadWells() DownloadEntity urlToFile; QString wellRequest; - if (m_wellPathImport->utmFilterMode == RimWellPathImport::UTM_FILTER_OFF) + if (m_wellPathImportObject->utmFilterMode == RimWellPathImport::UTM_FILTER_OFF) { wellRequest = QString("/resinsight/projects/%1/wells").arg(oilField->edmId); } @@ -593,10 +591,10 @@ void RiuWellImportWizard::downloadWells() { wellRequest = QString("/resinsight/projects/%1/wellsInArea?north=%2&south=%3&east=%4&west=%5&utmZone=32N") .arg(oilField->edmId) - .arg(QString::number(m_wellPathImport->north, 'g', 10)) - .arg(QString::number(m_wellPathImport->south, 'g', 10)) - .arg(QString::number(m_wellPathImport->east, 'g', 10)) - .arg(QString::number(m_wellPathImport->west, 'g', 10)); + .arg(QString::number(m_wellPathImportObject->north, 'g', 10)) + .arg(QString::number(m_wellPathImportObject->south, 'g', 10)) + .arg(QString::number(m_wellPathImportObject->east, 'g', 10)) + .arg(QString::number(m_wellPathImportObject->west, 'g', 10)); } urlToFile.requestUrl = m_webServiceAddress + wellRequest; @@ -620,9 +618,9 @@ void RiuWellImportWizard::downloadWells() //-------------------------------------------------------------------------------------------------- void RiuWellImportWizard::downloadWellPaths() { - for (size_t rIdx = 0; rIdx < m_wellPathImport->regions.size(); rIdx++) + for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++) { - RimOilRegionEntry* oilRegion = m_wellPathImport->regions[rIdx]; + RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx]; if (oilRegion->selected) { for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++) @@ -676,13 +674,13 @@ void RiuWellImportWizard::checkDownloadQueueAndIssueRequests_v2() if (m_currentDownloadState == DOWNLOAD_WELLS) { - m_wellCollection->wells.clear(); + m_wellCollection->objects.clear(); // Update UI with downloaded wells - for (size_t rIdx = 0; rIdx < m_wellPathImport->regions.size(); rIdx++) + for (size_t rIdx = 0; rIdx < m_wellPathImportObject->regions.size(); rIdx++) { - RimOilRegionEntry* oilRegion = m_wellPathImport->regions[rIdx]; + RimOilRegionEntry* oilRegion = m_wellPathImportObject->regions[rIdx]; if (oilRegion->selected) { for (size_t fIdx = 0; fIdx < oilRegion->fields.size(); fIdx++) @@ -694,7 +692,7 @@ void RiuWellImportWizard::checkDownloadQueueAndIssueRequests_v2() for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++) { - m_wellCollection->wells.push_back(oilField->wells[wIdx]); + m_wellCollection->objects.push_back(oilField->wells[wIdx]); } } } @@ -726,7 +724,7 @@ RiuWellImportWizard::~RiuWellImportWizard() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimWellCollection* RiuWellImportWizard::wellCollection() +caf::PdmObjectGroup* RiuWellImportWizard::wellCollection() { return m_wellCollection; } @@ -739,6 +737,41 @@ void RiuWellImportWizard::resetAuthenticationCount() m_firstTimeRequestingAuthentication = true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +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]; + + QString wellStatus; + if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath)) + { + filePaths += oilField->wells[wIdx]->wellPathFilePath; + } + } + } + } + } + } + + return filePaths; +} + @@ -922,7 +955,16 @@ void WellSummaryPage::updateSummaryPage() for (size_t wIdx = 0; wIdx < oilField->wells.size(); wIdx++) { RimWellPathEntry* wellPathEntry = oilField->wells[wIdx]; - QString wellStatus = QString("%1 %2").arg(oilField->wells[wIdx]->name).arg(oilField->wells[wIdx]->wellPathFilePath); + + QString wellStatus; + if (QFile::exists(oilField->wells[wIdx]->wellPathFilePath)) + { + wellStatus = QString("%1 %2").arg(oilField->wells[wIdx]->name).arg(oilField->wells[wIdx]->wellPathFilePath); + } + else + { + wellStatus = QString("Failed to get file %1 from well %2").arg(oilField->wells[wIdx]->wellPathFilePath).arg(oilField->wells[wIdx]->name); + } m_textEdit->append(wellStatus); diff --git a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h index c43566aad9..eeac5ad05e 100644 --- a/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h +++ b/ApplicationCode/WellPathImportSsihub/RiuWellImportWizard.h @@ -121,9 +121,11 @@ public: void setJsonDestinationFolder(const QString& folder); void setWellPathImportObject(RimWellPathImport* wellPathImportObject); + QStringList absoluteFilePathsToWellPaths() const; + // Methods used from the wizard pages - RimWellCollection* wellCollection(); + caf::PdmObjectGroup* wellCollection(); void resetAuthenticationCount(); private: @@ -173,10 +175,10 @@ private: QString m_webServiceAddress; QString m_destinationFolder; - RimWellPathImport* m_wellPathImport; + RimWellPathImport* m_wellPathImportObject; caf::PdmUiTreeView* m_pdmTreeView; - RimWellCollection* m_wellCollection; + caf::PdmObjectGroup* m_wellCollection; QProgressDialog* m_progressDialog;