#3255 Replace code that duplicates functionality in caf::SelectionManager

This commit is contained in:
Gaute Lindkvist 2018-08-22 12:04:42 +02:00
parent 12202fe4e6
commit 445e134d49
7 changed files with 18 additions and 55 deletions

View File

@ -42,17 +42,6 @@
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellLogTrack* RicWellLogTools::selectedWellLogPlotTrack()
{
std::vector<RimWellLogTrack*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
return selection.size() > 0 ? selection[0] : nullptr;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -74,35 +63,6 @@ RimSimWellInView* RicWellLogTools::selectedSimulationWell(int *branchIndex)
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPath* RicWellLogTools::selectedWellPath()
{
std::vector<RimWellPath*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
return selection.size() > 0 ? selection[0] : nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimWellPath* RicWellLogTools::findWellPathFromSelection()
{
std::vector<caf::PdmObject*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() > 0)
{
caf::PdmObject* firstSelection = selection[0];
RimWellPath* wellPath;
firstSelection->firstAncestorOrThisOfType(wellPath);
if (wellPath)
{
return wellPath;
}
}
return nullptr;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -195,7 +155,7 @@ RimWellPath* RicWellLogTools::selectedWellPathWithLogFile()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimWellPath* RicWellLogTools::findWellPathWithLogFileFromSelection() RimWellPath* RicWellLogTools::findWellPathWithLogFileFromSelection()
{ {
RimWellPath* wellPath = findWellPathFromSelection(); RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
if (wellPath->wellLogFiles().size() > 0) if (wellPath->wellLogFiles().size() > 0)
{ {
return wellPath; return wellPath;

View File

@ -38,10 +38,7 @@ class RimWellPath;
class RicWellLogTools class RicWellLogTools
{ {
public: public:
static RimWellLogTrack* selectedWellLogPlotTrack();
static RimSimWellInView* selectedSimulationWell(int* branchIndex); static RimSimWellInView* selectedSimulationWell(int* branchIndex);
static RimWellPath* selectedWellPath();
static RimWellPath* findWellPathFromSelection();
static bool wellHasRftData(const QString& wellName); static bool wellHasRftData(const QString& wellName);
static bool isWellPathOrSimWellSelectedInView(); static bool isWellPathOrSimWellSelectedInView();
static void addWellLogChannelsToPlotTrack(RimWellLogTrack* plotTrack, static void addWellLogChannelsToPlotTrack(RimWellLogTrack* plotTrack,

View File

@ -29,6 +29,8 @@
#include "Riu3DMainWindowTools.h" #include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction> #include <QAction>
CAF_CMD_SOURCE_INIT(RicAdd3dWellLogCurveFeature, "RicAdd3dWellLogCurveFeature"); CAF_CMD_SOURCE_INIT(RicAdd3dWellLogCurveFeature, "RicAdd3dWellLogCurveFeature");
@ -42,7 +44,7 @@ bool RicAdd3dWellLogCurveFeature::isCommandEnabled()
RiaApplication::instance()->project()->allCases(cases); RiaApplication::instance()->project()->allCases(cases);
if (cases.empty()) return false; if (cases.empty()) return false;
return RicWellLogTools::findWellPathFromSelection() != nullptr; return caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -50,7 +52,7 @@ bool RicAdd3dWellLogCurveFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicAdd3dWellLogCurveFeature::onActionTriggered(bool isChecked) void RicAdd3dWellLogCurveFeature::onActionTriggered(bool isChecked)
{ {
RimWellPath* selectedWellPath = RicWellLogTools::findWellPathFromSelection(); RimWellPath* selectedWellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
if (!selectedWellPath) return; if (!selectedWellPath) return;
Rim3dWellLogExtractionCurve* rim3dWellLogExtractionCurve = new Rim3dWellLogExtractionCurve(); Rim3dWellLogExtractionCurve* rim3dWellLogExtractionCurve = new Rim3dWellLogExtractionCurve();

View File

@ -28,6 +28,8 @@
#include "Riu3DMainWindowTools.h" #include "Riu3DMainWindowTools.h"
#include "cafSelectionManager.h"
#include <QAction> #include <QAction>
CAF_CMD_SOURCE_INIT(RicAdd3dWellLogRftCurveFeature, "RicAdd3dWellLogRftCurveFeature"); CAF_CMD_SOURCE_INIT(RicAdd3dWellLogRftCurveFeature, "RicAdd3dWellLogRftCurveFeature");
@ -41,7 +43,7 @@ bool RicAdd3dWellLogRftCurveFeature::isCommandEnabled()
RiaApplication::instance()->project()->allCases(cases); RiaApplication::instance()->project()->allCases(cases);
if (cases.empty()) return false; if (cases.empty()) return false;
RimWellPath* wellPath = RicWellLogTools::findWellPathFromSelection(); RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
if (wellPath) if (wellPath)
{ {
return RicWellLogTools::wellHasRftData(wellPath->name()); return RicWellLogTools::wellHasRftData(wellPath->name());
@ -54,7 +56,7 @@ bool RicAdd3dWellLogRftCurveFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicAdd3dWellLogRftCurveFeature::onActionTriggered(bool isChecked) void RicAdd3dWellLogRftCurveFeature::onActionTriggered(bool isChecked)
{ {
RimWellPath* selectedWellPath = RicWellLogTools::findWellPathFromSelection(); RimWellPath* selectedWellPath = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellPath>();
if (!selectedWellPath) return; if (!selectedWellPath) return;
Rim3dWellLogRftCurve* rim3dWellLogRftCurve = new Rim3dWellLogRftCurve(); Rim3dWellLogRftCurve* rim3dWellLogRftCurve = new Rim3dWellLogRftCurve();

View File

@ -57,7 +57,7 @@ bool RicNewWellLogCurveExtractionFeature::isCommandEnabled()
if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return false; if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return false;
if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false; if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false;
int branchIndex; int branchIndex;
return (RicWellLogTools::selectedWellLogPlotTrack() != nullptr || RicWellLogTools::selectedWellPath() != nullptr || RicWellLogTools::selectedSimulationWell(&branchIndex) != nullptr) && caseAvailable(); return (caf::SelectionManager::instance()->selectedItemOfType<RimWellLogTrack>() != nullptr || caf::SelectionManager::instance()->selectedItemOfType<RimWellPath>() != nullptr || RicWellLogTools::selectedSimulationWell(&branchIndex) != nullptr) && caseAvailable();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -67,14 +67,14 @@ void RicNewWellLogCurveExtractionFeature::onActionTriggered(bool isChecked)
{ {
if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return; if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return;
RimWellLogTrack* wellLogPlotTrack = RicWellLogTools::selectedWellLogPlotTrack(); RimWellLogTrack* wellLogPlotTrack = caf::SelectionManager::instance()->selectedItemOfType<RimWellLogTrack>();
if (wellLogPlotTrack) if (wellLogPlotTrack)
{ {
RicWellLogTools::addExtractionCurve(wellLogPlotTrack, nullptr, nullptr, nullptr, -1, true); RicWellLogTools::addExtractionCurve(wellLogPlotTrack, nullptr, nullptr, nullptr, -1, true);
} }
else else
{ {
RimWellPath* wellPath = RicWellLogTools::selectedWellPath(); RimWellPath* wellPath = caf::SelectionManager::instance()->selectedItemOfType<RimWellPath>();
int branchIndex = -1; int branchIndex = -1;
RimSimWellInView* simWell = RicWellLogTools::selectedSimulationWell(&branchIndex); RimSimWellInView* simWell = RicWellLogTools::selectedSimulationWell(&branchIndex);

View File

@ -50,7 +50,7 @@ CAF_CMD_SOURCE_INIT(RicNewWellLogFileCurveFeature, "RicNewWellLogFileCurveFeatur
bool RicNewWellLogFileCurveFeature::isCommandEnabled() bool RicNewWellLogFileCurveFeature::isCommandEnabled()
{ {
if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false; if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false;
return (RicWellLogTools::selectedWellLogPlotTrack() != nullptr && wellLogFilesAvailable()) || RicWellLogTools::selectedWellPathWithLogFile() != nullptr; return (caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellLogTrack>() != nullptr && wellLogFilesAvailable()) || RicWellLogTools::selectedWellPathWithLogFile() != nullptr;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -58,7 +58,7 @@ bool RicNewWellLogFileCurveFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellLogFileCurveFeature::onActionTriggered(bool isChecked) void RicNewWellLogFileCurveFeature::onActionTriggered(bool isChecked)
{ {
RimWellLogTrack* wellLogPlotTrack = RicWellLogTools::selectedWellLogPlotTrack(); RimWellLogTrack* wellLogPlotTrack = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimWellLogTrack>();
if (wellLogPlotTrack) if (wellLogPlotTrack)
{ {
RicWellLogTools::addFileCurve(wellLogPlotTrack); RicWellLogTools::addFileCurve(wellLogPlotTrack);

View File

@ -37,6 +37,8 @@
#include <QAction> #include <QAction>
#include <QString> #include <QString>
#include "cafSelectionManager.h"
#include <vector> #include <vector>
@ -48,7 +50,7 @@ CAF_CMD_SOURCE_INIT(RicNewWellLogRftCurveFeature, "RicNewWellLogRftCurveFeature"
bool RicNewWellLogRftCurveFeature::isCommandEnabled() bool RicNewWellLogRftCurveFeature::isCommandEnabled()
{ {
if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false; if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return false;
if (RicWellLogTools::selectedWellLogPlotTrack() != nullptr) if (caf::SelectionManager::instance()->selectedItemOfType<RimWellLogTrack>() != nullptr)
{ {
return true; return true;
} }
@ -69,7 +71,7 @@ bool RicNewWellLogRftCurveFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewWellLogRftCurveFeature::onActionTriggered(bool isChecked) void RicNewWellLogRftCurveFeature::onActionTriggered(bool isChecked)
{ {
RimWellLogTrack* wellLogPlotTrack = RicWellLogTools::selectedWellLogPlotTrack(); RimWellLogTrack* wellLogPlotTrack = caf::SelectionManager::instance()->selectedItemOfType<RimWellLogTrack>();
if (wellLogPlotTrack) if (wellLogPlotTrack)
{ {
int branchIdx; int branchIdx;