#3757 Add selection of text annotations by picking

This commit is contained in:
Jacob Støren 2018-12-03 10:53:40 +01:00
parent e984b06ea6
commit a13201e42e
4 changed files with 98 additions and 52 deletions

View File

@ -1,7 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
// 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
@ -19,15 +18,13 @@
#include "RivTextAnnotationSourceInfo.h"
#include "RimEclipseView.h"
#include "RimAnnotationInViewCollection.h"
#include "RimTextAnnotation.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivTextAnnotationSourceInfo::RivTextAnnotationSourceInfo(RimTextAnnotation* annotation)
: m_annotation(annotation)
: RivObjectSourceInfo(annotation)
{
}
@ -36,5 +33,5 @@ RivTextAnnotationSourceInfo::RivTextAnnotationSourceInfo(RimTextAnnotation* anno
//--------------------------------------------------------------------------------------------------
RimTextAnnotation* RivTextAnnotationSourceInfo::annotation() const
{
return m_annotation.p();
return dynamic_cast<RimTextAnnotation*>( this->object() );
}

View File

@ -1,7 +1,6 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
// 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
@ -19,14 +18,11 @@
#pragma once
#include "cvfBase.h"
#include "cvfObject.h"
#include "cafPdmPointer.h"
#include "RivObjectSourceInfo.h"
//class RimAnnotationInView;
class RimTextAnnotation;
class RivTextAnnotationSourceInfo : public cvf::Object
class RivTextAnnotationSourceInfo : public RivObjectSourceInfo
{
public:
RivTextAnnotationSourceInfo(RimTextAnnotation* annotation);

View File

@ -100,6 +100,11 @@
#include <QStatusBar>
#include <array>
#include "cvfScene.h"
#include "RivPartPriority.h"
#include "cvfDrawableText.h"
#include "cvfRay.h"
#include "RimTextAnnotation.h"
@ -111,7 +116,6 @@
RicPickEventHandler* RiuViewerCommands::sm_overridingPickHandler = nullptr;
std::vector<RicDefaultPickEventHandler*> RiuViewerCommands::sm_defaultPickEventHandlers;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -522,14 +526,16 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
std::vector<RiuPickItemInfo> pickItemInfos;
{
cvf::HitItemCollection hitItems;
if ( m_viewer->rayPick(winPosX, winPosY, &hitItems) )
{
m_viewer->rayPick(winPosX, winPosY, &hitItems);
// Do specialized text pick, since vizfwk does not hit text
handleTextPicking(winPosX, winPosY, &hitItems);
if ( hitItems.count() )
{
pickItemInfos = RiuPickItemInfo::convertToPickItemInfos(hitItems);
}
}
}
// Make pickEventHandlers do their stuff
@ -620,10 +626,11 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
if (rivObjectSourceInfo)
{
RimFracture* fracture = dynamic_cast<RimFracture*>(rivObjectSourceInfo->object());
if ( fracture )
{
{
bool blockSelectionOfFracture = false;
if (fracture)
{
std::vector<caf::PdmUiItem*> uiItems;
RiuMainWindow::instance()->projectTreeView()->selectedUiItems(uiItems);
@ -671,6 +678,13 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM
}
}
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>(rivObjectSourceInfo->object());
if (textAnnot)
{
RiuMainWindow::instance()->selectAsCurrentItem(textAnnot, true);
}
}
if (rivSourceInfo)
{
gridIndex = rivSourceInfo->gridIndex();
@ -1124,3 +1138,41 @@ bool RiuViewerCommands::handleOverlayItemPicking(int winPosX, int winPosY)
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuViewerCommands::handleTextPicking(int winPosX, int winPosY, cvf::HitItemCollection* hitItems)
{
using namespace cvf;
int translatedMousePosX = winPosX;
int translatedMousePosY = m_viewer->height() - winPosY;
Scene* scene = m_viewer->currentScene();
Collection<Part> partCollection;
scene->allParts(&partCollection);
ref<Ray> ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
for (size_t pIdx = 0; pIdx < partCollection.size(); ++pIdx)
{
if (partCollection[pIdx]->priority() == RivPartPriority::PartType::Text) // Just trying to avoid dyncasting all drawables
{
DrawableText* textDrawable = dynamic_cast<DrawableText*> (partCollection[pIdx]->drawable());
if (textDrawable)
{
cvf::Vec3d ppoint;
if (textDrawable->rayIntersect(*ray, *( m_viewer->mainCamera()), &ppoint))
{
cvf::ref<HitItem> hitItem = new HitItem(0, ppoint);
hitItem->setPart(partCollection[pIdx].p());
hitItems->add(hitItem.p());
}
}
}
}
hitItems->sort();
}

View File

@ -89,4 +89,5 @@ private:
static RicPickEventHandler* sm_overridingPickHandler;
static std::vector<RicDefaultPickEventHandler*> sm_defaultPickEventHandlers;
void handleTextPicking(int winPosX, int winPosY, cvf::HitItemCollection* hitItems);
};