System : Simplify access to selected objects

This commit is contained in:
Magne Sjaastad
2017-10-19 09:09:22 +02:00
parent 66ff7d91bb
commit 22159a1c63
4 changed files with 93 additions and 43 deletions

View File

@@ -26,7 +26,7 @@
#include "RiuMainPlotWindow.h"
#include "cafSelectionManager.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
#include <QBoxLayout>
@@ -174,12 +174,10 @@ void RicTextWidget::contextMenuEvent(QContextMenuEvent* event)
//--------------------------------------------------------------------------------------------------
bool RicShowPlotDataFeature::isCommandEnabled()
{
std::vector<RimSummaryPlot*> selectedSummaryPlots;
caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots);
auto selectedSummaryPlots = caf::selectedObjectsByType<RimSummaryPlot*>();
if (selectedSummaryPlots.size() > 0) return true;
std::vector<RimWellLogPlot*> wellLogPlots;
caf::SelectionManager::instance()->objectsByType(&wellLogPlots);
auto wellLogPlots = caf::selectedObjectsByType<RimWellLogPlot*>();
if (wellLogPlots.size() > 0) return true;
return false;
@@ -192,11 +190,8 @@ void RicShowPlotDataFeature::onActionTriggered(bool isChecked)
{
this->disableModelChangeContribution();
std::vector<RimSummaryPlot*> selectedSummaryPlots;
caf::SelectionManager::instance()->objectsByType(&selectedSummaryPlots);
std::vector<RimWellLogPlot*> wellLogPlots;
caf::SelectionManager::instance()->objectsByType(&wellLogPlots);
std::vector<RimSummaryPlot*> selectedSummaryPlots = caf::selectedObjectsByType<RimSummaryPlot*>();
std::vector<RimWellLogPlot*> wellLogPlots = caf::selectedObjectsByType<RimWellLogPlot*>();
if (selectedSummaryPlots.size() == 0 && wellLogPlots.size() == 0)
{

View File

@@ -41,7 +41,7 @@
#include "RiuMainPlotWindow.h"
#include "RiuSelectionManager.h"
#include "cafSelectionManager.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
@@ -50,25 +50,6 @@
CAF_CMD_SOURCE_INIT(RicNewRftPlotFeature, "RicNewRftPlotFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename T>
static T selectedPdmObject()
{
T objToFind = nullptr;
caf::PdmUiItem* pdmUiItem = caf::SelectionManager::instance()->selectedItem();
caf::PdmObjectHandle* objHandle = dynamic_cast<caf::PdmObjectHandle*>(pdmUiItem);
if (objHandle)
{
objHandle->firstAncestorOrThisOfType(objToFind);
}
return objToFind;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -78,13 +59,13 @@ bool RicNewRftPlotFeature::isCommandEnabled()
//int branchIndex;
RimSimWellInView* simWell = selectedPdmObject<RimSimWellInView*>();
RimWellPath* rimWellPath = simWell == nullptr ? selectedPdmObject<RimWellPath*>() : nullptr;
RimSimWellInView* simWell = caf::firstAncestorOfTypeFromSelectedObject<RimSimWellInView*>();
RimWellPath* rimWellPath = simWell == nullptr ? caf::firstAncestorOfTypeFromSelectedObject<RimWellPath*>() : nullptr;
bool enable = true;
if (simWell != nullptr)
{
RimEclipseResultCase* eclCase = selectedPdmObject<RimEclipseResultCase*>();
RimEclipseResultCase* eclCase = caf::firstAncestorOfTypeFromSelectedObject<RimEclipseResultCase*>();
if (simWell != nullptr)
{
enable &= RimWellRftPlot::hasPressureData(eclCase);
@@ -116,11 +97,11 @@ void RicNewRftPlotFeature::onActionTriggered(bool isChecked)
QString wellName;
RimWellPath* wellPath = nullptr;
RimSimWellInView* eclipseWell = nullptr;
if ((wellPath = selectedPdmObject<RimWellPath*>()) != nullptr)
if ((wellPath = caf::firstAncestorOfTypeFromSelectedObject<RimWellPath*>()) != nullptr)
{
wellName = wellPath->name();
}
else if ((eclipseWell = selectedPdmObject<RimSimWellInView*>()) != nullptr)
else if ((eclipseWell = caf::firstAncestorOfTypeFromSelectedObject<RimSimWellInView*>()) != nullptr)
{
wellName = eclipseWell->name();
}
@@ -164,8 +145,7 @@ void RicNewRftPlotFeature::setupActionLook(QAction* actionToSetup)
//--------------------------------------------------------------------------------------------------
RimWellLogTrack* RicNewRftPlotFeature::selectedWellLogPlotTrack() const
{
std::vector<RimWellLogTrack*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
auto selection = caf::selectedObjectsByType<RimWellLogTrack*>();
return selection.size() > 0 ? selection[0] : nullptr;
}
@@ -174,8 +154,7 @@ RimWellLogTrack* RicNewRftPlotFeature::selectedWellLogPlotTrack() const
//--------------------------------------------------------------------------------------------------
RimWellPath* RicNewRftPlotFeature::selectedWellPath() const
{
std::vector<RimWellPath*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
auto selection = caf::selectedObjectsByType<RimWellPath*>();
return selection.size() > 0 ? selection[0] : nullptr;
}