#3757 Wip: Add draggers to text annotation points when text is selected

This commit is contained in:
Jacob Støren 2018-11-29 15:51:32 +01:00
parent c60e6b8140
commit c2206abca5
5 changed files with 255 additions and 0 deletions

View File

@ -4,6 +4,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicImportPolylinesAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateReachCircleAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicCreateUserDefinedPolylinesAnnotationFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -11,6 +12,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicImportPolylinesAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateTextAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateReachCircleAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicCreateUserDefinedPolylinesAnnotationFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.cpp
)
list(APPEND CODE_HEADER_FILES
@ -23,6 +25,7 @@ ${SOURCE_GROUP_SOURCE_FILES}
set (QT_MOC_HEADERS
${QT_MOC_HEADERS}
${CMAKE_CURRENT_LIST_DIR}/RicTextAnnotation3dEditor.h
)

View File

@ -0,0 +1,188 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicTextAnnotation3dEditor.h"
#include "../WellPathCommands/PointTangentManipulator/RicPointTangentManipulator.h"
#include "RimTextAnnotation.h"
#include "Rim3dView.h"
#include "RimCase.h"
#include "RiuViewer.h"
#include "cafDisplayCoordTransform.h"
#include "cafPdmUiCommandSystemProxy.h"
#include "cafSelectionManager.h"
#include "cvfPart.h"
#include "cvfModelBasicList.h"
CAF_PDM_UI_3D_OBJECT_EDITOR_SOURCE_INIT(RicTextAnnotation3dEditor);
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicTextAnnotation3dEditor::RicTextAnnotation3dEditor()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicTextAnnotation3dEditor::~RicTextAnnotation3dEditor()
{
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>(ownerViewer());
if (m_cvfModel.notNull() && ownerRiuViewer)
{
// Could result in some circularities ....
ownerRiuViewer->removeStaticModel(m_cvfModel.p());
}
auto textAnnot = dynamic_cast<RimTextAnnotation*>(this->pdmObject());
if (textAnnot)
{
textAnnot->m_anchorPointXyd.uiCapability()->removeFieldEditor(this);
textAnnot->m_labelPointXyd.uiCapability()->removeFieldEditor(this);
}
delete m_labelManipulator;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicTextAnnotation3dEditor::configureAndUpdateUi(const QString& uiConfigName)
{
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>(this->pdmObject());
RiuViewer* ownerRiuViewer = dynamic_cast<RiuViewer*>(ownerViewer());
if ( !textAnnot || !textAnnot->isActive())
{
m_cvfModel->removeAllParts();
return;
}
textAnnot->m_anchorPointXyd.uiCapability()->addFieldEditor(this);
textAnnot->m_labelPointXyd.uiCapability()->addFieldEditor(this);
if (m_labelManipulator.isNull())
{
m_labelManipulator = new RicPointTangentManipulator(ownerRiuViewer);
m_anchorManipulator = new RicPointTangentManipulator(ownerRiuViewer);
QObject::connect(m_labelManipulator,
SIGNAL( notifyUpdate(const cvf::Vec3d& , const cvf::Vec3d& ) ),
this,
SLOT( slotLabelUpdated(const cvf::Vec3d& , const cvf::Vec3d& ) ) );
QObject::connect(m_anchorManipulator,
SIGNAL( notifyUpdate(const cvf::Vec3d& , const cvf::Vec3d& ) ),
this,
SLOT( slotAnchorUpdated(const cvf::Vec3d& , const cvf::Vec3d& ) ) );
m_cvfModel = new cvf::ModelBasicList;
ownerRiuViewer->addStaticModelOnce(m_cvfModel.p());
}
cvf::ref<caf::DisplayCoordTransform> dispXf;
double handleSize = 1.0;
{
dispXf = ownerRiuViewer->ownerReservoirView()->displayCoordTransform();
Rim3dView* view = dynamic_cast<Rim3dView*>(ownerRiuViewer->ownerReservoirView());
handleSize = 0.7 * view->ownerCase()->characteristicCellSize();
}
cvf::Vec3d labelPos(textAnnot->m_labelPointXyd());
labelPos.z() *= -1.0;
m_labelManipulator->setOrigin(dispXf->transformToDisplayCoord( labelPos ));
m_labelManipulator->setHandleSize(handleSize);
cvf::Vec3d anchorPos(textAnnot->m_anchorPointXyd());
anchorPos.z() *= -1.0;
m_anchorManipulator->setOrigin(dispXf->transformToDisplayCoord( anchorPos ));
m_anchorManipulator->setHandleSize(handleSize);
m_cvfModel->removeAllParts();
m_labelManipulator->appendPartsToModel(m_cvfModel.p());
m_anchorManipulator->appendPartsToModel(m_cvfModel.p());
m_cvfModel->updateBoundingBoxesRecursive();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicTextAnnotation3dEditor::cleanupBeforeSettingPdmObject()
{
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>(this->pdmObject());
if (textAnnot)
{
textAnnot->m_anchorPointXyd.uiCapability()->removeFieldEditor(this);
textAnnot->m_labelPointXyd.uiCapability()->removeFieldEditor(this);
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicTextAnnotation3dEditor::slotLabelUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& tangent)
{
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>(this->pdmObject());
if ( !textAnnot)
{
return;
}
updatePoint(textAnnot->m_labelPointXyd.uiCapability(), origin);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicTextAnnotation3dEditor::slotAnchorUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& dummy)
{
RimTextAnnotation* textAnnot = dynamic_cast<RimTextAnnotation*>(this->pdmObject());
if ( !textAnnot)
{
return;
}
updatePoint(textAnnot->m_anchorPointXyd.uiCapability(), origin);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicTextAnnotation3dEditor::updatePoint(caf::PdmUiFieldHandle* uiField, const cvf::Vec3d& newPos)
{
cvf::ref<caf::DisplayCoordTransform> dispXf;
{
RiuViewer* viewer = dynamic_cast<RiuViewer*>(ownerViewer());
dispXf = viewer->ownerReservoirView()->displayCoordTransform();
}
cvf::Vec3d domainPos = dispXf->transformToDomainCoord( newPos);
domainPos.z() = -domainPos.z();
QVariant originVariant = caf::PdmValueFieldSpecialization < cvf::Vec3d >::convert(domainPos);
caf::PdmUiCommandSystemProxy::instance()->setUiValueToField(uiField, originVariant);
}

View File

@ -0,0 +1,59 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafPdmUi3dObjectEditorHandle.h"
class RicPointTangentManipulator;
#include "cvfBase.h"
#include "cvfObject.h"
#include "cvfVector3.h"
namespace cvf {
class ModelBasicList;
}
class QString;
#include <QPointer>
class RicTextAnnotation3dEditor : public caf::PdmUi3dObjectEditorHandle
{
CAF_PDM_UI_3D_OBJECT_EDITOR_HEADER_INIT;
Q_OBJECT
public:
RicTextAnnotation3dEditor();
~RicTextAnnotation3dEditor() override;
protected:
void configureAndUpdateUi(const QString& uiConfigName) override;
void cleanupBeforeSettingPdmObject() override;
private slots:
void slotLabelUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& dummy);
void slotAnchorUpdated(const cvf::Vec3d& origin, const cvf::Vec3d& dummy);
private:
void updatePoint(caf::PdmUiFieldHandle* uiField, const cvf::Vec3d& newPos);
QPointer<RicPointTangentManipulator> m_labelManipulator;
QPointer<RicPointTangentManipulator> m_anchorManipulator;
cvf::ref<cvf::ModelBasicList> m_cvfModel;
};

View File

@ -22,6 +22,7 @@
#include "RimGridView.h"
#include "RimProject.h"
#include "RimAnnotationCollection.h"
#include "AnnotationCommands/RicTextAnnotation3dEditor.h"
CAF_PDM_SOURCE_INIT(RimTextAnnotation, "RimTextAnnotation");
@ -33,6 +34,8 @@ CAF_PDM_SOURCE_INIT(RimTextAnnotation, "RimTextAnnotation");
RimTextAnnotation::RimTextAnnotation()
{
CAF_PDM_InitObject("TextAnnotation", ":/TextAnnotation16x16.png", "", "");
this->setUi3dEditorTypeName(RicTextAnnotation3dEditor::uiEditorTypeName());
CAF_PDM_InitField(&m_anchorPointXyd, "AnchorPointXyd", Vec3d::ZERO, "Anchor Point", "", "", "");
CAF_PDM_InitField(&m_labelPointXyd, "LabelPointXyd", Vec3d::ZERO, "Label Point", "", "", "");

View File

@ -66,6 +66,8 @@ protected:
virtual caf::PdmFieldHandle* objectToggleField() override;
private:
friend class RicTextAnnotation3dEditor;
caf::PdmField<Vec3d> m_anchorPointXyd;
caf::PdmField<Vec3d> m_labelPointXyd;
caf::PdmField<QString> m_text;