//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicWellPathImportCompletionsFileFeature::onActionTriggered(bool isChecked)
{
    RimFishboneWellPathCollection* fishbonesWellPathCollection = RicWellPathImportCompletionsFileFeature::selectedWellPathCollection();
    CVF_ASSERT(fishbonesWellPathCollection);

    // Open dialog box to select well path files
    RiaApplication* app = RiaApplication::instance();
    QString defaultDir = app->lastUsedDialogDirectory("WELLPATH_DIR");
    QStringList wellPathFilePaths = QFileDialog::getOpenFileNames(Riu3DMainWindowTools::mainWindowWidget(), "Import Fishbone Laterals", defaultDir, "Well Path Laterals (*.json *.asc *.asci *.ascii *.dev);;All Files (*.*)");

    if (wellPathFilePaths.size() < 1) return;

    // Remember the path to next time
    app->setLastUsedDialogDirectory("WELLPATH_DIR", QFileInfo(wellPathFilePaths.last()).absolutePath());

    fishbonesWellPathCollection->importCompletionsFromFile(wellPathFilePaths);

    RimWellPathCollection* wellPathCollection;
    fishbonesWellPathCollection->firstAncestorOrThisOfType(wellPathCollection);
    if (wellPathCollection)
    {
        wellPathCollection->updateConnectedEditors();
    }

    if (app->project())
    {
        app->project()->scheduleCreateDisplayModelAndRedrawAllViews();
    }
}
Example #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimCommandIssueFieldChanged::redo()
{
    RiaApplication* app = RiaApplication::instance();
    PdmObject* project = app->project();

    caf::PdmObjectHandle* pdmObject = findObjectByName(project, this->objectName);

    if (pdmObject)
    {
        caf::PdmFieldHandle* fieldHandle = findFieldByKeyword(pdmObject, this->fieldName);

        if (fieldHandle && fieldHandle->uiCapability())
        {
            caf::PdmValueField* valueField = dynamic_cast<caf::PdmValueField*>(fieldHandle);
            CVF_ASSERT(valueField);

            QVariant oldValue = valueField->toQVariant();
            QVariant newValue(this->fieldValueToApply);

            valueField->setFromQVariant(newValue);

            caf::PdmUiFieldHandle* uiFieldHandle = fieldHandle->uiCapability();
            uiFieldHandle->notifyFieldChanged(oldValue, newValue);
        }
    }
}
Example #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicImportEnsembleFeature::onActionTriggered(bool isChecked)
{
    RiaApplication* app   = RiaApplication::instance();
    QStringList fileNames = RicImportSummaryCasesFeature::runRecursiveSummaryCaseFileSearchDialog("Import Ensemble");
    
    if (fileNames.isEmpty()) return;

    QString ensembleName = askForEnsembleName();
    if (ensembleName.isEmpty()) return;

    std::vector<RimSummaryCase*> cases;
    RicImportSummaryCasesFeature::createSummaryCasesFromFiles(fileNames, &cases);

    validateEnsembleCases(cases);

    RicImportSummaryCasesFeature::addSummaryCases(cases);
    RicCreateSummaryCaseCollectionFeature::groupSummaryCases(cases, ensembleName, true);

    RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
    if (mainPlotWindow && !cases.empty())
    {
        mainPlotWindow->selectAsCurrentItem(cases.back());

        mainPlotWindow->updateSummaryPlotToolBar();
    }

    std::vector<RimCase*> allCases;
    app->project()->allCases(allCases);

    if (allCases.size() == 0)
    {
        RiuMainWindow::instance()->close();
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicSnapshotViewToFileFeature::onActionTriggered(bool isChecked)
{
    RiaApplication* app = RiaApplication::instance();
    RimProject* proj = app->project();

    QString startPath;
    if (!proj->fileName().isEmpty())
    {
        QFileInfo fi(proj->fileName());
        startPath = fi.absolutePath();
    }
    else
    {
        startPath = app->lastUsedDialogDirectory("IMAGE_SNAPSHOT");
    }

    startPath += "/image.png";

    QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"), startPath, tr("Image files (*.bmp *.png * *.jpg)"));
    if (fileName.isEmpty())
    {
        return;
    }

    // Remember the directory to next time
    app->setLastUsedDialogDirectory("IMAGE_SNAPSHOT", QFileInfo(fileName).absolutePath());

    RimViewWindow* viewWindow = app->activeViewWindow();
    RicSnapshotViewToFileFeature::saveSnapshotAs(fileName, viewWindow);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCasesFeature::createSummaryCasesFromFiles(const QStringList&            fileNames,
                                                               std::vector<RimSummaryCase*>* newCases,
                                                               bool                          ensembleOrGroup)
{
    RiaApplication*               app  = RiaApplication::instance();
    RimProject*                   proj = app->project();
    RimSummaryCaseMainCollection* sumCaseColl =
        proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;

    if (newCases) newCases->clear();
    if (!sumCaseColl) return false;

    RifSummaryCaseRestartSelector fileSelector;
    fileSelector.setEnsembleOrGroupMode(ensembleOrGroup);
    fileSelector.determineFilesToImportFromSummaryFiles(fileNames);

    std::vector<RifSummaryCaseFileResultInfo> importFileInfos = fileSelector.summaryFileInfos();

    if (!importFileInfos.empty())
    {
        std::vector<RimSummaryCase*> sumCases = sumCaseColl->createSummaryCasesFromFileInfos(importFileInfos, true);
        if (newCases) newCases->insert(newCases->end(), sumCases.begin(), sumCases.end());
    }

    if (fileSelector.foundErrors())
    {
        QString errorMessage = fileSelector.createCombinedErrorMessage();
        RiaLogging::error(errorMessage);
        QMessageBox::warning(nullptr, QString("Problem Importing Summary Case File(s)"), errorMessage);
    }

    return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::createNewPlot(RimSummaryCase* summaryCase)
{
    RiaApplication* app  = RiaApplication::instance();
    RimProject*     proj = app->project();

    RicNewSummaryCurveFeature::createNewPlot(proj->mainPlotCollection->summaryPlotCollection(), summaryCase);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicImportSummaryCasesFeature::createAndAddSummaryCasesFromFiles(const QStringList&            fileNames,
                                                                     std::vector<RimSummaryCase*>* newCases)
{
    RiaApplication* app = RiaApplication::instance();

    std::vector<RimSummaryCase*>  temp;
    std::vector<RimSummaryCase*>* cases = newCases ? newCases : &temp;
    if (createSummaryCasesFromFiles(fileNames, cases))
    {
        addSummaryCases(*cases);
        if (!cases->empty())
        {
            createNewPlot(cases->back());
        }

        RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
        if (mainPlotWindow && !cases->empty())
        {
            mainPlotWindow->selectAsCurrentItem(cases->back());
            mainPlotWindow->updateSummaryPlotToolBar();

            // Close main window if there are no eclipse cases imported
            std::vector<RimCase*> allCases;
            app->project()->allCases(allCases);

            if (allCases.size() == 0)
            {
                RiuMainWindow::instance()->close();
            }
        }
        return true;
    }

    return false;
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicWellPathsImportFileFeature::onActionTriggered(bool isChecked)
{
    // Open dialog box to select well path files
    RiaApplication* app = RiaApplication::instance();
    QString defaultDir = app->defaultFileDialogDirectory("WELLPATH_DIR");
    QStringList wellPathFilePaths = QFileDialog::getOpenFileNames(RiuMainWindow::instance(), "Import Well Paths", defaultDir, "Well Paths (*.json *.asc *.asci *.ascii *.dev);;All Files (*.*)");

    if (wellPathFilePaths.size() < 1) return;

    // Remember the path to next time
    app->setDefaultFileDialogDirectory("WELLPATH_DIR", QFileInfo(wellPathFilePaths.last()).absolutePath());

    app->addWellPathsToModel(wellPathFilePaths);
    if (app->project())
    {
        app->project()->createDisplayModelAndRedrawAllViews();
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicSnapshotAllPlotsToFileFeature::saveAllPlots()
{
    RiaApplication* app = RiaApplication::instance();

    RiuMainPlotWindow* mainPlotWindow = app->mainPlotWindow();
    if (!mainPlotWindow) return;

    RimProject* proj = app->project();
    if (!proj) return;

    // Save images in snapshot catalog relative to project directory
    QString snapshotFolderName = app->createAbsolutePathFromProjectRelativePath("snapshots");

    QDir snapshotPath(snapshotFolderName);
    if (!snapshotPath.exists())
    {
        if (!snapshotPath.mkpath(".")) return;
    }

    const QString absSnapshotPath = snapshotPath.absolutePath();

    // Well log plots
    {
        std::vector<RimWellLogPlot*> wellLogPlots;
        proj->descendantsIncludingThisOfType(wellLogPlots);
        for (RimWellLogPlot* wellLogPlot : wellLogPlots)
        {
            if (wellLogPlot && wellLogPlot->viewWidget())
            {
                QString fileName = wellLogPlot->description();
                fileName.replace(" ", "_");

                QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");

                RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, wellLogPlot);
            }
        }
    }

    // Summary plots
    {
        std::vector<RimSummaryPlot*> summaryPlots;
        proj->descendantsIncludingThisOfType(summaryPlots);
        for (RimSummaryPlot* summaryPlot : summaryPlots)
        {
            if (summaryPlot && summaryPlot->viewWidget())
            {
                QString fileName = summaryPlot->description();
                fileName.replace(" ", "_");

                QString absoluteFileName = caf::Utils::constructFullFileName(absSnapshotPath, fileName, ".png");

                RicSnapshotViewToFileFeature::saveSnapshotAs(absoluteFileName, summaryPlot);
            }
        }
    }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::addSummaryCases(const std::vector<RimSummaryCase*> cases)
{
    RiaApplication*               app  = RiaApplication::instance();
    RimProject*                   proj = app->project();
    RimSummaryCaseMainCollection* sumCaseColl =
        proj->activeOilField() ? proj->activeOilField()->summaryCaseMainCollection() : nullptr;
    sumCaseColl->addCases(cases);

    sumCaseColl->updateAllRequiredEditors();
}
Example #11
0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuPlotMainWindow::customMenuRequested(const QPoint& pos)
{
    QMenu menu;

    RiaApplication* app = RiaApplication::instance();
    app->project()->actionsBasedOnSelection(menu);

    // Qt doc: QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport().
    // Since we might get this signal from different treeViews, we need to map the position accordingly.
    QObject*   senderObj = this->sender();
    QTreeView* treeView  = dynamic_cast<QTreeView*>(senderObj);
    if (treeView)
    {
        QPoint globalPos = treeView->viewport()->mapToGlobal(pos);
        menu.exec(globalPos);
    }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate(RimSummaryCaseCollection* ensemble)
{
    RiaApplication* app  = RiaApplication::instance();
    RimProject*     proj = app->project();

    RimSummaryPlotCollection* summaryPlotCollection = proj->mainPlotCollection->summaryPlotCollection();
    RimSummaryPlot*           plot                  = summaryPlotCollection->createSummaryPlotWithAutoTitle();

    RimEnsembleCurveSet* curveSet = RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet(plot, ensemble);
    plot->loadDataAndUpdate();
    summaryPlotCollection->updateConnectedEditors();

    RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
    if (mainPlotWindow)
    {
        mainPlotWindow->selectAsCurrentItem(curveSet);
        mainPlotWindow->updateSummaryPlotToolBar();
    }
}
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RicImportInputEclipseCaseOpmFeature::onActionTriggered(bool isChecked)
{
    RiaApplication* app = RiaApplication::instance();
    QString defaultDir = app->lastUsedDialogDirectory("INPUT_FILES");
    QString fileName = QFileDialog::getOpenFileName(RiuMainWindow::instance(), "Import Eclipse Input file", defaultDir, "Eclipse Input Files (*.GRDECL);;All Files (*.*)");

    if (fileName.isEmpty()) return;

    // Remember the path to next time
    app->setLastUsedDialogDirectory("INPUT_FILES", QFileInfo(fileName).absolutePath());

    RimProject* proj = app->project();
    RimEclipseCaseCollection* analysisModels = proj->activeOilField() ? proj->activeOilField()->analysisModels() : NULL;
    if (analysisModels)
    {
        // This code originates from RiaApplication::openInputEclipseCaseFromFileNames

        RimEclipseInputCaseOpm* rimInputReservoir = new RimEclipseInputCaseOpm();
        proj->assignCaseIdToCase(rimInputReservoir);

        rimInputReservoir->importNewEclipseGridAndProperties(fileName);

        analysisModels->cases.push_back(rimInputReservoir);

        RimEclipseView* riv = rimInputReservoir->createAndAddReservoirView();

        riv->cellResult()->setResultType(RimDefines::INPUT_PROPERTY);
        riv->hasUserRequestedAnimation = true;

        riv->loadDataAndUpdate();

        if (!riv->cellResult()->hasResult())
        {
            riv->cellResult()->setResultVariable(RimDefines::undefinedResultName());
        }

        analysisModels->updateConnectedEditors();

        RiuMainWindow::instance()->selectAsCurrentItem(riv->cellResult());
    }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicImportSummaryCasesFeature::onActionTriggered(bool isChecked)
{
    RiaApplication* app           = RiaApplication::instance();
    QString         pathCacheName = "INPUT_FILES";
    QStringList     fileNames     = runRecursiveSummaryCaseFileSearchDialog("Import Summary Cases", pathCacheName);

    std::vector<RimSummaryCase*> cases;
    if (!fileNames.isEmpty()) createSummaryCasesFromFiles(fileNames, &cases);

    addSummaryCases(cases);
    if (!cases.empty())
    {
        createNewPlot(cases.front());
    }

    addCasesToGroupIfRelevant(cases);

    for (const auto& rimCase : cases)
        RiaApplication::instance()->addToRecentFiles(rimCase->summaryHeaderFilename());

    RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
    if (mainPlotWindow && !cases.empty())
    {
        mainPlotWindow->selectAsCurrentItem(cases.back());

        mainPlotWindow->updateSummaryPlotToolBar();
    }

    std::vector<RimCase*> allCases;
    app->project()->allCases(allCases);

    if (allCases.size() == 0)
    {
        RiuMainWindow::instance()->close();
    }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateSaturationPressurePlotsFeature::onActionTriggered(bool isChecked)
{
    RimProject* project = RiaApplication::instance()->project();

    RimSaturationPressurePlotCollection* collection = project->mainPlotCollection()->saturationPressurePlotCollection();

    std::vector<RimEclipseResultCase*> eclipseCases;
    {
        RiaApplication*       app = RiaApplication::instance();
        std::vector<RimCase*> cases;
        app->project()->allCases(cases);
        for (auto* rimCase : cases)
        {
            auto erc = dynamic_cast<RimEclipseResultCase*>(rimCase);
            if (erc)
            {
                eclipseCases.push_back(erc);
            }
        }
    }

    RimEclipseResultCase* eclipseResultCase = nullptr;

    if (!eclipseCases.empty())
    {
        if (eclipseCases.size() == 1)
        {
            eclipseResultCase = eclipseCases[0];
        }
        else
        {
            RicSaturationPressureUi saturationPressureUi;
            saturationPressureUi.setSelectedCase(eclipseCases[0]);

            RiuPlotMainWindow* plotwindow = RiaApplication::instance()->mainPlotWindow();

            caf::PdmUiPropertyViewDialog propertyDialog(
                plotwindow, &saturationPressureUi, "Select Case to create Pressure Saturation plots", "");

            if (propertyDialog.exec() == QDialog::Accepted)
            {
                eclipseResultCase = dynamic_cast<RimEclipseResultCase*>(saturationPressureUi.selectedCase());
            }
        }
    }

    caf::PdmObject* objectToSelect = nullptr;

    std::vector<RimSaturationPressurePlot*> plots = createPlots(eclipseResultCase);
    if (plots.empty())
    {
        QString text = "No plots generated.\n\n";
        text += "Data required to generate saturation/pressure plots:\n";
        text += " - EQLNUM property defining at least one region\n";
        text += " - Dynamic properties PRESSURE, PBUB and PDEW\n\n";
        text += "Make sure to add 'PBPD' to the RPTRST keyword in the SOLUTION selection. ";
        text += "If this is a two phase run (Oil/water or Gas/Water) or if both VAPOIL ";
        text += "and DISGAS are disabled, saturation pressure are not valid.";

        QMessageBox::warning(nullptr, "Saturation Pressure Plots", text);

        RiaLogging::warning(text);
    }
    else
    {
        objectToSelect = plots.front();
    }

    collection->updateAllRequiredEditors();
    RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();

    if (objectToSelect)
    {
        RiuPlotMainWindowTools::selectAsCurrentItem(objectToSelect);
    }
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicWellPathExportCompletionDataFeature::prepareExportSettingsAndExportCompletions(
    const QString&                        dialogTitle,
    const std::vector<RimWellPath*>&      wellPaths,
    const std::vector<RimSimWellInView*>& simWells)
{
    RiaApplication* app        = RiaApplication::instance();
    RimProject*     project    = app->project();
    QString         defaultDir = RiaApplication::instance()->lastUsedDialogDirectoryWithFallbackToProjectFolder("COMPLETIONS");

    RicExportCompletionDataSettingsUi* exportSettings = project->dialogData()->exportCompletionData();

    if (wellPaths.empty())
    {
        exportSettings->showForSimWells();
    }
    else
    {
        exportSettings->showForWellPath();
    }

    if (!exportSettings->caseToApply())
    {
        std::vector<RimCase*> cases;
        app->project()->allCases(cases);
        for (auto c : cases)
        {
            RimEclipseCase* eclipseCase = dynamic_cast<RimEclipseCase*>(c);
            if (eclipseCase != nullptr)
            {
                exportSettings->caseToApply = eclipseCase;
                break;
            }
        }
    }

    if (exportSettings->folder().isEmpty()) exportSettings->folder = defaultDir;

    std::vector<RimSimWellFracture*>       simWellFractures;
    std::vector<RimWellPathFracture*>      wellPathFractures;
    std::vector<RimFishbonesMultipleSubs*> wellPathFishbones;
    std::vector<RimPerforationInterval*>   wellPathPerforations;

    for (auto s : simWells)
    {
        s->descendantsIncludingThisOfType(simWellFractures);
    }

    for (auto w : wellPaths)
    {
        w->descendantsIncludingThisOfType(wellPathFractures);
        w->descendantsIncludingThisOfType(wellPathFishbones);
        w->descendantsIncludingThisOfType(wellPathPerforations);
    }

    if ((!simWellFractures.empty()) || (!wellPathFractures.empty()))
    {
        exportSettings->showFractureInUi(true);
    }
    else
    {
        exportSettings->showFractureInUi(false);
    }

    if (!wellPathFishbones.empty())
    {
        exportSettings->showFishbonesInUi(true);
    }
    else
    {
        exportSettings->showFishbonesInUi(false);
    }

    if (!wellPathPerforations.empty())
    {
        exportSettings->showPerforationsInUi(true);

        std::vector<const RimWellPathValve*> perforationValves;
        for (const auto& perf : wellPathPerforations)
        {
            perf->descendantsIncludingThisOfType(perforationValves);
        }

        if (!perforationValves.empty())
        {
            exportSettings->enableIncludeMsw();
        }
    }
    else
    {
        exportSettings->showPerforationsInUi(false);
    }

    caf::PdmUiPropertyViewDialog propertyDialog(Riu3DMainWindowTools::mainWindowWidget(), exportSettings, dialogTitle, "");
    RicExportFeatureImpl::configureForExport(propertyDialog.dialogButtonBox());

    if (propertyDialog.exec() == QDialog::Accepted)
    {
        RiaApplication::instance()->setLastUsedDialogDirectory("COMPLETIONS", exportSettings->folder);

        RicWellPathExportCompletionDataFeatureImpl::exportCompletions(wellPaths, simWells, *exportSettings);
    }
}