(#404) Added RicViewerEventInterface and moved well path text display into a separate class

This commit is contained in:
Magne Sjaastad 2015-12-04 15:15:13 +01:00
parent 27206cab3b
commit e65facd590
9 changed files with 177 additions and 70 deletions

View File

@ -78,14 +78,14 @@ void RicNewPolylineCrossSectionFeature::setupActionLook(QAction* actionToSetup)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewPolylineCrossSectionFeature::handleUiEvent(cvf::Object* uiEventObject)
bool RicNewPolylineCrossSectionFeature::handleEvent(cvf::Object* eventObject)
{
std::vector<RimCrossSection*> selection;
caf::SelectionManager::instance()->objectsByType(&selection);
if (selection.size() == 1)
{
RicLocalIntersectionUiEvent* polylineUiEvent = dynamic_cast<RicLocalIntersectionUiEvent*>(uiEventObject);
RicViewerEventObject* polylineUiEvent = dynamic_cast<RicViewerEventObject*>(eventObject);
if (polylineUiEvent)
{
RimCrossSection* crossSection = selection[0];

View File

@ -19,7 +19,7 @@
#pragma once
#include "RicCommandFeature.h"
#include "RicViewerEventInterface.h"
#include "cafCmdExecuteCommand.h"
#include "cafPdmPointer.h"
@ -53,7 +53,7 @@ private:
//==================================================================================================
///
//==================================================================================================
class RicNewPolylineCrossSectionFeature : public RicCommandFeature
class RicNewPolylineCrossSectionFeature : public caf::CmdFeature, public RicViewerEventInterface
{
CAF_CMD_HEADER_INIT;
@ -66,7 +66,7 @@ protected:
virtual void onActionTriggered( bool isChecked );
virtual void setupActionLook( QAction* actionToSetup );
virtual bool handleUiEvent(cvf::Object* uiEventObject);
virtual bool handleEvent(cvf::Object* eventObject);
};

View File

@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight 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.
//
// ResInsight 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector3.h"
namespace cvf {
class Part;
}
class RicViewerEventInterface
{
public:
virtual bool handleEvent(cvf::Object* eventObject) = 0;
};
class RicViewerEventObject : public cvf::Object
{
public:
RicViewerEventObject(cvf::Vec3d localIntersectionPoint, cvf::Part* firstHitPart, cvf::uint firstPartTriangleIndex)
: localIntersectionPoint(localIntersectionPoint),
firstHitPart(firstHitPart),
firstPartTriangleIndex(firstPartTriangleIndex)
{
}
cvf::Vec3d localIntersectionPoint;
cvf::Part* firstHitPart;
cvf::uint firstPartTriangleIndex;
};

View File

@ -9,6 +9,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.h
${CEE_CURRENT_LIST_DIR}RicWellPathViewerEventHandler.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -16,6 +17,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.cpp
${CEE_CURRENT_LIST_DIR}RicWellPathViewerEventHandler.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,92 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// ResInsight 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.
//
// ResInsight 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicWellPathViewerEventHandler.h"
#include "RiaApplication.h"
#include "RimCase.h"
#include "RimView.h"
#include "RimWellPath.h"
#include "RiuMainWindow.h"
#include "RivWellPathSourceInfo.h"
#include "cvfPart.h"
#include "cvfVector3.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicWellPathViewerEventHandler* RicWellPathViewerEventHandler::instance()
{
static RicWellPathViewerEventHandler* singleton = new RicWellPathViewerEventHandler;
return singleton;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicWellPathViewerEventHandler::handleEvent(cvf::Object* eventObject)
{
RicViewerEventObject* uiEvent = dynamic_cast<RicViewerEventObject*>(eventObject);
if (!uiEvent) return false;
if (uiEvent->firstHitPart && uiEvent->firstHitPart->sourceInfo())
{
const RivWellPathSourceInfo* wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(uiEvent->firstHitPart->sourceInfo());
if (wellPathSourceInfo)
{
cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO;
RimView* activeView = RiaApplication::instance()->activeReservoirView();
if (!activeView) return false;
RimCase* rimCase = NULL;
activeView->firstAnchestorOrThisOfType(rimCase);
if (rimCase)
{
displayModelOffset = rimCase->displayModelOffset();
}
cvf::Vec3d unscaledIntersection = uiEvent->localIntersectionPoint;
unscaledIntersection.z() /= activeView->scaleZ;
size_t wellSegmentIndex = wellPathSourceInfo->segmentIndex(uiEvent->firstPartTriangleIndex);
double measuredDepth = wellPathSourceInfo->measuredDepth(uiEvent->firstPartTriangleIndex, unscaledIntersection + displayModelOffset);
cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(uiEvent->firstPartTriangleIndex, unscaledIntersection + displayModelOffset);
QString wellPathText;
wellPathText += QString("Well path name : %1\n").arg(wellPathSourceInfo->wellPath()->name);
wellPathText += QString("Measured depth : %1\n").arg(measuredDepth);
QString formattedText;
formattedText.sprintf("Intersection point : [E: %.2f, N: %.2f, Depth: %.2f]", trueVerticalDepth.x(), trueVerticalDepth.y(), -trueVerticalDepth.z());
wellPathText += formattedText;
RiuMainWindow::instance()->setResultInfo(wellPathText);
return true;
}
}
return false;
}

View File

@ -19,27 +19,17 @@
#pragma once
#include "cafCmdFeature.h"
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector3.h"
#include "RicViewerEventInterface.h"
class RicCommandFeature : public caf::CmdFeature
//==================================================================================================
///
//==================================================================================================
class RicWellPathViewerEventHandler : public RicViewerEventInterface
{
public:
virtual bool handleUiEvent(cvf::Object* uiEventObject) = 0;
};
class RicLocalIntersectionUiEvent : public cvf::Object
{
public:
RicLocalIntersectionUiEvent(cvf::Vec3d localIntersectionPoint)
: localIntersectionPoint(localIntersectionPoint)
{
}
cvf::Vec3d localIntersectionPoint;
static RicWellPathViewerEventHandler* instance();
virtual bool handleEvent(cvf::Object* eventObject);
};

View File

@ -21,8 +21,6 @@
#include "RiaApplication.h"
#include "RicCommandFeature.h"
#include "RigSimulationWellCenterLineCalculator.h"
#include "RimCase.h"

View File

@ -19,7 +19,7 @@
#include "RiuViewerCommands.h"
#include "RicCommandFeature.h"
#include "RicViewerEventInterface.h"
#include "RicEclipsePropertyFilterNewExec.h"
#include "RicGeoMechPropertyFilterNewExec.h"
#include "RicRangeFilterNewExec.h"
@ -65,10 +65,13 @@
#include "cvfHitItemCollection.h"
#include "cvfPart.h"
#include "WellPathCommands/RicWellPathViewerEventHandler.h"
#include <QMenu>
#include <QMouseEvent>
#include <QStatusBar>
//==================================================================================================
//
// RiaViewerCommands
@ -84,13 +87,16 @@ RiuViewerCommands::RiuViewerCommands(RiuViewer* ownerViewer)
m_currentGridIdx(-1),
m_currentCellIndex(-1)
{
caf::CmdFeature* cmdFeature = caf::CmdFeatureManager::instance()->getCommandFeature("RicNewPolylineCrossSectionFeature");
CVF_ASSERT(cmdFeature);
{
caf::CmdFeature* cmdFeature = caf::CmdFeatureManager::instance()->getCommandFeature("RicNewPolylineCrossSectionFeature");
CVF_ASSERT(cmdFeature);
RicCommandFeature* riCommandFeature = dynamic_cast<RicCommandFeature*>(cmdFeature);
CVF_ASSERT(riCommandFeature);
m_viewerEventHandlers.push_back(dynamic_cast<RicViewerEventInterface*>(cmdFeature));
}
m_activeUiCommandFeature = riCommandFeature;
{
m_viewerEventHandlers.push_back(dynamic_cast<RicViewerEventInterface*>(RicWellPathViewerEventHandler::instance()));
}
}
//--------------------------------------------------------------------------------------------------
@ -109,7 +115,6 @@ void RiuViewerCommands::setOwnerView(RimView * owner)
m_reservoirView = owner;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -434,11 +439,10 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
{
extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &firstNncHitPart, &nncPartTriangleIndex);
if (!m_activeUiCommandFeature.isNull())
cvf::ref<RicViewerEventObject> eventObj = new RicViewerEventObject(localIntersectionPoint, firstHitPart, firstPartTriangleIndex);
for (size_t i = 0; i < m_viewerEventHandlers.size(); i++)
{
cvf::ref<RicLocalIntersectionUiEvent> uiEventObj = new RicLocalIntersectionUiEvent(localIntersectionPoint);
if (m_activeUiCommandFeature->handleUiEvent(uiEventObj.p()))
if (m_viewerEventHandlers[i]->handleEvent(eventObj.p()))
{
return;
}
@ -451,7 +455,6 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
{
const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>(firstHitPart->sourceInfo());
const RivFemPickSourceInfo* femSourceInfo = dynamic_cast<const RivFemPickSourceInfo*>(firstHitPart->sourceInfo());
const RivWellPathSourceInfo* wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(firstHitPart->sourceInfo());
const RivCrossSectionSourceInfo* crossSectionSourceInfo = dynamic_cast<const RivCrossSectionSourceInfo*>(firstHitPart->sourceInfo());
if (rivSourceInfo)
@ -470,37 +473,6 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
gridIndex = femSourceInfo->femPartIndex();
cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex(firstPartTriangleIndex);
}
else if (wellPathSourceInfo)
{
cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO;
RimCase* rimCase = NULL;
m_reservoirView->firstAnchestorOrThisOfType(rimCase);
if (rimCase)
{
displayModelOffset = rimCase->displayModelOffset();
}
cvf::Vec3d unscaledIntersection = localIntersectionPoint;
unscaledIntersection.z() /= m_reservoirView->scaleZ;
size_t wellSegmentIndex = wellPathSourceInfo->segmentIndex(firstPartTriangleIndex);
double measuredDepth = wellPathSourceInfo->measuredDepth(firstPartTriangleIndex, unscaledIntersection + displayModelOffset);
cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(firstPartTriangleIndex, unscaledIntersection + displayModelOffset);
QString wellPathText;
wellPathText += wellPathSourceInfo->wellPath()->name;
wellPathText += "\n";
wellPathText += QString("Well path segment index : %1\n").arg(wellSegmentIndex);
wellPathText += QString("Measured depth : %1\n").arg(measuredDepth);
QString formattedText;
formattedText.sprintf("Intersection point : [E: %.2f, N: %.2f, Depth: %.2f]", trueVerticalDepth.x(), trueVerticalDepth.y(), -trueVerticalDepth.z());
wellPathText += formattedText;
RiuMainWindow::instance()->setResultInfo(wellPathText);
}
else if (crossSectionSourceInfo)
{
findCellAndGridIndex(crossSectionSourceInfo, firstPartTriangleIndex, &cellIndex, &gridIndex);

View File

@ -31,7 +31,7 @@ class RimGeoMechView;
class RimView;
class RiuViewer;
class RivCrossSectionSourceInfo;
class RicCommandFeature;
class RicViewerEventInterface;
class QMouseEvent;
@ -79,7 +79,7 @@ private:
QPointer<RiuViewer> m_viewer;
QPointer<RicCommandFeature> m_activeUiCommandFeature;
std::vector<RicViewerEventInterface*> m_viewerEventHandlers;
};