mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
System : Simplify access to selected objects
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,13 +46,11 @@ set( PROJECT_FILES
|
||||
|
||||
cafSelectionManager.cpp
|
||||
cafSelectionManager.h
|
||||
|
||||
|
||||
cafSelectionManagerTools.h
|
||||
)
|
||||
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
${PROJECT_FILES}
|
||||
)
|
||||
|
||||
source_group("" FILES ${PROJECT_FILES})
|
||||
source_group("" FILES ${PROJECT_FILES})
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// Custom Visualization Core library
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This library may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
namespace caf {
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Get the single selected object from selection manager. Then, starting at this object, find the
|
||||
/// first object of given type searching upwards to root using firstAncestorOrThisOfType()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
T firstAncestorOfTypeFromSelectedObject()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Return all objects of given type from the selection manager
|
||||
///
|
||||
/// Consider replace SelectionManager::objectsByType with this function when all consumers
|
||||
/// have been updated to use this function instead of SelectionManager::objectsByType
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
std::vector<T> selectedObjectsByType()
|
||||
{
|
||||
std::vector<T> objectByType;
|
||||
caf::SelectionManager::instance()->objectsByType(&objectByType);
|
||||
|
||||
return objectByType;
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
Reference in New Issue
Block a user