Skip to content

Commit

Permalink
#1288 Show view selection dialog also from 3D view
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Mar 10, 2017
1 parent ecfd61c commit db56dd4
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

#include "RicShowContributingWellsFeatureImpl.h"

#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimEclipseWell.h"
#include "RimViewManipulator.h"

#include "RiuMainWindow.h"

#include "cafSelectionManager.h"
#include "cafCmdFeatureManager.h"
#include "cafSelectionManager.h"

#include <QAction>

Expand Down Expand Up @@ -59,10 +61,19 @@ void RicShowContributingWellsFeature::onActionTriggered(bool isChecked)
RimEclipseView* eclipseView = nullptr;
well->firstAncestorOrThisOfTypeAsserted(eclipseView);

RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(eclipseView, well->name(), eclipseView->currentTimeStep());
RimEclipseResultCase* eclipseResultCase = nullptr;
well->firstAncestorOrThisOfTypeAsserted(eclipseResultCase);

RimEclipseView* modifiedView = RicShowContributingWellsFeatureImpl::showViewSelection(eclipseResultCase, well->name(), eclipseView->currentTimeStep());
if (modifiedView)
{
modifiedView->createDisplayModelAndRedraw();

std::vector<RimView*> viewsToUpdate;
viewsToUpdate.push_back(modifiedView);

RiuMainWindow::instance()->setExpanded(eclipseView, true);
RiuMainWindow::instance()->selectAsCurrentItem(eclipseView);
RimViewManipulator::applySourceViewCameraOnDestinationViews(eclipseView, viewsToUpdate);
}
}

//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#include "RicShowContributingWellsFeatureImpl.h"

#include "RiaApplication.h"

#include "RicSelectViewUI.h"

#include "RigFlowDiagResultAddress.h"
#include "RigSingleWellResultsData.h"

Expand All @@ -28,14 +32,111 @@
#include "RimEclipseView.h"
#include "RimEclipseWell.h"
#include "RimEclipseWellCollection.h"
#include "RimFlowDiagSolution.h"
#include "RimFaultCollection.h"
#include "RimFlowDiagSolution.h"
#include "RimProject.h"
#include "RimViewManipulator.h"

#include "RiuMainWindow.h"

#include "cafAssert.h"
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmUiPropertyViewDialog.h"

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseView* RicShowContributingWellsFeatureImpl::showViewSelection(RimEclipseResultCase* wellAllocationResultCase, QString wellName, int timeStep)
{
const QString lastUsedViewKey("lastUsedViewKey");

RimEclipseView* defaultSelectedView = nullptr;
{
QString lastUsedViewRef = RiaApplication::instance()->cacheDataObject(lastUsedViewKey).toString();
RimEclipseView* lastUsedView = dynamic_cast<RimEclipseView*>(caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedViewRef));
if (lastUsedView)
{
RimEclipseResultCase* lastUsedViewResultCase = nullptr;
lastUsedView->firstAncestorOrThisOfTypeAsserted(lastUsedViewResultCase);

if (lastUsedViewResultCase == wellAllocationResultCase)
{
defaultSelectedView = lastUsedView;
}
}

if (!defaultSelectedView)
{
RimEclipseView* activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
if (activeView)
{
RimEclipseResultCase* activeViewResultCase = nullptr;
activeView->firstAncestorOrThisOfTypeAsserted(activeViewResultCase);

if (activeViewResultCase == wellAllocationResultCase)
{
defaultSelectedView = activeView;
}
else
{
if (wellAllocationResultCase->views().size() > 0)
{
defaultSelectedView = dynamic_cast<RimEclipseView*>(wellAllocationResultCase->views()[0]);
}
}
}
}
}

RicSelectViewUI featureUi;
if (defaultSelectedView)
{
featureUi.setView(defaultSelectedView);
}
else
{
featureUi.setCase(wellAllocationResultCase);
}

caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Show Contributing Wells in View", "");
propertyDialog.resize(QSize(400, 200));

if (propertyDialog.exec() != QDialog::Accepted) return nullptr;

RimEclipseView* viewToManipulate = nullptr;
if (featureUi.createNewView())
{
RimEclipseView* createdView = wellAllocationResultCase->createAndAddReservoirView();
createdView->name = featureUi.newViewName();

// Must be run before buildViewItems, as wells are created in this function
createdView->loadDataAndUpdate();
wellAllocationResultCase->updateConnectedEditors();

viewToManipulate = createdView;
}
else
{
viewToManipulate = featureUi.selectedView();
}

CAF_ASSERT(viewToManipulate);


RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(viewToManipulate, wellName, timeStep);

auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature");
feature->actionTriggered(false);

RiuMainWindow::instance()->setExpanded(viewToManipulate, true);
RiuMainWindow::instance()->selectAsCurrentItem(viewToManipulate);

QString refFromProjectToView = caf::PdmReferenceHelper::referenceFromRootToObject(RiaApplication::instance()->project(), viewToManipulate);
RiaApplication::instance()->setCacheDataObject(lastUsedViewKey, refFromProjectToView);

return viewToManipulate;
}

//--------------------------------------------------------------------------------------------------
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@

#include <QString>

class RimEclipseWell;
class RigSingleWellResultsData;
class RimEclipseResultCase;
class RimEclipseView;
class RimEclipseWell;
class RimFlowDiagSolution;
class RigSingleWellResultsData;

//==================================================================================================
///
//==================================================================================================
class RicShowContributingWellsFeatureImpl
{
public:
static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep);
static RimEclipseView* showViewSelection(RimEclipseResultCase* wellAllocationResultCase, QString wellName, int timeStep);

private:
static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep);

static std::vector<QString> findContributingTracerNames(
const RimFlowDiagSolution* flowDiagSolution,
const RigSingleWellResultsData* wellResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,12 @@

#include "RiaApplication.h"

#include "RicSelectViewUI.h"
#include "RicShowContributingWellsFeatureImpl.h"

#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimFlowDiagSolution.h"
#include "RimProject.h"
#include "RimWellAllocationPlot.h"

#include "RiuMainWindow.h"

#include "cafCmdFeatureManager.h"
#include "cafPdmUiPropertyViewDialog.h"

#include <QAction>

CAF_CMD_SOURCE_INIT(RicShowContributingWellsFromPlotFeature, "RicShowContributingWellsFromPlotFeature");
Expand All @@ -51,100 +43,16 @@ bool RicShowContributingWellsFromPlotFeature::isCommandEnabled()
//--------------------------------------------------------------------------------------------------
void RicShowContributingWellsFromPlotFeature::onActionTriggered(bool isChecked)
{
const QString lastUsedViewKey("lastUsedViewKey");

RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot();
if (!wellAllocationPlot) return;

RimEclipseResultCase* wellAllocationResultCase = nullptr;
wellAllocationPlot->flowDiagSolution()->firstAncestorOrThisOfTypeAsserted(wellAllocationResultCase);

RimEclipseView* defaultSelectedView = nullptr;

{
QString lastUsedViewRef = RiaApplication::instance()->cacheDataObject(lastUsedViewKey).toString();
RimEclipseView* lastUsedView = dynamic_cast<RimEclipseView*>(caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedViewRef));
if (lastUsedView)
{
RimEclipseResultCase* lastUsedViewResultCase = nullptr;
lastUsedView->firstAncestorOrThisOfTypeAsserted(lastUsedViewResultCase);

if (lastUsedViewResultCase == wellAllocationResultCase)
{
defaultSelectedView = lastUsedView;
}
}

if (!defaultSelectedView)
{
RimEclipseView* activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
if (activeView)
{
RimEclipseResultCase* activeViewResultCase = nullptr;
activeView->firstAncestorOrThisOfTypeAsserted(activeViewResultCase);

if (activeViewResultCase == wellAllocationResultCase)
{
defaultSelectedView = activeView;
}
else
{
if (wellAllocationResultCase->views().size() > 0)
{
defaultSelectedView = dynamic_cast<RimEclipseView*>(wellAllocationResultCase->views()[0]);
}
}
}
}
}

RicSelectViewUI featureUi;
if (defaultSelectedView)
{
featureUi.setView(defaultSelectedView);
}
else
{
featureUi.setCase(wellAllocationResultCase);
}

caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Show Contributing Wells in View", "");
propertyDialog.resize(QSize(400, 200));

if (propertyDialog.exec() != QDialog::Accepted) return;

RimEclipseView* viewToManipulate = nullptr;
if (featureUi.createNewView())
{
RimEclipseView* createdView = wellAllocationResultCase->createAndAddReservoirView();
createdView->name = featureUi.newViewName();

// Must be run before buildViewItems, as wells are created in this function
createdView->loadDataAndUpdate();
wellAllocationResultCase->updateConnectedEditors();

viewToManipulate = createdView;
}
else
{
viewToManipulate = featureUi.selectedView();
}

CAF_ASSERT(viewToManipulate);

int timeStep = wellAllocationPlot->timeStep();
QString wellName = wellAllocationPlot->wellName();

RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(viewToManipulate, wellName, timeStep);

auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature");
feature->actionTriggered(false);

RiuMainWindow::instance()->setExpanded(viewToManipulate, true);
RiuMainWindow::instance()->selectAsCurrentItem(viewToManipulate);
RimEclipseResultCase* wellAllocationResultCase = nullptr;
wellAllocationPlot->flowDiagSolution()->firstAncestorOrThisOfTypeAsserted(wellAllocationResultCase);

QString refFromProjectToView = caf::PdmReferenceHelper::referenceFromRootToObject(RiaApplication::instance()->project(), viewToManipulate);
RiaApplication::instance()->setCacheDataObject(lastUsedViewKey, refFromProjectToView);
RicShowContributingWellsFeatureImpl::showViewSelection(wellAllocationResultCase, wellName, timeStep);
}

//--------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit db56dd4

Please sign in to comment.