#3757 New feature to add a text annotation in the 3D view

This commit is contained in:
Jacob Støren 2018-11-30 14:29:46 +01:00
parent 92a45e959e
commit a9a5eaf604
8 changed files with 343 additions and 0 deletions

View File

@ -2,6 +2,7 @@
set (SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportPolylinesAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationIn3dViewFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateReachCircleAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateUserDefinedPolylinesAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.h
@ -10,6 +11,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.h
set (SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicImportPolylinesAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationIn3dViewFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateReachCircleAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateUserDefinedPolylinesAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.cpp

View File

@ -0,0 +1,90 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- equinor ASA
//
// 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 "RicCreateTextAnnotationIn3dViewFeature.h"
#include "RiaApplication.h"
#include "RimTextAnnotation.h"
#include "RimAnnotationInViewCollection.h"
#include "RimGridView.h"
#include "RimCase.h"
#include "RiuMainWindow.h"
#include "RiuViewer.h"
#include <QAction>
#include "cvfBoundingBox.h"
#include "cvfCamera.h"
CAF_CMD_SOURCE_INIT(RicCreateTextAnnotationIn3dViewFeature, "RicCreateTextAnnotationIn3dViewFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateTextAnnotationIn3dViewFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateTextAnnotationIn3dViewFeature::onActionTriggered(bool isChecked)
{
RimGridView* activeView = RiaApplication::instance()->activeGridView();
if ( activeView )
{
cvf::Vec3d domainCoord = activeView->viewer()->lastPickPositionInDomainCoords();
cvf::BoundingBox bbox = activeView->ownerCase()->activeCellsBoundingBox();
auto coll = activeView->annotationCollection();
if ( coll )
{
auto newAnnotation = new RimTextAnnotation();
newAnnotation->setAnchorPoint(domainCoord);
cvf::Vec3d labelPos = domainCoord;
labelPos.z() = bbox.max().z();
double height = labelPos.z() - domainCoord.z();
cvf::Vec3d horizontalRight = activeView->viewer()->mainCamera()->direction() ^ cvf::Vec3d::Z_AXIS;
bool isOk = horizontalRight.normalize();
if (!isOk) horizontalRight = {1.0, 0.0, 0.0};
newAnnotation->setLabelPoint(labelPos + horizontalRight*0.5*height);
coll->addAnnotation(newAnnotation);
coll->scheduleRedrawOfRelevantViews();
coll->updateConnectedEditors();
RiuMainWindow::instance()->selectAsCurrentItem(newAnnotation);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateTextAnnotationIn3dViewFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setIcon(QIcon(":/TextAnnotation16x16.png"));
actionToSetup->setText("Create Text Annotation");
}

View File

@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- equinor ASA
//
// 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"
//==================================================================================================
///
//==================================================================================================
class RicCreateTextAnnotationIn3dViewFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered(bool isChecked) override;
void setupActionLook(QAction* actionToSetup) override;
};

View File

@ -0,0 +1,146 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018- Statoil ASA
//
// 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 "RicCreateTextAnnotationPickEventHandler.h"
#include "RiaOffshoreSphericalCoords.h"
#include "RigWellPath.h"
#include "Rim3dView.h"
#include "RimModeledWellPath.h"
#include "RimWellPath.h"
#include "RimWellPathGeometryDef.h"
#include "RimWellPathTarget.h"
#include "RiuViewerCommands.h"
#include "RivWellPathSourceInfo.h"
#include "cafDisplayCoordTransform.h"
#include "cafSelectionManager.h"
#include <vector>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicCreateTextAnnotationPickEventHandler::RicCreateTextAnnotationPickEventHandler(RimTextAnnotation* textAnnotation)
: m_annotationToEdit(textAnnotation)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicCreateTextAnnotationPickEventHandler::~RicCreateTextAnnotationPickEventHandler() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCreateTextAnnotationPickEventHandler::notifyUnregistered()
{
m_annotationToEdit->enableTargetPointPicking(false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCreateTextAnnotationPickEventHandler::handlePickEvent(const Ric3DPickEvent& eventObject)
{
if (!caf::SelectionManager::instance()->isSelected(m_annotationToEdit.p(), 0))
{
m_annotationToEdit->enableTargetPointPicking(false);
return false;
}
if (m_annotationToEdit)
{
Rim3dView* rimView = eventObject.m_view;
cvf::Vec3d targetPointInDomain = cvf::Vec3d::ZERO;
// If clicked on an other well path, snap target point to well path center line
auto firstPickItem = eventObject.m_pickItemInfos.front();
auto wellPathSourceInfo = dynamic_cast<const RivWellPathSourceInfo*>(firstPickItem.sourceInfo());
auto intersectionPointInDomain =
rimView->displayCoordTransform()->transformToDomainCoord(firstPickItem.globalPickedPoint());
bool doSetAzimuthAndInclination = false;
double azimuth = 0.0;
double inclination = 0.0;
if (wellPathSourceInfo)
{
targetPointInDomain =
wellPathSourceInfo->closestPointOnCenterLine(firstPickItem.faceIdx(), intersectionPointInDomain);
double md = wellPathSourceInfo->measuredDepth(firstPickItem.faceIdx(), intersectionPointInDomain);
doSetAzimuthAndInclination = calculateAzimuthAndInclinationAtMd(
md, wellPathSourceInfo->wellPath()->wellPathGeometry(), &azimuth, &inclination);
}
else
{
targetPointInDomain = intersectionPointInDomain;
doSetAzimuthAndInclination = false;
}
if (!m_annotationToEdit->firstActiveTarget())
{
m_annotationToEdit->setReferencePointXyz(targetPointInDomain);
if (wellPathSourceInfo)
{
double mdrkbAtFirstTarget = wellPathSourceInfo->measuredDepth(firstPickItem.faceIdx(), intersectionPointInDomain);
RimModeledWellPath* modeledWellPath = dynamic_cast<RimModeledWellPath*>(wellPathSourceInfo->wellPath());
if (modeledWellPath)
{
mdrkbAtFirstTarget += modeledWellPath->geometryDefinition()->mdrkbAtFirstTarget();
}
m_annotationToEdit->setMdrkbAtFirstTarget(mdrkbAtFirstTarget);
}
}
cvf::Vec3d referencePoint = m_annotationToEdit->referencePointXyz();
cvf::Vec3d relativeTagetPoint = targetPointInDomain - referencePoint;
RimWellPathTarget* newTarget = new RimWellPathTarget;
if (doSetAzimuthAndInclination)
{
newTarget->setAsPointXYZAndTangentTarget(
cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), relativeTagetPoint.z()), azimuth, inclination);
}
else
{
newTarget->setAsPointTargetXYD(cvf::Vec3d(relativeTagetPoint.x(), relativeTagetPoint.y(), -relativeTagetPoint.z()));
}
m_annotationToEdit->insertTarget(nullptr, newTarget);
m_annotationToEdit->updateConnectedEditors();
m_annotationToEdit->updateWellPathVisualization();
return true; // Todo: See if we really should eat the event instead
}
return false;
}

View File

@ -0,0 +1,44 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
//
// 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 "RicPickEventHandler.h"
#include "cafPdmPointer.h"
class RimTextAnnotation;
//==================================================================================================
///
//==================================================================================================
class RicCreateTextAnnotationPickEventHandler : public RicPickEventHandler
{
public:
RicCreateTextAnnotationPickEventHandler(RimTextAnnotation* textAnnotation);
~RicCreateTextAnnotationPickEventHandler();
protected:
bool handlePickEvent(const Ric3DPickEvent& eventObject) override;
void notifyUnregistered() override;
private:
private:
caf::PdmPointer<RimTextAnnotation> m_annotationToEdit;
};

View File

@ -64,6 +64,15 @@ cvf::Vec3d RimTextAnnotation::anchorPoint() const
return pos;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimTextAnnotation::setAnchorPoint(const Vec3d & pointXyz)
{
m_anchorPointXyd = pointXyz;
m_anchorPointXyd.v().z() *= -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -74,6 +83,15 @@ cvf::Vec3d RimTextAnnotation::labelPoint() const
return pos;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimTextAnnotation::setLabelPoint(const Vec3d & pointXyz)
{
m_labelPointXyd = pointXyz;
m_labelPointXyd.v().z() *= -1;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -54,7 +54,9 @@ public:
~RimTextAnnotation();
Vec3d anchorPoint() const;
void setAnchorPoint(const Vec3d & pointXyz) ;
Vec3d labelPoint() const;
void setLabelPoint(const Vec3d & pointXyz) ;
void setText(const QString& text);
const QString& text() const;
bool isActive();

View File

@ -475,6 +475,11 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
menuBuilder << "RicSelectColorResult";
}
}
else
{
menuBuilder.addSeparator();
menuBuilder << "RicCreateTextAnnotationIn3dViewFeature";
}
if (gridView)
{