Example #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
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();

            // If we have an array, skip to next node
            if (it.key() == "length")
                continue;

            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_wellPathImportObject->updateRegions(regions, fields, edmIds);
        m_wellPathImportObject->updateConnectedEditors();
    }
}
Example #2
0
//--------------------------------------------------------------------------------------------------
/// Read JSON file containing well path data
//--------------------------------------------------------------------------------------------------
void RimWellPath::readJsonWellPathFile()
{
    RigWellPath* wellPathGeom = new RigWellPath();
    JsonReader jsonReader;
    QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(filepath);

    // General well info

    name            = jsonMap["name"].toString();
    id              = jsonMap["id"].toString();
    sourceSystem    = jsonMap["sourceSystem"].toString();
    utmZone         = jsonMap["utmZone"].toString();
    updateUser      = jsonMap["updateUser"].toString();

    setSurveyType(jsonMap["surveyType"].toString());

    // Convert updateDate from the following format:
    // "Number of milliseconds elapsed since midnight Coordinated Universal Time (UTC) 
    // of January 1, 1970, not counting leap seconds"

    QString updateDateStr = jsonMap["updateDate"].toString().trimmed();
    uint updateDateUint = updateDateStr.toULongLong() / 1000; // should be within 32 bit, maximum number is 4294967295 which corresponds to year 2106
    QDateTime updateDateTime;
    updateDateTime.setTime_t(updateDateUint);

    updateDate = updateDateTime.toString("d MMMM yyyy");

    // Well path points

    double datumElevation = jsonMap["datumElevation"].toDouble();

    QList<QVariant> pathList = jsonMap["path"].toList();
    foreach (QVariant point, pathList)
    {
        QMap<QString, QVariant> coordinateMap = point.toMap();
        cvf::Vec3d vec3d(coordinateMap["east"].toDouble(), coordinateMap["north"].toDouble(), -(coordinateMap["tvd"].toDouble() - datumElevation));
        wellPathGeom->m_wellPathPoints.push_back(vec3d);
        
        double measuredDepth = coordinateMap["md"].toDouble();
        wellPathGeom->m_measuredDepths.push_back(measuredDepth);
    }
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RiuWellImportWizard::parseWellsResponse(RimOilFieldEntry* oilFieldEntry)
{
    QStringList surveyNames;
    QStringList planNames;

    if (QFile::exists(oilFieldEntry->wellsFilePath))
    {
        JsonReader jsonReader;
        QMap<QString, QVariant> jsonMap = jsonReader.decodeFile(oilFieldEntry->wellsFilePath);

        QMapIterator<QString, QVariant> it(jsonMap);
        while (it.hasNext())
        {
            it.next();

            // If we have an array, skip to next node
            if (it.key() == "length")
                continue;

            QMap<QString, QVariant> rootMap = it.value().toMap();

            if (m_wellPathImportObject->wellTypeSurvey)
            {
                QMap<QString, QVariant> surveyMap = rootMap["survey"].toMap();
                QString name = surveyMap["name"].toString();

                if (!oilFieldEntry->find(name, RimWellPathEntry::WELL_SURVEY))
                {
                    QMap<QString, QVariant> linksMap = surveyMap["links"].toMap();
                    QString requestUrl = m_webServiceAddress + linksMap["entity"].toString();
                    QString surveyType = surveyMap["surveyType"].toString();
                    RimWellPathEntry* surveyWellPathEntry = RimWellPathEntry::createWellPathEntry(name, surveyType, requestUrl, m_destinationFolder, RimWellPathEntry::WELL_SURVEY);
                    oilFieldEntry->wells.push_back(surveyWellPathEntry);
                }

                surveyNames.push_back(name);
            }

            if (m_wellPathImportObject->wellTypePlans)
            {
                QList<QVariant> plansList = rootMap["plans"].toList();
                QListIterator<QVariant> planIt(plansList);
                while (planIt.hasNext())
                {
                    QMap<QString, QVariant> planMap = planIt.next().toMap();
                    QString name = planMap["name"].toString();

                    if (!oilFieldEntry->find(name, RimWellPathEntry::WELL_PLAN))
                    {
                        QMap<QString, QVariant> linksMap = planMap["links"].toMap();
                        QString requestUrl = m_webServiceAddress + linksMap["entity"].toString();
                        QString surveyType = planMap["surveyType"].toString();
                        RimWellPathEntry* surveyWellPathEntry = RimWellPathEntry::createWellPathEntry(name, surveyType, requestUrl, m_destinationFolder, RimWellPathEntry::WELL_PLAN);
                        oilFieldEntry->wells.push_back(surveyWellPathEntry);
                    }

                    planNames.push_back(name);
                }
            }
        }
    }

    // Delete the well path entries in the model that are not part of the reply from the web service
    std::vector<RimWellPathEntry*> wellsToRemove;

    for (size_t i = 0; i < oilFieldEntry->wells.size(); i++)
    {
        RimWellPathEntry* wellPathEntry = oilFieldEntry->wells[i];
        if (wellPathEntry->wellPathType == RimWellPathEntry::WELL_PLAN)
        {
            if (!planNames.contains(wellPathEntry->name))
            {
                wellsToRemove.push_back(wellPathEntry);
            }
        }
        else
        {
            if (!surveyNames.contains(wellPathEntry->name))
            {
                wellsToRemove.push_back(wellPathEntry);
            }
        }
    }

    for (size_t i = 0; i < wellsToRemove.size(); i++)
    {
        oilFieldEntry->wells.removeChildObject(wellsToRemove[i]);

        delete wellsToRemove[i];
    }

    WellSelectionPage* wellSelectionPage = dynamic_cast<WellSelectionPage*>(page(m_wellSelectionPageId));
    if (wellSelectionPage)
        wellSelectionPage->buildWellTreeView();
}