Added data model for well import wizard

Updated test application
p4#: 22265
This commit is contained in:
Magne Sjaastad 2013-09-02 08:39:29 +02:00
parent f260092d3c
commit bc282106da
17 changed files with 1491 additions and 5 deletions

View File

@ -8,8 +8,11 @@ set( QOBJECT_HEADERS
ssihubDialog.h
httpwindow.h
RiuWellImportWizard.h
)
set( QT_UI_FILES
authenticationdialog.ui
)
@ -23,6 +26,8 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../FileInterface
${CMAKE_CURRENT_SOURCE_DIR}/../../cafProjectDataModel
${CMAKE_CURRENT_SOURCE_DIR}/../../cafUserInterface
)
@ -32,8 +37,18 @@ add_library( ${PROJECT_NAME}
ssihubDialog.cpp
httpwindow.cpp
RimWellPathImport.h
RimWellPathImport.cpp
RimOilRegionEntry.h
RimOilRegionEntry.cpp
RimOilFieldEntry.h
RimOilFieldEntry.cpp
RiuWellImportWizard.h
RiuWellImportWizard.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../FileInterface/RifJsonEncodeDecode.cpp
${MOC_FILES_CPP}
${FORM_FILES_CPP}
${HEADER_FILES}
)

View File

@ -0,0 +1,56 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimOilFieldEntry.h"
CAF_PDM_SOURCE_INIT(RimOilFieldEntry, "RimOilFieldEntry");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimOilFieldEntry::RimOilFieldEntry()
{
CAF_PDM_InitObject("OilFieldEntry", "", "", "");
CAF_PDM_InitFieldNoDefault(&name, "OilFieldName", "OilFieldName", "", "", "");
CAF_PDM_InitFieldNoDefault(&edmId, "EdmId", "EdmId", "", "", "");
CAF_PDM_InitField(&selected, "Selected", true, "Selected", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimOilFieldEntry::userDescriptionField()
{
return &name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimOilFieldEntry::objectToggleField()
{
return &selected;
}

View File

@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
class RimOilFieldEntry : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimOilFieldEntry();
virtual caf::PdmFieldHandle* userDescriptionField();
virtual caf::PdmFieldHandle* objectToggleField();
caf::PdmField<QString> name;
caf::PdmField<QString> edmId;
caf::PdmField<bool> selected;
};

View File

@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimOilRegionEntry.h"
#include "RimOilFieldEntry.h"
CAF_PDM_SOURCE_INIT(RimOilRegionEntry, "RimOilRegionEntry");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimOilRegionEntry::RimOilRegionEntry()
{
CAF_PDM_InitObject("OilRegionEntry", "", "", "");
CAF_PDM_InitFieldNoDefault(&name, "OilRegionEntry", "OilRegionEntry", "", "", "");
CAF_PDM_InitFieldNoDefault(&fields, "Fields", "", "", "", "");
CAF_PDM_InitField(&selected, "Selected", true, "Selected", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimOilRegionEntry::userDescriptionField()
{
return &name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmFieldHandle* RimOilRegionEntry::objectToggleField()
{
return &selected;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimOilRegionEntry::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (&selected == changedField)
{
for (size_t i = 0; i < fields.size(); i++)
{
fields[i]->selected = newValue.toBool();
}
}
// this->updateConnectedEditors();
}

View File

@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "RimOilFieldEntry.h"
class RimOilRegionEntry : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RimOilRegionEntry();
virtual caf::PdmFieldHandle* userDescriptionField();
virtual caf::PdmFieldHandle* objectToggleField();
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
caf::PdmField<QString> name;
caf::PdmField<bool> selected;
caf::PdmPointersField<RimOilFieldEntry*> fields;
};

View File

@ -0,0 +1,115 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RimWellPathImport.h"
namespace caf {
template<>
void caf::AppEnum< RimWellPathImport::UtmFilterEnum >::setUp()
{
addItem(RimWellPathImport::UTM_FILTER_OFF, "UTM_FILTER_OFF", "Off");
addItem(RimWellPathImport::UTM_FILTER_PROJECT, "UTM_FILTER_PROJECT", "Project");
addItem(RimWellPathImport::UTM_FILTER_CUSTOM, "UTM_FILTER_CUSTOM", "Custom");
setDefault(RimWellPathImport::UTM_FILTER_PROJECT);
}
template<>
void caf::AppEnum< RimWellPathImport::WellTypeEnum >::setUp()
{
addItem(RimWellPathImport::WELL_ALL, "WELL_ALL", "All");
addItem(RimWellPathImport::WELL_SURVEY, "WELL_SURVEY", "Survey");
addItem(RimWellPathImport::WELL_PLAN, "WELL_PLAN", "Plan");
setDefault(RimWellPathImport::WELL_ALL);
}
} // End namespace caf
CAF_PDM_SOURCE_INIT(RimWellPathImport, "RimWellPathImport");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathImport::RimWellPathImport()
{
CAF_PDM_InitObject("RimWellPathImport", "", "", "");
caf::AppEnum<RimWellPathImport::WellTypeEnum> defaultWellMode = WELL_ALL;
CAF_PDM_InitField(&wellMode, "WellMode", defaultWellMode, "Well types", "", "", "");
caf::AppEnum<RimWellPathImport::UtmFilterEnum> defaultUtmMode = UTM_FILTER_OFF;
CAF_PDM_InitField(&utmFilterMode, "UtmMode", defaultUtmMode, "Utm filter", "", "", "");
CAF_PDM_InitField(&north, "UtmNorth", 0.0, "North", "", "", "");
CAF_PDM_InitField(&south, "UtmSouth", 0.0, "South", "", "", "");
CAF_PDM_InitField(&east, "UtmEast", 0.0, "East", "", "", "");
CAF_PDM_InitField(&west, "UtmWest", 0.0, "West", "", "", "");
CAF_PDM_InitFieldNoDefault(&regions, "Regions", "", "", "", "");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPathImport::updateRegions(const QStringList& regionStrings, const QStringList& fieldStrings, const QStringList& edmIds)
{
assert(regionStrings.size() == fieldStrings.size() && regionStrings.size() == edmIds.size());
for (int i = 0; i < regionStrings.size(); i++)
{
RimOilRegionEntry* oilRegionEntry = NULL;
bool edmIdFound = false;
for (size_t regionIdx = 0; regionIdx < this->regions.size(); regionIdx++)
{
if (this->regions[regionIdx]->name == regionStrings[i])
{
oilRegionEntry = this->regions[regionIdx];
for (size_t fIdx = 0; fIdx < this->regions[regionIdx]->fields.size(); fIdx++)
{
if (this->regions[regionIdx]->fields[fIdx]->edmId == edmIds[i])
{
edmIdFound = true;
}
}
}
}
if (!edmIdFound)
{
if (!oilRegionEntry)
{
oilRegionEntry = new RimOilRegionEntry;
oilRegionEntry->name = regionStrings[i];
this->regions.push_back(oilRegionEntry);
}
RimOilFieldEntry* oilFieldEntry = new RimOilFieldEntry;
oilFieldEntry->name = fieldStrings[i];
oilFieldEntry->edmId = edmIds[i];
oilRegionEntry->fields.push_back(oilFieldEntry);
}
}
}

View File

@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafPdmObject.h"
#include "cafPdmField.h"
#include "cafAppEnum.h"
#include "RimOilRegionEntry.h"
class RimWellPathImport : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
enum WellTypeEnum
{
WELL_ALL,
WELL_SURVEY,
WELL_PLAN
};
enum UtmFilterEnum
{
UTM_FILTER_OFF,
UTM_FILTER_PROJECT,
UTM_FILTER_CUSTOM
};
public:
RimWellPathImport();
caf::PdmField< caf::AppEnum< WellTypeEnum > > wellMode;
caf::PdmField< caf::AppEnum< UtmFilterEnum > > utmFilterMode;
caf::PdmField<double> north;
caf::PdmField<double> south;
caf::PdmField<double> east;
caf::PdmField<double> west;
caf::PdmPointersField<RimOilRegionEntry*> regions;
void updateRegions(const QStringList& regions, const QStringList& fields, const QStringList& edmIds);
};

View File

@ -0,0 +1,761 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiuWellImportWizard.h"
#include <QObject>
#include <QtGui>
#include <QtNetwork>
/*
#include <QWizard>
#include <QVBoxLayout>
#include <QTreeView>
#include <QLabel>
#include <QFormLayout>
#include <QLineEdit>
#include <QFile>
#include <QUuid>
*/
#include "cafPdmUiPropertyView.h"
#include "RimWellPathImport.h"
#include "cafUiTreeModelPdm.h"
#include "ssihubDialog.h"
#include "RifJsonEncodeDecode.h"
#include "cafPdmUiTreeView.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuWellImportWizard::RiuWellImportWizard(const QString& webServiceAddress, const QString& downloadFolder, RimWellPathImport* wellPathImportObject, QWidget *parent /*= 0*/)
: QWizard(parent)
{
m_wellPathImport = wellPathImportObject;
m_destinationFolder = downloadFolder;
m_webServiceAddress = webServiceAddress;
// m_treeModelPdm = new caf::UiTreeModelPdm(this);
addPage(new IntroPage(webServiceAddress, this));
m_pdmTreeView = new caf::PdmUiTreeView(this);
m_pdmTreeView->showTree(wellPathImportObject);
addPage(new FieldSelectionPage(m_wellPathImport, NULL, m_pdmTreeView, this));
m_statusLabel = new QLabel(tr("Status : idle"));
m_statusLabel->setWordWrap(true);
m_progressDialog = new QProgressDialog(this);
connect(&m_networkAccessManager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
#ifndef QT_NO_OPENSSL
connect(&m_networkAccessManager, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
#endif
connect(m_progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::setWebServiceAddress(const QString& wsAddress)
{
m_webServiceAddress = wsAddress;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::setJsonDestinationFolder(const QString& folder)
{
m_destinationFolder = folder;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::setWellPathImportObject(RimWellPathImport* wellPathImportObject)
{
m_wellPathImport = wellPathImportObject;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuWellImportWizard::jsonFieldsFilePath()
{
return m_destinationFolder + "/fields.json";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiuWellImportWizard::jsonWellsFilePath()
{
return m_destinationFolder + "/wellpaths.json";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::downloadWellPaths()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::downloadFields()
{
QString wellFileName = jsonWellsFilePath();
if (QFile::exists(wellFileName))
{
QFile::remove(wellFileName);
// m_wellPathsModel->clear();
// m_wellPathsModel->setColumnCount(2);
// clear
}
m_wellPathImport->regions.deleteAllChildObjects();
m_wellPathImport->updateConnectedEditors();
QString completeUrlText = m_webServiceAddress + "/resinsight/projects";
QString destinationFileName = jsonFieldsFilePath();
m_currentDownloadState = DOWNLOAD_FIELDS;
issueHttpRequestToFile(completeUrlText, destinationFileName);
return;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::checkDownloadQueueAndIssueRequests()
{
if (m_wellPathRequestQueue.size() > 0)
{
QString link = m_wellPathRequestQueue[0];
m_wellPathRequestQueue.pop_front();
QString completeUrlText = m_webServiceAddress + link;
QUuid guid = QUuid::createUuid();
QString singleWellPathFilePath = m_destinationFolder + QString("/wellpath_%1.json").arg(guid);
m_currentDownloadState = DOWNLOAD_WELL_PATH;
issueHttpRequestToFile(completeUrlText, singleWellPathFilePath);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::issueHttpRequestToFile(QString completeUrlText, QString destinationFileName)
{
setUrl(completeUrlText);
m_file = new QFile(destinationFileName);
if (!m_file->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("HTTP"),
tr("Unable to save the file %1: %2.")
.arg(destinationFileName).arg(m_file->errorString()));
delete m_file;
m_file = 0;
return;
}
m_progressDialog->setWindowTitle(tr("HTTP"));
m_progressDialog->setLabelText(tr("Downloading %1.").arg(destinationFileName));
// schedule the request
m_httpRequestAborted = false;
startRequest(m_url);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::cancelDownload()
{
//m_statusLabel->setText(tr("Download canceled."));
m_httpRequestAborted = true;
m_reply->abort();
refreshButtonStatus();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::httpFinished()
{
if (m_httpRequestAborted) {
if (m_file) {
m_file->close();
m_file->remove();
delete m_file;
m_file = 0;
}
m_reply->deleteLater();
m_progressDialog->hide();
return;
}
if (m_wellPathRequestQueue.size() == 0)
{
m_progressDialog->hide();
}
m_file->flush();
m_file->close();
QVariant redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
if (m_reply->error()) {
m_file->remove();
QMessageBox::information(this, tr("HTTP"),
tr("Download failed: %1.")
.arg(m_reply->errorString()));
} else if (!redirectionTarget.isNull()) {
QUrl newUrl = m_url.resolved(redirectionTarget.toUrl());
if (QMessageBox::question(this, tr("HTTP"),
tr("Redirect to %1 ?").arg(newUrl.toString()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
m_url = newUrl;
m_reply->deleteLater();
m_file->open(QIODevice::WriteOnly);
m_file->resize(0);
startRequest(m_url);
return;
}
} else {
m_statusLabel->setText(tr("Downloaded data to %1.").arg(m_destinationFolder));
}
if (m_currentDownloadState == DOWNLOAD_WELL_PATH)
{
QString singleWellPathFilePath = m_file->fileName();
QFile file(singleWellPathFilePath);
if (file.open(QFile::ReadOnly))
{
QString singleWellPathContent = file.readAll();
// Strip leading and trailing []
if (singleWellPathContent.indexOf('{') > 0)
{
singleWellPathContent = singleWellPathContent.right(singleWellPathContent.size() - singleWellPathContent.indexOf('{'));
}
if (singleWellPathContent[singleWellPathContent.size() - 1] == ']')
{
singleWellPathContent = singleWellPathContent.left(singleWellPathContent.size() - 1);
}
QString wellPathName = getValue("name", singleWellPathContent);
if (!singleWellPathContent.isEmpty() && !wellPathName.isEmpty())
{
// int currentRowCount = m_wellPathsModel->rowCount();
// m_wellPathsModel->setRowCount(m_wellPathsModel->rowCount() + 1);
//
// QModelIndex miName = m_wellPathsModel->index(currentRowCount, 0);
// m_wellPathsModel->setData(miName, wellPathName);
//
// QModelIndex miFileName = m_wellPathsModel->index(currentRowCount, 1);
// m_wellPathsModel->setData(miFileName, singleWellPathFilePath);
// Write out the content without leading/trailing []
file.close();
file.remove(singleWellPathFilePath);
if (file.open(QFile::WriteOnly))
{
QTextStream out(&file);
out << singleWellPathContent;
}
}
}
}
refreshButtonStatus();
m_reply->deleteLater();
m_reply = 0;
delete m_file;
m_file = 0;
if (m_currentDownloadState == DOWNLOAD_WELLS)
{
QStringList survey;
QStringList plans;
getWellPathLinks(&survey, &plans);
m_currentDownloadState = DOWNLOAD_UNDEFINED;
issueDownloadOfWellPaths(survey, plans);
}
else if (m_currentDownloadState == DOWNLOAD_FIELDS)
{
updateFieldsModel();
m_currentDownloadState = DOWNLOAD_UNDEFINED;
}
else
{
checkDownloadQueueAndIssueRequests();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::httpReadyRead()
{
// this slot gets called every time the QNetworkReply has new data.
// We read all of its new data and write it into the file.
// That way we use less RAM than when reading it at the finished()
// signal of the QNetworkReply
if (m_file)
m_file->write(m_reply->readAll());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
if (m_httpRequestAborted)
return;
m_progressDialog->setMaximum(totalBytes);
m_progressDialog->setValue(bytesRead);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::refreshButtonStatus()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::slotAuthenticationRequired(QNetworkReply* networkReply, QAuthenticator* authenticator)
{
/*
QDialog dlg;
Ui::Dialog ui;
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(m_url.host()));
// Did the URL have information? Fill the UI
// This is only relevant if the URL-supplied credentials were wrong
ui.userEdit->setText(m_url.userName());
ui.passwordEdit->setText(m_url.password());
ui.passwordEdit->setEchoMode(QLineEdit::Password);
if (dlg.exec() == QDialog::Accepted) {
authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
}
*/
authenticator->setUser(field("username").toString());
authenticator->setPassword(field("password").toString());
}
#ifndef QT_NO_OPENSSL
void RiuWellImportWizard::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
{
QString errorString;
foreach (const QSslError &error, errors) {
if (!errorString.isEmpty())
errorString += ", ";
errorString += error.errorString();
}
if (QMessageBox::warning(this, tr("HTTP"),
tr("One or more SSL errors has occurred: %1").arg(errorString),
QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
m_reply->ignoreSslErrors();
}
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::setUrl(const QString& httpAddress)
{
// m_urlLineEdit->setText(httpAddress);
m_url = httpAddress;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::startRequest(QUrl url)
{
m_reply = m_networkAccessManager.get(QNetworkRequest(url));
connect(m_reply, SIGNAL(finished()),
this, SLOT(httpFinished()));
connect(m_reply, SIGNAL(readyRead()),
this, SLOT(httpReadyRead()));
connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)),
this, SLOT(updateDataReadProgress(qint64,qint64)));
}
//--------------------------------------------------------------------------------------------------
/// Search for string, and find the associated value inside the next quoted string
// text content : "A" : "B"
// A search for key "A" returns B
//--------------------------------------------------------------------------------------------------
QString RiuWellImportWizard::getValue(const QString& key, const QString& stringContent)
{
QString quotedKey = "\"" + key + "\"";
int pos = stringContent.indexOf(quotedKey);
if (pos >=0)
{
int valueStartPos = stringContent.indexOf("\"", pos + quotedKey.size());
int valueEndPos = stringContent.indexOf("\"", valueStartPos + 1);
if (valueStartPos >= 0 && valueEndPos > valueStartPos)
{
return stringContent.mid(valueStartPos + 1, valueEndPos - valueStartPos - 1);
}
}
return QString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::getWellPathLinks(QStringList* surveyLinks, QStringList* planLinks)
{
QStringList entities;
QString filename = jsonWellsFilePath();
if (QFile::exists(filename))
{
JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(filename);
QMapIterator<QString, QVariant> it(jsonMap);
while (it.hasNext())
{
it.next();
QString key = it.key();
if (key[0].isDigit())
{
QMap<QString, QVariant> slotMap = it.value().toMap();
QMap<QString, QVariant> linkMap = slotMap["links"].toMap();
QString surveyLink = linkMap["survey"].toString();
surveyLinks->push_back(surveyLink);
QString planLink = linkMap["plans"].toString();
planLinks->push_back(planLink);
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::issueDownloadOfWellPaths(const QStringList& surveyLinks, const QStringList& planLinks)
{
m_wellPathRequestQueue.clear();
// if (m_importSurveyCheckBox->isChecked())
{
m_wellPathRequestQueue += surveyLinks;
}
// if (m_importPlansCheckBox->isChecked())
{
m_wellPathRequestQueue += planLinks;
}
checkDownloadQueueAndIssueRequests();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::updateFieldsModel()
{
QString fileName = jsonFieldsFilePath();
if (QFile::exists(fileName))
{
JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);
QStringList regions;
QStringList fields;
QStringList edmIds;
QMapIterator<QString, QVariant> it(jsonMap);
while (it.hasNext())
{
it.next();
QString key = it.key();
if (key[0].isDigit())
{
QMap<QString, QVariant> fieldMap = it.value().toMap();
regions.push_back(fieldMap["region"].toString());
fields.push_back(fieldMap["name"].toString());
edmIds.push_back(fieldMap["edmId"].toString());
}
}
m_wellPathImport->updateRegions(regions, fields, edmIds);
m_wellPathImport->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
IntroPage::IntroPage(const QString& webServiceAddress, QWidget *parent /*= 0*/) : QWizardPage(parent)
{
setTitle("SSIHUB - Login");
QVBoxLayout* layout = new QVBoxLayout;
QLabel* label = new QLabel("Please enter your login information for SSIHUB at : " + webServiceAddress);
layout->addWidget(label);
QFormLayout* formLayout = new QFormLayout;
layout->addLayout(formLayout);
QLineEdit* usernameLineEdit = new QLineEdit("admin", this);
QLineEdit* passwordlLineEdit = new QLineEdit("resinsight", this);
passwordlLineEdit->setEchoMode(QLineEdit::Password);
formLayout->addRow("&Username:", usernameLineEdit);
formLayout->addRow("&Password:", passwordlLineEdit);
setLayout(layout);
// Make variables accessible to other pages in wizard
// Use * at end of field name to indicate mandatory field
registerField("username", usernameLineEdit);
registerField("password", passwordlLineEdit);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
FieldSelectionPage::FieldSelectionPage(RimWellPathImport* wellPathImport, caf::UiTreeModelPdm* treeModelPdm, caf::PdmUiTreeView* pdmUiTreeView, QWidget *parent /*= 0*/)
{
setTitle("Field Selection");
QVBoxLayout* layout = new QVBoxLayout;
setLayout(layout);
QLabel* label = new QLabel("Select fields");
layout->addWidget(label);
layout->addWidget(pdmUiTreeView);
// Property view
caf::PdmUiPropertyView* propertyView = new caf::PdmUiPropertyView(this);
layout->addWidget(propertyView);
propertyView->showProperties(wellPathImport);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void FieldSelectionPage::initializePage()
{
RiuWellImportWizard* wiz = dynamic_cast<RiuWellImportWizard*>(wizard());
wiz->downloadFields();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWizardPage* createFieldSelectionPage(RimWellPathImport* wellPathImport)
{
QWizardPage* page = new QWizardPage;
page->setTitle("Field Selection");
QVBoxLayout* layout = new QVBoxLayout;
page->setLayout(layout);
QLabel* label = new QLabel("Select fields");
layout->addWidget(label);
// Tree view
caf::PdmUiTreeItem* treeItemRoot = caf::UiTreeItemBuilderPdm::buildViewItems(NULL, -1, wellPathImport);
caf::UiTreeModelPdm* treeModelPdm = new caf::UiTreeModelPdm(page);
treeModelPdm->setTreeItemRoot(treeItemRoot);
QTreeView* treeView = new QTreeView(page);
treeView->setModel(treeModelPdm);
layout->addWidget(treeView);
// Property view
caf::PdmUiPropertyView* propertyView = new caf::PdmUiPropertyView(page);
layout->addWidget(propertyView);
propertyView->showProperties(wellPathImport);
return page;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWizardPage* createLoginPage(const QString& webServiceAddress)
{
QWizardPage* page = new QWizardPage;
page->setTitle("SSIHUB - Login");
QVBoxLayout* layout = new QVBoxLayout;
QLabel* label = new QLabel("Please enter your login information for SSIHUB at : " + webServiceAddress);
layout->addWidget(label);
QFormLayout* formLayout = new QFormLayout;
layout->addLayout(formLayout);
QLineEdit* usernameLineEdit = new QLineEdit(page);
QLineEdit* passwordlLineEdit = new QLineEdit(page);
passwordlLineEdit->setEchoMode(QLineEdit::Password);
formLayout->addRow("&Username:", usernameLineEdit);
formLayout->addRow("&Password:", passwordlLineEdit);
page->setLayout(layout);
return page;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QWizardPage* createWellPathSelectionPage()
{
QWizardPage* page = new QWizardPage;
return page;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RuiWellImportWizard::showImportWizard(const QString& webServiceAddress, const QString& jsonDestinationFolder)
{
return;
ssihub::FetchWellPathsDialog fetchWellPaths;
fetchWellPaths.setSsiHubUrl(webServiceAddress);
fetchWellPaths.setDestinationFolder(jsonDestinationFolder);
//fetchWellPaths.setRegion(m_north, m_south, m_east, m_west);
QStringList regions, fields, edmIds;
fetchWellPaths.requestFieldData(regions, fields, edmIds);
RimWellPathImport* wellPathImport = new RimWellPathImport;
wellPathImport->updateRegions(regions, fields, edmIds);
QWizard wizard;
wizard.addPage(createFieldSelectionPage(wellPathImport));
wizard.addPage(createWellPathSelectionPage());
wizard.setField("username", "dymmy");
wizard.setField("password", "dymmy");
wizard.setWindowTitle("ssihub Well Path Import Wizard");
wizard.exec();
}

View File

@ -0,0 +1,159 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
#include <QWizard>
#include <QNetworkAccessManager>
#include <QUrl>
#include <QItemSelection>
class QFile;
class QProgressDialog;
class QLabel;
class RimWellPathImport;
namespace caf
{
class UiTreeModelPdm;
class PdmUiTreeView;
}
class IntroPage : public QWizardPage
{
Q_OBJECT
public:
IntroPage(const QString& webServiceAddress, QWidget *parent = 0);
};
class FieldSelectionPage : public QWizardPage
{
Q_OBJECT
public:
FieldSelectionPage(RimWellPathImport* wellPathImport, caf::UiTreeModelPdm* treeModelPdm, caf::PdmUiTreeView* pdmUiTreeView, QWidget* parent = 0);
virtual void initializePage();
private:
//RimWellPathImport* m_wellPathImportObject;
};
class RiuWellImportWizard : public QWizard
{
Q_OBJECT
public:
enum DownloadState{ DOWNLOAD_FIELDS, DOWNLOAD_WELLS, DOWNLOAD_WELL_PATH, DOWNLOAD_UNDEFINED};
public:
RiuWellImportWizard(const QString& webServiceAddress, const QString& downloadFolder, RimWellPathImport* wellPathImportObject, QWidget *parent = 0);
void setWebServiceAddress(const QString& wsAdress);
void setJsonDestinationFolder(const QString& folder);
void setWellPathImportObject(RimWellPathImport* wellPathImportObject);
private:
void startRequest(QUrl url);
void setUrl(const QString& httpAddress);
QString jsonFieldsFilePath();
QString jsonWellsFilePath();
void updateFieldsModel();
QString getValue(const QString& key, const QString& stringContent);
void getWellPathLinks(QStringList* surveyLinks, QStringList* planLinks);
void issueDownloadOfWellPaths(const QStringList& surveyLinks, const QStringList& planLinks);
public slots:
void downloadWellPaths();
void downloadFields();
void checkDownloadQueueAndIssueRequests();
void issueHttpRequestToFile( QString completeUrlText, QString destinationFileName );
void cancelDownload();
void httpFinished();
void httpReadyRead();
void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
void refreshButtonStatus();
void slotAuthenticationRequired(QNetworkReply* networkReply, QAuthenticator* authenticator);
void slotSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
#ifndef QT_NO_OPENSSL
void sslErrors(QNetworkReply*,const QList<QSslError> &errors);
#endif
private:
QString m_webServiceAddress;
QString m_destinationFolder;
RimWellPathImport* m_wellPathImport;
// caf::UiTreeModelPdm* m_treeModelPdm;
caf::PdmUiTreeView* m_pdmTreeView;
QProgressDialog* m_progressDialog;
QUrl m_url;
QNetworkAccessManager m_networkAccessManager;
QNetworkReply* m_reply;
QFile* m_file;
bool m_httpRequestAborted;
QStringList m_wellPathRequestQueue;
DownloadState m_currentDownloadState;
// To be deleted
QLabel* m_statusLabel;
};
class RuiWellImportWizard
{
public:
static void showImportWizard(const QString& webServiceAddress, const QString& jsonDestinationFolder);
};

View File

@ -553,7 +553,9 @@ void FetchWellPathsDialog::updateFieldsModel()
JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);
QStringList fieldNames;
QStringList regions;
QStringList fields;
QStringList edmIds;
QMapIterator<QString, QVariant> it(jsonMap);
while (it.hasNext())
{
@ -564,11 +566,13 @@ void FetchWellPathsDialog::updateFieldsModel()
{
QMap<QString, QVariant> fieldMap = it.value().toMap();
fieldNames.push_back(fieldMap["name"].toString());
regions.push_back(fieldMap["region"].toString());
fields.push_back(fieldMap["name"].toString());
edmIds.push_back(fieldMap["edmId"].toString());
}
}
m_fieldModel->setStringList(fieldNames);
m_fieldModel->setStringList(fields);
}
}
@ -760,6 +764,41 @@ void FetchWellPathsDialog::checkDownloadQueueAndIssueRequests()
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void FetchWellPathsDialog::requestFieldData(QStringList& regions, QStringList& fields, QStringList& edmIds)
{
downloadFields();
QString fileName = jsonFieldsFilePath();
if (QFile::exists(fileName))
{
JsonReader jsonReader;
QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(fileName);
QStringList regions;
QStringList fields;
QStringList edmIds;
QMapIterator<QString, QVariant> it(jsonMap);
while (it.hasNext())
{
it.next();
QString key = it.key();
if (key[0].isDigit())
{
QMap<QString, QVariant> fieldMap = it.value().toMap();
regions.push_back(fieldMap["region"].toString());
fields.push_back(fieldMap["name"].toString());
edmIds.push_back(fieldMap["edmId"].toString());
}
}
}
}
} // namespace ssihub

View File

@ -65,7 +65,7 @@ public:
protected:
virtual void showEvent(QShowEvent* event);
private:
public:
void startRequest(QUrl url);
void setUrl(const QString& httpAddress);
@ -79,6 +79,12 @@ private:
void getWellPathLinks(QStringList* surveyLinks, QStringList* planLinks);
void issueDownloadOfWellPaths(const QStringList& surveyLinks, const QStringList& planLinks);
void requestFieldData(QStringList& regions, QStringList& fields, QStringList& edmIds);
signals:
void signalFieldsDownloaded();
private slots:
void downloadWellPaths();

View File

@ -21,6 +21,7 @@
#include "ssihubWebServiceInterface.h"
#include <math.h>
#include "RiuWellImportWizard.h"
namespace ssihub {
@ -69,6 +70,8 @@ void Interface::setRegion(int north, int south, int east, int west)
//--------------------------------------------------------------------------------------------------
QStringList Interface::jsonWellPaths()
{
RuiWellImportWizard::showImportWizard(m_webServiceAddress, m_jsonDestinationFolder);
FetchWellPathsDialog fetchWellPaths;
fetchWellPaths.setSsiHubUrl(m_webServiceAddress);
fetchWellPaths.setDestinationFolder(m_jsonDestinationFolder);

View File

@ -12,9 +12,13 @@ find_package( OpenGL )
add_subdirectory(../ssihubInterface "${CMAKE_CURRENT_BINARY_DIR}/ssihubInterface")
add_subdirectory(../../cafProjectDataModel "${CMAKE_CURRENT_BINARY_DIR}/cafProjectDataModel")
add_subdirectory(../../cafUserInterface "${CMAKE_CURRENT_BINARY_DIR}/cafUserInterface")
include_directories(
${ssihubInterface_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../cafProjectDataModel
${CMAKE_CURRENT_SOURCE_DIR}/../../cafUserInterface
)
@ -39,11 +43,17 @@ qt4_add_resources( QRC_FILES_CPP
# add the executable
add_executable ( ${PROJECT_NAME}
main.cpp
TestTools.cpp
TestTools.h
${MOC_FILES_CPP}
${QRC_FILES_CPP}
)
target_link_libraries ( ${PROJECT_NAME}
cafProjectDataModel
cafUserInterface
ssihubInterface
${QT_LIBRARIES}
)

View File

@ -0,0 +1,51 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "TestTools.h"
#include "RimWellPathImport.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPathImport* TestTools::createMockObject()
{
RimWellPathImport* wellPathImport = new RimWellPathImport;
RimOilRegionEntry* regionA = new RimOilRegionEntry;
regionA->name = "Region A";
RimOilFieldEntry* fieldA = new RimOilFieldEntry;
fieldA->name = "test a";
fieldA->edmId = "edm1";
RimOilFieldEntry* fieldB = new RimOilFieldEntry;
fieldB->name = "test b";
fieldB->edmId = "edm b";
regionA->fields.push_back(fieldA);
wellPathImport->regions.push_back(regionA);
RimOilRegionEntry* regionB = new RimOilRegionEntry;
regionB->name = "Region B";
wellPathImport->regions.push_back(regionB);
return wellPathImport;
}

View File

@ -0,0 +1,28 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
class RimWellPathImport;
class TestTools
{
public:
static RimWellPathImport* createMockObject();
};

View File

@ -42,6 +42,12 @@
#include <QDir>
#include "ssihubInterface.h"
#include "TestTools.h"
#include "RiuWellImportWizard.h"
int main(int argc, char *argv[])
{
@ -61,7 +67,7 @@ int main(int argc, char *argv[])
int west = 400000;
wsInterface.setRegion(north, south, east, west);
QStringList jsonWellPathFileNames = wsInterface.jsonWellPaths();
//QStringList jsonWellPathFileNames = wsInterface.jsonWellPaths();
// void setWebServiceAddress(const QString wsAdress);
// void setJsonDestinationFolder(const QString folder);
@ -69,6 +75,11 @@ int main(int argc, char *argv[])
//
// QStringList jsonWellPaths();
RimWellPathImport* wellPathImportObject = TestTools::createMockObject();
RiuWellImportWizard wizard(wsAddress, destinationFolder, wellPathImportObject);
wizard.show();
return app.exec();
}

View File

@ -47,6 +47,11 @@ PdmUiTreeViewEditor::PdmUiTreeViewEditor()
//--------------------------------------------------------------------------------------------------
PdmUiTreeViewEditor::~PdmUiTreeViewEditor()
{
if (m_proxyEditor)
{
delete m_proxyEditor;
m_proxyEditor = NULL;
}
}
//--------------------------------------------------------------------------------------------------