diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp index 161a2d848b..8b069480ea 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.cpp @@ -20,20 +20,32 @@ #include "RiaApplication.h" +#include "RimEclipseWell.h" #include "RimProject.h" #include "RimWellLogRftCurve.h" #include "RimWellLogTrack.h" +#include "RimWellLogPlot.h" +#include "RimWellLogCurve.h" +#include "RimEclipseResultCase.h" + +#include "RigWellLogCurveData.h" + +#include "RifReaderEclipseRft.h" -#include "RiuSelectionManager.h" #include "RiuMainPlotWindow.h" +#include "RiuSelectionManager.h" +#include "RicWellLogPlotCurveFeatureImpl.h" +#include "RicNewWellLogPlotFeatureImpl.h" #include "cafSelectionManager.h" #include +#include #include + CAF_CMD_SOURCE_INIT(RicNewWellLogRftCurveFeature, "RicNewWellLogRftCurveFeature"); //-------------------------------------------------------------------------------------------------- @@ -41,7 +53,20 @@ CAF_CMD_SOURCE_INIT(RicNewWellLogRftCurveFeature, "RicNewWellLogRftCurveFeature" //-------------------------------------------------------------------------------------------------- bool RicNewWellLogRftCurveFeature::isCommandEnabled() { - return (selectedWellLogPlotTrack() != nullptr); + + if (RicNewWellLogRftCurveFeature::selectedWellLogPlotTrack() != nullptr) + { + return true; + } + + int branchIdx; + RimEclipseWell* simulationWell = RicNewWellLogRftCurveFeature::selectedSimulationWell(&branchIdx); + + if (simulationWell != nullptr) + { + return RicNewWellLogRftCurveFeature::wellHasRftData(simulationWell->name()); + } + return false; } //-------------------------------------------------------------------------------------------------- @@ -50,9 +75,32 @@ bool RicNewWellLogRftCurveFeature::isCommandEnabled() void RicNewWellLogRftCurveFeature::onActionTriggered(bool isChecked) { RimWellLogTrack* wellLogPlotTrack = selectedWellLogPlotTrack(); - if (!wellLogPlotTrack) return; + if (wellLogPlotTrack) + { + int branchIdx; + RicNewWellLogRftCurveFeature::addCurve(wellLogPlotTrack, selectedSimulationWell(&branchIdx)); + } + else + { + int branchIndex = -1; + RimEclipseWell* simWell = selectedSimulationWell(&branchIndex); + if (simWell) + { + RimWellLogTrack* wellLogPlotTrack = RicNewWellLogPlotFeatureImpl::createWellLogPlotTrack(); + RimWellLogRftCurve* plotCurve = RicNewWellLogRftCurveFeature::addCurve(wellLogPlotTrack, simWell); - RicNewWellLogRftCurveFeature::addCurve(wellLogPlotTrack); + plotCurve->loadDataAndUpdate(true); + + RimWellLogPlot* plot = NULL; + wellLogPlotTrack->firstAncestorOrThisOfType(plot); + if (plot && plotCurve->curveData()) + { + plot->setDepthUnit(plotCurve->curveData()->depthUnit()); + } + + plotCurve->updateConnectedEditors(); + } + } } //-------------------------------------------------------------------------------------------------- @@ -64,6 +112,49 @@ void RicNewWellLogRftCurveFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setIcon(QIcon(":/WellLogCurve16x16.png")); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimWellLogRftCurve* RicNewWellLogRftCurveFeature::addCurve(RimWellLogTrack* plotTrack, const RimEclipseWell* simWell) +{ + CVF_ASSERT(plotTrack); + + RimWellLogRftCurve* curve = new RimWellLogRftCurve(); + + RimEclipseResultCase* resultCase; + + std::vector cases; + RiaApplication::instance()->project()->allCases(cases); + + for (RimCase* rimCase : cases) + { + if (resultCase = dynamic_cast(rimCase)) + { + break; + } + } + + if (simWell && resultCase) + { + curve->setEclipseResultCase(resultCase); + curve->setDefaultAddress(simWell->name()); + } + + cvf::Color3f curveColor = RicWellLogPlotCurveFeatureImpl::curveColorFromTable(plotTrack->curveCount()); + curve->setColor(curveColor); + + plotTrack->addCurve(curve); + plotTrack->updateConnectedEditors(); + + RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow(); + + RiaApplication::instance()->project()->updateConnectedEditors(); + + plotwindow->selectAsCurrentItem(curve); + + return curve; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -77,20 +168,40 @@ RimWellLogTrack* RicNewWellLogRftCurveFeature::selectedWellLogPlotTrack() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimWellLogRftCurve* RicNewWellLogRftCurveFeature::addCurve(RimWellLogTrack* plotTrack) +RimEclipseWell* RicNewWellLogRftCurveFeature::selectedSimulationWell(int *branchIndex) { - CVF_ASSERT(plotTrack); - - RimWellLogRftCurve* curve = new RimWellLogRftCurve(); - plotTrack->addCurve(curve); - - plotTrack->updateConnectedEditors(); - - RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow(); - - RiaApplication::instance()->project()->updateConnectedEditors(); - - plotwindow->selectAsCurrentItem(curve); - - return curve; + RiuSelectionItem* selItem = RiuSelectionManager::instance()->selectedItem(RiuSelectionManager::RUI_TEMPORARY); + RiuSimWellSelectionItem* simWellSelItem = dynamic_cast(selItem); + if (simWellSelItem) + { + (*branchIndex) = static_cast(simWellSelItem->m_branchIndex); + return simWellSelItem->m_simWell; + } + else + { + std::vector selection; + caf::SelectionManager::instance()->objectsByType(&selection); + (*branchIndex) = 0; + return selection.size() > 0 ? selection[0] : NULL; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicNewWellLogRftCurveFeature::wellHasRftData(const QString& wellName) +{ + RimEclipseResultCase* resultCase; + std::vector cases; + RiaApplication::instance()->project()->allCases(cases); + + for (RimCase* rimCase : cases) + { + if (resultCase = dynamic_cast(rimCase)) + { + return resultCase->rftReader()->wellHasRftData(wellName); + } + } + + return false; } diff --git a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.h b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.h index c749101fea..2e61a130d1 100644 --- a/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.h +++ b/ApplicationCode/Commands/WellLogCommands/RicNewWellLogRftCurveFeature.h @@ -22,6 +22,8 @@ class RimWellLogRftCurve; class RimWellLogTrack; +class RimEclipseWell; +class RimWellPath; //================================================================================================== /// @@ -30,12 +32,13 @@ class RicNewWellLogRftCurveFeature : public caf::CmdFeature { CAF_CMD_HEADER_INIT; -public: - static RimWellLogRftCurve* addCurve(RimWellLogTrack* plotTrack); - static RimWellLogTrack* selectedWellLogPlotTrack(); - private: virtual bool isCommandEnabled() override; virtual void onActionTriggered( bool isChecked ) override; virtual void setupActionLook( QAction* actionToSetup ) override; + + static RimWellLogRftCurve* addCurve(RimWellLogTrack* plotTrack, const RimEclipseWell* simWell); + static RimWellLogTrack* selectedWellLogPlotTrack(); + static RimEclipseWell* selectedSimulationWell(int * branchIndex); + static bool wellHasRftData(const QString& wellName); }; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseRft.cpp b/ApplicationCode/FileInterface/RifReaderEclipseRft.cpp index 5601068afc..144d23c8dc 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseRft.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseRft.cpp @@ -272,6 +272,29 @@ const std::set& RifReaderEclipseRft::wellNames() return m_wellNames; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RifReaderEclipseRft::wellHasRftData(QString wellName) +{ + if (!m_ecl_rft_file) + { + open(); + } + + for (const QString& name : wellNames()) + { + if (name == wellName) + { + return true; + } + } + + return false; +} + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/FileInterface/RifReaderEclipseRft.h b/ApplicationCode/FileInterface/RifReaderEclipseRft.h index 042f75dff2..6b69617425 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseRft.h +++ b/ApplicationCode/FileInterface/RifReaderEclipseRft.h @@ -45,6 +45,7 @@ public: std::vector availableTimeSteps(const QString& wellName, const RifEclipseRftAddress::RftWellLogChannelName& wellLogChannelName); std::vector availableWellLogChannels(const QString& wellName); const std::set& wellNames(); + bool wellHasRftData(QString wellName); private: void open(); diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index bf4c7dddaf..9491449ffd 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -366,6 +366,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() else if (dynamic_cast(uiItem)) { commandIds << "RicNewWellLogCurveExtractionFeature"; + commandIds << "RicNewWellLogRftCurveFeature"; commandIds << "RicNewSimWellIntersectionFeature"; commandIds << "RicShowWellAllocationPlotFeature"; } diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp index a006c596ad..fb89e0fda6 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp @@ -134,6 +134,37 @@ RifEclipseRftAddress RimWellLogRftCurve::rftAddress() const return RifEclipseRftAddress(m_wellName, m_timeStep, m_wellLogChannelName()); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellLogRftCurve::setDefaultAddress(QString wellName) +{ + RifReaderEclipseRft* reader = rftReader(); + if (!reader) return; + + bool wellNameHasRftData = false; + std::set wellNames = reader->wellNames(); + for (const QString& wellNameWithRft : wellNames) + { + if (wellName == wellNameWithRft) + { + wellNameHasRftData = true; + m_wellName = wellName; + break; + } + } + + if (!wellNameHasRftData) return; + + m_wellLogChannelName = RifEclipseRftAddress::PRESSURE; + + std::vector timeSteps = reader->availableTimeSteps(m_wellName, m_wellLogChannelName()); + if (timeSteps.size() > 0) + { + m_timeStep = timeSteps[0]; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h index 485f9b7454..c774738d26 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h @@ -52,6 +52,8 @@ public: void setRftAddress(RifEclipseRftAddress address); RifEclipseRftAddress rftAddress() const; + void setDefaultAddress(QString wellName); + protected: // Overrides from RimWellLogPlotCurve virtual QString createCurveAutoName() override; diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index ab89af4580..1d2d434229 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -325,6 +325,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) RiuSelectionManager::instance()->setSelectedItem(selItem, RiuSelectionManager::RUI_TEMPORARY); commandIds << "RicNewWellLogCurveExtractionFeature"; + commandIds << "RicNewWellLogRftCurveFeature"; commandIds << "RicNewRftPlotFeature"; commandIds << "RicShowWellAllocationPlotFeature"; commandIds << "RicPlotProductionRateFeature";